1 /***************************************************************************
2                           rksettingsmodule  -  description
3                              -------------------
4     begin                : Fri Apr 22 2005
5     copyright            : (C) 2005, 2015 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 
18 #include "rksettingsmoduleobjectbrowser.h"
19 
20 #include <KLocalizedString>
21 #include <kconfig.h>
22 #include <kconfiggroup.h>
23 
24 #include <qlayout.h>
25 #include <qcheckbox.h>
26 #include <qlabel.h>
27 #include <QVBoxLayout>
28 #include <QInputDialog>
29 
30 #include "../rkglobals.h"
31 #include "../misc/multistringselector.h"
32 #include "rksettings.h"
33 #include "rksettingsmodulegeneral.h"
34 #include "../debug.h"
35 
36 // static
37 bool RKSettingsModuleObjectBrowser::workspace_settings[RKObjectListViewSettings::SettingsCount];
38 bool RKSettingsModuleObjectBrowser::varselector_settings[RKObjectListViewSettings::SettingsCount];
39 QStringList RKSettingsModuleObjectBrowser::getstructure_blacklist;
40 
RKSettingsModuleObjectBrowser(RKSettings * gui,QWidget * parent)41 RKSettingsModuleObjectBrowser::RKSettingsModuleObjectBrowser (RKSettings *gui, QWidget *parent) : RKSettingsModule (gui, parent) {
42 	RK_TRACE (SETTINGS);
43 
44 	QVBoxLayout *layout = new QVBoxLayout (this);
45 
46 	// Note: Up to RKWard 0.6.3, this settings module had a lot of additional checkboxes. Since 0.6.4, most settings are stored, implicitly,
47 	//       i.e. the Workspace Browser tool window "remembers" its latest settings (and so does the Varselector, separately). This modules
48 	//       is still responsible to storing / loading settings.
49 
50 	blacklist_choser = new MultiStringSelector (i18n ("Never fetch the structure of these packages:"), this);
51 	blacklist_choser->setValues (getstructure_blacklist);
52 	connect (blacklist_choser, &MultiStringSelector::listChanged, this, &RKSettingsModuleObjectBrowser::listChanged);
53 	connect (blacklist_choser, &MultiStringSelector::getNewStrings, this, &RKSettingsModuleObjectBrowser::addBlackList);
54 	layout->addWidget (blacklist_choser);
55 }
56 
~RKSettingsModuleObjectBrowser()57 RKSettingsModuleObjectBrowser::~RKSettingsModuleObjectBrowser () {
58 	RK_TRACE (SETTINGS);
59 }
60 
61 //static
setDefaultForWorkspace(RKObjectListViewSettings::PersistentSettings setting,bool state)62 void RKSettingsModuleObjectBrowser::setDefaultForWorkspace (RKObjectListViewSettings::PersistentSettings setting, bool state) {
63 	RK_TRACE (SETTINGS);
64 	workspace_settings[setting] = state;
65 }
66 
67 //static
setDefaultForVarselector(RKObjectListViewSettings::PersistentSettings setting,bool state)68 void RKSettingsModuleObjectBrowser::setDefaultForVarselector (RKObjectListViewSettings::PersistentSettings setting, bool state) {
69 	RK_TRACE (SETTINGS);
70 	varselector_settings[setting] = state;
71 }
72 
73 //static
isPackageBlacklisted(const QString & package_name)74 bool RKSettingsModuleObjectBrowser::isPackageBlacklisted (const QString &package_name) {
75 	RK_TRACE (SETTINGS);
76 	return getstructure_blacklist.contains (package_name);
77 }
78 
addBlackList(QStringList * string_list)79 void RKSettingsModuleObjectBrowser::addBlackList (QStringList *string_list) {
80 	RK_TRACE (SETTINGS);
81 	bool ok;
82 	QString new_string = QInputDialog::getText (this, i18n ("Add exclusion"), i18n ("Add the name of the package that no structure should be fetched for"), QLineEdit::Normal, QString (), &ok);
83 	if (ok) (*string_list).append (new_string);
84 }
85 
applyChanges()86 void RKSettingsModuleObjectBrowser::applyChanges () {
87 	RK_TRACE (SETTINGS);
88 
89 	getstructure_blacklist = blacklist_choser->getValues();
90 }
91 
save(KConfig * config)92 void RKSettingsModuleObjectBrowser::save (KConfig *config) {
93 	RK_TRACE (SETTINGS);
94 	saveSettings (config);
95 }
96 
caption()97 QString RKSettingsModuleObjectBrowser::caption () {
98 	RK_TRACE (SETTINGS);
99 	return (i18n ("Workspace"));
100 }
101 
writeSettings(KConfigGroup & cg,bool * settings)102 void writeSettings (KConfigGroup &cg, bool *settings) {
103 	cg.writeEntry ("show hidden vars", settings[RKObjectListViewSettings::ShowObjectsHidden]);
104 	cg.writeEntry ("show label field", settings[RKObjectListViewSettings::ShowFieldsLabel]);
105 	cg.writeEntry ("show type field", settings[RKObjectListViewSettings::ShowFieldsType]);
106 	cg.writeEntry ("show class field", settings[RKObjectListViewSettings::ShowFieldsClass]);
107 }
108 
109 //static
saveSettings(KConfig * config)110 void RKSettingsModuleObjectBrowser::saveSettings (KConfig *config) {
111 	RK_TRACE (SETTINGS);
112 
113 	KConfigGroup cg = config->group ("Object Browser");
114 	cg.writeEntry ("package blacklist", getstructure_blacklist);
115 
116 	KConfigGroup toolgroup = cg.group ("Tool window");
117 	writeSettings (toolgroup, workspace_settings);
118 	KConfigGroup varselgroup = cg.group ("Varselector");
119 	writeSettings (varselgroup, varselector_settings);
120 }
121 
readSettings(const KConfigGroup & cg,bool * settings)122 void readSettings (const KConfigGroup &cg, bool *settings) {
123 	settings[RKObjectListViewSettings::ShowObjectsHidden] = cg.readEntry ("show hidden vars", false);
124 	settings[RKObjectListViewSettings::ShowFieldsLabel] = cg.readEntry ("show label field", true);
125 	settings[RKObjectListViewSettings::ShowFieldsType] = cg.readEntry ("show type field", true);
126 	settings[RKObjectListViewSettings::ShowFieldsClass] = cg.readEntry ("show class field", true);
127 }
128 
129 //static
loadSettings(KConfig * config)130 void RKSettingsModuleObjectBrowser::loadSettings (KConfig *config) {
131 	RK_TRACE (SETTINGS);
132 
133 	KConfigGroup cg = config->group ("Object Browser");
134 	getstructure_blacklist = cg.readEntry ("package blacklist", QStringList ("GO"));
135 
136 	readSettings (cg.group ("Tool window"), workspace_settings);
137 	readSettings (cg.group ("Varselector"), varselector_settings);
138 }
139 
boxChanged(int)140 void RKSettingsModuleObjectBrowser::boxChanged (int) {
141 	RK_TRACE (SETTINGS);
142 	change ();
143 }
144 
listChanged()145 void RKSettingsModuleObjectBrowser::listChanged () {
146 	RK_TRACE (SETTINGS);
147 	change ();
148 }
149 
150