From: hama Date: Sun, 3 May 2015 21:52:10 +0000 (+0200) Subject: Option dialog, context menu X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=2284e0f6834ee9205e2b481aed7b28a6e9812a4e;p=reqt Option dialog, context menu --- diff --git a/appl/refind/dialogfileplaceholder.ui b/appl/refind/dialogfileplaceholder.ui index 2b3dde1..f274a2a 100644 --- a/appl/refind/dialogfileplaceholder.ui +++ b/appl/refind/dialogfileplaceholder.ui @@ -16,279 +16,269 @@ 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 - - - + + + + + 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 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/appl/refind/dialogglobalplaceholder.ui b/appl/refind/dialogglobalplaceholder.ui index 070d4d1..a8bab09 100644 --- a/appl/refind/dialogglobalplaceholder.ui +++ b/appl/refind/dialogglobalplaceholder.ui @@ -16,234 +16,224 @@ 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} - + + + + + 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 + + + - - - current date/time - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - - ${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 - - - + diff --git a/appl/refind/dialogoptions.cpp b/appl/refind/dialogoptions.cpp new file mode 100644 index 0000000..b4bc9e3 --- /dev/null +++ b/appl/refind/dialogoptions.cpp @@ -0,0 +1,72 @@ +/* + * 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 "dialogoptions.hpp" +#include "ui_dialogoptions.h" + +DialogOptions::DialogOptions(ContextHandlerList& handlers, QWidget *parent) : + QDialog(parent), ui(new Ui::DialogOptions), m_contextHandlers(handlers){ + ui->setupUi(this); + fillTable(); +} + +DialogOptions::~DialogOptions(){ + delete ui; +} +/** + * Fills the table with the data from the list. + */ +void DialogOptions::fillTable(){ + int count = m_contextHandlers.list().size(); + ui->tableWidget->setRowCount(count); + QString value; + QList < QString > dirMode; + for (int row = 0; row < count; row++){ + ContextHandler* handler = m_contextHandlers.list().at(row); + ui->tableWidget->setItem(row, COL_TITLE, + new QTableWidgetItem(handler->m_text)); + ui->tableWidget->setItem(row, COL_PROGRAM, + new QTableWidgetItem(handler->m_program)); + ui->tableWidget->setItem(row, COL_ARGUMENTS, + new QTableWidgetItem(handler->m_arguments)); + value = ui->comboBoxFileType->itemText(handler->m_fileType - 1); + ui->tableWidget->setItem(row, COL_FILE_TYPE, new QTableWidgetItem(value)); + value = ui->comboBoxCurrentDirectory->itemText( + handler->m_directoryMode - 1); + ui->tableWidget->setItem(row, COL_CURRENT_DIR, + new QTableWidgetItem(value)); + } +} + +/** + * Fills the list from the data of the table. + */ +void DialogOptions::fromTable(){ + m_contextHandlers.clear(); + QList < QString > fileTypes; + for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++) + fileTypes.append(ui->comboBoxFileType->itemText(ix)); + for (int ix = 0; ix < ui->comboBoxCurrentDirectory->count(); ix++) + fileTypes.append(ui->comboBoxCurrentDirectory->itemText(ix)); + for (int row = 0; row < ui->tableWidget->rowCount(); row++){ + ContextHandler* handler = new ContextHandler; + handler->m_text = ui->tableWidget->item(row, COL_TITLE)->text(); + handler->m_program = ui->tableWidget->item(row, COL_PROGRAM)->text(); + handler->m_arguments = ui->tableWidget->item(row, COL_ARGUMENTS)->text(); + handler->m_fileType = ContextHandler::FileType( + 1 + + fileTypes.indexOf( + ui->comboBoxFileType->itemText(row, COL_FILE_TYPE)->text())); + handler->m_directoryMode = ContextHandler::DirMode( + 1 + + fileTypes.indexOf( + ui->comboBoxCurrentDirectory->itemText(row, COL_CURRENT_DIR))); + m_contextHandlers.list().append(handler); + } +} + diff --git a/appl/refind/dialogoptions.hpp b/appl/refind/dialogoptions.hpp new file mode 100644 index 0000000..8cd0d46 --- /dev/null +++ b/appl/refind/dialogoptions.hpp @@ -0,0 +1,32 @@ +/* + * 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 DIALOGOPTIONS_HPP +#define DIALOGOPTIONS_HPP +#include "utils.hpp" +#include + +namespace Ui { +class DialogOptions; +} + +class DialogOptions: public QDialog { + Q_OBJECT + +public: + explicit DialogOptions(ContextHandlerList& handlers, QWidget *parent = 0); + ~DialogOptions(); +private: + void fillTable(); + void fromTable(); +private: + Ui::DialogOptions *ui; + ContextHandlerList& m_contextHandlers; +}; + +#endif // DIALOGOPTIONS_HPP diff --git a/appl/refind/dialogoptions.ui b/appl/refind/dialogoptions.ui new file mode 100644 index 0000000..66e6dce --- /dev/null +++ b/appl/refind/dialogoptions.ui @@ -0,0 +1,410 @@ + + + DialogOptions + + + + 0 + 0 + 944 + 591 + + + + Dialog + + + + + + 0 + + + + Programs (Context Menu) + + + + + + + 850 + 0 + + + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::EditKeyPressed + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + 175 + + + true + + + false + + + + Neue Zeile + + + + + edit + + + + + File Type + + + + + Titel (Menu) + + + + + Program + + + + + Arguments + + + + + Current Directory + + + + + Editor + + + + + /usr/bin/kate + + + + + ${full} + + + + + + + + + + Shell + + + + + /usr/bin/bash + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Add + + + + + + + D&elete + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + &Up + + + + + + + &Down + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Current Entry + + + + + + File Type: + + + + + + + Title: + + + + + + + <html><head/><body><p>Program:</p></body></html> + + + + + + + Arguments: + + + + + + + Current Directory: + + + + + + + + 100 + 16777215 + + + + + File + + + + + Directory + + + + + Both + + + + + + + + + 100 + 16777215 + + + + + + + + + + true + + + + + + + + 50 + 16777215 + + + + ... + + + + :/main/icons/layout_add.png:/main/icons/layout_add.png + + + + + + + + + + 100 + 16777215 + + + + true + + + + ${full} + + + + + ${path} + + + + + ${node} + + + + + ${ext} + + + + + + + + + 150 + 16777215 + + + + + + + + + + + + Tab 2 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + + + + + buttonBox + accepted() + DialogOptions + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogOptions + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/appl/refind/filefinder.cpp b/appl/refind/filefinder.cpp index bc21de7..8a754b9 100644 --- a/appl/refind/filefinder.cpp +++ b/appl/refind/filefinder.cpp @@ -9,6 +9,7 @@ #include #include "base/rebase.hpp" #include "gui/regui.hpp" +#include "utils.hpp" #include "mainwindow.hpp" #include "filefinder.hpp" #include "textfinder.hpp" @@ -112,7 +113,7 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table, entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort); QList ::iterator it; QString relativePath = ReQStringUtil::nativePath( - path.mid(1 + m_baseDir.length())); + path.mid(1 + m_baseDir.length())); QString node, ext; for (it = entries.begin(); it != entries.end(); ++it){ diff --git a/appl/refind/icons/eye.png b/appl/refind/icons/eye.png new file mode 100644 index 0000000..564a1a9 Binary files /dev/null and b/appl/refind/icons/eye.png differ diff --git a/appl/refind/icons/paste_plain.png b/appl/refind/icons/paste_plain.png new file mode 100644 index 0000000..c0490eb Binary files /dev/null and b/appl/refind/icons/paste_plain.png differ diff --git a/appl/refind/icons/wrench.png b/appl/refind/icons/wrench.png new file mode 100644 index 0000000..5c8213f Binary files /dev/null and b/appl/refind/icons/wrench.png differ diff --git a/appl/refind/main.cpp b/appl/refind/main.cpp index d9e4218..60031bd 100644 --- a/appl/refind/main.cpp +++ b/appl/refind/main.cpp @@ -12,6 +12,7 @@ #include #include "base/rebase.hpp" #include "gui/regui.hpp" +#include "utils.hpp" #include "mainwindow.hpp" int main(int argc, char *argv[]){ diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index ac74665..33fb4a8 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -9,16 +9,9 @@ * The latest sources: https://github.com/republib */ -#include -#include -#include -#include -#include -#include -#include -#include #include "base/rebase.hpp" #include "gui/regui.hpp" +#include "utils.hpp" #include "textfinder.hpp" #include "mainwindow.hpp" #include "ui_mainwindow.h" @@ -26,6 +19,16 @@ #include "dialogglobalplaceholder.hpp" #include "filefinder.hpp" #include "aboutdialog.hpp" +#include "dialogoptions.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include /** * @brief Constructor. @@ -44,8 +47,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, m_lastOrder(Qt::DescendingOrder), m_homeDir(), m_storageFile(), - m_fileHandler(), - m_dirHandler(){ + m_contextHandlers(){ ui->setupUi(this); initializeHome(); m_statusMessage = new QLabel(tr("Willkommen bei refind")); @@ -66,6 +68,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, connect(ui->pushButtonDirectory, SIGNAL(clicked()), this, SLOT(selectDirectory())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); + connect(ui->actionOptions, SIGNAL(triggered()), this, SLOT(options())); connect(ui->actionGetAbsPath, SIGNAL(triggered()), this, SLOT(absPathToClipboard())); connect(ui->actionGetFullName, SIGNAL(triggered()), this, @@ -84,6 +87,8 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, SLOT(headerPlaceholder())); connect(ui->pushButtonFooterPlaceholder, SIGNAL(clicked()), this, SLOT(footerPlaceholder())); + connect(ui->actionPreview, SIGNAL(triggered()), this, SLOT(preview())); + connect(ui->pushButtonPreview, SIGNAL(clicked()), this, SLOT(preview())); m_horizontalHeader = ui->tableWidget->horizontalHeader(); connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ), @@ -93,7 +98,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, ui->tableWidget->setColumnWidth(TC_SIZE, 125); ui->tableWidget->setColumnWidth(TC_MODIFIED, 175); ui->tableWidget->setColumnWidth(TC_TYPE, 75); - addContextMenu(); + prepareContextMenu(); } /** @@ -103,50 +108,24 @@ MainWindow::~MainWindow(){ delete ui; } -/** - * Prepares the context menu of the result table. - * - */ -void MainWindow::addContextMenu(){ - ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->tableWidget, - SIGNAL(customContextMenuRequested(const QPoint&)), - SLOT(handleTableContextMenu(const QPoint&))); - ContextHandler* handler = new ContextHandler(); - handler->m_text = "kedit"; - handler->m_program = "kedit"; - handler->m_arguments = "${full}"; - handler->m_changeToParentDirectory = ContextHandler::DM_UNDEF; - m_fileHandler.append(handler); - handler = new ContextHandler(); - handler->m_text = "bash"; - handler->m_program = "konsole"; - handler->m_arguments = "${full}"; - handler->m_changeToParentDirectory = ContextHandler::DM_TO_FILE; - m_dirHandler.append(handler); -} - -======= ->>>>>>> branch 'master' of git@f-r-e-i.de:/home/git/repo/rplqt -void MainWindow::mousePressEvent(QMouseEvent* event) -{ - if (event->button() == Qt::LeftButton - && ui->tableWidget->geometry().contains(event->pos())) { - - QDrag *drag = new QDrag(this); - QMimeData *mimeData = new QMimeData; - - mimeData->setText("test text"); - drag->setMimeData(mimeData); +void MainWindow::mousePressEvent(QMouseEvent* event){ + if (event->button() == Qt::LeftButton + && ui->tableWidget->geometry().contains(event->pos())){ + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + + mimeData->setText("test text"); + drag->setMimeData(mimeData); #if 0 - const QPixmap image = iconShader.pixmap(QSize(16,16)); - drag->drawPixmap(0, 0, 16, 16, image); - drag->drawText(QRect(20, 0, 170, 20), tr("copy or move") ); + const QPixmap image = iconShader.pixmap(QSize(16,16)); + drag->drawPixmap(0, 0, 16, 16, image); + drag->drawText(QRect(20, 0, 170, 20), tr("copy or move") ); - drag->setPixmap(iconPixmap); + drag->setPixmap(iconPixmap); #endif - Qt::DropAction dropAction = drag->exec(); - } + Qt::DropAction dropAction = drag->exec(); + } } /** * initializeHomeializes the program home directory. @@ -170,30 +149,18 @@ void MainWindow::initializeHome(){ } /** - * Handles the event "header column clicked". - * - * @param col the col + * Starts the about dialog. */ -void MainWindow::headerClicked(int col){ - m_lastOrder = - m_lastOrder == Qt::AscendingOrder ? - Qt::DescendingOrder : Qt::AscendingOrder; - ui->tableWidget->sortItems(col, m_lastOrder); - m_horizontalHeader->setSortIndicatorShown(true); - m_horizontalHeader->setSortIndicator(col, m_lastOrder); -} - -void MainWindow::preview(){ - QString value; - QTextStream stream(&value); - exportToStream(stream, 1); +void MainWindow::about(){ + AboutDialog dialog; + dialog.exec(); } /** - * Starts the about dialog. + * Starts the options dialog. */ -void MainWindow::about(){ - AboutDialog dialog; +void MainWindow::options(){ + DialogOptions dialog(m_contextHandlers, NULL); dialog.exec(); } @@ -352,8 +319,8 @@ void MainWindow::exportFiles(){ * @param maxRow -1 or the maximum row to export */ void MainWindow::exportToStream(QTextStream& stream, int maxRow){ - QHash placeholders; - buildGlobalPlaceholders(placeholders); + QMap < QString, QString > placeholders; + buildGlobalPlaceholders (placeholders); if (!ui->comboBoxHeader->currentText().isEmpty()){ stream << replaceGlobalPlaceholders(ui->comboBoxHeader, placeholders) << endl; @@ -364,20 +331,20 @@ void MainWindow::exportToStream(QTextStream& stream, int maxRow){ QString error; for (int ii = 0; ii < count; ii++){ QString line = ui->comboBoxTemplate->currentText(); - QHash placeholders; + QMap < QString, QString > placeholders; QString path = m_lastBaseDir.absoluteFilePath( - ReQStringUtil::pathAppend( - ui->tableWidget->item(ii, TC_PATH)->text(), - ui->tableWidget->item(ii, TC_NODE)->text())); + ReQStringUtil::pathAppend(ui->tableWidget->item(ii, TC_PATH)->text(), + ui->tableWidget->item(ii, TC_NODE)->text())); placeholders.insert("full", ReQStringUtil::nativePath(path)); placeholders.insert("path", ui->tableWidget->item(ii, TC_PATH)->text()); placeholders.insert("ext", ui->tableWidget->item(ii, TC_EXT)->text()); placeholders.insert("node", ui->tableWidget->item(ii, TC_NODE)->text()); - placeholders.insert("modified", ui->tableWidget->item(ii, TC_MODIFIED)->text()); + placeholders.insert("modified", + ui->tableWidget->item(ii, TC_MODIFIED)->text()); placeholders.insert("size", ui->tableWidget->item(ii, TC_SIZE)->text()); - if (! ReQStringUtil::replacePlaceholders(line, placeholders, &error)){ - guiError(ui->comboBoxTemplate, error); - break; + if (!ReQStringUtil::replacePlaceholders(line, placeholders, &error)){ + guiError(ui->comboBoxTemplate, error); + break; } stream << replaceEscSequences(line) << endl; } @@ -437,65 +404,82 @@ void MainWindow::handlePlaceholder(QComboBox* target){ * @param position the position of a mouse click */ void MainWindow::handleTableContextMenu(const QPoint& position){ - int row = ui->tableWidget->rowAt(position.y()); - if (row >= 0){ - QMenu menu; - - QString node = ui->tableWidget->item(row, TC_NODE)->text(); - QString parent = buildAbsPath(row); - QString full = ReQStringUtil::pathAppend(parent, node); - QFileInfo file(full); - QList& list = file.isDir() ? m_dirHandler : m_fileHandler; - QList::const_iterator it; - QHash actions; - ContextHandler* handler; - for (it = list.begin(); it != list.end(); ++it){ - handler = *it; - QString text = handler->m_text + " " + node; - actions.insert(menu.addAction(text), handler); - } - QAction* selectedItem = menu.exec(ui->tableWidget->viewport()->mapToGlobal(position)); - if (selectedItem != NULL) - { - handler = *actions.find(selectedItem); - QString arguments = handler->m_arguments; - QString dir; - switch(handler->m_changeToParentDirectory){ - case ContextHandler::DM_TO_PARENT: - dir = parent; - break; - case ContextHandler::DM_TO_FILE: - dir = full; - break; - default: - dir = ui->comboBoxDirectory->currentText(); - break; - } - QMap placeholders; - placeholders.insert("full", full); - placeholders.insert("node", node); - placeholders.insert("path", parent); - placeholders.insert("ext", ReQStringUtil::extensionOf(node)); - QString error; - QStringList args = arguments.split(' '); - bool hasErrors = false; - for (int ix = 0; ix < args.size(); ix++){ - QString arg = args.at(ix); - if (! ReQStringUtil::replacePlaceholders(arg, placeholders, &error)){ - guiError(NULL, error); - hasErrors = true; - break; - } - args.replace(ix, arg); - } - if (! hasErrors){ - QProcess::startDetached(handler->m_program, args, dir, NULL); - setStatusMessage(false, "call of " + handler->m_program + " " - + arguments); + int row = ui->tableWidget->rowAt(position.y()); + if (row >= 0){ + QMenu menu; + + QString node = ui->tableWidget->item(row, TC_NODE)->text(); + QString parent = buildAbsPath(row); + QString full = ReQStringUtil::pathAppend(parent, node); + QFileInfo file(full); + bool isDir = file.isDir(); + QList ::const_iterator it; + QMap actions; + ContextHandler* handler; + for (it = m_contextHandlers.list().begin(); + it != m_contextHandlers.list().end(); ++it){ + handler = *it; + if ((isDir && handler->m_fileType == ContextHandler::FT_FILE) + || (!isDir && handler->m_fileType == ContextHandler::FT_DIR)) + continue; + QString text = handler->m_text + " " + node; + actions.insert(menu.addAction(text), handler); + } + QAction* selectedItem = menu.exec( + ui->tableWidget->viewport()->mapToGlobal(position)); + if (selectedItem != NULL){ + handler = *actions.find(selectedItem); + QString arguments = handler->m_arguments; + QString dir; + switch (handler->m_directoryMode) { + case ContextHandler::DM_TO_PARENT: + dir = parent; + break; + case ContextHandler::DM_TO_FILE: + dir = full; + break; + default: + dir = ui->comboBoxDirectory->currentText(); + break; + } + QMap < QString, QString > placeholders; + placeholders.insert("full", full); + placeholders.insert("node", node); + placeholders.insert("path", parent); + placeholders.insert("ext", ReQStringUtil::extensionOf(node)); + QString error; + QStringList args = arguments.split(' '); + bool hasErrors = false; + for (int ix = 0; ix < args.size(); ix++){ + QString arg = args.at(ix); + if (!ReQStringUtil::replacePlaceholders(arg, placeholders, &error)){ + guiError(NULL, error); + hasErrors = true; + break; } - } + args.replace(ix, arg); + } + if (!hasErrors){ + QProcess::startDetached(handler->m_program, args, dir, NULL); + setStatusMessage(false, + tr("started:") + " " + handler->m_program + " " + arguments); + } + } + } +} - } +/** + * Handles the event "header column clicked". + * + * @param col the col + */ +void MainWindow::headerClicked(int col){ + m_lastOrder = + m_lastOrder == Qt::AscendingOrder ? + Qt::DescendingOrder : Qt::AscendingOrder; + ui->tableWidget->sortItems(col, m_lastOrder); + m_horizontalHeader->setSortIndicatorShown(true); + m_horizontalHeader->setSortIndicator(col, m_lastOrder); } /** @@ -505,6 +489,31 @@ void MainWindow::headerPlaceholder(){ handlePlaceholder(ui->comboBoxHeader); } +/** + * Prepares the context menu of the result table. + * + */ +void MainWindow::prepareContextMenu(){ + ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->tableWidget, + SIGNAL(customContextMenuRequested(const QPoint&)), + SLOT(handleTableContextMenu(const QPoint&))); + ContextHandler* handler = new ContextHandler(); + handler->m_text = "kedit"; + handler->m_program = "/usr/bin/kate"; + handler->m_arguments = "${full}"; + handler->m_directoryMode = ContextHandler::DM_UNDEF; + handler->m_fileType = ContextHandler::FT_FILE; + m_contextHandlers.list().append(handler); + handler = new ContextHandler(); + handler->m_text = "bash"; + handler->m_program = "/usr/bin/konsole"; + handler->m_arguments = "${full}"; + handler->m_directoryMode = ContextHandler::DM_TO_FILE; + handler->m_fileType = ContextHandler::FT_DIR; + m_contextHandlers.list().append(handler); +} + /** * Prepares the text search. */ @@ -518,18 +527,36 @@ void MainWindow::prepareTextFind(){ } } -void MainWindow::buildGlobalPlaceholders(QHash& hash){ - - hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText()); - hash.insert("base", m_lastBaseDir.absolutePath()); - hash.insert("textpattern", 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")); +/** + * Shows a preview of the result export. + */ +void MainWindow::preview(){ + QString value; + QTextStream stream(&value); + exportToStream(stream, 1); + QMessageBox msgBox; + msgBox.setText(value); + msgBox.setInformativeText(tr("Preview of the Export")); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Save); + msgBox.exec(); +} + +void MainWindow::buildGlobalPlaceholders(QMap & hash){ + + hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText()); + hash.insert("base", m_lastBaseDir.absolutePath()); + hash.insert("textpattern", 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 placeholders valid in header and footer. @@ -538,11 +565,11 @@ void MainWindow::buildGlobalPlaceholders(QHash& hash){ * @return text with the esc sequences replaced */ QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo, - QHash& placeholders){ - QString rc = combo->currentText(); - QString error; - if (! ReQStringUtil::replacePlaceholders(rc, placeholders, &error)) - guiError(combo, error); + QMap & placeholders){ + QString rc = combo->currentText(); + QString error; + if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error)) + guiError(combo, error); return replaceEscSequences(rc); } @@ -592,6 +619,7 @@ void MainWindow::restoreState(){ storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true); storage.restore(ui->comboBoxTextPattern, "comboBoxTextPattern"); storage.restore(ui->comboBoxYounger, "comboBoxYounger"); + m_contextHandlers.restore(storage); storage.close(); } @@ -615,6 +643,7 @@ void MainWindow::saveState(){ storage.store(ui->comboBoxTemplate, "comboBoxTemplate"); storage.store(ui->comboBoxTextPattern, "comboBoxTextPattern"); storage.store(ui->comboBoxYounger, "comboBoxYounger"); + m_contextHandlers.save(storage); storage.close(); } diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index 55cd987..6585f8f 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -25,6 +25,9 @@ #if ! defined GUI_REGUI_HPP_ #include "gui/regui.hpp" #endif +#if ! defined UTILS_HPP +#include "utils.hpp" +#endif namespace Ui { class MainWindow; } @@ -32,36 +35,6 @@ enum TableColumns { TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH }; -struct Statistics { - Statistics(){ - clear(); - } - void clear(){ - m_dirs = m_files = 0; - m_bytes = 0; - m_runtimeSeconds = 0; - } - int m_dirs; - int m_files; - int64_t m_bytes; - double m_runtimeSeconds; -}; - -class ContextHandler { -public: - enum DirMode { - DM_UNDEF, - DM_TO_PARENT, - DM_TO_FILE - }; - -public: - QString m_text; - QString m_program; - QString m_arguments; - DirMode m_changeToParentDirectory; -}; - class MainWindow: public QMainWindow, public ReGuiValidator { Q_OBJECT @@ -83,6 +56,7 @@ private slots: void handleTableContextMenu(const QPoint& position); void headerClicked(int col); void headerPlaceholder(); + void options(); void preview(); void resetParameters(); void saveState(); @@ -92,10 +66,10 @@ private slots: void up(); private: - void addContextMenu(); + void prepareContextMenu(); QString buildAbsPath(int row); QDir::Filters buildFileTypes(); - void buildGlobalPlaceholders(QHash& hash); + void buildGlobalPlaceholders(QMap & hash); QString cellAsText(int row, int col); void exportToStream(QTextStream& stream, int maxRow = -1); void handlePlaceholder(QComboBox* target); @@ -103,7 +77,7 @@ private: void mousePressEvent(QMouseEvent* event); void prepareTextFind(); QString replaceGlobalPlaceholders(QComboBox* combo, - QHash& placeholders); + QMap & placeholders); void restoreState(); virtual void setStatusMessage(bool error, const QString& message); private: @@ -120,8 +94,7 @@ private: QString m_storageFile; QAction* m_actionEditor; QAction* m_actionStartShell; - QList m_fileHandler; - QList m_dirHandler; + ContextHandlerList m_contextHandlers; }; #endif // MAINWINDOW_HPP diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index 6752c61..a8543de 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -407,221 +407,215 @@ &Size, Date, Depth, Excluded Dirs - - - - 10 - 0 - 812 - 113 - - - - - 10 - - - 10 - - - - - - 150 - 16777215 - - - - Min. Size: - - - - - - - - 175 - 0 - - - - - 200 - 16777215 - - - - <html><head/><body><p>Formula of the minimal size.</p><p>Example: 3*512ki + 5MiByte + -2^10</p><p><br/></p><p>A non zero value excludes automatically directories.</p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>Units: factor 1000: KByte, MByte, GByte, TByte<br/>factor 1024: KiByte, MiByte, GiByte, TiByte</p><p><br/></p></body></html> - - - true - - - - - - - - 200 - 16777215 - - - - Younger than: - - - - - - - - 200 - 0 - - - - - 16777215 - 16777215 - - - - <html><head/><body><p>Formula of the minimal file date.</p><p>Example (relative): 3*5days+ 2hour</p><p>Example (absolute): 2015.12.31/23:59:59 - 3weeks</p><p><br/></p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>The first operand may be an absolute date, date and time or time:</p><p>Date syntax: yyyy.mm.dd</p><p>Time syntax HH:MM:SS</p><p>Units: minutes, hours, days, weeks</p><p>Abbrevation is allowed: 'd' is the same as 'days'</p><p><br/></p></body></html> - - - true - - - - - - - Min. Depth: - - - - - - - <html><head/><body><p>Minimal distance of the subdirectory containing the found file from the base directory.</p><p>Example:<br/>Min.Depth: 1<br/>Direcory: /home</p><p>/home/x will not be found</p><p>/home/dir/x will be found</p></body></html> - - - true - - - - - - - - 150 - 16777215 - - - - Max Size: - - - - - - - - 175 - 0 - - - - - 200 - 16777215 - - - - <html><head/><body><p>Formula of the maximum size.</p><p>Example: 3*512ki + 5MiByte + -2^10</p><p><br/></p><p>A non zero value excludes automatically directories.</p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>Units: factor 1000: KByte, MByte, GByte, TByte<br/>factor 1024: KiByte, MiByte, GiByte, TiByte</p><p><br/></p></body></html> - - - true - - - - - - - - 200 - 16777215 - - - - Older than: - - - - - - - - 200 - 16777215 - - - - <html><head/><body><p>Formula of the maximal file date.</p><p>Example (relative): 3*5days+ 2hour</p><p>Example (absolute): 2015.12.31/23:59:59 - 3weeks</p><p><br/></p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>The first operand may be an absolute date, date and time or time:</p><p>Date syntax: yyyy.mm.dd</p><p>Time syntax HH:MM:SS</p><p>Units: minutes, hours, days, weeks</p><p>Abbrevation is allowed: 'd' is the same as 'days'</p><p><br/></p></body></html> - - - true - - - - - - - Max. Depth: - - - - - - - <html><head/><body><p>Maximum distance of the subdirectory containing the found file from the base directory.</p><p>Example:<br/>Max. Depth: 0<br/>It found no files in subdirectories.</p></body></html> - - - true - - - - - - - Excluded Dirs: - - - - - - - <html><head/><body><p>a comma (',') separated list of directory names not entered for the search.</p><p>Example: .git,.cache</p></body></html> - - - true - - - - - - - &Run search - - - - :/main/icons/action_go.gif - :/main/icons/action_go.png:/main/icons/action_go.gif - - - - - + + + + + 10 + + + 10 + + + + + + 150 + 16777215 + + + + Max Size: + + + + + + + + 175 + 0 + + + + + 200 + 16777215 + + + + <html><head/><body><p>Formula of the maximum size.</p><p>Example: 3*512ki + 5MiByte + -2^10</p><p><br/></p><p>A non zero value excludes automatically directories.</p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>Units: factor 1000: KByte, MByte, GByte, TByte<br/>factor 1024: KiByte, MiByte, GiByte, TiByte</p><p><br/></p></body></html> + + + true + + + + + + + + 200 + 0 + + + + + 16777215 + 16777215 + + + + <html><head/><body><p>Formula of the minimal file date.</p><p>Example (relative): 3*5days+ 2hour</p><p>Example (absolute): 2015.12.31/23:59:59 - 3weeks</p><p><br/></p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>The first operand may be an absolute date, date and time or time:</p><p>Date syntax: yyyy.mm.dd</p><p>Time syntax HH:MM:SS</p><p>Units: minutes, hours, days, weeks</p><p>Abbrevation is allowed: 'd' is the same as 'days'</p><p><br/></p></body></html> + + + true + + + + + + + + 175 + 0 + + + + + 200 + 16777215 + + + + <html><head/><body><p>Formula of the minimal size.</p><p>Example: 3*512ki + 5MiByte + -2^10</p><p><br/></p><p>A non zero value excludes automatically directories.</p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>Units: factor 1000: KByte, MByte, GByte, TByte<br/>factor 1024: KiByte, MiByte, GiByte, TiByte</p><p><br/></p></body></html> + + + true + + + + + + + + 200 + 16777215 + + + + <html><head/><body><p>Formula of the maximal file date.</p><p>Example (relative): 3*5days+ 2hour</p><p>Example (absolute): 2015.12.31/23:59:59 - 3weeks</p><p><br/></p><p>A formula is a arithmetic expression with the operators '+', '*' and '^' (potentioning).</p><p>Usual precedence: '+' &lt; '*' &lt; '^'</p><p>The operands are integer numbers with potentionally a unit.</p><p>The first operand may be an absolute date, date and time or time:</p><p>Date syntax: yyyy.mm.dd</p><p>Time syntax HH:MM:SS</p><p>Units: minutes, hours, days, weeks</p><p>Abbrevation is allowed: 'd' is the same as 'days'</p><p><br/></p></body></html> + + + true + + + + + + + <html><head/><body><p>Maximum distance of the subdirectory containing the found file from the base directory.</p><p>Example:<br/>Max. Depth: 0<br/>It found no files in subdirectories.</p></body></html> + + + true + + + + + + + + 150 + 16777215 + + + + Min. Size: + + + + + + + <html><head/><body><p>Minimal distance of the subdirectory containing the found file from the base directory.</p><p>Example:<br/>Min.Depth: 1<br/>Direcory: /home</p><p>/home/x will not be found</p><p>/home/dir/x will be found</p></body></html> + + + true + + + + + + + + 200 + 16777215 + + + + Younger than: + + + + + + + &Run search + + + + :/main/icons/action_go.gif + :/main/icons/action_go.png:/main/icons/action_go.gif + + + + + + + + 200 + 16777215 + + + + Older than: + + + + + + + <html><head/><body><p>a comma (',') separated list of directory names not entered for the search.</p><p>Example: .git,.cache</p></body></html> + + + true + + + + + + + Min. Depth: + + + + + + + Max. Depth: + + + + + + + Excluded Dirs: + + + + + + @@ -646,7 +640,7 @@ 10 11 981 - 101 + 103 @@ -725,6 +719,17 @@ + + + + &Preview + + + + :/main/icons/eye.png:/main/icons/eye.png + + + @@ -941,6 +946,7 @@ + @@ -971,6 +977,8 @@ + + @@ -1015,6 +1023,8 @@ + + @@ -1026,6 +1036,7 @@ false + @@ -1065,7 +1076,7 @@ &About - Ctrl+A + Ctrl+Shift+A @@ -1122,7 +1133,7 @@ Puts the absolute path of the selected file into the clipboard - Ctrl+P + Ctrl+Shift+P @@ -1165,7 +1176,7 @@ Sets the file filter properties to the default - Ctrl+E + Ctrl+Shift+R @@ -1180,7 +1191,37 @@ Saves the program state (position, history...) to a file - Ctrl+S + Ctrl+Shift+S + + + + + + :/main/icons/wrench.png:/main/icons/wrench.png + + + &Options + + + Dialog for changing the options + + + Ctrl+Shift+O + + + + + + :/main/icons/eye.png:/main/icons/eye.png + + + Pre&view + + + Shows a preview of the result export + + + Ctrl+Shift+V diff --git a/appl/refind/refind.pro b/appl/refind/refind.pro index 709b269..5e62b72 100644 --- a/appl/refind/refind.pro +++ b/appl/refind/refind.pro @@ -25,7 +25,8 @@ SOURCES += main.cpp\ ../../gui/ReGuiValidator.cpp \ dialogglobalplaceholder.cpp \ dialogfileplaceholder.cpp \ - utils.cpp + utils.cpp \ + dialogoptions.cpp HEADERS += mainwindow.hpp \ @@ -39,13 +40,15 @@ HEADERS += mainwindow.hpp \ ../../gui/regui.hpp \ dialogglobalplaceholder.hpp \ dialogfileplaceholder.hpp \ - utils.hpp + utils.hpp \ + dialogoptions.hpp FORMS += mainwindow.ui \ aboutdialog.ui \ dialogglobalplaceholder.ui \ - dialogfileplaceholder.ui + dialogfileplaceholder.ui \ + dialogoptions.ui TRANSLATIONS = refind_de.ts diff --git a/appl/refind/refind.qrc b/appl/refind/refind.qrc index 7c6cce9..5f2890a 100644 --- a/appl/refind/refind.qrc +++ b/appl/refind/refind.qrc @@ -18,5 +18,7 @@ icons/cog_edit.png icons/database_save.png icons/disk.png + icons/wrench.png + icons/eye.png diff --git a/appl/refind/textfinder.cpp b/appl/refind/textfinder.cpp index c3055b0..16a5cfd 100644 --- a/appl/refind/textfinder.cpp +++ b/appl/refind/textfinder.cpp @@ -7,6 +7,7 @@ */ #include "base/rebase.hpp" +#include "utils.hpp" #include "textfinder.hpp" /** diff --git a/appl/refind/utils.cpp b/appl/refind/utils.cpp new file mode 100644 index 0000000..d5123a9 --- /dev/null +++ b/appl/refind/utils.cpp @@ -0,0 +1,147 @@ +/* + * 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 "base/rebase.hpp" +#include "utils.hpp" + +/** + * Constructor. + */ +ContextHandler::ContextHandler() : + m_text(), + m_program(), + m_arguments(), + m_directoryMode(DM_TO_PARENT), + m_fileType(FT_FILE){ +} + +/** + * Constructor. + */ +ContextHandlerList::ContextHandlerList() : + m_list(){ +} + +/** + * Constructor. + */ +ContextHandlerList::~ContextHandlerList(){ + clear(); +} +/** + * Copy constructor. + * + * @param source source to copy + * @return the instance itself + */ +ContextHandlerList::ContextHandlerList(const ContextHandlerList& source) : + m_list(){ + copy(source); +} + +/** + * Assignment operator. + * + * @param source source to copy + * @return the instance itself + */ +ContextHandlerList& ContextHandlerList::operator =( + const ContextHandlerList& source){ + return copy(source); +} + +/** + * Frees the resources. + */ +void ContextHandlerList::clear(){ + QList ::const_iterator it; + for (it = m_list.begin(); it != m_list.end(); ++it){ + delete *it; + } + m_list.clear(); +} + +/** + * Assignment operator. + * + * @param source source to copy + * @return the instance itself + */ +ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){ + clear(); + QList ::const_iterator it; + for (it = source.m_list.begin(); it != source.m_list.end(); ++it){ + ContextHandler* handler = *it; + m_list.append(handler); + } + return *this; +} + +/** + * Stores the list in the storage. + * + * @param storage IN/OUT: the storage + */ +void ContextHandlerList::save(ReStateStorage& storage){ + QString name = "context.program"; + QString value; + for (int ix = 0; ix < m_list.size(); ix++){ + ContextHandler* handler = m_list.at(ix); + value = handler->m_text + "\t" + handler->m_program + "\t" + + QString::number(handler->m_fileType) + "\t" + + QString::number(handler->m_directoryMode); + storage.store(name, value, ix); + } +} + +/** + * Reads the list from the storage. + * + * @param storage + */ +void ContextHandlerList::restore(ReStateStorage& storage){ + QString name = "context.program"; + clear(); + int ix = -1; + QString value; + QStringList cols; + while (true){ + ix++; + value = storage.restore(name, ix); + if (value.isEmpty()) + break; + cols = value.split('\t'); + if (cols.size() != 5) + break; + ContextHandler* handler = new ContextHandler; + handler->m_text = cols.at(0); + handler->m_program = cols.at(1); + handler->m_arguments = cols.at(2); + handler->m_fileType = ContextHandler::FileType( + 1 + atol(cols.at(3).toUtf8().constData())); + handler->m_directoryMode = ContextHandler::DirMode( + 1 + atol(cols.at(4).toUtf8().constData())); + m_list.append(handler); + } +} + +/** + * Constructor. + */ +Statistics::Statistics(){ + clear(); +} + +/** + * Resets all members. + */ +void Statistics::clear(){ + m_dirs = m_files = 0; + m_bytes = 0; + m_runtimeSeconds = 0; +} diff --git a/appl/refind/utils.hpp b/appl/refind/utils.hpp new file mode 100644 index 0000000..0a90b6e --- /dev/null +++ b/appl/refind/utils.hpp @@ -0,0 +1,65 @@ +/* + * 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 UTILS_HPP +#define UTILS_HPP + +#include +#include "gui/ReStateStorage.hpp" +enum { + COL_FILE_TYPE, COL_TITLE, COL_PROGRAM, COL_ARGUMENTS, COL_CURRENT_DIR +}; +class ContextHandler { +public: + enum DirMode { + DM_UNDEF, DM_TO_PARENT, DM_TO_FILE + }; + enum FileType { + FT_UNDEF, FT_DIR, FT_FILE, FT_ALL + }; +public: + ContextHandler(); +public: + QString m_text; + QString m_program; + QString m_arguments; + DirMode m_directoryMode; + FileType m_fileType; +}; + +class ContextHandlerList { +public: + ContextHandlerList(); + ~ContextHandlerList(); + ContextHandlerList(const ContextHandlerList& source); + ContextHandlerList& operator =(const ContextHandlerList& source); +public: + void clear(); + ContextHandlerList©(const ContextHandlerList& source); + QList & list(){ + return m_list; + } + void save(ReStateStorage& storage); + void restore(ReStateStorage& storage); +private: + QList m_list; +}; + +class Statistics { +public: + Statistics(); +public: + void clear(); +public: + int m_dirs; + int m_files; + int64_t m_bytes; + double m_runtimeSeconds; +}; + +#endif // UTILS_HPP diff --git a/base/ReQStringUtil.cpp b/base/ReQStringUtil.cpp index af4a960..9ee3619 100644 --- a/base/ReQStringUtil.cpp +++ b/base/ReQStringUtil.cpp @@ -390,12 +390,12 @@ QString ReQStringUtil::pathAppend(const QString& base, const QString& path) * @return true: success
* false: unknown name found (not replaced) */ -bool ReQStringUtil::replacePlaceholders(QString& text, - const QHash& placeholders, QString* error){ +bool ReQStringUtil::replacePlaceholders(QString& text, const QMap& placeholders, QString* error){ int start = 0; bool rc = true; QString name; - QHash::const_iterator it; + QMap::const_iterator it; while (start >= 0){ start = text.indexOf("${", start); if (start < 0) diff --git a/base/ReQStringUtil.hpp b/base/ReQStringUtil.hpp index 55a0888..11f70b0 100644 --- a/base/ReQStringUtil.hpp +++ b/base/ReQStringUtil.hpp @@ -43,7 +43,7 @@ public: #endif } static QString pathAppend(const QString& base, const QString& path); - static bool replacePlaceholders(QString& text, const QHash& placeholders, QString* error); static void skipExpected(const ReString& text, QChar expected, int& index, int& length); diff --git a/base/rebase.hpp b/base/rebase.hpp index 2c7ab85..a91f568 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/gui/ReStateStorage.cpp b/gui/ReStateStorage.cpp index 9bec52e..fbadb0a 100644 --- a/gui/ReStateStorage.cpp +++ b/gui/ReStateStorage.cpp @@ -129,6 +129,26 @@ void ReStateStorage::restore(QComboBox* combo, const QString& name, } } } +/** + * Reads a value from the storage. + * + * @param name name of the variable + * @param index -1 (no array) or the index of the entry + * @return "": not found
+ * otherwise: the stored value of the variable + */ +QString ReStateStorage::restore(const QString& name, int index) +{ + QString rc; + if (initForRead()){ + QString key(name); + if (index >= 0) + key += QString::number(index); + if (m_map.contains(key)) + rc = m_map.value(key); + } + return rc; +} /** * Stores the data of a combobox. * @@ -154,3 +174,22 @@ void ReStateStorage::store(const QComboBox* combo, const QString& name, m_stream->flush(); } +/** + * Stores the data of a combobox. + * + * @param combo the combobox to store + * @param name the name of the combobox + * @param withCurrentText true: the current text will be saved too + */ +void ReStateStorage::store(const QString& name, const QString& value, int index) +{ + if (initForWrite()){ + QString key(name); + if (index >= 0) + key += QString::number(index); + *m_stream << key << "=" << value << endl; + } + m_stream->flush(); + +} + diff --git a/gui/ReStateStorage.hpp b/gui/ReStateStorage.hpp index 3f3665c..5d25035 100644 --- a/gui/ReStateStorage.hpp +++ b/gui/ReStateStorage.hpp @@ -27,9 +27,11 @@ public: bool initForWrite(); void restore(QComboBox* combo, const QString& name, bool withCurrentText = false); + QString restore(const QString& name, int index = -1); + void setForm(const QString& form); void store(const QComboBox* combo, const QString& name, bool withCurrentText = true); - void setForm(const QString& form); + void store(const QString& name, const QString& value, int index = -1); private: QString m_filename;