Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/vlg/develop/gwavmerger/src/PrefWindow.cpp

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //------------------------------------------------------------------------------
00003 //                              PrefWindow.cpp
00004 //------------------------------------------------------------------------------
00005 // $Id: PrefWindow.cpp,v 1.6 2003/02/07 05:15:10 vlg Exp $
00006 //------------------------------------------------------------------------------
00007 //  Copyright (c) 2002 by Vladislav Grinchenko
00008 //
00009 //  This program is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU General Public License
00011 //  as published by the Free Software Foundation; either version
00012 //  2 of the License, or (at your option) any later version.
00013 //------------------------------------------------------------------------------
00014 // Created: 01/06/2002
00015 //------------------------------------------------------------------------------
00016 
00017 #include <assa/Logger.h>
00018 #include <assa/Assert.h>
00019 
00020 #include <gtkmm/box.h>
00021 #include <gtkmm/label.h>
00022 #include <gtkmm/button.h>
00023 #include <gtkmm/table.h>
00024 #include <gtkmm/entry.h>
00025 #include <gtkmm/main.h>
00026 
00027 #include "PrefWindow.h"
00028 #include "Config.h"
00029 
00030 using ASSA::TRACE;
00031 using ASSA::APP;
00032 
00033 
00034 PrefWindow::PrefWindow (Config& config_)
00035     : MyPropertyBox ("Preferences"),
00036       m_config (config_),
00037       m_merge_map_pref (*this),
00038       m_ignore_callbacks (true),
00039       m_changed (false)
00040 {
00041     trace("PrefWindow::PrefWindow");
00042 
00043     Gtk::VBox*   vbox       = manage (new Gtk::VBox ());
00044     Gtk::Label*  tab1_label = manage (new Gtk::Label ("Project Settings"));
00045     Gtk::Label*  tab2_label = manage (new Gtk::Label ("Merge Map"));
00046 
00047     // Name/Path table
00048 
00049     Gtk::Label* label;
00050     Gtk::Table*  table = manage (new Gtk::Table (2, 2, FALSE));
00051 
00052     label  = manage (new Gtk::Label ("Project Name"));
00053     label->set_justify (Gtk::JUSTIFY_LEFT);
00054     table->attach (*label, 0, 1, 0, 1);
00055     m_proj_name = manage (new Gtk::Entry ());
00056     table->attach (*m_proj_name, 1, 2, 0, 1);
00057     
00058     label  = manage (new Gtk::Label ("Project Path"));
00059     label->set_justify (Gtk::JUSTIFY_LEFT);
00060     table->attach (*label, 0, 1, 1, 2);
00061     m_path_entry = manage (new Gnome::UI::FileEntry ("PathSel", 
00062                                                      "Select Project Path"));
00063     table->attach (*m_path_entry, 1, 2, 1, 2);
00064     vbox->pack_start (*table);
00065 
00066     // Prefixes & directories table
00067     table = manage (new Gtk::Table (2, 4, FALSE));
00068 
00069     label = manage (new Gtk::Label ("Directory A"));
00070     label->set_justify (Gtk::JUSTIFY_LEFT);
00071     table->attach (*label, 0, 1, 0, 1);
00072     m_A_dir = manage (new Gtk::Entry ());
00073     table->attach (*m_A_dir, 1, 2, 0, 1);
00074 
00075     label = manage (new Gtk::Label ("Prefix A"));
00076     label->set_justify (Gtk::JUSTIFY_LEFT);
00077     table->attach (*label, 0, 1, 1, 2);
00078     m_A_prefix = manage (new Gtk::Entry ());
00079     table->attach (*m_A_prefix, 1, 2, 1, 2);
00080 
00081     label = manage (new Gtk::Label ("Directory B"));
00082     label->set_justify (Gtk::JUSTIFY_LEFT);
00083     table->attach (*label, 0, 1, 2, 3);
00084     m_B_dir = manage (new Gtk::Entry ());
00085     table->attach (*m_B_dir, 1, 2, 2, 3);
00086     
00087     label  = manage (new Gtk::Label ("Prefix B"));
00088     label->set_justify (Gtk::JUSTIFY_LEFT);
00089     table->attach (*label, 0, 1, 3, 4);
00090     m_B_prefix = manage (new Gtk::Entry ());
00091     table->attach (*m_B_prefix, 1, 2, 3, 4);
00092     vbox->pack_start (*table);
00093 
00096     m_proj_name->signal_changed().connect (
00097         SigC::slot (*this, &PrefWindow::changed_cb));
00098     m_A_prefix ->signal_changed().connect (
00099         SigC::slot (*this, &PrefWindow::changed_cb));
00100     m_B_prefix ->signal_changed().connect (
00101         SigC::slot (*this, &PrefWindow::changed_cb));
00102     m_A_dir    ->signal_changed().connect (
00103         SigC::slot (*this, &PrefWindow::changed_cb));
00104     m_B_dir    ->signal_changed().connect (
00105         SigC::slot (*this, &PrefWindow::changed_cb));
00106 
00107     Gtk::Entry* entry = 
00108         dynamic_cast<Gtk::Entry*> (m_path_entry->gtk_entry ());
00109     entry->signal_changed().connect (
00110         SigC::slot (*this, &PrefWindow::changed_cb));
00111 
00114     m_merge_map_pref.set_pre_delay (m_config.get_pre_delay ().c_str ());
00115     m_merge_map_pref.set_post_delay (m_config.get_post_delay ().c_str ());
00116 
00119     vbox->show_all ();
00120     m_merge_map_pref.show_all ();
00121 
00122     set_title ("Preferences");
00123     append_page (*vbox, "Project Settings");
00124     append_page (m_merge_map_pref.get_vbox (), "Merge Map");
00125 }
00126 
00127 
00139 bool
00140 
00141 PrefWindow::run ()
00142 {
00143     trace("PrefWindow::run");
00144 
00145     m_ignore_callbacks = true;  
00146     m_changed = false;
00147 
00148     m_proj_name->set_text (m_config.get_proj_name ());
00149 
00150     m_path_entry->set_directory_entry ();
00151     m_path_entry->set_default_path (m_config.get_proj_path ());
00152 
00153     Gtk::Entry* entry = 
00154         dynamic_cast<Gtk::Entry*> (m_path_entry->gtk_entry ());
00155     entry->set_text (m_config.get_proj_path ());
00156 
00157     m_A_prefix->set_text (m_config.get_A_prefix ());
00158     m_B_prefix->set_text (m_config.get_B_prefix ());
00159 
00160     m_A_dir->set_text (m_config.get_A_dir ());
00161     m_B_dir->set_text (m_config.get_B_dir ());
00162 
00163     m_ignore_callbacks = false;
00164     m_apply_button->set_sensitive (false);
00165 
00166     show ();
00167     Gtk::Main::run ();
00168     return m_changed;
00169 }
00170 
00171 void 
00172 
00173 PrefWindow::apply_impl ()
00174 {
00175     trace("PrefWindow::apply_impl");
00176 
00177     DL((APP,"Preferences(view) state:\n"));
00178     dump ();
00179 
00180     string s = m_proj_name->get_text ();
00181     if (m_config.get_proj_name () != s) {
00182         m_config.set_proj_name (s);
00183         m_changed = true;
00184     }
00185 
00186     s = m_path_entry->get_full_path (true);
00187 #if 0
00188     /* remove bogus last segment of the path */
00189     {
00190         std::string::size_type idx;
00191         idx = s.rfind ("/");
00192         if (idx != std::string::npos) {
00193             s.resize (idx);
00194         }
00195     }
00196 #endif
00197     if (m_config.get_proj_path () != s) {
00198         m_config.set_proj_path (s);
00199         m_changed = true;
00200     }
00201 
00202     s = m_A_prefix->get_text ();
00203     if (m_config.get_A_prefix () != s) {
00204         m_config.set_A_prefix (s);
00205         m_changed = true;
00206     }
00207 
00208     s = m_B_prefix->get_text ();
00209     if (m_config.get_B_prefix () != s) { 
00210         m_config.set_B_prefix  (s);
00211         m_changed = true;
00212     }
00213 
00214     s = m_A_dir->get_text ();
00215     if (m_config.get_A_dir () != s) {
00216         m_config.set_A_dir (s);
00217         m_changed = true;
00218     }
00219 
00220     s = m_B_dir->get_text ();
00221     if (m_config.get_B_dir () != s) {
00222         m_config.set_B_dir (s);
00223         m_changed = true;
00224     }
00225     
00226     m_config.dump ();
00227     m_merge_map_pref.dump ();
00228     
00229     s = m_merge_map_pref.get_pre_delay ();
00230     if (m_config.get_pre_delay () != s) {
00231         m_config.set_pre_delay (s);
00232         m_changed = true;
00233     }
00234 
00235     s = m_merge_map_pref.get_post_delay ();
00236     if (m_config.get_post_delay () != s) {
00237         m_config.set_post_delay (s);
00238         m_changed = true;
00239     }
00240 
00241     DL((APP,"Config(model) state:\n"));
00242     m_config.dump ();
00243 }
00244 
00245 void 
00246 
00247 PrefWindow::dump () const
00248 {
00249     DL((TRACE,"proj_name : \"%s\"\n", m_proj_name->get_text ().c_str ()));
00250     DL((TRACE,"proj_path : \"%s\"\n", 
00251         m_path_entry->get_full_path (true).c_str ()));
00252     DL((TRACE,"A_prefix  : \"%s\"\n", m_A_prefix->get_text ().c_str ()));
00253     DL((TRACE,"B_prefix  : \"%s\"\n", m_B_prefix->get_text ().c_str ()));
00254     DL((TRACE,"A_dir     : \"%s\"\n", m_A_dir->get_text ().c_str ()));
00255     DL((TRACE,"B_dir     : \"%s\"\n", m_B_dir->get_text ().c_str ()));
00256 }

Generated on Tue Feb 11 23:05:19 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002