kcontrol: format and indent componentchooser KCM source and header files

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-10 14:26:38 +02:00
parent f1de78f207
commit 2ccfe10531
12 changed files with 404 additions and 426 deletions

View file

@ -51,57 +51,57 @@ CfgComponent::~CfgComponent()
}
void CfgComponent::slotComponentChanged(const QString&) {
emit changed(true);
emit changed(true);
}
void CfgComponent::save(KConfig *cfg) {
// yes, this can happen if there are NO KTrader offers for this component
if (!m_lookupDict.contains(ComponentSelector->currentText()))
return;
// yes, this can happen if there are NO KTrader offers for this component
if (!m_lookupDict.contains(ComponentSelector->currentText()))
return;
KConfigGroup mainGroup = cfg->group(QByteArray());
QString serviceTypeToConfigure=mainGroup.readEntry("ServiceTypeToConfigure");
KConfig store(mainGroup.readPathEntry("storeInFile", "null"));
KConfigGroup cg(&store, mainGroup.readEntry("valueSection"));
cg.writePathEntry(mainGroup.readEntry("valueName", "kcm_componenchooser_null"),
m_lookupDict.value(ComponentSelector->currentText()));
store.sync();
emit changed(false);
KConfigGroup mainGroup = cfg->group(QByteArray());
QString serviceTypeToConfigure=mainGroup.readEntry("ServiceTypeToConfigure");
KConfig store(mainGroup.readPathEntry("storeInFile", "null"));
KConfigGroup cg(&store, mainGroup.readEntry("valueSection"));
cg.writePathEntry(mainGroup.readEntry("valueName", "kcm_componenchooser_null"),
m_lookupDict.value(ComponentSelector->currentText()));
store.sync();
emit changed(false);
}
void CfgComponent::load(KConfig *cfg) {
ComponentSelector->clear();
m_lookupDict.clear();
m_revLookupDict.clear();
ComponentSelector->clear();
m_lookupDict.clear();
m_revLookupDict.clear();
const KConfigGroup mainGroup = cfg->group(QByteArray());
const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure");
const KConfigGroup mainGroup = cfg->group(QByteArray());
const QString serviceTypeToConfigure = mainGroup.readEntry("ServiceTypeToConfigure");
const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure);
const KService::List offers = KServiceTypeTrader::self()->query(serviceTypeToConfigure);
for (KService::List::const_iterator tit = offers.begin(); tit != offers.end(); ++tit) {
ComponentSelector->addItem((*tit)->name());
m_lookupDict.insert((*tit)->name(), (*tit)->desktopEntryName());
m_revLookupDict.insert((*tit)->desktopEntryName(), (*tit)->name());
}
for (KService::List::const_iterator tit = offers.begin(); tit != offers.end(); ++tit) {
ComponentSelector->addItem((*tit)->name());
m_lookupDict.insert((*tit)->name(), (*tit)->desktopEntryName());
m_revLookupDict.insert((*tit)->desktopEntryName(), (*tit)->name());
}
KConfig store(mainGroup.readPathEntry("storeInFile","null"));
const KConfigGroup group(&store, mainGroup.readEntry("valueSection"));
QString setting = group.readEntry(mainGroup.readEntry("valueName","kcm_componenchooser_null"), QString());
KConfig store(mainGroup.readPathEntry("storeInFile","null"));
const KConfigGroup group(&store, mainGroup.readEntry("valueSection"));
QString setting = group.readEntry(mainGroup.readEntry("valueName", "kcm_componenchooser_null"), QString());
if (setting.isEmpty())
setting = mainGroup.readEntry("defaultImplementation", QString());
QString tmp = m_revLookupDict.value(setting);
if (!tmp.isEmpty()) {
for (int i=0;i<ComponentSelector->count();i++)
if (tmp==ComponentSelector->itemText(i))
{
ComponentSelector->setCurrentIndex(i);
break;
}
if (setting.isEmpty())
setting = mainGroup.readEntry("defaultImplementation", QString());
QString tmp = m_revLookupDict.value(setting);
if (!tmp.isEmpty()) {
for (int i = 0;i < ComponentSelector->count(); i++) {
if (tmp == ComponentSelector->itemText(i)) {
ComponentSelector->setCurrentIndex(i);
break;
}
}
emit changed(false);
}
emit changed(false);
}
void CfgComponent::defaults()
@ -112,177 +112,160 @@ void CfgComponent::defaults()
//END General kpart based Component selection
ComponentChooser::ComponentChooser(QWidget *parent):
QWidget(parent), Ui::ComponentChooser_UI(), somethingChanged(false), configWidget(0)
{
setupUi(this);
static_cast<QGridLayout*>(layout())->setRowStretch(1, 1);
setupUi(this);
static_cast<QGridLayout*>(layout())->setRowStretch(1, 1);
const QStringList services=KGlobal::dirs()->findAllResources( "data","kcm_componentchooser/*.desktop",
KStandardDirs::NoDuplicates);
for (QStringList::const_iterator it=services.constBegin(); it!=services.constEnd(); ++it)
{
KConfig cfg(*it, KConfig::SimpleConfig);
KConfigGroup cg = cfg.group(QByteArray());
QListWidgetItem *item = new QListWidgetItem(
KIcon(cg.readEntry("Icon",QString("preferences-desktop-default-applications"))),
cg.readEntry("Name",i18n("Unknown")));
item->setData(Qt::UserRole, (*it));
ServiceChooser->addItem(item);
}
ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20);
ServiceChooser->sortItems();
connect(ServiceChooser,SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),this,SLOT(slotServiceSelected(QListWidgetItem*)));
ServiceChooser->setCurrentRow(0);
slotServiceSelected(ServiceChooser->item(0));
const QStringList services = KGlobal::dirs()->findAllResources(
"data","kcm_componentchooser/*.desktop",
KStandardDirs::NoDuplicates
);
for (QStringList::const_iterator it = services.constBegin(); it!=services.constEnd(); ++it) {
KConfig cfg(*it, KConfig::SimpleConfig);
KConfigGroup cg = cfg.group(QByteArray());
QListWidgetItem *item = new QListWidgetItem(
KIcon(cg.readEntry("Icon",QString("preferences-desktop-default-applications"))),
cg.readEntry("Name",i18n("Unknown"))
);
item->setData(Qt::UserRole, (*it));
ServiceChooser->addItem(item);
}
ServiceChooser->setFixedWidth(ServiceChooser->sizeHintForColumn(0) + 20);
ServiceChooser->sortItems();
connect(
ServiceChooser, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
this, SLOT(slotServiceSelected(QListWidgetItem*))
);
ServiceChooser->setCurrentRow(0);
slotServiceSelected(ServiceChooser->item(0));
}
void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
if (!it) return;
void ComponentChooser::slotServiceSelected(QListWidgetItem* it)
{
if (!it)
return;
if (somethingChanged) {
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();
}
KConfig cfg(it->data(Qt::UserRole).toString(), KConfig::SimpleConfig);
if (somethingChanged) {
const int yesorno = 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()
);
if (yesorno == KMessageBox::Yes) {
save();
}
}
KConfig cfg(it->data(Qt::UserRole).toString(), KConfig::SimpleConfig);
ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment",i18n("No description available")));
ComponentDescription->setMinimumSize(ComponentDescription->sizeHint());
ComponentDescription->setText(cfg.group(QByteArray()).readEntry("Comment", i18n("No description available")));
ComponentDescription->setMinimumSize(ComponentDescription->sizeHint());
QString cfgType=cfg.group(QByteArray()).readEntry("configurationType");
QWidget *newConfigWidget = 0;
if (cfgType.isEmpty() || (cfgType=="component"))
{
if (!(configWidget && qobject_cast<CfgComponent*>(configWidget)))
{
CfgComponent* cfgcomp = new CfgComponent(configContainer);
cfgcomp->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text()));
newConfigWidget = cfgcomp;
}
else
{
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()));
}
}
else if (cfgType=="internal_email")
{
if (!(configWidget && qobject_cast<CfgEmailClient*>(configWidget)))
{
newConfigWidget = new CfgEmailClient(configContainer);
}
QString cfgType=cfg.group(QByteArray()).readEntry("configurationType");
QWidget *newConfigWidget = 0;
if (cfgType.isEmpty() || (cfgType=="component")) {
if (!(configWidget && qobject_cast<CfgComponent*>(configWidget))) {
CfgComponent* cfgcomp = new CfgComponent(configContainer);
cfgcomp->ChooserDocu->setText(i18n("Choose from the list below which component should be used by default for the %1 service.", it->text()));
newConfigWidget = cfgcomp;
} else {
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()));
}
} else if (cfgType=="internal_email") {
if (!(configWidget && qobject_cast<CfgEmailClient*>(configWidget))) {
newConfigWidget = new CfgEmailClient(configContainer);
}
} else if (cfgType=="internal_terminal") {
if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget))) {
newConfigWidget = new CfgTerminalEmulator(configContainer);
}
} else if (cfgType=="internal_wm") {
if (!(configWidget && qobject_cast<CfgWm*>(configWidget))) {
newConfigWidget = new CfgWm(configContainer);
}
} else if (cfgType=="internal_filemanager") {
if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget))) {
newConfigWidget = new CfgFileManager(configContainer);
}
}
#ifdef Q_OS_UNIX
else if (cfgType=="internal_terminal")
{
if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget)))
{
newConfigWidget = new CfgTerminalEmulator(configContainer);
}
} else if (cfgType=="internal_browser") {
if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget))) {
newConfigWidget = new CfgBrowser(configContainer);
}
}
}
#ifdef Q_WS_X11
else if (cfgType=="internal_wm")
{
if (!(configWidget && qobject_cast<CfgWm*>(configWidget)))
{
newConfigWidget = new CfgWm(configContainer);
}
if (newConfigWidget) {
configContainer->addWidget(newConfigWidget);
configContainer->setCurrentWidget (newConfigWidget);
configContainer->removeWidget(configWidget);
delete configWidget;
configWidget=newConfigWidget;
connect(configWidget,SIGNAL(changed(bool)),this,SLOT(emitChanged(bool)));
configContainer->setMinimumSize(configWidget->sizeHint());
}
}
#endif
#endif
else if (cfgType=="internal_filemanager")
{
if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget)))
{
newConfigWidget = new CfgFileManager(configContainer);
}
if (configWidget) {
dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg);
}
}
else if (cfgType=="internal_browser")
{
if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget)))
{
newConfigWidget = new CfgBrowser(configContainer);
}
}
if (newConfigWidget)
{
configContainer->addWidget(newConfigWidget);
configContainer->setCurrentWidget (newConfigWidget);
configContainer->removeWidget(configWidget);
delete configWidget;
configWidget=newConfigWidget;
connect(configWidget,SIGNAL(changed(bool)),this,SLOT(emitChanged(bool)));
configContainer->setMinimumSize(configWidget->sizeHint());
}
if (configWidget)
dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg);
emitChanged(false);
latestEditedService=it->data(Qt::UserRole).toString();
emitChanged(false);
latestEditedService=it->data(Qt::UserRole).toString();
}
void ComponentChooser::emitChanged(bool val) {
somethingChanged=val;
emit changed(val);
void ComponentChooser::emitChanged(bool val)
{
somethingChanged=val;
emit changed(val);
}
ComponentChooser::~ComponentChooser()
{
delete configWidget;
delete configWidget;
}
void ComponentChooser::load() {
if( configWidget )
{
CfgPlugin * plugin = dynamic_cast<CfgPlugin*>( configWidget );
if( plugin )
{
KConfig cfg(latestEditedService, KConfig::SimpleConfig);
plugin->load( &cfg );
}
}
void ComponentChooser::load()
{
if( configWidget ) {
CfgPlugin * plugin = dynamic_cast<CfgPlugin*>(configWidget);
if (plugin) {
KConfig cfg(latestEditedService, KConfig::SimpleConfig);
plugin->load(&cfg);
}
}
}
void ComponentChooser::save() {
if( configWidget )
{
CfgPlugin* plugin = dynamic_cast<CfgPlugin*>( configWidget );
if( plugin )
{
KConfig cfg(latestEditedService, KConfig::SimpleConfig);
plugin->save( &cfg );
}
}
void ComponentChooser::save()
{
if(configWidget) {
CfgPlugin* plugin = dynamic_cast<CfgPlugin*>(configWidget);
if (plugin) {
KConfig cfg(latestEditedService, KConfig::SimpleConfig);
plugin->save(&cfg);
}
}
}
void ComponentChooser::restoreDefault() {
if (configWidget)
{
void ComponentChooser::restoreDefault()
{
if (configWidget) {
dynamic_cast<CfgPlugin*>(configWidget)->defaults();
emitChanged(true);
}
/*
txtEMailClient->setText("kmail");
chkRunTerminal->setChecked(false);
txtEMailClient->setText("kmail");
chkRunTerminal->setChecked(false);
// Check if -e is needed, I do not think so
terminalLE->setText("xterm"); //No need for i18n
terminalCB->setChecked(true);
emitChanged(false);
// Check if -e is needed, I do not think so
terminalLE->setText("xterm"); //No need for i18n
terminalCB->setChecked(true);
emitChanged(false);
*/
}

View file

@ -18,72 +18,68 @@
#include "ui_componentchooser_ui.h"
#include "ui_componentconfig_ui.h"
#include <QHash>
//Added by qt3to4:
#include <QHash>
#include <QVBoxLayout>
#include <QListWidgetItem>
#include <kservice.h>
#include <QListWidgetItem>
class KConfig;
/* The CfgPlugin class is an exception. It is LGPL. It will be parted of the plugin interface
which I plan for KDE 3.2.
/*
The CfgPlugin class is an exception. It is LGPL. It will be parted of the plugin interface
which I plan for KDE 3.2.
*/
class CfgPlugin
{
public:
CfgPlugin(){}
virtual ~CfgPlugin(){}
virtual void load(KConfig *cfg)=0;
virtual void save(KConfig *cfg)=0;
virtual void defaults()=0;
CfgPlugin(){}
virtual ~CfgPlugin(){}
virtual void load(KConfig *cfg)=0;
virtual void save(KConfig *cfg)=0;
virtual void defaults()=0;
};
class CfgComponent: public QWidget, public Ui::ComponentConfig_UI, public CfgPlugin
{
Q_OBJECT
Q_OBJECT
public:
CfgComponent(QWidget *parent);
virtual ~CfgComponent();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
CfgComponent(QWidget *parent);
virtual ~CfgComponent();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
protected:
QHash<QString, QString> m_lookupDict,m_revLookupDict;
QHash<QString, QString> m_lookupDict,m_revLookupDict;
protected Q_SLOTS:
void slotComponentChanged(const QString&);
void slotComponentChanged(const QString&);
Q_SIGNALS:
void changed(bool);
void changed(bool);
};
class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI
{
Q_OBJECT
Q_OBJECT
public:
ComponentChooser(QWidget *parent=0);
virtual ~ComponentChooser();
void load();
void save();
void restoreDefault();
ComponentChooser(QWidget *parent=0);
virtual ~ComponentChooser();
void load();
void save();
void restoreDefault();
private:
QString latestEditedService;
bool somethingChanged;
QWidget *configWidget;
QString latestEditedService;
bool somethingChanged;
QWidget *configWidget;
protected Q_SLOTS:
void emitChanged(bool);
void slotServiceSelected(QListWidgetItem *);
void emitChanged(bool);
void slotServiceSelected(QListWidgetItem *);
Q_SIGNALS:
void changed(bool);
void changed(bool);
};
#endif

View file

@ -21,7 +21,7 @@
#include <KUrl>
CfgBrowser::CfgBrowser(QWidget *parent)
: QWidget(parent), Ui::BrowserConfig_UI(),CfgPlugin()
: QWidget(parent), Ui::BrowserConfig_UI(), CfgPlugin()
{
setupUi(this);
connect(lineExec,SIGNAL(textChanged(const QString &)),this,SLOT(configChanged()));
@ -30,7 +30,8 @@ CfgBrowser::CfgBrowser(QWidget *parent)
connect(btnSelectBrowser,SIGNAL(clicked()),this, SLOT(selectBrowser()));
}
CfgBrowser::~CfgBrowser() {
CfgBrowser::~CfgBrowser()
{
}
void CfgBrowser::configChanged()
@ -43,32 +44,26 @@ void CfgBrowser::defaults()
load(0);
}
void CfgBrowser::load(KConfig *)
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), QLatin1String("General") );
QString exec = config.readPathEntry( QLatin1String("BrowserApplication"), QString("") );
if (exec.isEmpty())
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), QLatin1String("General"));
QString exec = config.readPathEntry(QLatin1String("BrowserApplication"), QString(""));
if (exec.isEmpty()) {
radioKIO->setChecked(true);
m_browserExec = exec;
m_browserService = 0;
}
else
{
} else {
radioExec->setChecked(true);
if (exec.startsWith('!'))
{
if (exec.startsWith('!')) {
m_browserExec = exec.mid(1);
m_browserService = 0;
}
else
{
} else {
m_browserService = KService::serviceByStorageId( exec );
if (m_browserService)
if (m_browserService) {
m_browserExec = m_browserService->desktopEntryName();
else
} else {
m_browserExec.clear();
}
}
}
@ -81,15 +76,15 @@ void CfgBrowser::save(KConfig *)
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), QLatin1String("General") );
QString exec;
if (radioExec->isChecked())
{
if (radioExec->isChecked()) {
exec = lineExec->text();
if (m_browserService && (exec == m_browserExec))
if (m_browserService && (exec == m_browserExec)) {
exec = m_browserService->storageId(); // Use service
else if (!exec.isEmpty())
} else if (!exec.isEmpty()) {
exec = '!' + exec; // Literal command
}
}
config.writePathEntry( QLatin1String("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global
config.writePathEntry(QLatin1String("BrowserApplication"), exec); // KConfig::Normal|KConfig::Global
config.sync();
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged);
@ -101,13 +96,15 @@ void CfgBrowser::selectBrowser()
{
KUrl::List urlList;
KOpenWithDialog dlg(urlList, i18n("Select preferred Web browser application:"), QString(), this);
if (dlg.exec() != QDialog::Accepted)
if (dlg.exec() != QDialog::Accepted) {
return;
}
m_browserService = dlg.service();
if (m_browserService) {
m_browserExec = m_browserService->desktopEntryName();
if (m_browserExec.isEmpty())
if (m_browserExec.isEmpty()) {
m_browserExec = m_browserService->exec();
}
} else {
m_browserExec = dlg.text();
}

View file

@ -21,23 +21,23 @@
class CfgBrowser: public QWidget, public Ui::BrowserConfig_UI, public CfgPlugin
{
Q_OBJECT
Q_OBJECT
public:
CfgBrowser(QWidget *parent);
virtual ~CfgBrowser();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
CfgBrowser(QWidget *parent);
virtual ~CfgBrowser();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
protected Q_SLOTS:
void selectBrowser();
void configChanged();
void selectBrowser();
void configChanged();
Q_SIGNALS:
void changed(bool);
void changed(bool);
private:
QString m_browserExec;
KService::Ptr m_browserService;
QString m_browserExec;
KService::Ptr m_browserService;
};
#endif /* COMPONENTCHOOSERBROWSER_H */

View file

@ -65,7 +65,6 @@ void CfgEmailClient::load(KConfig *)
chkRunTerminal->setChecked((pSettings->getSetting(KEMailSettings::ClientTerminal) == "true"));
emit changed(false);
}
void CfgEmailClient::configChanged()
@ -79,7 +78,9 @@ void CfgEmailClient::selectEmailClient()
KOpenWithDialog dlg(urlList, i18n("Select preferred email client:"), QString(), this);
// hide "Do not &close when command exits" here, we don't need it for a mail client
dlg.hideNoCloseOnExit();
if (dlg.exec() != QDialog::Accepted) return;
if (dlg.exec() != QDialog::Accepted) {
return;
}
QString client = dlg.text();
// get the preferred Terminal Application
@ -89,34 +90,31 @@ void CfgEmailClient::selectEmailClient()
int len = preferredTerminal.length();
bool b = client.left(len) == preferredTerminal;
if (b) client = client.mid(len);
if (!client.isEmpty())
{
if (b) {
client = client.mid(len);
}
if (!client.isEmpty()) {
chkRunTerminal->setChecked(b);
txtEMailClient->setText(client);
}
}
void CfgEmailClient::save(KConfig *)
{
if (kmailCB->isChecked())
{
if (kmailCB->isChecked()) {
pSettings->setSetting(KEMailSettings::ClientProgram, QString());
pSettings->setSetting(KEMailSettings::ClientTerminal, "false");
}
else
{
} else {
pSettings->setSetting(KEMailSettings::ClientProgram, txtEMailClient->text());
pSettings->setSetting(KEMailSettings::ClientTerminal, (chkRunTerminal->isChecked()) ? "true" : "false");
}
// insure proper permissions -- contains sensitive data
QString cfgName(KGlobal::dirs()->findResource("config", "emails"));
if (!cfgName.isEmpty())
if (!cfgName.isEmpty()) {
::chmod(QFile::encodeName(cfgName), 0600);
QDBusMessage message = QDBusMessage::createSignal("/Component", "org.kde.Kcontrol", "KDE_emailSettingsChanged" );
}
QDBusMessage message = QDBusMessage::createSignal("/Component", "org.kde.Kcontrol", "KDE_emailSettingsChanged");
QDBusConnection::sessionBus().send(message);
emit changed(false);
}

View file

@ -28,10 +28,10 @@
#include <kconfiggroup.h>
CfgFileManager::CfgFileManager(QWidget *parent)
: QWidget(parent), Ui::FileManagerConfig_UI(),CfgPlugin()
: QWidget(parent), Ui::FileManagerConfig_UI(), CfgPlugin()
{
setupUi(this);
connect(btnSelectFileManager,SIGNAL(clicked()),this, SLOT(slotAddFileManager()));
connect(btnSelectFileManager, SIGNAL(clicked()), this, SLOT(slotAddFileManager()));
}
CfgFileManager::~CfgFileManager() {
@ -52,13 +52,13 @@ static KService::List appOffers()
return KMimeTypeTrader::self()->query("inode/directory", "Application");
}
void CfgFileManager::load(KConfig *) {
void CfgFileManager::load(KConfig *)
{
qDeleteAll(mDynamicWidgets);
mDynamicWidgets.clear();
const KService::List apps = appOffers();
bool first = true;
Q_FOREACH(const KService::Ptr& service, apps)
{
Q_FOREACH(const KService::Ptr& service, apps) {
QRadioButton* button = new QRadioButton(service->name(), this);
connect(button,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
button->setProperty("storageId", service->storageId());
@ -86,8 +86,10 @@ void CfgFileManager::save(KConfig *)
if (!storageId.isEmpty()) {
// This is taken from filetypes/mimetypedata.cpp
KSharedConfig::Ptr profile = KSharedConfig::openConfig("mimeapps.list", KConfig::NoGlobals, "xdgdata-apps");
if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504)
if (!profile->isConfigWritable(true)) {
// warn user if mimeapps.list is root-owned (#155126/#94504)
return;
}
KConfigGroup addedApps(profile, "Added Associations");
QStringList userApps = addedApps.readXdgListEntry("inode/directory");
userApps.removeAll(storageId); // remove if present, to make it first in the list

View file

@ -34,69 +34,68 @@
CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent)
: QWidget(parent), Ui::TerminalEmulatorConfig_UI(), CfgPlugin()
{
setupUi(this);
connect(terminalLE,SIGNAL(textChanged(QString)), this, SLOT(configChanged()));
connect(terminalCB,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
connect(otherCB,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
connect(btnSelectTerminal,SIGNAL(clicked()),this,SLOT(selectTerminalApp()));
setupUi(this);
connect(terminalLE, SIGNAL(textChanged(QString)), this, SLOT(configChanged()));
connect(terminalCB, SIGNAL(toggled(bool)), this, SLOT(configChanged()));
connect(otherCB, SIGNAL(toggled(bool)), this, SLOT(configChanged()));
connect(btnSelectTerminal, SIGNAL(clicked()), this, SLOT(selectTerminalApp()));
}
CfgTerminalEmulator::~CfgTerminalEmulator() {
CfgTerminalEmulator::~CfgTerminalEmulator()
{
}
void CfgTerminalEmulator::configChanged()
{
emit changed(true);
emit changed(true);
}
void CfgTerminalEmulator::defaults()
{
load(0);
load(0);
}
void CfgTerminalEmulator::load(KConfig *) {
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
QString terminal = config.readPathEntry("TerminalApplication","konsole");
if (terminal == "konsole")
{
terminalLE->setText("xterm");
terminalCB->setChecked(true);
}
else
{
terminalLE->setText(terminal);
otherCB->setChecked(true);
}
void CfgTerminalEmulator::load(KConfig *)
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
QString terminal = config.readPathEntry("TerminalApplication","konsole");
if (terminal == "konsole") {
terminalLE->setText("xterm");
terminalCB->setChecked(true);
} else {
terminalLE->setText(terminal);
otherCB->setChecked(true);
}
emit changed(false);
emit changed(false);
}
void CfgTerminalEmulator::save(KConfig *)
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
const QString terminal = terminalCB->isChecked() ? "konsole" : terminalLE->text();
config.writePathEntry("TerminalApplication", terminal); // KConfig::Normal|KConfig::Global);
config.sync();
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
const QString terminal = terminalCB->isChecked() ? "konsole" : terminalLE->text();
config.writePathEntry("TerminalApplication", terminal); // KConfig::Normal|KConfig::Global);
config.sync();
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged);
KGlobalSettings::self()->emitChange(KGlobalSettings::SettingsChanged);
emit changed(false);
emit changed(false);
}
void CfgTerminalEmulator::selectTerminalApp()
{
KUrl::List urlList;
KOpenWithDialog dlg(urlList, i18n("Select preferred terminal application:"), QString(), this);
// hide "Run in &terminal" here, we don't need it for a Terminal Application
dlg.hideRunInTerminal();
if (dlg.exec() != QDialog::Accepted) return;
QString client = dlg.text();
KUrl::List urlList;
KOpenWithDialog dlg(urlList, i18n("Select preferred terminal application:"), QString(), this);
// hide "Run in &terminal" here, we don't need it for a Terminal Application
dlg.hideRunInTerminal();
if (dlg.exec() != QDialog::Accepted) {
return;
}
QString client = dlg.text();
if (!client.isEmpty())
{
terminalLE->setText(client);
}
if (!client.isEmpty()) {
terminalLE->setText(client);
}
}
// vim: sw=4 ts=4 noet

View file

@ -18,6 +18,7 @@
#include "ui_terminalemulatorconfig_ui.h"
#include "componentchooser.h"
class KConfig;
class CfgPlugin;
@ -25,18 +26,18 @@ class CfgTerminalEmulator: public QWidget, public Ui::TerminalEmulatorConfig_UI,
{
Q_OBJECT
public:
CfgTerminalEmulator(QWidget *parent);
virtual ~CfgTerminalEmulator();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
CfgTerminalEmulator(QWidget *parent);
virtual ~CfgTerminalEmulator();
virtual void load(KConfig *cfg);
virtual void save(KConfig *cfg);
virtual void defaults();
protected Q_SLOTS:
void selectTerminalApp();
void configChanged();
void selectTerminalApp();
void configChanged();
Q_SIGNALS:
void changed(bool);
void changed(bool);
};
#endif

View file

@ -55,9 +55,9 @@ void killWM()
}
CfgWm::CfgWm(QWidget *parent)
: QWidget(parent)
, Ui::WmConfig_UI()
, CfgPlugin()
: QWidget(parent)
, Ui::WmConfig_UI()
, CfgPlugin()
{
setupUi(this);
connect(wmCombo,SIGNAL(activated(int)), this, SLOT(configChanged()));
@ -104,40 +104,35 @@ bool CfgWm::saveAndConfirm()
KConfigGroup c( &cfg, "General");
c.writeEntry("windowManager", currentWm());
emit changed(false);
if( oldwm == currentWm())
return true;
if( tryWmLaunch())
{
oldwm = currentWm();
cfg.sync();
QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer" );
ksmserver.call( QDBus::NoBlock, "wmChanged" );
KMessageBox::information( window(),
i18n( "A new window manager is running.\n"
"It is still recommended to restart this KDE session to make sure "
"all running applications adjust for this change." ),
i18n( "Window Manager Replaced" ), "restartafterwmchange" );
if (oldwm == currentWm()) {
return true;
}
else
{ // revert config
if (tryWmLaunch()) {
oldwm = currentWm();
cfg.sync();
QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer");
ksmserver.call(QDBus::NoBlock, "wmChanged");
KMessageBox::information( window(),
i18n("A new window manager is running.\n"
"It is still recommended to restart this KDE session to make sure "
"all running applications adjust for this change."),
i18n( "Window Manager Replaced"), "restartafterwmchange");
return true;
} else {
// revert config
emit changed(true);
c.writeEntry("windowManager", oldwm);
if( oldwm == "kwin" )
{
kwinRB->setChecked( true );
wmCombo->setEnabled( false );
}
else
{
differentRB->setChecked( true );
wmCombo->setEnabled( true );
for( QHash< QString, WmData >::ConstIterator it = wms.constBegin();
it != wms.constEnd();
++it )
{
if( (*it).internalName == oldwm ) // make it selected
if (oldwm == "kwin") {
kwinRB->setChecked(true);
wmCombo->setEnabled(false);
} else {
differentRB->setChecked(true);
wmCombo->setEnabled(true);
for (QHash< QString, WmData >::ConstIterator it = wms.constBegin(); it != wms.constEnd(); ++it) {
if ((*it).internalName == oldwm) {
// make it selected
wmCombo->setCurrentIndex( wmCombo->findText( it.key()));
}
}
}
return false;
@ -146,13 +141,17 @@ bool CfgWm::saveAndConfirm()
bool CfgWm::tryWmLaunch()
{
if( currentWm() == "kwin"
&& qstrcmp( NETRootInfo( QX11Info::display(), NET::SupportingWMCheck ).wmName(), "KWin" ) == 0 )
{
return true; // it is already running, don't necessarily restart e.g. after a failure with other WM
if (currentWm() == "kwin"
&& qstrcmp(NETRootInfo(QX11Info::display(), NET::SupportingWMCheck).wmName(), "KWin") == 0) {
// it is already running, don't necessarily restart e.g. after a failure with other WM
return true;
}
KMessageBox::information( window(), i18n( "Your running window manager will be now replaced with "
"the configured one." ), i18n( "Window Manager Change" ), "windowmanagerchange" );
KMessageBox::information(
window(),
i18n("Your running window manager will be now replaced with the configured one."),
i18n("Window Manager Change"),
"windowmanagerchange"
);
bool ret = false;
setEnabled(false);
@ -175,21 +174,23 @@ bool CfgWm::tryWmLaunch()
KTimerDialog* wmDialog = new KTimerDialog( 20000, KTimerDialog::CountDown, window(), i18n( "Config Window Manager Change" ),
KTimerDialog::Ok | KTimerDialog::Cancel, KTimerDialog::Cancel );
wmDialog->setButtonGuiItem( KDialog::Ok, KGuiItem( i18n( "&Accept Change" ), "dialog-ok" ));
wmDialog->setButtonGuiItem( KDialog::Cancel, KGuiItem( i18n( "&Revert to Previous" ), "dialog-cancel" ));
wmDialog->setButtonGuiItem(KDialog::Ok, KGuiItem(i18n("&Accept Change"), "dialog-ok"));
wmDialog->setButtonGuiItem(KDialog::Cancel, KGuiItem(i18n("&Revert to Previous"), "dialog-cancel"));
QLabel *label = new QLabel(
i18n( "The configured window manager is being launched.\n"
"Please check it has started properly and confirm the change.\n"
"The launch will be automatically reverted in 20 seconds." ), wmDialog );
label->setWordWrap( true );
wmDialog->setMainWidget( label );
label->setWordWrap(true);
wmDialog->setMainWidget(label);
if ( wmDialog->exec() != QDialog::Accepted ) {
if (wmDialog->exec() != QDialog::Accepted ) {
// cancelled for some reason
ret = false;
KMessageBox::sorry( window(),
i18n( "The running window manager has been reverted to the previous window manager." ));
KMessageBox::sorry(
window(),
i18n("The running window manager has been reverted to the previous window manager.")
);
}
delete wmDialog;
@ -197,9 +198,10 @@ bool CfgWm::tryWmLaunch()
} else {
ret = false;
KMessageBox::sorry( window(),
i18n( "The new window manager has failed to start.\n"
"The running window manager has been reverted to the previous window manager." ));
KMessageBox::sorry(
window(),
i18n("The new window manager has failed to start.\nThe running window manager has been reverted to the previous window manager.")
);
}
if (!ret) {
@ -208,7 +210,7 @@ bool CfgWm::tryWmLaunch()
if (wmkey.toLower() == oldwm) {
WmData oldwmdata = wms.value(wmkey);
killWM();
QProcess::startDetached( oldwmdata.exec );
QProcess::startDetached(oldwmdata.exec);
break;
}
}
@ -218,7 +220,7 @@ bool CfgWm::tryWmLaunch()
return ret;
}
void CfgWm::loadWMs( const QString& current )
void CfgWm::loadWMs(const QString& current)
{
WmData kwin;
kwin.internalName = "kwin";
@ -230,53 +232,52 @@ void CfgWm::loadWMs( const QString& current )
kwinRB->setChecked( true );
wmCombo->setEnabled( false );
QStringList list = KGlobal::dirs()->findAllResources( "windowmanagers", QString(), KStandardDirs::NoDuplicates );
QRegExp reg( ".*/([^/\\.]*)\\.[^/\\.]*" );
foreach( const QString& wmfile, list )
{
QStringList list = KGlobal::dirs()->findAllResources("windowmanagers", QString(), KStandardDirs::NoDuplicates);
QRegExp reg( ".*/([^/\\.]*)\\.[^/\\.]*");
foreach (const QString& wmfile, list) {
KDesktopFile file( wmfile );
if( file.noDisplay())
if (file.noDisplay())
continue;
if( !file.tryExec())
if (!file.tryExec())
continue;
QString testexec = file.desktopGroup().readEntry( "X-KDE-WindowManagerTestExec" );
if( !testexec.isEmpty())
{
if( QProcess::execute(testexec) != 0 )
QString testexec = file.desktopGroup().readEntry("X-KDE-WindowManagerTestExec");
if (!testexec.isEmpty()) {
if (QProcess::execute(testexec) != 0) {
continue;
}
}
QString name = file.readName();
if( name.isEmpty())
if (name.isEmpty())
continue;
if( !reg.exactMatch( wmfile ))
if (!reg.exactMatch(wmfile))
continue;
QString wm = reg.cap( 1 );
if( wms.contains( name ))
QString wm = reg.cap(1);
if (wms.contains(name))
continue;
WmData data;
data.internalName = wm;
data.exec = file.desktopGroup().readEntry( "Exec" );
if( data.exec.isEmpty())
if (data.exec.isEmpty())
continue;
data.configureCommand = file.desktopGroup().readEntry( "X-KDE-WindowManagerConfigure" );
data.parentArgument = file.desktopGroup().readEntry( "X-KDE-WindowManagerConfigureParentArgument" );
wms[ name ] = data;
wmCombo->addItem( name );
if( wms[ name ].internalName == current ) // make it selected
{
wmCombo->setCurrentIndex( wmCombo->count() - 1 );
data.configureCommand = file.desktopGroup().readEntry("X-KDE-WindowManagerConfigure");
data.parentArgument = file.desktopGroup().readEntry("X-KDE-WindowManagerConfigureParentArgument");
wms[name] = data;
wmCombo->addItem(name);
if (wms[ name ].internalName == current) {
// make it selected
wmCombo->setCurrentIndex(wmCombo->count() - 1);
oldwm = wm;
differentRB->setChecked( true );
wmCombo->setEnabled( true );
differentRB->setChecked(true);
wmCombo->setEnabled(true);
}
}
differentRB->setEnabled( wmCombo->count()>0 );
differentRB->setEnabled(wmCombo->count() > 0);
checkConfigureWm();
}
CfgWm::WmData CfgWm::currentWmData() const
{
return kwinRB->isChecked() ? wms[ "KWin" ] : wms[ wmCombo->currentText() ];
return kwinRB->isChecked() ? wms["KWin"] : wms[wmCombo->currentText()];
}
QString CfgWm::currentWm() const
@ -286,19 +287,20 @@ QString CfgWm::currentWm() const
void CfgWm::checkConfigureWm()
{
configureButton->setEnabled( !currentWmData().configureCommand.isEmpty());
configureButton->setEnabled(!currentWmData().configureCommand.isEmpty());
}
void CfgWm::configureWm()
{
if( oldwm != currentWm() // needs switching first
&& !saveAndConfirm())
{
if (oldwm != currentWm() && !saveAndConfirm()) {
// needs switching first
return;
}
QStringList args;
if( !currentWmData().parentArgument.isEmpty())
args << currentWmData().parentArgument << QString::number( window()->winId());
if( !QProcess::startDetached( currentWmData().configureCommand, args ))
KMessageBox::sorry( window(), i18n( "Running the configuration tool failed" ));
if (!currentWmData().parentArgument.isEmpty()) {
args << currentWmData().parentArgument << QString::number(window()->winId());
}
if (!QProcess::startDetached(currentWmData().configureCommand, args)) {
KMessageBox::sorry(window(), i18n("Running the configuration tool failed"));
}
}

View file

@ -48,7 +48,7 @@ private:
QString parentArgument;
};
WmData currentWmData() const;
QHash< QString, WmData > wms; // i18n text -> data
QHash<QString, WmData> wms; // i18n text -> data
QString oldwm; // the original value
};

View file

@ -31,35 +31,39 @@ K_PLUGIN_FACTORY(KCMComponentChooserFactory,
)
K_EXPORT_PLUGIN(KCMComponentChooserFactory("kcmcomponentchooser"))
KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &):
KCModule(KCMComponentChooserFactory::componentData(), parent) {
QVBoxLayout *lay = new QVBoxLayout(this);
KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &)
: KCModule(KCMComponentChooserFactory::componentData(), parent)
{
QVBoxLayout *lay = new QVBoxLayout(this);
lay->setMargin(0);
m_chooser=new ComponentChooser(this);
lay->addWidget(m_chooser);
connect(m_chooser,SIGNAL(changed(bool)),this,SIGNAL(changed(bool)));
setButtons( Default|Apply|Help );
m_chooser = new ComponentChooser(this);
lay->addWidget(m_chooser);
connect(m_chooser,SIGNAL(changed(bool)),this,SIGNAL(changed(bool)));
setButtons( Default|Apply|Help );
KAboutData *about =
new KAboutData(I18N_NOOP("kcmcomponentchooser"), 0, ki18n("Component Chooser"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c), 2002 Joseph Wenninger"));
KAboutData *about = new KAboutData(
I18N_NOOP("kcmcomponentchooser"), 0, ki18n("Component Chooser"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c), 2002 Joseph Wenninger")
);
about->addAuthor(ki18n("Joseph Wenninger"), KLocalizedString() , "jowenn@kde.org");
setAboutData( about );
about->addAuthor(ki18n("Joseph Wenninger"), KLocalizedString() , "jowenn@kde.org");
setAboutData( about );
}
void KCMComponentChooser::load(){
m_chooser->load();
void KCMComponentChooser::load()
{
m_chooser->load();
}
void KCMComponentChooser::save(){
m_chooser->save();
void KCMComponentChooser::save()
{
m_chooser->save();
}
void KCMComponentChooser::defaults(){
m_chooser->restoreDefault();
void KCMComponentChooser::defaults()
{
m_chooser->restoreDefault();
}

View file

@ -47,10 +47,9 @@ class KHBox;
*/
class KTimerDialog : public KDialog
{
Q_OBJECT
public:
Q_OBJECT
public:
/**
* @li @p CountDown - The timer counts downwards from the seconds given.
* @li @p CountUp - The timer counts up to the number of seconds given.
@ -121,19 +120,19 @@ class KTimerDialog : public KDialog
*/
void setMainWidget( QWidget *widget );
Q_SIGNALS:
Q_SIGNALS:
/**
* Signal which is emitted once the timer has timed out.
*/
void timerTimeout();
public Q_SLOTS:
public Q_SLOTS:
/**
* Execute the dialog modally - see @see QDialog .
*/
int exec();
private Q_SLOTS:
private Q_SLOTS:
/**
* Updates the dialog with the current progress levels.
*/
@ -144,7 +143,7 @@ class KTimerDialog : public KDialog
*/
void slotInternalTimeout();
private:
private:
/**
* Prepares the layout that manages the widgets of the dialog
*/
@ -167,6 +166,3 @@ class KTimerDialog : public KDialog
};
#endif