1 /***************************************************************************
2                           rksettings  -  description
3                              -------------------
4     begin                : Wed Jul 28 2004
5     copyright            : (C) 2004-2018 by Thomas Friedrichsmeier
6     email                : thomas.friedrichsmeier@kdemail.net
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #ifndef RKSETTINGS_H
18 #define RKSETTINGS_H
19 
20 #include <kpagedialog.h>
21 
22 #include <qmap.h>
23 
24 class RKSettingsModule;
25 class KConfig;
26 class RKWardMainWindow;
27 class RKSettingsTracker;
28 class RCommandChain;
29 
30 /**
31 The main settings-dialog. Contains subsections (tabs) for different modules. Use configureSettings () to invoke or raise the settings dialog
32 
33 @author Thomas Friedrichsmeier
34 */
35 class RKSettings : public KPageDialog {
36 	Q_OBJECT
37 public:
38 	enum SettingsPage {
39 		NoPage=0,
40 		PagePlugins,
41 		PageR,
42 		PageRPackages,
43 		PageGeneral,
44 		PageOutput,
45 		PageX11,
46 		PageWatch,
47 		PageConsole,
48 		PageCommandEditor,
49 		PageObjectBrowser,
50 		PageDebug,
51 		NumPages = PageDebug + 1
52 	};
53 
54 	static void configureSettings (SettingsPage page=NoPage, QWidget *parent=0, RCommandChain *chain=0);
55 
56 	static void loadSettings (KConfig *config);
57 	static void saveSettings (KConfig *config);
58 	/** Perform any settings validation that may need user interaction (and should happen after a GUI is available, and R has started up) */
59 	static void validateSettingsInteractive ();
60 
61 	void enableApply ();
62 
tracker()63 	static RKSettingsTracker* tracker () { return settings_tracker; };
64 public slots:
65 	void pageChange (KPageWidgetItem *current, KPageWidgetItem *before);
66 protected:
67 	RKSettings (QWidget *parent = 0);
68 	~RKSettings ();
69 
70 	void done (int result) override;
71 private slots:
72 	void applyAll ();
73 	void helpClicked ();
74 private:
75 	void initModules ();
76 	void raisePage (SettingsPage page);
77 	static void dialogClosed ();
78 
79 	typedef QMap<SettingsPage, RKSettingsModule *> ModuleMap;
80 	ModuleMap modules;
81 	KPageWidgetItem *pages[NumPages];
82 
83 	static RKSettings *settings_dialog;
84 friend class RKWardMainWindow;
85 	static RKSettingsTracker *settings_tracker;
86 };
87 
88 /** This class represents a very simple QObject. It's only purpose is to emit signals when certain settings have changed. Classes that need to
89 update themselves on certain changed settings should connect to those signals. */
90 class RKSettingsTracker : public QObject {
91 	Q_OBJECT
92 public:
93 	explicit RKSettingsTracker (QObject *parent);
94 	~RKSettingsTracker ();
95 
96 	void signalSettingsChange (RKSettings::SettingsPage page);
97 signals:
98 	void settingsChanged (RKSettings::SettingsPage);
99 };
100 
101 #endif
102