Blob Blame History Raw
commit f15e34b06bd25dce5fafa68eeee04f2b5a27e9a0
Author: Nathan Scott <nathans@redhat.com>
Date:   Fri May 14 11:10:56 2021 +1000

    pmchart: save changes to users prefered archive location
    
    Use the users QSettings configuration file to hold any new
    preference given for archive locations, and restore this at
    pmchart startup time.
    
    Similarly save and restore locations for exported images.
    
    While in here, some janitorial work has been done in terms
    of dropping paths to configuration files not used in many,
    many years now.
    
    Resolves Red Hat BZ #1615742

diff --git a/src/pmchart/chartdialog.cpp b/src/pmchart/chartdialog.cpp
index 3873abe9c..78ca0041b 100644
--- a/src/pmchart/chartdialog.cpp
+++ b/src/pmchart/chartdialog.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013-2015, Red Hat.
+ * Copyright (c) 2013-2015,2021 Red Hat.
  * Copyright (c) 2007-2008, Aconex.  All Rights Reserved.
  * 
  * This program is free software; you can redistribute it and/or modify it
@@ -374,10 +374,17 @@ void ChartDialog::archiveButtonClicked()
     af->setAcceptMode(QFileDialog::AcceptOpen);
     af->setIconProvider(fileIconProvider);
     af->setWindowTitle(tr("Add Archive"));
-    af->setDirectory(QDir::toNativeSeparators(QDir::homePath()));
+    af->setDirectory(globalSettings.lastArchivePath);
 
-    if (af->exec() == QDialog::Accepted)
+    if (af->exec() == QDialog::Accepted) {
 	al = af->selectedFiles();
+	QString path = QFileInfo(al.at(0)).dir().absolutePath();
+	if (globalSettings.lastArchivePath != path) {
+	    globalSettings.lastArchivePath = path;
+	    globalSettings.lastArchivePathModified = true;
+	}
+    }
+
     for (QStringList::Iterator it = al.begin(); it != al.end(); ++it) {
 	QString archive = *it;
 	if ((sts = archiveGroup->use(PM_CONTEXT_ARCHIVE, archive)) < 0) {
diff --git a/src/pmchart/exportdialog.cpp b/src/pmchart/exportdialog.cpp
index fe926ebfa..db38d16db 100644
--- a/src/pmchart/exportdialog.cpp
+++ b/src/pmchart/exportdialog.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2007, Aconex.  All Rights Reserved.
- * Copyright (c) 2013, Red Hat, Inc.
+ * Copyright (c) 2013,2021 Red Hat, Inc.
  * 
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -48,7 +48,7 @@ void ExportDialog::languageChange()
 void ExportDialog::init()
 {
     QChar	sep(pmPathSeparator());
-    QString	imgfile = QDir::toNativeSeparators(QDir::homePath());
+    QString	imgfile = globalSettings.lastExportPath;
 
     my.quality = 0;
     my.format = strdup("png");
@@ -122,10 +122,17 @@ void ExportDialog::displayQualitySlider()
 void ExportDialog::filePushButton_clicked()
 {
     ExportFileDialog file(this);
-
-    file.setDirectory(QDir::toNativeSeparators(QDir::homePath()));
-    if (file.exec() == QDialog::Accepted)
-	fileLineEdit->setText(file.selectedFiles().at(0));
+    file.setDirectory(globalSettings.lastExportPath);
+
+    if (file.exec() == QDialog::Accepted) {
+	QString selection = file.selectedFiles().at(0);
+	QString path = QFileInfo(selection).dir().absolutePath();
+	if (globalSettings.lastExportPath != path) {
+	    globalSettings.lastExportPath = path;
+	    globalSettings.lastExportPathModified = true;
+	}
+	fileLineEdit->setText(selection);
+    }
 }
 
 void ExportDialog::formatComboBox_currentIndexChanged(QString suffix)
diff --git a/src/pmchart/main.cpp b/src/pmchart/main.cpp
index 08de404d3..ef07fa012 100644
--- a/src/pmchart/main.cpp
+++ b/src/pmchart/main.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014,2016, Red Hat.
+ * Copyright (c) 2014,2016,2021 Red Hat.
  * Copyright (c) 2006, Ken McDonell.  All Rights Reserved.
  * Copyright (c) 2007-2009, Aconex.  All Rights Reserved.
  * 
@@ -234,6 +234,14 @@ void writeSettings(void)
 	else
 	    userSettings.remove("savedHosts");
     }
+    if (globalSettings.lastArchivePathModified) {
+	globalSettings.lastArchivePathModified = false;
+	userSettings.setValue("lastArchivePath", globalSettings.lastArchivePath);
+    }
+    if (globalSettings.lastExportPathModified) {
+	globalSettings.lastExportPathModified = false;
+	userSettings.setValue("lastExportPath", globalSettings.lastExportPath);
+    }
 
     userSettings.endGroup();
 }
@@ -373,6 +381,21 @@ static void readSettings(void)
 	globalSettings.savedHosts =
 			userSettings.value("savedHosts").toStringList();
 
+    //
+    // Saved filesystem search paths
+    //
+    globalSettings.lastArchivePathModified = false;
+    QChar sep(pmPathSeparator());
+    QString pmlogger = QDir::toNativeSeparators(QDir::homePath());
+    pmlogger.append(sep).append(".pcp").append(sep).append("pmlogger");
+    globalSettings.lastArchivePath =
+    		userSettings.value("lastArchivePath", pmlogger).toString();
+    globalSettings.lastExportPathModified = false;
+    QString pictures = QDir::toNativeSeparators(QDir::homePath());
+    pictures.append(sep).append("Pictures");
+    globalSettings.lastExportPath =
+    		userSettings.value("lastExportPath", pictures).toString();
+
     userSettings.endGroup();
 }
 
@@ -475,6 +498,7 @@ main(int argc, char ** argv)
     QApplication a(argc, argv);
     setupEnvironment();
     readSettings();
+    atexit(writeSettings);
 
     opts.flags = PM_OPTFLAG_MULTI | PM_OPTFLAG_MIXED;
     opts.short_options = "A:a:Cc:D:f:F:g:h:H:Ln:o:O:p:s:S:T:t:Vv:WzZ:?";
diff --git a/src/pmchart/main.h b/src/pmchart/main.h
index ec79ec9a4..4be939186 100644
--- a/src/pmchart/main.h
+++ b/src/pmchart/main.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Red Hat.
+ * Copyright (c) 2014,2021 Red Hat.
  * Copyright (c) 2007, Aconex.  All Rights Reserved.
  * Copyright (c) 2006, Ken McDonell.  All Rights Reserved.
  * 
@@ -71,6 +71,12 @@ typedef struct {
 	// Saved Hosts
 	QStringList savedHosts;
 	bool savedHostsModified;
+
+	// Filesysten Paths
+	QString lastArchivePath;
+	bool lastArchivePathModified;
+	QString lastExportPath;
+	bool lastExportPathModified;
 } Settings;
 
 extern Settings globalSettings;
diff --git a/src/pmchart/openviewdialog.cpp b/src/pmchart/openviewdialog.cpp
index d2eefa028..ed5a9f943 100644
--- a/src/pmchart/openviewdialog.cpp
+++ b/src/pmchart/openviewdialog.cpp
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2013, Red Hat.
- * Copyright (c) 2007-2009, Aconex.  All Rights Reserved.
+ * Copyright (c) 2013,2021 Red Hat.
+ * Copyright (c) 2007-2009 Aconex.  All Rights Reserved.
  * 
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -36,36 +36,16 @@ OpenViewDialog::OpenViewDialog(QWidget *parent) : QDialog(parent)
 
     QDir dir;
     QChar sep(pmPathSeparator());
-    QString sys = my.systemDir = pmGetConfig("PCP_VAR_DIR");
-    my.systemDir.append(sep);
-    my.systemDir.append("config");
-    my.systemDir.append(sep);
-    my.systemDir.append("kmchart");
-    if (dir.exists(my.systemDir))
-	pathComboBox->addItem(fileIconProvider->icon(QFileIconProvider::Folder),
-			  my.systemDir);
-    my.systemDir = sys;
-    my.systemDir.append(sep);
-    my.systemDir.append("config");
-    my.systemDir.append(sep);
-    my.systemDir.append("pmchart");
+    my.systemDir = pmGetConfig("PCP_VAR_DIR");
+    my.systemDir.append(sep).append("config");
+    my.systemDir.append(sep).append("pmchart");
     if (dir.exists(my.systemDir))
 	pathComboBox->addItem(fileIconProvider->icon(QFileIconProvider::Folder),
 			  my.systemDir);
 
-    QString home = my.userDir = QDir::toNativeSeparators(QDir::homePath());
-    my.userDir.append(sep);
-    my.userDir.append(".pcp");
-    my.userDir.append(sep);
-    my.userDir.append("kmchart");
-    if (dir.exists(my.userDir))
-	pathComboBox->addItem(fileIconProvider->icon(QFileIconProvider::Folder),
-			  my.userDir);
-    my.userDir = home;
-    my.userDir.append(sep);
-    my.userDir.append(".pcp");
-    my.userDir.append(sep);
-    my.userDir.append("pmchart");
+    QString home = my.userDir = QDir::homePath();
+    my.userDir.append(sep).append(".pcp");
+    my.userDir.append(sep).append("pmchart");
     if (dir.exists(my.userDir))
 	pathComboBox->addItem(fileIconProvider->icon(QFileIconProvider::Folder),
 			  my.userDir);
@@ -245,10 +225,17 @@ void OpenViewDialog::archiveAdd()
     af->setAcceptMode(QFileDialog::AcceptOpen);
     af->setWindowTitle(tr("Add Archive"));
     af->setIconProvider(fileIconProvider);
-    af->setDirectory(QDir::toNativeSeparators(QDir::homePath()));
+    af->setDirectory(globalSettings.lastArchivePath);
 
-    if (af->exec() == QDialog::Accepted)
+    if (af->exec() == QDialog::Accepted) {
 	al = af->selectedFiles();
+	QString path = QFileInfo(al.at(0)).dir().absolutePath();
+	if (globalSettings.lastArchivePath != path) {
+	    globalSettings.lastArchivePath = path;
+	    globalSettings.lastArchivePathModified = true;
+	}
+    }
+
     for (QStringList::Iterator it = al.begin(); it != al.end(); ++it) {
 	QString archive = *it;
 	if ((sts = archiveGroup->use(PM_CONTEXT_ARCHIVE, archive)) < 0) {
diff --git a/src/pmchart/recorddialog.cpp b/src/pmchart/recorddialog.cpp
index 35242078a..69a8a89c8 100644
--- a/src/pmchart/recorddialog.cpp
+++ b/src/pmchart/recorddialog.cpp
@@ -33,26 +33,7 @@ void RecordDialog::languageChange()
 
 void RecordDialog::init(Tab *tab)
 {
-    QChar	sep(pmPathSeparator());
-    QString	pmlogger = QDir::toNativeSeparators(QDir::homePath());
-    QString	view, folio, archive;
-
-    pmlogger.append(sep);
-    pmlogger.append(".pcp");
-    pmlogger.append(sep);
-    pmlogger.append("pmlogger");
-    pmlogger.append(sep);
-    view = folio = archive = pmlogger;
-
-    view.append("[date].view");
-    viewLineEdit->setText(view);
-    folio.append("[date].folio");
-    folioLineEdit->setText(folio);
-    archive.append("[host]");
-    archive.append(sep);
-    archive.append("[date]");
-    archiveLineEdit->setText(archive);
-
+    initText();
     my.tab = tab;
     my.units = QmcTime::Seconds;
     deltaLineEdit->setText(
@@ -62,6 +43,23 @@ void RecordDialog::init(Tab *tab)
     allGadgetsRadioButton->setChecked(true);
 }
 
+void RecordDialog::initText()
+{
+    QChar	sep(pmPathSeparator());
+
+    my.viewText = globalSettings.lastArchivePath;
+    my.viewText.append(sep).append("[date].view");
+    viewLineEdit->setText(my.viewText);
+
+    my.folioText = globalSettings.lastArchivePath;
+    my.folioText.append(sep).append("[date].folio");
+    folioLineEdit->setText(my.folioText);
+
+    my.archiveText = globalSettings.lastArchivePath;
+    my.archiveText.append(sep).append("[host]").append(sep).append("[date]");
+    archiveLineEdit->setText(my.archiveText);
+}
+
 void RecordDialog::selectedRadioButton_clicked()
 {
     selectedRadioButton->setChecked(true);
@@ -83,53 +81,41 @@ void RecordDialog::deltaUnitsComboBox_activated(int value)
 
 void RecordDialog::viewPushButton_clicked()
 {
-    RecordFileDialog view(this);
+    initText();
 
-    QChar sep(pmPathSeparator());
-    QString pmlogger = QDir::toNativeSeparators(QDir::homePath());
-    pmlogger.append(sep);
-    pmlogger.append(".pcp");
-    pmlogger.append(sep);
-    pmlogger.append("pmlogger");
-    pmlogger.append(sep);
+    RecordFileDialog view(this);
+    view.setDirectory(my.viewText);
 
-    view.setDirectory(pmlogger);
-    if (view.exec() == QDialog::Accepted)
-	viewLineEdit->setText(view.selectedFiles().at(0));
+    if (view.exec() == QDialog::Accepted) {
+	QString selection = view.selectedFiles().at(0);
+	viewLineEdit->setText(selection);
+    }
 }
 
 void RecordDialog::folioPushButton_clicked()
 {
-    RecordFileDialog folio(this);
+    initText();
 
-    QChar sep(pmPathSeparator());
-    QString pmlogger = QDir::toNativeSeparators(QDir::homePath());
-    pmlogger.append(sep);
-    pmlogger.append(".pcp");
-    pmlogger.append(sep);
-    pmlogger.append("pmlogger");
-    pmlogger.append(sep);
+    RecordFileDialog folio(this);
+    folio.setDirectory(my.folioText);
 
-    folio.setDirectory(pmlogger);
-    if (folio.exec() == QDialog::Accepted)
-	folioLineEdit->setText(folio.selectedFiles().at(0));
+    if (folio.exec() == QDialog::Accepted) {
+	QString selection = folio.selectedFiles().at(0);
+	folioLineEdit->setText(selection);
+    }
 }
 
 void RecordDialog::archivePushButton_clicked()
 {
-    RecordFileDialog archive(this);
+    initText();
 
-    QChar sep(pmPathSeparator());
-    QString pmlogger = QDir::toNativeSeparators(QDir::homePath());
-    pmlogger.append(sep);
-    pmlogger.append(".pcp");
-    pmlogger.append(sep);
-    pmlogger.append("pmlogger");
-    pmlogger.append(sep);
+    RecordFileDialog archive(this);
+    archive.setDirectory(my.archiveText);
 
-    archive.setDirectory(pmlogger);
-    if (archive.exec() == QDialog::Accepted)
-	archiveLineEdit->setText(archive.selectedFiles().at(0));
+    if (archive.exec() == QDialog::Accepted) {
+	QString selection = archive.selectedFiles().at(0);
+	archiveLineEdit->setText(selection);
+    }
 }
 
 // substitute "local:" or "localhost" with actual hostname
diff --git a/src/pmchart/recorddialog.h b/src/pmchart/recorddialog.h
index 784530353..67011b934 100644
--- a/src/pmchart/recorddialog.h
+++ b/src/pmchart/recorddialog.h
@@ -47,11 +47,17 @@ protected slots:
     virtual void languageChange();
 
 private:
+    void initText(void);
+
     struct {
 	Tab *tab;
 	QString delta;
 	QmcTime::DeltaUnits units;
 
+	QString viewText;
+	QString folioText;
+	QString archiveText;
+
 	QString view;
 	QString folio;
 	QStringList hosts;
diff --git a/src/pmchart/saveviewdialog.cpp b/src/pmchart/saveviewdialog.cpp
index b0363a19f..1a8b094f4 100644
--- a/src/pmchart/saveviewdialog.cpp
+++ b/src/pmchart/saveviewdialog.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Red Hat.
+ * Copyright (c) 2014,2021 Red Hat.
  * Copyright (c) 2007-2009, Aconex.  All Rights Reserved.
  * 
  * This program is free software; you can redistribute it and/or modify it
@@ -33,22 +33,14 @@ SaveViewDialog::SaveViewDialog(QWidget* parent) : QDialog(parent)
 	SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
 	this, SLOT(dirListView_selectionChanged()));
 
+    my.hostDynamic = true;
+    my.sizeDynamic = true;
+
     QDir dir;
     QChar sep(pmPathSeparator());
     QString home = my.userDir = QDir::toNativeSeparators(QDir::homePath());
-    my.userDir.append(sep);
-    my.userDir.append(".pcp");
-    my.userDir.append(sep);
-    my.userDir.append("kmchart");
-    if (!dir.exists(my.userDir)) {
-	my.userDir = home;
-	my.userDir.append(sep);
-	my.userDir.append(".pcp");
-	my.userDir.append(sep);
-	my.userDir.append("pmchart");
-    }
-    my.hostDynamic = true;
-    my.sizeDynamic = true;
+    my.userDir.append(sep).append(".pcp");
+    my.userDir.append(sep).append("pmchart");
 
     pathComboBox->addItem(fileIconProvider->icon(QFileIconProvider::Folder),
 			  my.userDir);
diff --git a/src/pmchart/view.cpp b/src/pmchart/view.cpp
index 16633243f..4fc79fd09 100644
--- a/src/pmchart/view.cpp
+++ b/src/pmchart/view.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2006, Ken McDonell.  All Rights Reserved.
- * Copyright (c) 2013, Red Hat Inc.
+ * Copyright (c) 2013,2021 Red Hat.
  * 
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the
@@ -281,37 +281,17 @@ bool OpenViewDialog::openView(const char *path)
 
 	strcpy(_fname, path);
 	if ((f = fopen(_fname, "r")) == NULL) {
-	    // not found, start the great hunt
-	    // try user's pmchart dir ...
+	    // not found, try users pmchart dir
 	    pmsprintf(_fname, sizeof(_fname),
 			"%s%c" ".pcp%c" "pmchart%c" "%s",
 			(const char *)homepath.toLatin1(), sep, sep, sep, path);
 	    if ((f = fopen(_fname, "r")) == NULL) {
-		// try system pmchart dir
+		// not found, try system pmchart dir
 		pmsprintf(_fname, sizeof(_fname),
 			    "%s%c" "config%c" "pmchart%c" "%s",
 			    pmGetConfig("PCP_VAR_DIR"), sep, sep, sep, path);
-		if ((f = fopen(_fname, "r")) == NULL) {
-		    // try user's kmchart dir
-		    pmsprintf(_fname, sizeof(_fname),
-				"%s%c" ".pcp%c" "kmchart%c" "%s",
-				(const char *)homepath.toLatin1(),
-				sep, sep, sep, path);
-		    if ((f = fopen(_fname, "r")) == NULL) {
-			// try system kmchart dir
-			pmsprintf(_fname, sizeof(_fname),
-				    "%s%c" "config%c" "kmchart%c" "%s",
-				    pmGetConfig("PCP_VAR_DIR"),
-				    sep, sep, sep, path);
-			if ((f = fopen(_fname, "r")) == NULL) {
-			    pmsprintf(_fname, sizeof(_fname),
-					"%s%c" "config%c" "pmchart%c" "%s",
-					pmGetConfig("PCP_VAR_DIR"),
-					sep, sep, sep, path);
-			    goto noview;
-			}
-		    }
-		}
+		if ((f = fopen(_fname, "r")) == NULL)
+		    goto noview;
 	    }
 	}
 	// check for executable and __pmProcessPipe() as needed