From c10a61a5c79d558a4de00cc6412d46a2655ff3b9 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 4 May 2019 23:52:26 +0000 Subject: [PATCH] generic: KApplication cleanup Signed-off-by: Ivailo Monev --- kdeui/kernel/kapplication.cpp | 58 +++++++++++++---------------- kdeui/kernel/kapplication.h | 17 ++++----- kdeui/kernel/kglobalsettings.cpp | 11 ++---- kdeui/kernel/kstyle.cpp | 2 + kdeui/kernel/kuniqueapplication.cpp | 4 +- kdeui/kernel/kuniqueapplication.h | 5 +-- kdeui/widgets/kmenu.cpp | 6 --- kio/kio/kmessageboxwrapper.h | 6 +-- kio/misc/kmailservice.cpp | 7 ++-- kross/console/main.cpp | 2 +- 10 files changed, 51 insertions(+), 67 deletions(-) diff --git a/kdeui/kernel/kapplication.cpp b/kdeui/kernel/kapplication.cpp index 078e03bd..8a18aebf 100644 --- a/kdeui/kernel/kapplication.cpp +++ b/kdeui/kernel/kapplication.cpp @@ -154,7 +154,7 @@ public: void _k_slot_KToolInvocation_hook(QStringList&, QByteArray&); QString sessionConfigName() const; - void init(bool GUIenabled=true); + void init(); void parseCommandLine( ); // Handle KDE arguments (Using KCmdLineArgs) static void preqapplicationhack(); static void preread_app_startup_id(); @@ -284,15 +284,15 @@ static SmcConn mySmcConnection = 0; // Possibly "steal" XFree86's libSM? #endif -KApplication::KApplication(bool GUIenabled) - : QApplication((KApplicationPrivate::preqapplicationhack(),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), GUIenabled), +KApplication::KApplication() + : QApplication((KApplicationPrivate::preqapplicationhack(),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), KAPPLICATION_GUI_TYPE), d(new KApplicationPrivate(this)) { d->read_app_startup_id(); setApplicationName(d->componentData.componentName()); setOrganizationDomain(d->componentData.aboutData()->organizationDomain()); installSigpipeHandler(); - d->init(GUIenabled); + d->init(); } #ifdef Q_WS_X11 @@ -319,24 +319,22 @@ KApplication::KApplication(Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap, } #endif -KApplication::KApplication(bool GUIenabled, const KComponentData &cData) - : QApplication((KApplicationPrivate::preqapplicationhack(),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), GUIenabled), +KApplication::KApplication(const KComponentData &cData) + : QApplication((KApplicationPrivate::preqapplicationhack(),KCmdLineArgs::qtArgc()), KCmdLineArgs::qtArgv(), KAPPLICATION_GUI_TYPE), d (new KApplicationPrivate(this, cData)) { d->read_app_startup_id(); setApplicationName(d->componentData.componentName()); setOrganizationDomain(d->componentData.aboutData()->organizationDomain()); installSigpipeHandler(); - d->init(GUIenabled); + d->init(); } #ifdef Q_WS_X11 -KApplication::KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName, - bool GUIenabled) +KApplication::KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName) : QApplication((KApplicationPrivate::preqapplicationhack(),display)), d(new KApplicationPrivate(this, rAppName)) { - Q_UNUSED(GUIenabled); d->read_app_startup_id(); setApplicationName(QLatin1String(rAppName)); installSigpipeHandler(); @@ -354,7 +352,7 @@ void KApplicationPrivate::preqapplicationhack() KGlobal::config(); // initialize qt plugin path (see KComponentDataPrivate::lazyInit) } -void KApplicationPrivate::init(bool GUIenabled) +void KApplicationPrivate::init() { if ((getuid() != geteuid()) || (getgid() != getegid())) @@ -367,39 +365,35 @@ void KApplicationPrivate::init(bool GUIenabled) KApplication::KApp = q; // make sure the clipboard is created before setting the window icon (bug 209263) - if(GUIenabled) - (void) QApplication::clipboard(); + (void) QApplication::clipboard(); parseCommandLine(); - if(GUIenabled) - (void) KClipboardSynchronizer::self(); + (void) KClipboardSynchronizer::self(); QApplication::setDesktopSettingsAware( false ); #ifdef Q_WS_X11 // create all required atoms in _one_ roundtrip to the X server - if ( q->type() == KApplication::GuiClient ) { - const int max = 20; - Atom* atoms[max]; - char* names[max]; - Atom atoms_return[max]; - int n = 0; + const int max = 20; + Atom* atoms[max]; + char* names[max]; + Atom atoms_return[max]; + int n = 0; - atoms[n] = &atom_DesktopWindow; - names[n++] = (char *) "KDE_DESKTOP_WINDOW"; + atoms[n] = &atom_DesktopWindow; + names[n++] = (char *) "KDE_DESKTOP_WINDOW"; - atoms[n] = &atom_NetSupported; - names[n++] = (char *) "_NET_SUPPORTED"; + atoms[n] = &atom_NetSupported; + names[n++] = (char *) "_NET_SUPPORTED"; - atoms[n] = &kde_xdnd_drop; - names[n++] = (char *) "XdndDrop"; + atoms[n] = &kde_xdnd_drop; + names[n++] = (char *) "XdndDrop"; - XInternAtoms( QX11Info::display(), names, n, false, atoms_return ); + XInternAtoms( QX11Info::display(), names, n, false, atoms_return ); - for (int i = 0; i < n; i++ ) - *atoms[i] = atoms_return[i]; - } + for (int i = 0; i < n; i++ ) + *atoms[i] = atoms_return[i]; #endif @@ -448,7 +442,7 @@ void KApplicationPrivate::init(bool GUIenabled) config->isConfigWritable(true); } - if (q->type() == KApplication::GuiClient) + if (q->type() == KAPPLICATION_GUI_TYPE) { #ifdef Q_WS_X11 // this is important since we fork() to launch the help (Matthias) diff --git a/kdeui/kernel/kapplication.h b/kdeui/kernel/kapplication.h index ef8f9c27..8a9b4eaa 100644 --- a/kdeui/kernel/kapplication.h +++ b/kdeui/kernel/kapplication.h @@ -34,6 +34,11 @@ class KConfig; #endif #define kapp KApplication::kApplication() +#ifdef QT_KATIE +#define KAPPLICATION_GUI_TYPE KApplication::Gui +#else +#define KAPPLICATION_GUI_TYPE KApplication::GuiClient +#endif class KApplicationPrivate; @@ -68,7 +73,6 @@ public: * This constructor is the one you should use. * It takes aboutData and command line arguments from KCmdLineArgs. * - * @param GUIenabled Set to false to disable all GUI stuff. * Note that for a non-GUI daemon, you might want to use QCoreApplication * and a KComponentData instance instead. You'll save an unnecessary dependency * to kdeui. The main difference is that you will have to do a number of things yourself: @@ -77,7 +81,7 @@ public: *
  • Call KGlobal::locale(), if using multiple threads.
  • * */ - explicit KApplication(bool GUIenabled = true); + explicit KApplication(); #ifdef Q_WS_X11 /** @@ -114,8 +118,7 @@ public: * * @param GUIenabled Set to false to disable all GUI stuff. */ - KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName, - bool GUIenabled=true); + KApplication(Display *display, int& argc, char** argv, const QByteArray& rAppName); #endif virtual ~KApplication(); @@ -324,7 +327,7 @@ protected: /** * @internal Used by KUniqueApplication */ - KApplication(bool GUIenabled, const KComponentData &cData); + KApplication(const KComponentData &cData); #ifdef Q_WS_X11 /** @@ -346,10 +349,6 @@ private: KApplication(const KApplication&); KApplication& operator=(const KApplication&); -private: - //### KDE4: This is to catch invalid implicit conversions, may want to reconsider - KApplication(bool, bool); - friend class KApplicationPrivate; KApplicationPrivate* const d; diff --git a/kdeui/kernel/kglobalsettings.cpp b/kdeui/kernel/kglobalsettings.cpp index 9e0b5868..299a2328 100644 --- a/kdeui/kernel/kglobalsettings.cpp +++ b/kdeui/kernel/kglobalsettings.cpp @@ -21,15 +21,14 @@ #include #include - #include #include #include #include #include #include - #include +#include #include #include @@ -46,8 +45,6 @@ #include #include #include "qplatformdefs.h" - -// next two needed so we can set their palettes #include #include @@ -968,7 +965,7 @@ void KGlobalSettings::Private::kdisplaySetPalette() return; } - if (qApp->type() == QApplication::GuiClient) { + if (qApp->type() == KAPPLICATION_GUI_TYPE) { QApplication::setPalette( q->createApplicationPalette() ); } emit q->kdisplayPaletteChanged(); @@ -984,7 +981,7 @@ void KGlobalSettings::Private::kdisplaySetFont() return; } - if (qApp->type() == QApplication::GuiClient) { + if (qApp->type() == KAPPLICATION_GUI_TYPE) { KGlobalSettingsData* data = KGlobalSettingsData::self(); QApplication::setFont( data->font(KGlobalSettingsData::GeneralFont) ); @@ -1002,7 +999,7 @@ void KGlobalSettings::Private::kdisplaySetFont() void KGlobalSettings::Private::kdisplaySetStyle() { - if (qApp->type() == QApplication::GuiClient) { + if (qApp->type() == KAPPLICATION_GUI_TYPE) { applyGUIStyle(); // Reread palette from config file. diff --git a/kdeui/kernel/kstyle.cpp b/kdeui/kernel/kstyle.cpp index 3010309c..361c7602 100644 --- a/kdeui/kernel/kstyle.cpp +++ b/kdeui/kernel/kstyle.cpp @@ -2533,8 +2533,10 @@ int KStyle::styleHint (StyleHint hint, const QStyleOption* option, const QWidget return cm.color(option ? option->palette : qApp->palette()).rgba(); } +#ifndef QT_KATIE case SH_DialogButtonLayout: return QDialogButtonBox::KdeLayout; +#endif case SH_ScrollBar_MiddleClickAbsolutePosition: return true; diff --git a/kdeui/kernel/kuniqueapplication.cpp b/kdeui/kernel/kuniqueapplication.cpp index c02af5e4..85732257 100644 --- a/kdeui/kernel/kuniqueapplication.cpp +++ b/kdeui/kernel/kuniqueapplication.cpp @@ -273,8 +273,8 @@ KUniqueApplication::start(StartFlags flags) } -KUniqueApplication::KUniqueApplication(bool GUIenabled, bool configUnique) - : KApplication( GUIenabled, Private::initHack( configUnique )), +KUniqueApplication::KUniqueApplication(bool configUnique) + : KApplication( Private::initHack( configUnique )), d(new Private(this)) { d->processingRequest = false; diff --git a/kdeui/kernel/kuniqueapplication.h b/kdeui/kernel/kuniqueapplication.h index 104d6814..0526ccf0 100644 --- a/kdeui/kernel/kuniqueapplication.h +++ b/kdeui/kernel/kuniqueapplication.h @@ -59,14 +59,11 @@ public: /** * Constructor. Takes command line arguments from KCmdLineArgs * - * @param GUIenabled Set to false to disable all GUI stuff. This implies - * no styles either. * @param configUnique If true, the uniqueness of the application will * depend on the value of the "MultipleInstances" * key in the "KDE" group of the application config file. */ - explicit KUniqueApplication( bool GUIenabled=true, - bool configUnique=false); + explicit KUniqueApplication( bool configUnique=false); #ifdef Q_WS_X11 /** diff --git a/kdeui/widgets/kmenu.cpp b/kdeui/widgets/kmenu.cpp index 7ed59be4..bf73ec54 100644 --- a/kdeui/widgets/kmenu.cpp +++ b/kdeui/widgets/kmenu.cpp @@ -228,7 +228,6 @@ void KMenu::keyPressEvent(QKeyEvent* e) return; } - QAction* a = 0L; bool firstpass = true; QString keyString = e->text(); @@ -281,11 +280,6 @@ void KMenu::keyPressEvent(QKeyEvent* e) // clear active item setActiveAction(0L); - - } else { - // the key sequence is not a null string - // therefore the lastHitAction is valid - a = d->lastHitAction; } } else if (key == Qt::Key_Backspace && menuAction()) { diff --git a/kio/kio/kmessageboxwrapper.h b/kio/kio/kmessageboxwrapper.h index 8325fe3b..5af2ff61 100644 --- a/kio/kio/kmessageboxwrapper.h +++ b/kio/kio/kmessageboxwrapper.h @@ -19,7 +19,7 @@ #ifndef KMESSAGEBOXWRAPPER_H #define KMESSAGEBOXWRAPPER_H -#include +#include #include #include @@ -35,7 +35,7 @@ public: const QString &text, const QString &caption = QString()) { - if (qApp && qApp->type() == QApplication::GuiClient) { + if (qApp && qApp->type() == KAPPLICATION_GUI_TYPE) { KMessageBox::error( parent, text, caption ); } else kWarning() << text; @@ -45,7 +45,7 @@ public: const QString &text, const QString &caption = QString()) { - if (qApp && qApp->type() == QApplication::GuiClient) { + if (qApp && qApp->type() == KAPPLICATION_GUI_TYPE) { KMessageBox::sorry( parent, text, caption ); } else kWarning() << text; diff --git a/kio/misc/kmailservice.cpp b/kio/misc/kmailservice.cpp index 8c49c769..4ad1c87b 100644 --- a/kio/misc/kmailservice.cpp +++ b/kio/misc/kmailservice.cpp @@ -16,12 +16,13 @@ Boston, MA 02110-1301, USA. */ -#include #include #include #include #include +#include + int main( int argc, char **argv ) { KCmdLineOptions options; @@ -30,14 +31,14 @@ int main( int argc, char **argv ) KCmdLineArgs::init( argc, argv, "kmailservice", "kdelibs4", ki18n("KMailService"), "unknown", ki18n("Mail service") ); KCmdLineArgs::addCmdLineOptions( options ); - KApplication a( false ); + QCoreApplication app(argc, argv); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() != 1 ) return 1; - KToolInvocation::invokeMailer(KUrl(args->arg(0)), a.startupId(), true); + KToolInvocation::invokeMailer(KUrl(args->arg(0)), QByteArray(), true); return 0; } diff --git a/kross/console/main.cpp b/kross/console/main.cpp index 64e8ad52..c18e3437 100644 --- a/kross/console/main.cpp +++ b/kross/console/main.cpp @@ -117,7 +117,7 @@ int main(int argc, char **argv) } // Create KApplication instance. - app = new KApplication( /* GUIenabled */ true ); + app = new KApplication(); // Each argument is a scriptfile to open for(int i = 0; i < args->count(); i++) {