config_editor.cpp

00001
00002 /***************************************************************************
00003  *  config_editor.cpp - Fawkes Config Editor
00004  *
00005  *  Created: Tue Sep 23 13:21:49 2008
00006  *  Copyright  2008  Daniel Beck
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022
00023 #include "config_editor.h"
00024 #include "config_tree_view.h"
00025 #include "retriever_config_plugin.h"
00026 #include "naostiffness_config_plugin.h"
00027
00028 #include <gui_utils/utils.h>
00029 #include <gui_utils/service_selector_cbe.h>
00030 #include <netcomm/fawkes/client.h>
00031
00032 #include <cstdlib>
00033 #include <cstring>
00034 #include <iostream>
00035
00036 using namespace std;
00037 using namespace fawkes;
00038 
00039 /** @class FawkesConfigEditor tools/config_editor/config_editor.h
00040  * Graphical configuration editor.
00041  *
00042  * @author Daniel Beck
00043  */
00044 
00045 /** Constructor.
00046  * @param ref_xml Glade XML file
00047  */
00048 FawkesConfigEditor::FawkesConfigEditor( Glib::RefPtr<Gnome::Glade::Xml> ref_xml )
00049 {
00050   m_wnd_main = dynamic_cast<Gtk::Window*>( get_widget(ref_xml, "wndMain") );
00051   m_btn_exit = dynamic_cast<Gtk::Button*>( get_widget(ref_xml, "btnExit") );
00052
00053   m_trv_config = NULL;
00054   ref_xml->get_widget_derived("trvConfig", m_trv_config);
00055   m_trv_config->register_plugin( new RetrieverConfigPlugin( RESDIR"/glade/config_editor/retriever_config_plugin.glade" ) );
00056   m_trv_config->register_plugin(new NaoStiffnessConfigPlugin(RESDIR"/glade/config_editor/naostiffness_config_plugin.glade"));
00057
00058   m_btn_exit->signal_clicked().connect( sigc::mem_fun( *this, &FawkesConfigEditor::on_btn_exit_clicked) );
00059
00060   m_service_selector = new ServiceSelectorCBE(ref_xml, "cbeHosts", "btnConnect");
00061   m_service_selector->signal_connected().connect( sigc::mem_fun( *this, &FawkesConfigEditor::on_connected) );
00062   m_service_selector->signal_disconnected().connect( sigc::mem_fun( *this, &FawkesConfigEditor::on_disconnected) );
00063 }
00064 
00065 /** Destructor. */
00066 FawkesConfigEditor::~FawkesConfigEditor()
00067 {
00068   delete m_service_selector;
00069 }
00070 
00071 /** Obtain a reference to the main window of the application.
00072  * @return reference to the main window
00073  */
00074 Gtk::Window&
00075 FawkesConfigEditor::get_window() const
00076 {
00077   return *m_wnd_main;
00078 }
00079
00080 void
00081 FawkesConfigEditor::on_btn_exit_clicked()
00082 {
00083   m_wnd_main->hide();
00084 }
00085
00086 void
00087 FawkesConfigEditor::on_connected()
00088 {
00089   m_network_client = m_service_selector->get_network_client();
00090   m_trv_config->set_network_client( m_network_client );
00091   m_wnd_main->set_title("Fawkes Config Editor @ " + m_service_selector->get_name());
00092 }
00093
00094 void
00095 FawkesConfigEditor::on_disconnected()
00096 {
00097   m_trv_config->set_network_client( NULL );
00098   m_wnd_main->set_title("Fawkes Config Editor");
00099 }