@@ -61,45 +61,72 @@ void MainDialog::deleteSelectedLayout(void)
61
61
m_model->deleteLayout (ui->layoutView ->currentIndex ().row ());
62
62
}
63
63
64
+ static QString getStr (std::vector<std::shared_ptr<Setting>> &settings, QString name)
65
+ {
66
+ std::shared_ptr<Setting> setting = retrieve (settings, name);
67
+ if (setting == nullptr ) {
68
+ qDebug () << " warning: no settings with name" << name;
69
+ return nullptr ;
70
+ }
71
+ if (setting->valueType () != LAB_VALUE_TYPE_STRING) {
72
+ qDebug () << " getStr(): not valid int setting" << name;
73
+ }
74
+ return std::get<QString>(setting->value ());
75
+ }
76
+
77
+ static int getInt (std::vector<std::shared_ptr<Setting>> &settings, QString name)
78
+ {
79
+ std::shared_ptr<Setting> setting = retrieve (settings, name);
80
+ if (setting == nullptr ) {
81
+ qDebug () << " warning: no settings with name" << name;
82
+ return -65535 ;
83
+ }
84
+ if (setting->valueType () != LAB_VALUE_TYPE_INT) {
85
+ qDebug () << " getInt(): not valid int setting" << name;
86
+ }
87
+ return std::get<int >(setting->value ());
88
+ }
89
+
90
+ /* Return -1 for error, which works will with setCurrentIndex() */
91
+ static int getBool (std::vector<std::shared_ptr<Setting>> &settings, QString name)
92
+ {
93
+ std::shared_ptr<Setting> setting = retrieve (settings, name);
94
+ if (setting == nullptr ) {
95
+ qDebug () << " warning: no settings with name" << name;
96
+ return -1 ;
97
+ }
98
+ if (setting->valueType () != LAB_VALUE_TYPE_BOOL) {
99
+ qDebug () << " getBool(): not valid int setting" << name;
100
+ }
101
+ return std::get<int >(setting->value ());
102
+ }
103
+
64
104
void MainDialog::activate ()
65
105
{
66
106
/* # APPEARANCE */
67
107
68
- // TODO: Use retrieve() instead of xml_get(), etc.
69
-
70
108
/* Labwc Theme */
71
109
QStringList labwcThemes = findLabwcThemes ();
72
110
ui->openboxTheme ->addItems (labwcThemes);
73
- ui->openboxTheme ->setCurrentIndex (labwcThemes.indexOf (xml_get ( " /labwc_config/theme/name" )));
111
+ ui->openboxTheme ->setCurrentIndex (labwcThemes.indexOf (getStr (m_settings, " /labwc_config/theme/name" )));
74
112
75
113
/* Corner Radius */
76
- ui->cornerRadius ->setValue (xml_get_int ( " /labwc_config/theme/cornerRadius" ));
114
+ ui->cornerRadius ->setValue (getInt (m_settings, " /labwc_config/theme/cornerRadius" ));
77
115
78
116
/* Drop Shadows */
79
117
ui->dropShadows ->addItem (" no" );
80
118
ui->dropShadows ->addItem (" yes" );
81
- ui->dropShadows ->setCurrentIndex (xml_get_bool_text ( " /labwc_config/theme/dropShadows" ));
119
+ ui->dropShadows ->setCurrentIndex (getBool (m_settings, " /labwc_config/theme/dropShadows" ));
82
120
83
121
/* Icon Theme */
84
122
QStringList themes = findIconThemes (LAB_ICON_THEME_TYPE_ICON);
85
123
ui->iconTheme ->addItems (themes);
86
- ui->iconTheme ->setCurrentIndex (themes.indexOf (xml_get ( " /labwc_config/theme/icon" )));
124
+ ui->iconTheme ->setCurrentIndex (themes.indexOf (getStr (m_settings, " /labwc_config/theme/icon" )));
87
125
88
126
/* # BEHAVIOUR */
89
- std::vector policies = { " " , " Automatic" , " Cascade" , " Center" , " Cursor" };
90
- int active = -1 ;
91
- const char *active_id = xml_get (" /labwc_config/placement/policy" );
92
- int i = 0 ;
93
- for (auto policy : policies) {
94
- if (active_id && !strcasecmp (policy, active_id)) {
95
- active = i;
96
- }
97
- ui->placementPolicy ->addItem (policy);
98
- ++i;
99
- }
100
- if (active != -1 ) {
101
- ui->placementPolicy ->setCurrentIndex (active);
102
- }
127
+ QStringList policies = { " " , " Automatic" , " Cascade" , " Center" , " Cursor" };
128
+ ui->placementPolicy ->addItems (policies);
129
+ ui->placementPolicy ->setCurrentIndex (policies.indexOf (getStr (m_settings, " /labwc_config/placement/policy" )));
103
130
104
131
/* # MOUSE & TOUCHPAD */
105
132
@@ -114,8 +141,7 @@ void MainDialog::activate()
114
141
/* Natural Scroll */
115
142
ui->naturalScroll ->addItem (" no" );
116
143
ui->naturalScroll ->addItem (" yes" );
117
- ui->naturalScroll ->setCurrentIndex (
118
- xml_get_bool_text (" /labwc_config/libinput/device/naturalscroll" ));
144
+ ui->naturalScroll ->setCurrentIndex (getBool (m_settings, " /labwc_config/libinput/device/naturalScroll" ));
119
145
120
146
/* # LANGUAGE */
121
147
@@ -138,6 +164,8 @@ void setInt(std::vector<std::shared_ptr<Setting>> &settings, QString name, int v
138
164
}
139
165
if (value != std::get<int >(setting->value ())) {
140
166
info (" '{} has changed to '{}'" , name.toStdString (), value);
167
+ xpath_add_node (name.toStdString ().c_str ());
168
+ // xml_save();
141
169
xml_set_num (name.toStdString ().c_str (), value);
142
170
}
143
171
}
@@ -154,6 +182,8 @@ void setStr(std::vector<std::shared_ptr<Setting>> &settings, QString name, QStri
154
182
}
155
183
if (value != std::get<QString>(setting->value ())) {
156
184
info (" '{} has changed to '{}'" , name.toStdString (), value.toStdString ());
185
+ xpath_add_node (name.toStdString ().c_str ());
186
+ // xml_save();
157
187
xml_set (name.toStdString ().c_str (), value.toStdString ().c_str ());
158
188
}
159
189
}
@@ -205,6 +235,8 @@ void setBool(std::vector<std::shared_ptr<Setting>> &settings, QString name, QStr
205
235
int boolValue = parseBool (value.toStdString ().c_str (), -1 );
206
236
if (boolValue != std::get<int >(setting->value ())) {
207
237
info (" '{} has changed to '{}'" , name.toStdString (), value.toStdString ());
238
+ xpath_add_node (name.toStdString ().c_str ());
239
+ // xml_save();
208
240
xml_set (name.toStdString ().c_str (), value.toStdString ().c_str ());
209
241
}
210
242
}
0 commit comments