"Fossies" - the Fresh Open Source Software Archive 
Member "regexxer-0.10/src/prefdialog.cc" (6 Oct 2011, 5696 Bytes) of package /linux/privat/old/regexxer-0.10.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "prefdialog.cc" see the
Fossies "Dox" file reference documentation.
1 /*
2 * Copyright (c) 2002-2007 Daniel Elstner <daniel.kitta@gmail.com>
3 *
4 * This file is part of regexxer.
5 *
6 * regexxer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * regexxer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with regexxer; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "prefdialog.h"
22 #include "globalstrings.h"
23 #include "stringutils.h"
24 #include "translation.h"
25 #include "settings.h"
26
27 #include <glib.h>
28 #include <gtkmm.h>
29 #include <vector>
30
31 #include <config.h>
32
33 namespace Regexxer
34 {
35
36 /**** Regexxer::PrefDialog *************************************************/
37
38 PrefDialog::PrefDialog(Gtk::Window& parent)
39 :
40 dialog_ (),
41 button_textview_font_ (0),
42 button_match_color_ (0),
43 button_current_color_ (0),
44 entry_fallback_ (0),
45 entry_fallback_changed_ (false)
46 {
47 load_xml();
48 dialog_->set_transient_for(parent);
49
50 initialize_configuration();
51 connect_signals();
52 }
53
54 PrefDialog::~PrefDialog()
55 {}
56
57 void PrefDialog::load_xml()
58 {
59 using namespace Gtk;
60
61 const Glib::RefPtr<Builder> xml = Builder::create_from_file(ui_prefdialog_filename);
62
63 Dialog* prefdialog = 0;
64 xml->get_widget("prefdialog", prefdialog);
65 dialog_.reset(prefdialog);
66
67 xml->get_widget("button_textview_font", button_textview_font_);
68 xml->get_widget("button_match_color", button_match_color_);
69 xml->get_widget("button_current_color", button_current_color_);
70 xml->get_widget("entry_fallback", entry_fallback_);
71
72 const Glib::RefPtr<SizeGroup> size_group = SizeGroup::create(SIZE_GROUP_VERTICAL);
73
74 Label* label_utf8 = 0, *label_locale = 0;
75 Box* box_fallback = 0;
76
77 xml->get_widget("label_utf8", label_utf8);
78 xml->get_widget("label_locale", label_locale);
79 xml->get_widget("box_fallback", box_fallback);
80
81 size_group->add_widget(*label_utf8);
82 size_group->add_widget(*label_locale);
83 size_group->add_widget(*box_fallback);
84 }
85
86 void PrefDialog::connect_signals()
87 {
88 dialog_->signal_response().connect(
89 sigc::mem_fun(*this, &PrefDialog::on_response));
90
91 button_textview_font_->signal_font_set().connect(
92 sigc::mem_fun(*this, &PrefDialog::on_textview_font_set));
93
94 button_match_color_->signal_color_set().connect(
95 sigc::mem_fun(*this, &PrefDialog::on_match_color_set));
96
97 button_current_color_->signal_color_set().connect(
98 sigc::mem_fun(*this, &PrefDialog::on_current_color_set));
99
100 entry_fallback_->signal_changed().connect(
101 sigc::mem_fun(*this, &PrefDialog::on_entry_fallback_changed));
102
103 entry_fallback_->signal_activate().connect(
104 sigc::mem_fun(*this, &PrefDialog::on_entry_fallback_activate));
105 }
106
107 void PrefDialog::on_response(int)
108 {
109 if (entry_fallback_changed_)
110 entry_fallback_->activate();
111
112 dialog_->hide();
113 }
114
115 void PrefDialog::on_conf_value_changed(const Glib::ustring& key)
116 {
117 Glib::RefPtr<Gio::Settings> settings = Settings::instance();
118
119 if (key.raw() == conf_key_textview_font)
120 {
121 button_textview_font_->set_font_name(settings->get_string(key));
122 }
123 else if (key.raw() == conf_key_match_color)
124 {
125 button_match_color_->set_color(Gdk::Color(settings->get_string(key)));
126 }
127 else if (key.raw() == conf_key_current_match_color)
128 {
129 button_current_color_->set_color(Gdk::Color(settings->get_string(key)));
130 }
131 else if (key.raw() == conf_key_fallback_encoding)
132 {
133 entry_fallback_->set_text(settings->get_string(key));
134 entry_fallback_changed_ = false;
135 }
136 }
137
138 void PrefDialog::initialize_configuration()
139 {
140 Glib::RefPtr<Gio::Settings> settings = Settings::instance();
141 const std::vector<Glib::ustring> entries = settings->list_keys();
142
143 for (std::vector<Glib::ustring>::const_iterator p = entries.begin(); p != entries.end(); ++p)
144 on_conf_value_changed(*p);
145
146 settings->bind(conf_key_textview_font, button_textview_font_, "font_name");
147 }
148
149 void PrefDialog::on_textview_font_set()
150 {
151 const Glib::ustring value = button_textview_font_->get_font_name();
152 Settings::instance()->set_string(conf_key_textview_font, value);
153 }
154
155 void PrefDialog::on_match_color_set()
156 {
157 const Glib::ustring value = Util::color_to_string(button_match_color_->get_color());
158 Settings::instance()->set_string(conf_key_match_color, value);
159 }
160
161 void PrefDialog::on_current_color_set()
162 {
163 const Glib::ustring value = Util::color_to_string(button_current_color_->get_color());
164 Settings::instance()->set_string(conf_key_current_match_color, value);
165 }
166
167 void PrefDialog::on_entry_fallback_changed()
168 {
169 entry_fallback_changed_ = true;
170 }
171
172 void PrefDialog::on_entry_fallback_activate()
173 {
174 const Glib::ustring fallback_encoding = entry_fallback_->get_text();
175
176 if (Util::validate_encoding(fallback_encoding.raw()))
177 {
178 Settings::instance()->set_string(conf_key_fallback_encoding,
179 fallback_encoding.uppercase());
180
181 entry_fallback_changed_ = false;
182 }
183 else
184 {
185 const Glib::ustring message =
186 Util::compose(_("\342\200\234%1\342\200\235 is not a valid encoding."), fallback_encoding);
187
188 Gtk::MessageDialog error_dialog (*dialog_, message, false,
189 Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
190 error_dialog.run();
191 }
192 }
193
194 } // namespace Regexxer