Merge branch 'master' of git+ssh://repo.or.cz/srv/git/jben
[jben.git] / src / frame_maingui.cpp
blobeaab238db2428b1c071ee2344a0e22e015e92055
1 /*
2 Project: J-Ben
3 Author: Paul Goins
4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
8 File: frame_maingui.cpp
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "frame_maingui.h"
25 #include "version.h"
26 #ifndef __WIN32__
27 # include "jben.xpm"
28 # include "jben_48.xpm"
29 # include "jben_32.xpm"
30 # include "jben_16.xpm"
31 #endif
32 #include <gtkmm/stock.h>
33 #include <gtkmm/main.h>
34 #include <gtkmm/messagedialog.h>
35 #include <glibmm/i18n.h>
36 #include <boost/format.hpp>
37 #include "string_utils.h"
38 #include "preferences.h"
40 FrameMainGUI* FrameMainGUI::singleton = NULL;
42 FrameMainGUI& FrameMainGUI::Get() {
43 if(!singleton) singleton = new FrameMainGUI;
44 return *singleton;
47 void FrameMainGUI::Destroy() {
48 if(singleton) {
49 delete singleton;
50 singleton = NULL;
54 FrameMainGUI::FrameMainGUI() {
55 set_title(PROGRAM_NAME);
57 #ifndef __WIN32__
58 /* Load icons */
59 list< Glib::RefPtr<Gdk::Pixbuf> > lIcons;
60 lIcons.push_back(Gdk::Pixbuf::create_from_xpm_data(iconJben_xpm));
61 lIcons.push_back(Gdk::Pixbuf::create_from_xpm_data(iconJben_48_xpm));
62 lIcons.push_back(Gdk::Pixbuf::create_from_xpm_data(iconJben_32_xpm));
63 lIcons.push_back(Gdk::Pixbuf::create_from_xpm_data(iconJben_16_xpm));
64 set_icon_list(lIcons);
65 #endif
67 /* Init vars */
68 pdKanjiListEditor = NULL;
69 pdVocabListEditor = NULL;
70 pdConfig = NULL;
71 pdKanjiPreTest = NULL;
72 pfHWPad = NULL;
73 pfKSearch = NULL;
75 /* Logic copied from widget_storeddialog */
76 Preferences* p = Preferences::Get();
77 string& size = p->GetSetting("gui.main.size");
78 int x, y;
79 if(!size.empty()) {
80 std::list<string> ls = StrTokenize<char>(size, "x");
81 if(ls.size()>=2) {
82 x = atoi(ls.front().c_str());
83 ls.pop_front();
84 y = atoi(ls.front().c_str());
85 set_default_size(x,y);
89 /* Create menu */
90 refActionGroup = Gtk::ActionGroup::create();
91 /* File menu */
92 refActionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
93 refActionGroup->add(
94 Gtk::Action::create("MenuFileQuit", Gtk::Stock::QUIT),
95 sigc::mem_fun(*this, &FrameMainGUI::OnMenuFileQuit));
96 /* Edit Menu */
97 refActionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
98 refActionGroup->add(
99 Gtk::Action::create("MenuEditVocab", _("_Vocab Study List")),
100 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditVocab));
101 refActionGroup->add(
102 Gtk::Action::create("MenuEditKanji", _("_Kanji Study List")),
103 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditKanji));
104 refActionGroup->add(
105 Gtk::Action::create("MenuEditPrefs", Gtk::Stock::PREFERENCES),
106 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditPrefs));
107 /* Practice Menu */
108 refActionGroup->add(Gtk::Action::create("MenuPractice", _("_Practice")));
109 refActionGroup->add(
110 Gtk::Action::create("MenuPracticeKanji", _("_Kanji")),
111 sigc::mem_fun(*this, &FrameMainGUI::OnMenuPracticeKanji));
112 /* Tools Menu */
113 refActionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
114 refActionGroup->add(
115 Gtk::Action::create("MenuToolsHand",
116 _("_Handwriting Recognition for Kanji")),
117 sigc::mem_fun(*this, &FrameMainGUI::OnMenuToolsHand));
118 refActionGroup->add(
119 Gtk::Action::create("MenuToolsKanjiSearch",
120 _("_Kanji Search")),
121 sigc::mem_fun(*this, &FrameMainGUI::OnMenuToolsKanjiSearch));
122 /* Help Menu */
123 refActionGroup->add(Gtk::Action::create("MenuHelp", _("_Help")));
124 refActionGroup->add(
125 Gtk::Action::create("MenuHelpAbout", Gtk::Stock::ABOUT),
126 sigc::mem_fun(*this, &FrameMainGUI::OnMenuHelpAbout));
127 refActionGroup->add(
128 Gtk::Action::create("MenuHelpLicense", _("_License Information...")),
129 sigc::mem_fun(*this, &FrameMainGUI::OnMenuHelpLicense));
131 refUIManager = Gtk::UIManager::create();
132 refUIManager->insert_action_group(refActionGroup);
133 add_accel_group(refUIManager->get_accel_group());
134 refUIManager->add_ui_from_string(
135 "<ui>"
136 " <menubar name='MenuBar'>"
137 " <menu action='MenuFile'>"
138 " <menuitem action='MenuFileQuit'/>"
139 " </menu>"
140 " <menu action='MenuEdit'>"
141 " <menuitem action='MenuEditVocab'/>"
142 " <menuitem action='MenuEditKanji'/>"
143 " <separator/>"
144 " <menuitem action='MenuEditPrefs'/>"
145 " </menu>"
146 " <menu action='MenuPractice'>"
147 " <menuitem action='MenuPracticeKanji'/>"
148 " </menu>"
149 " <menu action='MenuTools'>"
150 " <menuitem action='MenuToolsHand'/>"
151 " <menuitem action='MenuToolsKanjiSearch'/>"
152 " </menu>"
153 " <menu action='MenuHelp'>"
154 " <menuitem action='MenuHelpAbout'/>"
155 " <menuitem action='MenuHelpLicense'/>"
156 " </menu>"
157 " </menubar>"
158 "</ui>");
160 /* Create window layout */
161 add(layoutBox);
162 layoutBox.pack_start(*(refUIManager->get_widget("/MenuBar")),
163 Gtk::PACK_SHRINK);
164 layoutBox.pack_start(tabs);
165 tabs.append_page(panelWordDict, _("Word Dictionary"));
166 tabs.append_page(panelKanjiDict, _("Kanji Dictionary"));
168 Update();
169 show_all_children();
172 FrameMainGUI::~FrameMainGUI() {
173 if(pfHWPad) delete pfHWPad;
174 if(pfKSearch) delete pfKSearch;
175 if(pdKanjiListEditor) delete pdKanjiListEditor;
176 if(pdVocabListEditor) delete pdVocabListEditor;
177 if(pdConfig) delete pdConfig;
178 if(pdKanjiPreTest) delete pdKanjiPreTest;
180 /* Again, this is copied from widget_storeddialog. */
181 Preferences* p = Preferences::Get();
182 int x, y;
183 get_size(x,y);
184 string& size = p->GetSetting("gui.main.size");
185 size = (boost::format("%dx%d") % x % y).str();
188 void FrameMainGUI::Update() {
189 panelWordDict.Update();
190 panelKanjiDict.Update();
191 if(pfHWPad) pfHWPad->Update();
192 if(pfKSearch) pfKSearch->Update();
195 void FrameMainGUI::OnMenuFileQuit() {hide();}
197 void FrameMainGUI::OnMenuEditVocab() {
198 if(!pdVocabListEditor)
199 pdVocabListEditor = new DialogVocabListEditor(*this);
200 int result = pdVocabListEditor->run();
201 pdVocabListEditor->hide();
202 if(result==Gtk::RESPONSE_OK)
203 panelWordDict.Update();
206 void FrameMainGUI::OnMenuEditKanji() {
207 if(!pdKanjiListEditor)
208 pdKanjiListEditor = new DialogKanjiListEditor(*this);
209 int result = pdKanjiListEditor->run();
210 pdKanjiListEditor->hide();
211 if(result==Gtk::RESPONSE_OK)
212 panelKanjiDict.Update();
215 void FrameMainGUI::OnMenuEditPrefs() {
216 if(!pdConfig)
217 pdConfig = new DialogConfig(*this);
218 int result = pdConfig->run();
219 pdConfig->hide();
220 if(result==Gtk::RESPONSE_OK)
221 Update();
224 void FrameMainGUI::OnMenuPracticeKanji() {
225 /* Test config dialog */
226 if(!pdKanjiPreTest)
227 pdKanjiPreTest = new DialogKanjiPreTest(*this);
228 else
229 pdKanjiPreTest->Update(); /* Updates controls in case the kanji list
230 has changed. */
231 int result = pdKanjiPreTest->run();
232 pdKanjiPreTest->hide();
233 if(result==Gtk::RESPONSE_OK) {
234 /* Blank out the dictionary panels */
235 panelKanjiDict.SetSearchString("");
236 panelWordDict .SetSearchString("");
237 panelKanjiDict.Update();
238 panelWordDict .Update();
239 /* Test dialog */
240 DialogKanjiTest dkt(*this, *pdKanjiPreTest);
241 result = dkt.run();
242 dkt.hide();
243 /* Result dialog */
244 DialogKanjiPostTest dkpt(*this, dkt);
245 dkpt.run();
246 dkpt.hide();
250 void FrameMainGUI::OnMenuToolsHand() {
251 if(!pfHWPad)
252 pfHWPad = new FrameHWPad();
253 else
254 pfHWPad->present();
255 pfHWPad->show();
258 void FrameMainGUI::OnMenuToolsKanjiSearch() {
259 if(!pfKSearch)
260 pfKSearch = new FrameKSearch();
261 else
262 pfKSearch->present();
263 pfKSearch->show();
266 void FrameMainGUI::OnMenuHelpAbout() {
267 Gtk::MessageDialog md
268 (*this, (boost::format(
269 _("%s v%s\n"
270 "By %s\n"
271 "Copyright %s\n\n"
273 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
274 "http://www.physics.ucla.edu/~grosenth/\n\n"
276 "Powered by the many Japanese dictionary files from Monash "
277 "University, many thanks to Jim Breen:\n"
278 "http://www.csse.monash.edu.au/~jwb/japanese.html\n"
279 "Thanks also to Jim Rose of kanjicafe.com for his extended "
280 "RADKFILE2/KRADFILE2 databases and derived database files.\n\n"
282 "Built using gtkmm: http://www.gtkmm.org/\n\n"
284 "Hand writing recognition is based upon code from im-ja "
285 "(http://im-ja.sourceforge.net/) and KanjiPad "
286 "(http://fishsoup.net/software/kanjipad/). KanjiPad was "
287 "written by Owen Taylor.\n\n"
289 "See \"Help->License Information...\" for important license "
290 "details."))
291 % PROGRAM_NAME % VERSION_STR % AUTHOR_NAME % COPYRIGHT_DATE).str());
292 md.set_title((boost::format(_("About %s")) % PROGRAM_NAME).str());
293 md.run();
296 void FrameMainGUI::OnMenuHelpLicense() {
297 string licenseMessage(
298 _("Program distributed under the GNU General Public License (GPL) "
299 "version 2:\n"
300 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
302 "The included dictionary data files, with the exception of the "
303 "handwriting databases and Jim Rose's extensions to the radical "
304 "databases, are distributed under a separate license specified "
305 "at\n"
306 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
308 "Jim Rose's extended databases are licensed to Monash University "
309 "with permission to modify and redistribute the files, as long as "
310 "his copyright notices are preserved.\n\n"
312 "The SKIP (System of Kanji Indexing by Patterns) system for ordering "
313 "kanji was developed by Jack Halpern (Kanji Dictionary Publishing "
314 "Society at http://www.kanji.org/), and is used with his "
315 "permission.\n\n"
317 "Copies of the GNU General Public License, Monash University's "
318 "license for the dictionary files and documentation for the "
319 "dictionary files are contained in this program's \"license\" "
320 "directory."));
321 #ifndef __WIN32__
322 licenseMessage.append(
323 (boost::format(_(" (On this system, it should be located at:\n%s)"))
324 % LICENSEDIR).str());
325 #endif
327 Gtk::MessageDialog md(*this, licenseMessage);
328 md.set_title(_("License Information"));
329 md.run();