SearchWindow
This commit is contained in:
parent
8e4f348b8d
commit
623720c9e3
121
searchwindow.cpp
Normal file
121
searchwindow.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/liststore.h>
|
||||
#include <gtkmm/messagedialog.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "gtkfunctions.hpp"
|
||||
#include "searchwindow.hpp"
|
||||
#include "tv_rename.hpp"
|
||||
|
||||
void SearchWindow::search() {
|
||||
language_code =
|
||||
( *m_combo_language->get_active() )[m_columns_language.m_col_code];
|
||||
|
||||
searchShow( m_entry_show, m_combo_possible, m_columns_show.m_col_show,
|
||||
m_columns_show.m_col_id, language_code, this );
|
||||
}
|
||||
|
||||
void SearchWindow::select() {
|
||||
search_show =
|
||||
( *m_combo_possible->get_active() )[m_columns_show.m_col_show];
|
||||
search_id = ( *m_combo_possible->get_active() )[m_columns_show.m_col_id];
|
||||
quit();
|
||||
}
|
||||
|
||||
void SearchWindow::quit() {
|
||||
hide();
|
||||
}
|
||||
|
||||
SearchWindow::~SearchWindow() {
|
||||
auto children = get_children();
|
||||
freeChildren( children );
|
||||
}
|
||||
|
||||
SearchWindow::SearchWindow( std::string &_show, std::string &_id,
|
||||
std::string &_lang,
|
||||
std::map< std::string, std::string > &_languages )
|
||||
: search_show( _show ), search_id( _id ), language_code( _lang ),
|
||||
language_map( _languages ) {
|
||||
set_title( "Select show" );
|
||||
property_modal().set_value( true );
|
||||
set_resizable( false );
|
||||
|
||||
auto *box = new Gtk::Box( Gtk::ORIENTATION_VERTICAL );
|
||||
add( *box );
|
||||
auto *hbox = new Gtk::Box( Gtk::ORIENTATION_HORIZONTAL );
|
||||
auto *buttons = new Gtk::Box( Gtk::ORIENTATION_HORIZONTAL );
|
||||
box->pack_start( *hbox, Gtk::PACK_EXPAND_WIDGET );
|
||||
box->pack_start( *m_combo_possible, Gtk::PACK_SHRINK );
|
||||
box->pack_start( *buttons, Gtk::PACK_EXPAND_WIDGET );
|
||||
hbox->pack_start( *m_entry_show, Gtk::PACK_EXPAND_WIDGET );
|
||||
hbox->pack_start( *m_combo_language, Gtk::PACK_EXPAND_WIDGET );
|
||||
auto *search_button = new Gtk::Button( "Search" );
|
||||
hbox->pack_start( *search_button, Gtk::PACK_SHRINK );
|
||||
auto *select_button = new Gtk::Button( "Select" );
|
||||
auto *cancel_button = new Gtk::Button( "Cancel" );
|
||||
buttons->pack_end( *cancel_button, Gtk::PACK_SHRINK );
|
||||
buttons->pack_end( *select_button, Gtk::PACK_SHRINK );
|
||||
|
||||
hbox->set_margin_top( 5 );
|
||||
hbox->set_margin_left( 5 );
|
||||
hbox->set_margin_right( 5 );
|
||||
m_entry_show->set_margin_right( 5 );
|
||||
m_entry_show->set_valign( Gtk::ALIGN_CENTER );
|
||||
m_combo_language->set_margin_right( 5 );
|
||||
m_combo_language->set_halign( Gtk::ALIGN_CENTER );
|
||||
m_combo_language->set_valign( Gtk::ALIGN_CENTER );
|
||||
search_button->set_halign( Gtk::ALIGN_CENTER );
|
||||
search_button->set_valign( Gtk::ALIGN_CENTER );
|
||||
|
||||
m_combo_possible->set_margin_top( 5 );
|
||||
m_combo_possible->set_margin_right( 5 );
|
||||
m_combo_possible->set_margin_left( 5 );
|
||||
m_combo_possible->set_halign( Gtk::ALIGN_CENTER );
|
||||
m_combo_possible->set_valign( Gtk::ALIGN_CENTER );
|
||||
|
||||
buttons->set_margin_top( 5 );
|
||||
buttons->set_margin_left( 5 );
|
||||
buttons->set_margin_bottom( 5 );
|
||||
buttons->set_margin_right( 5 );
|
||||
select_button->set_margin_right( 5 );
|
||||
select_button->set_halign( Gtk::ALIGN_CENTER );
|
||||
select_button->set_valign( Gtk::ALIGN_CENTER );
|
||||
cancel_button->set_halign( Gtk::ALIGN_CENTER );
|
||||
cancel_button->set_valign( Gtk::ALIGN_CENTER );
|
||||
|
||||
select_button->set_size_request( 80, 30 );
|
||||
cancel_button->set_size_request( 80, 30 );
|
||||
|
||||
{
|
||||
auto model = Gtk::ListStore::create( m_columns_language );
|
||||
m_combo_language->set_model( model );
|
||||
|
||||
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;
|
||||
if ( x.first == "en" )
|
||||
m_combo_language->set_active( row );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto model = Gtk::ListStore::create( m_columns_show );
|
||||
m_combo_possible->set_model( model );
|
||||
}
|
||||
|
||||
m_combo_language->pack_start( m_columns_language.m_col_language );
|
||||
m_combo_possible->pack_start( m_columns_show.m_col_show );
|
||||
|
||||
search_button->signal_clicked().connect(
|
||||
sigc::mem_fun( *this, &SearchWindow::search ) );
|
||||
select_button->signal_clicked().connect(
|
||||
sigc::mem_fun( *this, &SearchWindow::select ) );
|
||||
cancel_button->signal_clicked().connect(
|
||||
sigc::mem_fun( *this, &SearchWindow::quit ) );
|
||||
|
||||
// show everything
|
||||
show_all_children();
|
||||
m_combo_possible->hide();
|
||||
}
|
55
searchwindow.hpp
Normal file
55
searchwindow.hpp
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef GTKMM_SEARCH_WINDOW
|
||||
#define GTKMM_SEARCH_WINDOW
|
||||
|
||||
#include <gtkmm/combobox.h>
|
||||
#include <gtkmm/treeview.h>
|
||||
#include <gtkmm/window.h>
|
||||
#include <unordered_set>
|
||||
|
||||
class SearchWindow : public Gtk::Window {
|
||||
public:
|
||||
SearchWindow() = delete;
|
||||
SearchWindow( std::string &_show, std::string &_id, std::string &_lang,
|
||||
std::map< std::string, std::string > &_languages );
|
||||
virtual ~SearchWindow();
|
||||
|
||||
private:
|
||||
void search();
|
||||
void select();
|
||||
void quit();
|
||||
|
||||
protected:
|
||||
class LanguageColumns : public Gtk::TreeModel::ColumnRecord {
|
||||
public:
|
||||
LanguageColumns() {
|
||||
add( m_col_code );
|
||||
add( m_col_language );
|
||||
}
|
||||
Gtk::TreeModelColumn< std::string > m_col_code;
|
||||
Gtk::TreeModelColumn< std::string > m_col_language;
|
||||
};
|
||||
|
||||
class ShowColumns : public Gtk::TreeModel::ColumnRecord {
|
||||
public:
|
||||
ShowColumns() {
|
||||
add( m_col_id );
|
||||
add( m_col_show );
|
||||
}
|
||||
Gtk::TreeModelColumn< std::string > m_col_id;
|
||||
Gtk::TreeModelColumn< std::string > m_col_show;
|
||||
};
|
||||
|
||||
LanguageColumns m_columns_language;
|
||||
ShowColumns m_columns_show;
|
||||
|
||||
Gtk::Entry *m_entry_show = new Gtk::Entry();
|
||||
Gtk::ComboBox *m_combo_possible = new Gtk::ComboBox();
|
||||
Gtk::ComboBox *m_combo_language = new Gtk::ComboBox();
|
||||
|
||||
std::string &search_show;
|
||||
std::string &search_id;
|
||||
std::string &language_code;
|
||||
std::map< std::string, std::string > &language_map;
|
||||
};
|
||||
|
||||
#endif // GTKMM_MAIN_WINDOW
|
Loading…
Reference in New Issue
Block a user