generic: KApplication cleanup

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-05-04 23:52:26 +00:00
parent e189969fd1
commit c10a61a5c7
10 changed files with 51 additions and 67 deletions

View file

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

View file

@ -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:
* <li>Call KGlobal::locale(), if using multiple threads.</li>
* </ul>
*/
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;

View file

@ -21,15 +21,14 @@
#include <config.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kprotocolinfo.h>
#include <kcolorscheme.h>
#include <kstyle.h>
#include <kapplication.h>
#include <QtGui/QColor>
#include <QtGui/QCursor>
@ -46,8 +45,6 @@
#include <QtGui/QStyleFactory>
#include <QDesktopServices>
#include "qplatformdefs.h"
// next two needed so we can set their palettes
#include <QtGui/QToolTip>
#include <QtGui/QWhatsThis>
@ -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.

View file

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

View file

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

View file

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

View file

@ -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()) {

View file

@ -19,7 +19,7 @@
#ifndef KMESSAGEBOXWRAPPER_H
#define KMESSAGEBOXWRAPPER_H
#include <QtGui/qapplication.h>
#include <kapplication.h>
#include <kmessagebox.h>
#include <kdebug.h>
@ -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;

View file

@ -16,12 +16,13 @@
Boston, MA 02110-1301, USA.
*/
#include <kapplication.h>
#include <ktoolinvocation.h>
#include <klocale.h>
#include <kcmdlineargs.h>
#include <kurl.h>
#include <QCoreApplication>
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;
}

View file

@ -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++) {