1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 11:50:37 +02:00

Proper splash screen support for database schema upgrade.

This commit is contained in:
Teo Mrnjavac
2014-01-15 17:12:59 +01:00
parent fbed11a93d
commit 2d5ae48524
5 changed files with 54 additions and 10 deletions

View File

@@ -3,6 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -54,6 +55,14 @@ Tomahawk::DatabaseImpl::DatabaseImpl( const QString& dbname )
QTime t;
t.start();
// Signals for splash screen must be connected here
connect( this, SIGNAL( schemaUpdateStarted() ),
qApp, SLOT( onSchemaUpdateStarted() ) );
connect( this, SIGNAL( schemaUpdateStatus( QString ) ),
qApp, SLOT( onSchemaUpdateStatus( QString ) ) );
connect( this, SIGNAL( schemaUpdateDone() ),
qApp, SLOT( onSchemaUpdateDone() ) );
bool schemaUpdated = openDatabase( dbname );
tDebug( LOGVERBOSE ) << "Opened database:" << t.elapsed();
@@ -239,8 +248,9 @@ Tomahawk::DatabaseImpl::updateSchema( int oldVersion )
QString sql = QString::fromUtf8( script.readAll() ).trimmed();
QStringList statements = sql.split( ";", QString::SkipEmptyParts );
foreach ( const QString& sql, statements )
for ( int i = 0; i < statements.count(); ++i )
{
QString sql = statements.at( i );
QString clean = cleanSql( sql ).trimmed();
if ( clean.isEmpty() )
continue;
@@ -248,6 +258,10 @@ Tomahawk::DatabaseImpl::updateSchema( int oldVersion )
tLog() << "Executing upgrade statement:" << clean;
TomahawkSqlQuery q = newquery();
q.exec( clean );
//Report to splash screen
emit schemaUpdateStatus( QString( "%1/%2" ).arg( QString::number( i + 1 ) )
.arg( QString::number( statements.count() ) ) );
}
}
m_db.commit();

View File

@@ -2,6 +2,7 @@
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -87,6 +88,7 @@ public:
signals:
void indexReady();
void schemaUpdateStarted();
void schemaUpdateStatus( const QString& message );
void schemaUpdateDone();
private:

View File

@@ -3,7 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2013-2014, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -184,7 +184,10 @@ TomahawkApp::init()
setQuitOnLastWindowClosed( false );
if ( arguments().contains( "--splash" ) )
startSplashWidget( "Splash screen test" );
{
startSplashWidget( "Splash screen test\n" );
updateSplashWidgetMessage( "Splash screen test\n2/7" );
}
QFont f = font();
#ifdef Q_OS_MAC
@@ -477,11 +480,7 @@ TomahawkApp::initDatabase()
tDebug( LOGEXTRA ) << "Using database:" << dbpath;
m_database = QPointer<Tomahawk::Database>( new Tomahawk::Database( dbpath, this ) );
connect( m_database->impl(), SIGNAL( schemaUpdateStarted() ),
this, SLOT( startSplashWidget() ) );
connect( m_database->impl(), SIGNAL( schemaUpdateDone() ),
this, SLOT( killSplashWidget() ) );
// this also connects dbImpl schema update signals
Pipeline::instance()->databaseReady();
}
@@ -693,6 +692,27 @@ TomahawkApp::onInfoSystemReady()
}
void
TomahawkApp::onSchemaUpdateStarted()
{
startSplashWidget( tr( "Updating database\n") );
}
void
TomahawkApp::onSchemaUpdateStatus( const QString& status )
{
updateSplashWidgetMessage( tr("Updating database\n%1" ).arg( status ) );
}
void
TomahawkApp::onSchemaUpdateDone()
{
killSplashWidget();
}
void
TomahawkApp::startSplashWidget( const QString& initialMessage )
{
@@ -706,7 +726,10 @@ TomahawkApp::startSplashWidget( const QString& initialMessage )
void
TomahawkApp::updateSplashWidgetMessage( const QString& message )
{
if ( m_splashWidget )
{
m_splashWidget->showMessage( message );
}
}

View File

@@ -3,6 +3,7 @@
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -115,6 +116,10 @@ private slots:
void spotifyApiCheckFinished();
void onInfoSystemReady();
void onSchemaUpdateStarted();
void onSchemaUpdateStatus( const QString& status );
void onSchemaUpdateDone();
void startSplashWidget( const QString& initialMessage = QString() );
void updateSplashWidgetMessage( const QString& message );
void killSplashWidget();

View File

@@ -43,5 +43,5 @@ SplashWidget::SplashWidget()
void
SplashWidget::showMessage( const QString& message )
{
QSplashScreen::showMessage( message + "\n\n", Qt::AlignBottom | Qt::AlignHCenter );
QSplashScreen::showMessage( message + "\n", Qt::AlignBottom | Qt::AlignHCenter );
}