diff mbox series

[v3,3/8] kernel-shark: Add logic for the initial path of Open-File dialogs

Message ID 20190419135036.19340-4-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series Various modifications and fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov April 19, 2019, 1:50 p.m. UTC
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@goodmis.org>
Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 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(-)

Comments

Steven Rostedt April 19, 2019, 4:23 p.m. UTC | #1
On Fri, 19 Apr 2019 16:50:31 +0300
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> 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}.

Why can't the open dialog boxes start at where the program was executed
from?

Also, if one were to change the location of the open dialog, can we
save that and if the open dialog happens again, it will open where the
user left off the last time (like Mozilla does).

-- Steve

> 
> Suggested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>
diff mbox series

Patch

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. */