@@ -50,19 +50,13 @@ TrayItem::TrayItem(windowid_t window, const TrayItemOptions &args)
50
50
m_desktop = XLibUtil::getWindowDesktop (m_window);
51
51
52
52
readDockedAppName ();
53
- loadSettings (args);
53
+ m_settings. loadSettings (m_dockedAppName, args);
54
54
updateTitle ();
55
55
updateIcon ();
56
56
57
57
createContextMenu ();
58
58
updateToggleAction ();
59
59
60
- if (!m_settings.getIconPath ().isEmpty ())
61
- setCustomIcon (m_settings.getIconPath ());
62
-
63
- if (!m_settings.getAttentionIconPath ().isEmpty ())
64
- setAttentionIcon (m_settings.getAttentionIconPath ());
65
-
66
60
doSkipTaskbar ();
67
61
doSkipPager ();
68
62
doSticky ();
@@ -78,161 +72,6 @@ TrayItem::~TrayItem()
78
72
XLibUtil::deleteSizeHints (m_sizeHint);
79
73
}
80
74
81
- void TrayItem::loadSettings (const TrayItemOptions &args)
82
- {
83
- // Precedence:
84
- // 1) Command line overrides (argSetting, if positive)
85
- // 2) User app-specific defaults (QSettings: "<m_dockedAppName>/<key>")
86
- // 3) User global defaults (QSettings: "_GLOBAL_DEFAULTS/<key>")
87
- // 4) KDocker defaults (TrayItemOptions::default*)
88
- m_settings.setIconPath (readSetting (args.getIconPath (), " CustomIcon" , TrayItemOptions::defaultIconPath ()));
89
- m_settings.setAttentionIconPath (
90
- readSetting (args.getAttentionIconPath (), " AttentionIcon" , TrayItemOptions::defaultAttentionIconPath ()));
91
- m_settings.setNotifyTime (readSetting (args.getNotifyTime (), " BalloonTimeout" , TrayItemOptions::defaultNotifyTime ()));
92
- m_settings.setSticky (readSetting (args.getStickyState (), " Sticky" , TrayItemOptions::defaultSticky ()));
93
- m_settings.setSkipPager (readSetting (args.getSkipPagerState (), " SkipPager" , TrayItemOptions::defaultSkipPager ()));
94
- m_settings.setSkipTaskbar (
95
- readSetting (args.getSkipTaskbarState (), " SkipTaskbar" , TrayItemOptions::defaultSkipTaskbar ()));
96
- m_settings.setIconifyMinimized (
97
- readSetting (args.getIconifyMinimizedState (), " IconifyMinimized" , TrayItemOptions::defaultIconifyMinimized ()));
98
- m_settings.setIconifyObscured (
99
- readSetting (args.getIconifyObscuredState (), " IconifyObscured" , TrayItemOptions::defaultIconifyObscured ()));
100
- m_settings.setIconifyFocusLost (
101
- readSetting (args.getIconifyFocusLostState (), " IconifyFocusLost" , TrayItemOptions::defaultIconifyFocusLost ()));
102
- m_settings.setLockToDesktop (
103
- readSetting (args.getLockToDesktopState (), " LockToDesktop" , TrayItemOptions::defaultLockToDesktop ()));
104
- }
105
-
106
- bool TrayItem::readSetting (TrayItemOptions::TriState argSetting, const QString &key, bool kdockerDefault)
107
- {
108
- if (argSetting != TrayItemOptions::TriState::Unset)
109
- return (argSetting == TrayItemOptions::TriState::SetTrue ? true : false );
110
- return readConfigValue (key, kdockerDefault).toBool ();
111
- }
112
-
113
- int TrayItem::readSetting (int argSetting, const QString &key, int kdockerDefault)
114
- {
115
- if (argSetting >= 0 )
116
- return argSetting;
117
- return readConfigValue (key, kdockerDefault).toInt ();
118
- }
119
-
120
- QString TrayItem::readSetting (const QString &argSetting, const QString &key, const QString &kdockerDefault)
121
- {
122
- if (!argSetting.isEmpty ())
123
- return argSetting;
124
- return readConfigValue (key, kdockerDefault).toString ();
125
- }
126
-
127
- QVariant TrayItem::readConfigValue (const QString &key, const QVariant &defaultValue)
128
- {
129
- QString app = QString (" %1/%2" ).arg (m_dockedAppName).arg (key);
130
- QString global = QString (" %1/%2" ).arg (GLOBALSKEY).arg (key);
131
- return m_config.value (app, m_config.value (global, defaultValue));
132
- }
133
-
134
- int TrayItem::nonZeroBalloonTimeout ()
135
- {
136
- QString fmt = " %1/BalloonTimeout" ;
137
- int bto = m_config.value (fmt.arg (m_dockedAppName), 0 ).toInt ();
138
- if (!bto)
139
- bto = m_config.value (fmt.arg (GLOBALSKEY), 0 ).toInt ();
140
- return bto ? bto : TrayItemOptions::defaultNotifyTime ();
141
- }
142
-
143
- TrayItemOptions TrayItem::readConfigGlobals ()
144
- {
145
- TrayItemOptions config;
146
-
147
- m_config.beginGroup (GLOBALSKEY);
148
- config.setIconPath (m_config.value (" CustomIcon" , config.getIconPath ()).toString ());
149
- config.setAttentionIconPath (m_config.value (" AttentionIcon" , config.getAttentionIconPath ()).toString ());
150
- config.setNotifyTime (m_config.value (" BalloonTimeout" , config.getNotifyTime ()).toInt ());
151
- config.setSticky (m_config.value (" Sticky" , config.getSticky ()).toBool ());
152
- config.setSkipPager (m_config.value (" SkipPager" , config.getSkipPager ()).toBool ());
153
- config.setSkipTaskbar (m_config.value (" SkipTaskbar" , config.getSkipTaskbar ()).toBool ());
154
- config.setIconifyMinimized (m_config.value (" IconifyMinimized" , config.getIconifyMinimized ()).toBool ());
155
- config.setIconifyObscured (m_config.value (" IconifyObscured" , config.getIconifyObscured ()).toBool ());
156
- config.setIconifyFocusLost (m_config.value (" IconifyFocusLost" , config.getIconifyFocusLost ()).toBool ());
157
- config.setLockToDesktop (m_config.value (" LockToDesktop" , config.getLockToDesktop ()).toBool ());
158
- m_config.endGroup ();
159
-
160
- return config;
161
- }
162
-
163
- void TrayItem::saveSettingsGlobal ()
164
- {
165
- m_config.beginGroup (GLOBALSKEY);
166
- saveSettings ();
167
- m_config.endGroup ();
168
- }
169
-
170
- void TrayItem::saveSettingsApp ()
171
- {
172
- TrayItemOptions globals = readConfigGlobals ();
173
-
174
- m_config.beginGroup (m_dockedAppName);
175
- QVariant keyval;
176
-
177
- if (!m_settings.getIconPath ().isEmpty ())
178
- m_config.setValue (" CustomIcon" , m_settings.getIconPath ());
179
-
180
- if (!m_settings.getAttentionIconPath ().isEmpty ())
181
- m_config.setValue (" AttentionIcon" , m_settings.getAttentionIconPath ());
182
-
183
- saveSettings ();
184
-
185
- // Remove app-specific settings if they match their default values
186
-
187
- keyval = m_config.value (" BalloonTimeout" );
188
- if (keyval.isValid () && (keyval.toInt () == globals.getNotifyTime ()))
189
- m_config.remove (" BalloonTimeout" );
190
-
191
- keyval = m_config.value (" Sticky" );
192
- if (keyval.isValid () && keyval.toBool () == globals.getSticky ())
193
- m_config.remove (" Sticky" );
194
-
195
- keyval = m_config.value (" SkipPager" );
196
- if (keyval.isValid () && keyval.toBool () == globals.getSkipPager ())
197
- m_config.remove (" SkipPager" );
198
-
199
- keyval = m_config.value (" SkipTaskbar" );
200
- if (keyval.isValid () && keyval.toBool () == globals.getSkipTaskbar ())
201
- m_config.remove (" SkipTaskbar" );
202
-
203
- keyval = m_config.value (" IconifyMinimized" );
204
- if (keyval.isValid () && keyval.toBool () == globals.getIconifyMinimized ())
205
- m_config.remove (" IconifyMinimized" );
206
-
207
- keyval = m_config.value (" IconifyObscured" );
208
- if (keyval.isValid () && keyval.toBool () == globals.getIconifyObscured ())
209
- m_config.remove (" IconifyObscured" );
210
-
211
- keyval = m_config.value (" IconifyFocusLost" );
212
- if (keyval.isValid () && keyval.toBool () == globals.getIconifyFocusLost ())
213
- m_config.remove (" IconifyFocusLost" );
214
-
215
- keyval = m_config.value (" LockToDesktop" );
216
- if (keyval.isValid () && keyval.toBool () == globals.getLockToDesktop ())
217
- m_config.remove (" LockToDesktop" );
218
-
219
- m_config.endGroup ();
220
- }
221
-
222
- void TrayItem::saveSettings ()
223
- {
224
- // "/home/<user>/.config/com.kdocker/KDocker.conf" <== m_config.fileName();
225
- // Group is set by caller
226
- m_config.setValue (" BalloonTimeout" , m_settings.getNotifyTime ());
227
- m_config.setValue (" Sticky" , m_settings.getSticky ());
228
- m_config.setValue (" SkipPager" , m_settings.getSkipPager ());
229
- m_config.setValue (" SkipTaskbar" , m_settings.getSkipTaskbar ());
230
- m_config.setValue (" IconifyMinimized" , m_settings.getIconifyMinimized ());
231
- m_config.setValue (" IconifyObscured" , m_settings.getIconifyObscured ());
232
- m_config.setValue (" IconifyFocusLost" , m_settings.getIconifyFocusLost ());
233
- m_config.setValue (" LockToDesktop" , m_settings.getLockToDesktop ());
234
- }
235
-
236
75
bool TrayItem::xcbEventFilter (void *message)
237
76
{
238
77
if (isBadWindow ())
@@ -505,11 +344,7 @@ void TrayItem::setLockToDesktop(bool value)
505
344
506
345
void TrayItem::setBalloonTimeout (bool value)
507
346
{
508
- if (!value) {
509
- m_settings.setNotifyTime (0 );
510
- } else {
511
- m_settings.setNotifyTime (nonZeroBalloonTimeout ());
512
- }
347
+ m_settings.setQuiet (!value);
513
348
}
514
349
515
350
void TrayItem::toggleWindow ()
@@ -598,7 +433,7 @@ void TrayItem::updateTitle()
598
433
QString title = XLibUtil::getWindowTitle (m_window);
599
434
600
435
setToolTip (QString (" %1 [%2]" ).arg (title).arg (m_dockedAppName));
601
- if (m_settings.getNotifyTime () > 0 )
436
+ if (!m_settings. getQuiet () && m_settings.getNotifyTime () > 0 )
602
437
showMessage (m_dockedAppName, title, QSystemTrayIcon::Information, m_settings.getNotifyTime ());
603
438
604
439
if (m_iconified && !m_attentionIcon.isNull () && !m_wantsAttention) {
@@ -681,13 +516,13 @@ void TrayItem::createContextMenu()
681
516
682
517
action = optionsMenu->addAction (tr (" Balloon title changes" ), this , &TrayItem::setBalloonTimeout);
683
518
action->setCheckable (true );
684
- action->setChecked (m_settings.getNotifyTime () ? true : false );
519
+ action->setChecked (! m_settings.getQuiet () );
685
520
686
521
// Save settings menu
687
522
optionsMenu->addSeparator ();
688
523
QMenu *menu = optionsMenu->addMenu (QIcon (" :/menu/savesettings.png" ), tr (" Save settings" ));
689
- menu->addAction (tr (" %1 only" ).arg (m_dockedAppName), this , &TrayItem ::saveSettingsApp);
690
- menu->addAction (tr (" Global (all new)" ), this , &TrayItem ::saveSettingsGlobal);
524
+ menu->addAction (tr (" %1 only" ).arg (m_dockedAppName), &m_settings , &TrayItemSettings ::saveSettingsApp);
525
+ menu->addAction (tr (" Global (all new)" ), &m_settings , &TrayItemSettings ::saveSettingsGlobal);
691
526
692
527
// ---
693
528
0 commit comments