PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/converseen-0.5.1/src/dialogconversionstatus.cpp

#
C++ | 166 lines | 111 code | 33 blank | 22 comment | 14 complexity | 55f341d61a7fc41eb18717a46ee48202 MD5 | raw file
Possible License(s): GPL-3.0
  1. /*
  2. * This file is part of Converseen, an open-source batch image converter
  3. * and resizer.
  4. *
  5. * (C) Francesco Mondello 2009-2012
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Contact e-mail: Faster <faster3ck@gmail.com>
  21. *
  22. */
  23. #include <QMenu>
  24. #include <QAction>
  25. #include <QList>
  26. #include <QDesktopServices>
  27. #include <QUrl>
  28. #include "dialogconversionstatus.h"
  29. DialogConversionStatus::DialogConversionStatus(QWidget *parent) :
  30. QDialog(parent){
  31. setupUi(this);
  32. setWindowFlags(Qt::Dialog | Qt::WindowMinimizeButtonHint);
  33. connect(pushClose, SIGNAL(clicked()), this, SLOT(close()));
  34. connect(pushAbort, SIGNAL(clicked()), this, SLOT(abort()));
  35. menu = new QMenu(this);
  36. actionOpenAllDirs = new QAction(tr("Open all the destination folders"), this);
  37. connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(openDir(QAction*)));
  38. connect(actionOpenAllDirs, SIGNAL(triggered()), this, SLOT(openAllDirs()));
  39. }
  40. void DialogConversionStatus::setup(int n_images)
  41. {
  42. treeWidget->clear();
  43. c_tot = 0;
  44. c_ok = 0;
  45. c_no = 0;
  46. progressBar->reset();
  47. progressBar->setMinimum(0);
  48. progressBar->setMaximum(n_images);
  49. pushClose->setEnabled(false);
  50. pushAbort->setEnabled(true);
  51. m_totimages = n_images;
  52. m_msg.clear();
  53. outDirs.clear();
  54. pushOpen->setEnabled(false);
  55. }
  56. void DialogConversionStatus::conversionStatus(int conv_status, QString fileName)
  57. {
  58. QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget);
  59. if (conv_status == 1)
  60. m_msg = tr("Converted");
  61. item->setText(0, fileName);
  62. item->setText(1, m_msg);
  63. }
  64. void DialogConversionStatus::counter(int conv_status)
  65. {
  66. c_tot++; // Count total images and compare with total global to reset the window
  67. if (conv_status == 1)
  68. c_ok++;
  69. if (conv_status == -1)
  70. c_no++;
  71. labelOk->setText(QString::number(c_ok));
  72. labelKo->setText(QString::number(c_no));
  73. labelTotal->setText(QString::number(c_tot));
  74. }
  75. void DialogConversionStatus::step(int conv_status, QString fileName) // avviene quando un'immagine ?ยจ stata processata (o saltata)
  76. {
  77. counter(conv_status);
  78. conversionStatus(conv_status, fileName);
  79. progressBar->setValue(c_tot);
  80. if (c_tot == m_totimages)
  81. resetButtons();
  82. }
  83. void DialogConversionStatus::abort()
  84. {
  85. resetButtons();
  86. emit stopProcess();
  87. }
  88. void DialogConversionStatus::resetButtons()
  89. {
  90. pushClose->setEnabled(true);
  91. pushAbort->setEnabled(false);
  92. }
  93. void DialogConversionStatus::setErrorMsg(QString err_status)
  94. {
  95. m_msg = err_status;
  96. }
  97. void DialogConversionStatus::addOutputDirectory(QString path)
  98. {
  99. if (!outDirs.contains(path))
  100. outDirs.append(path);
  101. if (c_tot == m_totimages) {
  102. if (outDirs.count() > 0) {
  103. setupOpenButton();
  104. pushOpen->setEnabled(true);
  105. }
  106. }
  107. }
  108. void DialogConversionStatus::setupOpenButton()
  109. {
  110. QList<QAction *> aL;
  111. menu->clear();
  112. for (int i = 0; i < outDirs.count(); i++) {
  113. QString s = outDirs.at(i);
  114. QAction *a = new QAction(s, this);
  115. a->setData(s);
  116. aL << a;
  117. }
  118. menu->addActions(aL);
  119. menu->addSeparator();
  120. menu->addAction(actionOpenAllDirs);
  121. pushOpen->setMenu(menu);
  122. }
  123. void DialogConversionStatus::openDir(QAction *action)
  124. {
  125. QString value = action->data().toString();
  126. QDesktopServices::openUrl(QUrl("file:///" + value, QUrl::TolerantMode));
  127. }
  128. void DialogConversionStatus::openAllDirs()
  129. {
  130. for (int i = 0; i < outDirs.count(); i++) {
  131. QDesktopServices::openUrl(QUrl("file:///" + outDirs.at(i), QUrl::TolerantMode));
  132. }
  133. }