tv_rename/mainwindow.cpp

616 lines
20 KiB
C++
Raw Normal View History

2019-02-04 16:39:48 +00:00
#include <fstream>
2019-01-23 19:46:03 +00:00
#include <gtkmm/filechooserdialog.h>
2020-01-16 22:22:21 +00:00
#include <gtkmm/grid.h>
2019-02-04 16:39:48 +00:00
#include <gtkmm/liststore.h>
2019-01-23 19:46:03 +00:00
#include <gtkmm/messagedialog.h>
2019-07-12 21:10:40 +00:00
#include <gtkmm/scrolledwindow.h>
2019-01-23 19:46:03 +00:00
#include <gtkmm/textview.h>
#include <thread>
2019-01-23 19:46:03 +00:00
2020-01-17 13:14:24 +00:00
#include "databasewindow.hpp"
2019-02-04 16:39:48 +00:00
#include "filesystem.hpp"
#include "functions.hpp"
#include "mainwindow.hpp"
#include "progresswindow.hpp"
2019-02-04 16:39:48 +00:00
#include "tv_rename.hpp"
2019-01-23 19:46:03 +00:00
void MainWindow::chooseFile() {
// create a dialog for choosing directory
2019-02-04 16:39:48 +00:00
Gtk::FileChooserDialog dialog( "Select a directory",
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER );
dialog.set_transient_for( *this );
2019-01-23 19:46:03 +00:00
// add cancel and select buttons
2019-02-04 16:39:48 +00:00
dialog.add_button( "_Cancel", Gtk::RESPONSE_CANCEL );
dialog.add_button( "Select", Gtk::RESPONSE_OK );
2019-01-23 19:46:03 +00:00
auto result = dialog.run();
2019-02-04 16:39:48 +00:00
switch ( result ) {
2019-01-23 19:46:03 +00:00
case Gtk::RESPONSE_OK:
2019-07-12 21:10:40 +00:00
m_entry_dir->set_text( dialog.get_filename() );
2019-01-23 19:46:03 +00:00
break;
case Gtk::RESPONSE_CANCEL:
break;
default:
break;
}
}
void MainWindow::quit() {
hide();
}
void MainWindow::patternHelp() {
2019-02-04 16:39:48 +00:00
Gtk::MessageDialog dialog( *this, "Pattern escape sequences" );
dialog.set_secondary_text(
"%filename - original filename (without type extension)\n"
"%show - show name from thetvdb\n"
"%epname - episode name from thetvdb\n"
"%season - season number\n"
"%episode - episode number\n"
"Both season number and episode number can be padded with zeros, just "
"add width of padding"
" right after %, like this: %2season.\n"
"Default pattern is \"%filename - %epname\", you might want to change "
"this to"
" \"S%2seasonE%2episode - %epname\" or \"%show - S%2seasonE%2episode - "
"%epname\"" );
2019-01-23 19:46:03 +00:00
dialog.run();
}
void MainWindow::process() {
2019-02-04 16:39:48 +00:00
// check required field is filled out
2019-07-12 21:10:40 +00:00
if ( m_entry_show->get_text().empty() ) {
2019-02-04 16:39:48 +00:00
Gtk::MessageDialog dialog( *this, "Show field is empty" );
2019-01-23 19:46:03 +00:00
dialog.run();
return;
}
// language code
2019-02-04 16:39:48 +00:00
language_code =
2019-07-12 21:10:40 +00:00
( *m_combo_language->get_active() )[m_columns_language.m_col_code];
2019-01-23 19:46:03 +00:00
// fill up m_combo_possible with possible tv shows
2020-01-17 13:14:24 +00:00
auto possible_shows =
searchShow( std::string( m_entry_show->get_text() ), language_code );
2019-01-23 19:46:03 +00:00
// if no possible shows were found, tell the user
2019-02-04 16:39:48 +00:00
if ( possible_shows.size() == 0 ) {
Gtk::MessageDialog dialog( *this,
"No results found for given show name" );
2019-01-23 19:46:03 +00:00
dialog.run();
return;
}
2019-02-04 16:39:48 +00:00
// show widgets
2019-07-12 21:10:40 +00:00
m_label_possible->show();
m_button_rename->show();
m_button_db_add->show();
m_combo_possible->show();
2019-01-23 19:46:03 +00:00
// fill up combo box with results from thetvdb
2020-01-16 10:12:22 +00:00
auto model = Gtk::ListStore::create( m_columns_show );
2019-01-23 19:46:03 +00:00
2019-07-12 21:10:40 +00:00
m_combo_possible->set_model( model );
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
auto row = *( model->append() );
2019-01-23 19:46:03 +00:00
2020-01-16 10:12:22 +00:00
row[m_columns_show.m_col_show] = possible_shows[0].first;
row[m_columns_show.m_col_id] = possible_shows[0].second;
2019-07-12 21:10:40 +00:00
m_combo_possible->set_active( row );
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
for ( size_t i = 1; i < possible_shows.size(); i++ ) {
auto row = *( model->append() );
2020-01-16 10:12:22 +00:00
row[m_columns_show.m_col_show] = possible_shows[i].first;
row[m_columns_show.m_col_id] = possible_shows[i].second;
2019-01-23 19:46:03 +00:00
}
}
void MainWindow::getNames() {
2019-02-04 16:39:48 +00:00
// check required field is filled out
2019-07-12 21:10:40 +00:00
if ( m_entry_dir->get_text().empty() ) {
2019-02-04 16:39:48 +00:00
Gtk::MessageDialog dialog( *this, "Directory field is empty" );
2019-01-23 19:46:03 +00:00
dialog.run();
return;
}
// check directory exists
2019-07-12 21:10:40 +00:00
if ( !FSLib::isDirectory( m_entry_dir->get_text() ) ) {
2019-02-04 16:39:48 +00:00
Gtk::MessageDialog dialog( *this, "Directory doesn't exist" );
2019-01-23 19:46:03 +00:00
dialog.run();
return;
}
2019-07-12 21:10:40 +00:00
path = m_entry_dir->get_text();
2019-01-23 19:46:03 +00:00
selected.clear();
files.clear();
2019-02-04 16:39:48 +00:00
std::vector< int > options;
2019-01-23 19:46:03 +00:00
// get all files in path and seperate them in map `files` by season
2019-02-04 16:39:48 +00:00
iterateFS( files, path );
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
for ( auto &x : files ) {
options.push_back( x.first );
2019-01-23 19:46:03 +00:00
}
// create a window with possible seasons to rename
// store selected seasons in `selected`
2019-07-12 21:10:40 +00:00
sw.reset( new SeasonWindow( options, selected ) );
2019-02-04 16:39:48 +00:00
sw->signal_hide().connect(
sigc::mem_fun( *this, &MainWindow::finishedSelection ) );
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
app->add_window( *sw );
2019-01-23 19:46:03 +00:00
sw->show();
}
/* change names of original files to generated new names
* orig - original filenames
* renamed - renamed filenames (sorted in the same order as `orig`)
*/
2019-02-04 16:39:48 +00:00
void renameFiles(
2020-01-17 13:14:24 +00:00
const std::vector< std::pair< std::pair< int, std::string >,
std::pair< std::string, std::string > > >
2019-02-04 16:39:48 +00:00
&renamed ) {
for ( auto renamed_it = renamed.begin(); renamed_it != renamed.end();
++renamed_it ) {
2020-01-17 13:14:24 +00:00
FSLib::rename(
renamed_it->first.second + "/" + renamed_it->second.first,
renamed_it->first.second + "/" + renamed_it->second.second );
2019-01-23 19:46:03 +00:00
}
}
void MainWindow::finishedSelection() {
// remove created SeasonWindow and delete it from memory
2019-02-04 16:39:48 +00:00
app->remove_window( *sw );
2019-01-23 19:46:03 +00:00
2019-07-12 21:10:40 +00:00
auto iter = m_combo_possible->get_active();
2019-01-23 19:46:03 +00:00
2020-01-16 10:12:22 +00:00
std::string show_id =
static_cast< Glib::ustring >( ( *iter )[m_columns_show.m_col_id] );
// shouldn't ever happen, but just to be sure
2020-01-16 10:12:22 +00:00
if ( show_id.empty() )
return;
2019-07-12 21:10:40 +00:00
std::string input_pattern = m_entry_pattern->get_text();
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
// store pattern to cache if it's different from default
if ( input_pattern != default_pattern ) {
std::ofstream file( userHome() + "/.cache/tv_rename_pattern" );
if ( file ) {
2019-01-23 19:46:03 +00:00
file << input_pattern;
}
}
2019-02-04 16:39:48 +00:00
for ( auto &x : selected ) {
2019-01-23 19:46:03 +00:00
// get renamed files for given season
2019-02-04 16:39:48 +00:00
auto renamed_files = getRenamedFiles(
2020-01-17 13:14:24 +00:00
static_cast< Glib::ustring >(
( *iter )[m_columns_show.m_col_show] ),
2020-01-16 10:12:22 +00:00
x, show_id, language_code,
2019-02-04 16:39:48 +00:00
( input_pattern.empty() ? default_pattern : input_pattern ),
2020-01-16 22:22:21 +00:00
!m_check_linux->get_active(), files[x], m_check_dvd->get_active() );
2019-01-23 19:46:03 +00:00
2019-02-04 16:39:48 +00:00
if ( renamed_files.empty() )
2019-01-23 19:46:03 +00:00
continue;
// if trust checkbox is ticked, rename files
2019-07-12 21:10:40 +00:00
if ( m_check_trust->get_active() ) {
2019-02-04 16:39:48 +00:00
renameFiles( renamed_files );
2019-01-23 19:46:03 +00:00
continue;
}
// create a custom dialog box with textview of new episode names
2020-01-17 13:14:24 +00:00
std::unique_ptr< Gtk::Dialog > dialog(
new Gtk::Dialog( "Rename confirmation", *this ) );
2019-07-12 21:10:40 +00:00
dialog->set_default_size( 550, 350 );
dialog->set_resizable( false );
auto content = dialog->get_content_area();
std::unique_ptr< Gtk::ScrolledWindow > sc_w( new Gtk::ScrolledWindow );
2020-01-17 13:14:24 +00:00
std::unique_ptr< Gtk::TextView > tx( new Gtk::TextView );
content->pack_start( *sc_w );
sc_w->add( *tx );
2019-07-12 21:10:40 +00:00
tx->set_editable( false );
tx->set_cursor_visible( false );
dialog->add_button( "_No", Gtk::RESPONSE_CANCEL );
dialog->add_button( "_Yes", Gtk::RESPONSE_OK );
sc_w->show();
2019-07-12 21:10:40 +00:00
tx->show();
auto buff = tx->get_buffer();
2019-02-04 16:39:48 +00:00
buff->place_cursor( buff->begin() );
buff->insert_at_cursor( renamed_files[0].second.first.c_str() );
buff->insert_at_cursor( " --> " );
buff->insert_at_cursor( renamed_files[0].second.second.c_str() );
for ( size_t i = 1; i < renamed_files.size(); i++ ) {
buff->insert_at_cursor( "\n" );
buff->insert_at_cursor( renamed_files[i].second.first.c_str() );
buff->insert_at_cursor( " --> " );
buff->insert_at_cursor( renamed_files[i].second.second.c_str() );
2019-01-23 19:46:03 +00:00
}
2019-07-12 21:10:40 +00:00
auto response = dialog->run();
2019-01-23 19:46:03 +00:00
// if user clicked "Yes" in dialog, rename files
2019-02-04 16:39:48 +00:00
switch ( response ) {
2019-01-23 19:46:03 +00:00
case Gtk::RESPONSE_OK:
2019-02-04 16:39:48 +00:00
renameFiles( renamed_files );
2019-01-23 19:46:03 +00:00
default:
break;
}
}
}
2019-07-12 21:10:40 +00:00
MainWindow::~MainWindow() {
auto children = get_children();
size_t max = children.size();
size_t index{};
2020-01-17 13:14:24 +00:00
while ( index < max ) {
if ( auto *p = dynamic_cast< Gtk::Container * >( children[index] ) ) {
2019-07-12 21:10:40 +00:00
auto temp = p->get_children();
children.insert( children.end(), temp.begin(), temp.end() );
max = children.size();
}
index++;
}
2020-01-17 13:14:24 +00:00
for ( int i = max - 1; i >= 0; i-- ) {
2019-07-12 21:10:40 +00:00
delete children[i];
}
}
2019-02-04 16:39:48 +00:00
MainWindow::MainWindow( const Glib::RefPtr< Gtk::Application > &ptr )
: app( ptr ) {
set_title( "TV Rename" );
2019-01-23 19:46:03 +00:00
// create widgets
Gtk::Button *button_dir = new Gtk::Button();
Gtk::Button *button_quit = new Gtk::Button();
Gtk::Button *button_process = new Gtk::Button();
Gtk::Button *button_pattern = new Gtk::Button();
Gtk::Label *label_language = new Gtk::Label();
Gtk::Label *label_show = new Gtk::Label();
Gtk::Label *label_dir = new Gtk::Label();
Gtk::Label *label_pattern = new Gtk::Label();
2019-07-12 21:10:40 +00:00
set_default_size( 400, 345 );
2019-02-04 16:39:48 +00:00
set_resizable( false );
2019-01-23 19:46:03 +00:00
{
2019-02-04 16:39:48 +00:00
// if cached pattern exists, load that instead of default
std::ifstream file( userHome() + "/.cache/tv_rename_pattern" );
if ( file ) {
2019-01-23 19:46:03 +00:00
std::getline( file, default_pattern );
} else {
default_pattern = "%filename - %epname";
}
}
2020-01-17 13:14:24 +00:00
auto *box = new Gtk::Box( Gtk::ORIENTATION_VERTICAL );
2019-07-12 21:10:40 +00:00
auto *menu = new Gtk::MenuBar();
2020-01-16 22:22:21 +00:00
auto *inputs = new Gtk::Grid();
auto *processing = new Gtk::Grid();
2020-01-17 13:14:24 +00:00
auto *buttons = new Gtk::Box( Gtk::ORIENTATION_HORIZONTAL );
2019-07-12 21:10:40 +00:00
add( *box );
2020-01-17 13:14:24 +00:00
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( *button_quit, false, true );
2019-07-12 21:10:40 +00:00
auto *item = new Gtk::MenuItem();
auto *submenu = new Gtk::Menu();
2020-01-17 13:14:24 +00:00
menu->append( *item );
2019-07-12 21:10:40 +00:00
// File menu
2020-01-17 13:14:24 +00:00
item->set_label( "File" );
item->set_submenu( *submenu );
2019-07-12 21:10:40 +00:00
// Exit item for File menu
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Exit" );
2019-07-12 21:10:40 +00:00
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::quit ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2019-07-12 21:10:40 +00:00
// Database menu
item = new Gtk::MenuItem();
submenu = new Gtk::Menu();
2020-01-17 13:14:24 +00:00
item->set_label( "Database" );
item->set_submenu( *submenu );
menu->append( *item );
2019-07-12 21:10:40 +00:00
// Update database
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Update database" );
2019-07-12 21:10:40 +00:00
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbUpdate ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2019-07-12 21:10:40 +00:00
// Refresh database
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Refresh database" );
2019-07-12 21:10:40 +00:00
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbRefresh ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2019-07-12 21:10:40 +00:00
// Clean database
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Clean database" );
2019-07-12 21:10:40 +00:00
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbClean ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2019-07-12 21:10:40 +00:00
// Manage database
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Manage database" );
2019-07-12 21:10:40 +00:00
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbManage ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2019-01-23 19:46:03 +00:00
item = new Gtk::MenuItem();
2020-01-17 13:14:24 +00:00
item->set_label( "Change pattern" );
item->signal_activate().connect(
sigc::mem_fun( *this, &MainWindow::dbPattern ) );
2020-01-17 13:14:24 +00:00
submenu->append( *item );
2020-01-17 13:14:24 +00:00
std::vector< Gtk::Widget * > left_aligned_widgets = {
label_show, label_language, m_entry_show, m_combo_language,
label_dir, m_entry_dir, label_pattern, m_entry_pattern,
button_pattern, button_process, m_check_linux, m_check_trust,
m_check_dvd, m_label_possible, m_combo_possible, m_button_rename,
m_button_db_add, button_dir
2020-01-16 22:22:21 +00:00
};
// set widgets' position in boxes
inputs->attach( *label_show, 0, 0, 1, 1 );
inputs->attach( *label_language, 1, 0, 1, 1 );
2020-01-16 22:22:21 +00:00
inputs->attach( *m_entry_show, 0, 1, 1, 1 );
inputs->attach( *m_combo_language, 1, 1, 1, 1 );
inputs->attach( *label_dir, 0, 2, 2, 1 );
2020-01-16 22:22:21 +00:00
inputs->attach( *m_entry_dir, 0, 3, 1, 1 );
inputs->attach( *button_dir, 1, 3, 1, 1 );
inputs->attach( *label_pattern, 0, 4, 2, 1 );
2020-01-17 13:14:24 +00:00
inputs->attach( *m_entry_pattern, 0, 5, 1, 1 );
inputs->attach( *button_pattern, 1, 5, 1, 1 );
2020-01-16 22:22:21 +00:00
inputs->set_column_homogeneous( true );
processing->attach( *button_process, 0, 0, 1, 2 );
2020-01-17 13:14:24 +00:00
processing->attach( *m_check_linux, 1, 0, 1, 1 );
processing->attach( *m_check_trust, 1, 1, 1, 1 );
2020-01-16 22:22:21 +00:00
buttons->pack_start( *m_button_rename, false, true );
buttons->pack_start( *m_button_db_add, false, true );
// set widgets alignment and margins
2020-01-17 13:14:24 +00:00
for ( auto &x : left_aligned_widgets ) {
2020-01-16 22:22:21 +00:00
x->set_halign( Gtk::ALIGN_START );
x->set_valign( Gtk::ALIGN_CENTER );
x->set_margin_left( 5 );
x->set_margin_top( 5 );
}
m_entry_show->set_halign( Gtk::ALIGN_FILL );
m_entry_dir->set_halign( Gtk::ALIGN_FILL );
m_entry_pattern->set_halign( Gtk::ALIGN_FILL );
button_quit->set_halign( Gtk::ALIGN_END );
button_quit->set_valign( Gtk::ALIGN_CENTER );
button_quit->set_margin_right( 5 );
button_quit->set_margin_top( 5 );
button_quit->set_margin_bottom( 5 );
2019-01-23 19:46:03 +00:00
// set button texts
button_process->set_label( "Process" );
button_quit->set_label( "Quit" );
button_dir->set_label( "Choose directory" );
button_pattern->set_label( "Pattern help" );
2019-07-12 21:10:40 +00:00
m_button_rename->set_label( "Rename" );
m_button_db_add->set_label( "Add to database" );
m_check_linux->set_label( "Replace windows-illegal characters" );
m_check_trust->set_label( "Don't ask for rename confirmation" );
2020-01-16 22:22:21 +00:00
m_check_dvd->set_label( "Use DVD ordering" );
2019-01-23 19:46:03 +00:00
// set label texts
label_show->set_label( "Show:" );
label_language->set_label( "Language:" );
label_dir->set_label( "Directory:" );
label_pattern->set_label( "Pattern:" );
2019-07-12 21:10:40 +00:00
m_label_possible->set_label( "Possible shows:" );
2019-01-23 19:46:03 +00:00
2019-07-12 21:10:40 +00:00
m_entry_show->set_size_request( 170, 30 );
m_entry_dir->set_size_request( 170, 30 );
2019-01-23 19:46:03 +00:00
button_dir->set_size_request( 80, 30 );
button_quit->set_size_request( 80, 30 );
button_process->set_size_request( 80, 30 );
2019-07-12 21:10:40 +00:00
m_button_rename->set_size_request( 80, 30 );
m_button_db_add->set_size_request( 80, 30 );
2019-01-23 19:46:03 +00:00
// set default pattern
2019-07-12 21:10:40 +00:00
m_entry_pattern->set_text( default_pattern );
2019-01-23 19:46:03 +00:00
// put languages in combo box
{
2019-02-04 16:39:48 +00:00
auto model = Gtk::ListStore::create( m_columns_language );
2019-07-12 21:10:40 +00:00
m_combo_language->set_model( model );
2019-02-04 16:39:48 +00:00
2020-01-16 10:12:22 +00:00
for ( const auto &x : getLangs() ) {
auto row = *( model->append() );
row[m_columns_language.m_col_code] = x.first;
row[m_columns_language.m_col_language] = x.second;
2020-01-17 13:14:24 +00:00
if ( x.first == "en" )
2020-01-16 10:12:22 +00:00
m_combo_language->set_active( row );
2019-01-23 19:46:03 +00:00
}
}
// set column to be shown in comboboxes
2019-07-12 21:10:40 +00:00
m_combo_language->pack_start( m_columns_language.m_col_language );
2020-01-16 10:12:22 +00:00
m_combo_possible->pack_start( m_columns_show.m_col_show );
// set dimensions
m_combo_language->set_size_request( 120, 30 );
m_combo_possible->set_size_request( 200, 30 );
2019-01-23 19:46:03 +00:00
// set signals
button_dir->signal_clicked().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::chooseFile ) );
button_quit->signal_clicked().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::quit ) );
button_process->signal_clicked().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::process ) );
button_pattern->signal_clicked().connect(
sigc::mem_fun( *this, &MainWindow::patternHelp ) );
2019-07-12 21:10:40 +00:00
m_button_rename->signal_clicked().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::getNames ) );
2019-07-12 21:10:40 +00:00
m_button_db_add->signal_clicked().connect(
sigc::mem_fun( *this, &MainWindow::dbAdd ) );
m_entry_show->signal_activate().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::process ) );
2019-07-12 21:10:40 +00:00
m_entry_dir->signal_activate().connect(
2019-02-04 16:39:48 +00:00
sigc::mem_fun( *this, &MainWindow::process ) );
2019-01-23 19:46:03 +00:00
// show everything except possible shows and items related to them
show_all_children();
2019-07-12 21:10:40 +00:00
m_check_linux->set_active( true );
2020-01-16 22:22:21 +00:00
m_label_possible->hide();
m_combo_possible->hide();
m_button_rename->hide();
m_button_db_add->hide();
2019-07-12 21:10:40 +00:00
}
void MainWindow::dbUpdate() {
auto *pw = new ProgressWindow;
app->add_window( *pw );
auto app_ptr = app;
2020-01-17 13:14:24 +00:00
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();
2019-07-12 21:10:40 +00:00
}
void MainWindow::dbClean() {
cleanDB();
}
void MainWindow::dbRefresh() {
auto *pw = new ProgressWindow;
app->add_window( *pw );
auto app_ptr = app;
2020-01-17 13:14:24 +00:00
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();
2019-07-12 21:10:40 +00:00
}
void MainWindow::dbAdd() {
// check required field is filled out
if ( m_entry_dir->get_text().empty() ) {
Gtk::MessageDialog dialog( *this, "Directory field is empty" );
dialog.run();
return;
}
// check directory exists
if ( !FSLib::isDirectory( m_entry_dir->get_text() ) ) {
Gtk::MessageDialog dialog( *this, "Directory doesn't exist" );
dialog.run();
return;
}
auto iter = m_combo_possible->get_active();
std::string input_pattern = m_entry_pattern->get_text();
2020-01-17 13:14:24 +00:00
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] );
2019-07-12 21:10:40 +00:00
auto *pw = new ProgressWindow;
app->add_window( *pw );
auto app_ptr = app;
2020-01-17 13:14:24 +00:00
pw->signal_hide().connect( [pw, app_ptr]() {
app_ptr->remove_window( *pw );
delete pw;
} );
std::thread t( addToDB, std::move( show ), m_entry_dir->get_text(),
std::move( language_code ), std::move( show_id ),
m_entry_pattern->get_text(), !m_check_linux->get_active(),
m_check_dvd->get_active(), pw );
t.detach();
pw->show();
2019-07-12 21:10:40 +00:00
}
void MainWindow::dbManage() {
auto *dbWindow = new DatabaseWindow( !m_check_linux->get_active(), app );
2019-07-12 21:10:40 +00:00
app->add_window( *dbWindow );
auto app_ptr = app;
2020-01-17 13:14:24 +00:00
dbWindow->signal_hide().connect( [dbWindow, app_ptr]() {
app_ptr->remove_window( *dbWindow );
delete dbWindow;
} );
2019-07-12 21:10:40 +00:00
dbWindow->show();
2019-01-23 19:46:03 +00:00
}
void MainWindow::dbPattern() {
// Create a custom dialog box for pattern change
2020-01-17 13:14:24 +00:00
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();
2020-01-17 13:14:24 +00:00
std::unique_ptr< Gtk::Entry > pattern_entry( new Gtk::Entry );
content->pack_start( *pattern_entry );
dialog->add_button( "_Cancel", Gtk::RESPONSE_CANCEL );
dialog->add_button( "_OK", Gtk::RESPONSE_OK );
dialog->show_all_children();
dialog->signal_response().connect(
2020-01-17 13:14:24 +00:00
[&pattern, &pattern_entry]( int response ) {
if ( response == Gtk::RESPONSE_OK )
pattern = pattern_entry->get_text();
2020-01-17 13:14:24 +00:00
} );
pattern_entry->set_text( pattern );
auto response = dialog->run();
2020-01-17 13:14:24 +00:00
if ( response == Gtk::RESPONSE_OK ) {
changeDBPattern( pattern );
}
}