From: hama Date: Sun, 26 Apr 2015 14:03:43 +0000 (+0200) Subject: placeholder dialogs, state storage works X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=ed121cfc9cfe70c9588b625d77f555db17eb3c1c;p=reqt placeholder dialogs, state storage works --- diff --git a/appl/refind/dialogfileplaceholder.cpp b/appl/refind/dialogfileplaceholder.cpp new file mode 100644 index 0000000..5ea4100 --- /dev/null +++ b/appl/refind/dialogfileplaceholder.cpp @@ -0,0 +1,40 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#include "dialogfileplaceholder.hpp" +#include "ui_dialogfileplaceholders.h" + +DialogFilePlaceholder::DialogFilePlaceholder(QWidget *parent) : + QDialog(parent), ui(new Ui::DialogFilePlaceHolders){ + ui->setupUi(this); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(ok())); +} + +DialogFilePlaceholder::~DialogFilePlaceholder(){ + delete ui; +} + +/** + * Handles the push of the OK button. + */ +void DialogFilePlaceholder::ok(){ + int row = ui->tableWidget->currentRow(); + if (row >= 0) + m_var = ui->tableWidget->item(row, COL_VAR)->text(); + close(); +} +/** + * Returns the selected placeholder. + * + * @return "": nothing selected
+ * otherwise: the name of the selected placeholder + */ +QString DialogFilePlaceholder::var() const{ + return m_var; +} + diff --git a/appl/refind/dialogfileplaceholder.hpp b/appl/refind/dialogfileplaceholder.hpp new file mode 100644 index 0000000..10c46e3 --- /dev/null +++ b/appl/refind/dialogfileplaceholder.hpp @@ -0,0 +1,37 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#ifndef DIALOGLINEPLACEHOLDERS_HPP +#define DIALOGLINEPLACEHOLDERS_HPP + +#include + +namespace Ui { +class DialogFilePlaceHolders; +} + +class DialogFilePlaceholder: public QDialog { + Q_OBJECT + +public: + enum { + COL_VAR, COL_EXAMPLE, COL_DESCR + }; +public: + explicit DialogFilePlaceholder(QWidget *parent = 0); + ~DialogFilePlaceholder(); +public: + QString var() const;public slots: + void ok(); + +private: + Ui::DialogFilePlaceHolders *ui; + QString m_var; +}; + +#endif // DIALOGLINEPLACEHOLDERS_HPP diff --git a/appl/refind/dialogfileplaceholder.ui b/appl/refind/dialogfileplaceholder.ui new file mode 100644 index 0000000..214be86 --- /dev/null +++ b/appl/refind/dialogfileplaceholder.ui @@ -0,0 +1,328 @@ + + + DialogFilePlaceHolders + + + + 0 + 0 + 800 + 429 + + + + File Specific Placeholders + + + true + + + + + 440 + 380 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 20 + 20 + 761 + 351 + + + + 190 + + + true + + + false + + + true + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + Placeholder + + + + + Example + + + + + Description + + + + + ${base} + + + + + /home/bob + + + + + base directory + + + + + ${full} + + + + + /home/bob/doc/intro.txt + + + + + filename with absolute path + + + + + ${path} + + + + + doc + + + + + relative path + + + + + ${node} + + + + + intro.txt + + + + + filename with extension + + + + + ${name} + + + + + intro + + + + + filename without extension + + + + + ${ext} + + + + + .txt + + + + + extension + + + + + ${modified} + + + + + 2015.04.03/08:07:14 + + + + + date/time of the last change + + + + + ${size} + + + + + 0.001223 + + + + + file length in megabyte + + + + + ${type} + + + + + file + + + + + 'file', 'dir', 'link (file)', 'link (dir)' + + + + + \t + + + + + \t + + + + + tabulator + + + + + \n + + + + + \n + + + + + newline + + + + + + + + buttonBox + accepted() + DialogFilePlaceHolders + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogFilePlaceHolders + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/appl/refind/dialogglobalplaceholder.cpp b/appl/refind/dialogglobalplaceholder.cpp new file mode 100644 index 0000000..a882081 --- /dev/null +++ b/appl/refind/dialogglobalplaceholder.cpp @@ -0,0 +1,41 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#include "dialogglobalplaceholder.hpp" +#include "ui_dialogglobalplaceholder.h" + +DialogGlobalPlaceholder::DialogGlobalPlaceholder(QWidget *parent) : + QDialog(parent), ui(new Ui::DialogGlobalPlaceholder), m_var(){ + ui->setupUi(this); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(ok())); +} + +DialogGlobalPlaceholder::~DialogGlobalPlaceholder(){ + delete ui; +} + +/** + * Handles the push of the OK button. + */ +void DialogGlobalPlaceholder::ok(){ + int row = ui->tableWidget->currentRow(); + if (row >= 0) + m_var = ui->tableWidget->item(row, COL_VAR)->text(); + close(); +} + +/** + * Returns the selected placeholder. + * + * @return "": nothing selected
+ * otherwise: the name of the selected placeholder + */ +QString DialogGlobalPlaceholder::var() const{ + return m_var; +} + diff --git a/appl/refind/dialogglobalplaceholder.hpp b/appl/refind/dialogglobalplaceholder.hpp new file mode 100644 index 0000000..03cbf00 --- /dev/null +++ b/appl/refind/dialogglobalplaceholder.hpp @@ -0,0 +1,38 @@ +/* + * Licence: + * You can use and modify this file without any restriction. + * There is no warranty. + * You also can use the licence from http://www.wtfpl.net/. + * The original sources can be found on https://github.com/republib. + */ + +#ifndef DIALOGGLOBALPLACEHOLDER_HPP +#define DIALOGGLOBALPLACEHOLDER_HPP + +#include + +namespace Ui { +class DialogGlobalPlaceholder; +} + +class DialogGlobalPlaceholder: public QDialog { + Q_OBJECT +public: + enum { + COL_VAR, COL_DESCR + }; + +public: + explicit DialogGlobalPlaceholder(QWidget *parent = 0); + ~DialogGlobalPlaceholder(); +public: + QString var() const; + +public slots: + void ok(); +private: + Ui::DialogGlobalPlaceholder *ui; + QString m_var; +}; + +#endif // DIALOGGLOBALPLACEHOLDER_HPP diff --git a/appl/refind/dialogglobalplaceholder.ui b/appl/refind/dialogglobalplaceholder.ui new file mode 100644 index 0000000..84d711c --- /dev/null +++ b/appl/refind/dialogglobalplaceholder.ui @@ -0,0 +1,283 @@ + + + DialogGlobalPlaceholder + + + + 0 + 0 + 583 + 470 + + + + Placeholders for Header and Footer + + + true + + + + + 220 + 420 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 20 + 20 + 541 + 391 + + + + 150 + + + true + + + false + + + true + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + New Row + + + + + Placeholder + + + + + Description + + + + + ${datetime} + + + + + current date/time + + + + + ${filepatterns} + + + + + current file patterns + + + + + ${textpattern} + + + + + current text pattern + + + + + ${dirs} + + + + + count of found directories + + + + + ${files} + + + + + count of found files + + + + + ${bytes} + + + + + sum of the lengths of the found files + + + + + ${megabytes} + + + + + sum of the lengths of the found files in MBytes + + + + + ${runtime} + + + + + runtime of the search in seconds + + + + + \n + + + + + newline (line feed) + + + + + \r + + + + + newline character (carriage return) + + + + + \t + + + + + tabulator + + + + + \\ + + + + + backslash + + + + + + + + buttonBox + accepted() + DialogGlobalPlaceholder + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogGlobalPlaceholder + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/appl/refind/main.cpp b/appl/refind/main.cpp index 3e01aff..d9e4218 100644 --- a/appl/refind/main.cpp +++ b/appl/refind/main.cpp @@ -15,9 +15,14 @@ #include "mainwindow.hpp" int main(int argc, char *argv[]){ - QApplication a(argc, argv); - MainWindow w(argc > 1 ? argv[1] : ""); + QApplication app(argc, argv); + QString startDir = argc > 1 ? argv[1] : ""; + QString homeDir = argc > 2 ? argv[2] : ""; + MainWindow w(startDir, homeDir); + + QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(closing())); + w.show(); - return a.exec(); + return app.exec(); } diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index 5887522..1de8f6a 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -18,6 +18,8 @@ #include "textfinder.hpp" #include "mainwindow.hpp" #include "ui_mainwindow.h" +#include "dialogfileplaceholder.hpp" +#include "dialogglobalplaceholder.hpp" #include "filefinder.hpp" #include "aboutdialog.hpp" @@ -26,7 +28,8 @@ * * @param parent NULL or the parent widget */ -MainWindow::MainWindow(const QString& startDir, QWidget *parent) : +MainWindow::MainWindow(const QString& startDir, const QString& homeDir, + QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_statusMessage(NULL), @@ -34,11 +37,16 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : m_textFinder(), m_lastBaseDir(), m_horizontalHeader(NULL), - m_lastOrder(Qt::DescendingOrder){ + m_lastOrder(Qt::DescendingOrder), + m_homeDir(), + m_storageFile(){ ui->setupUi(this); + initializeHome(); m_statusMessage = new QLabel(tr("Willkommen bei refind")); - ui->comboBoxDirectory->setCurrentText( - startDir.isEmpty() ? QDir::currentPath() : startDir); + if (!startDir.isEmpty()) + ui->comboBoxDirectory->setCurrentText(startDir); + if (ui->comboBoxDirectory->currentText().isEmpty()) + ui->comboBoxDirectory->setCurrentText(QDir::currentPath()); statusBar()->addWidget(m_statusMessage); connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search())); connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search())); @@ -47,6 +55,8 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up())); connect(ui->actionSelectDirectory, SIGNAL(triggered()), this, SLOT(selectDirectory())); + connect(ui->actionSaveProgramState, SIGNAL(triggered()), this, + SLOT(saveState())); connect(ui->pushButtonDirectory, SIGNAL(clicked()), this, SLOT(selectDirectory())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); @@ -62,6 +72,12 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : connect(ui->pushButtonExport, SIGNAL(clicked()), this, SLOT(exportFiles())); connect(ui->pushButtonExportFile, SIGNAL(clicked()), this, SLOT(selectExportFile())); + connect(ui->pushButtonFilePlaceholder, SIGNAL(clicked()), this, + SLOT(filePlaceholder())); + connect(ui->pushButtonHeaderPlaceholder, SIGNAL(clicked()), this, + SLOT(headerPlaceholder())); + connect(ui->pushButtonFooterPlaceholder, SIGNAL(clicked()), this, + SLOT(footerPlaceholder())); m_horizontalHeader = ui->tableWidget->horizontalHeader(); connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ), @@ -74,6 +90,27 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) : ui->tableWidget->horizontalHeader()->setStretchLastSection(true); } +/** + * 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(); +} + /** * Handles the event "header column clicked". * @@ -109,6 +146,25 @@ void MainWindow::about(){ dialog.exec(); } +/** + * Puts the absolute path of the current (selected) file into the clipboard. + */ +void MainWindow::absPathToClipboard(){ + int row = ui->tableWidget->currentRow(); + if (row >= 0){ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(buildAbsPath(row)); + } +} + +/** + * Puts the base directory into the clipboard. + */ +void MainWindow::baseDirToClipboard(){ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(m_lastBaseDir.absolutePath()); +} + /** * Gets the absolute path of the file in the given row. * @@ -124,22 +180,47 @@ QString MainWindow::buildAbsPath(int row){ } /** - * Puts the absolute path of the current (selected) file into the clipboard. + * Converts the checkbox states to a filetype mask. + * @return the filetypes selected by the checkboxes */ -void MainWindow::absPathToClipboard(){ - int row = ui->tableWidget->currentRow(); - if (row >= 0){ - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(buildAbsPath(row)); - } +QDir::Filters MainWindow::buildFileTypes(){ + QDir::Filters rc = 0; + if (ui->checkBoxDirs->isChecked()) + rc |= QDir::Dirs; + if (ui->checkBoxFiles->isChecked()) + rc |= QDir::Files; + if (rc == 0) + rc |= QDir::Dirs | QDir::Files; + if (!ui->checkBoxLinks->isChecked()) + rc |= QDir::NoSymLinks; + if (ui->checkBoxHidden) + rc |= QDir::Hidden | QDir::System; + QDir::Filters mask = 0; + if (ui->checkBoxWritable->isChecked()) + mask |= QDir::Writable; + if (ui->checkBoxReadable->isChecked()) + mask |= QDir::Readable; + if (ui->checkBoxExecutable->isChecked()) + mask |= QDir::Executable; + if (mask == 0) + mask |= QDir::PermissionMask; + rc |= mask; + return rc; } /** - * Puts the base directory into the clipboard. + * Gets the content of the given cell as string. + * + * @param row the row number: 0..R-1 + * @param col the column number: 0..C-1 + * @return the text of the given cell */ -void MainWindow::baseDirToClipboard(){ - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(m_lastBaseDir.absolutePath()); +QString MainWindow::cellAsText(int row, int col){ + QTableWidgetItem* widget = ui->tableWidget->item(row, col); + QString rc; + if (widget != NULL) + rc = widget->text(); + return rc; } /** @@ -178,50 +259,39 @@ QString replaceEscSequences(const QString& text){ return rc; } +void MainWindow::closing(){ + saveState(); +} + /** - * Replaces placeholders valid in header and footer. - * - * @param text the text to convert - * @return text with the esc sequences replaced + * Handles the click of the "export" button. */ -QString MainWindow::replaceGlobalPlaceholder(const QString& text){ - int start = 0; - QString replacement; - QString name; - QString rc = text; - while (start >= 0){ - start = rc.indexOf("${", start); - if (start < 0) - break; - int end = rc.indexOf('}', start + 1); - if (end < 0) - break; - name = rc.mid(start + 2, end - start - 2); - if (name == "filepatterns") - replacement = ui->comboBoxFilePatterns->currentText(); - else if (name == "base") - replacement = m_lastBaseDir.absolutePath(); - else if (name == "textpattern") - replacement = ui->comboBoxTextPattern->currentText(); - else if (name == "dirs") - replacement = QString::number(m_statistics.m_dirs); - else if (name == "files") - replacement = QString::number(m_statistics.m_files); - else if (name == "runtime") - replacement = QString::number(m_statistics.m_runtimeSeconds, 'g', 3); - else if (name == "bytes") - replacement = QString::number(m_statistics.m_bytes); - else if (name == "megabytes") - replacement = QString::number((double) m_statistics.m_bytes / 1000000); +void MainWindow::exportFiles(){ + comboText(ui->comboBoxHeader); + comboText(ui->comboBoxTemplate); + comboText(ui->comboBoxExportFile); + comboText(ui->comboBoxFooter); + if (ui->radioButtonFile->isChecked()){ + QString fn = ui->comboBoxExportFile->currentText(); + FILE* fp = fopen(fn.toUtf8(), "w"); + if (fp == NULL) + guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn); else{ - QString msg = tr("unknown placeholder: ") + name; - guiError(ui->comboBoxFooter, msg); - break; + QTextStream stream(fp); + exportToStream(stream); + fclose(fp); + setStatusMessage(false, tr("result exported to ") + fn); } - rc = rc.replace("${" + name + "}", replacement); - start += replacement.length(); + }else{ + QString value; + QTextStream stream(&value); + m_errors = 0; + exportToStream(stream); + QClipboard* clipboard = QApplication::clipboard(); + clipboard->setText(value); + if (m_errors == 0) + setStatusMessage(false, tr("result exported to the clipboard")); } - return replaceEscSequences(rc); } /** @@ -235,7 +305,7 @@ void MainWindow::exportToStream(QTextStream& stream, int maxRow){ stream << replaceGlobalPlaceholder(ui->comboBoxHeader->currentText()) << endl; } - int count = ui->tabWidget->count(); + int count = ui->tableWidget->rowCount(); if (count > 0 && maxRow > 0) count = maxRow; for (int ii = 0; ii < count; ii++){ @@ -284,49 +354,22 @@ void MainWindow::exportToStream(QTextStream& stream, int maxRow){ } /** - * Handles the click of the "export" button. + * Handles the push of "select file placeholder". */ -void MainWindow::exportFiles(){ - comboText(ui->comboBoxHeader); - comboText(ui->comboBoxTemplate); - comboText(ui->comboBoxExportFile); - comboText(ui->comboBoxFooter); - if (ui->radioButtonFile->isChecked()){ - QString fn = ui->comboBoxExportFile->currentText(); - FILE* fp = fopen(fn.toUtf8(), "w"); - if (fp == NULL) - guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn); - else{ - QTextStream stream(fp); - exportToStream(stream); - fclose(fp); - setStatusMessage(false, tr("result exported to ") + fn); - } - }else{ - QString value; - QTextStream stream(&value); - m_errors = 0; - exportToStream(stream); - QClipboard* clipboard = QApplication::clipboard(); - clipboard->setText(value); - if (m_errors == 0) - setStatusMessage(false, tr("result exported to the clipboard")); +void MainWindow::filePlaceholder(){ + DialogFilePlaceholder dialog; + dialog.exec(); + if (!dialog.var().isEmpty()){ + QComboBox* target = ui->comboBoxTemplate; + target->setCurrentText(target->currentText() + dialog.var()); } } /** - * Gets the content of the given cell as string. - * - * @param row the row number: 0..R-1 - * @param col the column number: 0..C-1 - * @return the text of the given cell + * Handles the push of "select placeholder for the footer". */ -QString MainWindow::cellAsText(int row, int col){ - QTableWidgetItem* widget = ui->tableWidget->item(row, col); - QString rc; - if (widget != NULL) - rc = widget->text(); - return rc; +void MainWindow::footerPlaceholder(){ + handlePlaceholder(ui->comboBoxFooter); } /** @@ -343,32 +386,22 @@ void MainWindow::fullNameToClipboard(){ } /** - * Converts the checkbox states to a filetype mask. - * @return the filetypes selected by the checkboxes + * Handles the global placeholder selection dialog. + * + * @param target OUT: the combobox where the result is appended */ -QDir::Filters MainWindow::buildFileTypes(){ - QDir::Filters rc = 0; - if (ui->checkBoxDirs->isChecked()) - rc |= QDir::Dirs; - if (ui->checkBoxFiles->isChecked()) - rc |= QDir::Files; - if (rc == 0) - rc |= QDir::Dirs | QDir::Files; - if (!ui->checkBoxLinks->isChecked()) - rc |= QDir::NoSymLinks; - if (ui->checkBoxHidden) - rc |= QDir::Hidden | QDir::System; - QDir::Filters mask = 0; - if (ui->checkBoxWritable->isChecked()) - mask |= QDir::Writable; - if (ui->checkBoxReadable->isChecked()) - mask |= QDir::Readable; - if (ui->checkBoxExecutable->isChecked()) - mask |= QDir::Executable; - if (mask == 0) - mask |= QDir::PermissionMask; - rc |= mask; - return rc; +void MainWindow::handlePlaceholder(QComboBox* target){ + DialogGlobalPlaceholder dialog; + dialog.exec(); + if (!dialog.var().isEmpty()) + target->setCurrentText(target->currentText() + dialog.var()); +} + +/** + * Handles the push of "select placeholder for the header". + */ +void MainWindow::headerPlaceholder(){ + handlePlaceholder(ui->comboBoxHeader); } /** @@ -384,6 +417,60 @@ void MainWindow::prepareTextFind(){ } } +/** + * Replaces placeholders valid in header and footer. + * + * @param text the text to convert + * @return text with the esc sequences replaced + */ +QString MainWindow::replaceGlobalPlaceholder(const QString& text){ + int start = 0; + QString replacement; + QString name; + QString rc = text; + while (start >= 0){ + start = rc.indexOf("${", start); + if (start < 0) + break; + int end = rc.indexOf('}', start + 1); + if (end < 0) + break; + name = rc.mid(start + 2, end - start - 2); + if (name == "filepatterns") + replacement = ui->comboBoxFilePatterns->currentText(); + else if (name == "base") + replacement = m_lastBaseDir.absolutePath(); + else if (name == "textpattern") + replacement = ui->comboBoxTextPattern->currentText(); + else if (name == "dirs") + replacement = QString::number(m_statistics.m_dirs); + else if (name == "files") + replacement = QString::number(m_statistics.m_files); + else if (name == "runtime") + replacement = QString::number(m_statistics.m_runtimeSeconds, 'g', 3); + else if (name == "bytes") + replacement = QString::number(m_statistics.m_bytes); + else if (name == "megabytes") + replacement = QString::number((double) m_statistics.m_bytes / 1000000); + else if (name == "datetime") + replacement = QDateTime::currentDateTime().toLocalTime().toString( + "yyyy.MM.dd/hh:mm:ss"); + else{ + QString msg = tr("unknown placeholder: ") + name; + guiError(ui->comboBoxFooter, msg); + break; + } + rc = rc.replace("${" + name + "}", replacement); + start += replacement.length(); + } + return replaceEscSequences(rc); +} + +/** + * @brief Handles the action "reset parameters". + * + * Most of the filter parameters will be set to the default. + */ void MainWindow::resetParameters(){ ui->comboBoxFilePatterns->setCurrentText(""); ui->comboBoxMaxDepth->setCurrentText(""); @@ -405,6 +492,52 @@ void MainWindow::resetParameters(){ ui->checkBoxExecutable->setChecked(true); } +/** + * Handles the push of the button "select directory". + */ +void MainWindow::restoreState(){ + ReStateStorage storage(m_storageFile); + storage.setForm("main"); + storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true); + storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true); + storage.restore(ui->comboBoxExportFile, "comboBoxExportFile", true); + storage.restore(ui->comboBoxFilePatterns, "comboBoxFilePatterns"); + storage.restore(ui->comboBoxFooter, "comboBoxFooter", true); + storage.restore(ui->comboBoxHeader, "comboBoxHeader", true); + storage.restore(ui->comboBoxMaxDepth, "comboBoxMaxDepth"); + storage.restore(ui->comboBoxMaxSize, "comboBoxMaxSize"); + storage.restore(ui->comboBoxMinDepth, "comboBoxMinDepth"); + storage.restore(ui->comboBoxMinSize, "comboBoxMinSize"); + storage.restore(ui->comboBoxOlder, "comboBoxOlder"); + storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true); + storage.restore(ui->comboBoxTextPattern, "comboBoxTextPattern"); + storage.restore(ui->comboBoxYounger, "comboBoxYounger"); + storage.close(); +} + +/** + * Handles the push of the button "select directory". + */ +void MainWindow::saveState(){ + ReStateStorage storage(m_storageFile); + storage.setForm("main"); + storage.store(ui->comboBoxDirectory, "comboBoxDirectory"); + storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs"); + storage.store(ui->comboBoxExportFile, "comboBoxExportFile"); + storage.store(ui->comboBoxFilePatterns, "comboBoxFilePatterns"); + storage.store(ui->comboBoxFooter, "comboBoxFooter"); + storage.store(ui->comboBoxHeader, "comboBoxHeader"); + storage.store(ui->comboBoxMaxDepth, "comboBoxMaxDepth"); + storage.store(ui->comboBoxMaxSize, "comboBoxMaxSize"); + storage.store(ui->comboBoxMinDepth, "comboBoxMinDepth"); + storage.store(ui->comboBoxMinSize, "comboBoxMinSize"); + storage.store(ui->comboBoxOlder, "comboBoxOlder"); + storage.store(ui->comboBoxTemplate, "comboBoxTemplate"); + storage.store(ui->comboBoxTextPattern, "comboBoxTextPattern"); + storage.store(ui->comboBoxYounger, "comboBoxYounger"); + storage.close(); +} + /** * Handles the "search" button. */ @@ -476,7 +609,7 @@ void MainWindow::selectDirectory(){ * Calls the file selection dialog. */ void MainWindow::selectExportFile(){ - QString name = QFileDialog::getOpenFileName(this, tr("Select Export File"), + QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"), ui->comboBoxExportFile->currentText()); if (!name.isEmpty()) ui->comboBoxExportFile->setCurrentText(name); diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index c28fc44..616c875 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -52,18 +52,24 @@ class MainWindow: public QMainWindow, public ReGuiValidator { Q_OBJECT public: - explicit MainWindow(const QString& startDir, QWidget *parent = 0); + explicit MainWindow(const QString& startDir, const QString& homeDir, + QWidget *parent = 0); ~MainWindow(); private slots: void about(); void absPathToClipboard(); void baseDirToClipboard(); + void closing(); void exportFiles(); + void filePlaceholder(); + void footerPlaceholder(); void fullNameToClipboard(); void headerClicked(int col); + void headerPlaceholder(); void preview(); void resetParameters(); + void saveState(); void search(); void selectDirectory(); void selectExportFile(); @@ -74,8 +80,11 @@ private: QDir::Filters buildFileTypes(); QString cellAsText(int row, int col); void exportToStream(QTextStream& stream, int maxRow = -1); + void handlePlaceholder(QComboBox* target); + void initializeHome(); void prepareTextFind(); QString replaceGlobalPlaceholder(const QString& text); + void restoreState(); virtual void setStatusMessage(bool error, const QString& message); private: Ui::MainWindow *ui; @@ -87,6 +96,8 @@ private: QHeaderView* m_horizontalHeader; Qt::SortOrder m_lastOrder; Statistics m_statistics; + QString m_homeDir; + QString m_storageFile; }; #endif // MAINWINDOW_HPP diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index e4e66b2..72fe81f 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -292,7 +292,7 @@ Execute the search - &Search + &Run search @@ -302,6 +302,12 @@ Ctrl+F + + true + + + true + @@ -350,7 +356,7 @@ Select directory by a dialog box - ... + @@ -605,7 +611,7 @@ - &Search + &Run search @@ -655,6 +661,9 @@ + + Template of a line for each file + true @@ -664,7 +673,7 @@ - + 50 @@ -672,7 +681,7 @@ - Placeholder for the template + Select a placeholder for the template ... @@ -722,6 +731,9 @@ + + Name of the export file + true @@ -796,16 +808,12 @@ - 300 + 16777215 16777215 - <html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li -<li>\t tabulator</li> -<li>\\ slash</li> -</ul></p> -</body></html> + Text at the top of the export file true @@ -815,11 +823,7 @@ - <html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li -<li>\t tabulator</li> -<li>\\ slash</li> -</ul></p> -</body></html> + Text at the end of the export file true @@ -829,6 +833,38 @@ + + + + + 50 + 16777215 + + + + Select a placeholder for the header + + + ... + + + + + + + + 50 + 16777215 + + + + Select a placeholder for the footer + + + ... + + + @@ -895,6 +931,7 @@ + @@ -978,6 +1015,7 @@ false + @@ -1001,13 +1039,13 @@ :/main/icons/action_go.png:/main/icons/action_go.png - &Search + &Run search Search the files with the given properties - Ctrl+F + Ctrl+R @@ -1082,7 +1120,7 @@ :/main/icons/table.gif:/main/icons/table.png - Get &full name + &full name to clipboard Ctrl+N @@ -1094,7 +1132,7 @@ :/main/icons/action_paste.png:/main/icons/action_paste.png - Get &base directory + &base directory to clipboard Puts the base directory into the clipboard @@ -1115,7 +1153,22 @@ Sets the file filter properties to the default - Ctrl+R + Ctrl+E + + + + + + :/main/icons/disk.png:/main/icons/disk.png + + + Sa&ve + + + Saves the program state (position, history...) to a file + + + Ctrl+S @@ -1124,18 +1177,19 @@ comboBoxDirectory pushButtonUp pushButtonDirectory + pushButtonSearch comboBoxFilePatterns checkBoxFiles checkBoxDirs checkBoxLinks checkBoxHidden checkBoxWritable + checkBoxReadable + checkBoxExecutable comboBoxTextPattern checkBoxTextIgnoreCase checkBoxRegExpr checkBoxBinaryFiles - pushButtonSearch - tableWidget comboBoxMinSize comboBoxMaxSize comboBoxYounger @@ -1143,6 +1197,20 @@ comboBoxMinDepth comboBoxMaxDepth comboBoxExcludedDirs + pushButtonSearch2 + comboBoxTemplate + pushButtonFilePlaceholder + comboBoxHeader + pushButtonHeaderPlaceholder + comboBoxExportFile + pushButtonExportFile + comboBoxFooter + pushButtonFooterPlaceholder + radioButtonFile + radioButtonClipboard + pushButtonExport + tabWidget + tableWidget diff --git a/appl/refind/refind.pro b/appl/refind/refind.pro index 130a549..d8f3901 100644 --- a/appl/refind/refind.pro +++ b/appl/refind/refind.pro @@ -22,7 +22,9 @@ SOURCES += main.cpp\ textfinder.cpp \ aboutdialog.cpp \ ../../gui/ReStateStorage.cpp \ - ../../gui/ReGuiValidator.cpp + ../../gui/ReGuiValidator.cpp \ + dialogglobalplaceholder.cpp \ + dialogfileplaceholder.cpp HEADERS += mainwindow.hpp \ @@ -33,11 +35,15 @@ HEADERS += mainwindow.hpp \ ../../gui/ReStateStorage.hpp \ aboutdialog.hpp \ ../../gui/ReGuiValidator.hpp \ - ../../gui/regui.hpp + ../../gui/regui.hpp \ + dialogglobalplaceholder.hpp \ + dialogfileplaceholder.hpp FORMS += mainwindow.ui \ - aboutdialog.ui + aboutdialog.ui \ + dialogglobalplaceholder.ui \ + dialogfileplaceholder.ui RESOURCES += \ refind.qrc diff --git a/base/ReQStringUtil.cpp b/base/ReQStringUtil.cpp index 7082523..edd3ddd 100644 --- a/base/ReQStringUtil.cpp +++ b/base/ReQStringUtil.cpp @@ -19,6 +19,23 @@ #include "base/rebase.hpp" #include #include + +/** + * Removes end of line characters if any. + * + * @param text text to inspect + * @return text without trailing '\n' and/or '\r' + */ +ReString ReQStringUtil::chomp(const ReString& text) +{ + int last = text.length() - 1; + while (last >= 0 && (text[last] == '\n' || text[last] == '\r')){ + last--; + } + return last == text.length() - 1 ? text : text.mid(0, last + 1); +} + + /** * @brief Determines the length and vlaue of an integer. * diff --git a/base/ReQStringUtil.hpp b/base/ReQStringUtil.hpp index b5573e7..e968926 100644 --- a/base/ReQStringUtil.hpp +++ b/base/ReQStringUtil.hpp @@ -14,6 +14,7 @@ class ReQStringUtil { public: + static ReString chomp(const ReString& text); static int lengthOfDate(const ReString& text, int start = 0, QDate* value = NULL); static int lengthOfDateTime(const ReString& text, int start = 0, diff --git a/gui/ReStateStorage.cpp b/gui/ReStateStorage.cpp index dde8322..9bec52e 100644 --- a/gui/ReStateStorage.cpp +++ b/gui/ReStateStorage.cpp @@ -25,13 +25,44 @@ ReStateStorage::ReStateStorage(const QString& filename) : * Destructor. */ ReStateStorage::~ReStateStorage(){ + close(); +} + +/** + * Closes open stream/file and frees the resources. + */ +void ReStateStorage::close(){ delete m_stream; + m_stream = NULL; if (m_fp != NULL){ fclose(m_fp); m_fp = NULL; } } +/** + * Initializes the instance for writing the storage information. + */ +bool ReStateStorage::initForRead(){ + if (m_fp == NULL) + m_fp = fopen(m_filename.toUtf8().constData(), "rb"); + if (m_fp != NULL && m_stream == NULL){ + m_stream = new QTextStream(m_fp, QIODevice::ReadOnly); + QString line; + m_map.clear(); + QString value; + while (!m_stream->atEnd()){ + line = m_stream->readLine(64 * 1024); + int ixAssignment = line.indexOf('='); + if (ixAssignment > 0){ + value = line.mid(ixAssignment + 1); + QString key = line.mid(0, ixAssignment); + m_map.insert(key, value); + } + } + } + return m_stream != NULL; +} /** * Initializes the instance for writing the storage information. */ @@ -39,7 +70,7 @@ bool ReStateStorage::initForWrite(){ if (m_fp == NULL) m_fp = fopen(m_filename.toUtf8().constData(), "wb"); if (m_fp != NULL) - m_stream = new QTextStream(m_fp, QIODevice::ReadOnly); + m_stream = new QTextStream(m_fp, QIODevice::ReadWrite); return m_stream != NULL; } /** @@ -51,6 +82,15 @@ QString ReStateStorage::form() const{ return m_form; } +/** + * Returns the full name of a widget. + * + * @param name the name of the widget + * @return
'.' or (if no form name is set) + */ +QString ReStateStorage::fullname(const QString& name){ + return m_form.isEmpty() ? name : m_form + "." + name; +} /** * Sets the name of the current form. * @@ -60,6 +100,35 @@ void ReStateStorage::setForm(const QString& form){ m_form = form; } +/** + * Restores the data of a combobox. + * + * @param combo the combobox to restore + * @param name the name of the combobox + * @param withCurrentText true: the current text will be set too + */ +void ReStateStorage::restore(QComboBox* combo, const QString& name, + bool withCurrentText){ + if (initForRead()){ + QString keyPrefix = fullname(name) + ".item"; + int ix = 0; + QString key; + while (true){ + key = keyPrefix + QString::number(ix); + if (!m_map.contains(key)) + break; + combo->addItem(m_map.value(key)); + ix++; + } + key = fullname(name) + ".text"; + if (!withCurrentText) + combo->setCurrentText(""); + else{ + if (m_map.contains(key)) + combo->setCurrentText(m_map.value(key)); + } + } +} /** * Stores the data of a combobox. * @@ -75,7 +144,7 @@ void ReStateStorage::store(const QComboBox* combo, const QString& name, fullname = m_form + "."; fullname += name; for (int ii = 0; ii < combo->count(); ii++){ - *m_stream << fullname << ".item:" << ii << "=" << combo->itemText(ii) + *m_stream << fullname << ".item" << ii << "=" << combo->itemText(ii) << endl; } if (withCurrentText){ diff --git a/gui/ReStateStorage.hpp b/gui/ReStateStorage.hpp index 9f3837b..3f3665c 100644 --- a/gui/ReStateStorage.hpp +++ b/gui/ReStateStorage.hpp @@ -20,10 +20,15 @@ public: ReStateStorage(const QString& filename); virtual ~ReStateStorage(); public: + void close(); QString form() const; + QString fullname(const QString& name); + bool initForRead(); bool initForWrite(); + void restore(QComboBox* combo, const QString& name, bool withCurrentText = + false); void store(const QComboBox* combo, const QString& name, - bool withCurrentText = false); + bool withCurrentText = true); void setForm(const QString& form); private: @@ -31,6 +36,7 @@ private: FILE* m_fp; QTextStream* m_stream; QString m_form; + QMap m_map; }; #endif /* GUI_RESTATESTORAGE_HPP_ */