]> gitweb.hamatoma.de Git - reqt/commitdiff
Refind: drag works
authorhama <hama@siduction.net>
Sun, 24 May 2015 23:23:28 +0000 (01:23 +0200)
committerhama <hama@siduction.net>
Sun, 24 May 2015 23:23:28 +0000 (01:23 +0200)
13 files changed:
appl/.gitignore [new file with mode: 0644]
appl/refind.ico [new file with mode: 0644]
appl/refind/dialogoptions.cpp
appl/refind/filetablewidget.cpp [new file with mode: 0644]
appl/refind/filetablewidget.hpp [new file with mode: 0644]
appl/refind/mainwindow.cpp
appl/refind/mainwindow.hpp
appl/refind/mainwindow.ui
appl/refind/refind.pro
appl/refind/utils.cpp
appl/refind/utils.hpp
base/ReQStringUtil.cpp
base/ReQStringUtil.hpp

diff --git a/appl/.gitignore b/appl/.gitignore
new file mode 100644 (file)
index 0000000..5ec952f
--- /dev/null
@@ -0,0 +1,2 @@
+build-reviewer-Desktop5-Debug/
+
diff --git a/appl/refind.ico b/appl/refind.ico
new file mode 100644 (file)
index 0000000..b48307f
Binary files /dev/null and b/appl/refind.ico differ
index 358cc3db62b823480e571d073708bca28e17c1b7..61bda5f95db4a7ae551e1aa50593ba6c99b4144d 100644 (file)
  * @param dialog    the option dialog
  */
 TableKeyPressEater::TableKeyPressEater(DialogOptions* dialog) :
-    QObject(dialog),
-    m_dialog(dialog)
-{
+         QObject(dialog), m_dialog(dialog){
 }
 
-
 /**
  * Event handler for the up/down keys of the table widget.
  *
@@ -33,16 +30,15 @@ TableKeyPressEater::TableKeyPressEater(DialogOptions* dialog) :
  * @param event     the current event
  * @return
  */
-bool TableKeyPressEater::eventFilter(QObject *obj, QEvent *event)
-{
-    if (event->type() == QEvent::KeyPress){
-        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(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 <QKeyEvent*>(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<QTableWidgetSelectionRange> selections = ui->tableWidget->selectedRanges();
-    QList<QTableWidgetSelectionRange>::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 <QTableWidgetSelectionRange>::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 (file)
index 0000000..bb2ad98
--- /dev/null
@@ -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 <QMouseEvent>
+#include <QApplication>
+#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 (file)
index 0000000..597861b
--- /dev/null
@@ -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 <QTableWidget>
+
+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
index 170fd211146e5908d1b39bfc5a6fa76ad501de5e..2a98cc0e116006d49ec27e1d1282382df54c1dcc 100644 (file)
@@ -27,6 +27,7 @@
 #include <QMouseEvent>
 #include <QDrag>
 #include <QMimeData>
+#include <QPainter>
 #include <QProcess>
 #include <QMessageBox>
 
@@ -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 <QTableWidgetSelectionRange>::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 <QString, QString>& 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 <QString, QString>& hash){
  * @return      <code>text</code> with the esc sequences replaced
  */
 QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo,
-   QMap <QString, QString>& placeholders){
-   QString rc = combo->currentText();
-   QString error;
-   if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error))
-      guiError(combo, error);
-   return replaceEscSequences(rc);
+QMap <QString, QString>& 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);
    }
 }
+}
index 6585f8febfdae1aa4bb4750b7f791c09762c2054..2d15782314e708947a898c27061f736c1dd9f847 100644 (file)
@@ -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 <QString, QString>& 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 <QString, QString>& placeholders);
index a8543deb1729da93ff622e3dd75fdf72d85c3b9f..99ba460104bea424105e0f48377bc3cf84b56b52 100644 (file)
        </widget>
       </item>
       <item>
-       <widget class="QTableWidget" name="tableWidget">
+       <widget class="FileTableWidget" name="tableWidget">
         <property name="editTriggers">
          <set>QAbstractItemView::NoEditTriggers</set>
         </property>
         <property name="dragEnabled">
          <bool>true</bool>
         </property>
+        <property name="dragDropMode">
+         <enum>QAbstractItemView::DragDrop</enum>
+        </property>
+        <property name="defaultDropAction">
+         <enum>Qt::CopyAction</enum>
+        </property>
         <property name="selectionBehavior">
          <enum>QAbstractItemView::SelectRows</enum>
         </property>
   </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+  <customwidget>
+   <class>FileTableWidget</class>
+   <extends>QTableWidget</extends>
+   <header>filetablewidget.hpp</header>
+  </customwidget>
+ </customwidgets>
  <tabstops>
   <tabstop>comboBoxDirectory</tabstop>
   <tabstop>pushButtonUp</tabstop>
index 5e62b72a5dfe3e173c8527599a1d6ffa9429ef1d..669aac4a90c009a56b5dd0420fade9519ebe2e21 100644 (file)
@@ -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
 
index 9a54c42acdfca54fcad4ae155124717fcbb006cc..bf6f2c5c6d65ba8479c3c84a44ed2b10f0d49926 100644 (file)
@@ -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 <ContextHandler*>::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();
 }
 
 /**
index 1d3ad406a4e8acc4cf2c8d5a5b9c06eb41fcfdba..91d161843abc408e06209933ce799d3fd90f16f8 100644 (file)
@@ -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&copy(const ContextHandlerList& source);
    QList <ContextHandler*>& list(){
index e6160fb60c43c31653ffbb6011c0d53cd0518f7e..1bc55da227c4a4a01bb3c68dca80c061aff805ad 100644 (file)
@@ -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.
  *
index 2ca937448608011b725df75dac66df92dc91edb9..e3a221ccdb87a4aa518f65e84723ca1ba374ec22 100644 (file)
@@ -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);