kutils: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-07-30 09:44:43 +03:00
parent 833951fbc3
commit 48e591141b
10 changed files with 670 additions and 662 deletions

View file

@ -44,22 +44,20 @@ class KCModuleContainer::KCModuleContainerPrivate
{
public:
KCModuleContainerPrivate(const QStringList &mods)
: modules( mods )
, tabWidget( 0 )
, topLayout( 0 )
{}
: modules(mods),
tabWidget(nullptr),
topLayout(nullptr)
{
}
QStringList modules;
KTabWidget *tabWidget;
KCModule::Buttons buttons;
QVBoxLayout *topLayout;
};
/***********************************************************************/
// The KCModuleContainer is only a wrapper around real KCModules. Therefore it doesn't need a
// special KComponentData and can just use the global instance. The contained KCModules create their own
// KComponentData objects when needed.
@ -88,13 +86,13 @@ void KCModuleContainer::init()
connect(d->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabSwitched(int)));
d->topLayout->addWidget(d->tabWidget);
if ( !d->modules.isEmpty() )
{
if (!d->modules.isEmpty()) {
/* Add our modules */
foreach (const QString it, d->modules )
foreach (const QString it, d->modules) {
addModule(it);
}
}
}
void KCModuleContainer::addModule(const QString &module)
{
@ -103,24 +101,26 @@ void KCModuleContainer::addModule( const QString& module )
* For example, KCM monitor gamma can be in kdegraphics.
*/
KService::Ptr service = KService::serviceByDesktopName(module);
if ( !service )
{
kDebug(713) << "KCModuleContainer: module '" <<
module << "' was not found and thus not loaded";
if (!service) {
kDebug(713) << "KCModuleContainer: module '"
<< module << "' was not found and thus not loaded";
return;
}
if ( service->noDisplay() )
if (service->noDisplay()) {
return;
}
KCModuleProxy* proxy = new KCModuleProxy(service, d->tabWidget);
allModules.append(proxy);
proxy->setObjectName(module.toLatin1());
d->tabWidget->addTab( proxy, KIcon( proxy->moduleInfo().icon() ),
/* Qt eats ampersands for dinner. But not this time. */
proxy->moduleInfo().moduleName().replace( '&', "&&" ));
d->tabWidget->addTab(
proxy, KIcon(proxy->moduleInfo().icon()),
/* Katie eats ampersands for dinner. But not this time. */
proxy->moduleInfo().moduleName().replace('&', "&&")
);
d->tabWidget->setTabToolTip(d->tabWidget->indexOf(proxy), proxy->moduleInfo().comment());
@ -141,8 +141,7 @@ void KCModuleContainer::save()
{
ModuleList list = changedModules;
ModuleList::iterator it;
for ( it = list.begin() ; it !=list.end() ; ++it )
{
for ( it = list.begin() ; it !=list.end() ; ++it ) {
(*it)->save();
}
@ -154,8 +153,7 @@ void KCModuleContainer::load()
{
ModuleList list = allModules;
ModuleList::iterator it;
for ( it = list.begin() ; it !=list.end() ; ++it )
{
for ( it = list.begin() ; it !=list.end() ; ++it ) {
(*it)->load();
}
@ -166,20 +164,19 @@ void KCModuleContainer::defaults()
{
ModuleList list = allModules;
ModuleList::iterator it;
for ( it = list.begin() ; it !=list.end() ; ++it )
{
for (it = list.begin() ; it !=list.end() ; ++it) {
(*it)->defaults();
}
emit changed( true );
}
void KCModuleContainer::moduleChanged(KCModuleProxy *proxy)
{
changedModules.append(proxy);
if( changedModules.isEmpty() )
if (changedModules.isEmpty()) {
return;
}
emit changed(true);
}
@ -188,9 +185,3 @@ KCModuleContainer::~KCModuleContainer()
{
delete d;
}
/***********************************************************************/

View file

@ -35,10 +35,15 @@ class KCModuleInfo::Private
{
public:
Private();
Private( KService::Ptr );
Private(KService::Ptr s);
QStringList keywords;
QString name, icon, lib, fileName, doc, comment;
QString name;
QString icon;
QString lib;
QString fileName;
QString doc;
QString comment;
bool allLoaded;
int weight;
@ -56,11 +61,10 @@ KCModuleInfo::Private::Private()
}
KCModuleInfo::Private::Private(KService::Ptr s)
: allLoaded( false )
, service( s )
{
if ( !service )
: allLoaded(false),
service(s)
{
if (!service) {
kDebug(712) << "Could not find the service.";
return;
}
@ -75,23 +79,23 @@ KCModuleInfo::Private::Private( KService::Ptr s )
}
KCModuleInfo::KCModuleInfo()
: d(new Private())
{
d = new Private;
}
KCModuleInfo::KCModuleInfo(const QString &desktopFile)
: d(new Private(KService::serviceByStorageId(desktopFile)))
{
d = new Private( KService::serviceByStorageId(desktopFile) );
}
KCModuleInfo::KCModuleInfo(KService::Ptr moduleInfo)
: d(new Private(moduleInfo))
{
d = new Private( moduleInfo );
}
KCModuleInfo::KCModuleInfo(const KCModuleInfo &rhs)
: d(new Private())
{
d = new Private;
(*this) = rhs;
}
@ -120,8 +124,10 @@ void KCModuleInfo::Private::loadAll()
{
allLoaded = true;
if( !service ) /* We have a bogus service. All get functions will return empty/zero values */
if (!service) {
/* We have a bogus service. All get functions will return empty/zero values */
return;
}
// get the documentation path
doc = service->property("X-DocPath", QVariant::String).toString();
@ -168,18 +174,16 @@ QString KCModuleInfo::library() const
QString KCModuleInfo::docPath() const
{
if (!d->allLoaded)
if (!d->allLoaded) {
d->loadAll();
}
return d->doc;
}
int KCModuleInfo::weight() const
{
if (!d->allLoaded)
if (!d->allLoaded) {
d->loadAll();
}
return d->weight;
}
// vim: ts=2 sw=2 et

View file

@ -44,11 +44,9 @@
* @author Daniel Molkentin <molkentin@kde.org>
*
*/
class KCMUTILS_EXPORT KCModuleInfo // krazy:exclude=dpointer (implicitly shared)
class KCMUTILS_EXPORT KCModuleInfo
{
public:
/**
* Constructs a KCModuleInfo.
* @note a KCModuleInfo object will have to be manually deleted, it is not
@ -153,5 +151,3 @@ private:
};
#endif // KCMODULEINFO_H
// vim: ts=2 sw=2 et

View file

@ -55,12 +55,14 @@ public:
};
/***************************************************************/
KCModule *KCModuleLoader::loadModule(const QString &module, ErrorReporting report, QWidget *parent, const QStringList &args)
KCModule *KCModuleLoader::loadModule(const QString &module, ErrorReporting report,
QWidget *parent, const QStringList &args)
{
return loadModule(KCModuleInfo(module), report, parent, args);
}
KCModule* KCModuleLoader::loadModule(const KCModuleInfo& mod, ErrorReporting report, QWidget* parent, const QStringList& args )
KCModule* KCModuleLoader::loadModule(const KCModuleInfo &mod, ErrorReporting report,
QWidget *parent, const QStringList &args)
{
/*
* Simple libraries as modules are the easiest case:
@ -68,17 +70,31 @@ KCModule* KCModuleLoader::loadModule(const KCModuleInfo& mod, ErrorReporting rep
* from the factory.
*/
if ( !mod.service() )
return reportError( report,
i18n("The module %1 could not be found.",
mod.moduleName() ), i18n("<qt><p>The diagnosis is:<br />The desktop file %1 could not be found.</p></qt>", mod.fileName()), parent );
if( mod.service()->noDisplay() )
return reportError( report, i18n( "The module %1 is disabled.", mod.moduleName() ),
i18n( "<qt><p>Either the hardware/software the module configures is not available or the module has been disabled by the administrator.</p></qt>" ),
parent );
if (!mod.service()) {
return reportError(
report,
i18n(
"The module %1 could not be found.",
mod.moduleName()
),
i18n(
"<qt><p>The diagnosis is:<br />The desktop file %1 could not be found.</p></qt>", mod.fileName()
),
parent
);
}
if (mod.service()->noDisplay()) {
return reportError(
report,
i18n("The module %1 is disabled.", mod.moduleName()),
i18n(
"<qt><p>Either the hardware/software the module configures is not available or the module has been disabled by the administrator.</p></qt>"
),
parent
);
}
if (!mod.library().isEmpty())
{
if (!mod.library().isEmpty()) {
QString error;
QVariantList args2;
foreach (const QString &arg, args) {
@ -99,9 +115,12 @@ KCModule* KCModuleLoader::loadModule(const KCModuleInfo& mod, ErrorReporting rep
* (startService calls kcmshell which calls modloader which calls startService...)
*
*/
return reportError( report,
return reportError(
report,
i18n("The module %1 is not a valid configuration module.", mod.moduleName()),
i18n("<qt>The diagnosis is:<br />The desktop file %1 does not specify a library.</qt>", mod.fileName()), parent );
i18n("<qt>The diagnosis is:<br />The desktop file %1 does not specify a library.</qt>", mod.fileName()),
parent
);
}
KCModule* KCModuleLoader::reportError(ErrorReporting report, const QString &text,
@ -109,11 +128,13 @@ KCModule* KCModuleLoader::reportError( ErrorReporting report, const QString & te
{
QString realDetails = details;
if (realDetails.isNull()) {
realDetails = i18n("<qt><p>Possible reasons:<ul><li>An error occurred during your last "
realDetails = i18n(
"<qt><p>Possible reasons:<ul><li>An error occurred during your last "
"KDE upgrade leaving an orphaned control module</li><li>You have old third party "
"modules lying around.</li></ul></p><p>Check these points carefully and try to remove "
"the module mentioned in the error message. If this fails, consider contacting "
"your distributor or packager.</p></qt>");
"your distributor or packager.</p></qt>"
);
}
if (report & KCModuleLoader::Dialog) {
KMessageBox::detailedError(parent, text, realDetails);
@ -121,7 +142,5 @@ KCModule* KCModuleLoader::reportError( ErrorReporting report, const QString & te
if (report & KCModuleLoader::Inline) {
return new KCMError(text, realDetails, parent);
}
return 0;
return nullptr;
}
// vim: ts=4

View file

@ -48,7 +48,7 @@ namespace KCModuleLoader
enum ErrorReporting {
/**
* no error reporting is done
* */
*/
None = 0,
/**
* the error report is shown instead of the
@ -72,8 +72,8 @@ namespace KCModuleLoader
*
* @return a pointer to the loaded @ref KCModule
*/
KCMUTILS_EXPORT KCModule *loadModule(const KCModuleInfo &module, ErrorReporting
report, QWidget * parent = 0, const QStringList& args = QStringList() );
KCMUTILS_EXPORT KCModule* loadModule(const KCModuleInfo &module, ErrorReporting report,
QWidget *parent = nullptr, const QStringList &args = QStringList());
/**
* Loads a @ref KCModule. If loading fails a zero pointer is returned.
@ -84,7 +84,7 @@ namespace KCModuleLoader
* @return a pointer to the loaded @ref KCModule
*/
KCMUTILS_EXPORT KCModule* loadModule(const QString &module, ErrorReporting report,
QWidget *parent = 0, const QStringList& args = QStringList() );
QWidget *parent = nullptr, const QStringList &args = QStringList());
/**
* Returns a KCModule containing the messages @p report and @p text.
@ -99,5 +99,4 @@ namespace KCModuleLoader
const QString &details, QWidget *parent);
}
// vim: ts=2 sw=2 et
#endif // KCMODULELOADER_H

View file

@ -45,8 +45,7 @@
- Two Layout problems in runAsRoot:
* lblBusy doesn't show
* d->kcm/d->rootInfo doesn't get it right when the user
presses cancel in the kdesudo dialog
* d->kcm/d->rootInfo doesn't get it right when the user presses cancel in the kdesudo dialog
- Resizing horizontally is contrained; minimum size is set somewhere.
It appears to be somehow derived from the module's size.
@ -64,8 +63,7 @@ KCModule* KCModuleProxy::realModule() const
*/
/* Already loaded */
if( !d->kcm )
{
if (!d->kcm) {
QApplication::setOverrideCursor(Qt::WaitCursor);
const_cast<KCModuleProxyPrivate*>(d)->loadModule();
QApplication::restoreOverrideCursor();
@ -75,8 +73,7 @@ KCModule* KCModuleProxy::realModule() const
void KCModuleProxyPrivate::loadModule()
{
if( !topLayout )
{
if (!topLayout) {
topLayout = new QVBoxLayout(parent);
topLayout->setMargin(0);
@ -86,10 +83,12 @@ void KCModuleProxyPrivate::loadModule()
dbusService = QLatin1String("org.kde.internal.KSettingsWidget_") + name;
}
if( QDBusConnection::sessionBus().registerService( dbusService ) || bogusOccupier )
{ /* We got the name we requested, because no one was before us,
* or, it was an random application which had picked that name */
kDebug(711) << "Module not already loaded, loading module " << modInfo.moduleName() << " from library " << modInfo.library();
if (QDBusConnection::sessionBus().registerService(dbusService) || bogusOccupier) {
/* We got the name we requested, because no one was before us,
* or, it was an random application which had picked that name
*/
kDebug(711) << "Module not already loaded, loading module " << modInfo.moduleName()
<< " from library " << modInfo.library();
kcm = KCModuleLoader::loadModule(modInfo, KCModuleLoader::Inline, parent, args);
@ -102,14 +101,18 @@ void KCModuleProxyPrivate::loadModule()
kcm->layout()->setMargin(0);
}
topLayout->addWidget( kcm );
if( !modInfo.library().isEmpty() )
QDBusConnection::sessionBus().registerObject(dbusPath, new KSettingsWidgetAdaptor(parent), QDBusConnection::ExportAllSlots);
if (!modInfo.library().isEmpty()) {
QDBusConnection::sessionBus().registerObject(
dbusPath, new KSettingsWidgetAdaptor(parent), QDBusConnection::ExportAllSlots
);
}
if (!rootInfo && /* If it's not already done */
kcm->useRootOnlyMessage() && /* kcm wants root message */
!KUser().isSuperUser() ) /* Not necessary if we're root */
{
/*rootInfo = new QLabel( parent );
#if 0
rootInfo = new QLabel(parent);
topLayout->insertWidget(0, rootInfo);
QPalette palette = rootInfo->palette();
@ -121,41 +124,51 @@ void KCModuleProxyPrivate::loadModule()
const QString message = kcm->rootOnlyMessage();
if (message.isEmpty() )
rootInfo->setText( i18n(
rootInfo->setText(
i18n(
"<b>Changes in this section require root access.</b><br />"
"On applying your changes you will have to supply your root "
"password." ) );
else
"password." )
);
} else {
rootInfo->setText(message);
}
rootInfo->setWhatsThis( i18n(
rootInfo->setWhatsThis(
i18n(
"This section requires special permissions, probably "
"for system-wide changes; therefore, it is "
"required that you provide the root password to be "
"able to change the module's properties. If "
"you cannot provide the password, the changes of the "
"module cannot be saved " ) );*/
"module cannot be saved "
)
);
#endif
}
}
else
{
} else {
kDebug(711) << "Module already loaded, loading KCMError";
/* Figure out the name of where the module is already loaded */
QDBusInterface proxy(dbusService, dbusPath, "org.kde.internal.KSettingsWidget");
QDBusReply<QString> reply = proxy.call("applicationName");
if( reply.isValid() )
{
QObject::connect( QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
parent, SLOT(_k_ownerChanged(QString,QString,QString)));
kcm = KCModuleLoader::reportError( KCModuleLoader::Inline,
i18nc( "Argument is application name", "This configuration section is "
"already opened in %1" , reply.value() ), " ", parent );
if (reply.isValid()) {
QObject::connect(
QDBusConnection::sessionBus().interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)),
parent, SLOT(_k_ownerChanged(QString,QString,QString))
);
kcm = KCModuleLoader::reportError(
KCModuleLoader::Inline,
i18nc(
"Argument is application name", "This configuration section is "
"already opened in %1", reply.value()
),
" ",
parent
);
topLayout->addWidget(kcm);
}
else
{
} else {
kDebug(711) << "Calling KCModuleProxy's DBus interface for fetching the name failed.";
bogusOccupier = true;
loadModule();
@ -169,7 +182,7 @@ void KCModuleProxyPrivate::_k_ownerChanged(const QString &service, const QString
// Violence: Get rid of KCMError & CO, so that
// realModule() attempts to reload the module
delete kcm;
kcm = 0;
kcm = nullptr;
Q_Q(KCModuleProxy);
q->realModule();
@ -196,7 +209,6 @@ void KCModuleProxy::showEvent( QShowEvent * ev )
KCModuleProxy::~KCModuleProxy()
{
deleteClient();
delete d_ptr;
}
@ -204,7 +216,7 @@ void KCModuleProxy::deleteClient()
{
Q_D(KCModuleProxy);
delete d->kcm;
d->kcm = 0;
d->kcm = nullptr;
if (qApp) {
qApp->syncX();
@ -225,36 +237,37 @@ void KCModuleProxyPrivate::_k_moduleChanged(bool c)
void KCModuleProxyPrivate::_k_moduleDestroyed()
{
kcm = 0;
kcm = nullptr;
}
KCModuleProxy::KCModuleProxy(const KService::Ptr &service, QWidget *parent,
const QStringList &args)
: QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(service), args))
: QWidget(parent),
d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(service), args))
{
d_ptr->q_ptr = this;
}
KCModuleProxy::KCModuleProxy(const KCModuleInfo &info, QWidget *parent,
const QStringList &args)
: QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, info, args))
: QWidget(parent),
d_ptr(new KCModuleProxyPrivate(this, info, args))
{
d_ptr->q_ptr = this;
}
KCModuleProxy::KCModuleProxy(const QString &serviceName, QWidget *parent,
const QStringList &args)
: QWidget(parent), d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(serviceName), args))
: QWidget(parent),
d_ptr(new KCModuleProxyPrivate(this, KCModuleInfo(serviceName), args))
{
d_ptr->q_ptr = this;
}
void KCModuleProxy::load()
{
Q_D(KCModuleProxy);
if( realModule() )
{
if (realModule()) {
d->kcm->load();
d->_k_moduleChanged(false);
}
@ -263,8 +276,7 @@ void KCModuleProxy::load()
void KCModuleProxy::save()
{
Q_D(KCModuleProxy);
if( d->changed && realModule() )
{
if (d->changed && realModule()) {
d->kcm->save();
d->_k_moduleChanged(false);
}
@ -273,9 +285,10 @@ void KCModuleProxy::save()
void KCModuleProxy::defaults()
{
Q_D(KCModuleProxy);
if( realModule() )
if (realModule()) {
d->kcm->defaults();
}
}
QString KCModuleProxy::quickHelp() const
{
@ -284,13 +297,14 @@ QString KCModuleProxy::quickHelp() const
const KAboutData* KCModuleProxy::aboutData() const
{
return realModule() ? realModule()->aboutData() : 0;
return realModule() ? realModule()->aboutData() : nullptr;
}
KCModule::Buttons KCModuleProxy::buttons() const
{
if( realModule() )
if (realModule()) {
return realModule()->buttons();
}
return KCModule::Buttons(KCModule::Help | KCModule::Default | KCModule::Apply);
}
@ -340,5 +354,3 @@ QString KCModuleProxy::dbusPath() const
/***************************************************************/
#include "moc_kcmoduleproxy.cpp"
// vim: ts=4

View file

@ -71,10 +71,9 @@ public:
*
* @param info The KCModuleInfo to construct the module from.
* @param parent the parent QWidget.
* @param args This is used in the implementation and is internal.
* Use the default.
* @param args This is used in the implementation and is internal. Use the default.
*/
explicit KCModuleProxy( const KCModuleInfo& info, QWidget* parent = 0,
explicit KCModuleProxy(const KCModuleInfo &info, QWidget *parent = nullptr,
const QStringList &args = QStringList());
/**
@ -84,10 +83,9 @@ public:
*
* @param serviceName The module's service name to construct from.
* @param parent the parent QWidget.
* @param args This is used in the implementation and is internal.
* Use the default.
* @param args This is used in the implementation and is internal. Use the default.
*/
explicit KCModuleProxy( const QString& serviceName, QWidget* parent = 0,
explicit KCModuleProxy(const QString &serviceName, QWidget *parent = nullptr,
const QStringList &args = QStringList());
/**
@ -95,10 +93,9 @@ public:
*
* @param service The KService to construct from.
* @param parent the parent QWidget.
* @param args This is used in the implementation and is internal.
* Use the default.
* @param args This is used in the implementation and is internal. Use the default.
*/
explicit KCModuleProxy( const KService::Ptr& service, QWidget* parent = 0,
explicit KCModuleProxy(const KService::Ptr &service, QWidget *parent = nullptr,
const QStringList &args = QStringList());
/**
@ -107,17 +104,14 @@ public:
~KCModuleProxy();
/**
* Calling it will cause the contained module to
* run its load() routine.
* Calling it will cause the contained module to run its load() routine.
*/
void load();
/**
* Calling it will cause the contained module to
* run its save() routine.
* Calling it will cause the contained module to run its save() routine.
*
* If the module was not modified, it will not be asked
* to save.
* If the module was not modified, it will not be asked to save.
*/
void save();
@ -138,8 +132,7 @@ public:
KCModule::Buttons buttons() const;
/**
* @return The module's custom root
* message, if it has one
* @return The module's custom root message, if it has one
* @deprecated
*/
QString rootOnlyMessage() const;
@ -180,8 +173,7 @@ public:
KCModule* realModule() const;
/**
* @return a KCModuleInfo for the encapsulated
* module
* @return a KCModuleInfo for the encapsulated module
*/
KCModuleInfo moduleInfo() const;
@ -195,7 +187,6 @@ public:
QString dbusPath() const;
public Q_SLOTS:
/**
* Calling it will cause the contained module to
* load its default values.
@ -210,7 +201,6 @@ public Q_SLOTS:
void deleteClient();
Q_SIGNALS:
/*
* This signal is emitted when the contained module is changed.
*/
@ -235,7 +225,6 @@ Q_SIGNALS:
void quickHelpChanged();
protected:
/**
* Reimplemented for internal purposes. Makes sure the encapsulated
* module is loaded before the show event is taken care of.

View file

@ -74,4 +74,3 @@ class KCModuleProxyPrivate
};
#endif // KCMUTILS_KCMODULEPROXY_P_H
// vim: sw=4 sts=4 et tw=100

View file

@ -45,7 +45,7 @@ class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog
*
* @param parent The parent widget
**/
KCMultiDialog( QWidget *parent = 0 );
KCMultiDialog(QWidget *parent = nullptr);
/**
@ -66,8 +66,7 @@ class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog
*
* @returns The @see KPageWidgetItem associated with the new dialog page.
**/
KPageWidgetItem* addModule( const QString& module, const QStringList&
args = QStringList() );
KPageWidgetItem* addModule(const QString &module, const QStringList &args = QStringList());
/**
* Add a module.
@ -80,11 +79,11 @@ class KCMUTILS_EXPORT KCMultiDialog : public KPageDialog
* to the list of modules the dialog will show.
*
* @param parent The @see KPageWidgetItem that should appear as parents
* in the tree view or a 0 pointer if there is no parent.
* in the tree view or a null pointer if there is no parent.
*
* @param args The arguments that should be given to the KCModule when it is created
**/
KPageWidgetItem* addModule( const KCModuleInfo& moduleinfo, KPageWidgetItem *parent = 0,
KPageWidgetItem* addModule(const KCModuleInfo &moduleinfo, KPageWidgetItem *parent = nullptr,
const QStringList &args = QStringList());
/**