Mainwindow: formatting

This commit is contained in:
zvon 2020-01-17 14:14:24 +01:00
parent d3a4ee8b0c
commit 100834c01f
2 changed files with 90 additions and 88 deletions

View File

@ -8,10 +8,10 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include "databasewindow.hpp"
#include "filesystem.hpp" #include "filesystem.hpp"
#include "functions.hpp" #include "functions.hpp"
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "databasewindow.hpp"
#include "progresswindow.hpp" #include "progresswindow.hpp"
#include "tv_rename.hpp" #include "tv_rename.hpp"
@ -76,8 +76,8 @@ void MainWindow::process() {
( *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 // fill up m_combo_possible with possible tv shows
auto possible_shows = searchShow( auto possible_shows =
std::string( m_entry_show->get_text() ), language_code ); searchShow( std::string( m_entry_show->get_text() ), language_code );
// if no possible shows were found, tell the user // if no possible shows were found, tell the user
if ( possible_shows.size() == 0 ) { if ( possible_shows.size() == 0 ) {
@ -154,15 +154,16 @@ void MainWindow::getNames() {
* renamed - renamed filenames (sorted in the same order as `orig`) * renamed - renamed filenames (sorted in the same order as `orig`)
*/ */
void renameFiles( void renameFiles(
const std::vector< const std::vector< std::pair< std::pair< int, std::string >,
std::pair< std::pair< int, std::string >, std::pair< std::string, std::string > > > std::pair< std::string, std::string > > >
&renamed ) { &renamed ) {
for ( auto renamed_it = renamed.begin(); renamed_it != renamed.end(); for ( auto renamed_it = renamed.begin(); renamed_it != renamed.end();
++renamed_it ) { ++renamed_it ) {
std::cout << renamed_it->first.second << "/" << renamed_it->second.first std::cout << renamed_it->first.second << "/" << renamed_it->second.first
<< " --> " << renamed_it->first.second << "/" << " --> " << renamed_it->first.second << "/"
<< renamed_it->second.second << std::endl; << renamed_it->second.second << std::endl;
FSLib::rename( renamed_it->first.second + "/" + renamed_it->second.first, FSLib::rename(
renamed_it->first.second + "/" + renamed_it->second.first,
renamed_it->first.second + "/" + renamed_it->second.second ); renamed_it->first.second + "/" + renamed_it->second.second );
} }
} }
@ -199,7 +200,8 @@ void MainWindow::finishedSelection() {
for ( auto &x : selected ) { for ( auto &x : selected ) {
// get renamed files for given season // get renamed files for given season
auto renamed_files = getRenamedFiles( auto renamed_files = getRenamedFiles(
static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_show] ), static_cast< Glib::ustring >(
( *iter )[m_columns_show.m_col_show] ),
x, show_id, language_code, x, show_id, language_code,
( input_pattern.empty() ? default_pattern : input_pattern ), ( input_pattern.empty() ? default_pattern : input_pattern ),
!m_check_linux->get_active(), files[x], m_check_dvd->get_active() ); !m_check_linux->get_active(), files[x], m_check_dvd->get_active() );
@ -214,13 +216,14 @@ void MainWindow::finishedSelection() {
} }
// create a custom dialog box with textview of new episode names // create a custom dialog box with textview of new episode names
std::unique_ptr<Gtk::Dialog> dialog( new Gtk::Dialog( "Rename confirmation", *this ) ); std::unique_ptr< Gtk::Dialog > dialog(
new Gtk::Dialog( "Rename confirmation", *this ) );
dialog->set_default_size( 550, 350 ); dialog->set_default_size( 550, 350 );
dialog->set_resizable( false ); dialog->set_resizable( false );
auto content = dialog->get_content_area(); auto content = dialog->get_content_area();
std::unique_ptr<Gtk::ScrolledWindow> sw( new Gtk::ScrolledWindow ); std::unique_ptr< Gtk::ScrolledWindow > sw( new Gtk::ScrolledWindow );
std::unique_ptr<Gtk::TextView> tx( new Gtk::TextView ); std::unique_ptr< Gtk::TextView > tx( new Gtk::TextView );
content->pack_start( *sw ); content->pack_start( *sw );
sw->add( *tx ); sw->add( *tx );
tx->set_editable( false ); tx->set_editable( false );
@ -260,8 +263,8 @@ MainWindow::~MainWindow() {
auto children = get_children(); auto children = get_children();
size_t max = children.size(); size_t max = children.size();
size_t index{}; size_t index{};
while( index < max ) { while ( index < max ) {
if( auto *p = dynamic_cast<Gtk::Container*>(children[index]) ) { if ( auto *p = dynamic_cast< Gtk::Container * >( children[index] ) ) {
auto temp = p->get_children(); auto temp = p->get_children();
children.insert( children.end(), temp.begin(), temp.end() ); children.insert( children.end(), temp.begin(), temp.end() );
max = children.size(); max = children.size();
@ -269,7 +272,7 @@ MainWindow::~MainWindow() {
index++; index++;
} }
std::cout << children.size() << std::endl; std::cout << children.size() << std::endl;
for( int i = max - 1; i >= 0; i-- ) { for ( int i = max - 1; i >= 0; i-- ) {
delete children[i]; delete children[i];
} }
} }
@ -291,119 +294,118 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
} }
} }
auto *box = new Gtk::Box(Gtk::ORIENTATION_VERTICAL); auto *box = new Gtk::Box( Gtk::ORIENTATION_VERTICAL );
auto *menu = new Gtk::MenuBar(); auto *menu = new Gtk::MenuBar();
auto *inputs = new Gtk::Grid(); auto *inputs = new Gtk::Grid();
auto *processing = new Gtk::Grid(); auto *processing = new Gtk::Grid();
auto *buttons = new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL); auto *buttons = new Gtk::Box( Gtk::ORIENTATION_HORIZONTAL );
add( *box ); add( *box );
box->pack_start(*menu, false, false); box->pack_start( *menu, false, false );
box->pack_start(*inputs, false, true); box->pack_start( *inputs, false, true );
box->pack_start(*processing, false, true); box->pack_start( *processing, false, true );
box->pack_start(*m_check_dvd, false, true); box->pack_start( *m_check_dvd, false, true );
box->pack_start(*m_label_possible, false, true); box->pack_start( *m_label_possible, false, true );
box->pack_start(*m_combo_possible, false, true); box->pack_start( *m_combo_possible, false, true );
box->pack_start(*buttons, false, true ); box->pack_start( *buttons, false, true );
box->pack_start(*m_button_quit, false, true ); box->pack_start( *m_button_quit, false, true );
auto *item = new Gtk::MenuItem(); auto *item = new Gtk::MenuItem();
auto *submenu = new Gtk::Menu(); auto *submenu = new Gtk::Menu();
menu->append(*item); menu->append( *item );
// File menu // File menu
item->set_label("File"); item->set_label( "File" );
item->set_submenu(*submenu); item->set_submenu( *submenu );
// Exit item for File menu // Exit item for File menu
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Exit"); item->set_label( "Exit" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::quit ) ); sigc::mem_fun( *this, &MainWindow::quit ) );
submenu->append( *item );
submenu->append(*item);
// Database menu // Database menu
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
submenu = new Gtk::Menu(); submenu = new Gtk::Menu();
item->set_label("Database"); item->set_label( "Database" );
item->set_submenu(*submenu); item->set_submenu( *submenu );
menu->append(*item); menu->append( *item );
// Update database // Update database
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Update database"); item->set_label( "Update database" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbUpdate ) ); sigc::mem_fun( *this, &MainWindow::dbUpdate ) );
submenu->append(*item); submenu->append( *item );
// Refresh database // Refresh database
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Refresh database"); item->set_label( "Refresh database" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbRefresh ) ); sigc::mem_fun( *this, &MainWindow::dbRefresh ) );
submenu->append(*item); submenu->append( *item );
// Clean database // Clean database
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Clean database"); item->set_label( "Clean database" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbClean ) ); sigc::mem_fun( *this, &MainWindow::dbClean ) );
submenu->append(*item); submenu->append( *item );
// Manage database // Manage database
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Manage database"); item->set_label( "Manage database" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbManage ) ); sigc::mem_fun( *this, &MainWindow::dbManage ) );
submenu->append(*item); submenu->append( *item );
item = new Gtk::MenuItem(); item = new Gtk::MenuItem();
item->set_label("Change pattern"); item->set_label( "Change pattern" );
item->signal_activate().connect( item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbPattern ) ); sigc::mem_fun( *this, &MainWindow::dbPattern ) );
submenu->append(*item); submenu->append( *item );
std::vector<Gtk::Widget*> left_aligned_widgets = {m_label_show, std::vector< Gtk::Widget * > left_aligned_widgets = {
m_label_language, m_entry_show, m_combo_language, m_label_dir, m_label_show, m_label_language, m_entry_show, m_combo_language,
m_entry_dir, m_label_pattern, m_entry_pattern, m_button_pattern, m_label_dir, m_entry_dir, m_label_pattern, m_entry_pattern,
m_button_process, m_check_linux, m_check_trust, m_check_dvd, m_button_pattern, m_button_process, m_check_linux, m_check_trust,
m_label_possible, m_combo_possible, m_button_rename, m_check_dvd, m_label_possible, m_combo_possible, m_button_rename,
m_button_db_add, m_button_dir m_button_db_add, m_button_dir
}; };
// set widgets' position in boxes // set widgets' position in boxes
inputs->attach( *m_label_show, 0, 0, 1, 1 ); inputs->attach( *m_label_show, 0, 0, 1, 1 );
inputs->attach( *m_label_language, 1, 0, 1, 1); inputs->attach( *m_label_language, 1, 0, 1, 1 );
inputs->attach( *m_entry_show, 0, 1, 1, 1 ); inputs->attach( *m_entry_show, 0, 1, 1, 1 );
inputs->attach( *m_combo_language, 1, 1, 1, 1 ); inputs->attach( *m_combo_language, 1, 1, 1, 1 );
inputs->attach( *m_label_dir, 0, 2, 2, 1 ); inputs->attach( *m_label_dir, 0, 2, 2, 1 );
inputs->attach( *m_entry_dir, 0, 3, 1, 1 ); inputs->attach( *m_entry_dir, 0, 3, 1, 1 );
inputs->attach( *m_button_dir, 1, 3, 1, 1 ); inputs->attach( *m_button_dir, 1, 3, 1, 1 );
inputs->attach( *m_label_pattern, 0, 4, 2, 1); inputs->attach( *m_label_pattern, 0, 4, 2, 1 );
inputs->attach( *m_entry_pattern, 0, 5, 1, 1); inputs->attach( *m_entry_pattern, 0, 5, 1, 1 );
inputs->attach( *m_button_pattern, 1, 5, 1, 1); inputs->attach( *m_button_pattern, 1, 5, 1, 1 );
inputs->set_column_homogeneous( true ); inputs->set_column_homogeneous( true );
processing->attach( *m_button_process, 0, 0, 1, 2 ); processing->attach( *m_button_process, 0, 0, 1, 2 );
processing->attach( *m_check_linux, 1, 0, 1, 1); processing->attach( *m_check_linux, 1, 0, 1, 1 );
processing->attach( *m_check_trust, 1, 1, 1, 1); processing->attach( *m_check_trust, 1, 1, 1, 1 );
buttons->pack_start( *m_button_rename, false, true ); buttons->pack_start( *m_button_rename, false, true );
buttons->pack_start( *m_button_db_add, false, true ); buttons->pack_start( *m_button_db_add, false, true );
// set widgets alignment and margins // set widgets alignment and margins
for( auto &x : left_aligned_widgets ) { for ( auto &x : left_aligned_widgets ) {
x->set_halign( Gtk::ALIGN_START ); x->set_halign( Gtk::ALIGN_START );
x->set_valign( Gtk::ALIGN_CENTER ); x->set_valign( Gtk::ALIGN_CENTER );
x->set_margin_left( 5 ); x->set_margin_left( 5 );
@ -459,7 +461,7 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
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;
if( x.first == "en" ) if ( x.first == "en" )
m_combo_language->set_active( row ); m_combo_language->set_active( row );
} }
} }
@ -504,11 +506,10 @@ void MainWindow::dbUpdate() {
app->add_window( *pw ); app->add_window( *pw );
auto app_ptr = app; auto app_ptr = app;
pw->signal_hide().connect( pw->signal_hide().connect( [pw, app_ptr]() {
[pw, app_ptr](){
app_ptr->remove_window( *pw ); app_ptr->remove_window( *pw );
delete pw; delete pw;
}); } );
std::thread t( updateDB, !m_check_linux->get_active(), pw ); std::thread t( updateDB, !m_check_linux->get_active(), pw );
t.detach(); t.detach();
pw->show(); pw->show();
@ -523,11 +524,10 @@ void MainWindow::dbRefresh() {
app->add_window( *pw ); app->add_window( *pw );
auto app_ptr = app; auto app_ptr = app;
pw->signal_hide().connect( pw->signal_hide().connect( [pw, app_ptr]() {
[pw, app_ptr](){
app_ptr->remove_window( *pw ); app_ptr->remove_window( *pw );
delete pw; delete pw;
}); } );
std::thread t( refreshDB, !m_check_linux->get_active(), pw ); std::thread t( refreshDB, !m_check_linux->get_active(), pw );
t.detach(); t.detach();
pw->show(); pw->show();
@ -550,9 +550,12 @@ void MainWindow::dbAdd() {
auto iter = m_combo_possible->get_active(); auto iter = m_combo_possible->get_active();
std::string input_pattern = m_entry_pattern->get_text(); std::string input_pattern = m_entry_pattern->get_text();
std::string show = static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_show] ); std::string show =
std::string language_code = static_cast< Glib::ustring >( ( *m_combo_language->get_active() )[m_columns_language.m_col_code] ); static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_show] );
std::string show_id = static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_id] ); std::string language_code = static_cast< Glib::ustring >(
( *m_combo_language->get_active() )[m_columns_language.m_col_code] );
std::string show_id =
static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_id] );
std::cout << show << " " << language_code << " " << show_id << std::endl; std::cout << show << " " << language_code << " " << show_id << std::endl;
@ -560,11 +563,10 @@ void MainWindow::dbAdd() {
app->add_window( *pw ); app->add_window( *pw );
auto app_ptr = app; auto app_ptr = app;
pw->signal_hide().connect( pw->signal_hide().connect( [pw, app_ptr]() {
[pw, app_ptr](){
app_ptr->remove_window( *pw ); app_ptr->remove_window( *pw );
delete pw; delete pw;
}); } );
std::thread t( addToDB, std::ref( show ), m_entry_dir->get_text(), std::thread t( addToDB, std::ref( show ), m_entry_dir->get_text(),
std::ref( language_code ), std::ref( show_id ), std::ref( language_code ), std::ref( show_id ),
@ -579,24 +581,24 @@ void MainWindow::dbManage() {
app->add_window( *dbWindow ); app->add_window( *dbWindow );
auto app_ptr = app; auto app_ptr = app;
dbWindow->signal_hide().connect( dbWindow->signal_hide().connect( [dbWindow, app_ptr]() {
[dbWindow, app_ptr](){
app_ptr->remove_window( *dbWindow ); app_ptr->remove_window( *dbWindow );
delete dbWindow; delete dbWindow;
}); } );
dbWindow->show(); dbWindow->show();
} }
void MainWindow::dbPattern() { void MainWindow::dbPattern() {
// Create a custom dialog box for pattern change // Create a custom dialog box for pattern change
std::unique_ptr<Gtk::Dialog> dialog( new Gtk::Dialog( "Change pattern", *this ) ); std::unique_ptr< Gtk::Dialog > dialog(
new Gtk::Dialog( "Change pattern", *this ) );
dialog->set_default_size( 350, 0 ); dialog->set_default_size( 350, 0 );
auto content = dialog->get_content_area(); auto content = dialog->get_content_area();
auto pattern = getDBPattern(); auto pattern = getDBPattern();
std::unique_ptr<Gtk::Entry> pattern_entry( new Gtk::Entry ); std::unique_ptr< Gtk::Entry > pattern_entry( new Gtk::Entry );
content->pack_start( *pattern_entry ); content->pack_start( *pattern_entry );
dialog->add_button( "_Cancel", Gtk::RESPONSE_CANCEL ); dialog->add_button( "_Cancel", Gtk::RESPONSE_CANCEL );
@ -604,16 +606,16 @@ void MainWindow::dbPattern() {
dialog->show_all_children(); dialog->show_all_children();
dialog->signal_response().connect( dialog->signal_response().connect(
[&pattern, &pattern_entry]( int response ){ [&pattern, &pattern_entry]( int response ) {
if( response == Gtk::RESPONSE_OK ) if ( response == Gtk::RESPONSE_OK )
pattern = pattern_entry->get_text(); pattern = pattern_entry->get_text();
}); } );
pattern_entry->set_text( pattern ); pattern_entry->set_text( pattern );
auto response = dialog->run(); auto response = dialog->run();
if( response == Gtk::RESPONSE_OK ) { if ( response == Gtk::RESPONSE_OK ) {
changeDBPattern( pattern ); changeDBPattern( pattern );
} }
} }

View File

@ -12,8 +12,8 @@
#include <gtkmm/menubar.h> #include <gtkmm/menubar.h>
#include <gtkmm/menuitem.h> #include <gtkmm/menuitem.h>
#include <gtkmm/window.h> #include <gtkmm/window.h>
#include <set>
#include <iostream> #include <iostream>
#include <set>
#include "network.hpp" #include "network.hpp"
#include "seasonwindow.hpp" #include "seasonwindow.hpp"
@ -87,7 +87,7 @@ protected:
Glib::RefPtr< Gtk::Application > app; Glib::RefPtr< Gtk::Application > app;
std::unique_ptr<SeasonWindow> sw{nullptr}; std::unique_ptr< SeasonWindow > sw{ nullptr };
std::vector< int > selected; std::vector< int > selected;
std::map< int, std::map< int, string > > files; std::map< int, std::map< int, string > > files;
std::string path; std::string path;