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

@ -94,13 +94,13 @@ void CfgComponent::load(KConfig *cfg) {
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))
{
for (int i = 0;i < ComponentSelector->count(); i++) {
if (tmp == ComponentSelector->itemText(i)) {
ComponentSelector->setCurrentIndex(i);
break;
}
}
}
emit changed(false);
}
@ -112,41 +112,53 @@ 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);
const QStringList services=KGlobal::dirs()->findAllResources( "data","kcm_componentchooser/*.desktop",
KStandardDirs::NoDuplicates);
for (QStringList::const_iterator it=services.constBegin(); it!=services.constEnd(); ++it)
{
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")));
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*)));
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();
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);
@ -156,66 +168,38 @@ void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
QString cfgType=cfg.group(QByteArray()).readEntry("configurationType");
QWidget *newConfigWidget = 0;
if (cfgType.isEmpty() || (cfgType=="component"))
{
if (!(configWidget && qobject_cast<CfgComponent*>(configWidget)))
{
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
{
} 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)))
{
} else if (cfgType=="internal_email") {
if (!(configWidget && qobject_cast<CfgEmailClient*>(configWidget))) {
newConfigWidget = new CfgEmailClient(configContainer);
}
}
#ifdef Q_OS_UNIX
else if (cfgType=="internal_terminal")
{
if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget)))
{
} else if (cfgType=="internal_terminal") {
if (!(configWidget && qobject_cast<CfgTerminalEmulator*>(configWidget))) {
newConfigWidget = new CfgTerminalEmulator(configContainer);
}
}
#ifdef Q_WS_X11
else if (cfgType=="internal_wm")
{
if (!(configWidget && qobject_cast<CfgWm*>(configWidget)))
{
} else if (cfgType=="internal_wm") {
if (!(configWidget && qobject_cast<CfgWm*>(configWidget))) {
newConfigWidget = new CfgWm(configContainer);
}
}
#endif
#endif
else if (cfgType=="internal_filemanager")
{
if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget)))
{
} else if (cfgType=="internal_filemanager") {
if (!(configWidget && qobject_cast<CfgFileManager*>(configWidget))) {
newConfigWidget = new CfgFileManager(configContainer);
}
}
else if (cfgType=="internal_browser")
{
if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget)))
{
} else if (cfgType=="internal_browser") {
if (!(configWidget && qobject_cast<CfgBrowser*>(configWidget))) {
newConfigWidget = new CfgBrowser(configContainer);
}
}
if (newConfigWidget)
{
if (newConfigWidget) {
configContainer->addWidget(newConfigWidget);
configContainer->setCurrentWidget (newConfigWidget);
configContainer->removeWidget(configWidget);
@ -225,15 +209,16 @@ void ComponentChooser::slotServiceSelected(QListWidgetItem* it) {
configContainer->setMinimumSize(configWidget->sizeHint());
}
if (configWidget)
if (configWidget) {
dynamic_cast<CfgPlugin*>(configWidget)->load(&cfg);
}
emitChanged(false);
latestEditedService=it->data(Qt::UserRole).toString();
}
void ComponentChooser::emitChanged(bool val) {
void ComponentChooser::emitChanged(bool val)
{
somethingChanged=val;
emit changed(val);
}
@ -244,33 +229,31 @@ ComponentChooser::~ComponentChooser()
delete configWidget;
}
void ComponentChooser::load() {
if( configWidget )
void ComponentChooser::load()
{
if( configWidget ) {
CfgPlugin * plugin = dynamic_cast<CfgPlugin*>(configWidget);
if( plugin )
{
if (plugin) {
KConfig cfg(latestEditedService, KConfig::SimpleConfig);
plugin->load(&cfg);
}
}
}
void ComponentChooser::save() {
if( configWidget )
void ComponentChooser::save()
{
if(configWidget) {
CfgPlugin* plugin = dynamic_cast<CfgPlugin*>(configWidget);
if( plugin )
{
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);
}

View file

@ -18,17 +18,17 @@
#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
/*
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
@ -62,9 +62,7 @@ Q_SIGNALS:
class ComponentChooser : public QWidget, public Ui::ComponentChooser_UI
{
Q_OBJECT
public:
ComponentChooser(QWidget *parent=0);
virtual ~ComponentChooser();
@ -82,8 +80,6 @@ protected Q_SLOTS:
Q_SIGNALS:
void changed(bool);
};
#endif

View file

@ -30,7 +30,8 @@ CfgBrowser::CfgBrowser(QWidget *parent)
connect(btnSelectBrowser,SIGNAL(clicked()),this, SLOT(selectBrowser()));
}
CfgBrowser::~CfgBrowser() {
CfgBrowser::~CfgBrowser()
{
}
void CfgBrowser::configChanged()
@ -43,34 +44,28 @@ 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())
{
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();
}
}
}
lineExec->setText(m_browserExec);
@ -81,14 +76,14 @@ 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.sync();
@ -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

@ -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");
QDBusConnection::sessionBus().send(message);
emit changed(false);
}

View file

@ -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

@ -39,10 +39,10 @@ CfgTerminalEmulator::CfgTerminalEmulator(QWidget *parent)
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()
@ -56,16 +56,14 @@ void CfgTerminalEmulator::defaults()
}
void CfgTerminalEmulator::load(KConfig *) {
void CfgTerminalEmulator::load(KConfig *)
{
KConfigGroup config(KSharedConfig::openConfig("kdeglobals"), "General");
QString terminal = config.readPathEntry("TerminalApplication","konsole");
if (terminal == "konsole")
{
if (terminal == "konsole") {
terminalLE->setText("xterm");
terminalCB->setChecked(true);
}
else
{
} else {
terminalLE->setText(terminal);
otherCB->setChecked(true);
}
@ -91,11 +89,12 @@ void CfgTerminalEmulator::selectTerminalApp()
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;
if (dlg.exec() != QDialog::Accepted) {
return;
}
QString client = dlg.text();
if (!client.isEmpty())
{
if (!client.isEmpty()) {
terminalLE->setText(client);
}
}

View file

@ -18,6 +18,7 @@
#include "ui_terminalemulatorconfig_ui.h"
#include "componentchooser.h"
class KConfig;
class CfgPlugin;

View file

@ -104,10 +104,10 @@ bool CfgWm::saveAndConfirm()
KConfigGroup c( &cfg, "General");
c.writeEntry("windowManager", currentWm());
emit changed(false);
if( oldwm == currentWm())
if (oldwm == currentWm()) {
return true;
if( tryWmLaunch())
{
}
if (tryWmLaunch()) {
oldwm = currentWm();
cfg.sync();
QDBusInterface ksmserver("org.kde.ksmserver", "/KSMServer");
@ -118,28 +118,23 @@ bool CfgWm::saveAndConfirm()
"all running applications adjust for this change."),
i18n( "Window Manager Replaced"), "restartafterwmchange");
return true;
}
else
{ // revert config
} else {
// revert config
emit changed(true);
c.writeEntry("windowManager", oldwm);
if( oldwm == "kwin" )
{
if (oldwm == "kwin") {
kwinRB->setChecked(true);
wmCombo->setEnabled(false);
}
else
{
} 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
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;
}
}
@ -147,12 +142,16 @@ 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
&& 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);
@ -188,8 +187,10 @@ bool CfgWm::tryWmLaunch()
// 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) {
@ -232,19 +234,18 @@ void CfgWm::loadWMs( const QString& current )
QStringList list = KGlobal::dirs()->findAllResources("windowmanagers", QString(), KStandardDirs::NoDuplicates);
QRegExp reg( ".*/([^/\\.]*)\\.[^/\\.]*");
foreach( const QString& wmfile, list )
{
foreach (const QString& wmfile, list) {
KDesktopFile file( wmfile );
if (file.noDisplay())
continue;
if (!file.tryExec())
continue;
QString testexec = file.desktopGroup().readEntry("X-KDE-WindowManagerTestExec");
if( !testexec.isEmpty())
{
if( QProcess::execute(testexec) != 0 )
if (!testexec.isEmpty()) {
if (QProcess::execute(testexec) != 0) {
continue;
}
}
QString name = file.readName();
if (name.isEmpty())
continue;
@ -262,8 +263,8 @@ void CfgWm::loadWMs( const QString& current )
data.parentArgument = file.desktopGroup().readEntry("X-KDE-WindowManagerConfigureParentArgument");
wms[name] = data;
wmCombo->addItem(name);
if( wms[ name ].internalName == current ) // make it selected
{
if (wms[ name ].internalName == current) {
// make it selected
wmCombo->setCurrentIndex(wmCombo->count() - 1);
oldwm = wm;
differentRB->setChecked(true);
@ -291,14 +292,15 @@ void CfgWm::checkConfigureWm()
void CfgWm::configureWm()
{
if( oldwm != currentWm() // needs switching first
&& !saveAndConfirm())
{
if (oldwm != currentWm() && !saveAndConfirm()) {
// needs switching first
return;
}
QStringList args;
if( !currentWmData().parentArgument.isEmpty())
if (!currentWmData().parentArgument.isEmpty()) {
args << currentWmData().parentArgument << QString::number(window()->winId());
if( !QProcess::startDetached( currentWmData().configureCommand, args ))
}
if (!QProcess::startDetached(currentWmData().configureCommand, args)) {
KMessageBox::sorry(window(), i18n("Running the configuration tool failed"));
}
}

View file

@ -31,9 +31,9 @@ K_PLUGIN_FACTORY(KCMComponentChooserFactory,
)
K_EXPORT_PLUGIN(KCMComponentChooserFactory("kcmcomponentchooser"))
KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &):
KCModule(KCMComponentChooserFactory::componentData(), parent) {
KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &)
: KCModule(KCMComponentChooserFactory::componentData(), parent)
{
QVBoxLayout *lay = new QVBoxLayout(this);
lay->setMargin(0);
@ -42,24 +42,28 @@ KCMComponentChooser::KCMComponentChooser(QWidget *parent, const QVariantList &):
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"),
KAboutData *about = new KAboutData(
I18N_NOOP("kcmcomponentchooser"), 0, ki18n("Component Chooser"),
0, KLocalizedString(), KAboutData::License_GPL,
ki18n("(c), 2002 Joseph Wenninger"));
ki18n("(c), 2002 Joseph Wenninger")
);
about->addAuthor(ki18n("Joseph Wenninger"), KLocalizedString() , "jowenn@kde.org");
setAboutData( about );
}
void KCMComponentChooser::load(){
void KCMComponentChooser::load()
{
m_chooser->load();
}
void KCMComponentChooser::save(){
void KCMComponentChooser::save()
{
m_chooser->save();
}
void KCMComponentChooser::defaults(){
void KCMComponentChooser::defaults()
{
m_chooser->restoreDefault();
}

View file

@ -50,7 +50,6 @@ class KTimerDialog : public KDialog
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.
@ -167,6 +166,3 @@ class KTimerDialog : public KDialog
};
#endif