/* $Id$ */ /* * Cantus Tag Editor * Copyright © 2002-2004 by Samuel Abels * Copyright © 2007 by Tim Huetz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see **/ /* some headers which are just needed inside this source file */ #include #include // For fork(), execlp() Mainwindow::Mainwindow() { this->m_lockevents = FALSE; this->m_pWindow = NULL; this->m_fileBrowser = NULL; this->m_pluginArea1 = NULL; this->m_pluginArea2 = NULL; this->m_applicationLogo = NULL; this->m_aboutDialog = NULL; } Mainwindow::~Mainwindow() { if( NULL != this->m_fileBrowser ) { delete( this->m_fileBrowser ); this->m_fileBrowser = NULL; } if( NULL != this->m_pluginArea1 ) { delete( this->m_pluginArea1 ); this->m_pluginArea1 = NULL; } if( NULL != this->m_pluginArea2 ) { delete( this->m_pluginArea2 ); this->m_pluginArea2 = NULL; } if( NULL != this->m_applicationLogo ) { delete( this->m_applicationLogo ); this->m_applicationLogo = NULL; } if( NULL != this->m_aboutDialog ) { delete( this->m_aboutDialog ); this->m_aboutDialog = NULL; } } Gtk::Window *Mainwindow::create() { /* load the Glade file and instantiate its widgets */ try { this->m_refXml = Gnome::Glade::Xml::create( PACKAGE_DATA_DIR "/cantus/glade/cantus.glade", "mainwindow" ); } catch( const Gnome::Glade::XmlError & err ) { std::cerr << err.what() << '\n'; return( NULL ); } /* get the Glade-instantiated Dialog */ this->m_refXml->get_widget( "mainwindow", this->m_pWindow ); this->m_refXml->get_widget( "table_main", this->m_table ); this->m_refXml->get_widget( "statusbar", this->m_statusbar ); this->m_refXml->get_widget( "progressbar", this->m_progressbar ); this->m_table->set_border_width( 5 ); /* create a HPaned in the upper row of the table */ this->m_hPaned = new Gtk::HPaned; this->m_table->attach( *this->m_hPaned, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); /* create a notebook in the left side of the hpaned */ this->m_notebook = new Gtk::Notebook; this->m_notebook->set_show_tabs( FALSE ); this->m_notebook->set_show_border( FALSE ); this->m_hPaned->pack1( *this->m_notebook, Gtk::FILL|Gtk::EXPAND ); /* create the filebrowser in the notebook */ this->m_fileBrowser = new FileBrowser; this->m_notebook->append_page( *this->m_fileBrowser, _( "Browser" ) ); /* pluginarea1 */ this->m_pluginArea1 = new PluginArea( TRUE ); this->m_pluginArea1->set_size_request( 350, -1 ); this->m_pluginArea1->show(); this->m_hPaned->pack2( *this->m_pluginArea1, Gtk::FILL ); /* pluginarea2 */ this->m_pluginArea2 = new PluginArea( FALSE ); this->m_table->attach( *this->m_pluginArea2, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL, 0, 0 ); this->m_pluginArea2->set_size_request( -1, 200 ); /* position the pane and show all the stuff we've added */ this->m_hPaned->set_position( 200000 ); this->m_table->show_all(); /* connect the required signals to the window class */ this->connectSignals(); /* return the created window class */ return( this->m_pWindow ); } void Mainwindow::connectSignals() { g_return_if_fail( this->m_pWindow != NULL ); Gtk::MenuItem * widget = NULL; /* file menu */ this->m_refXml->get_widget( "menu_file_quit", widget ); widget->signal_activate().connect( sigc::mem_fun( *this->m_pWindow, &Gtk::Window::hide ) ); this->m_refXml->get_widget( "menu_file_save", widget ); widget->signal_activate().connect( this->signalMenuFileSaveActivate ); /* view menu */ this->m_refXml->get_widget( "menu_view_pluginarea1", widget ); widget->signal_activate().connect( sigc::mem_fun( *this, &Mainwindow::onMenuViewPluginarea1Activate ) ); this->m_refXml->get_widget( "menu_view_pluginarea2", widget ); widget->signal_activate().connect( sigc::mem_fun( *this, &Mainwindow::onMenuViewPluginarea2Activate ) ); /* edit menu */ this->m_refXml->get_widget( "menu_edit_preferences", widget ); widget->signal_activate().connect( this->signalMenuEditPreferencesActivate ); /* help menu */ this->m_refXml->get_widget( "menu_help_contents", widget ); widget->signal_activate().connect( sigc::mem_fun( *this, &Mainwindow::onMenuHelpContentsActivate ) ); this->m_refXml->get_widget( "menu_help_about", widget ); widget->signal_activate().connect( sigc::mem_fun( *this, &Mainwindow::onMenuHelpAboutActivate ) ); this->m_fileBrowser->signal_filelist_selection_changed.connect( this->signalFileBrowserSelectionChanged ); this->m_pluginArea1->signal_widget_removed.connect( this->signalPluginareaWidgetRemoved ); this->m_pluginArea2->signal_widget_removed.connect( this->signalPluginareaWidgetRemoved ); } void Mainwindow::pluginareaUpdate( std::list * plugins ) { this->m_pluginArea1->plugins_set( plugins ); this->m_pluginArea2->plugins_set( plugins ); } void Mainwindow::setStatus( std::string status ) { this->m_statusbar->pop(); this->m_statusbar->push( status ); } void Mainwindow::setProgress( double percent ) { this->m_progressbar->set_fraction( percent ); } void Mainwindow::pluginarea1SetActive( gboolean active ) { if( active == this->m_pluginArea1->is_visible() ) { return; } if( active ) { this->m_table->remove( *this->m_notebook ); this->m_table->attach( *this->m_hPaned, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); this->m_hPaned->add1( *this->m_notebook ); this->m_pluginArea1->show(); } else { this->m_pluginArea1->hide(); this->m_hPaned->remove( *this->m_notebook ); this->m_table->remove( *this->m_hPaned ); this->m_table->attach( *this->m_notebook, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); } Gtk::CheckMenuItem * widget = NULL; this->m_lockevents = TRUE; this->m_refXml->get_widget( "menu_view_pluginarea1", widget )->set_active( active ); this->m_lockevents = FALSE; this->signalPluginarea1VisibilityChanged.emit( active ); } void Mainwindow::pluginarea2SetActive( gboolean active ) { if( active == this->m_pluginArea2->is_visible() ) { return; } if( active ) { this->m_table->resize( 2, 1 ); this->m_table->attach( *this->m_pluginArea2, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL ); this->m_pluginArea2->show(); } else { this->m_pluginArea2->hide(); this->m_table->remove( *this->m_pluginArea2); this->m_table->resize( 1, 1 ); } Gtk::CheckMenuItem * widget = NULL; this->m_lockevents = TRUE; this->m_refXml->get_widget( "menu_view_pluginarea2", widget )->set_active( active ); this->m_lockevents = FALSE; this->signalPluginarea2VisibilityChanged.emit( active ); } void Mainwindow::onMenuHelpContentsActivate() { pid_t pid; if( ( pid = fork() ) == 0 ) { execlp( "gnome-help", "gnome-help", "ghelp:" GETTEXT_PACKAGE ); g_error( _( "Cannot launch gnome-help" ) ); } } Glib::ustring Mainwindow::listToString( const std::vector & inputList ) { std::vector::const_iterator i = inputList.begin(); Glib::ustring returnString( "" ); for( ; i != inputList.end(); i++ ) { returnString.append( *i ); returnString.append( "\n" ); } return( returnString ); } void Mainwindow::onMenuHelpAboutActivate() { /* we have just to initialize the needed classes for the about dialog if we haven't do this before */ if( NULL == this->m_aboutDialog ) { /* some local variables we need */ Glib::ustring licenseString( "This program is free software: you can redistribute it " \ "and/or modify it under the terms of the GNU General " \ "Public License as published by the Free Software " \ "Foundation, either version 3 of the License, or " \ "(at your option) any later version.\n" \ "\n" \ "This program is distributed in the hope that it will be " \ "useful, but WITHOUT ANY WARRANTY; without even the implied warranty of " \ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " \ "GNU General Public License for more details.\n" \ "\n" \ "You should have received a copy of the GNU General Public License " \ "along with this program. If not, see " ); std::vector authorList; std::vector documenterList; std::vector artistList; std::vector translatorList; /* create the needed classes */ this->m_applicationLogo = new Gtk::Image( PACKAGE_PIXMAPS_DIR "/logo/cantus_tag.png" ); this->m_aboutDialog = new Gtk::AboutDialog(); /* generate the list of all authors */ authorList.push_back( "Samuel Abels " ); authorList.push_back( "Tim Hütz " ); /* generate the list of all documenters */ documenterList.push_back( "Samuel Abels " ); /* generate the list of all artists */ artistList.push_back( "Samuel Abels " ); /* generate the list of all translators */ translatorList.push_back( "Samuel Abels " ); translatorList.push_back( "Tim Hütz " ); /* set some information about the running application */ this->m_aboutDialog->set_name( "Cantus" ); this->m_aboutDialog->set_logo_icon_name( PACKAGE_PIXMAPS_DIR "/logo/cantus_tag.png" ); this->m_aboutDialog->set_logo( this->m_applicationLogo->get_pixbuf() ); this->m_aboutDialog->set_translator_credits( this->listToString( translatorList ) ); this->m_aboutDialog->set_comments( "Build on " BUILD_DATE " at " BUILD_TIME ); this->m_aboutDialog->set_version( PACKAGE_VERSION ); this->m_aboutDialog->set_copyright( "© 2002-2004 by Samuel Abels. All rights reserved.\n© 2007 by Tim Hütz. All rights reserved." ); this->m_aboutDialog->set_license( licenseString ); this->m_aboutDialog->set_wrap_license( true ); this->m_aboutDialog->set_website( "http://debain.org/software/cantus" ); this->m_aboutDialog->set_authors( authorList ); this->m_aboutDialog->set_documenters( documenterList ); this->m_aboutDialog->set_artists( artistList ); } /* show the dialog to the user and wait until he clicks close */ this->m_aboutDialog->run(); this->m_aboutDialog->hide(); } void Mainwindow::onMenuViewPluginarea1Activate() { if( this->m_lockevents ) { return; } this->pluginarea1SetActive( !this->m_pluginArea1->is_visible() ); } void Mainwindow::onMenuViewPluginarea2Activate() { if( this->m_lockevents ) { return; } this->pluginarea2SetActive( !this->m_pluginArea2->is_visible() ); }