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:
@@ -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();
|
||||
|
@@ -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:
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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 );
|
||||
}
|
||||
|
Reference in New Issue
Block a user