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"
28 # include "jben_48.xpm"
29 # include "jben_32.xpm"
30 # include "jben_16.xpm"
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
;
47 void FrameMainGUI::Destroy() {
54 FrameMainGUI::FrameMainGUI() {
55 set_title(PROGRAM_NAME
);
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
);
68 pdKanjiListEditor
= NULL
;
69 pdVocabListEditor
= NULL
;
71 pdKanjiPreTest
= NULL
;
75 /* Logic copied from widget_storeddialog */
76 Preferences
* p
= Preferences::Get();
77 string
& size
= p
->GetSetting("gui.main.size");
80 std::list
<string
> ls
= StrTokenize
<char>(size
, "x");
82 x
= atoi(ls
.front().c_str());
84 y
= atoi(ls
.front().c_str());
85 set_default_size(x
,y
);
90 refActionGroup
= Gtk::ActionGroup::create();
92 refActionGroup
->add(Gtk::Action::create("MenuFile", _("_File")));
94 Gtk::Action::create("MenuFileQuit", Gtk::Stock::QUIT
),
95 sigc::mem_fun(*this, &FrameMainGUI::OnMenuFileQuit
));
97 refActionGroup
->add(Gtk::Action::create("MenuEdit", _("_Edit")));
99 Gtk::Action::create("MenuEditVocab", _("_Vocab Study List")),
100 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditVocab
));
102 Gtk::Action::create("MenuEditKanji", _("_Kanji Study List")),
103 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditKanji
));
105 Gtk::Action::create("MenuEditPrefs", Gtk::Stock::PREFERENCES
),
106 sigc::mem_fun(*this, &FrameMainGUI::OnMenuEditPrefs
));
108 refActionGroup
->add(Gtk::Action::create("MenuPractice", _("_Practice")));
110 Gtk::Action::create("MenuPracticeKanji", _("_Kanji")),
111 sigc::mem_fun(*this, &FrameMainGUI::OnMenuPracticeKanji
));
113 refActionGroup
->add(Gtk::Action::create("MenuTools", _("_Tools")));
115 Gtk::Action::create("MenuToolsHand",
116 _("_Handwriting Recognition for Kanji")),
117 sigc::mem_fun(*this, &FrameMainGUI::OnMenuToolsHand
));
119 Gtk::Action::create("MenuToolsKanjiSearch",
121 sigc::mem_fun(*this, &FrameMainGUI::OnMenuToolsKanjiSearch
));
123 refActionGroup
->add(Gtk::Action::create("MenuHelp", _("_Help")));
125 Gtk::Action::create("MenuHelpAbout", Gtk::Stock::ABOUT
),
126 sigc::mem_fun(*this, &FrameMainGUI::OnMenuHelpAbout
));
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(
136 " <menubar name='MenuBar'>"
137 " <menu action='MenuFile'>"
138 " <menuitem action='MenuFileQuit'/>"
140 " <menu action='MenuEdit'>"
141 " <menuitem action='MenuEditVocab'/>"
142 " <menuitem action='MenuEditKanji'/>"
144 " <menuitem action='MenuEditPrefs'/>"
146 " <menu action='MenuPractice'>"
147 " <menuitem action='MenuPracticeKanji'/>"
149 " <menu action='MenuTools'>"
150 " <menuitem action='MenuToolsHand'/>"
151 " <menuitem action='MenuToolsKanjiSearch'/>"
153 " <menu action='MenuHelp'>"
154 " <menuitem action='MenuHelpAbout'/>"
155 " <menuitem action='MenuHelpLicense'/>"
160 /* Create window layout */
162 layoutBox
.pack_start(*(refUIManager
->get_widget("/MenuBar")),
164 layoutBox
.pack_start(tabs
);
165 tabs
.append_page(panelWordDict
, _("Word Dictionary"));
166 tabs
.append_page(panelKanjiDict
, _("Kanji Dictionary"));
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();
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() {
217 pdConfig
= new DialogConfig(*this);
218 int result
= pdConfig
->run();
220 if(result
==Gtk::RESPONSE_OK
)
224 void FrameMainGUI::OnMenuPracticeKanji() {
225 /* Test config dialog */
227 pdKanjiPreTest
= new DialogKanjiPreTest(*this);
229 pdKanjiPreTest
->Update(); /* Updates controls in case the kanji list
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();
240 DialogKanjiTest
dkt(*this, *pdKanjiPreTest
);
244 DialogKanjiPostTest
dkpt(*this, dkt
);
250 void FrameMainGUI::OnMenuToolsHand() {
252 pfHWPad
= new FrameHWPad();
258 void FrameMainGUI::OnMenuToolsKanjiSearch() {
260 pfKSearch
= new FrameKSearch();
262 pfKSearch
->present();
266 void FrameMainGUI::OnMenuHelpAbout() {
267 Gtk::MessageDialog md
268 (*this, (boost::format(
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 "
291 % PROGRAM_NAME
% VERSION_STR
% AUTHOR_NAME
% COPYRIGHT_DATE
).str());
292 md
.set_title((boost::format(_("About %s")) % PROGRAM_NAME
).str());
296 void FrameMainGUI::OnMenuHelpLicense() {
297 string
licenseMessage(
298 _("Program distributed under the GNU General Public License (GPL) "
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 "
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 "
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\" "
322 licenseMessage
.append(
323 (boost::format(_(" (On this system, it should be located at:\n%s)"))
324 % LICENSEDIR
).str());
327 Gtk::MessageDialog
md(*this, licenseMessage
);
328 md
.set_title(_("License Information"));