Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooser.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | componentchooser.cpp - description | 2 | componentchooser.cpp - description | ||
3 | ------------------- | 3 | ------------------- | ||
4 | copyright : (C) 2002 by Joseph Wenninger | 4 | copyright : (C) 2002 by Joseph Wenninger | ||
5 | email : jowenn@kde.org | 5 | email : jowenn@kde.org | ||
6 | ***************************************************************************/ | 6 | ***************************************************************************/ | ||
7 | 7 | | |||
8 | /*************************************************************************** | 8 | /*************************************************************************** | ||
9 | * * | 9 | * * | ||
10 | * This program is free software; you can redistribute it and/or modify * | 10 | * This program is free software; you can redistribute it and/or modify * | ||
11 | * it under the terms of the GNU General Public License verstion 2 as * | 11 | * it under the terms of the GNU General Public License version 2 as * | ||
12 | * published by the Free Software Foundation * | 12 | * published by the Free Software Foundation * | ||
13 | * * | 13 | * * | ||
14 | ***************************************************************************/ | 14 | ***************************************************************************/ | ||
15 | 15 | | |||
16 | #include "componentchooser.h" | 16 | #include "componentchooser.h" | ||
17 | 17 | | |||
18 | #include "componentchooserbrowser.h" | 18 | #include "componentchooserbrowser.h" | ||
19 | #include "componentchooseremail.h" | 19 | #include "componentchooseremail.h" | ||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 72 | void CfgComponent::load(KConfig *cfg) { | |||
75 | m_lookupDict.clear(); | 75 | m_lookupDict.clear(); | ||
76 | m_revLookupDict.clear(); | 76 | m_revLookupDict.clear(); | ||
77 | 77 | | |||
78 | const KConfigGroup mainGroup = cfg->group(QByteArray()); | 78 | const KConfigGroup mainGroup = cfg->group(QByteArray()); | ||
79 | const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure"); | 79 | const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure"); | ||
80 | 80 | | |||
81 | const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure); | 81 | const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure); | ||
82 | 82 | | |||
83 | for (KService::List::const_iterator tit = offers.begin(); tit != offers.end(); ++tit) { | 83 | for (const auto &service: offers) { | ||
84 | ComponentSelector->addItem((*tit)->name()); | 84 | ComponentSelector->addItem(service->name()); | ||
85 | m_lookupDict.insert((*tit)->name(), (*tit)->desktopEntryName()); | 85 | m_lookupDict.insert(service->name(), service->desktopEntryName()); | ||
86 | m_revLookupDict.insert((*tit)->desktopEntryName(), (*tit)->name()); | 86 | m_revLookupDict.insert(service->desktopEntryName(), service->name()); | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | KConfig store(mainGroup.readPathEntry("storeInFile",QStringLiteral("null"))); | 89 | KConfig store(mainGroup.readPathEntry("storeInFile",QStringLiteral("null"))); | ||
90 | const KConfigGroup group(&store, mainGroup.readEntry("valueSection")); | 90 | const KConfigGroup group(&store, mainGroup.readEntry("valueSection")); | ||
91 | QString setting = group.readEntry(mainGroup.readEntry("valueName","kcm_componenchooser_null"), QString()); | 91 | QString setting = group.readEntry(mainGroup.readEntry("valueName","kcm_componenchooser_null"), QString()); | ||
92 | 92 | | |||
93 | if (setting.isEmpty()) | 93 | if (setting.isEmpty()) | ||
94 | setting = mainGroup.readEntry("defaultImplementation", QString()); | 94 | setting = mainGroup.readEntry("defaultImplementation", QString()); | ||
Show All 9 Lines | |||||
104 | emit changed(false); | 104 | emit changed(false); | ||
105 | } | 105 | } | ||
106 | 106 | | |||
107 | void CfgComponent::defaults() | 107 | void CfgComponent::defaults() | ||
108 | { | 108 | { | ||
109 | //todo | 109 | //todo | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | bool CfgComponent::isDefaults() const | ||||
113 | { | ||||
114 | return false; | ||||
115 | } | ||||
116 | | ||||
112 | //END General kpart based Component selection | 117 | //END General kpart based Component selection | ||
113 | 118 | | |||
114 | 119 | | |||
115 | 120 | | |||
116 | 121 | | |||
117 | 122 | | |||
118 | 123 | | |||
119 | ComponentChooser::ComponentChooser(QWidget *parent): | 124 | ComponentChooser::ComponentChooser(QWidget *parent): | ||
120 | QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(nullptr) | 125 | QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(nullptr) | ||
121 | { | 126 | { | ||
122 | setupUi(this); | 127 | setupUi(this); | ||
123 | static_cast<QGridLayout*>(layout())->setRowStretch(1, 1); | 128 | static_cast<QGridLayout*>(layout())->setRowStretch(1, 1); | ||
124 | 129 | | |||
125 | const QStringList services=KGlobal::dirs()->findAllResources( "data",QStringLiteral("kcm_componentchooser/*.desktop"), | 130 | const QStringList directories = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kcm_componentchooser"), QStandardPaths::LocateDirectory); | ||
126 | KStandardDirs::NoDuplicates); | 131 | QStringList services; | ||
127 | for (QStringList::const_iterator it=services.constBegin(); it!=services.constEnd(); ++it) | 132 | for(const QString &directory : directories) { | ||
133 | const QDir dir(directory); | ||||
134 | for(const QString &f: dir.entryList(QStringList("*.desktop"))) { | ||||
135 | services += dir.absoluteFilePath(f); | ||||
136 | } | ||||
137 | } | ||||
138 | | ||||
139 | for (const QString &service : qAsConst(services)) | ||||
128 | { | 140 | { | ||
129 | KConfig cfg(*it, KConfig::SimpleConfig); | 141 | KConfig cfg(service, KConfig::SimpleConfig); | ||
130 | KConfigGroup cg = cfg.group(QByteArray()); | 142 | KConfigGroup cg = cfg.group(QByteArray()); | ||
131 | QListWidgetItem *item = new QListWidgetItem( | 143 | QListWidgetItem *item = new QListWidgetItem( | ||
132 | QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), | 144 | QIcon::fromTheme(cg.readEntry("Icon",QStringLiteral("preferences-desktop-default-applications"))), | ||
133 | cg.readEntry("Name",i18n("Unknown"))); | 145 | cg.readEntry("Name",i18n("Unknown"))); | ||
134 | item->setData(Qt::UserRole, (*it)); | 146 | item->setData(Qt::UserRole, service); | ||
135 | ServiceChooser->addItem(item); | 147 | ServiceChooser->addItem(item); | ||
136 | loadConfigWidget((*it), cfg.group(QByteArray()).readEntry("configurationType"), item->text()); | 148 | loadConfigWidget(service, cfg.group(QByteArray()).readEntry("configurationType"), item->text()); | ||
137 | } | 149 | } | ||
138 | ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); | 150 | ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20); | ||
139 | ServiceChooser->sortItems(); | 151 | ServiceChooser->sortItems(); | ||
140 | connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); | 152 | connect(ServiceChooser,&QListWidget::currentItemChanged,this,&ComponentChooser::slotServiceSelected); | ||
141 | ServiceChooser->setCurrentRow(0); | 153 | ServiceChooser->setCurrentRow(0); | ||
142 | } | 154 | } | ||
143 | 155 | | |||
144 | void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) | 156 | void ComponentChooser::loadConfigWidget(const QString &service, const QString &cfgType, const QString &name) | ||
Show All 40 Lines | 190 | void ComponentChooser::slotServiceSelected(QListWidgetItem* it) { | |||
185 | KConfig cfg(service, KConfig::SimpleConfig); | 197 | KConfig cfg(service, KConfig::SimpleConfig); | ||
186 | 198 | | |||
187 | ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); | 199 | ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available"))); | ||
188 | ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); | 200 | ComponentDescription->setMinimumSize(ComponentDescription->sizeHint()); | ||
189 | 201 | | |||
190 | configWidget = configWidgetMap.value(service); | 202 | configWidget = configWidgetMap.value(service); | ||
191 | if (configWidget) { | 203 | if (configWidget) { | ||
192 | configContainer->setCurrentWidget(configWidget); | 204 | configContainer->setCurrentWidget(configWidget); | ||
193 | dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg); | 205 | const auto plugin = dynamic_cast<CfgPlugin*>(configWidget); | ||
206 | plugin->load(&cfg); | ||||
207 | emit defaulted(plugin->isDefaults()); | ||||
194 | } | 208 | } | ||
195 | 209 | | |||
196 | emitChanged(false); | 210 | emitChanged(false); | ||
197 | latestEditedService = service; | 211 | latestEditedService = service; | ||
198 | } | 212 | } | ||
199 | 213 | | |||
200 | 214 | | |||
201 | void ComponentChooser::emitChanged(bool val) { | 215 | void ComponentChooser::emitChanged(bool val) { | ||
202 | somethingChanged=val; | 216 | somethingChanged=val; | ||
203 | emit changed(val); | 217 | emit changed(val); | ||
218 | | ||||
219 | CfgPlugin *plugin = dynamic_cast<CfgPlugin *>( configWidget ); | ||||
220 | emit defaulted(plugin->isDefaults()); | ||||
204 | } | 221 | } | ||
205 | 222 | | |||
206 | 223 | | |||
207 | ComponentChooser::~ComponentChooser() | 224 | ComponentChooser::~ComponentChooser() | ||
208 | { | 225 | { | ||
209 | for (QWidget *configWidget : configWidgetMap) { | 226 | for (QWidget *configWidget : configWidgetMap) { | ||
210 | delete configWidget; | 227 | delete configWidget; | ||
211 | } | 228 | } | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |