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 <thread>
#include "databasewindow.hpp"
#include "filesystem.hpp"
#include "functions.hpp"
#include "mainwindow.hpp"
#include "databasewindow.hpp"
#include "progresswindow.hpp"
#include "tv_rename.hpp"
@ -76,8 +76,8 @@ void MainWindow::process() {
( *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 );
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 ) {
@ -154,16 +154,17 @@ void MainWindow::getNames() {
* renamed - renamed filenames (sorted in the same order as `orig`)
*/
void renameFiles(
const std::vector<
std::pair< std::pair< int, std::string >, std::pair< std::string, std::string > > >
const std::vector< std::pair< std::pair< int, std::string >,
std::pair< std::string, std::string > > >
&renamed ) {
for ( auto renamed_it = renamed.begin(); renamed_it != renamed.end();
++renamed_it ) {
std::cout << renamed_it->first.second << "/" << renamed_it->second.first
<< " --> " << renamed_it->first.second << "/"
<< renamed_it->second.second << std::endl;
FSLib::rename( renamed_it->first.second + "/" + renamed_it->second.first,
renamed_it->first.second + "/" + renamed_it->second.second );
FSLib::rename(
renamed_it->first.second + "/" + renamed_it->second.first,
renamed_it->first.second + "/" + renamed_it->second.second );
}
}
@ -199,7 +200,8 @@ void MainWindow::finishedSelection() {
for ( auto &x : selected ) {
// get renamed files for given season
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,
( input_pattern.empty() ? default_pattern : input_pattern ),
!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
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_resizable( false );
auto content = dialog->get_content_area();
std::unique_ptr<Gtk::ScrolledWindow> sw( new Gtk::ScrolledWindow );
std::unique_ptr<Gtk::TextView> tx( new Gtk::TextView );
std::unique_ptr< Gtk::ScrolledWindow > sw( new Gtk::ScrolledWindow );
std::unique_ptr< Gtk::TextView > tx( new Gtk::TextView );
content->pack_start( *sw );
sw->add( *tx );
tx->set_editable( false );
@ -260,8 +263,8 @@ 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]) ) {
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();
@ -269,7 +272,7 @@ MainWindow::~MainWindow() {
index++;
}
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];
}
}
@ -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 *inputs = 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 );
box->pack_start(*menu, false, false);
box->pack_start(*inputs, false, true);
box->pack_start(*processing, false, true);
box->pack_start(*m_check_dvd, false, true);
box->pack_start(*m_label_possible, false, true);
box->pack_start(*m_combo_possible, false, true);
box->pack_start(*buttons, false, true );
box->pack_start(*m_button_quit, false, true );
box->pack_start( *menu, false, false );
box->pack_start( *inputs, false, true );
box->pack_start( *processing, false, true );
box->pack_start( *m_check_dvd, false, true );
box->pack_start( *m_label_possible, false, true );
box->pack_start( *m_combo_possible, false, true );
box->pack_start( *buttons, false, true );
box->pack_start( *m_button_quit, false, true );
auto *item = new Gtk::MenuItem();
auto *submenu = new Gtk::Menu();
menu->append(*item);
menu->append( *item );
// File menu
item->set_label("File");
item->set_submenu(*submenu);
item->set_label( "File" );
item->set_submenu( *submenu );
// Exit item for File menu
item = new Gtk::MenuItem();
item->set_label("Exit");
item->set_label( "Exit" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::quit ) );
submenu->append(*item);
submenu->append( *item );
// Database menu
item = new Gtk::MenuItem();
submenu = new Gtk::Menu();
item->set_label("Database");
item->set_submenu(*submenu);
menu->append(*item);
item->set_label( "Database" );
item->set_submenu( *submenu );
menu->append( *item );
// Update database
item = new Gtk::MenuItem();
item->set_label("Update database");
item->set_label( "Update database" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbUpdate ) );
submenu->append(*item);
submenu->append( *item );
// Refresh database
item = new Gtk::MenuItem();
item->set_label("Refresh database");
item->set_label( "Refresh database" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbRefresh ) );
submenu->append(*item);
submenu->append( *item );
// Clean database
item = new Gtk::MenuItem();
item->set_label("Clean database");
item->set_label( "Clean database" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbClean ) );
submenu->append(*item);
submenu->append( *item );
// Manage database
item = new Gtk::MenuItem();
item->set_label("Manage database");
item->set_label( "Manage database" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbManage ) );
submenu->append(*item);
submenu->append( *item );
item = new Gtk::MenuItem();
item->set_label("Change pattern");
item->set_label( "Change pattern" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbPattern ) );
submenu->append(*item);
submenu->append( *item );
std::vector<Gtk::Widget*> left_aligned_widgets = {m_label_show,
m_label_language, m_entry_show, m_combo_language, m_label_dir,
m_entry_dir, m_label_pattern, m_entry_pattern, m_button_pattern,
m_button_process, m_check_linux, m_check_trust, m_check_dvd,
m_label_possible, m_combo_possible, m_button_rename,
m_button_db_add, m_button_dir
std::vector< Gtk::Widget * > left_aligned_widgets = {
m_label_show, m_label_language, m_entry_show, m_combo_language,
m_label_dir, m_entry_dir, m_label_pattern, m_entry_pattern,
m_button_pattern, m_button_process, m_check_linux, m_check_trust,
m_check_dvd, m_label_possible, m_combo_possible, m_button_rename,
m_button_db_add, m_button_dir
};
// set widgets' position in boxes
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_combo_language, 1, 1, 1, 1 );
inputs->attach( *m_label_dir, 0, 2, 2, 1 );
inputs->attach( *m_entry_dir, 0, 3, 1, 1 );
inputs->attach( *m_button_dir, 1, 3, 1, 1 );
inputs->attach( *m_label_pattern, 0, 4, 2, 1);
inputs->attach( *m_entry_pattern, 0, 5, 1, 1);
inputs->attach( *m_button_pattern, 1, 5, 1, 1);
inputs->attach( *m_label_pattern, 0, 4, 2, 1 );
inputs->attach( *m_entry_pattern, 0, 5, 1, 1 );
inputs->attach( *m_button_pattern, 1, 5, 1, 1 );
inputs->set_column_homogeneous( true );
processing->attach( *m_button_process, 0, 0, 1, 2 );
processing->attach( *m_check_linux, 1, 0, 1, 1);
processing->attach( *m_check_trust, 1, 1, 1, 1);
processing->attach( *m_check_linux, 1, 0, 1, 1 );
processing->attach( *m_check_trust, 1, 1, 1, 1 );
buttons->pack_start( *m_button_rename, false, true );
buttons->pack_start( *m_button_db_add, false, true );
// 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_valign( Gtk::ALIGN_CENTER );
x->set_margin_left( 5 );
@ -459,7 +461,7 @@ MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
auto row = *( model->append() );
row[m_columns_language.m_col_code] = x.first;
row[m_columns_language.m_col_language] = x.second;
if( x.first == "en" )
if ( x.first == "en" )
m_combo_language->set_active( row );
}
}
@ -504,11 +506,10 @@ void MainWindow::dbUpdate() {
app->add_window( *pw );
auto app_ptr = app;
pw->signal_hide().connect(
[pw, app_ptr](){
app_ptr->remove_window( *pw );
delete pw;
});
pw->signal_hide().connect( [pw, app_ptr]() {
app_ptr->remove_window( *pw );
delete pw;
} );
std::thread t( updateDB, !m_check_linux->get_active(), pw );
t.detach();
pw->show();
@ -523,11 +524,10 @@ void MainWindow::dbRefresh() {
app->add_window( *pw );
auto app_ptr = app;
pw->signal_hide().connect(
[pw, app_ptr](){
app_ptr->remove_window( *pw );
delete pw;
});
pw->signal_hide().connect( [pw, app_ptr]() {
app_ptr->remove_window( *pw );
delete pw;
} );
std::thread t( refreshDB, !m_check_linux->get_active(), pw );
t.detach();
pw->show();
@ -550,9 +550,12 @@ void MainWindow::dbAdd() {
auto iter = m_combo_possible->get_active();
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 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::string show =
static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_show] );
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;
@ -560,11 +563,10 @@ void MainWindow::dbAdd() {
app->add_window( *pw );
auto app_ptr = app;
pw->signal_hide().connect(
[pw, app_ptr](){
app_ptr->remove_window( *pw );
delete pw;
});
pw->signal_hide().connect( [pw, app_ptr]() {
app_ptr->remove_window( *pw );
delete pw;
} );
std::thread t( addToDB, std::ref( show ), m_entry_dir->get_text(),
std::ref( language_code ), std::ref( show_id ),
@ -579,24 +581,24 @@ void MainWindow::dbManage() {
app->add_window( *dbWindow );
auto app_ptr = app;
dbWindow->signal_hide().connect(
[dbWindow, app_ptr](){
app_ptr->remove_window( *dbWindow );
delete dbWindow;
});
dbWindow->signal_hide().connect( [dbWindow, app_ptr]() {
app_ptr->remove_window( *dbWindow );
delete dbWindow;
} );
dbWindow->show();
}
void MainWindow::dbPattern() {
// 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 );
auto content = dialog->get_content_area();
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 );
dialog->add_button( "_Cancel", Gtk::RESPONSE_CANCEL );
@ -604,16 +606,16 @@ void MainWindow::dbPattern() {
dialog->show_all_children();
dialog->signal_response().connect(
[&pattern, &pattern_entry]( int response ){
if( response == Gtk::RESPONSE_OK )
[&pattern, &pattern_entry]( int response ) {
if ( response == Gtk::RESPONSE_OK )
pattern = pattern_entry->get_text();
});
} );
pattern_entry->set_text( pattern );
auto response = dialog->run();
if( response == Gtk::RESPONSE_OK ) {
if ( response == Gtk::RESPONSE_OK ) {
changeDBPattern( pattern );
}
}

View File

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