]> vaikene.ee Git - evaf/commitdiff
* Added commands to copy current file name or all names to the clipboard.
authorEnar Väikene <enar@vaikene.net>
Fri, 2 Dec 2011 07:46:16 +0000 (09:46 +0200)
committerEnar Väikene <enar@vaikene.net>
Fri, 2 Dec 2011 07:46:16 +0000 (09:46 +0200)
* Hack to fix '?' characters in file/directory names. Needs testing on Windows.

src/apps/FileFinder/GUI/gui.cpp
src/apps/FileFinder/GUI/gui.h
src/apps/FileFinder/GUI/version.h

index d1f1c4b36169b9bfa4bee7cd3d93e65ef2be9df9..e664dd7703d484f06e62890ee6ccc8f73a2f04c9 100644 (file)
@@ -83,6 +83,8 @@ FileFinder::GUI::Module::Module()
     , mFinder(0)
     , mOpenFileAction(0)
     , mOpenDirectoryAction(0)
+    , mCopyNameAction(0)
+    , mCopyAllNamesAction(0)
     , wMain(0)
     , wDirectory(0)
     , wRecursive(0)
@@ -281,8 +283,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 +316,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 +406,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);
     }
 }
index c8d36334b5777ad139075b0f1c238b5f20e4cd0b..2c55cc517fae35f09099ba7dab601a95f94125a0 100644 (file)
@@ -112,6 +112,10 @@ private slots:
 
     void openDirectory();
 
+    void copyName();
+
+    void copyAllNames();
+
 
 private: // Members
 
@@ -127,6 +131,8 @@ private: // Members
     /// Actions
     QAction * mOpenFileAction;
     QAction * mOpenDirectoryAction;
+    QAction * mCopyNameAction;
+    QAction * mCopyAllNamesAction;
 
     /// Widgets on the screen
     Internal::MainWidget * wMain;
index 481c3f1df74161a3677c5ba03dc0cf6ec5fe10b3..248d5e09afb2762815c0c0ee156c39cfa7b87412 100644 (file)
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,4,4
+#define VER_FILE_VERSION                0,1,5,5
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.4.4\0"
+#define VER_FILE_VERSION_STR            "0.1.5.5\0"
 
 /**
  * Module/library name (shall end with \0)