From: hama Date: Sat, 16 Jan 2016 10:31:55 +0000 (+0100) Subject: source sorting, working reimgconvert X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=8ca51ea0bc1df14be17dbd008654edf98599c82b;p=reqt source sorting, working reimgconvert * source sorting in refind and reimgconvert * pre alpha of reimgconvert --- diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index 1f50c41..33c0a81 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -123,8 +123,6 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, ui->tableWidget->setColumnWidth(TC_TYPE, 75); prepareContextMenu(); m_guiTimer->start(100); - bool active = m_guiTimer->isActive(); - active = ! active; } /** @@ -134,27 +132,6 @@ MainWindow::~MainWindow(){ delete ui; } -/** - * initializeHomeializes the program home directory. - */ -void MainWindow::initializeHome(){ - if (m_homeDir.isEmpty()){ - m_homeDir = QDir::home().absoluteFilePath(".refind"); - } - - QDir home(m_homeDir); - if (!home.exists()){ - if (!home.mkpath(m_homeDir)){ - m_homeDir = home.tempPath() + "/.refind"; - home.mkpath(m_homeDir); - } - } - if (!m_homeDir.endsWith("/")) - m_homeDir += "/"; - m_storageFile = m_homeDir + "state.conf"; - restoreState(); -} - /** * Starts the about dialog. */ @@ -163,14 +140,6 @@ void MainWindow::about(){ dialog.exec(); } -/** - * Starts the options dialog. - */ -void MainWindow::options(){ - DialogOptions dialog(m_contextHandlers, NULL); - dialog.exec(); -} - /** * Puts the absolute path of the current (selected) file into the clipboard. */ @@ -231,6 +200,27 @@ QDir::Filters MainWindow::buildFileTypes(){ return rc; } + +/** + * Builds the hash with the global placeholders with their current values. + * + * @param hash IN/OUT: the placeholders will be appended here + */ +void MainWindow::buildGlobalPlaceholders(QMap & hash){ + + hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText()); + hash.insert("base", m_lastBaseDir.absolutePath()); + hash.insert("textpattern", addEsc(ui->comboBoxTextPattern->currentText())); + hash.insert("dirs", QString::number(m_statistics.m_dirs)); + hash.insert("files", QString::number(m_statistics.m_files)); + hash.insert("runtime", QString::number(m_statistics.m_runtimeSeconds, 'g', 3)); + hash.insert("bytes", QString::number(m_statistics.m_bytes)); + hash.insert("megabytes", + QString::number((double) m_statistics.m_bytes / 1000000)); + hash.insert("datetime", + QDateTime::currentDateTime().toLocalTime().toString("yyyy.MM.dd/hh:mm:ss")); +} + /** * Gets the content of the given cell as string. * @@ -280,7 +270,9 @@ QString replaceEscSequences(const QString& text){ } return rc; } - +/** + * Actions while closing the application. + */ void MainWindow::closing(){ saveState(); } @@ -674,6 +666,28 @@ void MainWindow::headerPlaceholder(){ handlePlaceholder(ui->comboBoxHeader); } + +/** + * initializeHomeializes the program home directory. + */ +void MainWindow::initializeHome(){ + if (m_homeDir.isEmpty()){ + m_homeDir = QDir::home().absoluteFilePath(".refind"); + } + + QDir home(m_homeDir); + if (!home.exists()){ + if (!home.mkpath(m_homeDir)){ + m_homeDir = home.tempPath() + "/.refind"; + home.mkpath(m_homeDir); + } + } + if (!m_homeDir.endsWith("/")) + m_homeDir += "/"; + m_storageFile = m_homeDir + "state.conf"; + restoreState(); +} + /** * Informs the instance about some state changes. * @@ -685,6 +699,59 @@ ReObserver::ReturnCode MainWindow::notify(const char* message) return ReObserver::SUCCESS; } +/** + * Starts the options dialog. + */ +void MainWindow::options(){ + DialogOptions dialog(m_contextHandlers, NULL); + dialog.exec(); +} + + +/** + * Sets the properties of the file finder. + * + * @param finder OUT: the finder to populate + */ +void MainWindow::populateFinder(FileFinder& finder){ + if (! ui->checkBoxAppend->isChecked()){ + ui->tableWidget->setRowCount(0); + m_statistics.clear(); + } + finder.setObserver(this); + finder.setGuiQueue(&this->m_guiQueue); + finder.setBaseDir(comboText(ui->comboBoxDirectory)); + finder.setTable(ui->tableWidget); + m_lastBaseDir.cd(comboText(ui->comboBoxDirectory)); + finder.setMaxSize(comboSize(ui->comboBoxMaxSize)); + finder.setMinSize(comboSize(ui->comboBoxMinSize)); + finder.setOlderThan(comboDate(ui->comboBoxOlder)); + finder.setYoungerThan(comboDate(ui->comboBoxYounger)); + finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0)); + finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1)); + finder.setMaxHits(comboInt(ui->comboBoxMaxHits, 0x7fffffff)); + finder.setFiletypes(buildFileTypes()); + QStringList patterns; + QString value = comboText(ui->comboBoxFilePatterns); + if (!value.isEmpty()) + patterns = value.split(","); + finder.setPatterns(patterns); + value = comboText(ui->comboBoxExcludedDirs); + if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0) + guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed")); + else if (value.indexOf('*') >= 0) + guiError(ui->comboBoxExcludedDirs, + tr("no patterns allowed. Do not use '*")); + else if (!value.isEmpty()) + patterns = value.split(","); + finder.setExcludedDirs(patterns); + if (m_errors == 0){ + prepareTextFind(); + if (!comboText(ui->comboBoxTextPattern).isEmpty()) + finder.setTextFinder(&m_textFinder); + } +} + /** * Prepares the context menu of the result table. * @@ -724,25 +791,6 @@ msgBox.setDefaultButton(QMessageBox::Save); msgBox.exec(); } -/** - * Builds the hash with the global placeholders with their current values. - * - * @param hash IN/OUT: the placeholders will be appended here - */ -void MainWindow::buildGlobalPlaceholders(QMap & hash){ - - hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText()); - hash.insert("base", m_lastBaseDir.absolutePath()); - hash.insert("textpattern", addEsc(ui->comboBoxTextPattern->currentText())); - hash.insert("dirs", QString::number(m_statistics.m_dirs)); - hash.insert("files", QString::number(m_statistics.m_files)); - hash.insert("runtime", QString::number(m_statistics.m_runtimeSeconds, 'g', 3)); - hash.insert("bytes", QString::number(m_statistics.m_bytes)); - hash.insert("megabytes", - QString::number((double) m_statistics.m_bytes / 1000000)); - hash.insert("datetime", - QDateTime::currentDateTime().toLocalTime().toString("yyyy.MM.dd/hh:mm:ss")); -} /** * Replaces the placeholders valid in header and footer. * @@ -828,50 +876,6 @@ m_contextHandlers.save(storage); storage.close(); } -/** - * Sets the properties of the file finder. - * - * @param finder OUT: the finder to populate - */ -void MainWindow::populateFinder(FileFinder& finder){ - if (! ui->checkBoxAppend->isChecked()){ - ui->tableWidget->setRowCount(0); - m_statistics.clear(); - } - finder.setObserver(this); - finder.setGuiQueue(&this->m_guiQueue); - finder.setBaseDir(comboText(ui->comboBoxDirectory)); - finder.setTable(ui->tableWidget); - m_lastBaseDir.cd(comboText(ui->comboBoxDirectory)); - finder.setMaxSize(comboSize(ui->comboBoxMaxSize)); - finder.setMinSize(comboSize(ui->comboBoxMinSize)); - finder.setOlderThan(comboDate(ui->comboBoxOlder)); - finder.setYoungerThan(comboDate(ui->comboBoxYounger)); - finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0)); - finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1)); - finder.setMaxHits(comboInt(ui->comboBoxMaxHits, 0x7fffffff)); - finder.setFiletypes(buildFileTypes()); - QStringList patterns; - QString value = comboText(ui->comboBoxFilePatterns); - if (!value.isEmpty()) - patterns = value.split(","); - finder.setPatterns(patterns); - value = comboText(ui->comboBoxExcludedDirs); - if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0) - guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed")); - else if (value.indexOf('*') >= 0) - guiError(ui->comboBoxExcludedDirs, - tr("no patterns allowed. Do not use '*")); - else if (!value.isEmpty()) - patterns = value.split(","); - finder.setExcludedDirs(patterns); - if (m_errors == 0){ - prepareTextFind(); - if (!comboText(ui->comboBoxTextPattern).isEmpty()) - finder.setTextFinder(&m_textFinder); - } -} - /** * Handles the "search" button. */ @@ -943,7 +947,7 @@ bool MainWindow::say(ReLoggerLevel level, const QString& message){ * @param start true: the search should start */ void MainWindow::startStop(bool start){ - ui->actionStart->setEnabled(!start); + ui->actionStart->setEnabled(!start); ui->actionStop->setEnabled(start); ui->pushButtonSearch->setEnabled(! start); ui->pushButtonSearch2->setEnabled(! start); @@ -955,7 +959,7 @@ void MainWindow::startStop(bool start){ * Handles the "search" button. */ void MainWindow::stop(){ - m_finder->setStop(true); + m_finder->setStop(true); startStop(false); } diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index f29f983..c94ce6f 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -54,8 +54,8 @@ private slots: void about(); void absPathToClipboard(); void baseDirToClipboard(); - void closing(); void clear(); + void closing(); void exportFiles(); void filePlaceholder(); void footerPlaceholder(); diff --git a/appl/reimgconvert/converter.cpp b/appl/reimgconvert/converter.cpp index 6e1b4d1..0eb8c5f 100644 --- a/appl/reimgconvert/converter.cpp +++ b/appl/reimgconvert/converter.cpp @@ -14,7 +14,7 @@ #include "converter.hpp" #include "mainwindow.hpp" #include -#include +#include /** @file * @@ -112,6 +112,9 @@ QString sizeToString(qint64 size); * @param targetDirectory the target directory * @param sourcePattern the pattern for the files to process * @param targetType the target image type + * @param simpleConversion true: same limits for landscape/portrait/square + * @param maxWidth maximal width (only uses in simple mode) + * @param maxHeight maximal height (only uses in simple mode) * @param landscapeX 0 or the given maximal width for landscape format * @param landscapeY 0 or the given maximal height for landscape format * @param portraitX 0 or the given maximal width for portrait format @@ -122,7 +125,8 @@ QString sizeToString(qint64 size); * @param mainWindow the window. Will be used for output */ Converter::Converter(const QString& directory, const QString& targetDirectory, - const QString& sourcePattern, const QString& targetType, int landscapeX, + const QString& sourcePattern, const QString& targetType, + bool simpleConversion, int maxWidth, int maxHeight, int landscapeX, int landscapeY, int portraitX, int portraitY, int squareX, int quality, MainWindow* mainWindow) : m_dir(directory), @@ -143,7 +147,11 @@ Converter::Converter(const QString& directory, const QString& targetDirectory, m_imageInfo( new QRegularExpression(" (PNG|GIF|JPEG) (\\d+)x(\\d+) ")), m_groupWidth(2), - m_groupHeight(3){ + m_groupHeight(3), + m_simpleMode(simpleConversion), + m_maxWidth(maxWidth), + m_maxHeight(maxHeight) + { } /** @@ -210,6 +218,76 @@ void Converter::convert(const QString& source, const QString& target, int width, process.close(); } +/** + * Converts an image with a given maximal width and size. + * + * @param width the width of the image + * @param height the height of the image + * @param widthNew OUT: the width of the converted image + * @param heightNew OUT: the height of the converted image + * @return true: the image needs to be converted + */ +bool Converter::handleSimple(int width, int height, int& widthNew, int& heightNew) +{ + bool doConvert = false; + if (width > m_maxWidth){ + doConvert = true; + widthNew = m_maxWidth; + heightNew = roundInt((double) height * widthNew / width); + if (heightNew > m_maxHeight){ + heightNew = m_maxHeight; + widthNew = roundInt((double) width * heightNew / height); + } + } else if (height > m_maxHeight){ + heightNew = m_maxHeight; + widthNew = roundInt((double) width * heightNew / height); + } + return doConvert; +} +/** + * Converts an image with a given maximal width and size. + * + * @param width the width of the image + * @param height the height of the image + * @param widthNew OUT: the width of the converted image + * @param heightNew OUT: the height of the converted image + * @return true: the image needs to be converted + */ +bool Converter::handleUserDefined(int width, int height, int& widthNew, int& heightNew){ + bool doConvert = false; + if (abs(width - height) < 5){ + // Square format: + doConvert = width > m_squareWidth; + if (doConvert) + widthNew = heightNew = m_squareWidth; + }else if (width > height){ + // Landscape: + doConvert = width > m_landscapeWidth || height > m_landscapeHeight; + if (doConvert){ + if (width > m_landscapeWidth && m_landscapeWidth > 0){ + widthNew = m_landscapeWidth; + heightNew = height * m_landscapeWidth / width; + }else{ + heightNew = m_landscapeHeight; + widthNew = width * m_landscapeHeight / height; + } + } + }else{ + // Portrait + doConvert = width > m_portraitWidth || height > m_portraitHeight; + if (doConvert){ + if (width > m_portraitWidth && m_portraitWidth > 0){ + widthNew = m_portraitWidth; + heightNew = height * m_portraitWidth / width; + }else{ + heightNew = m_portraitHeight; + widthNew = width * m_portraitHeight / height; + } + } + } + return doConvert; +} + /** * @brief Converts one file. * @@ -224,38 +302,13 @@ void Converter::convertOneFile(const QString& source, const QString& target, QString info; clock_t start = clock(); if (readProperties(source, width, height, info)){ - bool doConvert = false; - int widthNew, heightNew; - if (abs(width - height) < 5){ - // Square format: - doConvert = width > m_squareWidth; - if (doConvert) - widthNew = heightNew = m_squareWidth; - }else if (width > height){ - // Landscape: - doConvert = width > m_landscapeWidth || height > m_landscapeHeight; - if (doConvert){ - if (width > m_landscapeWidth && m_landscapeWidth > 0){ - widthNew = m_landscapeWidth; - heightNew = height * m_landscapeWidth / width; - }else{ - heightNew = m_landscapeHeight; - widthNew = width * m_landscapeHeight / height; - } - } - }else{ - // Portrait - doConvert = width > m_portraitWidth || height > m_portraitHeight; - if (doConvert){ - if (width > m_portraitWidth && m_portraitWidth > 0){ - widthNew = m_portraitWidth; - heightNew = height * m_portraitWidth / width; - }else{ - heightNew = m_portraitHeight; - widthNew = width * m_portraitHeight / height; - } - } - } + int widthNew = width; + int heightNew = height; + bool doConvert; + if (m_simpleMode) + doConvert = handleSimple(width, height, widthNew, heightNew); + else + doConvert = handleUserDefined(width, height, widthNew, heightNew); log( source + " " + info + " " + sizeToString(size) + QString(" -> %1x%2 ").arg(widthNew).arg(heightNew)); @@ -266,7 +319,7 @@ void Converter::convertOneFile(const QString& source, const QString& target, } m_mainWindows->logAppendLast( QString("").sprintf("%.3f sec", - double(clock() - start) / CLOCKS_PER_SEC)); + double(clock() - start) / CLOCKS_PER_SEC)); } /** @@ -295,7 +348,7 @@ bool Converter::log(const QString& message){ } /** - * Reads the image properties using the external program "identify". + * Reads the image properties. * * @param name the filename with path * @param width OUT: the width of the image @@ -305,6 +358,29 @@ bool Converter::log(const QString& message){ * false: properties not readable */ bool Converter::readProperties(const QString& name, int& width, int& height, + QString& info){ + QPixmap image(name); + + width = image.width(); + height = image.height(); + bool rc = width != 0 && height != 0; + if (! rc) + error(tr("unknown format in ") + name); + info = QString("%1x%2").arg(width).arg(height); + return rc; +} + +/** + * Reads the image properties using the external program "identify". + * + * @param name the filename with path + * @param width OUT: the width of the image + * @param height OUT: the height of the image + * @param info OUT: an info about the image + * @return true: success + * false: properties not readable + */ +bool Converter::readPropertiesByIdentify(const QString& name, int& width, int& height, QString& info){ QStringList args; args << name; diff --git a/appl/reimgconvert/converter.hpp b/appl/reimgconvert/converter.hpp index c8c4b8d..c0585d8 100644 --- a/appl/reimgconvert/converter.hpp +++ b/appl/reimgconvert/converter.hpp @@ -23,10 +23,10 @@ class MainWindow; class ConverterException { public: ConverterException(const QString& message) : - m_message(message){ + m_message(message){ } const QString& message() const{ - return m_message; + return m_message; } private: @@ -43,30 +43,35 @@ class Converter: public QThread { Q_OBJECT public: enum State { - STATE_UNDEF, STATE_STARTING, STATE_SUB_TASK_STOPPED, STATE_READY, + STATE_UNDEF, STATE_STARTING, STATE_SUB_TASK_STOPPED, STATE_READY, }; public: Converter(const QString& directory, const QString& targetDirectory, - const QString& sourcePattern, const QString& targetType, int landscapeX, - int landscapey, int portraitX, int portraitY, int squareX, int quality, - MainWindow* mainWindows); + const QString& sourcePattern, const QString& targetType, + bool simpleConversion, int maxWidth, int maxHeight, int landscapeX, + int landscapeY, int portraitX, int portraitY, int squareX, int quality, + MainWindow* mainWindows); ~Converter(); public: bool error(const QString& message); bool log(const QString& message); void run(); void stop(){ - m_shouldStop = true; + m_shouldStop = true; } protected: bool buildArgs(); void changeState(State state, const QString& info); void convert(const QString& source, const QString& target, int width, - int height, int widthNew, int heightNew, int quality); + int height, int widthNew, int heightNew, int quality); void convertOneFile(const QString& source, const QString& target, - qint64 size); + qint64 size); + bool handleSimple(int width, int height, int& widthNew, int& heightNew); + bool handleUserDefined(int width, int height, int& widthNew, int& heightNew); bool readProperties(const QString& name, int &width, int &height, - QString &info); + QString &info); + bool readPropertiesByIdentify(const QString& name, int &width, int &height, + QString &info); private: QDir m_dir; QDir m_targetDir; @@ -83,6 +88,9 @@ private: QRegularExpression* m_imageInfo; int m_groupWidth; int m_groupHeight; + bool m_simpleMode; + int m_maxWidth; + int m_maxHeight; }; #endif // CONVERTER_HPP diff --git a/appl/reimgconvert/main.cpp b/appl/reimgconvert/main.cpp index e70992e..051c685 100644 --- a/appl/reimgconvert/main.cpp +++ b/appl/reimgconvert/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]){ QString homeDir = argc > 1 ? argv[1] : ""; QApplication a(argc, argv); MainWindow w(homeDir); - w.show(); - - return a.exec(); + QObject::connect(&a, SIGNAL(aboutToQuit()), &w, SLOT(closing())); + w.show(); + return a.exec(); } diff --git a/appl/reimgconvert/mainwindow.cpp b/appl/reimgconvert/mainwindow.cpp index 3ba3947..c258dda 100644 --- a/appl/reimgconvert/mainwindow.cpp +++ b/appl/reimgconvert/mainwindow.cpp @@ -15,7 +15,7 @@ #include "ui_mainwindow.h" #include "aboutdialog.hpp" -const QString VERSION("2015.05.31"); +const QString VERSION("2016.01.15"); /** @class MainWindow mainwindow.hpp "mainwindow.hpp" * @@ -40,22 +40,26 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : m_logger(), m_guiQueue(), m_guiTimer(new QTimer(this)){ - - ui->setupUi(this); - initializeHome(); - startStop(true); + ui->setupUi(this); + initializeHome(); + m_logger.buildStandardAppender(I18N::s2b(m_homeDir + OS_SEPARATOR_STR + + "reimgconvert").constData()); + startStop(false); m_statusMessage = new QLabel(tr("Welcome at reimgconvert")); statusBar()->addWidget(m_statusMessage); - connect(ui->actionSelectDestination, SIGNAL(triggered()), this, - SLOT(selectDestination())); + connect(ui->actionSelectTarget, SIGNAL(triggered()), this, + SLOT(selectTarget())); + connect(ui->actionClear, SIGNAL(triggered()), this, SLOT(clear())); + connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(clear())); + connect(ui->actionSelectTarget, SIGNAL(triggered()), this, + SLOT(selectTarget())); connect(ui->pushButtonSelectDest, SIGNAL(clicked()), this, - SLOT(selectDestination())); + SLOT(selectTarget())); connect(ui->actionSelectSource, SIGNAL(triggered()), this, SLOT(selectSource())); - connect(ui->pushButtonSelectDest, SIGNAL(clicked()), this, - SLOT(selectDestination())); + connect(ui->pushButtonSelectSource, SIGNAL(clicked()), this, + SLOT(selectSource())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); - restoreState(); connect(ui->comboBoxTemplate, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(on_templateChangeIndex(const QString&))); connect(ui->pushButtonActivate, SIGNAL(clicked()), this, SLOT(activate())); @@ -73,64 +77,51 @@ MainWindow::~MainWindow(){ } /** - * Slot when the pushbutton "activate" is clicked. + * Starts the about dialog. */ -void MainWindow::activate(){ - int width = comboInt(ui->comboBoxMaxWidth, 0); - int height = comboInt(ui->comboBoxMaxHeight, 0); - setMaxDimensions(width, height); +void MainWindow::about(){ + AboutDialog dialog(VERSION); + dialog.exec(); } /** - * Sets the maximal dimensions (from the "simple" interface). - * - * @param maxWidth the maximal width - * @param maxHeight the maximal height + * Slot when the pushbutton "activate" is clicked. */ -void MainWindow::setMaxDimensions(int maxWidth, int maxHeight){ - if (maxWidth > maxHeight){ - ui->comboBoxLandscapeX->setCurrentText(QString::number(maxWidth)); - ui->comboBoxLandscapeY->setCurrentText("*"); - ui->comboBoxPortraitX->setCurrentText("*"); - ui->comboBoxPortraitY->setCurrentText(QString::number(maxHeight)); - ui->comboBoxSquareX->setCurrentText(QString::number(maxHeight)); - }else{ - ui->comboBoxLandscapeY->setCurrentText(QString::number(maxHeight)); - ui->comboBoxLandscapeX->setCurrentText("*"); - ui->comboBoxPortraitY->setCurrentText("*"); - ui->comboBoxPortraitX->setCurrentText(QString::number(maxWidth)); - ui->comboBoxSquareX->setCurrentText(QString::number(maxWidth)); - } +void MainWindow::activate(){ + QString theTemplate = comboText(ui->comboBoxTemplate); + QRegularExpression rexpr("(\\d+)x(\\d+)"); + QRegularExpressionMatch matcher = rexpr.match(theTemplate); + if (matcher.hasMatch()){ + int width = atoi(matcher.captured(1).toLatin1()); + int height = atoi(matcher.captured(2).toLatin1()); + setMaxDimensions(width, height); + } } /** - * Selects the destination directory with a dialog. + * Clears the table. */ -void MainWindow::selectDestination(){ - QString dir = QFileDialog::getExistingDirectory(this, - tr("Select Destination Directory"), ui->comboBoxTarget->currentText(), - QFileDialog::ShowDirsOnly); - if (!dir.isEmpty()) - ui->comboBoxTarget->setCurrentText(dir); +void MainWindow::clear() +{ + ui->listWidget->clear(); } /** - * Selects the destination directory with a dialog. + * Actions while closing the application. */ -void MainWindow::selectSource(){ - QString dir = QFileDialog::getExistingDirectory(this, - tr("Select Source Directory"), ui->comboBoxSourceDir->currentText(), - QFileDialog::ShowDirsOnly); - if (!dir.isEmpty()) - ui->comboBoxSourceDir->setCurrentText(dir); +void MainWindow::closing(){ + saveState(); } /** - * Starts the about dialog. + * Issues an error message. + * + * @param message the message to issue + * @return false */ -void MainWindow::about(){ - AboutDialog dialog(VERSION); - dialog.exec(); +bool MainWindow::error(const QString& message){ + log("+++ " + message); + return false; } /** @@ -182,7 +173,34 @@ void MainWindow::initializeHome(){ if (!m_homeDir.endsWith("/")) m_homeDir += "/"; m_storageFile = m_homeDir + "state.conf"; - restoreState(); +} + + +/** + * @brief Logs a message + * + * @param message the message to log + * @return true + */ +bool MainWindow::log(const QString& message){ + ui->listWidget->addItem(message); + ui->listWidget->setCurrentRow(ui->listWidget->count() - 1); + return true; +} + +/** + * @brief Logs a message + * + * Note: used by non main threads + * + * @param message the message to log + * @return true + */ +bool MainWindow::logAppendLast(const QString& message){ + m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListEnd, ui->listWidget, message)); + QListWidgetItem* item = ui->listWidget->item(0); + item->setText(item->text() + " " + message); + return true; } /** @@ -190,8 +208,6 @@ void MainWindow::initializeHome(){ */ void MainWindow::on_pushButtonStop_clicked(){ m_converter->stop(); - ui->pushButtonConvert->show(); - ui->pushButtonStop->hide(); } /** @@ -235,12 +251,19 @@ void MainWindow::on_pushButtonConvert_clicked(){ int portraitX = comboInt(ui->comboBoxPortraitX, 0, "*", 0); int portraitY = comboInt(ui->comboBoxPortraitY, 0, "*", 0); int squareX = comboInt(ui->comboBoxSquareX, 0); - int quality = comboInt(ui->comboBoxQuality, 70); + int quality = comboInt(ui->comboBoxQuality, 75); + int maxWidth = comboInt(ui->comboBoxMaxWidth, 0); + int maxHeight = comboInt(ui->comboBoxMaxHeight, 0); + QRegularExpressionMatch match = QRegularExpression("\\dx\\d").match( + ui->comboBoxTemplate->currentText()); + bool simpleConversion = match.hasMatch(); if (m_errors == 0){ m_converter = new Converter(ui->comboBoxSourceDir->currentText(), ui->comboBoxLandscapeX->currentText(), ui->comboBoxSourcePattern->currentText(), - ui->comboBoxDestType->currentText(), landscapeX, landscapeY, portraitX, + ui->comboBoxDestType->currentText(), + simpleConversion, maxWidth, maxHeight, + landscapeX, landscapeY, portraitX, portraitY, squareX, quality, this); // start the thread: m_converter->start(); @@ -260,7 +283,6 @@ void MainWindow::on_threadStateChanged(Converter::State state, const QString& in switch (state) { case Converter::STATE_READY: m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, info)); - ui->pushButtonStop->hide(); //ui->statusBar->showMessage(info); break; case Converter::STATE_SUB_TASK_STOPPED: @@ -271,37 +293,11 @@ void MainWindow::on_threadStateChanged(Converter::State state, const QString& in break; } } - -/** - * @brief Logs a message - * - * @param message the message to log - * @return true - */ -bool MainWindow::log(const QString& message){ - ui->listWidget->insertItem(0, message); - return true; -} - -/** - * @brief Logs a message - * - * Note: used by non main threads - * - * @param message the message to log - * @return true - */ -bool MainWindow::logAppendLast(const QString& message){ - m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListEnd, ui->listWidget, message)); - QListWidgetItem* item = ui->listWidget->item(0); - item->setText(item->text() + " " + message); - return true; -} - /** * Reads the history of the widget values and other parameters and set it. */ void MainWindow::restoreState(){ + log(tr("Reading data from ") + m_storageFile); ReStateStorage storage(m_storageFile, &m_logger); storage.setForm("main"); storage.restore(ui->comboBoxMaxHeight, "comboBoxMaxHeight", true); @@ -314,7 +310,9 @@ void MainWindow::restoreState(){ storage.restore(ui->comboBoxQuality, "comboBoxQuality", true); storage.restore(ui->comboBoxSourceDir, "comboBoxSourceDir", true); storage.restore(ui->comboBoxSquareX, "comboBoxSquareX", true); - storage.restore(ui->comboBoxTarget, "comboBoxTarget", true); + storage.restore(ui->comboBoxTargetDir, "comboBoxTargetDir", true); + storage.restore(ui->comboBoxDestType, "comboBoxDestType", true); + storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true); storage.close(); } @@ -334,10 +332,75 @@ void MainWindow::saveState(){ storage.store(ui->comboBoxQuality, "comboBoxQuality"); storage.store(ui->comboBoxSourceDir, "comboBoxSourceDir"); storage.store(ui->comboBoxSquareX, "comboBoxSquareX"); - storage.store(ui->comboBoxTarget, "comboBoxTarget"); + storage.store(ui->comboBoxTargetDir, "comboBoxTargetDir"); + storage.store(ui->comboBoxDestType, "comboBoxDestType"); + storage.store(ui->comboBoxTemplate, "comboBoxTemplate"); storage.close(); } + +/** + * Issues a message. + * + * @param level type of the message + * @param message message to issue + * @return level == LOG_ERROR + */ +bool MainWindow::say(ReLoggerLevel level, const QString& message) +{ + if (level == LOG_ERROR || level == LOG_WARNING) + error(message); + else + log(message); + return level == LOG_ERROR; +} + +/** + * Selects the destination directory with a dialog. + */ +void MainWindow::selectSource(){ + QString dir = QFileDialog::getExistingDirectory(this, + tr("Select Source Directory"), ui->comboBoxSourceDir->currentText(), + QFileDialog::ShowDirsOnly); + if (!dir.isEmpty()) + ui->comboBoxSourceDir->setCurrentText(dir); +} + +/** + * Sets the maximal dimensions (from the "simple" interface). + * + * @param maxWidth the maximal width + * @param maxHeight the maximal height + */ +void MainWindow::setMaxDimensions(int maxWidth, int maxHeight){ + if (maxWidth > maxHeight){ + ui->comboBoxLandscapeX->setCurrentText(QString::number(maxWidth)); + ui->comboBoxLandscapeY->setCurrentText("*"); + ui->comboBoxPortraitX->setCurrentText("*"); + ui->comboBoxPortraitY->setCurrentText(QString::number(maxHeight)); + ui->comboBoxSquareX->setCurrentText(QString::number(maxHeight)); + }else{ + ui->comboBoxLandscapeY->setCurrentText(QString::number(maxHeight)); + ui->comboBoxLandscapeX->setCurrentText("*"); + ui->comboBoxPortraitY->setCurrentText("*"); + ui->comboBoxPortraitX->setCurrentText(QString::number(maxWidth)); + ui->comboBoxSquareX->setCurrentText(QString::number(maxWidth)); + } + ui->comboBoxMaxWidth->setCurrentText(QString::number(maxWidth)); + ui->comboBoxMaxHeight->setCurrentText(QString::number(maxHeight)); +} + +/** + * Selects the destination directory with a dialog. + */ +void MainWindow::selectTarget(){ + QString dir = QFileDialog::getExistingDirectory(this, + tr("Select Destination Directory"), ui->comboBoxTargetDir->currentText(), + QFileDialog::ShowDirsOnly); + if (!dir.isEmpty()) + ui->comboBoxTargetDir->setCurrentText(dir); +} + /** * Writes a text to the status line. * @@ -345,6 +408,7 @@ void MainWindow::saveState(){ * @param message the text to set */ void MainWindow::setStatusMessage(bool error, const QString& message){ + RE_UNUSED(error); m_statusMessage->setText(message); } @@ -360,19 +424,3 @@ void MainWindow::startStop(bool isStart){ ui->pushButtonStop->setEnabled(isStart); } -/** - * Issues a message. - * - * @param level type of the message - * @param message message to issue - * @return level == LOG_ERROR - */ -bool MainWindow::say(ReLoggerLevel level, const QString& message) -{ - if (level == LOG_ERROR || level == LOG_WARNING) - error(message); - else - log(message); - return level == LOG_ERROR; -} - diff --git a/appl/reimgconvert/mainwindow.hpp b/appl/reimgconvert/mainwindow.hpp index 980694a..cef44ba 100644 --- a/appl/reimgconvert/mainwindow.hpp +++ b/appl/reimgconvert/mainwindow.hpp @@ -32,16 +32,15 @@ public: explicit MainWindow(const QString& homeDir, QWidget *parent = 0); ~MainWindow(); +public slots: + void closing(); public: - bool error(const QString& message){ - log("+++ " + message); - return false; - } + bool error(const QString& message); bool log(const QString& message); bool logAppendLast(const QString& message); void on_threadStateChanged(Converter::State state, const QString& info); void setStatusMessage(bool error, const QString& message); - void switchRun(bool runActive); +public: virtual bool say(ReLoggerLevel level, const QString& message); private: void initializeHome(); @@ -52,13 +51,14 @@ private: private slots: void activate(); void about(); + void clear(); void guiTimerUpdate(); void on_pushButtonFileSelect_clicked(); void on_pushButtonStop_clicked(); void on_pushButtonConvert_clicked(); void on_templateChangeIndex(const QString& text); - void selectDestination(); void selectSource(); + void selectTarget(); private: QString m_homeDir; QString m_storageFile; diff --git a/appl/reimgconvert/mainwindow.ui b/appl/reimgconvert/mainwindow.ui index 1d46a60..5ed2f0c 100644 --- a/appl/reimgconvert/mainwindow.ui +++ b/appl/reimgconvert/mainwindow.ui @@ -105,6 +105,11 @@ Mini: 150x100 + + + User defined + + @@ -752,7 +757,7 @@ - + true @@ -803,7 +808,7 @@ - Alle Bilder aus dem Quellverzeichnis konvertieren und im Zielverzeichnis ablegen + Converts the images &Convert @@ -814,6 +819,32 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clears the list + + + C&lear + + + Ctrl+L + + + @@ -830,7 +861,7 @@ - false + true @@ -845,7 +876,7 @@ - Alle Bilder aus dem Quellverzeichnis konvertieren und im Zielverzeichnis ablegen + Stops the conversion &Stop @@ -885,11 +916,13 @@ + + - + - + @@ -922,7 +955,7 @@ false - + @@ -969,7 +1002,7 @@ Ctrl+O - + :/main/icons/folder_go.png:/main/icons/folder_go.png @@ -1032,6 +1065,17 @@ Ctrl+Shift+A + + + C&lear + + + Clears the list + + + Alt+L + +