Changeset View
Standalone View
kcmkwin/kwintabbox/main.cpp
Show All 24 Lines | |||||
25 | // Qt | 25 | // Qt | ||
26 | #include <QtDBus> | 26 | #include <QtDBus> | ||
27 | #include <QDesktopWidget> | 27 | #include <QDesktopWidget> | ||
28 | #include <QDialogButtonBox> | 28 | #include <QDialogButtonBox> | ||
29 | #include <QHBoxLayout> | 29 | #include <QHBoxLayout> | ||
30 | #include <QPushButton> | 30 | #include <QPushButton> | ||
31 | #include <QVBoxLayout> | 31 | #include <QVBoxLayout> | ||
32 | #include <QSpacerItem> | 32 | #include <QSpacerItem> | ||
33 | #include <QTabWidget> | ||||
33 | #include <QStandardPaths> | 34 | #include <QStandardPaths> | ||
34 | #include <QPointer> | 35 | #include <QPointer> | ||
36 | #include <QStandardItemModel> | ||||
35 | 37 | | |||
36 | // KDE | 38 | // KDE | ||
37 | #include <KActionCollection> | | |||
38 | #include <KCModuleProxy> | 39 | #include <KCModuleProxy> | ||
39 | #include <KGlobalAccel> | | |||
40 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
41 | #include <KPluginFactory> | 41 | #include <KPluginFactory> | ||
42 | #include <KPluginTrader> | 42 | #include <KPluginTrader> | ||
43 | #include <KTitleWidget> | 43 | #include <KTitleWidget> | ||
44 | #include <KServiceTypeTrader> | 44 | #include <KServiceTypeTrader> | ||
45 | #include <KShortcutsEditor> | | |||
46 | #include <KNewStuff3/KNS3/DownloadDialog> | 45 | #include <KNewStuff3/KNS3/DownloadDialog> | ||
47 | // Plasma | 46 | // Plasma | ||
48 | #include <KPackage/Package> | 47 | #include <KPackage/Package> | ||
49 | #include <KPackage/PackageLoader> | 48 | #include <KPackage/PackageLoader> | ||
50 | 49 | | |||
51 | // own | 50 | // own | ||
51 | #include "kwintabboxconfigform.h" | ||||
52 | #include "layoutpreview.h" | 52 | #include "layoutpreview.h" | ||
53 | #include "kwintabboxsettings.h" | 53 | #include "kwintabboxsettings.h" | ||
54 | #include "kwinswitcheffectsettings.h" | 54 | #include "kwinswitcheffectsettings.h" | ||
55 | #include "kwinpluginssettings.h" | 55 | #include "kwinpluginssettings.h" | ||
56 | 56 | | |||
57 | K_PLUGIN_FACTORY(KWinTabBoxConfigFactory, registerPlugin<KWin::KWinTabBoxConfig>();) | 57 | K_PLUGIN_FACTORY(KWinTabBoxConfigFactory, registerPlugin<KWin::KWinTabBoxConfig>();) | ||
58 | 58 | | |||
59 | namespace KWin | 59 | namespace KWin | ||
60 | { | 60 | { | ||
61 | 61 | | |||
62 | using namespace TabBox; | 62 | using namespace TabBox; | ||
63 | 63 | | |||
64 | KWinTabBoxConfigForm::KWinTabBoxConfigForm(QWidget* parent) | | |||
65 | : QWidget(parent) | | |||
66 | { | | |||
67 | setupUi(this); | | |||
68 | } | | |||
69 | 64 | | |||
70 | KWinTabBoxConfig::KWinTabBoxConfig(QWidget* parent, const QVariantList& args) | 65 | KWinTabBoxConfig::KWinTabBoxConfig(QWidget* parent, const QVariantList& args) | ||
71 | : KCModule(parent, args) | 66 | : KCModule(parent, args) | ||
72 | , m_config(KSharedConfig::openConfig("kwinrc")) | 67 | , m_config(KSharedConfig::openConfig("kwinrc")) | ||
73 | , m_tabBoxConfig(new TabBoxSettings(QStringLiteral("TabBox"), this)) | 68 | , m_tabBoxConfig(new TabBoxSettings(QStringLiteral("TabBox"), this)) | ||
74 | , m_tabBoxAlternativeConfig(new TabBoxSettings(QStringLiteral("TabBoxAlternative"), this)) | 69 | , m_tabBoxAlternativeConfig(new TabBoxSettings(QStringLiteral("TabBoxAlternative"), this)) | ||
75 | , m_coverSwitchConfig(new SwitchEffectSettings(QStringLiteral("Effect-CoverSwitch"), this)) | 70 | , m_coverSwitchConfig(new SwitchEffectSettings(QStringLiteral("Effect-CoverSwitch"), this)) | ||
76 | , m_flipSwitchConfig(new SwitchEffectSettings(QStringLiteral("Effect-FlipSwitch"), this)) | 71 | , m_flipSwitchConfig(new SwitchEffectSettings(QStringLiteral("Effect-FlipSwitch"), this)) | ||
77 | , m_pluginsConfig(new PluginsSettings(this)) | 72 | , m_pluginsConfig(new PluginsSettings(this)) | ||
78 | { | 73 | { | ||
79 | QTabWidget* tabWidget = new QTabWidget(this); | 74 | QTabWidget* tabWidget = new QTabWidget(this); | ||
80 | m_primaryTabBoxUi = new KWinTabBoxConfigForm(tabWidget); | 75 | m_primaryTabBoxUi = new KWinTabBoxConfigForm(KWinTabBoxConfigForm::TabboxType::Main, tabWidget); | ||
81 | m_alternativeTabBoxUi = new KWinTabBoxConfigForm(tabWidget); | 76 | m_alternativeTabBoxUi = new KWinTabBoxConfigForm(KWinTabBoxConfigForm::TabboxType::Alternative, tabWidget); | ||
82 | tabWidget->addTab(m_primaryTabBoxUi, i18n("Main")); | 77 | tabWidget->addTab(m_primaryTabBoxUi, i18n("Main")); | ||
83 | tabWidget->addTab(m_alternativeTabBoxUi, i18n("Alternative")); | 78 | tabWidget->addTab(m_alternativeTabBoxUi, i18n("Alternative")); | ||
84 | 79 | | |||
85 | QPushButton* ghnsButton = new QPushButton(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")), i18n("Get New Task Switchers...")); | 80 | QPushButton* ghnsButton = new QPushButton(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")), i18n("Get New Task Switchers...")); | ||
86 | connect(ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNS())); | 81 | connect(ghnsButton, SIGNAL(clicked(bool)), SLOT(slotGHNS())); | ||
87 | 82 | | |||
88 | QHBoxLayout* buttonBar = new QHBoxLayout(); | 83 | QHBoxLayout* buttonBar = new QHBoxLayout(); | ||
89 | QSpacerItem* buttonBarSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); | 84 | QSpacerItem* buttonBarSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); | ||
90 | buttonBar->addItem(buttonBarSpacer); | 85 | buttonBar->addItem(buttonBarSpacer); | ||
91 | buttonBar->addWidget(ghnsButton); | 86 | buttonBar->addWidget(ghnsButton); | ||
92 | 87 | | |||
93 | QVBoxLayout* layout = new QVBoxLayout(this); | 88 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
94 | KTitleWidget* infoLabel = new KTitleWidget(tabWidget); | 89 | KTitleWidget* infoLabel = new KTitleWidget(tabWidget); | ||
95 | infoLabel->setText(i18n("Focus policy settings limit the functionality of navigating through windows."), | 90 | infoLabel->setText(i18n("Focus policy settings limit the functionality of navigating through windows."), | ||
96 | KTitleWidget::InfoMessage); | 91 | KTitleWidget::InfoMessage); | ||
97 | infoLabel->setPixmap(KTitleWidget::InfoMessage, KTitleWidget::ImageLeft); | 92 | infoLabel->setPixmap(KTitleWidget::InfoMessage, KTitleWidget::ImageLeft); | ||
98 | layout->addWidget(infoLabel,0); | 93 | layout->addWidget(infoLabel,0); | ||
99 | layout->addWidget(tabWidget,1); | 94 | layout->addWidget(tabWidget,1); | ||
100 | layout->addLayout(buttonBar); | 95 | layout->addLayout(buttonBar); | ||
101 | setLayout(layout); | 96 | setLayout(layout); | ||
102 | 97 | | |||
103 | #define ADD_SHORTCUT(_NAME_, _CUT_, _BTN_) \ | 98 | addConfig(m_tabBoxConfig, m_primaryTabBoxUi); | ||
104 | a = m_actionCollection->addAction(_NAME_);\ | 99 | addConfig(m_tabBoxAlternativeConfig, m_alternativeTabBoxUi); | ||
105 | a->setProperty("isConfigurationAction", true);\ | | |||
106 | _BTN_->setProperty("shortcutAction", _NAME_);\ | | |||
107 | a->setText(i18n(_NAME_));\ | | |||
108 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << _CUT_); \ | | |||
109 | connect(_BTN_, SIGNAL(keySequenceChanged(QKeySequence)), SLOT(shortcutChanged(QKeySequence))) | | |||
110 | | ||||
111 | // Shortcut config. The shortcut belongs to the component "kwin"! | | |||
112 | m_actionCollection = new KActionCollection(this, QStringLiteral("kwin")); | | |||
113 | m_actionCollection->setComponentDisplayName(i18n("KWin")); | | |||
114 | m_actionCollection->setConfigGroup("Navigation"); | | |||
115 | m_actionCollection->setConfigGlobal(true); | | |||
116 | QAction* a; | | |||
117 | ADD_SHORTCUT("Walk Through Windows", Qt::ALT + Qt::Key_Tab, m_primaryTabBoxUi->scAll); | | |||
118 | ADD_SHORTCUT("Walk Through Windows (Reverse)", Qt::ALT + Qt::SHIFT + Qt::Key_Backtab, | | |||
119 | m_primaryTabBoxUi->scAllReverse); | | |||
120 | ADD_SHORTCUT("Walk Through Windows Alternative", QKeySequence(), m_alternativeTabBoxUi->scAll); | | |||
121 | ADD_SHORTCUT("Walk Through Windows Alternative (Reverse)", QKeySequence(), m_alternativeTabBoxUi->scAllReverse); | | |||
122 | ADD_SHORTCUT("Walk Through Windows of Current Application", Qt::ALT + Qt::Key_QuoteLeft, | | |||
123 | m_primaryTabBoxUi->scCurrent); | | |||
124 | ADD_SHORTCUT("Walk Through Windows of Current Application (Reverse)", Qt::ALT + Qt::Key_AsciiTilde, | | |||
125 | m_primaryTabBoxUi->scCurrentReverse); | | |||
126 | ADD_SHORTCUT("Walk Through Windows of Current Application Alternative", QKeySequence(), m_alternativeTabBoxUi->scCurrent); | | |||
127 | ADD_SHORTCUT("Walk Through Windows of Current Application Alternative (Reverse)", QKeySequence(), | | |||
128 | m_alternativeTabBoxUi->scCurrentReverse); | | |||
129 | #undef ADD_SHORTCUT | | |||
130 | 100 | | |||
131 | initLayoutLists(); | 101 | createConnections(m_primaryTabBoxUi, m_tabBoxConfig); | ||
132 | KWinTabBoxConfigForm *ui[2] = { m_primaryTabBoxUi, m_alternativeTabBoxUi }; | 102 | createConnections(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | ||
133 | for (int i = 0; i < 2; ++i) { | | |||
134 | ui[i]->effectConfigButton->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); | | |||
135 | 103 | | |||
136 | connect(ui[i]->highlightWindowCheck, SIGNAL(clicked(bool)), SLOT(changed())); | 104 | initLayoutLists(); | ||
137 | connect(ui[i]->showTabBox, SIGNAL(clicked(bool)), SLOT(tabBoxToggled(bool))); | | |||
138 | connect(ui[i]->effectCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); | | |||
139 | connect(ui[i]->effectCombo, SIGNAL(currentIndexChanged(int)), SLOT(effectSelectionChanged(int))); | | |||
140 | connect(ui[i]->effectConfigButton, SIGNAL(clicked(bool)), SLOT(configureEffectClicked())); | | |||
141 | | ||||
142 | connect(ui[i]->switchingModeCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); | | |||
143 | connect(ui[i]->showDesktop, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
144 | | ||||
145 | connect(ui[i]->filterDesktops, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
146 | connect(ui[i]->currentDesktop, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
147 | connect(ui[i]->otherDesktops, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
148 | | ||||
149 | connect(ui[i]->filterActivities, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
150 | connect(ui[i]->currentActivity, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
151 | connect(ui[i]->otherActivities, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
152 | | ||||
153 | connect(ui[i]->filterScreens, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
154 | if (QApplication::screens().count() < 2) { | | |||
155 | ui[i]->filterScreens->hide(); | | |||
156 | ui[i]->screenFilter->hide(); | | |||
157 | } else { | | |||
158 | connect(ui[i]->currentScreen, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
159 | connect(ui[i]->otherScreens, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
160 | } | | |||
161 | | ||||
162 | connect(ui[i]->oneAppWindow, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
163 | connect(ui[i]->filterMinimization, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
164 | connect(ui[i]->visibleWindows, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
165 | connect(ui[i]->hiddenWindows, SIGNAL(clicked(bool)), SLOT(changed())); | | |||
166 | } | | |||
167 | 105 | | |||
168 | // check focus policy - we don't offer configs for unreasonable focus policies | 106 | // check focus policy - we don't offer configs for unreasonable focus policies | ||
169 | KConfigGroup config(m_config, "Windows"); | 107 | KConfigGroup config(m_config, "Windows"); | ||
170 | QString policy = config.readEntry("FocusPolicy", "ClickToFocus"); | 108 | QString policy = config.readEntry("FocusPolicy", "ClickToFocus"); | ||
171 | if ((policy == "FocusUnderMouse") || (policy == "FocusStrictlyUnderMouse")) { | 109 | if ((policy == "FocusUnderMouse") || (policy == "FocusStrictlyUnderMouse")) { | ||
172 | tabWidget->setEnabled(false); | 110 | tabWidget->setEnabled(false); | ||
173 | infoLabel->show(); | 111 | infoLabel->show(); | ||
174 | } else { | 112 | } else { | ||
175 | infoLabel->hide(); | 113 | infoLabel->hide(); | ||
176 | } | 114 | } | ||
177 | } | 115 | } | ||
178 | 116 | | |||
179 | KWinTabBoxConfig::~KWinTabBoxConfig() | 117 | KWinTabBoxConfig::~KWinTabBoxConfig() | ||
180 | { | 118 | { | ||
181 | } | 119 | } | ||
182 | 120 | | |||
183 | | ||||
184 | static QList<KPackage::Package> availableLnFPackages() | 121 | static QList<KPackage::Package> availableLnFPackages() | ||
185 | { | 122 | { | ||
186 | QList<KPackage::Package> packages; | 123 | QList<KPackage::Package> packages; | ||
187 | QStringList paths; | 124 | QStringList paths; | ||
188 | const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | 125 | const QStringList dataPaths = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation); | ||
189 | 126 | | |||
190 | for (const QString &path : dataPaths) { | 127 | for (const QString &path : dataPaths) { | ||
191 | QDir dir(path + QLatin1String("/plasma/look-and-feel")); | 128 | QDir dir(path + QLatin1String("/plasma/look-and-feel")); | ||
Show All 16 Lines | |||||
208 | } | 145 | } | ||
209 | 146 | | |||
210 | return packages; | 147 | return packages; | ||
211 | } | 148 | } | ||
212 | 149 | | |||
213 | void KWinTabBoxConfig::initLayoutLists() | 150 | void KWinTabBoxConfig::initLayoutLists() | ||
214 | { | 151 | { | ||
215 | // search the effect names | 152 | // search the effect names | ||
216 | QString coverswitch = BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).displayName; | 153 | m_coverSwitch = BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).name; | ||
217 | QString flipswitch = BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).displayName; | 154 | m_flipSwitch = BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).name; | ||
218 | 155 | | |||
219 | QList<KPluginMetaData> offers = KPackage::PackageLoader::self()->listPackages("KWin/WindowSwitcher"); | 156 | QList<KPluginMetaData> offers = KPackage::PackageLoader::self()->listPackages("KWin/WindowSwitcher"); | ||
220 | QStringList layoutNames, layoutPlugins, layoutPaths; | 157 | QStringList layoutNames, layoutPlugins, layoutPaths; | ||
221 | 158 | | |||
222 | const auto lnfPackages = availableLnFPackages(); | 159 | const auto lnfPackages = availableLnFPackages(); | ||
223 | for (const auto &package : lnfPackages) { | 160 | for (const auto &package : lnfPackages) { | ||
224 | const auto &metaData = package.metadata(); | 161 | const auto &metaData = package.metadata(); | ||
225 | layoutNames << metaData.name(); | 162 | layoutNames << metaData.name(); | ||
Show All 18 Lines | 180 | if (scriptFile.isNull()) { | |||
244 | continue; | 181 | continue; | ||
245 | } | 182 | } | ||
246 | 183 | | |||
247 | layoutNames << offer.name(); | 184 | layoutNames << offer.name(); | ||
248 | layoutPlugins << pluginName; | 185 | layoutPlugins << pluginName; | ||
249 | layoutPaths << scriptFile; | 186 | layoutPaths << scriptFile; | ||
250 | } | 187 | } | ||
251 | 188 | | |||
189 | | ||||
252 | KWinTabBoxConfigForm *ui[2] = { m_primaryTabBoxUi, m_alternativeTabBoxUi }; | 190 | KWinTabBoxConfigForm *ui[2] = { m_primaryTabBoxUi, m_alternativeTabBoxUi }; | ||
253 | for (int i=0; i<2; ++i) { | 191 | for (int i=0; i<2; ++i) { | ||
254 | int index = ui[i]->effectCombo->currentIndex(); | 192 | QStandardItemModel *model = new QStandardItemModel; | ||
255 | QVariant data = ui[i]->effectCombo->itemData(index); | 193 | | ||
256 | ui[i]->effectCombo->clear(); | 194 | QStandardItem *coverItem = new QStandardItem(BuiltInEffects::effectData(BuiltInEffect::CoverSwitch).displayName); | ||
257 | ui[i]->effectCombo->addItem(coverswitch); | 195 | coverItem->setData(m_coverSwitch, Qt::UserRole); | ||
258 | ui[i]->effectCombo->addItem(flipswitch); | 196 | coverItem->setData(false, KWinTabBoxConfigForm::AddonEffect); | ||
197 | model->appendRow(coverItem); | ||||
198 | | ||||
199 | QStandardItem *flipItem = new QStandardItem(BuiltInEffects::effectData(BuiltInEffect::FlipSwitch).displayName); | ||||
200 | flipItem->setData(m_flipSwitch, Qt::UserRole); | ||||
201 | flipItem->setData(false, KWinTabBoxConfigForm::AddonEffect); | ||||
202 | model->appendRow(flipItem); | ||||
203 | | ||||
259 | for (int j = 0; j < layoutNames.count(); ++j) { | 204 | for (int j = 0; j < layoutNames.count(); ++j) { | ||
260 | ui[i]->effectCombo->addItem(layoutNames[j], layoutPlugins[j]); | 205 | QStandardItem *item = new QStandardItem(layoutNames[j]); | ||
261 | ui[i]->effectCombo->setItemData(ui[i]->effectCombo->count() - 1, layoutPaths[j], Qt::UserRole+1); | 206 | item->setData(layoutPlugins[j], Qt::UserRole); | ||
207 | item->setData(layoutPaths[j], KWinTabBoxConfigForm::LayoutPath); | ||||
208 | item->setData(true, KWinTabBoxConfigForm::AddonEffect); | ||||
209 | model->appendRow(item); | ||||
262 | } | 210 | } | ||
263 | if (data.isValid()) { | 211 | model->sort(0); | ||
264 | ui[i]->effectCombo->setCurrentIndex(ui[i]->effectCombo->findData(data)); | 212 | ui[i]->setEffectComboModel(model); | ||
265 | } else if (index != -1) { | 213 | } | ||
266 | ui[i]->effectCombo->setCurrentIndex(index); | 214 | } | ||
215 | | ||||
216 | void KWinTabBoxConfig::createConnections(KWinTabBoxConfigForm *form, TabBoxSettings *config) | ||||
217 | { | ||||
218 | connect(form, SIGNAL(effectConfigButtonClicked()), SLOT(configureEffectClicked())); | ||||
meven: Too bad we have to use old syntax for private slots | |||||
219 | | ||||
220 | connect(form, SIGNAL(filterScreenChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
Risk seems low... but just in case, I'd use the four variant connect in this method still and pass this as third parameter just before the lambda. Granted in case of crash the bug would be somewhere else (as in the reason why ui would outlive this...) but if I would be the future developer having to debug such a regression I'd rather have another symptom than a crash deep within Qt signal emission implementation. :-) ervin: Risk seems low... but just in case, I'd use the four variant connect in this method still and… | |||||
221 | connect(form, SIGNAL(filterDesktopChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
222 | connect(form, SIGNAL(filterActivitiesChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
Probably works, that being said, we're not supposed to temper with the config object in those slots (this is a KCModule not a Plasma::ConfigModule, they unfortunately both have very different approaches). If we want to stay true to the KCModule approach, we'd rather connect to updateUnmanagedState() directly, and inside updateUnmanagedState() compare the widget value with the corresponding setting values. ervin: Probably works, that being said, we're not supposed to temper with the config object in those… | |||||
223 | connect(form, SIGNAL(filterMinimizationChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
224 | connect(form, SIGNAL(applicationModeChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
225 | connect(form, SIGNAL(showDesktopModeChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
226 | connect(form, SIGNAL(switchingModeChanged(int)), this, SLOT(updateUnmanagedState())); | ||||
227 | connect(form, SIGNAL(layoutNameChanged(QString)), this, SLOT(updateUnmanagedState())); | ||||
228 | } | ||||
229 | | ||||
230 | void KWinTabBoxConfig::updateUnmanagedState() | ||||
231 | { | ||||
232 | bool isNeedSave = false; | ||||
233 | isNeedSave |= updateUnmanagedIsNeedSave(m_primaryTabBoxUi, m_tabBoxConfig); | ||||
234 | isNeedSave |= updateUnmanagedIsNeedSave(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | ||||
235 | | ||||
236 | unmanagedWidgetChangeState(isNeedSave); | ||||
237 | | ||||
238 | bool isDefault = true; | ||||
239 | isDefault &= updateUnmanagedIsDefault(m_primaryTabBoxUi, m_tabBoxConfig); | ||||
240 | isDefault &= updateUnmanagedIsDefault(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | ||||
241 | | ||||
242 | unmanagedWidgetDefaultState(isDefault); | ||||
267 | } | 243 | } | ||
244 | | ||||
245 | bool KWinTabBoxConfig::updateUnmanagedIsNeedSave(const KWinTabBoxConfigForm *form, const TabBoxSettings *config) | ||||
246 | { | ||||
247 | bool isNeedSave = false; | ||||
248 | isNeedSave |= form->filterScreen() != config->multiScreenMode(); | ||||
249 | isNeedSave |= form->filterDesktop() != config->desktopMode(); | ||||
250 | isNeedSave |= form->filterActivities() != config->activitiesMode(); | ||||
251 | isNeedSave |= form->filterMinimization() != config->minimizedMode(); | ||||
252 | isNeedSave |= form->applicationMode() != config->applicationsMode(); | ||||
253 | isNeedSave |= form->showDesktopMode() != config->showDesktopMode(); | ||||
254 | isNeedSave |= form->switchingMode() != config->switchingMode(); | ||||
255 | isNeedSave |= form->layoutName() != config->layoutName(); | ||||
256 | | ||||
If you address my comment above, implementation here is likely to change quite a bit. ervin: If you address my comment above, implementation here is likely to change quite a bit. | |||||
257 | return isNeedSave; | ||||
268 | } | 258 | } | ||
259 | | ||||
260 | bool KWinTabBoxConfig::updateUnmanagedIsDefault(const KWinTabBoxConfigForm *form, const TabBoxSettings *config) | ||||
261 | { | ||||
262 | bool isDefault = true; | ||||
263 | isDefault &= form->filterScreen() == config->defaultMultiScreenModeValue(); | ||||
264 | isDefault &= form->filterDesktop() == config->defaultDesktopModeValue(); | ||||
265 | isDefault &= form->filterActivities() == config->defaultActivitiesModeValue(); | ||||
266 | isDefault &= form->filterMinimization() == config->defaultMinimizedModeValue(); | ||||
267 | isDefault &= form->applicationMode() == config->defaultApplicationsModeValue(); | ||||
268 | isDefault &= form->showDesktopMode() == config->defaultShowDesktopModeValue(); | ||||
269 | isDefault &= form->switchingMode() == config->defaultSwitchingModeValue(); | ||||
270 | isDefault &= form->layoutName() == config->defaultLayoutNameValue(); | ||||
271 | | ||||
272 | return isDefault; | ||||
269 | } | 273 | } | ||
270 | 274 | | |||
271 | void KWinTabBoxConfig::load() | 275 | void KWinTabBoxConfig::load() | ||
272 | { | 276 | { | ||
273 | KCModule::load(); | 277 | KCModule::load(); | ||
274 | 278 | | |||
275 | m_tabBoxConfig->load(); | 279 | m_tabBoxConfig->load(); | ||
276 | m_tabBoxAlternativeConfig->load(); | 280 | m_tabBoxAlternativeConfig->load(); | ||
277 | 281 | | |||
282 | updateUiFromConfig(m_primaryTabBoxUi, m_tabBoxConfig); | ||||
283 | updateUiFromConfig(m_alternativeTabBoxUi , m_tabBoxAlternativeConfig); | ||||
284 | | ||||
278 | m_coverSwitchConfig->load(); | 285 | m_coverSwitchConfig->load(); | ||
279 | m_flipSwitchConfig->load(); | 286 | m_flipSwitchConfig->load(); | ||
280 | 287 | | |||
281 | m_pluginsConfig->load(); | 288 | m_pluginsConfig->load(); | ||
282 | 289 | | |||
283 | updateUiFromConfig(m_primaryTabBoxUi, m_tabBoxConfig); | | |||
284 | updateUiFromConfig(m_alternativeTabBoxUi , m_tabBoxAlternativeConfig); | | |||
285 | | ||||
286 | if (m_pluginsConfig->coverswitchEnabled()) { | 290 | if (m_pluginsConfig->coverswitchEnabled()) { | ||
287 | if (m_coverSwitchConfig->tabBox()) { | 291 | if (m_coverSwitchConfig->tabBox()) { | ||
288 | m_primaryTabBoxUi->effectCombo->setCurrentIndex(CoverSwitch); | 292 | m_primaryTabBoxUi->setLayoutName(m_coverSwitch); | ||
289 | } | 293 | } | ||
290 | if (m_coverSwitchConfig->tabBoxAlternative()) { | 294 | if (m_coverSwitchConfig->tabBoxAlternative()) { | ||
291 | m_alternativeTabBoxUi->effectCombo->setCurrentIndex(CoverSwitch); | 295 | m_alternativeTabBoxUi->setLayoutName(m_coverSwitch); | ||
292 | } | 296 | } | ||
293 | } | 297 | } | ||
294 | if (m_pluginsConfig->flipswitchEnabled()) { | 298 | if (m_pluginsConfig->flipswitchEnabled()) { | ||
295 | if (m_flipSwitchConfig->tabBox()) { | 299 | if (m_flipSwitchConfig->tabBox()) { | ||
296 | m_primaryTabBoxUi->effectCombo->setCurrentIndex(FlipSwitch); | 300 | m_primaryTabBoxUi->setLayoutName(m_flipSwitch); | ||
297 | } | 301 | } | ||
298 | if (m_flipSwitchConfig->tabBoxAlternative()) { | 302 | if (m_flipSwitchConfig->tabBoxAlternative()) { | ||
299 | m_alternativeTabBoxUi->effectCombo->setCurrentIndex(FlipSwitch); | 303 | m_alternativeTabBoxUi->setLayoutName(m_flipSwitch); | ||
300 | } | 304 | } | ||
301 | } | 305 | } | ||
302 | 306 | | |||
303 | KWinTabBoxConfigForm* ui[2] = { m_primaryTabBoxUi, m_alternativeTabBoxUi }; | 307 | m_primaryTabBoxUi->loadShortcuts(); | ||
304 | for (int i = 0; i < 2; ++i) { | 308 | m_alternativeTabBoxUi->loadShortcuts(); | ||
305 | QString action; | 309 | | ||
306 | #define LOAD_SHORTCUT(_BTN_)\ | 310 | updateUnmanagedState(); | ||
307 | action = ui[i]->_BTN_->property("shortcutAction").toString();\ | | |||
308 | qDebug() << "load shortcut for " << action;\ | | |||
309 | if (QAction *a = m_actionCollection->action(action)) { \ | | |||
310 | auto shortcuts = KGlobalAccel::self()->shortcut(a); \ | | |||
311 | if (!shortcuts.isEmpty()) \ | | |||
312 | ui[i]->_BTN_->setKeySequence(shortcuts.first()); \ | | |||
313 | } | | |||
314 | LOAD_SHORTCUT(scAll); | | |||
315 | LOAD_SHORTCUT(scAllReverse); | | |||
316 | LOAD_SHORTCUT(scCurrent); | | |||
317 | LOAD_SHORTCUT(scCurrentReverse); | | |||
318 | #undef LOAD_SHORTCUT | | |||
319 | } | | |||
320 | emit changed(false); | | |||
321 | } | 311 | } | ||
322 | 312 | | |||
323 | void KWinTabBoxConfig::save() | 313 | void KWinTabBoxConfig::save() | ||
324 | { | 314 | { | ||
325 | KCModule::save(); | | |||
326 | | ||||
327 | // sync ui to config | | |||
328 | updateConfigFromUi(m_primaryTabBoxUi, m_tabBoxConfig); | | |||
329 | updateConfigFromUi(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | | |||
330 | m_tabBoxConfig->save(); | | |||
331 | m_tabBoxAlternativeConfig->save(); | | |||
332 | | ||||
333 | // effects | 315 | // effects | ||
334 | bool highlightWindows = m_primaryTabBoxUi->highlightWindowCheck->isChecked() || | 316 | const bool highlightWindows = m_primaryTabBoxUi->highlightWindows() || m_alternativeTabBoxUi->highlightWindows(); | ||
335 | m_alternativeTabBoxUi->highlightWindowCheck->isChecked(); | 317 | const bool coverSwitch = m_primaryTabBoxUi->showTabBox() | ||
336 | const bool coverSwitch = m_primaryTabBoxUi->showTabBox->isChecked() && | 318 | && m_primaryTabBoxUi->effectComboCurrentData().toString() == m_coverSwitch; | ||
337 | m_primaryTabBoxUi->effectCombo->currentIndex() == CoverSwitch; | 319 | const bool flipSwitch = m_primaryTabBoxUi->showTabBox() | ||
338 | const bool flipSwitch = m_primaryTabBoxUi->showTabBox->isChecked() && | 320 | && m_primaryTabBoxUi->effectComboCurrentData().toString() == m_flipSwitch; | ||
339 | m_primaryTabBoxUi->effectCombo->currentIndex() == FlipSwitch; | 321 | const bool coverSwitchAlternative = m_alternativeTabBoxUi->showTabBox() | ||
340 | const bool coverSwitchAlternative = m_alternativeTabBoxUi->showTabBox->isChecked() && | 322 | && m_alternativeTabBoxUi->effectComboCurrentData().toString() == m_coverSwitch; | ||
341 | m_alternativeTabBoxUi->effectCombo->currentIndex() == CoverSwitch; | 323 | const bool flipSwitchAlternative = m_alternativeTabBoxUi->showTabBox() | ||
342 | const bool flipSwitchAlternative = m_alternativeTabBoxUi->showTabBox->isChecked() && | 324 | && m_alternativeTabBoxUi->effectComboCurrentData().toString() == m_flipSwitch; | ||
343 | m_alternativeTabBoxUi->effectCombo->currentIndex() == FlipSwitch; | | |||
344 | 325 | | |||
345 | // activate effects if not active | 326 | // activate effects if not active | ||
346 | if (coverSwitch || coverSwitchAlternative) { | 327 | if (coverSwitch || coverSwitchAlternative) { | ||
347 | m_pluginsConfig->setCoverswitchEnabled(true); | 328 | m_pluginsConfig->setCoverswitchEnabled(true); | ||
348 | } | 329 | } | ||
349 | if (flipSwitch || flipSwitchAlternative) { | 330 | if (flipSwitch || flipSwitchAlternative) { | ||
350 | m_pluginsConfig->setFlipswitchEnabled(true); | 331 | m_pluginsConfig->setFlipswitchEnabled(true); | ||
351 | } | 332 | } | ||
352 | if (highlightWindows) { | 333 | if (highlightWindows) { | ||
353 | m_pluginsConfig->setHighlightwindowEnabled(true); | 334 | m_pluginsConfig->setHighlightwindowEnabled(true); | ||
354 | } | 335 | } | ||
355 | m_pluginsConfig->save(); | 336 | m_pluginsConfig->save(); | ||
356 | 337 | | |||
357 | m_coverSwitchConfig->setTabBox(coverSwitch); | 338 | m_coverSwitchConfig->setTabBox(coverSwitch); | ||
358 | m_coverSwitchConfig->setTabBoxAlternative(coverSwitchAlternative); | 339 | m_coverSwitchConfig->setTabBoxAlternative(coverSwitchAlternative); | ||
359 | m_coverSwitchConfig->save(); | 340 | m_coverSwitchConfig->save(); | ||
360 | 341 | | |||
361 | m_flipSwitchConfig->setTabBox(flipSwitch); | 342 | m_flipSwitchConfig->setTabBox(flipSwitch); | ||
362 | m_flipSwitchConfig->setTabBoxAlternative(flipSwitchAlternative); | 343 | m_flipSwitchConfig->setTabBoxAlternative(flipSwitchAlternative); | ||
363 | m_flipSwitchConfig->save(); | 344 | m_flipSwitchConfig->save(); | ||
364 | 345 | | |||
346 | updateConfigFromUi(m_primaryTabBoxUi, m_tabBoxConfig); | ||||
I'd expect those save calls to be done by the KCModule::save() call. Maybe what you want is instead of have the KCModule::save() call done before the dbug message being sent out. ervin: I'd expect those save calls to be done by the KCModule::save() call. Maybe what you want is… | |||||
347 | updateConfigFromUi(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | ||||
348 | | ||||
349 | m_tabBoxConfig->save(); | ||||
350 | m_tabBoxAlternativeConfig->save(); | ||||
351 | | ||||
352 | KCModule::save(); | ||||
353 | updateUnmanagedState(); | ||||
354 | | ||||
365 | // Reload KWin. | 355 | // Reload KWin. | ||
366 | QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); | 356 | QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); | ||
367 | QDBusConnection::sessionBus().send(message); | 357 | QDBusConnection::sessionBus().send(message); | ||
368 | // and reconfigure the effects | 358 | // and reconfigure the effects | ||
369 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | 359 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||
370 | QStringLiteral("/Effects"), | 360 | QStringLiteral("/Effects"), | ||
371 | QDBusConnection::sessionBus()); | 361 | QDBusConnection::sessionBus()); | ||
372 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::CoverSwitch)); | 362 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::CoverSwitch)); | ||
373 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::FlipSwitch)); | 363 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::FlipSwitch)); | ||
374 | | ||||
375 | emit changed(false); | | |||
376 | } | 364 | } | ||
377 | 365 | | |||
378 | void KWinTabBoxConfig::defaults() | 366 | void KWinTabBoxConfig::defaults() | ||
379 | { | 367 | { | ||
380 | KCModule::defaults(); | | |||
381 | | ||||
382 | m_tabBoxConfig->setDefaults(); | | |||
383 | m_tabBoxAlternativeConfig->setDefaults(); | | |||
384 | | ||||
385 | m_pluginsConfig->setDefaults(); | | |||
386 | m_coverSwitchConfig->setDefaults(); | 368 | m_coverSwitchConfig->setDefaults(); | ||
387 | m_flipSwitchConfig->setDefaults(); | 369 | m_flipSwitchConfig->setDefaults(); | ||
388 | 370 | | |||
389 | updateUiFromConfig(m_primaryTabBoxUi, m_tabBoxConfig); | 371 | updateUiFromDefaultConfig(m_primaryTabBoxUi, m_tabBoxConfig); | ||
390 | updateUiFromConfig(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | 372 | updateUiFromDefaultConfig(m_alternativeTabBoxUi, m_tabBoxAlternativeConfig); | ||
391 | 373 | | |||
392 | QString action; | 374 | m_primaryTabBoxUi->resetShortcuts(); | ||
393 | auto RESET_SHORTCUT = [this](KKeySequenceWidget *widget, const QKeySequence &sequence = QKeySequence()) { | 375 | m_alternativeTabBoxUi->resetShortcuts(); | ||
394 | const QString action = widget->property("shortcutAction").toString(); | | |||
395 | QAction *a = m_actionCollection->action(action); | | |||
396 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << sequence, KGlobalAccel::NoAutoloading); | | |||
397 | }; | | |||
398 | RESET_SHORTCUT(m_primaryTabBoxUi->scAll, Qt::ALT + Qt::Key_Tab); | | |||
399 | RESET_SHORTCUT(m_primaryTabBoxUi->scAllReverse, Qt::ALT + Qt::SHIFT + Qt::Key_Backtab); | | |||
400 | RESET_SHORTCUT(m_alternativeTabBoxUi->scAll); | | |||
401 | RESET_SHORTCUT(m_alternativeTabBoxUi->scAllReverse); | | |||
402 | RESET_SHORTCUT(m_primaryTabBoxUi->scCurrent, Qt::ALT + Qt::Key_QuoteLeft); | | |||
403 | RESET_SHORTCUT(m_primaryTabBoxUi->scCurrentReverse, Qt::ALT + Qt::Key_AsciiTilde); | | |||
404 | RESET_SHORTCUT(m_alternativeTabBoxUi->scCurrent); | | |||
405 | RESET_SHORTCUT(m_alternativeTabBoxUi->scCurrentReverse); | | |||
406 | m_actionCollection->writeSettings(); | | |||
407 | emit changed(true); | | |||
408 | } | | |||
409 | | ||||
410 | void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm *ui, const KWin::TabBox::TabBoxSettings *config) | | |||
411 | { | | |||
412 | #define CONFIGURE(SETTING, MODE, IS, VALUE) ui->SETTING->setChecked(config->MODE##Mode() IS TabBoxConfig::VALUE) | | |||
413 | CONFIGURE(filterDesktops, desktop, !=, AllDesktopsClients); | | |||
414 | CONFIGURE(currentDesktop, desktop, ==, OnlyCurrentDesktopClients); | | |||
415 | CONFIGURE(otherDesktops, desktop, ==, ExcludeCurrentDesktopClients); | | |||
416 | CONFIGURE(filterActivities, activities, !=, AllActivitiesClients); | | |||
417 | CONFIGURE(currentActivity, activities, ==, OnlyCurrentActivityClients); | | |||
418 | CONFIGURE(otherActivities, activities, ==, ExcludeCurrentActivityClients); | | |||
419 | CONFIGURE(filterScreens, multiScreen, !=, IgnoreMultiScreen); | | |||
420 | CONFIGURE(currentScreen, multiScreen, ==, OnlyCurrentScreenClients); | | |||
421 | CONFIGURE(otherScreens, multiScreen, ==, ExcludeCurrentScreenClients); | | |||
422 | CONFIGURE(oneAppWindow, applications, ==, OneWindowPerApplication); | | |||
423 | CONFIGURE(filterMinimization, minimized, !=, IgnoreMinimizedStatus); | | |||
424 | CONFIGURE(visibleWindows, minimized, ==, ExcludeMinimizedClients); | | |||
425 | CONFIGURE(hiddenWindows, minimized, ==, OnlyMinimizedClients); | | |||
426 | | ||||
427 | ui->switchingModeCombo->setCurrentIndex(config->switchingMode()); | | |||
428 | | ||||
429 | // check boxes | | |||
430 | ui->showTabBox->setChecked(config->showTabBox()); | | |||
431 | ui->highlightWindowCheck->setChecked(config->highlightWindows()); | | |||
432 | ui->effectCombo->setCurrentIndex(ui->effectCombo->findData(config->layoutName())); | | |||
433 | CONFIGURE(showDesktop, showDesktop, ==, ShowDesktopClient); | | |||
434 | #undef CONFIGURE | | |||
435 | } | | |||
436 | 376 | | |||
437 | void KWinTabBoxConfig::updateConfigFromUi(const KWin::KWinTabBoxConfigForm *ui, TabBoxSettings *config) | 377 | KCModule::defaults(); | ||
438 | { | 378 | updateUnmanagedState(); | ||
439 | if (ui->filterDesktops->isChecked()) { | | |||
440 | config->setDesktopMode(ui->currentDesktop->isChecked() ? TabBoxConfig::OnlyCurrentDesktopClients : TabBoxConfig::ExcludeCurrentDesktopClients); | | |||
441 | } else { | | |||
442 | config->setDesktopMode(TabBoxConfig::AllDesktopsClients); | | |||
443 | } | | |||
444 | if (ui->filterActivities->isChecked()) { | | |||
445 | config->setActivitiesMode(ui->currentActivity->isChecked() ? TabBoxConfig::OnlyCurrentActivityClients : TabBoxConfig::ExcludeCurrentActivityClients); | | |||
446 | } else { | | |||
447 | config->setActivitiesMode(TabBoxConfig::AllActivitiesClients); | | |||
448 | } | | |||
449 | if (ui->filterScreens->isChecked()) { | | |||
450 | config->setMultiScreenMode(ui->currentScreen->isChecked() ? TabBoxConfig::OnlyCurrentScreenClients : TabBoxConfig::ExcludeCurrentScreenClients); | | |||
451 | } else { | | |||
452 | config->setMultiScreenMode(TabBoxConfig::IgnoreMultiScreen); | | |||
453 | } | | |||
454 | config->setApplicationsMode(ui->oneAppWindow->isChecked() ? TabBoxConfig::OneWindowPerApplication : TabBoxConfig::AllWindowsAllApplications); | | |||
455 | if (ui->filterMinimization->isChecked()) { | | |||
456 | config->setMinimizedMode(ui->visibleWindows->isChecked() ? TabBoxConfig::ExcludeMinimizedClients : TabBoxConfig::OnlyMinimizedClients); | | |||
457 | } else { | | |||
458 | config->setMinimizedMode(TabBoxConfig::IgnoreMinimizedStatus); | | |||
459 | } | | |||
460 | | ||||
461 | config->setSwitchingMode(TabBoxConfig::ClientSwitchingMode(ui->switchingModeCombo->currentIndex())); | | |||
462 | | ||||
463 | config->setShowTabBox(ui->showTabBox->isChecked()); | | |||
464 | config->setHighlightWindows(ui->highlightWindowCheck->isChecked()); | | |||
465 | if (ui->effectCombo->currentIndex() >= Layout) { | | |||
466 | config->setLayoutName(ui->effectCombo->itemData(ui->effectCombo->currentIndex()).toString()); | | |||
467 | } | | |||
468 | config->setShowDesktopMode(ui->showDesktop->isChecked() ? TabBoxConfig::ShowDesktopClient : TabBoxConfig::DoNotShowDesktopClient); | | |||
469 | } | | |||
470 | | ||||
471 | #define CHECK_CURRENT_TABBOX_UI \ | | |||
472 | Q_ASSERT(sender());\ | | |||
473 | KWinTabBoxConfigForm *ui = nullptr;\ | | |||
474 | QObject *dad = sender();\ | | |||
475 | while (!ui && (dad = dad->parent()))\ | | |||
476 | ui = qobject_cast<KWinTabBoxConfigForm*>(dad);\ | | |||
477 | Q_ASSERT(ui); | | |||
478 | | ||||
479 | void KWinTabBoxConfig::effectSelectionChanged(int index) | | |||
480 | { | | |||
481 | CHECK_CURRENT_TABBOX_UI | | |||
482 | ui->effectConfigButton->setIcon(QIcon::fromTheme(index < Layout ? "configure" : "view-preview")); | | |||
483 | if (!ui->showTabBox->isChecked()) | | |||
484 | return; | | |||
485 | ui->highlightWindowCheck->setEnabled(index >= Layout); | | |||
486 | } | 379 | } | ||
487 | 380 | | |||
488 | void KWinTabBoxConfig::tabBoxToggled(bool on) | 381 | void KWinTabBoxConfig::updateUiFromConfig(KWinTabBoxConfigForm *form, const KWin::TabBox::TabBoxSettings *config) | ||
489 | { | 382 | { | ||
490 | CHECK_CURRENT_TABBOX_UI | 383 | form->setFilterScreen(static_cast<TabBoxConfig::ClientMultiScreenMode>(config->multiScreenMode())); | ||
491 | on = !on || ui->effectCombo->currentIndex() >= Layout; | 384 | form->setFilterDesktop(static_cast<TabBoxConfig::ClientDesktopMode>(config->desktopMode())); | ||
492 | ui->highlightWindowCheck->setEnabled(on); | 385 | form->setFilterActivities(static_cast<TabBoxConfig::ClientActivitiesMode>(config->activitiesMode())); | ||
493 | markAsChanged(); | 386 | form->setFilterMinimization(static_cast<TabBoxConfig::ClientMinimizedMode>(config->minimizedMode())); | ||
387 | form->setApplicationMode(static_cast<TabBoxConfig::ClientApplicationsMode>(config->applicationsMode())); | ||||
388 | form->setShowDesktopMode(static_cast<TabBoxConfig::ShowDesktopMode>(config->showDesktopMode())); | ||||
389 | form->setSwitchingModeChanged(static_cast<TabBoxConfig::ClientSwitchingMode>(config->switchingMode())); | ||||
390 | form->setLayoutName(config->layoutName()); | ||||
391 | } | ||||
392 | | ||||
393 | void KWinTabBoxConfig::updateConfigFromUi(const KWinTabBoxConfigForm *form, TabBoxSettings *config) | ||||
394 | { | ||||
395 | config->setMultiScreenMode(form->filterScreen()); | ||||
396 | config->setDesktopMode(form->filterDesktop()); | ||||
397 | config->setActivitiesMode(form->filterActivities()); | ||||
398 | config->setMinimizedMode(form->filterMinimization()); | ||||
399 | config->setApplicationsMode(form->applicationMode()); | ||||
400 | config->setShowDesktopMode(form->showDesktopMode()); | ||||
401 | config->setSwitchingMode(form->switchingMode()); | ||||
402 | config->setLayoutName(config->layoutName()); | ||||
Oops, should be form->layoutName() instead, otherwise it won't save the new layout. crossi: Oops, should be `form->layoutName()` instead, otherwise it won't save the new layout. | |||||
403 | } | ||||
404 | | ||||
405 | void KWinTabBoxConfig::updateUiFromDefaultConfig(KWinTabBoxConfigForm *form, const KWin::TabBox::TabBoxSettings *config) | ||||
406 | { | ||||
407 | form->setFilterScreen(static_cast<TabBoxConfig::ClientMultiScreenMode>(config->defaultMultiScreenModeValue())); | ||||
408 | form->setFilterDesktop(static_cast<TabBoxConfig::ClientDesktopMode>(config->defaultDesktopModeValue())); | ||||
409 | form->setFilterActivities(static_cast<TabBoxConfig::ClientActivitiesMode>(config->defaultActivitiesModeValue())); | ||||
410 | form->setFilterMinimization(static_cast<TabBoxConfig::ClientMinimizedMode>(config->defaultMinimizedModeValue())); | ||||
411 | form->setApplicationMode(static_cast<TabBoxConfig::ClientApplicationsMode>(config->defaultApplicationsModeValue())); | ||||
412 | form->setShowDesktopMode(static_cast<TabBoxConfig::ShowDesktopMode>(config->defaultShowDesktopModeValue())); | ||||
413 | form->setSwitchingModeChanged(static_cast<TabBoxConfig::ClientSwitchingMode>(config->defaultSwitchingModeValue())); | ||||
414 | form->setLayoutName(config->defaultLayoutNameValue()); | ||||
494 | } | 415 | } | ||
495 | 416 | | |||
496 | void KWinTabBoxConfig::configureEffectClicked() | 417 | void KWinTabBoxConfig::configureEffectClicked() | ||
497 | { | 418 | { | ||
498 | CHECK_CURRENT_TABBOX_UI | 419 | Q_ASSERT(sender()); | ||
Too bad you lost the Q_ASSERT(form) in the process. It's all the more important now that we're using the evil sender(). :-) Could we please have the assert back? ervin: Too bad you lost the Q_ASSERT(form) in the process. It's all the more important now that we're… | |||||
499 | 420 | KWinTabBoxConfigForm *form = nullptr; | |||
ervin: `dad` that's cute :-) | |||||
zzag: Heh, we have a variable somewhere in KWin core called "daddy". :D | |||||
500 | const int effect = ui->effectCombo->currentIndex(); | 421 | QObject *ancestor = sender(); | ||
What!? dad isn't my dad? It's my grand-dad? Or wait my grand-grand-daddy? This is gross. Clearly it's a complicated family with dark secrets. ;-) What about calling it ancestor? ervin: What!? `dad` isn't my dad? It's my grand-dad? Or wait my grand-grand-daddy? This is gross. | |||||
501 | if (effect >= Layout) { | 422 | form = qobject_cast<KWinTabBoxConfigForm *>(ancestor); | ||
Could we maybe drop ancestor? e.g. auto form = qobject_cast<KWinTabBoxConfigForm *>(sender()); zzag: Could we maybe drop `ancestor`? e.g.
```lang=cpp
auto form = qobject_cast<KWinTabBoxConfigForm… | |||||
502 | // TODO: here we need to show the preview | 423 | Q_ASSERT(form); | ||
503 | new LayoutPreview(ui->effectCombo->itemData(effect, Qt::UserRole+1).toString(), this); | 424 | | ||
425 | if (form->effectComboCurrentData(KWinTabBoxConfigForm::AddonEffect).toBool()) { | ||||
426 | // Show the preview for addon effect | ||||
427 | new LayoutPreview(form->effectComboCurrentData(KWinTabBoxConfigForm::LayoutPath).toString(), this); | ||||
504 | } else { | 428 | } else { | ||
429 | // For builtin effect, display a configuration dialog | ||||
meven: s/dispplay/display | |||||
505 | QPointer<QDialog> configDialog = new QDialog(this); | 430 | QPointer<QDialog> configDialog = new QDialog(this); | ||
506 | configDialog->setLayout(new QVBoxLayout); | 431 | configDialog->setLayout(new QVBoxLayout); | ||
507 | configDialog->setWindowTitle(ui->effectCombo->currentText()); | 432 | configDialog->setWindowTitle(form->effectComboCurrentData(Qt::DisplayRole).toString()); | ||
508 | QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults, configDialog); | 433 | QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::RestoreDefaults, configDialog); | ||
509 | connect(buttonBox, SIGNAL(accepted()), configDialog, SLOT(accept())); | 434 | connect(buttonBox, SIGNAL(accepted()), configDialog, SLOT(accept())); | ||
510 | connect(buttonBox, SIGNAL(rejected()), configDialog, SLOT(reject())); | 435 | connect(buttonBox, SIGNAL(rejected()), configDialog, SLOT(reject())); | ||
511 | 436 | | |||
512 | const QString name = BuiltInEffects::nameForEffect(effect == CoverSwitch ? BuiltInEffect::CoverSwitch : BuiltInEffect::FlipSwitch); | 437 | const QString name = form->effectComboCurrentData().toString(); | ||
513 | | ||||
514 | KCModule *kcm = KPluginTrader::createInstanceFromQuery<KCModule>(QStringLiteral("kwin/effects/configs/"), QString(), | 438 | KCModule *kcm = KPluginTrader::createInstanceFromQuery<KCModule>(QStringLiteral("kwin/effects/configs/"), QString(), | ||
515 | QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(name), | 439 | QStringLiteral("'%1' in [X-KDE-ParentComponents]").arg(name), | ||
516 | configDialog); | 440 | configDialog); | ||
517 | if (!kcm) { | 441 | if (!kcm) { | ||
518 | delete configDialog; | 442 | delete configDialog; | ||
519 | return; | 443 | return; | ||
520 | } | 444 | } | ||
521 | 445 | | |||
Show All 10 Lines | 455 | if (configDialog->exec() == QDialog::Accepted) { | |||
532 | kcm->save(); | 456 | kcm->save(); | ||
533 | } else { | 457 | } else { | ||
534 | kcm->load(); | 458 | kcm->load(); | ||
535 | } | 459 | } | ||
536 | delete configDialog; | 460 | delete configDialog; | ||
537 | } | 461 | } | ||
538 | } | 462 | } | ||
539 | 463 | | |||
540 | void KWinTabBoxConfig::shortcutChanged(const QKeySequence &seq) | | |||
541 | { | | |||
542 | QString action; | | |||
543 | if (sender()) | | |||
544 | action = sender()->property("shortcutAction").toString(); | | |||
545 | if (action.isEmpty()) | | |||
546 | return; | | |||
547 | QAction *a = m_actionCollection->action(action); | | |||
548 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading); | | |||
549 | m_actionCollection->writeSettings(); | | |||
550 | } | | |||
551 | | ||||
552 | void KWinTabBoxConfig::slotGHNS() | 464 | void KWinTabBoxConfig::slotGHNS() | ||
553 | { | 465 | { | ||
554 | QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog("kwinswitcher.knsrc", this); | 466 | QPointer<KNS3::DownloadDialog> downloadDialog = new KNS3::DownloadDialog("kwinswitcher.knsrc", this); | ||
555 | if (downloadDialog->exec() == QDialog::Accepted) { | 467 | if (downloadDialog->exec() == QDialog::Accepted) { | ||
556 | if (!downloadDialog->changedEntries().isEmpty()) { | 468 | if (!downloadDialog->changedEntries().isEmpty()) { | ||
557 | initLayoutLists(); | 469 | initLayoutLists(); | ||
558 | } | 470 | } | ||
559 | } | 471 | } | ||
560 | delete downloadDialog; | 472 | delete downloadDialog; | ||
561 | } | 473 | } | ||
562 | 474 | | |||
563 | } // namespace | 475 | } // namespace | ||
564 | 476 | | |||
565 | #include "main.moc" | 477 | #include "main.moc" |
Too bad we have to use old syntax for private slots