154
172
xmlNode *element)
158
xmlChar* value = NULL;
159
xmlChar* disabled = NULL;
161
175
if(!strcmp((char*)element->name, "engine"))
164
id = xmlGetProp(element, (xmlChar*)"name");
165
value = xmlGetProp(element, (xmlChar*)"category");
166
disabled = xmlGetProp(element, (xmlChar*)"disabled");
168
if(id && value && strcmp((char*)id, "") && strcmp((char*)value, ""))
170
// cout << "found engine " << id << " for category " << value << endl; // debugging ;-)
172
if(disabled && !strcasecmp((char*)disabled, "true"))
173
ConfigLoader::attach_engine((char*)id, (char*)value, pConfig, false);
174
// pConfig->setEngineOverride((char*)value, false);
176
ConfigLoader::attach_engine((char*)id, (char*)value, pConfig, true);
177
// pConfig->setEngineOverride((char*)value, true);
179
reload_enginetable_row(string((char*)value), pWindow);
180
select_engine(string((char*)value), string((char*)id), pWindow);
183
xmlNode* subelement = element->children;
186
xmlChar* subdisabled;
187
while( subelement != NULL )
193
if(subelement->type == XML_ELEMENT_NODE)
195
subname = xmlGetProp(subelement, (xmlChar*)"name");
196
subvalue = xmlGetProp(subelement, (xmlChar*)"value");
197
subdisabled = xmlGetProp(subelement, (xmlChar*)"disabled");
199
if(subname && subvalue && strcmp((char*)subname, "") && strcmp((char*)subvalue, ""))
201
// cout << "-> found subelement " << subname << endl; // debugging ;-)
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
207
if(subdisabled && !strcasecmp((char*)subdisabled, "true"))
208
pConfig->setOverride((char*)value, (char*)subname, false);
210
pConfig->setOverride((char*)value, (char*)subname, true);
216
xmlFree(subdisabled);
219
subelement = subelement->next;
235
void ConfigLoader::fill_config(TreeHandler* pConfig,
236
const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
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");
181
if(name != "" && category != "")
183
// cout << "found engine " << name << " for category " << category << endl; // debugging ;-)
185
if(disabled != "" && !strcasecmp(disabled.c_str(), "true"))
186
ConfigLoader::attach_engine(name, category, pConfig, false);
187
// pConfig->setEngineOverride(category, false);
189
ConfigLoader::attach_engine(name, category, pConfig, true);
190
// pConfig->setEngineOverride(category, true);
192
reload_enginetable_row(category, pWindow);
193
select_engine(category, name, pWindow);
195
ConfigLoader::load_theme_engine_options(pConfig, category, element);
203
void ConfigLoader::load_theme_engine_options(
204
TreeHandler *pConfig,
209
xmlNode *element = Utils::Xml::get_node(engine->children, "element");
211
while( element != NULL )
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");
217
if(name != "" && value != "")
219
//cout << "-> found engine option " << name << endl; // debugging ;-)
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());
225
if(disabled != "" && !strcasecmp(disabled.c_str(), "true"))
226
pConfig->setOverride(category, name, false);
228
pConfig->setOverride(category, name, true);
231
element = Utils::Xml::get_node(element->next, "element");
239
void ConfigLoader::fill_config(
240
TreeHandler* pConfig,
241
const Glib::RefPtr<Gnome::Glade::Xml>& refGlade,
241
246
//todo: safer implementation (atoi)
687
void ConfigLoader::load_engine_params(EngineWindow* window, string engine_name, string category, TreeHandler* config)
691
if(engine_name != "" && engines != NULL)
693
Engine *engine = engines;
695
while(engine != NULL)
697
if(engine_name == engine->name)
699
engine = engine->next;
702
if(engine != NULL && engine_name == engine->name)
704
xmlNode* root = xmlDocGetRootElement(engine->doc);
705
xmlNode* element = root->children;
708
while(element != NULL)
710
if(element->type == XML_ELEMENT_NODE && !strcmp((char*)element->name,"option"))
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;
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;
734
// create new Parameter (for saving widgets in order to be able to delete them later)
738
params = new Param();
744
while(param->next != NULL)
746
if(param->name == w_name)
753
if(param->name == w_name)
760
element = element->next;
761
break; // goto next parameter
763
param->next = new Param();
767
param->name = w_name;
772
// attention: recycling of skipParam *g*
777
// create widgets of that new Parameter and attach them to the output table
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) );
791
if(w_type == "color")
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) );
798
else if(w_type == "boolean")
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) );
805
else if(w_type == "integer")
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) );
813
else if(w_type == "real")
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) );
821
else if(w_type == "enumeration")
823
ComboBox *widget = new ComboBox();
826
param->widget_ebox = new Gtk::EventBox();
827
param->widget_ebox->add(*widget);
831
for(xmlNode* option = element->children; option != NULL; option = option->next)
833
if(option->type == XML_ELEMENT_NODE && !strcmp((char*)option->name, "enumeration"))
836
string option_value = (dummy = get_property(option, "value")) ? dummy : "",
837
option_name = (dummy = get_content(option, "label")) ? dummy : "";
839
string option_value = Utils::Xml::get_property(option, "value"),
840
option_name = Utils::Xml::get_content(option, "label");
842
if(option_value != "" && option_name != "")
844
widget->append_text((char*)option_value.c_str(), (char*)option_name.c_str());
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) );
856
//todo: delete param and its widgets!
863
char* config_label = NULL;
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);
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() )),
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);
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) );
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);
898
window->tooltips.set_tip(*param->widget, w_ldesc);
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);
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);
911
param->box->pack_start(*param->widget, Gtk::PACK_EXPAND_WIDGET);
919
element = element->next;
928
void ConfigLoader::unload_engine_params()
930
Param *param = params;
935
param_next = param->next;
947
delete param->widget;
948
if(param->widget_ebox)
949
delete param->widget_ebox;
955
// cout << "unloaded engine" << endl; // debugging ;-)
959
void ConfigLoader::fill_with_engines(string category, ComboBox* box, TreeHandler* p_refConfig)
691
void ConfigLoader::load_engine_params(
692
EngineWindow* window,
698
g_return_if_fail(engines != NULL);
699
g_return_if_fail(engine_name != "");
700
g_return_if_fail(category != "");
702
Engine *engine = engines;
703
while(engine != NULL)
705
if(engine_name == engine->name)
707
engine = engine->next;
710
if(engine == NULL || engine_name != engine->name)
713
xmlNode *root = xmlDocGetRootElement(engine->doc);
714
xmlNode *element = Utils::Xml::get_node(root->children, "option");
719
while(element != NULL)
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");
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)) )
733
element = Utils::Xml::get_node(element->next, "option");
734
continue; // goto next engine parameter
738
// create widget(s) of that new Parameter and attach them to the output table
739
if(ConfigLoader::create_engine_option_widget(
749
char* config_label = NULL;
751
param->box = new Gtk::HBox();
753
param->label = new Gtk::EventBox();
754
param->label->add_label(w_lname != "" ? w_lname : param->name);
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() )),
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);
769
param->cbox = new CheckButton();
770
param->cbox->init(category, w_name, config, false);
772
if(param->widget1 && param->widget2)
774
param->cbox->signal_toggled().connect(
775
sigc::bind( sigc::bind( sigc::bind( sigc::bind( sigc::mem_fun(
776
*window, &EngineWindow::on_checkbox_toggled),
779
param->cbox), w_name) );
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),
787
param->cbox), w_name) );
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);
797
window->tooltips.set_tip(*param->widget, w_ldesc);
800
window->table.resize(y+2, 2); // rows, coloumns
802
window->table.attach(
805
Gtk::FILL | Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
807
window->table.attach(
810
~Gtk::FILL & ~Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
812
window->table.attach(
815
Gtk::FILL | Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
817
window->table.attach(*param->line,
819
Gtk::FILL | Gtk::EXPAND, ~Gtk::FILL & ~Gtk::EXPAND);
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);
826
param->box->pack_start(*param->widget, Gtk::PACK_EXPAND_WIDGET);
831
element = Utils::Xml::get_node(element->next, "option");
837
ConfigLoader::Param* ConfigLoader::create_unique_param(string name)
842
params = new Param();
848
while(param->next != NULL)
850
if(param->name == name)
854
if(param->name == name)
857
param->next = new Param();
869
bool ConfigLoader::create_engine_option_widget(
870
EngineWindow *window,
880
if(w_type == "color")
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) );
891
if(w_type == "boolean")
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) );
902
if(w_type == "integer" || w_type == "real")
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) );
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) );
919
widget1->link_with_widget(widget2);
920
widget2->link_with_widget(widget1);
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;
929
if(w_type == "enumeration")
931
ComboBox *widget = new ComboBox();
934
param->widget_ebox = new Gtk::EventBox();
935
param->widget_ebox->add(*widget);
938
for(xmlNode *option = Utils::Xml::get_node(element->children, "enumeration"); \
940
option = Utils::Xml::get_node(option->next, "enumeration"))
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());
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) );
965
void ConfigLoader::fill_with_engines(
968
TreeHandler* p_refConfig)
1183
void ConfigLoader::unload_engine_params()
1185
Param *param = params;
1188
while(param != NULL)
1190
param_next = param->next;
1196
// cout << "unloaded engine" << endl; // debugging ;-)
1171
1200
ConfigLoader::Param::Param()
1178
this->widget = NULL;
1207
this->widget = NULL;
1208
this->widget1 = NULL;
1209
this->widget2 = NULL;
1179
1210
this->widget_ebox = NULL;
1186
/***********************************************************/
1187
//todo: remove these ugly doubled methods and create statics
1190
const char* ConfigLoader::get_property(xmlNode* node, const char* property)
1194
xmlChar* value = xmlGetProp(node, (xmlChar*)property);
1196
if(value != NULL && strcmp((char*)value, ""))
1198
string temp = string((char*)value);
1200
return temp.c_str();
1209
const char* ConfigLoader::get_content(xmlNode* node, const char* content)
1213
xmlNode *child = NULL;
1216
//todo: only use locale for indeed translatable tags
1218
&& ( !strcmp(content, "long_name") \
1219
|| !strcmp(content, "description") \
1220
|| !strcmp(content, "comment") \
1221
|| !strcmp(content, "label")
1223
&& (loc = setlocale(LC_ALL, NULL)) && strcmp(loc, "en")
1226
const char* output = NULL;
1229
if(output = get_lang(get_node(node->children, content), content, locale.c_str()))
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() ))
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() ))
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() ))
1245
return get_lang(get_node(node->children, content), content, NULL, true);
1252
const char* ConfigLoader::get_lang(xmlNode* node, const char* content, const char* locale, bool acceptSpace)
1254
xmlNode* child = node;
1255
xmlChar *lang = NULL;
1257
while(child != NULL && content != NULL)
1259
lang = xmlNodeGetLang(child);
1260
if(acceptSpace || (lang && !strcmp((char*)lang, locale)))
1262
//if(!acceptSpace)cout << "got content with " << locale << " for " << child->name << endl;
1263
//else cout << "got default content for " << child->name << endl;
1265
xmlChar* value = xmlNodeGetContent(child);
1266
if(value != NULL && strcmp((char*)value, ""))
1268
string temp = string((char*)value);
1271
return temp.c_str();
1275
//else cout << "got no content with " << locale << " for " << child->name << endl;
1277
child = get_node(child->next, content);
1285
xmlNode* ConfigLoader::get_node(xmlNode* ref_node, string name)
1289
xmlNode* node = ref_node;
1291
while(node != NULL && !(node->type == XML_ELEMENT_NODE && !strcmp((char*)node->name, name.c_str())))
1294
if(node != NULL && node->type == XML_ELEMENT_NODE && !strcmp((char*)node->name, name.c_str()))
1215
ConfigLoader::Param::~Param()