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.
This commit is contained in:
Jim Broadus 2021-02-20 21:44:07 -08:00 committed by John Maguire
parent 59864bf1b6
commit b989a674a4
5 changed files with 65 additions and 0 deletions

View File

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

View File

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

View File

@ -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<ApplicationImpl> p_;
std::unique_ptr<Splash> splash_;
QList<QThread*> threads_;
};

22
src/ui/splash.cpp Normal file
View File

@ -0,0 +1,22 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#include "splash.h"
#include <QPixmap>
Splash::Splash() : QSplashScreen(QPixmap(":/icon.png")) {}

28
src/ui/splash.h Normal file
View File

@ -0,0 +1,28 @@
/* This file is part of Clementine.
Copyright 2021, Jim Broadus <jbroadus@gmail.com>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef SPLASH_H
#define SPLASH_H
#include <QSplashScreen>
class Splash : public QSplashScreen {
public:
Splash();
};
#endif // SPLASH_H