~ubuntu-branches/debian/sid/gnome-color-chooser/sid

« back to all changes in this revision

Viewing changes to src/configloader.cc

  • Committer: Bazaar Package Importer
  • Author(s): Werner Pantke
  • Date: 2008-09-09 11:46:25 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080909114625-abbnpd1rhju2bi8i
Tags: 0.2.4-1
* new upstream release
  - license is now GNU GPL3+
  - strip down indirect dependencies by using LDFLAGS="-Wl,--as-needed"
    by default (if linker supports it)
* new homepage URL ( http://gnomecc.sourceforge.net ) (Closes: #493648)
* panel settings don't affect evolution's mail settings dialog anymore
  (LP: #219460)
* bumped Debian Policy Standards-Version to 3.8.0 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2006-2007 W. Pantke <gnome-color-chooser@punk-ass-bitch.org>
2
 
//  
3
 
// This program is free software; you can redistribute it and/or modify
4
 
// it under the terms of the GNU General Public License as published by
5
 
// the Free Software Foundation; either version 2 of the License, or
6
 
// (at your option) any later version.
7
 
// 
8
 
// This program is distributed in the hope that it will be useful,
9
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
// GNU General Public License for more details.
12
 
// 
13
 
// You should have received a copy of the GNU General Public License
14
 
// along with this program; if not, write to the Free Software 
15
 
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
1
/* GNOME Color Chooser - GTK+/GNOME desktop appearance customization tool
 
2
 * Copyright (C) 2006-2008 Werner Pantke <wpantke@punk-ass-bitch.org>
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation, either version 3 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 *
 
17
 * Project email: <gnome-color-chooser@punk-ass-bitch.org>
 
18
 *
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
16
24
 
17
25
#include "configloader.h"
 
26
#include "treehandler.h"
 
27
#include "mainwindow.h"
 
28
#include "enginewindow.h"
 
29
#include "validatorwindow.h"
 
30
#include "modwidget.h"
 
31
#include "combobox.h"
18
32
#include "utils.h"
 
33
#include "colorbutton.h"
 
34
#include "checkbutton.h"
 
35
#include "spinbutton.h"
 
36
#include "slider.h"
 
37
#include "combobox.h"
 
38
#include "fontbutton.h"
19
39
 
20
 
#include <string.h>
 
40
#include <glib/gi18n.h>
 
41
#include <cstring>
21
42
#include <fstream>
22
43
#include <iostream>
23
44
#include <sys/types.h>
24
45
#include <sys/stat.h>
25
46
#include <dirent.h> // not platform independent :(
26
47
#include <gtk/gtk.h>
27
 
 
28
 
 
 
48
#include <glib.h>
 
49
#include <gtkmm/box.h>
 
50
#include <gtkmm/eventbox.h>
 
51
#include <gtkmm/separator.h>
 
52
 
 
53
using std::cerr;
 
54
using std::cout;
 
55
using std::flush;
 
56
using std::endl;
 
57
using std::ofstream;
29
58
using namespace GnomeCC;
30
59
 
31
60
 
32
 
/*
33
 
ConfigLoader::ConfigLoader()
34
 
{
35
 
//  engines = NULL;
36
 
}
37
 
 
38
 
ConfigLoader::~ConfigLoader()
39
 
{
40
 
  
41
 
}
42
 
*/
43
 
 
44
 
bool ConfigLoader::load_config(string filename,
45
 
                               TreeHandler* pConfig,
46
 
                               const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
47
 
                               MainWindow* pWindow)
 
61
ConfigLoader::Engine  *ConfigLoader::engines       = NULL;
 
62
ConfigLoader::Param   *ConfigLoader::params        = NULL;
 
63
ConfigLoader::Profile *ConfigLoader::profiles      = NULL;
 
64
ConfigLoader::PTheme  *ConfigLoader::profile_theme = NULL;
 
65
 
 
66
 
 
67
bool ConfigLoader::load_config(
 
68
      string filename,
 
69
      TreeHandler* pConfig,
 
70
      const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
 
71
      MainWindow* pWindow)
48
72
{
49
73
//todo: check use of strtol() !
50
74
 
71
95
    if(element->type == XML_ELEMENT_NODE && (char*)element->name)
72
96
    {
73
97
      if(!strcmp((char*)element->name, "element"))
74
 
      {
75
98
        load_theme_element(pConfig, refGlade, pWindow, element);
76
 
      }
77
99
      else if(!strcmp((char*)element->name, "engine"))
78
 
      {
79
100
        load_theme_engine(pConfig, pWindow, element);
80
 
      }
81
101
      else if(!strcmp((char*)element->name, "profile"))
82
 
      {
83
102
        load_theme_profile(pConfig, element);
84
 
      }
85
 
 
86
103
    }
87
104
    
88
105
    element = element->next;
92
109
 
93
110
}
94
111
 
95
 
void ConfigLoader::load_theme_profile(TreeHandler *pConfig, xmlNode *element)
 
112
 
 
113
void ConfigLoader::load_theme_profile(
 
114
      TreeHandler *pConfig,
 
115
      xmlNode *element)
96
116
{
97
117
  if(strcmp((char*)element->name, "profile"))
98
118
    return;
120
140
      xmlNode    *element)
121
141
{
122
142
 
123
 
  xmlChar* id       = NULL;
124
 
  xmlChar* value    = NULL;
125
 
  xmlChar* disabled = NULL;
126
 
 
127
143
  if(!strcmp((char*)element->name, "element"))
128
144
  {
129
 
    id = xmlGetProp(element, (xmlChar*)"id");
130
 
    value = xmlGetProp(element, (xmlChar*)"value");
131
 
    disabled = xmlGetProp(element, (xmlChar*)"disabled");
 
145
    string id       = Utils::Xml::get_property(element, "id");
 
146
    string value    = Utils::Xml::get_property(element, "value");
 
147
    string disabled = Utils::Xml::get_property(element, "disabled");
132
148
    
133
 
    if(id && value && strcmp((char*)id, "") && strcmp((char*)value, ""))
 
149
    if(id != "" && value != "")
134
150
    {
135
 
      if(disabled && !strcasecmp((char*)disabled, "true"))
136
 
        pConfig->setOverride(strtol((char*)id, NULL, 10), false);
 
151
      if(disabled == "true")
 
152
        pConfig->setOverride(strtol(id.c_str(), NULL, 10), false);
137
153
      else
138
 
        pConfig->setOverride(strtol((char*)id, NULL, 10), true);
 
154
        pConfig->setOverride(strtol(id.c_str(), NULL, 10), true);
139
155
 
140
 
      ConfigLoader::fill_config(pConfig, refGlade, pWindow, atoi((char*)id), (char*)value);
 
156
      ConfigLoader::fill_config(
 
157
            pConfig,
 
158
            refGlade,
 
159
            pWindow,
 
160
            atoi(id.c_str()),
 
161
            value.c_str());
141
162
    }
142
 
    
143
 
    xmlFree(id);
144
 
    xmlFree(value);
145
 
    xmlFree(disabled);
 
163
 
146
164
  }
147
165
 
148
166
}
154
172
      xmlNode     *element)
155
173
{
156
174
 
157
 
  xmlChar* id       = NULL;
158
 
  xmlChar* value    = NULL;
159
 
  xmlChar* disabled = NULL;
160
 
 
161
175
  if(!strcmp((char*)element->name, "engine"))
162
176
  {
163
 
 
164
 
    id = xmlGetProp(element, (xmlChar*)"name");
165
 
    value = xmlGetProp(element, (xmlChar*)"category");
166
 
    disabled = xmlGetProp(element, (xmlChar*)"disabled");
167
 
 
168
 
    if(id && value && strcmp((char*)id, "") && strcmp((char*)value, ""))
169
 
    {
170
 
      // cout << "found engine " << id << " for category " << value << endl; // debugging ;-)
171
 
      
172
 
      if(disabled && !strcasecmp((char*)disabled, "true"))
173
 
        ConfigLoader::attach_engine((char*)id, (char*)value, pConfig, false);          
174
 
        // pConfig->setEngineOverride((char*)value, false);
175
 
      else
176
 
        ConfigLoader::attach_engine((char*)id, (char*)value, pConfig, true);
177
 
        // pConfig->setEngineOverride((char*)value, true);
178
 
      
179
 
      reload_enginetable_row(string((char*)value), pWindow);
180
 
      select_engine(string((char*)value), string((char*)id), pWindow);
181
 
 
182
 
 
183
 
      xmlNode* subelement = element->children;
184
 
      xmlChar* subname;
185
 
      xmlChar* subvalue;
186
 
      xmlChar* subdisabled;
187
 
      while( subelement != NULL )
188
 
      {
189
 
        subname = NULL;
190
 
        subvalue = NULL;
191
 
        subdisabled = NULL;
192
 
        
193
 
        if(subelement->type == XML_ELEMENT_NODE)
194
 
        {
195
 
          subname = xmlGetProp(subelement, (xmlChar*)"name");
196
 
          subvalue = xmlGetProp(subelement, (xmlChar*)"value");
197
 
          subdisabled = xmlGetProp(subelement, (xmlChar*)"disabled");
198
 
          
199
 
          if(subname && subvalue && strcmp((char*)subname, "") && strcmp((char*)subvalue, ""))
200
 
          {
201
 
            // cout << "-> found subelement " << subname << endl; // debugging ;-)
202
 
  
203
 
            //todo: set value only if 100% valid ;-)
204
 
            // (but theoretically it should be corrected automatically by the widgets themself)
205
 
            pConfig->setValue((char*)value, (char*)subname, (char*)subvalue); // value ^= category
206
 
  
207
 
            if(subdisabled && !strcasecmp((char*)subdisabled, "true"))
208
 
              pConfig->setOverride((char*)value, (char*)subname, false);
209
 
            else
210
 
              pConfig->setOverride((char*)value, (char*)subname, true);
211
 
  
212
 
          }
213
 
          
214
 
          xmlFree(subname);
215
 
          xmlFree(subvalue);
216
 
          xmlFree(subdisabled);
217
 
        }
218
 
  
219
 
        subelement = subelement->next;
220
 
      }
221
 
      
222
 
      
223
 
    }
224
 
    
225
 
    xmlFree(id);
226
 
    xmlFree(value);
227
 
    xmlFree(disabled);
228
 
  }
229
 
 
230
 
}
231
 
 
232
 
 
233
 
 
234
 
 
235
 
void ConfigLoader::fill_config(TreeHandler* pConfig,
236
 
                               const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
237
 
                               MainWindow* pWindow,
238
 
                               int id,
239
 
                               char* value)
 
177
    string name     = Utils::Xml::get_property(element, "name");
 
178
    string category = Utils::Xml::get_property(element, "category");
 
179
    string disabled = Utils::Xml::get_property(element, "disabled");
 
180
 
 
181
    if(name != "" && category != "")
 
182
    {
 
183
      // cout << "found engine " << name << " for category " << category << endl; // debugging ;-)
 
184
      
 
185
      if(disabled != "" && !strcasecmp(disabled.c_str(), "true"))
 
186
        ConfigLoader::attach_engine(name, category, pConfig, false);
 
187
        // pConfig->setEngineOverride(category, false);
 
188
      else
 
189
        ConfigLoader::attach_engine(name, category, pConfig, true);
 
190
        // pConfig->setEngineOverride(category, true);
 
191
      
 
192
      reload_enginetable_row(category, pWindow);
 
193
      select_engine(category, name, pWindow);
 
194
 
 
195
      ConfigLoader::load_theme_engine_options(pConfig, category, element);
 
196
      
 
197
    }
 
198
  }
 
199
 
 
200
}
 
201
 
 
202
 
 
203
void ConfigLoader::load_theme_engine_options(
 
204
      TreeHandler *pConfig,
 
205
      string       category,
 
206
      xmlNode     *engine)
 
207
{
 
208
 
 
209
  xmlNode *element = Utils::Xml::get_node(engine->children, "element");
 
210
 
 
211
  while( element != NULL )
 
212
  {
 
213
    string name     = Utils::Xml::get_property(element, "name");
 
214
    string value    = Utils::Xml::get_property(element, "value");
 
215
    string disabled = Utils::Xml::get_property(element, "disabled");
 
216
 
 
217
    if(name != "" && value != "")
 
218
    {
 
219
      //cout << "-> found engine option " << name << endl; // debugging ;-)
 
220
 
 
221
      //todo: set value only if 100% valid ;-)
 
222
      // (normally it should be corrected automatically by the widgets themself)
 
223
      pConfig->setValue(category, name, value.c_str());
 
224
 
 
225
      if(disabled != "" && !strcasecmp(disabled.c_str(), "true"))
 
226
        pConfig->setOverride(category, name, false);
 
227
      else
 
228
        pConfig->setOverride(category, name, true);
 
229
    }
 
230
 
 
231
    element = Utils::Xml::get_node(element->next, "element");
 
232
  }
 
233
 
 
234
}
 
235
 
 
236
 
 
237
 
 
238
 
 
239
void ConfigLoader::fill_config(
 
240
      TreeHandler* pConfig,
 
241
      const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
 
242
      MainWindow* pWindow,
 
243
      int id,
 
244
      const char* value)
240
245
{
241
246
//todo: safer implementation (atoi)
242
247
 
261
266
  //let the widgets itself and MainWindow correct wrong values and then save them
262
267
  if(type == "spin" || type == "iconsize")
263
268
  {
264
 
    if(atoi(value) >= pConfig->getElementMin() && atoi(value) <= pConfig->getElementMax()) // not necessarily needed
 
269
    if(atoi(value) >= pConfig->getElementMin() \
 
270
          && atoi(value) <= pConfig->getElementMax()) // not necessarily needed
265
271
    {
266
272
      char temp[11];
267
273
      snprintf (temp, 10, "%i", atoi(value));
316
322
}
317
323
 
318
324
 
319
 
void ConfigLoader::reload_enginetable_row(string category, MainWindow* p_refWindow)
 
325
void ConfigLoader::reload_enginetable_row(
 
326
      string category,
 
327
      MainWindow *pWindow)
320
328
{
321
329
  int i = 0;
322
 
  while(p_refWindow->engine_name[i] != "")
 
330
  
 
331
  if(!pWindow)
 
332
    return;
 
333
    
 
334
  while(pWindow->engine_name[i] != "")
323
335
  {
324
 
    if(p_refWindow->engine_name[i] == category)
 
336
    if(pWindow->engine_name[i] == category)
325
337
    {
326
 
      p_refWindow->engine_cbox[i].reload();
 
338
      pWindow->engine_cbox[i].reload();
327
339
      break;
328
340
    }
329
341
    i++;
330
342
  }
331
343
}
332
344
 
333
 
void ConfigLoader::select_engine(string category, string engine, MainWindow* p_refWindow)
 
345
 
 
346
void ConfigLoader::select_engine(
 
347
      string category,
 
348
      string engine,
 
349
      MainWindow *pWindow)
334
350
{
335
351
  int i = 0;
336
 
  while(p_refWindow->engine_name[i] != "")
 
352
 
 
353
  if(!pWindow)
 
354
    return;
 
355
 
 
356
  while(pWindow->engine_name[i] != "")
337
357
  {
338
 
    if(p_refWindow->engine_name[i] == category)
 
358
    if(pWindow->engine_name[i] == category)
339
359
    {
340
 
      p_refWindow->engine_combo[i].set_active_text(engine);
 
360
      pWindow->engine_combo[i].set_active_text(engine);
341
361
      break;
342
362
    }
343
363
    i++;
344
364
  }
 
365
 
345
366
}
346
367
 
347
368
 
348
369
string ConfigLoader::xml_encode(string input)
349
370
{
350
 
  xmlChar *temp = xmlEncodeSpecialChars (NULL, (xmlChar*)input.c_str());
 
371
  xmlChar *temp = xmlEncodeSpecialChars(NULL, (xmlChar*)input.c_str());
351
372
  string copy = string((char*)temp);
352
373
  xmlFree(temp);
353
 
  
354
374
  return copy;
355
375
}
356
376
 
357
377
 
358
 
bool ConfigLoader::export_config(TreeHandler* pConfig,
359
 
                                 string filename,
360
 
                                 bool export_disabled_elements,
361
 
                                 bool export_comments)
 
378
//todo: create GnomeCC-exporter
 
379
bool ConfigLoader::export_config(
 
380
      TreeHandler* pConfig,
 
381
      string filename,
 
382
      bool export_disabled_elements,
 
383
      bool export_comments)
362
384
{
363
385
 
364
386
  if(! (Utils::Io::check_file(filename, true) || Utils::Io::create_file(filename)) )
490
512
    perror((string("Error in accessing ") + directory).c_str());
491
513
  else
492
514
  {
493
 
    while(entry = readdir(dir))
 
515
    while( (entry = readdir(dir)) )
494
516
    {
495
517
      string name = string(entry->d_name);
496
518
      if(name.length() > 4)
513
535
 
514
536
bool ConfigLoader::load_engine_schema(string filename)
515
537
{
516
 
  if(!Utils::Io::check_file(filename)) // if file does not exists (or is no regular file)
 
538
  g_return_val_if_fail(filename != "", 0);
 
539
 
 
540
  if(!Utils::Io::check_file(filename)) // if file does not exist (or is no regular file)
517
541
    return 0;
518
542
 
519
543
  /*parse the file and get the DOM */
523
547
    return 0;
524
548
  
525
549
  xmlNode* root = xmlDocGetRootElement(doc);
526
 
 
527
 
  if(root == NULL)
528
 
  {
529
 
    xmlFreeDoc(doc);
530
 
    return 0;
531
 
  }
532
 
 
533
 
  if(strcmp((char*)root->name, "engine"))
534
 
  {
535
 
    xmlFreeDoc(doc);
536
 
    return 0;
537
 
  }
538
 
  
539
 
  xmlChar* xmlchar_val = xmlGetProp(root, (xmlChar*)"module_name");
540
 
 
541
 
  if(xmlchar_val == NULL || !strcmp((char*)xmlchar_val, ""))
542
 
  {
543
 
    xmlFree(xmlchar_val);
544
 
    xmlFreeDoc(doc);
545
 
    return 0;
546
 
  }
547
 
  
548
 
  std::string name = std::string((char*)xmlchar_val);
549
 
  xmlFree(xmlchar_val);
550
 
 
551
 
  if(name == "") // just for being super clean ;-)
552
 
  {
553
 
    xmlFreeDoc(doc);
554
 
    return 0;
555
 
  }
556
 
 
557
 
 
558
 
  // check if elements have name, type, and default value defined, otherwise delete them off the tree!
559
 
  xmlNode* element = root->children;
560
 
  xmlNode* element_tmp = NULL;
561
 
  while( element != NULL )
562
 
  {
563
 
    element_tmp = NULL;
564
 
    
565
 
    if(element->type == XML_ELEMENT_NODE && !strcmp((char*)element->name, "element"))
 
550
  if(root == NULL || strcmp((char*)root->name, "engine"))
 
551
  {
 
552
    xmlFreeDoc(doc);
 
553
    return 0;
 
554
  }
 
555
 
 
556
  string name = Utils::Xml::get_property(root, "module_name");
 
557
  if(name == "")
 
558
  {
 
559
    xmlFreeDoc(doc);
 
560
    return 0;
 
561
  }
 
562
 
 
563
 
 
564
  string schema_version = Utils::Xml::get_property(root, "schema_version");
 
565
  string long_name = "";
 
566
 
 
567
  if(schema_version == "0.1")
 
568
  {
 
569
    long_name = Utils::Xml::get_property(root, "long_name");
 
570
 
 
571
    // check if engine options have name, type, and default value defined,
 
572
    //   otherwise remove them from the tree!
 
573
    xmlNode* element      = Utils::Xml::get_node(root->children, "option");
 
574
    xmlNode* element_next = NULL;
 
575
    while( element != NULL )
566
576
    {
567
 
      xmlchar_val = xmlGetProp(element, (xmlChar*)"name");
568
 
      if(xmlchar_val == NULL || !strcmp((char*)xmlchar_val, ""))
 
577
      // find/save next element now, because the current element could get deleted
 
578
      element_next = Utils::Xml::get_node(element->next, "option");
 
579
      
 
580
      if(Utils::Xml::get_property(element, "name") == "" \
 
581
              || Utils::Xml::get_property(element, "type") == "" \
 
582
              || Utils::Xml::get_property(element, "default") == "")
569
583
      {
570
 
        element_tmp = element->next;
571
584
        xmlUnlinkNode(element);
572
585
        xmlFreeNode(element);
573
586
      }
574
 
      else
575
 
      {
576
 
        xmlFree(xmlchar_val);
577
 
        xmlchar_val = xmlGetProp(element, (xmlChar*)"type");
578
 
        if(xmlchar_val == NULL || !strcmp((char*)xmlchar_val, ""))
579
 
        {
580
 
          element_tmp = element->next;
581
 
          xmlUnlinkNode(element);
582
 
          xmlFreeNode(element);
583
 
        }
584
 
        else
585
 
        {
586
 
          xmlFree(xmlchar_val);
587
 
          xmlchar_val = xmlGetProp(element, (xmlChar*)"default");
588
 
          if(xmlchar_val == NULL || !strcmp((char*)xmlchar_val, ""))
589
 
          {
590
 
            element_tmp = element->next;
591
 
            xmlUnlinkNode(element);
592
 
            xmlFreeNode(element);
593
 
          }
594
 
          //else cout << "Valid Element!" << endl;
595
 
        }
596
 
      }
597
 
      xmlFree(xmlchar_val);
598
 
    }
599
 
 
600
 
    if(element_tmp)
601
 
      element = element_tmp;
602
 
    else
603
 
      element = element->next;
604
 
  }
605
 
 
606
 
 
607
 
 
608
 
  // save engine for later use
 
587
 
 
588
      element = element_next;
 
589
    }
 
590
  }
 
591
/*
 
592
  else if(schema_version == "0.2")
 
593
  {
 
594
//todo: set real xsd path!
 
595
    if(ValidatorWindow::is_valid(filename.c_str(), (string(getenv("PWD")) + "/schema_0_2.xsd").c_str() ) <= 0)
 
596
    {
 
597
      g_debug("Engine Schema %s (schema_version %s) is invalid!",
 
598
            filename.c_str(),
 
599
            schema_version.c_str() );
 
600
      xmlFreeDoc(doc);
 
601
      return 0;
 
602
    }
 
603
    long_name = Utils::Xml::get_content(root, "long_name");
 
604
  }
 
605
*/
 
606
  else
 
607
  {
 
608
    g_debug("Engine Schema %s (schema_version %s) is not supported!",
 
609
          filename.c_str(),
 
610
          schema_version != "" ? schema_version.c_str() : 0);
 
611
    xmlFreeDoc(doc);
 
612
    return 0;
 
613
  }
 
614
 
 
615
 
 
616
  // save engine for later use if engine name is unique
609
617
  Engine *engine;
610
618
  if(engines == NULL)
611
619
  {
631
639
    engine = engine->next;
632
640
  }
633
641
 
634
 
//todo: add only engines with different names _AND_ lnames!
635
 
 
636
642
  engine->name = name;
637
643
  engine->doc = doc;
638
644
  engine->next = NULL;
639
 
  
640
 
/*
641
 
  xmlChar* long_name = xmlGetProp(root, (xmlChar*)"long_name");
642
 
  engine->lname = (long_name != NULL) ? (char*)long_name : "";
643
 
  xmlFree(long_name);
644
 
*/
645
 
  engine->lname = Utils::Xml::get_property(root, "long_name");
646
 
  
 
645
  engine->lname = long_name;
 
646
 
647
647
  return 1;
648
648
}
649
649
 
665
665
}
666
666
 
667
667
 
668
 
void ConfigLoader::attach_engine(string engine_name, string category, TreeHandler* config, bool override)
 
668
void ConfigLoader::attach_engine(
 
669
      string engine_name,
 
670
      string category,
 
671
      TreeHandler* config,
 
672
      bool override)
669
673
{
670
674
  //cout << "!! attach engine " << engine_name << " to " << category << endl; // debugging, heh ;-)
671
675
  Engine *engine = engines;
684
688
 
685
689
 
686
690
 
687
 
void ConfigLoader::load_engine_params(EngineWindow* window, string engine_name, string category, TreeHandler* config)
688
 
{
689
 
  bool skipParam;
690
 
 
691
 
  if(engine_name != "" && engines != NULL)
692
 
  {
693
 
    Engine *engine = engines;
694
 
    
695
 
    while(engine != NULL)
696
 
    {
697
 
      if(engine_name == engine->name)
698
 
        break;
699
 
      engine = engine->next;
700
 
    }
701
 
    
702
 
    if(engine != NULL && engine_name == engine->name)
703
 
    {
704
 
      xmlNode* root = xmlDocGetRootElement(engine->doc);
705
 
      xmlNode* element = root->children;
706
 
      int y = 0;
707
 
      
708
 
      while(element != NULL)
709
 
      {
710
 
          if(element->type == XML_ELEMENT_NODE && !strcmp((char*)element->name,"option"))
711
 
          {
712
 
            skipParam = false;
713
 
 
714
 
/*
715
 
            const char* dummy = NULL;
716
 
            string w_name     = (dummy = get_property(element, "name"))             ? dummy : "",
717
 
                   w_value    = (dummy = get_property(element, "value"))            ? dummy : "",
718
 
                   w_default  = (dummy = get_property(element, "default"))          ? dummy : "",
719
 
                   w_type     = (dummy = get_property(element, "type"))             ? dummy : "",
720
 
                   w_lname    = (dummy = get_content(element,  "long_name"))        ? dummy : "",
721
 
                   w_sdesc    = (dummy = get_content(element,  "description"))      ? dummy : "",
722
 
                   w_ldesc    = (dummy = get_content(element,  "comment"))          ? dummy : "";
723
 
          bool   w_disabled = ((dummy = get_property(element, "disabled")) && !strcasecmp(dummy, "yes")) ? true : false;
724
 
*/
725
 
          string w_name     = Utils::Xml::get_property(element, "name"),
726
 
                 w_value    = Utils::Xml::get_property(element, "value"),
727
 
                 w_default  = Utils::Xml::get_property(element, "default"),
728
 
                 w_type     = Utils::Xml::get_property(element, "type"),
729
 
                 w_lname    = Utils::Xml::get_content(element, "long_name"),
730
 
                 w_sdesc    = Utils::Xml::get_content(element, "description"),
731
 
                 w_ldesc    = Utils::Xml::get_content(element, "comment");
732
 
          bool   w_disabled = Utils::Xml::get_property(element, "disabled") == "yes" ? true : false;
733
 
                 
734
 
          // create new Parameter (for saving widgets in order to be able to delete them later)
735
 
          Param *param;
736
 
          if(params == NULL)
737
 
          {
738
 
            params = new Param();
739
 
            param = params;
740
 
          }
741
 
          else
742
 
          {
743
 
            param = params;
744
 
            while(param->next != NULL)
745
 
            {
746
 
              if(param->name == w_name)
747
 
              {
748
 
                skipParam = true;
749
 
              }
750
 
              param = param->next;
751
 
            }
752
 
 
753
 
            if(param->name == w_name)
754
 
            {
755
 
              skipParam = true;
756
 
            }
757
 
    
758
 
            if(skipParam)
759
 
            {
760
 
              element = element->next;
761
 
              break; // goto next parameter
762
 
            }
763
 
            param->next = new Param();
764
 
            param = param->next;
765
 
          }
766
 
 
767
 
          param->name = w_name;
768
 
          param->next = NULL;
769
 
 
770
 
 
771
 
 
772
 
          // attention: recycling of skipParam *g*
773
 
          skipParam = false;
774
 
 
775
 
 
776
 
 
777
 
          // create widgets of that new Parameter and attach them to the output table
778
 
 
779
 
 
780
 
/*
781
 
          if(w_type == "spin")
782
 
          {
783
 
            SpinButton *widget = new SpinButton();
784
 
            widget->init(category, w_name, config);
785
 
            //widget->reload(); // already run by init() !
786
 
            param->widget = (Gtk::Widget*)widget;
787
 
            widget->signal_value_changed().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_spinbutton), widget) , w_name) );
788
 
 
789
 
          }
790
 
*/
791
 
          if(w_type == "color")
792
 
          {
793
 
            ColorButton *widget = new ColorButton();
794
 
            widget->init(category, w_name, config);
795
 
            param->widget = (Gtk::Widget*)widget;
796
 
            widget->signal_color_set().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_colorbutton), widget) , w_name) );
797
 
          }
798
 
          else if(w_type == "boolean")
799
 
          {
800
 
            CheckButton *widget = new CheckButton();
801
 
            widget->init(category, w_name, config);
802
 
            param->widget = (Gtk::Widget*)widget;
803
 
            widget->signal_toggled().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_checkbutton), widget) , w_name) );
804
 
          }
805
 
          else if(w_type == "integer")
806
 
          {
807
 
            //todo: add sync spinbutton
808
 
            Slider *widget = new Slider();
809
 
            widget->init(category, w_name, config);
810
 
            param->widget = (Gtk::Widget*)widget;
811
 
            widget->signal_value_changed().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_slider), widget) , w_name) );
812
 
          }
813
 
          else if(w_type == "real")
814
 
          {
815
 
            //todo: add sync spinbutton
816
 
            Slider *widget = new Slider();
817
 
            widget->init(category, w_name, config);
818
 
            param->widget = (Gtk::Widget*)widget;
819
 
            widget->signal_value_changed().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_slider), widget) , w_name) );
820
 
          }
821
 
          else if(w_type == "enumeration")
822
 
          {
823
 
            ComboBox *widget = new ComboBox();
824
 
            if(w_ldesc != "")
825
 
            {
826
 
              param->widget_ebox = new Gtk::EventBox();
827
 
              param->widget_ebox->add(*widget);
828
 
            }
829
 
 
830
 
            
831
 
            for(xmlNode* option = element->children; option != NULL; option = option->next)
832
 
            {
833
 
              if(option->type == XML_ELEMENT_NODE && !strcmp((char*)option->name, "enumeration"))
834
 
              {
835
 
/*
836
 
                string option_value = (dummy = get_property(option, "value")) ? dummy : "",
837
 
                       option_name  = (dummy = get_content(option, "label")) ? dummy : "";
838
 
*/
839
 
                string option_value = Utils::Xml::get_property(option, "value"),
840
 
                       option_name  = Utils::Xml::get_content(option, "label");
841
 
              
842
 
                if(option_value != "" && option_name != "")
843
 
                {
844
 
                  widget->append_text((char*)option_value.c_str(), (char*)option_name.c_str());
845
 
                }
846
 
 
847
 
              }
848
 
            }
849
 
 
850
 
            widget->init(category, w_name, config);
851
 
            param->widget = (Gtk::Widget*)widget;
852
 
            widget->signal_changed().connect( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_changed_combobox), widget) , w_name) );
853
 
          }
854
 
          else
855
 
          {
856
 
            //todo: delete param and its widgets!
857
 
            skipParam = true;
858
 
          }
859
 
 
860
 
 
861
 
          if(!skipParam)
862
 
          {
863
 
            char* config_label = NULL;
864
 
          
865
 
            param->box   = new Gtk::HBox();
866
 
//            param->label = new Gtk::Label(w_lname != "" ? w_lname : param->name);
867
 
            param->label = new Gtk::EventBox();
868
 
            param->label->add_label(w_lname != "" ? w_lname : param->name);
869
 
//            param->desc  = new Gtk::Label(w_sdesc != "" ? w_sdesc : (Glib::ustring("Configuration of ") +
870
 
//                                         (w_lname != "" ? w_lname : param->name)).c_str(), 0.0, 0.0);
871
 
            param->desc = new Gtk::EventBox();
872
 
//            param->desc->add_label(w_sdesc != "" ? w_sdesc : (Glib::ustring("Configuration of ") +
873
 
//                                  (w_lname != "" ? w_lname : param->name)).c_str(), 0.0, 0.0);
874
 
 
875
 
            param->desc->add_label(
876
 
                  w_sdesc != "" ? w_sdesc : config_label = g_strdup_printf(_("Configuration of %s"),
877
 
                        (w_lname != "" ? w_lname.c_str() : param->name.c_str() )),
878
 
                  0.0, 0.0);
879
 
 
880
 
            if(config_label)
881
 
              free(config_label);
882
 
            
883
 
            ((Gtk::Label*)(param->desc->get_child()))->set_line_wrap(true);
884
 
            param->line  = new Gtk::HSeparator();
885
 
            param->line->set_size_request(-1, 20);
886
 
            
887
 
            param->cbox  = new CheckButton();
888
 
            param->cbox->init(category, w_name, config, false);
889
 
            param->cbox->signal_toggled().connect( sigc::bind( sigc::bind( sigc::bind( sigc::mem_fun(*window, &EngineWindow::on_checkbox_toggled), param->widget),  param->cbox), w_name) );
890
 
            
891
 
            if(w_ldesc != "")
892
 
            {
893
 
              window->tooltips.set_tip(*param->label,  w_ldesc);
894
 
              window->tooltips.set_tip(*param->desc,   w_ldesc);
895
 
              if(param->widget_ebox)
896
 
                window->tooltips.set_tip(*param->widget_ebox, w_ldesc);
897
 
              else
898
 
                window->tooltips.set_tip(*param->widget, w_ldesc);
899
 
            }
900
 
            
901
 
            window->table.resize(y+2, 2); // rows, coloumns
902
 
            window->table.attach(*param->desc,  0, 2, y,   y+1,  Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
903
 
            window->table.attach(*param->label, 0, 1, y+1, y+2, ~Gtk::FILL & ~Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
904
 
            window->table.attach(*param->box,   1, 2, y+1, y+2,  Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
905
 
            window->table.attach(*param->line,  0, 2, y+2, y+3,  Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
906
 
            
907
 
            param->box->pack_start(*param->cbox,   Gtk::PACK_SHRINK);
908
 
            if(param->widget_ebox)
909
 
              param->box->pack_start(*param->widget_ebox, Gtk::PACK_EXPAND_WIDGET);
910
 
            else
911
 
              param->box->pack_start(*param->widget, Gtk::PACK_EXPAND_WIDGET);
912
 
              
913
 
          }
914
 
 
915
 
 
916
 
          y = y+3;
917
 
 
918
 
          }
919
 
          element = element->next;
920
 
      }
921
 
      
922
 
    }
923
 
  }
924
 
}
925
 
 
926
 
 
927
 
 
928
 
void ConfigLoader::unload_engine_params()
929
 
{
930
 
  Param *param = params;
931
 
  Param *param_next;
932
 
  
933
 
  while(param != NULL)
934
 
  {
935
 
    param_next = param->next;
936
 
    if(param->box)
937
 
      delete param->box;
938
 
    if(param->label)
939
 
      delete param->label;
940
 
    if(param->desc)
941
 
      delete param->desc;
942
 
    if(param->line)
943
 
      delete param->line;
944
 
    if(param->cbox)
945
 
      delete param->cbox;
946
 
    if(param->widget)
947
 
      delete param->widget;
948
 
    if(param->widget_ebox)
949
 
      delete param->widget_ebox;
950
 
    delete param;
951
 
    param = param_next;
952
 
  }
953
 
 
954
 
  params = NULL;
955
 
  // cout << "unloaded engine" << endl; // debugging ;-)
956
 
}
957
 
 
958
 
 
959
 
void ConfigLoader::fill_with_engines(string category, ComboBox* box, TreeHandler* p_refConfig)
 
691
void ConfigLoader::load_engine_params(
 
692
      EngineWindow* window,
 
693
      string engine_name,
 
694
      string category,
 
695
      TreeHandler* config)
 
696
{
 
697
 
 
698
  g_return_if_fail(engines     != NULL);
 
699
  g_return_if_fail(engine_name != "");
 
700
  g_return_if_fail(category    != "");
 
701
 
 
702
  Engine *engine = engines;
 
703
  while(engine != NULL)
 
704
  {
 
705
    if(engine_name == engine->name)
 
706
      break;
 
707
    engine = engine->next;
 
708
  }
 
709
 
 
710
  if(engine == NULL || engine_name != engine->name)
 
711
    return;
 
712
 
 
713
  xmlNode *root    = xmlDocGetRootElement(engine->doc);
 
714
  xmlNode *element = Utils::Xml::get_node(root->children, "option");
 
715
  Param   *param   = NULL;
 
716
 
 
717
  int y = 0;
 
718
 
 
719
  while(element != NULL)
 
720
  {
 
721
    string w_name     = Utils::Xml::get_property(element, "name"),
 
722
           w_value    = Utils::Xml::get_property(element, "value"),
 
723
           w_default  = Utils::Xml::get_property(element, "default"),
 
724
           w_type     = Utils::Xml::get_property(element, "type"),
 
725
           w_lname    = Utils::Xml::get_content (element, "long_name"),
 
726
           w_sdesc    = Utils::Xml::get_content (element, "description"),
 
727
           w_ldesc    = Utils::Xml::get_content (element, "comment");
 
728
 
 
729
 
 
730
    // create new Parameter (for saving widgets in order to be able to delete them later)
 
731
    if( !(param = ConfigLoader::create_unique_param(w_name)) )
 
732
    {
 
733
      element = Utils::Xml::get_node(element->next, "option");
 
734
      continue; // goto next engine parameter
 
735
    }
 
736
 
 
737
 
 
738
    // create widget(s) of that new Parameter and attach them to the output table
 
739
    if(ConfigLoader::create_engine_option_widget(
 
740
          window,
 
741
          param,
 
742
          config,
 
743
          element,
 
744
          category,
 
745
          w_name,
 
746
          w_type,
 
747
          w_ldesc))
 
748
    {
 
749
      char* config_label = NULL;
 
750
 
 
751
      param->box   = new Gtk::HBox();
 
752
 
 
753
      param->label = new Gtk::EventBox();
 
754
      param->label->add_label(w_lname != "" ? w_lname : param->name);
 
755
 
 
756
      param->desc = new Gtk::EventBox();
 
757
      param->desc->add_label(
 
758
            w_sdesc != "" ? w_sdesc : config_label = g_strdup_printf(_("Configuration of %s"),
 
759
                  (w_lname != "" ? w_lname.c_str() : param->name.c_str() )),
 
760
            0.0, 0.0);
 
761
 
 
762
      if(config_label)
 
763
        free(config_label);
 
764
 
 
765
      ((Gtk::Label*)(param->desc->get_child()))->set_line_wrap(true);
 
766
      param->line  = new Gtk::HSeparator();
 
767
      param->line->set_size_request(-1, 20);
 
768
 
 
769
      param->cbox  = new CheckButton();
 
770
      param->cbox->init(category, w_name, config, false);
 
771
 
 
772
      if(param->widget1 && param->widget2)
 
773
      {
 
774
        param->cbox->signal_toggled().connect(
 
775
              sigc::bind( sigc::bind( sigc::bind( sigc::bind( sigc::mem_fun(
 
776
                    *window, &EngineWindow::on_checkbox_toggled),
 
777
                    param->widget2),
 
778
                    param->widget1),
 
779
                    param->cbox), w_name) );
 
780
      }
 
781
      else{ // use param->widget instead
 
782
        param->cbox->signal_toggled().connect(
 
783
              sigc::bind( sigc::bind( sigc::bind( sigc::bind( sigc::mem_fun(
 
784
                    *window, &EngineWindow::on_checkbox_toggled),
 
785
                    param->widget),
 
786
                    param->widget),
 
787
                    param->cbox), w_name) );
 
788
      }
 
789
 
 
790
      if(w_ldesc != "")
 
791
      {
 
792
        window->tooltips.set_tip(*param->label, w_ldesc);
 
793
        window->tooltips.set_tip(*param->desc,  w_ldesc);
 
794
        if(param->widget_ebox)
 
795
          window->tooltips.set_tip(*param->widget_ebox, w_ldesc);
 
796
        else
 
797
          window->tooltips.set_tip(*param->widget, w_ldesc);
 
798
      }
 
799
 
 
800
      window->table.resize(y+2, 2); // rows, coloumns
 
801
 
 
802
      window->table.attach(
 
803
            *param->desc,
 
804
            0, 2, y, y+1,
 
805
            Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
 
806
 
 
807
      window->table.attach(
 
808
            *param->label,
 
809
            0, 1, y+1, y+2,
 
810
            ~Gtk::FILL & ~Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
 
811
 
 
812
      window->table.attach(
 
813
            *param->box,
 
814
            1, 2, y+1, y+2,
 
815
            Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
 
816
 
 
817
      window->table.attach(*param->line,
 
818
            0, 2, y+2, y+3,
 
819
            Gtk::FILL |  Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
 
820
 
 
821
 
 
822
      param->box->pack_start(*param->cbox, Gtk::PACK_SHRINK);
 
823
      if(param->widget_ebox)
 
824
        param->box->pack_start(*param->widget_ebox, Gtk::PACK_EXPAND_WIDGET);
 
825
      else
 
826
        param->box->pack_start(*param->widget, Gtk::PACK_EXPAND_WIDGET);
 
827
 
 
828
    }
 
829
 
 
830
    y = y+3;
 
831
    element = Utils::Xml::get_node(element->next, "option");
 
832
  }
 
833
 
 
834
}
 
835
 
 
836
 
 
837
ConfigLoader::Param* ConfigLoader::create_unique_param(string name)
 
838
{
 
839
  Param *param = NULL;
 
840
  if(params == NULL)
 
841
  {
 
842
    params = new Param();
 
843
    param = params;
 
844
  }
 
845
  else
 
846
  {
 
847
    param = params;
 
848
    while(param->next != NULL)
 
849
    {
 
850
      if(param->name == name)
 
851
        return NULL;
 
852
      param = param->next;
 
853
    }
 
854
    if(param->name == name)
 
855
      return NULL;
 
856
 
 
857
    param->next = new Param();
 
858
    param = param->next;
 
859
  }
 
860
 
 
861
  param->name = name;
 
862
  param->next = NULL;
 
863
 
 
864
  return param;
 
865
}
 
866
 
 
867
 
 
868
 
 
869
bool ConfigLoader::create_engine_option_widget(
 
870
      EngineWindow *window,
 
871
      Param        *param,
 
872
      TreeHandler  *config,
 
873
      xmlNode      *element,
 
874
      string        category,
 
875
      string        w_name,
 
876
      string        w_type,
 
877
      string        w_ldesc)
 
878
{
 
879
 
 
880
  if(w_type == "color")
 
881
  {
 
882
    ColorButton *widget = new ColorButton();
 
883
    widget->init(category, w_name, config);
 
884
    param->widget = (Gtk::Widget*)widget;
 
885
    widget->signal_color_set().connect(
 
886
          sigc::bind( sigc::bind( sigc::mem_fun(
 
887
                *window, &EngineWindow::on_changed_colorbutton), widget) , w_name) );
 
888
    return 1;
 
889
  }
 
890
 
 
891
  if(w_type == "boolean")
 
892
  {
 
893
    CheckButton *widget = new CheckButton();
 
894
    widget->init(category, w_name, config);
 
895
    param->widget = (Gtk::Widget*)widget;
 
896
    widget->signal_toggled().connect(
 
897
          sigc::bind( sigc::bind( sigc::mem_fun(
 
898
                *window, &EngineWindow::on_changed_checkbutton), widget) , w_name) );
 
899
    return 1;
 
900
  }
 
901
 
 
902
  if(w_type == "integer" || w_type == "real")
 
903
  {
 
904
    // create synchronized slider and spinbutton
 
905
    Slider *widget1 = new Slider();
 
906
    widget1->init(category, w_name, config);
 
907
    param->widget1 = (Gtk::Widget*)widget1;
 
908
    widget1->signal_value_changed().connect(
 
909
          sigc::bind( sigc::bind( sigc::mem_fun(
 
910
                *window, &EngineWindow::on_changed_slider), widget1) , w_name) );
 
911
 
 
912
    SpinButton *widget2 = new SpinButton();
 
913
    widget2->init(category, w_name, config);
 
914
    param->widget2 = (Gtk::Widget*)widget2;
 
915
    widget2->signal_value_changed().connect(
 
916
          sigc::bind( sigc::bind( sigc::mem_fun(
 
917
                *window, &EngineWindow::on_changed_spinbutton), widget2) , w_name) );
 
918
 
 
919
    widget1->link_with_widget(widget2);
 
920
    widget2->link_with_widget(widget1);
 
921
 
 
922
    Gtk::HBox *hbox = new Gtk::HBox();
 
923
    hbox->pack_start(*widget1, Gtk::PACK_EXPAND_WIDGET);
 
924
    hbox->pack_start(*widget2, Gtk::PACK_SHRINK);
 
925
    param->widget = (Gtk::Widget*)hbox;
 
926
    return 1;
 
927
  }
 
928
 
 
929
  if(w_type == "enumeration")
 
930
  {
 
931
    ComboBox *widget = new ComboBox();
 
932
    if(w_ldesc != "")
 
933
    {
 
934
      param->widget_ebox = new Gtk::EventBox();
 
935
      param->widget_ebox->add(*widget);
 
936
    }
 
937
 
 
938
    for(xmlNode *option = Utils::Xml::get_node(element->children, "enumeration"); \
 
939
          option != NULL; \
 
940
          option = Utils::Xml::get_node(option->next, "enumeration"))
 
941
    {
 
942
      string option_value = Utils::Xml::get_property(option, "value"),
 
943
             option_name  = Utils::Xml::get_content (option, "label");
 
944
       if(option_value != "" && option_name != "")
 
945
        widget->append_text((char*)option_value.c_str(), (char*)option_name.c_str());
 
946
    }
 
947
 
 
948
    widget->init(category, w_name, config);
 
949
    param->widget = (Gtk::Widget*)widget;
 
950
    widget->signal_changed().connect(
 
951
          sigc::bind( sigc::bind( sigc::mem_fun(
 
952
                *window, &EngineWindow::on_changed_combobox), widget) , w_name) );
 
953
    return 1;
 
954
  }
 
955
 
 
956
  return 0;
 
957
}
 
958
 
 
959
 
 
960
 
 
961
 
 
962
 
 
963
 
 
964
 
 
965
void ConfigLoader::fill_with_engines(
 
966
      string category,
 
967
      ComboBox* box,
 
968
      TreeHandler* p_refConfig)
960
969
{
961
970
  if(box != NULL)
962
971
  {
967
976
      Engine *engine = engines;
968
977
      while(engine != NULL)
969
978
      {
970
 
        box->append_text(engine->name, (engine->lname != "") ? engine->lname : engine->name);
 
979
        box->append_text(
 
980
              engine->name,
 
981
              (engine->lname != "") ? engine->lname : engine->name);
 
982
 
971
983
        if(first_entry)
972
984
        {
973
985
          box->set_active_text(engine->name);
974
986
          first_entry = false;
975
987
        }
 
988
        
976
989
        engine = engine->next;
977
990
      }
978
991
 
979
992
      if(box->get_active_text() != "")
980
 
        ConfigLoader::attach_engine(box->get_active_text(), category, p_refConfig, false);
 
993
        ConfigLoader::attach_engine(
 
994
              box->get_active_text(),
 
995
              category,
 
996
              p_refConfig,
 
997
              false);
981
998
    }
 
999
 
982
1000
  }
983
1001
}
984
1002
 
997
1015
    perror((string("Error in accessing ") + directory).c_str());
998
1016
  else
999
1017
  {
1000
 
    while(entry = readdir(dir))
 
1018
    while( (entry = readdir(dir)) )
1001
1019
    {
1002
1020
      string name = string(entry->d_name);
1003
1021
      if(name.length() > 4)
1017
1035
  return loaded_profile;
1018
1036
}
1019
1037
 
 
1038
 
1020
1039
bool ConfigLoader::load_profile(string filename)
1021
1040
{
1022
1041
  if(!Utils::Io::check_file(filename)) // if file does not exists (or is no regular file)
1030
1049
  
1031
1050
  xmlNode* root = xmlDocGetRootElement(doc);
1032
1051
 
1033
 
  if(root == NULL)
1034
 
  {
1035
 
    xmlFreeDoc(doc);
1036
 
    return 0;
1037
 
  }
1038
 
 
1039
 
  if(strcmp((char*)root->name, "profile"))
 
1052
  if(root == NULL || strcmp((char*)root->name, "profile"))
1040
1053
  {
1041
1054
    xmlFreeDoc(doc);
1042
1055
    return 0;
1083
1096
    profile = profile->next;
1084
1097
  }
1085
1098
 
1086
 
//todo: add only profiles with different names _AND_ lnames!
1087
 
 
1088
1099
  profile->name = name;
1089
1100
  profile->doc  = doc;
1090
1101
  profile->next = NULL;
1091
 
  
1092
1102
  profile->lname = Utils::Xml::get_content(root, "long_name");
1093
 
  
 
1103
 
1094
1104
  return 1;
1095
1105
}
1096
1106
 
1122
1132
  {
1123
1133
    box->append_text("none", _("None"));
1124
1134
    box->append_text("theme", _("Theme Default"));
1125
 
    //box->append_text("none", "-----");
1126
 
    
 
1135
 
1127
1136
    if(profiles != NULL)
1128
1137
    {
1129
1138
      Profile *profile = profiles;
1130
1139
      while(profile != NULL)
1131
1140
      {
1132
 
        box->append_text(profile->name, (profile->lname != "") ? profile->lname : profile->name);
 
1141
        box->append_text(
 
1142
              profile->name,
 
1143
              (profile->lname != "") ? profile->lname : profile->name);
 
1144
 
1133
1145
        profile = profile->next;
1134
1146
      }
1135
1147
    }
1136
 
    
 
1148
 
1137
1149
  }
1138
1150
}
1139
1151
 
 
1152
 
1140
1153
void ConfigLoader::change_profile(string profile_name, TreeHandler *pConfig)
1141
1154
{
1142
1155
  if(profile_name == "none" || profile_name == "")
1167
1180
}
1168
1181
 
1169
1182
 
 
1183
void ConfigLoader::unload_engine_params()
 
1184
{
 
1185
  Param *param = params;
 
1186
  Param *param_next;
 
1187
  
 
1188
  while(param != NULL)
 
1189
  {
 
1190
    param_next = param->next;
 
1191
    delete param;
 
1192
    param = param_next;
 
1193
  }
 
1194
 
 
1195
  params = NULL;
 
1196
  // cout << "unloaded engine" << endl; // debugging ;-)
 
1197
}
 
1198
 
1170
1199
 
1171
1200
ConfigLoader::Param::Param()
1172
1201
{
1173
 
  this->box    = NULL;
1174
 
  this->label  = NULL;
1175
 
  this->desc   = NULL;
1176
 
  this->line   = NULL;
1177
 
  this->cbox   = NULL;
1178
 
  this->widget = NULL;
 
1202
  this->box         = NULL;
 
1203
  this->label       = NULL;
 
1204
  this->desc        = NULL;
 
1205
  this->line        = NULL;
 
1206
  this->cbox        = NULL;
 
1207
  this->widget      = NULL;
 
1208
  this->widget1     = NULL;
 
1209
  this->widget2     = NULL;
1179
1210
  this->widget_ebox = NULL;
1180
 
  this->next   = NULL;
1181
 
}
1182
 
 
1183
 
 
1184
 
 
1185
 
 
1186
 
/***********************************************************/
1187
 
//todo: remove these ugly doubled methods and create statics
1188
 
 
1189
 
/*
1190
 
const char* ConfigLoader::get_property(xmlNode* node, const char* property)
1191
 
{
1192
 
  if(node)
1193
 
  {    
1194
 
    xmlChar* value = xmlGetProp(node, (xmlChar*)property);
1195
 
 
1196
 
    if(value != NULL && strcmp((char*)value, ""))
1197
 
    {
1198
 
      string temp = string((char*)value);
1199
 
      xmlFree(value);
1200
 
      return temp.c_str();
1201
 
    }
1202
 
 
1203
 
    xmlFree(value);
1204
 
  }
1205
 
 
1206
 
  return NULL;
1207
 
}
1208
 
 
1209
 
const char* ConfigLoader::get_content(xmlNode* node, const char* content)
1210
 
{
1211
 
  if(node && content)
1212
 
  {
1213
 
    xmlNode *child = NULL;
1214
 
    char *loc = NULL;
1215
 
    string locale;
1216
 
//todo: only use locale for indeed translatable tags
1217
 
    if( content \
1218
 
        && (    !strcmp(content, "long_name") \
1219
 
             || !strcmp(content, "description") \
1220
 
             || !strcmp(content, "comment") \
1221
 
             || !strcmp(content, "label")
1222
 
           )
1223
 
        && (loc = setlocale(LC_ALL, NULL)) && strcmp(loc, "en")
1224
 
      )
1225
 
    {
1226
 
      const char* output = NULL;
1227
 
      locale = loc;
1228
 
 
1229
 
      if(output = get_lang(get_node(node->children, content), content, locale.c_str()))
1230
 
        return output;
1231
 
 
1232
 
      if(locale.find("@", 0) != string::npos)
1233
 
        if(output = get_lang(get_node(node->children, content), content, locale.substr(0, locale.find("@", 0)).c_str() ))
1234
 
          return output;
1235
 
 
1236
 
      if(locale.find(".", 0) != string::npos)
1237
 
        if(output = get_lang(get_node(node->children, content), content, locale.substr(0, locale.find(".", 0)).c_str() ))
1238
 
          return output;
1239
 
 
1240
 
      if(locale.find("_", 0) != string::npos)
1241
 
        if(output = get_lang(get_node(node->children, content), content, locale.substr(0, locale.find("_", 0)).c_str() ))
1242
 
          return output;
1243
 
    }
1244
 
    
1245
 
    return get_lang(get_node(node->children, content), content, NULL, true);
1246
 
  }
1247
 
 
1248
 
  return NULL;
1249
 
}
1250
 
 
1251
 
 
1252
 
const char* ConfigLoader::get_lang(xmlNode* node, const char* content, const char* locale, bool acceptSpace)
1253
 
{
1254
 
  xmlNode* child = node;
1255
 
  xmlChar *lang = NULL;
1256
 
 
1257
 
  while(child != NULL && content != NULL)
1258
 
  {
1259
 
    lang = xmlNodeGetLang(child);
1260
 
    if(acceptSpace || (lang && !strcmp((char*)lang, locale)))
1261
 
    {
1262
 
      //if(!acceptSpace)cout << "got content with " << locale << " for " << child->name << endl;
1263
 
      //else cout << "got default content for " << child->name << endl;
1264
 
      
1265
 
      xmlChar* value = xmlNodeGetContent(child);
1266
 
      if(value != NULL && strcmp((char*)value, ""))
1267
 
      {
1268
 
        string temp = string((char*)value);
1269
 
        xmlFree(value);
1270
 
        xmlFree(lang);
1271
 
        return temp.c_str();
1272
 
      }
1273
 
      xmlFree(value);
1274
 
    }
1275
 
    //else cout << "got no content with " << locale << " for " << child->name << endl;
1276
 
    xmlFree(lang);
1277
 
    child = get_node(child->next, content);
1278
 
  }
1279
 
 
1280
 
  return NULL;
1281
 
}
1282
 
 
1283
 
 
1284
 
 
1285
 
xmlNode* ConfigLoader::get_node(xmlNode* ref_node, string name)
1286
 
{
1287
 
  if(ref_node)
1288
 
  {
1289
 
    xmlNode* node = ref_node;
1290
 
  
1291
 
    while(node != NULL && !(node->type == XML_ELEMENT_NODE && !strcmp((char*)node->name, name.c_str())))
1292
 
      node = node->next;
1293
 
   
1294
 
    if(node != NULL && node->type == XML_ELEMENT_NODE && !strcmp((char*)node->name, name.c_str()))
1295
 
      return node;
1296
 
  }
1297
 
 
1298
 
  return NULL;
1299
 
}
1300
 
 
1301
 
*/
1302
 
 
 
1211
  this->next        = NULL;
 
1212
}
 
1213
 
 
1214
 
 
1215
ConfigLoader::Param::~Param()
 
1216
{
 
1217
  if(box)
 
1218
    delete box;
 
1219
  if(label)
 
1220
    delete label;
 
1221
  if(desc)
 
1222
    delete desc;
 
1223
  if(line)
 
1224
    delete line;
 
1225
  if(cbox)
 
1226
    delete cbox;
 
1227
  if(widget)
 
1228
    delete widget;
 
1229
  if(widget1)
 
1230
    delete widget1;
 
1231
  if(widget2)
 
1232
    delete widget2;
 
1233
  if(widget_ebox)
 
1234
    delete widget_ebox;
 
1235
}
1303
1236
 
1304
1237
 
1305
1238