Move splash screen to header

This commit is contained in:
Weixuan XIAO 2019-11-19 22:42:30 +01:00 committed by Nicolas Fella
parent ed5797eaec
commit 71ec233f88
2 changed files with 16 additions and 16 deletions

View file

@ -19,6 +19,7 @@
*/ */
#include <QProcess> #include <QProcess>
#include <QSplashScreen>
#ifdef QSYSTRAY #ifdef QSYSTRAY
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
@ -44,4 +45,9 @@ public:
#else #else
void systrayIconHook(KStatusNotifierItem &systray); void systrayIconHook(KStatusNotifierItem &systray);
#endif #endif
private:
#ifdef Q_OS_MAC
QSplashScreen *m_splashScreen;
#endif
}; };

View file

@ -23,7 +23,6 @@
#include <QIcon> #include <QIcon>
#include <QMessageBox> #include <QMessageBox>
#include <QStandardPaths> #include <QStandardPaths>
#include <QSplashScreen>
#include <QThread> #include <QThread>
#include <QDebug> #include <QDebug>
@ -33,26 +32,23 @@
#include "indicatorhelper.h" #include "indicatorhelper.h"
static QSplashScreen *splashScreen = nullptr;
IndicatorHelper::IndicatorHelper() IndicatorHelper::IndicatorHelper()
{ {
QIcon kdeconnectIcon = QIcon::fromTheme(QStringLiteral("kdeconnect")); QIcon kdeconnectIcon = QIcon::fromTheme(QStringLiteral("kdeconnect"));
QPixmap splashPixmap(kdeconnectIcon.pixmap(256, 256)); QPixmap splashPixmap(kdeconnectIcon.pixmap(256, 256));
if (::splashScreen == nullptr) { m_splashScreen = new QSplashScreen(splashPixmap);
::splashScreen = new QSplashScreen(splashPixmap);
}
::splashScreen->showMessage(i18n("Launching") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); m_splashScreen->showMessage(i18n("Launching") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
::splashScreen->show(); m_splashScreen->show();
} }
IndicatorHelper::~IndicatorHelper() IndicatorHelper::~IndicatorHelper()
{ {
if (::splashScreen) { if (m_splashScreen != nullptr) {
delete ::splashScreen; delete m_splashScreen;
::splashScreen = nullptr; m_splashScreen = nullptr;
} }
} }
@ -60,9 +56,7 @@ void IndicatorHelper::preInit() {}
void IndicatorHelper::postInit() void IndicatorHelper::postInit()
{ {
if (::splashScreen) { m_splashScreen->finish(nullptr);
::splashScreen->finish(nullptr);
}
} }
void IndicatorHelper::iconPathHook() void IndicatorHelper::iconPathHook()
@ -81,7 +75,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd)
DBusHelper::macosUnsetLaunchctlEnv(); DBusHelper::macosUnsetLaunchctlEnv();
// Start kdeconnectd // Start kdeconnectd
::splashScreen->showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); m_splashScreen->showMessage(i18n("Launching daemon") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"))) { if (QFile::exists(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"))) {
kdeconnectd.startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd")); kdeconnectd.startDetached(QCoreApplication::applicationDirPath() + QStringLiteral("/kdeconnectd"));
} else if (QFile::exists(QString::fromLatin1(qgetenv("craftRoot")) + QStringLiteral("/../lib/libexec/kdeconnectd"))) { } else if (QFile::exists(QString::fromLatin1(qgetenv("craftRoot")) + QStringLiteral("/../lib/libexec/kdeconnectd"))) {
@ -96,7 +90,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd)
// Wait for dbus daemon env // Wait for dbus daemon env
QProcess getLaunchdDBusEnv; QProcess getLaunchdDBusEnv;
::splashScreen->showMessage(i18n("Waiting D-Bus") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); m_splashScreen->showMessage(i18n("Waiting D-Bus") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
int retry = 0; int retry = 0;
do { do {
getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl")); getLaunchdDBusEnv.setProgram(QStringLiteral("launchctl"));
@ -127,7 +121,7 @@ int IndicatorHelper::daemonHook(QProcess &kdeconnectd)
} }
} while(true); } while(true);
::splashScreen->showMessage(i18n("Loading modules") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white); m_splashScreen->showMessage(i18n("Loading modules") + QStringLiteral("\n"), Qt::AlignHCenter | Qt::AlignBottom, Qt::white);
return 0; return 0;
} }