99 lines
3.7 KiB
C++
99 lines
3.7 KiB
C++
|
#include <gtkmm/liststore.h>
|
||
|
#include <iostream>
|
||
|
|
||
|
#include "databasewindow.hpp"
|
||
|
#include "functions.hpp"
|
||
|
|
||
|
DatabaseWindow::~DatabaseWindow() {
|
||
|
delete m_button_save;
|
||
|
delete m_button_remove;
|
||
|
delete m_tree_database;
|
||
|
std::cout << "Deleting" << std::endl;
|
||
|
}
|
||
|
|
||
|
DatabaseWindow::DatabaseWindow( bool _linux, Curl &_c ) : c(_c), linux(_linux) {
|
||
|
set_title( "Database" );
|
||
|
|
||
|
set_default_size( 550, 350 );
|
||
|
set_resizable( false );
|
||
|
|
||
|
auto *layout = new Gtk::Layout();
|
||
|
add( *layout );
|
||
|
|
||
|
m_scrolled_window->set_size_request( 550, 300 );
|
||
|
m_scrolled_window->add( *m_tree_database );
|
||
|
|
||
|
// set widgets' location
|
||
|
layout->put( *m_scrolled_window, 0, 0 );
|
||
|
layout->put( *m_button_save, 380, 310 );
|
||
|
layout->put( *m_button_remove, 470, 310 );
|
||
|
|
||
|
// set button texts
|
||
|
m_button_save->set_label( "Save" );
|
||
|
m_button_remove->set_label( "Delete" );
|
||
|
|
||
|
// set dimensions
|
||
|
m_button_save->set_size_request( 80, 30 );
|
||
|
m_button_remove->set_size_request( 80, 30 );
|
||
|
|
||
|
// put languages in combo box
|
||
|
m_model = Gtk::ListStore::create( m_columns_database );
|
||
|
m_tree_database->set_model( m_model );
|
||
|
|
||
|
for( auto &x : dbGetShows() ) {
|
||
|
if( x["SHOW"] == "pattern" )
|
||
|
continue;
|
||
|
auto row = *( m_model->append() );
|
||
|
row[m_columns_database.m_col_id] = std::stoi(x["ID"]);
|
||
|
row[m_columns_database.m_col_show] = x["SHOW"];
|
||
|
row[m_columns_database.m_col_path] = x["PATH"];
|
||
|
row[m_columns_database.m_col_lang] = x["LANGUAGE"];
|
||
|
row[m_columns_database.m_col_url] = x["URL"];
|
||
|
}
|
||
|
|
||
|
m_tree_database->append_column_editable( "Show", m_columns_database.m_col_show );
|
||
|
m_tree_database->append_column_editable( "Path", m_columns_database.m_col_path );
|
||
|
m_tree_database->append_column_editable( "Language", m_columns_database.m_col_lang );
|
||
|
m_tree_database->append_column_editable( "URL", m_columns_database.m_col_url );
|
||
|
|
||
|
m_button_save->signal_clicked().connect(
|
||
|
sigc::mem_fun( *this, &DatabaseWindow::save ) );
|
||
|
m_button_remove->signal_clicked().connect(
|
||
|
sigc::mem_fun( *this, &DatabaseWindow::remove ) );
|
||
|
m_model->signal_row_changed().connect(
|
||
|
sigc::mem_fun( *this, &DatabaseWindow::changed ) );
|
||
|
|
||
|
// show everything
|
||
|
layout->show();
|
||
|
layout->show_all_children();
|
||
|
}
|
||
|
|
||
|
void DatabaseWindow::save() {
|
||
|
for( auto &x : m_model->children() ) {
|
||
|
auto index = static_cast<size_t> ( x[m_columns_database.m_col_id] );
|
||
|
if( changed_rows.find(index) != changed_rows.end() ) {
|
||
|
auto index = static_cast< size_t > ( x[m_columns_database.m_col_id] );
|
||
|
auto show = static_cast< std::string > ( x[m_columns_database.m_col_show] );
|
||
|
auto path = static_cast< std::string > ( x[m_columns_database.m_col_path] );
|
||
|
auto lang = static_cast< std::string > ( x[m_columns_database.m_col_lang] );
|
||
|
auto url = static_cast< std::string > ( x[m_columns_database.m_col_url] );
|
||
|
std::cout << index << " " << show << " " << path << " " << lang << " " << url << std::endl;
|
||
|
changeDB( index, path, lang, url, c );
|
||
|
refreshSingleDB( index, linux, c );
|
||
|
}
|
||
|
}
|
||
|
cleanDB();
|
||
|
changed_rows.clear();
|
||
|
}
|
||
|
|
||
|
void DatabaseWindow::remove() {
|
||
|
auto selected = m_tree_database->get_selection()->get_selected();
|
||
|
std::cout << static_cast< size_t > ( (*selected)[m_columns_database.m_col_id] ) << std::endl;
|
||
|
removeFromDB( static_cast< std::string > ( (*selected)[m_columns_database.m_col_path] ) );
|
||
|
m_model->erase(selected);
|
||
|
}
|
||
|
|
||
|
void DatabaseWindow::changed( const Gtk::TreeModel::Path &/*UNUSED*/, const Gtk::TreeModel::iterator &row ) {
|
||
|
changed_rows.insert( static_cast< size_t > ( (*row)[m_columns_database.m_col_id] ) );
|
||
|
}
|