[go: up one dir, main page]

Menu

[r247]: / gtk-ctafconf / src / main.cc  Maximize  Restore  History

Download this file

141 lines (113 with data), 3.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* main.cc
* Copyright (C) GESTES Cedric 2008 <ctaf42@gmail.com>
*
* main.cc is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* main.cc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with main.cc. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#include <gtkmm.h>
#include <iostream>
#include "gui-factory.hh"
#include "config-parser.hh"
#include "config-regexp.hh"
#ifdef ENABLE_NLS
# include <libintl.h>
#endif
void buildGui(const ConfigParser::ConfigList &values, GuiFactory &gui_factory)
{
ConfigParser::ConfigList::const_iterator it = values.begin();
for (;it != values.end(); ++it)
{
const std::string &type = (*it)->type();
const std::string &name = (*it)->name();
const ConfigObject::ConfigKeys &keys = (*it)->keys();
std::cout << "Config:" << name;
std::cout << " Type:" << type << std::endl;
if (type == "string")
{
const ConfigObject::ConfigKeys::const_iterator it = keys.find("default");
std::string def;
const ConfigObject::ConfigKeys::const_iterator it2 = keys.find("read");
if (it != keys.end())
def = (*it).second;
if (it2 != keys.end())
def = (*it2).second;
gui_factory.add_string(name, def);
}
else if (type == "frame")
{
gui_factory.add_frame(name);
}
else if (type == "checkbox")
{
gui_factory.add_checkbox(name, 1);
}
else if (type == "singlechoice")
{
std::vector<std::string> values;
const ConfigObject::ConfigKeys::const_iterator itd = keys.find("default");
std::string def;
if (itd != keys.end())
def = (*itd).second;
std::cout << "default: " << def << std::endl;
ConfigObject::ConfigKeys::const_iterator it = keys.begin();
for (;it != keys.end(); ++it)
{
if ((*it).first == "value")
values.push_back((*it).second);
}
gui_factory.add_singlechoice(name, values, def);
}
else if (type == "multichoice")
{
std::vector<std::string> defaults;
std::vector<std::string> values;
ConfigObject::ConfigKeys::const_iterator it = keys.begin();
for (;it != keys.end(); ++it)
{
if ((*it).first == "default")
defaults.push_back((*it).second);
else if ((*it).first == "value")
values.push_back((*it).second);
}
gui_factory.add_multichoice(name, values, defaults);
}
else if (type == "button")
gui_factory.add_button(name);
}
}
int
main (int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window dialog;
Gtk::Notebook notebook;
GuiFactory gui_factory(notebook);
/* ConfigParserCtafconf cp_ctafconf(gui_factory); */
/* ConfigParserEmacs cp_emacs(gui_factory); */
dialog.add(notebook);
dialog.set_default_size(640, 480);
ConfigParser config;
ConfigRegexp regexp;
config.parse("er.tpl");
regexp.process(config.values());
buildGui(config.values(), gui_factory);
dialog.show_all();
kit.run(dialog);
return 0;
}