From b989a674a487aaed20773ff0555b1edbd6eea7c5 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Sat, 20 Feb 2021 21:44:07 -0800 Subject: [PATCH] application: Add splash during initialization Since initialization on first startup or during a database schema update can take several seconds, show a splash screen. In the initial implementation, this is just a small Clementine logo. The benefit of instantiating the splash in the Application class rather than in main is that it could eventually show status messages during startup. However, this implementation does not use the QSplashScreen::finish mechanism that would synchronize the hiding of the splash screen with the showing of the main window. --- src/CMakeLists.txt | 1 + src/core/application.cpp | 12 ++++++++++++ src/core/application.h | 2 ++ src/ui/splash.cpp | 22 ++++++++++++++++++++++ src/ui/splash.h | 28 ++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 src/ui/splash.cpp create mode 100644 src/ui/splash.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6aa3b349f..5afb5b992 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -361,6 +361,7 @@ set(SOURCES ui/screensaver.cpp ui/settingsdialog.cpp ui/settingspage.cpp + ui/splash.cpp ui/standarditemiconloader.cpp ui/streamdetailsdialog.cpp ui/systemtrayicon.cpp diff --git a/src/core/application.cpp b/src/core/application.cpp index b63d60b4c..fcc1ba0c7 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -54,6 +54,7 @@ #include "networkremote/networkremotehelper.h" #include "playlist/playlistbackend.h" #include "playlist/playlistmanager.h" +#include "ui/splash.h" #ifdef HAVE_LIBLASTFM #include "covers/lastfmcoverprovider.h" @@ -203,6 +204,12 @@ class ApplicationImpl { Application::Application(QObject* parent) : QObject(parent), p_(new ApplicationImpl(this)) { setObjectName("Clementine Application"); + + // Show the splash + splash_.reset(new Splash()); + splash_->show(); + QCoreApplication::processEvents(); + // This must be before library_->Init(); // In the constructor the helper waits for the signal // PlaylistManagerInitialized @@ -254,6 +261,11 @@ void Application::AddError(const QString& message) { emit ErrorAdded(message); } void Application::Starting() { qLog(Debug) << "Application starting"; + + // Hide the splash + if (splash_) { + splash_.reset(); + } } QString Application::language_without_region() const { diff --git a/src/core/application.h b/src/core/application.h index 079c43ae2..913404938 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -55,6 +55,7 @@ class PodcastDeleter; class PodcastDownloader; class PodcastUpdater; class Scrobbler; +class Splash; class TagReaderClient; class TaskManager; @@ -133,6 +134,7 @@ class Application : public QObject { private: QString language_name_; std::unique_ptr p_; + std::unique_ptr splash_; QList threads_; }; diff --git a/src/ui/splash.cpp b/src/ui/splash.cpp new file mode 100644 index 000000000..9759b8cc7 --- /dev/null +++ b/src/ui/splash.cpp @@ -0,0 +1,22 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "splash.h" + +#include + +Splash::Splash() : QSplashScreen(QPixmap(":/icon.png")) {} diff --git a/src/ui/splash.h b/src/ui/splash.h new file mode 100644 index 000000000..689293cfe --- /dev/null +++ b/src/ui/splash.h @@ -0,0 +1,28 @@ +/* This file is part of Clementine. + Copyright 2021, Jim Broadus + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SPLASH_H +#define SPLASH_H + +#include + +class Splash : public QSplashScreen { + public: + Splash(); +}; + +#endif // SPLASH_H