CLI+GTK: show progress when cleaning database

This commit is contained in:
zvon 2020-04-13 19:58:57 +02:00
parent d6899a505e
commit 2206f28124
9 changed files with 40 additions and 7 deletions

View File

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

View File

@ -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();

View File

@ -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;
} );

View File

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

View File

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

View File

@ -126,3 +126,4 @@
#define INVALID_LOCALE 0x9080
#define MEM_ALLOC_FAILED 0x9081
#define DATABASE_MENU 0x9082
#define CLEANING_DB 0x9083

View File

@ -370,3 +370,6 @@ msgstr "neplatné locale"
msgid "memory allocation failed"
msgstr "alokace paměti selhala"
msgid "Cleaning database"
msgstr "Čistím databázi"

View File

@ -370,3 +370,6 @@ msgstr "invalid locale"
msgid "memory allocation failed"
msgstr "memory allocation failed"
msgid "Cleaning database"
msgstr "Cleaning database"

Binary file not shown.