diff --git a/ext/libclementine-common/core/closure.cpp b/ext/libclementine-common/core/closure.cpp index 4e1e26566..4ae3e25e8 100644 --- a/ext/libclementine-common/core/closure.cpp +++ b/ext/libclementine-common/core/closure.cpp @@ -18,6 +18,7 @@ #include "closure.h" #include "core/logging.h" +#include "core/timeconstants.h" namespace _detail { @@ -89,3 +90,12 @@ _detail::Closure* NewClosure( QObject* receiver, const char* slot) { return new _detail::Closure(sender, signal, receiver, slot); } + +void DoAfter(QObject* receiver, const char* slot, int msec) { + QTimer::singleShot(msec, receiver, slot); +} + +void DoInAMinuteOrSo(QObject* receiver, const char* slot) { + int msec = (60 + (qrand() % 60)) * kMsecPerSec; + DoAfter(receiver, slot, msec); +} diff --git a/ext/libclementine-common/core/closure.h b/ext/libclementine-common/core/closure.h index 1746ef83d..5c897ec3f 100644 --- a/ext/libclementine-common/core/closure.h +++ b/ext/libclementine-common/core/closure.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -224,4 +225,7 @@ _detail::Closure* NewClosure( C_ARG(T0, val0), C_ARG(T1, val1)); } +void DoAfter(QObject* receiver, const char* slot, int msec); +void DoInAMinuteOrSo(QObject* receiver, const char* slot); + #endif // CLOSURE_H diff --git a/src/core/application.cpp b/src/core/application.cpp index 53f9298ae..d1edd401c 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -90,7 +90,7 @@ Application::Application(QObject* parent) library_->Init(); library_->StartThreads(); - QMetaObject::invokeMethod(database_, "DoBackup", Qt::QueuedConnection); + DoInAMinuteOrSo(database_, SLOT(DoBackup())); } Application::~Application() { diff --git a/src/core/database.cpp b/src/core/database.cpp index 39e479519..1f09db065 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -685,6 +685,7 @@ bool Database::CheckErrors(const QSqlQuery& query) { } bool Database::IntegrityCheck(QSqlDatabase db) { + qLog(Debug) << "Starting database integrity check"; int task_id = app_->task_manager()->StartTask(tr("Integrity check")); bool ok = false; @@ -743,6 +744,7 @@ bool Database::OpenDatabase(const QString& filename, sqlite3** connection) const } void Database::BackupFile(const QString& filename) { + qLog(Debug) << "Starting database backup"; QString dest_filename = QString("%1.bak").arg(filename); const int task_id = app_->task_manager()->StartTask(tr("Backing up database")); diff --git a/src/core/database.h b/src/core/database.h index 44e19a2f1..b7c8e9431 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -64,7 +64,7 @@ class Database : public QObject { signals: void Error(const QString& message); - private slots: + public slots: void DoBackup(); private: diff --git a/src/main.cpp b/src/main.cpp index 006683b06..5c569203d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -303,6 +303,12 @@ int main(int argc, char *argv[]) { logging::SetLevels(options.log_levels()); g_log_set_default_handler(reinterpret_cast(&logging::GLog), NULL); + // Seed the random number generator + time_t t = time(NULL); + srand(time(NULL)); + qDebug() << "Seeding with:" << t; + qsrand(t); + IncreaseFDLimit(); QtSingleApplication a(argc, argv); @@ -387,9 +393,6 @@ int main(int argc, char *argv[]) { QNetworkProxyFactory::setApplicationProxyFactory( NetworkProxyFactory::Instance()); - // Seed the random number generator - srand(time(NULL)); - // Initialize the repository of cover providers. Last.fm registers itself // when its service is created. app.cover_providers()->AddProvider(new AmazonCoverProvider);