[education/rkward] /: Remove startup dialog

Thomas Friedrichsmeier null at kde.org
Sun Apr 24 14:54:25 BST 2022


Git commit b5ca2de22fcfd57d6a294e5f94419945be1fe827 by Thomas Friedrichsmeier.
Committed on 24/04/2022 at 13:54.
Pushed by tfry into branch 'master'.

Remove startup dialog

M  +1    -2    ChangeLog
M  +0    -1    rkward/dialogs/CMakeLists.txt
D  +0    -204  rkward/dialogs/startupdialog.cpp
D  +0    -73   rkward/dialogs/startupdialog.h
M  +2    -10   rkward/rkward.cpp
M  +17   -20   rkward/settings/rksettingsmodulegeneral.cpp
M  +2    -4    rkward/settings/rksettingsmodulegeneral.h

https://invent.kde.org/education/rkward/commit/b5ca2de22fcfd57d6a294e5f94419945be1fe827

diff --git a/ChangeLog b/ChangeLog
index dcc517c1..1714f9e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,7 @@
 - Fixed: Installation from dialog would fail for R packages requiring the rkward package
 - Allow separate analysis by grouping factors in Analysis->Descriptive Statistics
-- Rework help start page to serve as a dashboard for common tasks
+- Rework help start page to serve as a dashboard for common tasks, replacing the old startup dialog
    - TODO: finish this
-   - TODO: remove startup dialog
 - Fix quirks around "Save as" for rkward output documents
 
 --- Version 0.7.3 - Apr-21-2022
diff --git a/rkward/dialogs/CMakeLists.txt b/rkward/dialogs/CMakeLists.txt
index 74dfa46d..bcf786b6 100644
--- a/rkward/dialogs/CMakeLists.txt
+++ b/rkward/dialogs/CMakeLists.txt
@@ -1,7 +1,6 @@
 INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}    )
 
 SET(dialogs_STAT_SRCS
-   startupdialog.cpp
    rkloadlibsdialog.cpp
    rkreadlinedialog.cpp
    rkimportdialog.cpp
diff --git a/rkward/dialogs/startupdialog.cpp b/rkward/dialogs/startupdialog.cpp
deleted file mode 100644
index 2c564f95..00000000
--- a/rkward/dialogs/startupdialog.cpp
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
-startupdialog - This file is part of RKWard (https://rkward.kde.org). Created: Thu Aug 26 2004
-SPDX-FileCopyrightText: 2004-2018 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
-SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
-SPDX-License-Identifier: GPL-2.0-or-later
-*/
-#include "startupdialog.h"
-
-#include <qradiobutton.h>
-#include <qcheckbox.h>
-#include <qbuttongroup.h>
-#include <QGroupBox>
-#include <qlabel.h>
-#include <QListWidget>
-#include <qstringlist.h>
-#include <qpixmap.h>
-#include <QHBoxLayout>
-#include <QVBoxLayout>
-#include <QFileInfo>
-
-#include <KLocalizedString>
-#include <krecentfilesaction.h>
-#include <KConfigGroup>
-#include <QPushButton>
-
-#include "../settings/rksettingsmodulegeneral.h"
-#include "../misc/rkcommonfunctions.h"
-#include "../misc/rkdialogbuttonbox.h"
-
-#include "../debug.h"
-
-StartupDialog::StartupDialog (QWidget *parent, StartupDialogResult *result, KRecentFilesAction *recent_files) : QDialog (parent) {
-	RK_TRACE (DIALOGS);
-
-	setModal (true);
-	StartupDialog::result = result;
-
-	setWindowTitle (i18n ("What would you like to do?"));
-
-	QVBoxLayout *vbox = new QVBoxLayout ();
-	setLayout (vbox);
-	
-	QLabel *pic = new QLabel (this);
-	vbox->addWidget (pic);
-	pic->setPixmap (QPixmap (RKCommonFunctions::getRKWardDataDir () + "icons/rkward_logo.png"));
-
-	choser = new QButtonGroup (this);
-	QGroupBox* choser_box = new QGroupBox (this);
-	vbox->addWidget (choser_box);
-	QVBoxLayout* choser_layout = new QVBoxLayout(choser_box);
-
-	choser_layout->addWidget (empty_workspace_button = new QRadioButton (i18n ("Start with an empty workspace"), choser_box));
-	choser->addButton (empty_workspace_button);
-	choser_layout->addWidget (empty_table_button = new QRadioButton (i18n ("Start with an empty table"), choser_box));
-	choser->addButton (empty_table_button);
-	QUrl rdata_file = getRestoreFile ();
-	choser_layout->addWidget (restore_workspace_button = new QRadioButton (choser_box));
-	choser->addButton (restore_workspace_button);
-	if (rdata_file.isEmpty ()) {
-		restore_workspace_button->setEnabled (false);
-		restore_workspace_button->setText (i18n ("Load workspace from current directory"));
-	} else restore_workspace_button->setText (i18n ("Load workspace from current directory:\n%1", rdata_file.toLocalFile ()));
-	choser_layout->addWidget (open_button = new QRadioButton (i18n ("Load an existing workspace:"), choser_box));
-	choser->addButton (open_button);
-	connect (open_button, &QRadioButton::toggled, this, &StartupDialog::openButtonSelected);
-	empty_table_button->setChecked (true);
-
-	file_list = new QListWidget (choser_box);
-	file_list->setSelectionMode (QAbstractItemView::SingleSelection);
-	file_list->setSortingEnabled (false);
-	chose_file_item = new QListWidgetItem (i18n ("<<Open another file>>"), file_list);
-	if (recent_files) {
-		QList<QUrl> urls = recent_files->urls ();
-		for (int i = 0; i < urls.length (); ++i) {
-			file_list->addItem (urls[i].url (QUrl::PreferLocalFile));
-		}
-	}
-	connect (file_list, &QListWidget::itemClicked, this, &StartupDialog::listClicked);
-	connect (file_list, &QListWidget::itemDoubleClicked, this, &StartupDialog::listDoubleClicked);
-	choser_layout->addWidget (file_list);
-	choser_layout->addWidget (remember_box = new QCheckBox (i18n ("Always do this on startup"), choser_box));
-
-	RKDialogButtonBox *buttonBox = new RKDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
-	buttonBox->button (QDialogButtonBox::Ok)->setDefault (true);
-	vbox->addWidget (buttonBox);
-}
-
-StartupDialog::~StartupDialog() {
-	RK_TRACE (DIALOGS);
-}
-
-void StartupDialog::accept () {
-	RK_TRACE (DIALOGS);
-
-	if (empty_workspace_button->isChecked ()) {
-		result->result = EmptyWorkspace;
-	} else if (empty_table_button->isChecked ()) {
-		result->result = EmptyTable;
-	} else if (restore_workspace_button->isChecked ()) {
-		result->result = RestoreFromWD;
-		result->open_url = getRestoreFile ();
-	} else if (open_button->isChecked ()) {
-		QListWidgetItem *item = file_list->currentItem ();
-		if (item == chose_file_item) {
-			result->result = ChoseFile;
-		} else {
-			result->result = OpenFile;
-			result->open_url = QUrl::fromLocalFile (item->text ());
-		}
-	} else {
-		RK_ASSERT (false);
-	}
-	if (remember_box->isChecked ()) RKSettingsModuleGeneral::setStartupAction (result->result);
-	QDialog::accept ();
-}
-
-void StartupDialog::reject () {
-	RK_TRACE (DIALOGS);
-	
-	result->result = EmptyWorkspace;
-	
-	QDialog::reject ();
-}
-
-void StartupDialog::listDoubleClicked (QListWidgetItem *item) {
-	RK_TRACE (DIALOGS);
-	
-	if (item) {
-		open_button->setChecked (true);
-		file_list->setCurrentItem (item);
-		item->setSelected (true);
-		accept ();
-	}
-}
-
-void StartupDialog::listClicked (QListWidgetItem *item) {
-	RK_TRACE (DIALOGS);
-	
-	if (item) {
-		open_button->setChecked (true);
-		openButtonSelected (true);		// always do processing
-	}
-}
-
-void StartupDialog::openButtonSelected (bool checked) {
-	RK_TRACE (DIALOGS);
-
-	if (checked) {
-		if (!file_list->currentItem ()) {
-			file_list->setCurrentRow (0);
-		}
-		if (file_list->currentItem () != chose_file_item) {
-			remember_box->setChecked (false);
-			remember_box->setEnabled (false);
-		} else {
-			remember_box->setEnabled (true);
-		}
-	} else {
-		remember_box->setEnabled (true);
-	}
-}
-
-void StartupDialog::showEvent (QShowEvent *event) {
-	RK_TRACE (DIALOGS);
-
-	// somehow, trying to achieve this in the ctor leads to the dialog never actually being shown (KDE4.0 beta)
-	setFixedWidth (width ());
-	QDialog::showEvent (event);
-}
-
-// static
-QUrl StartupDialog::getRestoreFile () {
-	RK_TRACE (DIALOGS);
-
-	QFileInfo rdata_file (".RData");
-	if (rdata_file.exists ()) return QUrl::fromLocalFile (rdata_file.absoluteFilePath ());
-
-	return QUrl ();
-}
-
-//static
-StartupDialog::StartupDialogResult StartupDialog::getStartupAction (QWidget *parent, KRecentFilesAction *recent_files) {
-	RK_TRACE (DIALOGS);
-
-	StartupDialogResult result;
-	result.result = RKSettingsModuleGeneral::startupAction ();
-
-	if (result.result == RestoreFromWD) {
-		result.open_url = getRestoreFile ();
-		if (result.open_url.isEmpty ()) result.result = NoSavedSetting;
-	}
-	if (result.result != NoSavedSetting) {
-		return result;
-	}
-
-	StartupDialog *dialog = new StartupDialog (parent, &result, recent_files);
-	dialog->exec ();
-	delete dialog;
-	
-	RK_DEBUG (DIALOGS, DL_DEBUG, "startup-dialog result: %d, url: %s", result.result, qPrintable (result.open_url.url ()));
-	
-	return result;
-}
-
diff --git a/rkward/dialogs/startupdialog.h b/rkward/dialogs/startupdialog.h
deleted file mode 100644
index d0aa078a..00000000
--- a/rkward/dialogs/startupdialog.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-startupdialog - This file is part of the RKWard project. Created: Thu Aug 26 2004
-SPDX-FileCopyrightText: 2004-2011 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
-SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
-SPDX-License-Identifier: GPL-2.0-or-later
-*/
-#ifndef STARTUPDIALOG_H
-#define STARTUPDIALOG_H
-
-#include <QDialog>
-#include <QUrl>
-
-class QCheckBox;
-class QButtonGroup;
-class QRadioButton;
-class QListWidget;
-class QListWidgetItem;
-class KRecentFilesAction;
-
-/**
-This class represents the startup dialog asking you whether to open a recent file, start with an empty workspace, etc. It's probably only ever used in one place, namely RKWard startup. The normal way to invoke it is via the static member-function getStartupAction. The selected action is returned in a StartupDialogResult. Remember to delete that struct after you read it.
-
- at author Thomas Friedrichsmeier
-*/
-/// the startup dialog
-class StartupDialog : public QDialog {
-Q_OBJECT
-public:
-	/** enum to hold result of StartupDialog. WARNING: do not change the numeric values! They are saved as user settings in the config (@see RKSettingsModuleGeneral). */
-	enum Result {
-		EmptyWorkspace=0,			/**< start with an empty workspace */
-		EmptyTable=1,				/**< start with an empty table */
-		ChoseFile=2,				/**< chose file to open */
-		NoSavedSetting=3,			/**< not actually returned as a result. Used in RKSettingsModuleGeneral. This is saved, if user wants to be asked on every startup */
-		OpenFile=4,					/**< open a recent file (already specified) */
-		RestoreFromWD=5				/**< load workspace from current directory, if available (R option --restore). */
-	};
-	struct StartupDialogResult {
-		Result result;
-		QUrl open_url;
-	};
-
-	StartupDialog (QWidget *parent, StartupDialogResult *result, KRecentFilesAction *recent_files);
-
-	~StartupDialog();
-	
-	static StartupDialogResult getStartupAction (QWidget *parent, KRecentFilesAction *recent_files);
-	static QUrl getRestoreFile ();
-public slots:
-	void accept () override;
-	void reject () override;
-	void listDoubleClicked (QListWidgetItem* item);
-	void listClicked (QListWidgetItem* item);
-	void openButtonSelected (bool checked);
-protected:
-/** reimplemented from QWidget to achieve fixed width */
-	void showEvent (QShowEvent *event) override;
-private:
-	QRadioButton *empty_workspace_button;
-	QRadioButton *empty_table_button;
-	QRadioButton *restore_workspace_button;
-	QRadioButton *open_button;
-	QCheckBox *remember_box;
-	
-	QButtonGroup *choser;
-	
-	QListWidget *file_list;
-	QListWidgetItem *chose_file_item;
-	
-	StartupDialogResult *result;
-};
-
-#endif
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index 50a14847..1567294d 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -57,7 +57,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #include "misc/rkdbusapi.h"
 #include "misc/rkdialogbuttonbox.h"
 #include "misc/rkstyle.h"
-#include "dialogs/startupdialog.h"
 #include "dialogs/rkloadlibsdialog.h"
 #include "dialogs/rkimportdialog.h"
 #include "dialogs/rkrecoverdialog.h"
@@ -255,16 +254,9 @@ void RKWardMainWindow::doPostInit () {
 
 		openUrlsFromCommandLineOrDBus (warn_external, open_urls);
 	} else {
-		StartupDialog::StartupDialogResult result = StartupDialog::getStartupAction (this, fileOpenRecentWorkspace);
-		if (!result.open_url.isEmpty ()) {
+		if (RKSettingsModuleGeneral::openRestoreFileOnLoad() && QFile::exists(".RData")) {
 			// setNoAskSave(true); was called earlier
-			askOpenWorkspace(result.open_url);
-		} else {
-			if (result.result == StartupDialog::ChoseFile) {
-				askOpenWorkspace (QUrl());
-			} else if (result.result == StartupDialog::EmptyTable) {
-				RKWorkplace::mainWorkplace ()->editNewDataFrame (i18n ("my.data"));
-			}
+			askOpenWorkspace(QUrl::fromLocalFile(QFileInfo(".RData").absoluteFilePath()));
 		}
 
 		if (RKSettingsModuleGeneral::workplaceSaveMode () == RKSettingsModuleGeneral::SaveWorkplaceWithSession) {
diff --git a/rkward/settings/rksettingsmodulegeneral.cpp b/rkward/settings/rksettingsmodulegeneral.cpp
index 8d647b10..230d8989 100644
--- a/rkward/settings/rksettingsmodulegeneral.cpp
+++ b/rkward/settings/rksettingsmodulegeneral.cpp
@@ -31,7 +31,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
 // static members
 QString RKSettingsModuleGeneral::files_path;
 RKConfigValue<QString> RKSettingsModuleGeneral::new_files_path { "logfile dir", QString() }; // NOTE: default initialized at runtime!
-RKConfigValue<StartupDialog::Result, int> RKSettingsModuleGeneral::startup_action { "startup action", StartupDialog::NoSavedSetting };
+RKConfigValue<bool> RKSettingsModuleGeneral::autorestore_from_wd { "autorestore from wd", false };
 RKConfigValue<RKSettingsModuleGeneral::WorkplaceSaveMode, int> RKSettingsModuleGeneral::workplace_save_mode { "save mode", SaveWorkplaceWithWorkspace };
 RKConfigValue<bool> RKSettingsModuleGeneral::cd_to_workspace_dir_on_load {"cd to workspace on load", true};
 RKConfigValue<bool> RKSettingsModuleGeneral::show_help_on_startup {"show help on startup", true};
@@ -58,29 +58,18 @@ RKSettingsModuleGeneral::RKSettingsModuleGeneral (RKSettings *gui, QWidget *pare
 	RK_TRACE (SETTINGS);
 
 	QVBoxLayout *main_vbox = new QVBoxLayout (this);
-	main_vbox->addWidget (RKCommonFunctions::wordWrappedLabel (i18n ("Settings marked with (*) do not take effect until you restart RKWard")));
-
-	main_vbox->addSpacing (2*RKStyle::spacingHint ());
-
-	files_choser = new GetFileNameWidget (this, GetFileNameWidget::ExistingDirectory, true, i18n ("Directory where rkward may store files (*)"), QString (), new_files_path);
+	files_choser = new GetFileNameWidget (this, GetFileNameWidget::ExistingDirectory, true, i18n ("Directory where rkward may store files (setting takes effect after restarting RKWard)"), QString (), new_files_path);
 	connect (files_choser, &GetFileNameWidget::locationChanged, this, &RKSettingsModuleGeneral::change);
 	main_vbox->addWidget (files_choser);
 
 	main_vbox->addSpacing (2*RKStyle::spacingHint ());
 
-	main_vbox->addWidget(new QLabel(i18n("Startup Action (*)")));
-	auto startup_action_choser = startup_action.makeDropDown(RKConfigBase::LabelList(
-		{{StartupDialog::EmptyWorkspace, i18n("Start with an empty workspace")}, {StartupDialog::RestoreFromWD, i18n("Load .RData-file from current directory, if available (R option '--restore')")}, {StartupDialog::EmptyTable, i18n("Start with an empty table")}, {StartupDialog::ChoseFile, i18n("Ask for a file to open")}, {StartupDialog::NoSavedSetting, i18n("Show selection dialog (default)")}}
-	), this);
-	main_vbox->addWidget(startup_action_choser);
-
-	main_vbox->addWidget(show_help_on_startup.makeCheckbox(i18n("Show RKWard Help on Startup"), this));
-	auto num_recent_files_box = num_recent_files.makeSpinBox(1, INT_MAX, this);
-	RKCommonFunctions::setTips (i18n ("<p>The number of recent files to remember (in the Open Recent R Script File menu).</p>") + RKCommonFunctions::noteSettingsTakesEffectAfterRestart (), num_recent_files_box, num_recent_files_box);
-	main_vbox->addWidget(new QLabel(i18n("Maximum number of files to remember per category (*)")));
-	main_vbox->addWidget(num_recent_files_box);
+	auto group = new QGroupBox(i18n("Startup behavior"));
+	auto vbox = new QVBoxLayout(group);
+	vbox->addWidget(autorestore_from_wd.makeCheckbox(i18n("Load .RData-file from startup directory, if available (R option '--restore')"), this));
+	vbox->addWidget(show_help_on_startup.makeCheckbox(i18n("Show RKWard Help on Startup"), this));
 
-	QGroupBox* group_box = new QGroupBox (i18n ("Initial working directory (*)"), this);
+	QGroupBox* group_box = new QGroupBox (i18n ("Initial working directory"), this);
 	QHBoxLayout *hlayout = new QHBoxLayout (group_box);
 	auto initial_dir_chooser = initial_dir.makeDropDown(RKConfigBase::LabelList(
 		{{CurrentDirectory, i18n("Do not change current directory on startup")}, {RKWardDirectory, i18n("RKWard files directory (as specified, above)")}, {UserHomeDirectory, i18n("User home directory")}, {LastUsedDirectory, i18n("Last used directory")}, {CustomDirectory, i18n("The following directory (please specify):")}}
@@ -92,7 +81,15 @@ RKSettingsModuleGeneral::RKSettingsModuleGeneral (RKSettings *gui, QWidget *pare
 	connect(initial_dir_chooser, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [initial_dir_chooser, this]() { this->initial_dir_custom_chooser->setEnabled(initial_dir_chooser->currentData()==CustomDirectory); });
 	hlayout->addWidget (initial_dir_custom_chooser);
 	RKCommonFunctions::setTips (i18n ("<p>The initial working directory to use. Note that if you are loading a workspace on startup, and you have configured RKWard to change to the directory of loaded workspaces, that directory will take precedence.</p>"), group_box, initial_dir_chooser, initial_dir_custom_chooser);
-	main_vbox->addWidget (group_box);
+	vbox->addWidget (group_box);
+	main_vbox->addWidget(group);
+
+	main_vbox->addSpacing (2*RKStyle::spacingHint ());
+
+	auto num_recent_files_box = num_recent_files.makeSpinBox(1, INT_MAX, this);
+	RKCommonFunctions::setTips (i18n ("<p>The number of recent files to remember (in the Open Recent R Script File menu).</p>") + RKCommonFunctions::noteSettingsTakesEffectAfterRestart (), num_recent_files_box, num_recent_files_box);
+	vbox->addWidget(new QLabel(i18n("Maximum number of recently used files to remember per category")));
+	vbox->addWidget(num_recent_files_box);
 
 	main_vbox->addSpacing (2*RKStyle::spacingHint ());
 
@@ -190,7 +187,7 @@ void RKSettingsModuleGeneral::syncConfig(KConfig *config, RKConfigBase::ConfigSy
 	} else {
 		cg.writeEntry("last known data dir", RKCommonFunctions::getRKWardDataDir());
 	}
-	startup_action.syncConfig(cg, a);
+	autorestore_from_wd.syncConfig(cg, a);
 	show_help_on_startup.syncConfig(cg, a);
 	num_recent_files.syncConfig(cg, a);
 	initial_dir.syncConfig(cg, a);
diff --git a/rkward/settings/rksettingsmodulegeneral.h b/rkward/settings/rksettingsmodulegeneral.h
index 942ef35a..38304109 100644
--- a/rkward/settings/rksettingsmodulegeneral.h
+++ b/rkward/settings/rksettingsmodulegeneral.h
@@ -8,7 +8,6 @@ SPDX-License-Identifier: GPL-2.0-or-later
 #define RKSETTINGSMODULEGENERALFILES_H
 
 #include "rksettingsmodule.h"
-#include "../dialogs/startupdialog.h"
 
 class GetFileNameWidget;
 class QComboBox;
@@ -53,9 +52,8 @@ public:
 
 /// returns the directory-name where the logfiles should reside
 	static QString &filesPath () { return files_path; };
-	static StartupDialog::Result startupAction () { return startup_action; };
 	static bool showHelpOnStartup () { return show_help_on_startup; };
-	static void setStartupAction (StartupDialog::Result action) { startup_action = action; };
+	static bool openRestoreFileOnLoad() { return autorestore_from_wd; };
 	static WorkplaceSaveMode workplaceSaveMode () { return workplace_save_mode; };
 /** retrieve the saved workplace description. Meaningful only is workplaceSaveMode () == SaveWorkplaceWithSession */
 	static QString getSavedWorkplace (KConfig *config);
@@ -103,7 +101,7 @@ private:
 	QButtonGroup *workplace_save_chooser;
 	GetFileNameWidget *initial_dir_custom_chooser;
 
-	static RKConfigValue<StartupDialog::Result, int> startup_action;
+	static RKConfigValue<bool> autorestore_from_wd;
 	static QString files_path;
 /** since changing the files_path can not easily be done while in an active session, the setting should only take effect on the next start. This string stores a changed setting, while keeping the old one intact as long as RKWard is running */
 	static RKConfigValue<QString> new_files_path;


More information about the rkward-tracker mailing list