diff --git a/mainwindow.cpp b/mainwindow.cpp index 1ccb7ea..e597671 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,11 +5,13 @@ #include #include #include +#include #include #include "databasewindow.hpp" #include "filesystem.hpp" #include "functions.hpp" +#include "gtkfunctions.hpp" #include "mainwindow.hpp" #include "progresswindow.hpp" #include "tv_rename.hpp" @@ -59,51 +61,11 @@ void MainWindow::patternHelp() { } void MainWindow::process() { - // check required field is filled out - if ( m_entry_show->get_text().empty() ) { - Gtk::MessageDialog dialog( *this, "Show field is empty" ); - dialog.run(); - return; - } - - // language code language_code = ( *m_combo_language->get_active() )[m_columns_language.m_col_code]; - // fill up m_combo_possible with possible tv shows - auto possible_shows = - searchShow( std::string( m_entry_show->get_text() ), language_code ); - - // if no possible shows were found, tell the user - if ( possible_shows.size() == 0 ) { - Gtk::MessageDialog dialog( *this, - "No results found for given show name" ); - dialog.run(); - return; - } - - // show widgets - m_label_possible->show(); - m_button_rename->show(); - m_button_db_add->show(); - m_combo_possible->show(); - - // fill up combo box with results from thetvdb - auto model = Gtk::ListStore::create( m_columns_show ); - - m_combo_possible->set_model( model ); - - auto row = *( model->append() ); - - row[m_columns_show.m_col_show] = possible_shows[0].first; - row[m_columns_show.m_col_id] = possible_shows[0].second; - m_combo_possible->set_active( row ); - - for ( size_t i = 1; i < possible_shows.size(); i++ ) { - auto row = *( model->append() ); - row[m_columns_show.m_col_show] = possible_shows[i].first; - row[m_columns_show.m_col_id] = possible_shows[i].second; - } + searchShow( m_entry_show, m_combo_possible, m_columns_show.m_col_show, + m_columns_show.m_col_id, language_code, this ); } void MainWindow::getNames() { @@ -161,6 +123,7 @@ void renameFiles( const std::vector< void MainWindow::finishedSelection() { // remove created SeasonWindow and delete it from memory app->remove_window( *sw ); + sw.reset(); auto iter = m_combo_possible->get_active(); @@ -245,19 +208,7 @@ void MainWindow::finishedSelection() { MainWindow::~MainWindow() { auto children = get_children(); - size_t max = children.size(); - size_t index{}; - while ( index < max ) { - if ( auto *p = dynamic_cast< Gtk::Container * >( children[index] ) ) { - auto temp = p->get_children(); - children.insert( children.end(), temp.begin(), temp.end() ); - max = children.size(); - } - index++; - } - for ( int i = max - 1; i >= 0; i-- ) { - delete children[i]; - } + freeChildren( children ); } MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr ) @@ -446,12 +397,13 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr ) // set default pattern m_entry_pattern->set_text( default_pattern ); + language_map = getLangs(); // put languages in combo box { auto model = Gtk::ListStore::create( m_columns_language ); m_combo_language->set_model( model ); - for ( const auto &x : getLangs() ) { + for ( const auto &x : language_map ) { auto row = *( model->append() ); row[m_columns_language.m_col_code] = x.first; row[m_columns_language.m_col_language] = x.second; @@ -460,6 +412,12 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr ) } } + { + auto model = Gtk::ListStore::create( m_columns_show ); + + m_combo_possible->set_model( model ); + } + // set column to be shown in comboboxes m_combo_language->pack_start( m_columns_language.m_col_language ); m_combo_possible->pack_start( m_columns_show.m_col_show ); @@ -569,7 +527,8 @@ void MainWindow::dbAdd() { } void MainWindow::dbManage() { - auto *dbWindow = new DatabaseWindow( !m_check_linux->get_active(), app ); + auto *dbWindow = + new DatabaseWindow( !m_check_linux->get_active(), language_map, app ); app->add_window( *dbWindow ); auto app_ptr = app; diff --git a/mainwindow.hpp b/mainwindow.hpp index 11b4175..2930b28 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -69,8 +69,8 @@ protected: add( m_col_id ); add( m_col_show ); } - Gtk::TreeModelColumn< Glib::ustring > m_col_id; - Gtk::TreeModelColumn< Glib::ustring > m_col_show; + Gtk::TreeModelColumn< std::string > m_col_id; + Gtk::TreeModelColumn< std::string > m_col_show; }; LanguageColumns m_columns_language; @@ -84,6 +84,7 @@ protected: std::string path; std::string language_code; std::string default_pattern; + std::map< string, string > language_map; }; #endif // GTKMM_MAIN_WINDOW