Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooser.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 122 | { | |||
---|---|---|---|---|---|
129 | { | 129 | { | ||
130 | KConfig cfg(*it, KConfig::SimpleConfig); | 130 | KConfig cfg(*it, KConfig::SimpleConfig); | ||
131 | KConfigGroup cg = cfg.group(QByteArray()); | 131 | KConfigGroup cg = cfg.group(QByteArray()); | ||
132 | QListWidgetItem *item = new QListWidgetItem( | 132 | QListWidgetItem *item = new QListWidgetItem( | ||
133 | QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), | 133 | QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), | ||
134 | cg.readEntry("Name",i18n("Unknown"))); | 134 | cg.readEntry("Name",i18n("Unknown"))); | ||
135 | item->setData(Qt::UserRole, (*it)); | 135 | item->setData(Qt::UserRole, (*it)); | ||
136 | ServiceChooser->addItem(item); | 136 | ServiceChooser->addItem(item); | ||
137 | loadConfigWidget((*it), cfg.group(QByteArray()).readEntry("configurationType"), item->text()); | ||||
137 | } | 138 | } | ||
138 | ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); | 139 | ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); | ||
139 | ServiceChooser->sortItems(); | 140 | ServiceChooser->sortItems(); | ||
140 | connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); | 141 | connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); | ||
141 | ServiceChooser->setCurrentRow(0); | 142 | ServiceChooser->setCurrentRow(0); | ||
142 | slotServiceSelected(ServiceChooser->item(0)); | | |||
143 | | ||||
144 | } | 143 | } | ||
145 | 144 | | |||
146 | void ComponentChooser::slotServiceSelected(QListWidgetItem* it) { | 145 | void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) | ||
147 | if (!it) return; | | |||
148 | | ||||
149 | if (somethingChanged) { | | |||
150 | if (KMessageBox::questionYesNo(this,i18n("<qt>You changed the default component of your choice, do want to save that change now ?</qt>"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save(); | | |||
151 | } | | |||
152 | KConfig cfg(it->data(Qt::UserRole).toString(), KConfig::SimpleConfig); | | |||
153 | | ||||
154 | ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); | | |||
155 | ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); | | |||
156 | | ||||
157 | | ||||
158 | QString cfgType=cfg.group(QByteArray()).readEntry("configurationType"); | | |||
159 | QWidget *newConfigWidget = nullptr; | | |||
160 | if (cfgType.isEmpty() || (cfgType==QLatin1String("component"))) | | |||
161 | { | | |||
162 | if (!(configWidget && qobject_cast<CfgComponent*>(configWidget))) | | |||
163 | { | 146 | { | ||
164 | CfgComponent* cfgcomp = new CfgComponent(configContainer); | 147 | QWidget *loadedConfigWidget = nullptr; | ||
165 | cfgcomp->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text())); | 148 | if (cfgType.isEmpty() || (cfgType == QLatin1String("component"))) | ||
166 | newConfigWidget = cfgcomp; | | |||
167 | } | | |||
168 | else | | |||
169 | { | 149 | { | ||
170 | static_cast<CfgComponent*>(configWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text())); | 150 | loadedConfigWidget = new CfgComponent(configContainer); | ||
171 | } | 151 | static_cast<CfgComponent*>(loadedConfigWidget)->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", name)); | ||
172 | } | 152 | } | ||
173 | else if (cfgType==QLatin1String("internal_email")) | 153 | else if (cfgType==QLatin1String("internal_email")) | ||
174 | { | 154 | { | ||
175 | if (!(configWidget && qobject_cast<CfgEmailClient*>(configWidget))) | 155 | loadedConfigWidget = new CfgEmailClient(configContainer); | ||
176 | { | | |||
177 | newConfigWidget = new CfgEmailClient(configContainer); | | |||
178 | } | | |||
179 | | ||||
180 | } | 156 | } | ||
181 | #ifdef Q_OS_UNIX | 157 | #ifdef Q_OS_UNIX | ||
182 | else if (cfgType==QLatin1String("internal_terminal")) | 158 | else if (cfgType==QLatin1String("internal_terminal")) | ||
183 | { | 159 | { | ||
184 | if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget))) | 160 | loadedConfigWidget = new CfgTerminalEmulator(configContainer); | ||
185 | { | | |||
186 | newConfigWidget = new CfgTerminalEmulator(configContainer); | | |||
187 | } | | |||
188 | | ||||
189 | } | 161 | } | ||
190 | #endif | 162 | #endif | ||
191 | else if (cfgType==QLatin1String("internal_filemanager")) | 163 | else if (cfgType==QLatin1String("internal_filemanager")) | ||
192 | { | 164 | { | ||
193 | if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget))) | 165 | loadedConfigWidget = new CfgFileManager(configContainer); | ||
194 | { | | |||
195 | newConfigWidget = new CfgFileManager(configContainer); | | |||
196 | } | | |||
197 | | ||||
198 | } | 166 | } | ||
199 | else if (cfgType==QLatin1String("internal_browser")) | 167 | else if (cfgType==QLatin1String("internal_browser")) | ||
200 | { | 168 | { | ||
201 | if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget))) | 169 | loadedConfigWidget = new CfgBrowser(configContainer); | ||
202 | { | | |||
203 | newConfigWidget = new CfgBrowser(configContainer); | | |||
204 | } | 170 | } | ||
205 | 171 | | |||
172 | if (loadedConfigWidget) { | ||||
173 | configWidgetMap.insert(service, loadedConfigWidget); | ||||
174 | configContainer->addWidget(loadedConfigWidget); | ||||
175 | connect(loadedConfigWidget, SIGNAL(changed(bool)), this, SLOT(emitChanged(bool))); | ||||
176 | } | ||||
206 | } | 177 | } | ||
207 | 178 | | |||
208 | if (newConfigWidget) | 179 | void ComponentChooser::slotServiceSelected(QListWidgetItem* it) { | ||
209 | { | 180 | if (!it) return; | ||
210 | configContainer->addWidget(newConfigWidget); | 181 | | ||
211 | configContainer->setCurrentWidget (newConfigWidget); | 182 | if (somethingChanged) { | ||
212 | configContainer->removeWidget(configWidget); | 183 | if (KMessageBox::questionYesNo(this,i18n("<qt>You changed the default component of your choice, do want to save that change now ?</qt>"),QString(),KStandardGuiItem::save(),KStandardGuiItem::discard())==KMessageBox::Yes) save(); | ||
213 | delete configWidget; | | |||
214 | configWidget=newConfigWidget; | | |||
215 | connect(configWidget,SIGNAL(changed(bool)),this,SLOT(emitChanged(bool))); | | |||
216 | configContainer->setMinimumSize(configWidget->sizeHint()); | | |||
217 | } | 184 | } | ||
185 | const QString &service = it->data(Qt::UserRole).toString(); | ||||
186 | KConfig cfg(service, KConfig::SimpleConfig); | ||||
218 | 187 | | |||
219 | if (configWidget) | 188 | ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); | ||
189 | ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); | ||||
190 | | ||||
191 | configWidget = configWidgetMap.value(service); | ||||
192 | if (configWidget) { | ||||
193 | configContainer->setCurrentWidget(configWidget); | ||||
220 | dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg); | 194 | dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg); | ||
195 | } | ||||
221 | 196 | | |||
222 | emitChanged(false); | 197 | emitChanged(false); | ||
223 | latestEditedService=it->data(Qt::UserRole).toString(); | 198 | latestEditedService = service; | ||
224 | } | 199 | } | ||
225 | 200 | | |||
226 | 201 | | |||
227 | void ComponentChooser::emitChanged(bool val) { | 202 | void ComponentChooser::emitChanged(bool val) { | ||
228 | somethingChanged=val; | 203 | somethingChanged=val; | ||
229 | emit changed(val); | 204 | emit changed(val); | ||
230 | } | 205 | } | ||
231 | 206 | | |||
232 | 207 | | |||
233 | ComponentChooser::~ComponentChooser() | 208 | ComponentChooser::~ComponentChooser() | ||
234 | { | 209 | { | ||
210 | for (QWidget *configWidget : configWidgetMap) { | ||||
ngraham: No `foreach` in new code. See https://www.kdab.com/goodbye-q_foreach/
Also, follow KDE coding… | |||||
235 | delete configWidget; | 211 | delete configWidget; | ||
236 | } | 212 | } | ||
213 | } | ||||
237 | 214 | | |||
238 | void ComponentChooser::load() { | 215 | void ComponentChooser::load() { | ||
239 | if( configWidget ) | 216 | if( configWidget ) | ||
240 | { | 217 | { | ||
241 | CfgPlugin * plugin = dynamic_cast<CfgPlugin*>( configWidget ); | 218 | CfgPlugin * plugin = dynamic_cast<CfgPlugin*>( configWidget ); | ||
242 | if( plugin ) | 219 | if( plugin ) | ||
243 | { | 220 | { | ||
244 | KConfig cfg(latestEditedService, KConfig::SimpleConfig); | 221 | KConfig cfg(latestEditedService, KConfig::SimpleConfig); | ||
Show All 36 Lines |
No foreach in new code. See https://www.kdab.com/goodbye-q_foreach/
Also, follow KDE coding style and always use braces for loops and conditionals.