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: dialog_addkanjibyjlpt.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 "dialog_addkanjibyjlpt.h"
26 #include <glibmm/i18n.h>
27 #include <gtkmm/stock.h>
28 #include <gtkmm/messagedialog.h>
31 Glib::ustring jlptStrs
[] = {
39 DialogAddKanjiByJLPT::DialogAddKanjiByJLPT(Gtk::Window
& parent
)
40 : StoredDialog(_("Add Kanji By JLPT Level"), parent
, "gui.dlg.addkanjibyfreq.size"),
41 btnOK(Gtk::Stock::OK
),
42 btnCancel(Gtk::Stock::CANCEL
)
44 for(int i
=0; i
<jlptStrCount
; i
++) {
45 comboLowLevel
.append_text(jlptStrs
[i
]);
46 comboHighLevel
.append_text(jlptStrs
[i
]);
48 comboLowLevel
.set_active_text(jlptStrs
[0]);
49 comboHighLevel
.set_active_text(jlptStrs
[0]);
51 comboLowLevel
.signal_changed()
52 .connect(sigc::mem_fun(*this, &DialogAddKanjiByJLPT::OnLowValChange
));
53 comboHighLevel
.signal_changed()
54 .connect(sigc::mem_fun(*this, &DialogAddKanjiByJLPT::OnHighValChange
));
55 btnOK
.signal_clicked()
56 .connect(sigc::mem_fun(*this, &DialogAddKanjiByJLPT::OnOK
));
57 btnCancel
.signal_clicked()
58 .connect(sigc::mem_fun(*this, &DialogAddKanjiByJLPT::OnCancel
));
62 Gtk::VBox
* pvb
= get_vbox();
64 pvb
->pack_start(comboLowLevel
);
65 pvb
->pack_start(comboHighLevel
);
67 Gtk::ButtonBox
* phbb
= get_action_area();
68 phbb
->pack_start(btnCancel
);
69 phbb
->pack_start(btnOK
);
74 int ComboBoxToJLPT(const Gtk::ComboBoxText
& c
) {
76 Glib::ustring uStr
= c
.get_active_text();
77 for(i
=0;i
<jlptStrCount
;i
++)
78 if(uStr
==jlptStrs
[i
]) break;
79 if(i
<4) return 4-i
; /* 0-3 -> JLPT Level 4-1 */
80 assert(0 && "Error: i>=4, should be less than 4.");
81 return 0; /* No jlpt listed in KANJIDIC */
84 int DialogAddKanjiByJLPT::GetLowLevel() {
85 return ComboBoxToJLPT(comboLowLevel
);
88 int DialogAddKanjiByJLPT::GetHighLevel() {
89 return ComboBoxToJLPT(comboHighLevel
);
92 void DialogAddKanjiByJLPT::OnOK() {
96 void DialogAddKanjiByJLPT::OnCancel() {
100 void DialogAddKanjiByJLPT::OnLowValChange() {
103 high
= GetHighLevel();
104 /* Remember: with JLPT levels, a lower value is a higher level */
106 comboHighLevel
.set_active_text(comboLowLevel
.get_active_text());
109 void DialogAddKanjiByJLPT::OnHighValChange() {
112 high
= GetHighLevel();
113 /* See note in above function. */
115 comboLowLevel
.set_active_text(comboHighLevel
.get_active_text());
118 void DialogAddKanjiByJLPT::OKProc() {
119 int l
= GetLowLevel();
120 int h
= GetHighLevel();
122 Gtk::MessageDialog md
123 (*this, _("Please specify your level range from highest to lowest "
124 "level number. (Example: Level 4 to level 3)"));
125 md
.set_title(_("Bad JLPT level range"));
128 response(Gtk::RESPONSE_OK
);
131 void DialogAddKanjiByJLPT::CancelProc() {
132 response(Gtk::RESPONSE_CANCEL
);