Your warranties manager
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

scannerdialog.cpp 3.3 KiB

10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
10 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "scannerdialog.h"
  2. #include "ui_scannerdialog.h"
  3. #include <QDir>
  4. #include <QDesktopServices>
  5. #include <QUrl>
  6. #include <QProcess>
  7. #include <QMessageBox>
  8. #include <iostream>
  9. #ifdef Q_OS_WIN32
  10. // Includes propre à Windows pour l'utilisation du scanner (via le service Windows Image Acquisition)
  11. #include <windows.h>
  12. #include <wia.h>
  13. #include <wiadef.h>
  14. #include <wiadevd.h>
  15. #include <wiavideo.h>
  16. #endif
  17. ScannerDialog::ScannerDialog(QWidget *parent) :
  18. QDialog(parent),
  19. ui(new Ui::ScannerDialog)
  20. {
  21. ui->setupUi(this);
  22. ui->progressBar->hide();
  23. }
  24. ScannerDialog::~ScannerDialog()
  25. {
  26. delete ui;
  27. }
  28. void ScannerDialog::on_btnTest_clicked()
  29. {
  30. #if defined Q_OS_LINUX
  31. ui->btnTest->setEnabled(false);
  32. ui->btnScan->setEnabled(false);
  33. ui->btnAnnuler->setEnabled(false);
  34. QProcess* process = new QProcess();
  35. process->setStandardOutputFile(QDir::tempPath() + "/test.pnm");
  36. process->start("scanimage");
  37. ui->progressBar->show();
  38. connect(process, SIGNAL(finished(int)), SLOT(scanTestFinished(int)));
  39. #endif
  40. }
  41. void ScannerDialog::scanTestFinished(int r = 0)
  42. {
  43. #if defined Q_OS_WIN32
  44. QMessageBox::information(this, "test", "ok");
  45. #elif defined Q_OS_LINUX
  46. ui->progressBar->hide();
  47. ui->btnTest->setEnabled(true);
  48. ui->btnScan->setEnabled(true);
  49. ui->btnAnnuler->setEnabled(true);
  50. std::string s = "convert " + QDir::tempPath().toStdString() + "/test.pnm " + QDir::tempPath().toStdString() + "/test.pdf";
  51. if(r == 0)
  52. {
  53. int c = system(s.c_str());
  54. if(c == 0)
  55. QDesktopServices::openUrl(QUrl("file://"+QDir::tempPath()+"/test.pdf"));
  56. else
  57. QMessageBox::critical(this, tr("Erreur"), tr("Votre document a pu être numérisé, mais un problème est survenu lors de son traitement.\nErreur %1").arg(QString::number(c)));
  58. }
  59. else
  60. QMessageBox::critical(this, tr("Erreur"), tr("Impossible de communiquer avec votre scanner. Vérifiez qu'il est bien relié à l'ordinateur' et qu'il est sous tension, puis réessayez.\nSi le problème persiste, il est probable que votre scanner ne soit pas pris en charge."));
  61. #endif
  62. }
  63. void ScannerDialog::on_btnScan_clicked()
  64. {
  65. #ifdef Q_OS_LINUX
  66. ui->btnTest->setEnabled(false);
  67. ui->btnScan->setEnabled(false);
  68. ui->btnAnnuler->setEnabled(false);
  69. QProcess* process = new QProcess();
  70. process->setStandardOutputFile(QDir::tempPath() + "/output.pnm");
  71. process->start("scanimage --resolution 200");
  72. ui->progressBar->show();
  73. connect(process, SIGNAL(finished(int)), SLOT(scanFinished(int)));
  74. #endif
  75. }
  76. void ScannerDialog::scanFinished(int r)
  77. {
  78. ui->progressBar->hide();
  79. std::string s = "convert " + QDir::tempPath().toStdString() + "/output.pnm " + QDir::tempPath().toStdString() + "/output.pdf";
  80. if(r == 0)
  81. {
  82. int c = system(s.c_str());
  83. if(c != 0)
  84. QMessageBox::critical(this, tr("Erreur"), tr("Votre document a pu être numérisé, mais un problème est survenu lors de son traitement.\nErreur %1").arg(QString::number(c)));
  85. else
  86. this->accept();
  87. }
  88. else
  89. QMessageBox::critical(this, tr("Erreur"), tr("Impossible de communiquer avec votre scanner. Vérifiez qu'il est bien relié à l'ordinateur' et qu'il est sous tension, puis réessayez.\nSi le problème persiste, il est probable que votre scanner ne soit pas pris en charge."));
  90. }