]> vaikene.ee Git - evaf/blobdiff - src/apps/FileFinder/GUI/gui.cpp
Warning fixes and copyright update.
[evaf] / src / apps / FileFinder / GUI / gui.cpp
index 29dcd712b3280e4aa22d3d37ee4dbce38f32f592..b0531af0ca42db36b7c36d97df721371ebe9dae3 100644 (file)
@@ -3,7 +3,7 @@
  * @brief GUI for the FileFinder application
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2019 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -18,7 +18,6 @@
  */
 
 #include "gui.h"
-#include "version.h"
 
 #include "Engine/iFileFinder"
 
 #include <Common/iApp>
 #include <SdiWindow/iSdiWindow>
 
-#include <QtGui>
+#include <QtWidgets>
 
 VER_EXPORT_VERSION_INFO()
-Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR, eVaf::FileFinder::GUI::Module)
 
 using namespace eVaf;
 
@@ -44,7 +42,7 @@ void FileFinder::GUI::Internal::MainWidget::keyPressEvent(QKeyEvent * e)
         switch (e->key()) {
             case Qt::Key_Enter:
             case Qt::Key_Return: {
-                QList<QPushButton *> buttons = qFindChildren<QPushButton *>(this);
+                QList<QPushButton *> buttons = findChildren<QPushButton *>();
                 foreach (QPushButton * btn, buttons) {
                     if (btn->isDefault() && btn->isVisible()) {
                         if (btn->isEnabled())
@@ -80,17 +78,19 @@ int const FileFinder::GUI::Module::MaxHistoryItems = 20;
 FileFinder::GUI::Module::Module()
     : Plugins::iPlugin()
     , mReady(false)
-    , mFinder(0)
-    , mOpenFileAction(0)
-    , mOpenDirectoryAction(0)
-    , wMain(0)
-    , wDirectory(0)
-    , wRecursive(0)
-    , wIncludeNames(0)
-    , wExcludeNames(0)
-    , wIncludeContent(0)
-    , wExcludeContent(0)
-    , wFind(0)
+    , mFinder(nullptr)
+    , mOpenFileAction(nullptr)
+    , mOpenDirectoryAction(nullptr)
+    , mCopyNameAction(nullptr)
+    , mCopyAllNamesAction(nullptr)
+    , wMain(nullptr)
+    , wDirectory(nullptr)
+    , wRecursive(nullptr)
+    , wIncludeNames(nullptr)
+    , wExcludeNames(nullptr)
+    , wIncludeContent(nullptr)
+    , wExcludeContent(nullptr)
+    , wFind(nullptr)
 {
     setObjectName(QString("%1.Module").arg(VER_MODULE_NAME_STR));
 
@@ -107,18 +107,18 @@ bool FileFinder::GUI::Module::init(QString const & args)
     Q_UNUSED(args)
 
     // Get the iFileFinder interface
-    EVAF_TEST_X((mFinder = evafQueryInterface<FileFinder::iFileFinder>("iFileFinder")), "No iFileFinder interface");
+    EVAF_TEST_X((mFinder = evafQueryInterface<FileFinder::iFileFinder>("iFileFinder")), "No iFileFinder interface")
     connect(mFinder, SIGNAL(found(QString,QString)), this, SLOT(found(QString,QString)));
     connect(mFinder, SIGNAL(finished(bool)), this, SLOT(finished(bool)));
 
     // Get the main window interface and fill it with widgets
     SdiWindow::iSdiWindow * win = evafQueryInterface<SdiWindow::iSdiWindow>("iSdiWindow");
-    EVAF_TEST_X(win, "No iSdiWindow interface");
+    EVAF_TEST_X(win, "No iSdiWindow interface")
 
     // Create the main widget for this window
     wMain = new Internal::MainWidget;
     connect(wMain, SIGNAL(quit()), qApp, SLOT(quit()));
-    win->addWidget(wMain);
+    win->addPanel("FileFinder", wMain);
 
     // Create actions for the window and widgets on it
     createActions();
@@ -140,14 +140,14 @@ void FileFinder::GUI::Module::done()
 {
     mReady = false;
 
-    mFinder = 0;
+    mFinder = nullptr;
 
     /*
      * Widgets are deleted by the SdiWindow module. We use wMain to track calls to done() without
      * proper init().
      */
     if (wMain) {
-        wMain = 0;
+        wMain = nullptr;
         saveHistory();
     }
 
@@ -281,8 +281,7 @@ void FileFinder::GUI::Module::createWidgets()
 
     wResults = new QListWidget;
     wResults->setContextMenuPolicy(Qt::ActionsContextMenu);
-    wResults->addAction(mOpenFileAction);
-    wResults->addAction(mOpenDirectoryAction);
+    wResults->addActions(QList<QAction *>() << mOpenFileAction << mOpenDirectoryAction << mCopyNameAction << mCopyAllNamesAction);
     connect(wResults, SIGNAL(currentRowChanged(int)), this, SLOT(currentRowChanged(int)));
     connect(wResults, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openFile(QModelIndex)));
     vbox->addWidget(wResults);
@@ -315,6 +314,14 @@ void FileFinder::GUI::Module::createActions()
     mOpenDirectoryAction = new QAction(tr("Open &location"), wMain);
     mOpenDirectoryAction->setEnabled(false);
     connect(mOpenDirectoryAction, SIGNAL(triggered()), this, SLOT(openDirectory()));
+
+    mCopyNameAction = new QAction(tr("&Copy name"), wMain);
+    mCopyNameAction->setEnabled(false);
+    connect(mCopyNameAction, SIGNAL(triggered()), this, SLOT(copyName()));
+
+    mCopyAllNamesAction = new QAction(tr("Copy &all names"), wMain);
+    connect(mCopyAllNamesAction, SIGNAL(triggered()), this, SLOT(copyAllNames()));
+
 }
 
 void FileFinder::GUI::Module::browseDirectory()
@@ -397,19 +404,52 @@ void FileFinder::GUI::Module::currentRowChanged(int currentRow)
 {
     mOpenFileAction->setEnabled(currentRow >= 0);
     mOpenDirectoryAction->setEnabled(currentRow >= 0);
+    mCopyNameAction->setEnabled(currentRow >= 0);
 }
 
 void FileFinder::GUI::Module::openFile(QModelIndex const & index)
 {
     Q_UNUSED(index)
-    if (wResults->currentItem())
-        QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(wResults->currentItem()->text())));
+    if (wResults->currentItem()) {
+        QString t = wResults->currentItem()->text();
+        t.replace("?", "\0453f");
+        QDesktopServices::openUrl(QUrl::fromEncoded(QString("file:///%1").arg(t).toUtf8()));
+    }
 }
 
 void FileFinder::GUI::Module::openDirectory()
 {
     if (wResults->currentItem()) {
-        QFileInfo fi(wResults->currentItem()->text());
-        QDesktopServices::openUrl(QUrl(QString("file:///%1").arg(fi.path())));
+        QString t = wResults->currentItem()->text();
+        t.replace("?", "\0453f");
+        QFileInfo fi(t);
+        QDesktopServices::openUrl(QUrl::fromEncoded(QString("file:///%1").arg(fi.path()).toUtf8()));
+    }
+}
+
+void FileFinder::GUI::Module::copyName()
+{
+    if (wResults->currentItem()) {
+        QClipboard * cb = QApplication::clipboard();
+        if (cb)
+            cb->setText(wResults->currentItem()->text());
+    }
+}
+
+void FileFinder::GUI::Module::copyAllNames()
+{
+#ifdef Q_OS_WIN32
+    static char const * const EOLN = "\r\n";
+#else
+    static char const * const EOLN = "\n";
+#endif
+
+    QString t;
+    for (int i = 0; i < wResults->count(); ++i)
+        t.append(wResults->item(i)->text() + EOLN);
+    if (!t.isEmpty()) {
+        QClipboard * cb = QApplication::clipboard();
+        if (cb)
+            cb->setText(t);
     }
 }