@@ -397,20 +397,7 @@ void KsMainWindow::_exportSession()
if (!fileName.endsWith(".json")) {
fileName += ".json";
if (QFileInfo(fileName).exists()) {
- QString msg("A file ");
- QMessageBox msgBox;
-
- msg += fileName;
- msg += " already exists.";
- msgBox.setText(msg);
- msgBox.setInformativeText("Do you want to replace it?");
-
- msgBox.setStandardButtons(QMessageBox::Save |
- QMessageBox::Cancel);
-
- msgBox.setDefaultButton(QMessageBox::Cancel);
-
- if (msgBox.exec() == QMessageBox::Cancel)
+ if (!KsWidgetsLib::fileExistsDialog(fileName))
return;
}
}
@@ -461,8 +448,13 @@ void KsMainWindow::_exportFilter()
if (fileName.isEmpty())
return;
- if (!fileName.endsWith(".json"))
+ if (!fileName.endsWith(".json")) {
fileName += ".json";
+ if (QFileInfo(fileName).exists()) {
+ if (!KsWidgetsLib::fileExistsDialog(fileName))
+ return;
+ }
+ }
kshark_export_all_event_filters(kshark_ctx, &conf);
kshark_save_config_file(fileName.toStdString().c_str(), conf);
@@ -76,6 +76,35 @@ KsMessageDialog::KsMessageDialog(QString message, QWidget *parent)
this->setLayout(&_layout);
}
+namespace KsWidgetsLib
+{
+
+/**
+ * @brief Launch a File exists dialog. Use this function to ask the user
+ * before overwriting an existing file.
+ *
+ * @param fileName: the name of the file.
+ *
+ * @returns True if the user wants to overwrite the file. Otherwise
+ */
+bool fileExistsDialog(QString fileName)
+{
+ QString msg("A file ");
+ QMessageBox msgBox;
+
+ msg += fileName;
+ msg += " already exists.";
+ msgBox.setText(msg);
+ msgBox.setInformativeText("Do you want to replace it?");
+
+ msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Cancel);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+
+ return (msgBox.exec() == QMessageBox::Save);
+}
+
+}; // KsWidgetsLib
+
/**
* @brief Create KsCheckBoxWidget.
*
@@ -66,6 +66,13 @@ public:
/** The width of the KsMessageDialog widget. */
#define KS_MSG_DIALOG_WIDTH (SCREEN_WIDTH / 10)
+namespace KsWidgetsLib
+{
+
+bool fileExistsDialog(QString fileName);
+
+}; // KsWidgetsLib
+
/**
* The KsCheckBoxWidget class is the base class of all CheckBox widget used
* by KernelShark.
A helper function for launching a "File exists" dialog is added to KsWidgetsLib. This function asks the user, before overwriting an existing file. The "File exists" dialog function is used by the KsMainWindow widget when saving the configuration of the filters and sessions. Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com> --- kernel-shark-qt/src/KsMainWindow.cpp | 22 +++++++-------------- kernel-shark-qt/src/KsWidgetsLib.cpp | 29 ++++++++++++++++++++++++++++ kernel-shark-qt/src/KsWidgetsLib.hpp | 7 +++++++ 3 files changed, 43 insertions(+), 15 deletions(-)