summaryrefslogtreecommitdiff
path: root/ui/qt/qt_ui_utils.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-10-09 13:56:27 -0700
committerGerald Combs <gerald@wireshark.org>2015-10-13 02:44:53 +0000
commit7c3800228881f45049b29f491b9d7648c0a5ae5d (patch)
tree9066cdc94579a8d7ff11b5b775e324361b6fe48c /ui/qt/qt_ui_utils.cpp
parent1859ae8aca39d4c8678e8d0f25be3caf6c349393 (diff)
downloadwireshark-7c3800228881f45049b29f491b9d7648c0a5ae5d.tar.gz
Qt: Recent list context menu.
Add a context menu to the main window recent list. Add items that let the user open each file's containing folder and copy the file path to the clipboard. When opening the folder on Windows and OS X try to highlight the file in Explorer or the Finder. Change-Id: I991e8df8ba9f1f8c6385d1a861eb40223cfdd047 Reviewed-on: https://code.wireshark.org/review/10915 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Diffstat (limited to 'ui/qt/qt_ui_utils.cpp')
-rw-r--r--ui/qt/qt_ui_utils.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/ui/qt/qt_ui_utils.cpp b/ui/qt/qt_ui_utils.cpp
index 18be1b58ef..d18efa97b4 100644
--- a/ui/qt/qt_ui_utils.cpp
+++ b/ui/qt/qt_ui_utils.cpp
@@ -37,7 +37,12 @@
#include <QAction>
#include <QDateTime>
+#include <QDesktopServices>
+#include <QDir>
+#include <QFileInfo>
#include <QFontDatabase>
+#include <QProcess>
+#include <QUrl>
#include <QUuid>
/* Make the format_size_flags_e enum usable in C++ */
@@ -193,6 +198,38 @@ bool qStringCaseLessThan(const QString &s1, const QString &s2)
return s1.compare(s2, Qt::CaseInsensitive) < 0;
}
+// http://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt
+void desktop_show_in_folder(const QString file_path)
+{
+ bool success = false;
+
+#if defined(Q_OS_WIN)
+ QString path = QDir::toNativeSeparators(file_path);
+ QString command = "explorer.exe /select," + path;
+ success = QProcess::startDetached(command);
+#elif defined(Q_OS_MAC)
+ QStringList script_args;
+
+ // XXX Find a way to pass special characters here.
+ script_args << "-e"
+ << QString("tell application \"Finder\" to reveal POSIX file \"%1\"")
+ .arg(file_path);
+ if (QProcess::execute("/usr/bin/osascript", script_args) == 0) {
+ success = true;
+ script_args.clear();
+ script_args << "-e"
+ << "tell application \"Finder\" to activate";
+ QProcess::execute("/usr/bin/osascript", script_args);
+ }
+#else
+ // Is there a way to highlight the file using xdg-open?
+#endif
+ if (!success) { // Last resort
+ QFileInfo file_info = file_path;
+ QDesktopServices::openUrl(QUrl::fromLocalFile(file_info.dir().absolutePath()));
+ }
+}
+
/*
* Editor modelines
*