#include <Config.h>
Public Types | |
typedef deque< string > | DHList |
typedef DHList::iterator | DHList_Iter |
typedef DHList::const_iterator | DHList_CIter |
Public Methods | |
Config () | |
~Config () | |
int | load_project (const string &fname_) |
int | save_project () |
void | save_config () |
void | load_config () |
void | dont_save_project () |
void | set_proj_name (const string &name_) |
void | set_proj_path (const string &path_) |
void | set_A_prefix (const string &ap_) |
void | set_B_prefix (const string &bp_) |
void | set_A_dir (const string &ad_) |
void | set_B_dir (const string &bd_) |
void | set_pre_delay (const string &pd_) |
void | set_post_delay (const string &pd_) |
void | set_jump_next_row (bool b_) |
const string & | get_proj_name () const |
const string & | get_proj_path () const |
const string & | get_A_prefix () const |
const string & | get_B_prefix () const |
const string & | get_A_dir () const |
const string & | get_B_dir () const |
const string & | get_pre_delay () const |
const string & | get_post_delay () const |
bool | get_jump_next_row () const |
string | make_pathname (const string &type_, const string &name_, bool absolute_=false) const |
string | make_abs_pathname (const string &type_, const string &name_) const |
string | make_rel_pathname (const string &type_, const string &name_) const |
string | make_pause_pathname (int type_, const string &name_) const |
string | add_document_history () |
void | remove_document_history (const string &fullpath_) |
const DHList & | get_document_history () const |
void | dump () const |
void | dump_document_history () const |
Private Methods | |
Config (const Config &) | |
Config & | operator= (const Config &) |
Private Attributes | |
string | m_proj_name |
string | m_path_name |
bool | m_dont_save_project |
string | m_A_prefix |
string | m_B_prefix |
string | m_A_dir |
string | m_B_dir |
string | m_pre_delay |
string | m_post_delay |
bool | m_jump_next_row |
DHList | m_history |
|
Definition at line 27 of file Config.h. Referenced by get_document_history, and TopMenuBar::refill_history_list. |
|
Definition at line 29 of file Config.h. Referenced by dump_document_history, TopMenuBar::refill_history_list, and save_config. |
|
|
|
Definition at line 42 of file Config.cpp. References load_config, and m_path_name.
00042 : 00043 m_proj_name ("MyProject.gwm"), 00044 m_dont_save_project (false), 00045 m_A_prefix ("a"), 00046 m_B_prefix ("b"), 00047 m_A_dir ("A"), 00048 m_B_dir ("B"), 00049 m_pre_delay ("2x"), 00050 m_post_delay ("2x") 00051 { 00052 trace("Config::Config"); 00053 00054 // Always start with the current directory as pathname 00055 char* ptr = NULL; 00056 ptr = new char [PATH_MAX+1]; 00057 Assert_exit (getcwd (ptr, PATH_MAX) != NULL); 00058 m_path_name = ptr; 00059 delete [] ptr; 00060 00061 // Load history from ~/.gnome/gwavmerger configuration file 00062 load_config (); 00063 } |
|
Definition at line 68 of file Config.cpp. References dump, m_dont_save_project, save_config, and save_project.
00069 { 00070 trace("Config::~Config"); 00071 dump (); 00072 00073 if (!m_dont_save_project) { 00074 save_project (); 00075 } 00076 00077 // Save history to ~/.gnome/gwavmerger configuration file. 00078 save_config (); 00079 } |
|
|
|
Add the most recently visited project to the history list. Keep up to the last five files only. RETURN: the file path if file was successfully added to the list; an empty string otherwise. Definition at line 325 of file Config.cpp. References dump_document_history, m_history, m_path_name, and m_proj_name. Referenced by TopMenuBar::add_history, and MainWindow::exit_cb.
00326 { 00327 trace("Config::add_document_history"); 00328 00329 string fullpath; 00330 int hsz = 0; 00331 00332 if (m_path_name.size () == 0) { 00333 fullpath = m_proj_name; 00334 } 00335 else { 00336 fullpath = m_path_name + '/' + m_proj_name; 00337 } 00338 00339 if ((hsz = m_history.size ()) > 0) { 00340 for (int idx = 0; idx < hsz; idx++) { 00341 if (m_history [idx] == fullpath) { 00342 m_history.erase (m_history.begin () + idx); 00343 break; 00344 } 00345 } 00346 } 00347 00348 m_history.push_front (fullpath); 00349 if (m_history.size () > 5) { 00350 m_history.pop_back (); 00351 } 00352 dump_document_history (); 00353 return fullpath; 00354 } |
|
Definition at line 41 of file Config.h. References m_dont_save_project. Referenced by MainWindow::exit_cb.
00041 { m_dont_save_project = true; } |
|
[Project] project_name=Irena.gwm A_prefix=aa B_prefix=bb A_dir=A B_dir=B pre_delay=<delay> post_delay=<Delay> Definition at line 249 of file Config.cpp. References dump_document_history, m_A_dir, m_A_prefix, m_B_dir, m_B_prefix, m_path_name, m_post_delay, m_pre_delay, and m_proj_name. Referenced by PrefWindow::apply_impl, load_project, MainWindow::reload_cb, and ~Config.
00250 { 00251 trace("Config::dump"); 00252 DL((TRACE,"proj_name : \"%s\"\n", m_proj_name.c_str ())); 00253 DL((TRACE,"path_name : \"%s\"\n", m_path_name.c_str ())); 00254 DL((TRACE,"A_prefix : \"%s\"\n", m_A_prefix.c_str ())); 00255 DL((TRACE,"B_prefix : \"%s\"\n", m_B_prefix.c_str ())); 00256 DL((TRACE,"A_dir : \"%s\"\n", m_A_dir.c_str ())); 00257 DL((TRACE,"B_dir : \"%s\"\n", m_B_dir.c_str ())); 00258 DL((TRACE,"pre_delay : \"%s\"\n", m_pre_delay.c_str ())); 00259 DL((TRACE,"post_delay : \"%s\"\n", m_post_delay.c_str ())); 00260 00261 dump_document_history (); 00262 } |
|
Definition at line 268 of file Config.cpp. References DHList_CIter, and m_history. Referenced by add_document_history, and dump.
00269 { 00270 if (m_history.size () == 0) { 00271 DL((APP,"Document history is empty\n")); 00272 return; 00273 } 00274 DL((APP,"=== Document history ===\n")); 00275 DHList_CIter cit = m_history.begin (); 00276 uint idx = 0; 00277 while (cit != m_history.end ()) { 00278 DL((APP,"[%d] \"%s\"\n", idx++, (*cit).c_str ())); 00279 cit++; 00280 } 00281 DL((APP,"====== End history =====\n")); 00282 } |
|
Definition at line 58 of file Config.h. References m_A_dir. Referenced by PrefWindow::apply_impl, make_pathname, MainWindow::reload_cb, PrefWindow::run, and ActionsMenu::shift.
00058 { return m_A_dir; } |
|
Definition at line 56 of file Config.h. References m_A_prefix. Referenced by PrefWindow::apply_impl, make_pathname, MainWindow::reload_cb, PrefWindow::run, and ActionsMenu::shift.
00056 { return m_A_prefix; } |
|
Definition at line 59 of file Config.h. References m_B_dir. Referenced by PrefWindow::apply_impl, make_pathname, make_pause_pathname, MainWindow::reload_cb, PrefWindow::run, and ActionsMenu::shift.
00059 { return m_B_dir; } |
|
Definition at line 57 of file Config.h. References m_B_prefix. Referenced by PrefWindow::apply_impl, make_pathname, make_pause_pathname, MainWindow::reload_cb, PrefWindow::run, and ActionsMenu::shift.
00057 { return m_B_prefix; } |
|
Definition at line 75 of file Config.h. References DHList, and m_history. Referenced by MainWindow::open_recent_cb, and TopMenuBar::refill_history_list.
00075 { return m_history; } |
|
Definition at line 62 of file Config.h. References m_jump_next_row. Referenced by TopMenuBar::create, TopMenuBar::jump_next_row_cb, and MainWindow::play_sound.
00062 { return m_jump_next_row; } |
|
Definition at line 61 of file Config.h. References m_post_delay. Referenced by PrefWindow::apply_impl, Delays::Delays, and PrefWindow::PrefWindow.
00061 { return m_post_delay; } |
|
Definition at line 60 of file Config.h. References m_pre_delay. Referenced by PrefWindow::apply_impl, Delays::Delays, and PrefWindow::PrefWindow.
00060 { return m_pre_delay; } |
|
Definition at line 54 of file Config.h. References m_proj_name. Referenced by PrefWindow::apply_impl, MergeDialog::on_ok_button_clicked, PrefWindow::run, and MainWindow::set_mw_name.
00054 { return m_proj_name; } |
|
Definition at line 55 of file Config.h. References m_path_name. Referenced by PrefWindow::apply_impl, make_pathname, MergeDialog::on_ok_button_clicked, MainWindow::read_dir, PrefWindow::run, and ActionsMenu::shift.
00055 { return m_path_name; } |
|
Load configuration from ~/.gnome[2]/gwavmerger Definition at line 430 of file Config.cpp. References m_history, and m_jump_next_row. Referenced by Config.
00431 { 00432 trace("Config::load_config"); 00433 00434 string path ("/gwavmerger/Default/jump"); 00435 m_jump_next_row = gnome_config_get_bool (path.c_str ()); 00436 00437 path = "/gwavmerger/History"; 00438 gpointer iterator = gnome_config_init_iterator (path.c_str ()); 00439 00440 if (iterator != 0) { 00441 DL((APP,"Scanning [History] section ...\n")); 00442 gchar* key = NULL; 00443 gchar* value = NULL; 00444 while ((iterator = gnome_config_iterator_next (iterator, &key, &value))) 00445 { 00446 if (key == 0 || value == 0) { // paranoid? 00447 if (key) g_free (key); 00448 if (value) g_free (value); 00449 continue; 00450 } 00451 if (strlen (value) != 0) { 00452 m_history.push_front (value); 00453 } 00454 g_free (key); 00455 g_free (value); 00456 key = value = NULL; 00457 } 00458 DL((APP,"Loaded total %d history items\n", m_history.size ())); 00459 } 00460 else { 00461 DL((APP,"Section [History] is not in ~/.gnome[2]/gwavmerger\n")); 00462 } 00463 } |
|
Load project-specific configuration from a project file. PARAMETERS: <fname_> [IN] is the fully qualified path to the configuration file RETURN: 0 on success; -1 on error with error dialog posted Definition at line 92 of file Config.cpp. References dump, m_A_dir, m_A_prefix, m_B_dir, m_B_prefix, m_path_name, m_post_delay, m_pre_delay, m_proj_name, MAINWINDOW, set_proj_name, and set_proj_path. Referenced by FileOpen::ok_cb, and MainWindow::open_recent_cb.
00093 { 00094 trace("Config::load_project"); 00095 00096 DL((TRACE,"Loading config from \"%s\"\n", fname_.c_str ())); 00097 int idx = 1; 00098 struct stat file_stat; 00099 00100 if (stat (fname_.c_str (), &file_stat) < 0 || 00101 S_ISREG (file_stat.st_mode) == false) // invalid project file 00102 { 00103 // Test to see if file exists, and if it doesn't, show 00104 // modal error dialog and return 0 00105 string msg ("Invalid project file:\n"); 00106 msg += fname_; 00107 Gtk::MessageDialog md_error (msg, MESSAGE_ERROR); 00108 return -1; 00109 } 00110 /* Given the full file name, split it into dirname and basename 00111 * 00112 * From man dirname(3): 00113 * "Both dirname and basename may modify the contents of path, 00114 * so if you need to preserve the pathname string, 00115 * copies should be passed to these functions. 00116 * Furthermore, dirname and basename may return pointers to 00117 * statically allocated memory which may overwritten by subsequent 00118 * calls." 00119 */ 00120 char s [PATH_MAX]; 00121 strcpy (s, fname_.c_str ()); 00122 set_proj_name (basename (s)); // 's' might be modified! 00123 00124 strcpy (s, fname_.c_str ()); 00125 set_proj_path (dirname (s)); 00126 00127 string base ("=" + m_path_name + "/" + m_proj_name + "=/Project"); 00128 string key; 00129 char* val; 00130 00131 key = base + "/project_name"; 00132 val = gnome_config_get_string (key.c_str ()); 00133 if (val != 0) { 00134 m_proj_name = val; 00135 g_free (val); 00136 } 00137 00138 key = base + "/A_prefix"; 00139 val = gnome_config_get_string (key.c_str ()); 00140 if (val != 0) { 00141 m_A_prefix = val; 00142 g_free (val); 00143 } 00144 00145 key = base + "/B_prefix"; 00146 val = gnome_config_get_string (key.c_str ()); 00147 if (val != 0) { 00148 m_B_prefix = val; 00149 g_free (val); 00150 } 00151 00152 key = base + "/A_dir"; 00153 val = gnome_config_get_string (key.c_str ()); 00154 if (val != 0) { 00155 m_A_dir = val; 00156 g_free (val); 00157 } 00158 00159 key = base + "/B_dir"; 00160 val = gnome_config_get_string (key.c_str ()); 00161 if (val != 0) { 00162 m_B_dir = val; 00163 g_free (val); 00164 } 00165 00166 key = base + "/pre_delay"; 00167 val = gnome_config_get_string (key.c_str ()); 00168 if (val != 0) { 00169 m_pre_delay = val; 00170 g_free (val); 00171 } 00172 00173 key = base + "/post_delay"; 00174 val = gnome_config_get_string (key.c_str ()); 00175 if (val != 0) { 00176 m_post_delay = val; 00177 g_free (val); 00178 } 00179 00180 dump (); 00181 00182 MAINWINDOW->set_mw_name (); 00183 MAINWINDOW->reload_cb (); 00184 00185 return 0; 00186 } |
|
Definition at line 109 of file Config.h. References make_pathname. Referenced by MainWindow::make_selected_file_name.
00110 { 00111 return make_pathname (type_, name_, true); 00112 } |
|
Definition at line 286 of file Config.cpp. References get_A_dir, get_A_prefix, get_B_dir, get_B_prefix, and get_proj_path. Referenced by make_abs_pathname, and make_rel_pathname.
00287 { 00288 string pname; 00289 if (absolute_) { 00290 pname = get_proj_path () + "/"; 00291 } 00292 if (type_ == "A") { 00293 pname += get_A_dir () + "/" + get_A_prefix () + name_ + ".wav"; 00294 } 00295 else if (type_ == "B") { 00296 pname += get_B_dir () + "/" + get_B_prefix () + name_ + ".wav"; 00297 } 00298 else { 00299 DL((APP,"error: unknown type \"%s\"\n",type_.c_str ())); 00300 pname = ""; 00301 } 00302 return pname; 00303 } |
|
Definition at line 308 of file Config.cpp. References get_B_dir, and get_B_prefix. Referenced by MergeDialog::on_ok_button_clicked.
00309 { 00310 string pname (get_B_dir () + "/"); 00311 pname += get_B_prefix () + name_; 00312 pname += (type_ == 0) ? "_pre_pause.wav" : "_post_pause.wav"; 00313 return pname; 00314 } |
|
Definition at line 116 of file Config.h. References make_pathname. Referenced by MergeDialog::on_ok_button_clicked.
00117 { 00118 return make_pathname (type_, name_); 00119 } |
|
|
|
Remove project from document history list. This happens when user tries to open project that doesn't exist any longer. Definition at line 363 of file Config.cpp. References m_history. Referenced by MainWindow::open_recent_cb.
00364 { 00365 trace("Config::remove_document_history"); 00366 00367 size_t hsz; 00368 if ((hsz = m_history.size ()) == 0) { 00369 return; 00370 } 00371 for (int idx = 0; idx < hsz; idx++) { 00372 if (m_history [idx] == fullpath_) { 00373 m_history.erase (m_history.begin () + idx); 00374 break; 00375 } 00376 } 00377 } |
|
Save configuration to ~/.gnome[2]/gwavmerger History list can hold up to 5 elements. Keys (history?) are not important. [Default] jumprows={0,1} [History] history0=<path to>/Profile0.gwm history1=<path to>/Profile1.gwm ... ... history4=<path to>/Profile4.gwm Definition at line 396 of file Config.cpp. References DHList_CIter, m_history, and m_jump_next_row. Referenced by ~Config.
00397 { 00398 trace("Config::save_config"); 00399 00400 string path ("/gwavmerger/History"); 00401 string key; 00402 ostringstream ckey; 00403 int position = 0; 00404 00405 gnome_config_clean_file (path.c_str ()); 00406 00407 if (m_history.size () != 0) { 00408 DHList_CIter cit = m_history.begin (); 00409 while (cit != m_history.end ()) { 00410 ckey.str (""); 00411 ckey << path << "/" << position; 00412 DL((TRACE,"Saving\nhistory [%d] = <%s>\n", position, 00413 ckey.str ().c_str (), (*cit).c_str ())); 00414 gnome_config_set_string (ckey.str ().c_str (), (*cit).c_str ()); 00415 cit++; 00416 position++; 00417 } 00418 } 00419 path = "/gwavmerger/Default/jump"; 00420 gnome_config_set_bool (path.c_str (), m_jump_next_row); 00421 00422 gnome_config_sync (); 00423 } |
|
Save project configuration to the project file. Definition at line 194 of file Config.cpp. References m_A_dir, m_A_prefix, m_B_dir, m_B_prefix, m_path_name, m_post_delay, m_pre_delay, and m_proj_name. Referenced by MainWindow::save_config_file, and ~Config.
00195 { 00196 trace("Config::save_project"); 00197 00198 /* Project file name should have .gwm extension. 00199 * If it doesn't have one we ought to add it. 00200 */ 00201 string ext (".gwm"); 00202 if (m_proj_name.find (ext) == string::npos) { 00203 m_proj_name += ext; 00204 } 00205 string base ("=" + m_path_name + "/" + m_proj_name + "="); 00206 string key; 00207 00208 gnome_config_clean_file (base.c_str ()); 00209 gnome_config_sync (); 00210 00211 base += "/Project"; 00212 00213 DL((APP,"base = \"%s\"\n", base.c_str ())); 00214 00226 key = base + "/project_name"; 00227 gnome_config_set_string (key.c_str (), m_proj_name.c_str ()); 00228 key = base + "/A_prefix"; 00229 gnome_config_set_string (key.c_str (), m_A_prefix.c_str ()); 00230 key = base + "/B_prefix"; 00231 gnome_config_set_string (key.c_str (), m_B_prefix.c_str ()); 00232 key = base + "/A_dir"; 00233 gnome_config_set_string (key.c_str (), m_A_dir.c_str ()); 00234 key = base + "/B_dir"; 00235 gnome_config_set_string (key.c_str (), m_B_dir.c_str ()); 00236 key = base + "/pre_delay"; 00237 gnome_config_set_string (key.c_str (), m_pre_delay.c_str ()); 00238 key = base + "/post_delay"; 00239 gnome_config_set_string (key.c_str (), m_post_delay.c_str ()); 00240 00241 gnome_config_sync (); 00242 return 0; 00243 } |
|
Definition at line 48 of file Config.h. References m_A_dir. Referenced by PrefWindow::apply_impl.
00048 { m_A_dir = ad_; } |
|
Definition at line 46 of file Config.h. References m_A_prefix. Referenced by PrefWindow::apply_impl.
00046 { m_A_prefix = ap_; } |
|
Definition at line 49 of file Config.h. References m_B_dir. Referenced by PrefWindow::apply_impl.
00049 { m_B_dir = bd_; } |
|
Definition at line 47 of file Config.h. References m_B_prefix. Referenced by PrefWindow::apply_impl.
00047 { m_B_prefix = bp_; } |
|
Definition at line 52 of file Config.h. References m_jump_next_row. Referenced by TopMenuBar::jump_next_row_cb.
00052 { m_jump_next_row =b_; } |
|
Definition at line 51 of file Config.h. References m_post_delay. Referenced by PrefWindow::apply_impl.
00051 { m_post_delay = pd_; } |
|
Definition at line 50 of file Config.h. References m_pre_delay. Referenced by PrefWindow::apply_impl.
00050 { m_pre_delay = pd_; } |
|
Definition at line 44 of file Config.h. References m_proj_name. Referenced by PrefWindow::apply_impl, and load_project.
00044 { m_proj_name = name_; } |
|
Definition at line 45 of file Config.h. References m_path_name. Referenced by PrefWindow::apply_impl, and load_project.
00045 { m_path_name = path_; } |
|
Definition at line 92 of file Config.h. Referenced by dump, get_A_dir, load_project, save_project, and set_A_dir. |
|
Definition at line 90 of file Config.h. Referenced by dump, get_A_prefix, load_project, save_project, and set_A_prefix. |
|
Definition at line 93 of file Config.h. Referenced by dump, get_B_dir, load_project, save_project, and set_B_dir. |
|
Definition at line 91 of file Config.h. Referenced by dump, get_B_prefix, load_project, save_project, and set_B_prefix. |
|
Definition at line 88 of file Config.h. Referenced by dont_save_project, and ~Config. |
|
Definition at line 99 of file Config.h. Referenced by add_document_history, dump_document_history, get_document_history, load_config, remove_document_history, and save_config. |
|
Definition at line 97 of file Config.h. Referenced by get_jump_next_row, load_config, save_config, and set_jump_next_row. |
|
Definition at line 87 of file Config.h. Referenced by add_document_history, Config, dump, get_proj_path, load_project, save_project, and set_proj_path. |
|
Definition at line 95 of file Config.h. Referenced by dump, get_post_delay, load_project, save_project, and set_post_delay. |
|
Definition at line 94 of file Config.h. Referenced by dump, get_pre_delay, load_project, save_project, and set_pre_delay. |
|
Definition at line 86 of file Config.h. Referenced by add_document_history, dump, get_proj_name, load_project, save_project, and set_proj_name. |