From 6664ab74973a9b55a484e98495b9cdbc71f53ba0 Mon Sep 17 00:00:00 2001 From: hama Date: Mon, 25 May 2015 01:23:28 +0200 Subject: [PATCH] Refind: drag works --- appl/.gitignore | 2 + appl/refind.ico | Bin 0 -> 1406 bytes appl/refind/dialogoptions.cpp | 96 ++++---- appl/refind/filetablewidget.cpp | 47 ++++ appl/refind/filetablewidget.hpp | 27 +++ appl/refind/mainwindow.cpp | 415 +++++++++++++++++--------------- appl/refind/mainwindow.hpp | 6 +- appl/refind/mainwindow.ui | 15 +- appl/refind/refind.pro | 14 +- appl/refind/utils.cpp | 120 +++++---- appl/refind/utils.hpp | 9 + base/ReQStringUtil.cpp | 12 + base/ReQStringUtil.hpp | 1 + 13 files changed, 475 insertions(+), 289 deletions(-) create mode 100644 appl/.gitignore create mode 100644 appl/refind.ico create mode 100644 appl/refind/filetablewidget.cpp create mode 100644 appl/refind/filetablewidget.hpp diff --git a/appl/.gitignore b/appl/.gitignore new file mode 100644 index 0000000..5ec952f --- /dev/null +++ b/appl/.gitignore @@ -0,0 +1,2 @@ +build-reviewer-Desktop5-Debug/ + diff --git a/appl/refind.ico b/appl/refind.ico new file mode 100644 index 0000000000000000000000000000000000000000..b48307fcc1d61ae945c298856513fdf03076488d GIT binary patch literal 1406 zcmeH{drVVj7{(t5F3hN76PXHZxDed}DB+Ia=v)Cih@9c3+PG*jEjJH z10kl_*5F`)j`qaG#26EGGcg*YabB=^tKtUeA}zhy>)vx3mu1QR*#CP^e&>0f_scms zdC!**m`7J&Am|Q#j@GQn6`68Uz_UWC?}H&Ei3roq=3ICbs2dp+K08LeXcC z7Kk7#$%8bX^+J>t=c1x0hf~gP&&TevB2-EXP*YxvT3HG9R7yD-YRb@9w-a58T4ZeG zA(*}=H7OP!rNkquZ5#vLUm?1E9MK))i2vy>(oRiq{#7ro=PnX@^+-If_o-SBwwE|U zS*u6V5a}qbpVVX3m07I0YDCI)6AJr=P<+9FlAj+#ObEsd$oav5g0UwMYbTNMtBII{ z@HTPBj66boZWABZ$&lHcyR{u8%D^<%O6)IgDn^u=)&;v0~i_TfbP3P7#z{yjP?Z1GT)== zmI-Zl=Fl@fhrC8`_`P(Mfbq+R;NCeriYGZ+3k9 z$b#YfW~irM;sl{FSfP3DfR;GHHuPyTPXQNK18GC0} zh-CS$_eR;QVKmxM=^{yB*type() == QEvent::KeyPress){ - QKeyEvent *keyEvent = static_cast(event); - int key = keyEvent->key(); - if (key == Qt::Key_Up || key == Qt::Key_Down) - m_dialog->handleKey(key); - } - // standard event processing - return QObject::eventFilter(obj, event); +bool TableKeyPressEater::eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::KeyPress){ + QKeyEvent *keyEvent = static_cast (event); + int key = keyEvent->key(); + if (key == Qt::Key_Up || key == Qt::Key_Down) + m_dialog->handleKey(key); + } + // standard event processing + return QObject::eventFilter(obj, event); } /** * Constructor. @@ -64,8 +60,10 @@ DialogOptions::DialogOptions(ContextHandlerList& handlers, QWidget *parent) : SLOT(selectProgram())); connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up())); connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int,int))); - connect(ui->tableWidget, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); - connect(ui->tableWidget, SIGNAL(currentItemChanged()), this, SLOT(currentItemChanged())); + connect(ui->tableWidget, SIGNAL(selectionChanged()), this, + SLOT(selectionChanged())); + connect(ui->tableWidget, SIGNAL(currentItemChanged()), this, + SLOT(currentItemChanged())); ui->tableWidget->installEventFilter(new TableKeyPressEater(this)); for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++) @@ -84,8 +82,8 @@ DialogOptions::~DialogOptions(){ } void DialogOptions::currentItemChanged(QTableWidgetItem * current, - QTableWidgetItem * previous){ - QString text = current->text() + " " + previous->text(); + QTableWidgetItem * previous){ + QString text = current->text() + " " + previous->text(); } /** @@ -184,17 +182,20 @@ void DialogOptions::fillTable(){ 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->comboBoxDirMode->itemText(handler->m_directoryMode - 1); - ui->tableWidget->setItem(row, COL_CURRENT_DIR, - new QTableWidgetItem(value)); + if (handler->intrinsicType() == ContextHandler::IT_UNDEF){ + 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->comboBoxDirMode->itemText(handler->m_directoryMode - 1); + ui->tableWidget->setItem(row, COL_CURRENT_DIR, + new QTableWidgetItem(value)); + } } } @@ -233,15 +234,14 @@ void DialogOptions::fromTable(){ * * @param key the key (up or down) */ -void DialogOptions::handleKey(int key) -{ - if (key == Qt::Key_Down){ - if (m_selectedRow < ui->tableWidget->rowCount() - 1) - m_selectedRow++; - } else if (key == Qt::Key_Up){ - if (m_selectedRow > 0) - m_selectedRow--; - } +void DialogOptions::handleKey(int key){ + if (key == Qt::Key_Down){ + if (m_selectedRow < ui->tableWidget->rowCount() - 1) + m_selectedRow++; + }else if (key == Qt::Key_Up){ + if (m_selectedRow > 0) + m_selectedRow--; + } } /** @@ -281,18 +281,18 @@ void DialogOptions::selectProgram(){ QString file = QFileDialog::getOpenFileName(NULL, tr("Select Program File"), ui->comboBoxProgram->currentText()); if (!file.isEmpty()) - ui->comboBoxProgram->setCurrentText(file); + ui->comboBoxProgram->setCurrentText(file); } -void DialogOptions::selectionChanged() -{ - QList selections = ui->tableWidget->selectedRanges(); - QList::const_iterator it = selections.begin(); - if (it != selections.end()){ - int row = (*it).topRow(); - if (row != m_selectedRow) - selectRow(row); - } +void DialogOptions::selectionChanged(){ + QList < QTableWidgetSelectionRange > selections = + ui->tableWidget->selectedRanges(); + QList ::const_iterator it = selections.begin(); + if (it != selections.end()){ + int row = (*it).topRow(); + if (row != m_selectedRow) + selectRow(row); + } } /** * Handles the event "pushed button up". diff --git a/appl/refind/filetablewidget.cpp b/appl/refind/filetablewidget.cpp new file mode 100644 index 0000000..bb2ad98 --- /dev/null +++ b/appl/refind/filetablewidget.cpp @@ -0,0 +1,47 @@ +/* + * 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 +#include +#include "mainwindow.hpp" +#include "filetablewidget.hpp" + +/** + * Constructor. + */ +FileTableWidget::FileTableWidget(QWidget* parent) : + QTableWidget(parent), m_mainWindow(NULL), m_dragStartPosition(0, 0){ +} + +/** + * Reimplements the mouse press event (for dragging). + * + * @param event the event data + */ +void FileTableWidget::mousePressEvent(QMouseEvent *event){ + if (event->button() == Qt::LeftButton) + m_dragStartPosition = event->pos(); +} + +void FileTableWidget::setMainWindow(MainWindow* mainWindow){ + m_mainWindow = mainWindow; +} + +/** + * Reimplements the mouse move event (for dragging). + * + * @param event the event data + */ +void FileTableWidget::mouseMoveEvent(QMouseEvent *event){ + Qt::MouseButton button = event->button(); + if (button == Qt::LeftButton || button == Qt::NoButton){ + int distance = (event->pos() - m_dragStartPosition).manhattanLength(); + if (distance < QApplication::startDragDistance()) + m_mainWindow->fileDragging(); + } +} diff --git a/appl/refind/filetablewidget.hpp b/appl/refind/filetablewidget.hpp new file mode 100644 index 0000000..597861b --- /dev/null +++ b/appl/refind/filetablewidget.hpp @@ -0,0 +1,27 @@ +/* + * 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 CUSTOMWIDGETS_HPP +#define CUSTOMWIDGETS_HPP +#include + +class MainWindow; +class FileTableWidget: public QTableWidget { + Q_OBJECT +public: + FileTableWidget(QWidget* parent); +public: + void setMainWindow(MainWindow* mainWindow);protected slots: + void mouseMoveEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent* event); +private: + MainWindow* m_mainWindow; + QPoint m_dragStartPosition; +}; + +#endif // CUSTOMWIDGETS_HPP diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index 170fd21..2a98cc0 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,7 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, ui->comboBoxDirectory->setCurrentText(startDir); if (ui->comboBoxDirectory->currentText().isEmpty()) ui->comboBoxDirectory->setCurrentText(QDir::currentPath()); + ui->tableWidget->setMainWindow(this); statusBar()->addWidget(m_statusMessage); connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search())); connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search())); @@ -108,25 +110,6 @@ MainWindow::~MainWindow(){ delete ui; } -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") ); - - drag->setPixmap(iconPixmap); -#endif - Qt::DropAction dropAction = drag->exec(); - } -} /** * initializeHomeializes the program home directory. */ @@ -186,14 +169,21 @@ void MainWindow::baseDirToClipboard(){ /** * Gets the absolute path of the file in the given row. * - * @param row the row number - * @return the absolute path of the file given by the row + * @param row the row number + * @param withNode true: the node will be appended to the result + * @return the absolute path of the file given by the row */ -QString MainWindow::buildAbsPath(int row){ +QString MainWindow::buildAbsPath(int row, bool withNode){ QString rc(m_lastBaseDir.absolutePath()); QString value = cellAsText(row, TC_PATH); - if (!value.isEmpty()) - rc += "/" + value + "/"; + if (!value.isEmpty()){ + ReQStringUtil::ensureLastChar(rc, '/'); + rc += value; + } + if (withNode){ + ReQStringUtil::ensureLastChar(rc, '/'); + rc += cellAsText(row, TC_NODE); + } return rc; } @@ -489,60 +479,107 @@ void MainWindow::headerPlaceholder(){ handlePlaceholder(ui->comboBoxHeader); } +/** + * Processes the dragging operation of the selected files in the table widget. + */ +void MainWindow::fileDragging(){ + + QDrag *drag = new QDrag(this); + QMimeData *mimeData = new QMimeData; + QList < QUrl > urls; + QList < QTableWidgetSelectionRange > ranges = + ui->tableWidget->selectedRanges(); + QList ::iterator it; + int files = 0; + int dirs = 0; + bool isDir = false; + for (it = ranges.begin(); it != ranges.end(); ++it){ + for (int row = (*it).topRow(); row <= (*it).bottomRow(); row++){ + isDir = cellAsText(row, TC_SIZE).isEmpty(); + QUrl url(buildAbsPath(row, true)); + urls.append(url); + if (isDir) + dirs++; + else + files++; + } + } + if (urls.size() > 0){ + mimeData->setUrls(urls); + drag->setMimeData(mimeData); + QPixmap image(200, 30); + QPainter painter(&image); + QString msg; + if (urls.size() == 1) + msg = tr("copy ") + ReQStringUtil::nodeOf(urls.at(0).toString()); + else if (files > 0 && dirs > 0) + msg = tr("copy %1 file(s) and %2 dir(s)").arg(files).arg(dirs); + else if (files > 0) + msg = tr("copy %1 file(s)").arg(files); + else + msg = tr("copy %1 dirs(s)").arg(dirs); + + painter.fillRect(image.rect(), Qt::white); + painter.drawText(10, 20, msg); + drag->setPixmap(image); + + Qt::DropAction dropAction = drag->exec(Qt::CopyAction); + } + +} + /** * 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&))); +connect(ui->tableWidget, + SIGNAL(customContextMenuRequested(const QPoint&)), + SLOT(handleTableContextMenu(const QPoint&))); } /** * Prepares the text search. */ void MainWindow::prepareTextFind(){ - m_textFinder.setSearchParameter(ui->comboBoxTextPattern->currentText(), - ui->checkBoxTextIgnoreCase->isChecked(), ui->checkBoxRegExpr->isChecked(), - !ui->checkBoxBinaryFiles->isChecked()); - QString error = m_textFinder.regExprError(); - if (!error.isEmpty()){ - guiError(ui->comboBoxTextPattern, error); - } +m_textFinder.setSearchParameter(ui->comboBoxTextPattern->currentText(), + ui->checkBoxTextIgnoreCase->isChecked(), ui->checkBoxRegExpr->isChecked(), + !ui->checkBoxBinaryFiles->isChecked()); +QString error = m_textFinder.regExprError(); +if (!error.isEmpty()){ + guiError(ui->comboBoxTextPattern, error); +} } /** * 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(); +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")); +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. @@ -551,12 +588,12 @@ void MainWindow::buildGlobalPlaceholders(QMap & hash){ * @return text with the esc sequences replaced */ QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo, - QMap & placeholders){ - QString rc = combo->currentText(); - QString error; - if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error)) - guiError(combo, error); - return replaceEscSequences(rc); +QMap & placeholders){ +QString rc = combo->currentText(); +QString error; +if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error)) + guiError(combo, error); +return replaceEscSequences(rc); } /** @@ -565,149 +602,149 @@ QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo, * Most of the filter parameters will be set to the default. */ void MainWindow::resetParameters(){ - ui->comboBoxFilePatterns->setCurrentText(""); - ui->comboBoxMaxDepth->setCurrentText(""); - ui->comboBoxMaxSize->setCurrentText(""); - ui->comboBoxMinDepth->setCurrentText(""); - ui->comboBoxMinSize->setCurrentText(""); - ui->comboBoxOlder->setCurrentText(""); - ui->comboBoxYounger->setCurrentText(""); - ui->comboBoxTextPattern->setCurrentText(""); - ui->checkBoxBinaryFiles->setChecked(false); - ui->checkBoxDirs->setChecked(true); - ui->checkBoxFiles->setChecked(true); - ui->checkBoxHidden->setChecked(false); - ui->checkBoxLinks->setChecked(true); - ui->checkBoxReadable->setChecked(true); - ui->checkBoxRegExpr->setChecked(false); - ui->checkBoxTextIgnoreCase->setChecked(false); - ui->checkBoxWritable->setChecked(true); - ui->checkBoxExecutable->setChecked(true); +ui->comboBoxFilePatterns->setCurrentText(""); +ui->comboBoxMaxDepth->setCurrentText(""); +ui->comboBoxMaxSize->setCurrentText(""); +ui->comboBoxMinDepth->setCurrentText(""); +ui->comboBoxMinSize->setCurrentText(""); +ui->comboBoxOlder->setCurrentText(""); +ui->comboBoxYounger->setCurrentText(""); +ui->comboBoxTextPattern->setCurrentText(""); +ui->checkBoxBinaryFiles->setChecked(false); +ui->checkBoxDirs->setChecked(true); +ui->checkBoxFiles->setChecked(true); +ui->checkBoxHidden->setChecked(false); +ui->checkBoxLinks->setChecked(true); +ui->checkBoxReadable->setChecked(true); +ui->checkBoxRegExpr->setChecked(false); +ui->checkBoxTextIgnoreCase->setChecked(false); +ui->checkBoxWritable->setChecked(true); +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"); - m_contextHandlers.restore(storage); - storage.close(); +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"); +m_contextHandlers.restore(storage); +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"); - m_contextHandlers.save(storage); - storage.close(); +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"); +m_contextHandlers.save(storage); +storage.close(); } /** * Handles the "search" button. */ void MainWindow::search(){ - m_errors = 0; - QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString - path = ui->comboBoxDirectory->currentText(); - QFileInfo dir(path); - if (!dir.exists()) - guiError(ui->comboBoxDirectory, tr("directory not found: ") + path); - else if (!dir.isDir()) - guiError(ui->comboBoxDirectory, tr("not a directory: ") + path); - else{ - m_lastBaseDir.cd(path); - FileFinder finder; - finder.setBaseDir(path); - 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.setFiletypes(buildFileTypes()); - QStringList patterns; - QString value = ui->comboBoxFilePatterns->currentText(); - if (!value.isEmpty()) - patterns = value.split(","); - finder.setPatterns(patterns); - value = ui->comboBoxExcludedDirs->currentText(); - 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); - prepareTextFind(); - if (m_errors == 0){ - if (!ui->comboBoxTextPattern->currentText().isEmpty()) - finder.setTextFinder(&m_textFinder); - m_statistics.clear(); - clock_t start = clock(); - finder.fillTable(path, 0, ui->tableWidget, m_statistics); - m_statistics.m_runtimeSeconds = (double) (clock() - start) - / CLOCKS_PER_SEC; - QString msg; - msg.sprintf( - QObject::tr( - "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(), - m_statistics.m_dirs, m_statistics.m_files, - m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds); - setStatusMessage(false, msg); - } +m_errors = 0; +QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString +path = ui->comboBoxDirectory->currentText(); +QFileInfo dir(path); +if (!dir.exists()) + guiError(ui->comboBoxDirectory, tr("directory not found: ") + path); +else if (!dir.isDir()) + guiError(ui->comboBoxDirectory, tr("not a directory: ") + path); +else{ + m_lastBaseDir.cd(path); + FileFinder finder; + finder.setBaseDir(path); + 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.setFiletypes(buildFileTypes()); + QStringList patterns; + QString value = ui->comboBoxFilePatterns->currentText(); + if (!value.isEmpty()) + patterns = value.split(","); + finder.setPatterns(patterns); + value = ui->comboBoxExcludedDirs->currentText(); + 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); + prepareTextFind(); + if (m_errors == 0){ + if (!ui->comboBoxTextPattern->currentText().isEmpty()) + finder.setTextFinder(&m_textFinder); + m_statistics.clear(); + clock_t start = clock(); + finder.fillTable(path, 0, ui->tableWidget, m_statistics); + m_statistics.m_runtimeSeconds = (double) (clock() - start) + / CLOCKS_PER_SEC; + QString msg; + msg.sprintf( + QObject::tr( + "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(), + m_statistics.m_dirs, m_statistics.m_files, + m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds); + setStatusMessage(false, msg); } - QApplication::restoreOverrideCursor(); +} +QApplication::restoreOverrideCursor(); } /** * Handles the push of the button "select directory". */ void MainWindow::selectDirectory(){ - QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"), - ui->comboBoxDirectory->currentText(), QFileDialog::ShowDirsOnly); - if (!dir.isEmpty()) - ui->comboBoxDirectory->setCurrentText(dir); +QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"), + ui->comboBoxDirectory->currentText(), QFileDialog::ShowDirsOnly); +if (!dir.isEmpty()) + ui->comboBoxDirectory->setCurrentText(dir); } /** * Calls the file selection dialog. */ void MainWindow::selectExportFile(){ - QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"), - ui->comboBoxExportFile->currentText()); - if (!name.isEmpty()) - ui->comboBoxExportFile->setCurrentText(name); +QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"), + ui->comboBoxExportFile->currentText()); +if (!name.isEmpty()) + ui->comboBoxExportFile->setCurrentText(name); } @@ -718,26 +755,26 @@ void MainWindow::selectExportFile(){ * @param message the text to set */ void MainWindow::setStatusMessage(bool error, const QString& message){ - if (m_stdLabelBackgroundRole == NULL) - m_stdLabelBackgroundRole = new QPalette::ColorRole( - m_statusMessage->backgroundRole()); - m_statusMessage->setBackgroundRole( - error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole); - m_statusMessage->setText(message); +if (m_stdLabelBackgroundRole == NULL) + m_stdLabelBackgroundRole = new QPalette::ColorRole( + m_statusMessage->backgroundRole()); +m_statusMessage->setBackgroundRole( + error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole); +m_statusMessage->setText(message); } /** * @brief Handles the "up" button: go to the parent directory. */ void MainWindow::up(){ - QString path = ui->comboBoxDirectory->currentText(); - QDir dir(path); +QString path = ui->comboBoxDirectory->currentText(); +QDir dir(path); +if (dir.exists()){ + dir.cdUp(); if (dir.exists()){ - dir.cdUp(); - if (dir.exists()){ - path = dir.absolutePath(); - ui->comboBoxDirectory->setEditText(path); - setInHistory(ui->comboBoxDirectory, path); - } + path = dir.absolutePath(); + ui->comboBoxDirectory->setEditText(path); + setInHistory(ui->comboBoxDirectory, path); } } +} diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index 6585f8f..2d15782 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -44,7 +44,8 @@ public: QWidget *parent = 0); ~MainWindow(); -private slots: +public: + void fileDragging();private slots: void about(); void absPathToClipboard(); void baseDirToClipboard(); @@ -67,14 +68,13 @@ private slots: private: void prepareContextMenu(); - QString buildAbsPath(int row); + QString buildAbsPath(int row, bool withNode = false); QDir::Filters buildFileTypes(); void buildGlobalPlaceholders(QMap & hash); QString cellAsText(int row, int col); void exportToStream(QTextStream& stream, int maxRow = -1); void handlePlaceholder(QComboBox* target); void initializeHome(); - void mousePressEvent(QMouseEvent* event); void prepareTextFind(); QString replaceGlobalPlaceholders(QComboBox* combo, QMap & placeholders); diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index a8543de..99ba460 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -876,13 +876,19 @@ - + QAbstractItemView::NoEditTriggers true + + QAbstractItemView::DragDrop + + + Qt::CopyAction + QAbstractItemView::SelectRows @@ -1226,6 +1232,13 @@ + + + FileTableWidget + QTableWidget +
filetablewidget.hpp
+
+
comboBoxDirectory pushButtonUp diff --git a/appl/refind/refind.pro b/appl/refind/refind.pro index 5e62b72..669aac4 100644 --- a/appl/refind/refind.pro +++ b/appl/refind/refind.pro @@ -11,6 +11,8 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = refind TEMPLATE = app +win32:RC_ICONS += refind.ico + INCLUDEPATH = ../.. /usr/include/c++/4.9 SOURCES += main.cpp\ @@ -25,8 +27,9 @@ SOURCES += main.cpp\ ../../gui/ReGuiValidator.cpp \ dialogglobalplaceholder.cpp \ dialogfileplaceholder.cpp \ - utils.cpp \ - dialogoptions.cpp + utils.cpp \ + dialogoptions.cpp \ + filetablewidget.cpp HEADERS += mainwindow.hpp \ @@ -40,15 +43,16 @@ HEADERS += mainwindow.hpp \ ../../gui/regui.hpp \ dialogglobalplaceholder.hpp \ dialogfileplaceholder.hpp \ - utils.hpp \ - dialogoptions.hpp + utils.hpp \ + dialogoptions.hpp \ + filetablewidget.hpp FORMS += mainwindow.ui \ aboutdialog.ui \ dialogglobalplaceholder.ui \ dialogfileplaceholder.ui \ - dialogoptions.ui + dialogoptions.ui TRANSLATIONS = refind_de.ts diff --git a/appl/refind/utils.cpp b/appl/refind/utils.cpp index 9a54c42..bf6f2c5 100644 --- a/appl/refind/utils.cpp +++ b/appl/refind/utils.cpp @@ -9,6 +9,18 @@ #include "base/rebase.hpp" #include "utils.hpp" +/** + * Constructor. + */ +ContextHandler::ContextHandler(IntrinsicType intrinsicType, const QString& text) : + m_text(text), + m_program(), + m_arguments(), + m_directoryMode(DM_UNDEF), + m_fileType(FT_ALL), + m_intrinsicType(intrinsicType){ +} + /** * Constructor. */ @@ -17,7 +29,17 @@ ContextHandler::ContextHandler() : m_program(), m_arguments(), m_directoryMode(DM_TO_PARENT), - m_fileType(FT_FILE){ + m_fileType(FT_FILE), + m_intrinsicType(IT_UNDEF){ +} + +/** + * Returns the intrinsic type. + * + * @return the intrinsic type + */ +ContextHandler::IntrinsicType ContextHandler::intrinsicType() const{ + return m_intrinsicType; } /** @@ -55,6 +77,14 @@ ContextHandlerList& ContextHandlerList::operator =( return copy(source); } +/** + * Adds the intrinsic context menu actions. + */ +void ContextHandlerList::addIntrinsics(){ + m_list.append( + new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy"))); +} + /** * Frees the resources. */ @@ -77,8 +107,10 @@ ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){ QList ::const_iterator it; for (it = source.m_list.begin(); it != source.m_list.end(); ++it){ ContextHandler* handler = *it; - m_list.append(handler); + if (handler->intrinsicType() == ContextHandler::IT_UNDEF) + m_list.append(handler); } + addIntrinsics(); return *this; } @@ -92,33 +124,34 @@ void ContextHandlerList::save(ReStateStorage& storage){ 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" - + handler->m_arguments + "\t" - + QString::number(handler->m_fileType) + "\t" - + QString::number(handler->m_directoryMode); - storage.store(name, value, ix); + if (handler->intrinsicType() == ContextHandler::IT_UNDEF){ + value = handler->m_text + "\t" + handler->m_program + "\t" + + handler->m_arguments + "\t" + QString::number(handler->m_fileType) + + "\t" + QString::number(handler->m_directoryMode); + storage.store(name, value, ix); + } } } ContextHandler* createHandlerIfExists(const QString& file, - ContextHandler::FileType fileType = ContextHandler::FT_FILE){ - QFileInfo info(file); - ContextHandler* handler = NULL; - if (info.exists()){ - handler = new ContextHandler; - handler->m_text = ReQStringUtil::nodeOf(file); - handler->m_program = file; - handler->m_arguments = "${full}"; + ContextHandler::FileType fileType = ContextHandler::FT_FILE){ + QFileInfo info(file); + ContextHandler* handler = NULL; + if (info.exists()){ + handler = new ContextHandler; + handler->m_text = ReQStringUtil::nodeOf(file); + handler->m_program = file; + handler->m_arguments = "${full}"; #if defined WIN32 - if (handler->m_text == "cmd.exe") - handler->m_arguments = ""; + if (handler->m_text == "cmd.exe") + handler->m_arguments = ""; #endif - handler->m_fileType = fileType; - handler->m_directoryMode = fileType == ContextHandler::FT_FILE - ? ContextHandler::DM_TO_PARENT - : ContextHandler::DM_TO_FILE; - } - return handler; + handler->m_fileType = fileType; + handler->m_directoryMode = + fileType == ContextHandler::FT_FILE ? + ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE; + } + return handler; } /** @@ -153,30 +186,31 @@ void ContextHandlerList::restore(ReStateStorage& storage){ } if (m_list.size() == 0){ #if defined __linux__ - handler = createHandlerIfExists("/usr/bin/kate"); - if (handler == NULL) - handler = createHandlerIfExists("/usr/bin/geany"); - if (handler == NULL) - handler = createHandlerIfExists("/usr/bin/kwrite"); - if (handler == NULL) - handler = createHandlerIfExists("/usr/bin/gedit"); - if (handler != NULL) - m_list.append(handler); - handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR); - if (handler == NULL) - handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR); - if (handler != NULL) - m_list.append(handler); + handler = createHandlerIfExists("/usr/bin/kate"); + if (handler == NULL) + handler = createHandlerIfExists("/usr/bin/geany"); + if (handler == NULL) + handler = createHandlerIfExists("/usr/bin/kwrite"); + if (handler == NULL) + handler = createHandlerIfExists("/usr/bin/gedit"); + if (handler != NULL) + m_list.append(handler); + handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR); + if (handler == NULL) + handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR); + if (handler != NULL) + m_list.append(handler); #elif defined WIN32 - handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe"); - if (handler != NULL) - m_list.append(handler); - handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR); - if (handler != NULL) - m_list.append(handler); + handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe"); + if (handler != NULL) + m_list.append(handler); + handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR); + if (handler != NULL) + m_list.append(handler); #endif } + addIntrinsics(); } /** diff --git a/appl/refind/utils.hpp b/appl/refind/utils.hpp index 1d3ad40..91d1618 100644 --- a/appl/refind/utils.hpp +++ b/appl/refind/utils.hpp @@ -18,6 +18,10 @@ enum { }; class ContextHandler { public: + enum IntrinsicType { + IT_UNDEF, IT_COPY + }; + enum DirMode { DM_UNDEF, DM_TO_PARENT, DM_TO_FILE }; @@ -26,12 +30,16 @@ public: }; public: ContextHandler(); + ContextHandler(IntrinsicType intrinsicType, const QString& text); + IntrinsicType intrinsicType() const; public: QString m_text; QString m_program; QString m_arguments; DirMode m_directoryMode; FileType m_fileType; + IntrinsicType m_intrinsicType; + void setIntrinsicType(const IntrinsicType& intrinsicType); }; class ContextHandlerList { @@ -41,6 +49,7 @@ public: ContextHandlerList(const ContextHandlerList& source); ContextHandlerList& operator =(const ContextHandlerList& source); public: + void addIntrinsics(); void clear(); ContextHandlerList©(const ContextHandlerList& source); QList & list(){ diff --git a/base/ReQStringUtil.cpp b/base/ReQStringUtil.cpp index e6160fb..1bc55da 100644 --- a/base/ReQStringUtil.cpp +++ b/base/ReQStringUtil.cpp @@ -34,6 +34,18 @@ ReString ReQStringUtil::chomp(const ReString& text){ return last == text.length() - 1 ? text : text.mid(0, last + 1); } +/** + * Tests whether a given character is the last of the string and append it if not. + * + * @param value string to test + * @param lastChar the last character + */ +QString& ReQStringUtil::ensureLastChar(QString& value, QChar lastChar){ + if (value.isEmpty() || value.at(value.length() - 1) != lastChar) + value += lastChar; + return value; +} + /** * Extracts the extension of a filename. * diff --git a/base/ReQStringUtil.hpp b/base/ReQStringUtil.hpp index 2ca9374..e3a221c 100644 --- a/base/ReQStringUtil.hpp +++ b/base/ReQStringUtil.hpp @@ -15,6 +15,7 @@ class ReQStringUtil { public: static ReString chomp(const ReString& text); + static QString& ensureLastChar(QString& value, QChar lastChar); static ReString extensionOf(const ReString& filename); static int lengthOfDate(const ReString& text, int start = 0, QDate* value = NULL); -- 2.39.5