diff --git a/functions.cpp b/functions.cpp index 297580e..f6eac27 100644 --- a/functions.cpp +++ b/functions.cpp @@ -760,7 +760,11 @@ void changeDBPattern( const string &pattern ) { TEXT( "' WHERE TVID == 'pattern';" ) ); } +#ifndef GUI void cleanDB() { +#else +void cleanDB( void *progress_ptr ) { +#endif if ( !FSLib::exists( getDBName() ) ) return; std::vector< std::unordered_map< string, string > > shows; @@ -775,7 +779,19 @@ void cleanDB() { " != 'pattern';" ), shows ); +#ifndef GUI + ProgressBar p; +#else // GUI + ProgressBar p( progress_ptr ); +#endif // GUI + p.print( _( CLEANING_DB ) ); + p.print( 0 ); + int percent = 0; + int increment = 100 / shows.size(); + for ( auto &show : shows ) { + p.print( percent ); + percent += increment; bool dir_exists = FSLib::exists( show[TEXT( "PATH" )] ); std::unordered_set< string > episodes; db.exec( TEXT( "SELECT PATH FROM EPISODES WHERE SHOWID == " ) + @@ -796,6 +812,8 @@ void cleanDB() { show[TEXT( "ID" )] + TEXT( ";" ) ); } } + + p.print( 100 ); } void removeFromDB( const string &path ) { diff --git a/functions.hpp b/functions.hpp index 437f785..0f070e5 100644 --- a/functions.hpp +++ b/functions.hpp @@ -63,15 +63,13 @@ void removeFromDB( const string &path ); void changeDBPattern( const string &pattern ); #ifndef GUI void refreshDB( bool linux ); +void updateDB( bool linux ); +void cleanDB(); #else void refreshDB( bool linux, void *progress_ptr ); -#endif -#ifndef GUI -void updateDB( bool linux ); -#else void updateDB( bool linux, void *progress_ptr ); +void cleanDB( void *progress_ptr ); #endif -void cleanDB(); #ifdef GUI std::vector< std::unordered_map< string, string > > dbGetShows(); diff --git a/gtk/databasewindow.cpp b/gtk/databasewindow.cpp index db09ade..0a610e6 100644 --- a/gtk/databasewindow.cpp +++ b/gtk/databasewindow.cpp @@ -216,7 +216,6 @@ void DatabaseWindow::save() { auto *app_ptr = app.get(); pw->signal_hide().connect( [pw, app_ptr]() { - cleanDB(); app_ptr->remove_window( *pw ); delete pw; } ); diff --git a/gtk/mainwindow.cpp b/gtk/mainwindow.cpp index 259e154..f1f60eb 100644 --- a/gtk/mainwindow.cpp +++ b/gtk/mainwindow.cpp @@ -463,7 +463,17 @@ void MainWindow::dbUpdate() { } void MainWindow::dbClean() { - cleanDB(); + auto *pw = new ProgressWindow; + app->add_window( *pw ); + auto app_ptr = app; + + pw->signal_hide().connect( [pw, app_ptr]() { + app_ptr->remove_window( *pw ); + delete pw; + } ); + pw->show(); + std::thread t( cleanDB, pw ); + t.detach(); } void MainWindow::dbRefresh() { diff --git a/resources_linux.h b/resources_linux.h index a270101..461ba79 100644 --- a/resources_linux.h +++ b/resources_linux.h @@ -82,6 +82,7 @@ #define RENAMING "Renaming" #define ADDING_TO_DB "Adding to database" #define REFRESHING_DB "Refreshing database" +#define CLEANING_DB "Cleaning database" #define REFRESHING "Refreshing" #define UPDATING_IN_DB "Updating %s in database" #define UPDATING_DB "Updating database" diff --git a/resources_windows.h b/resources_windows.h index 721a167..7309c1f 100644 --- a/resources_windows.h +++ b/resources_windows.h @@ -126,3 +126,4 @@ #define INVALID_LOCALE 0x9080 #define MEM_ALLOC_FAILED 0x9081 #define DATABASE_MENU 0x9082 +#define CLEANING_DB 0x9083 diff --git a/translations/cs.po b/translations/cs.po index c79789c..0a8ba7e 100644 --- a/translations/cs.po +++ b/translations/cs.po @@ -370,3 +370,6 @@ msgstr "neplatné locale" msgid "memory allocation failed" msgstr "alokace paměti selhala" + +msgid "Cleaning database" +msgstr "Čistím databázi" diff --git a/translations/en_US.po b/translations/en_US.po index 81c2fe8..f07d598 100644 --- a/translations/en_US.po +++ b/translations/en_US.po @@ -370,3 +370,6 @@ msgstr "invalid locale" msgid "memory allocation failed" msgstr "memory allocation failed" + +msgid "Cleaning database" +msgstr "Cleaning database" diff --git a/tv_rename_stringtable.rc b/tv_rename_stringtable.rc index bcf6f20..d5d2274 100644 Binary files a/tv_rename_stringtable.rc and b/tv_rename_stringtable.rc differ