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_addkanjibygrade.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_addkanjibygrade.h"
26 #include <glibmm/i18n.h>
27 #include <gtkmm/stock.h>
28 #include <gtkmm/messagedialog.h>
30 Glib::ustring strs
[] = {
31 _("Jouyou Kanji Grade 1"),
32 _("Jouyou Kanji Grade 2"),
33 _("Jouyou Kanji Grade 3"),
34 _("Jouyou Kanji Grade 4"),
35 _("Jouyou Kanji Grade 5"),
36 _("Jouyou Kanji Grade 6"),
37 _("Jouyou Kanji, General Usage"),
38 _("Jinmeiyou Kanji (for names)"),
39 _("Non-Jouyou/Non-Jinmeiyou Kanji")
43 DialogAddKanjiByGrade::DialogAddKanjiByGrade(Gtk::Window
& parent
)
44 : StoredDialog(_("Add Kanji By Jouyou Grade"), parent
, "gui.dlg.addkanjibyfreq.size"),
45 btnOK(Gtk::Stock::OK
),
46 btnCancel(Gtk::Stock::CANCEL
)
48 for(int i
=0; i
<9; i
++) {
49 comboLowGrade
.append_text(strs
[i
]);
50 comboHighGrade
.append_text(strs
[i
]);
52 comboLowGrade
.set_active_text(strs
[0]);
53 comboHighGrade
.set_active_text(strs
[0]);
55 comboLowGrade
.signal_changed()
56 .connect(sigc::mem_fun(*this, &DialogAddKanjiByGrade::OnLowValChange
));
57 comboHighGrade
.signal_changed()
58 .connect(sigc::mem_fun(*this, &DialogAddKanjiByGrade::OnHighValChange
));
59 btnOK
.signal_clicked()
60 .connect(sigc::mem_fun(*this, &DialogAddKanjiByGrade::OnOK
));
61 btnCancel
.signal_clicked()
62 .connect(sigc::mem_fun(*this, &DialogAddKanjiByGrade::OnCancel
));
66 Gtk::VBox
* pvb
= get_vbox();
68 pvb
->pack_start(comboLowGrade
);
69 pvb
->pack_start(comboHighGrade
);
71 Gtk::ButtonBox
* phbb
= get_action_area();
72 phbb
->pack_start(btnCancel
);
73 phbb
->pack_start(btnOK
);
78 int ComboBoxToKanjidicGrade(const Gtk::ComboBoxText
& c
) {
80 Glib::ustring uStr
= c
.get_active_text();
81 for(i
=0;i
<strCount
;i
++)
82 if(uStr
==strs
[i
]) break;
83 if(i
<6) return i
+1; /* G1-G6 in KANJIDIC */
84 if(i
==6) return 8; /* G8 (Jouyou Jr. High) in KANJIDIC */
85 if(i
==7) return 9; /* G9 (Jinmeiyou) in KANJIDIC */
86 return 0; /* No grade listed in KANJIDIC */
89 int DialogAddKanjiByGrade::GetLowGrade() {
90 return ComboBoxToKanjidicGrade(comboLowGrade
);
93 int DialogAddKanjiByGrade::GetHighGrade() {
94 return ComboBoxToKanjidicGrade(comboHighGrade
);
97 void DialogAddKanjiByGrade::OnOK() {
101 void DialogAddKanjiByGrade::OnCancel() {
105 void DialogAddKanjiByGrade::OnLowValChange() {
108 high
= GetHighGrade();
109 /* 0 is a special code for non-graded kanji and is treated
110 as the highest grade level here. */
111 if(high
!=0 && (low
>high
|| low
==0))
112 comboHighGrade
.set_active_text(comboLowGrade
.get_active_text());
115 void DialogAddKanjiByGrade::OnHighValChange() {
118 high
= GetHighGrade();
119 /* 0 is a special code for non-graded kanji and is treated
120 as the highest grade level here. */
121 if(high
!=0 && (high
<low
|| low
==0))
122 comboLowGrade
.set_active_text(comboHighGrade
.get_active_text());
125 void DialogAddKanjiByGrade::OKProc() {
126 int l
= GetLowGrade();
127 int h
= GetHighGrade();
128 /* 0 is a special code for non-graded kanji and is treated
129 as the highest grade level here. */
130 if((h
<l
&& h
!=0) || (l
==0 && h
!=0)) {
131 Gtk::MessageDialog md
132 (*this, _("Your high grade level cannot be less than your low "
134 md
.set_title(_("Bad jouyou grade range"));
137 response(Gtk::RESPONSE_OK
);
140 void DialogAddKanjiByGrade::CancelProc() {
141 response(Gtk::RESPONSE_CANCEL
);