MainWindow: support UI changes of DatabaseWindow, use new functions

This commit is contained in:
zvon 2020-02-12 11:45:47 +01:00
parent adeed21976
commit 1f1e168ab4
2 changed files with 19 additions and 59 deletions

View File

@ -5,11 +5,13 @@
#include <gtkmm/messagedialog.h> #include <gtkmm/messagedialog.h>
#include <gtkmm/scrolledwindow.h> #include <gtkmm/scrolledwindow.h>
#include <gtkmm/textview.h> #include <gtkmm/textview.h>
#include <iostream>
#include <thread> #include <thread>
#include "databasewindow.hpp" #include "databasewindow.hpp"
#include "filesystem.hpp" #include "filesystem.hpp"
#include "functions.hpp" #include "functions.hpp"
#include "gtkfunctions.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "progresswindow.hpp" #include "progresswindow.hpp"
#include "tv_rename.hpp" #include "tv_rename.hpp"
@ -59,51 +61,11 @@ void MainWindow::patternHelp() {
} }
void MainWindow::process() { 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 = language_code =
( *m_combo_language->get_active() )[m_columns_language.m_col_code]; ( *m_combo_language->get_active() )[m_columns_language.m_col_code];
// fill up m_combo_possible with possible tv shows searchShow( m_entry_show, m_combo_possible, m_columns_show.m_col_show,
auto possible_shows = m_columns_show.m_col_id, language_code, this );
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;
}
} }
void MainWindow::getNames() { void MainWindow::getNames() {
@ -161,6 +123,7 @@ void renameFiles( const std::vector<
void MainWindow::finishedSelection() { void MainWindow::finishedSelection() {
// remove created SeasonWindow and delete it from memory // remove created SeasonWindow and delete it from memory
app->remove_window( *sw ); app->remove_window( *sw );
sw.reset();
auto iter = m_combo_possible->get_active(); auto iter = m_combo_possible->get_active();
@ -245,19 +208,7 @@ void MainWindow::finishedSelection() {
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
auto children = get_children(); auto children = get_children();
size_t max = children.size(); freeChildren( children );
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];
}
} }
MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr ) MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
@ -446,12 +397,13 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
// set default pattern // set default pattern
m_entry_pattern->set_text( default_pattern ); m_entry_pattern->set_text( default_pattern );
language_map = getLangs();
// put languages in combo box // put languages in combo box
{ {
auto model = Gtk::ListStore::create( m_columns_language ); auto model = Gtk::ListStore::create( m_columns_language );
m_combo_language->set_model( model ); m_combo_language->set_model( model );
for ( const auto &x : getLangs() ) { for ( const auto &x : language_map ) {
auto row = *( model->append() ); auto row = *( model->append() );
row[m_columns_language.m_col_code] = x.first; row[m_columns_language.m_col_code] = x.first;
row[m_columns_language.m_col_language] = x.second; 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 // set column to be shown in comboboxes
m_combo_language->pack_start( m_columns_language.m_col_language ); m_combo_language->pack_start( m_columns_language.m_col_language );
m_combo_possible->pack_start( m_columns_show.m_col_show ); m_combo_possible->pack_start( m_columns_show.m_col_show );
@ -569,7 +527,8 @@ void MainWindow::dbAdd() {
} }
void MainWindow::dbManage() { 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 ); app->add_window( *dbWindow );
auto app_ptr = app; auto app_ptr = app;

View File

@ -69,8 +69,8 @@ protected:
add( m_col_id ); add( m_col_id );
add( m_col_show ); add( m_col_show );
} }
Gtk::TreeModelColumn< Glib::ustring > m_col_id; Gtk::TreeModelColumn< std::string > m_col_id;
Gtk::TreeModelColumn< Glib::ustring > m_col_show; Gtk::TreeModelColumn< std::string > m_col_show;
}; };
LanguageColumns m_columns_language; LanguageColumns m_columns_language;
@ -84,6 +84,7 @@ protected:
std::string path; std::string path;
std::string language_code; std::string language_code;
std::string default_pattern; std::string default_pattern;
std::map< string, string > language_map;
}; };
#endif // GTKMM_MAIN_WINDOW #endif // GTKMM_MAIN_WINDOW