If the application has been started from the source code directory, all Open-File dialogs will start there. If the application has been started from its installation location, all Open-File dialogs will start at ${HOME}. Suggested-by: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx> Signed-off-by: Yordan Karadzhov <ykaradzhov@xxxxxxxxxx> --- kernel-shark/src/KsCaptureDialog.cpp | 6 +++--- kernel-shark/src/KsMainWindow.cpp | 12 ++++++------ kernel-shark/src/KsUtils.hpp | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/kernel-shark/src/KsCaptureDialog.cpp b/kernel-shark/src/KsCaptureDialog.cpp index 1272c2e..57bf7c7 100644 --- a/kernel-shark/src/KsCaptureDialog.cpp +++ b/kernel-shark/src/KsCaptureDialog.cpp @@ -208,7 +208,7 @@ void KsCaptureControl::_importSettings() /* Get the configuration document. */ fileName = QFileDialog::getOpenFileName(this, "Import from Filter", - KS_DIR, + KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -259,7 +259,7 @@ void KsCaptureControl::_exportSettings() QString fileName = QFileDialog::getSaveFileName(this, "Export to File", - KS_DIR, + KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -314,7 +314,7 @@ void KsCaptureControl::_browse() QString fileName = QFileDialog::getSaveFileName(this, "Save File", - KS_DIR, + KsUtils::dialogDir(), "trace-cmd files (*.dat);;All files (*)"); if (!fileName.isEmpty()) diff --git a/kernel-shark/src/KsMainWindow.cpp b/kernel-shark/src/KsMainWindow.cpp index c839aca..65ac71a 100644 --- a/kernel-shark/src/KsMainWindow.cpp +++ b/kernel-shark/src/KsMainWindow.cpp @@ -363,7 +363,7 @@ void KsMainWindow::_open() QString fileName = QFileDialog::getOpenFileName(this, "Open File", - KS_DIR, + KsUtils::dialogDir(), "trace-cmd files (*.dat);;All files (*)"); if (!fileName.isEmpty()) @@ -432,7 +432,7 @@ void KsMainWindow::_importSession() QString fileName = QFileDialog::getOpenFileName(this, "Import Session", - KS_DIR, + KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -463,7 +463,7 @@ void KsMainWindow::_exportSession() QString fileName = QFileDialog::getSaveFileName(this, "Export Filter", - KS_DIR, + KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -512,7 +512,7 @@ void KsMainWindow::_importFilter() if (!kshark_instance(&kshark_ctx)) return; - fileName = QFileDialog::getOpenFileName(this, "Import Filter", KS_DIR, + fileName = QFileDialog::getOpenFileName(this, "Import Filter", KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -540,7 +540,7 @@ void KsMainWindow::_exportFilter() if (!kshark_instance(&kshark_ctx)) return; - fileName = QFileDialog::getSaveFileName(this, "Export Filter", KS_DIR, + fileName = QFileDialog::getSaveFileName(this, "Export Filter", KsUtils::dialogDir(), "Kernel Shark Config files (*.json);;"); if (fileName.isEmpty()) @@ -861,7 +861,7 @@ void KsMainWindow::_pluginAdd() fileNames = QFileDialog::getOpenFileNames(this, "Add KernelShark plugins", - KS_DIR, + KsUtils::dialogDir(), "KernelShark Plugins (*.so);;"); if (fileNames.isEmpty()) diff --git a/kernel-shark/src/KsUtils.hpp b/kernel-shark/src/KsUtils.hpp index c8b5e88..77048ab 100644 --- a/kernel-shark/src/KsUtils.hpp +++ b/kernel-shark/src/KsUtils.hpp @@ -111,6 +111,21 @@ inline QString Ts2String(int64_t ts, int prec) bool matchCPUVisible(struct kshark_context *kshark_ctx, struct kshark_entry *e, int cpu); + +/** + * @brief Get the directory to be used when opening QFileDialog. If the + * application has been started from the source code directory, all + * Open File dialogs will start there. If the application has been + * started from its installation location, all Open File dialogs will + * start at ${HOME}. + */ +inline QString dialogDir() +{ + QString path = QCoreApplication::applicationFilePath(); + + return path.contains(KS_DIR) ? KS_DIR : QDir::homePath(); +} + }; // KsUtils /** Identifier of the Dual Marker active state. */ -- 2.20.1