2 * MStarDict - International dictionary for Maemo.
3 * Copyright (C) 2010 Roman Moravcik
5 * base on code of stardict:
6 * Copyright (C) 2003-2007 Hu Zheng <huzheng_001@163.com>
8 * based on code of sdcv:
9 * Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include <glib/gi18n.h>
39 #include <hildon/hildon.h>
41 #include "libwrapper.hpp"
42 #include "mstardict.hpp"
44 #include "transwin.hpp"
46 TransWin::TransWin(MStarDict *mStarDict)
48 oStarDict = mStarDict;
60 TransWin::onSayMenuItemClicked(GtkButton *button,
63 mTransWin->oStarDict->oTts->SayText(mTransWin->sExpression);
68 TransWin::CreateTransWidget(SearchResult *result)
70 GtkWidget *vbox, *hbox, *label;
71 char *bookname = NULL, *def = NULL, *exp = NULL;
73 bookname = g_markup_printf_escaped("<span color=\"dimgray\" size=\"x-small\">%s</span>",
75 exp = g_markup_printf_escaped("<span color=\"darkred\" weight=\"heavy\" size=\"large\">%s</span>",
77 def = g_strdup(result->def);
79 vbox = gtk_vbox_new(FALSE, 0);
81 hbox = gtk_hbox_new(FALSE, 0);
82 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
84 label = gtk_label_new("Expression");
85 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
86 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
88 gtk_label_set_markup(GTK_LABEL(label), exp);
92 label = gtk_label_new("Bookname");
93 gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
94 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
96 gtk_label_set_markup(GTK_LABEL(label), bookname);
100 label = gtk_label_new("Definition");
101 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
102 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
103 gtk_widget_set_size_request(label, 750, -1);
104 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
106 gtk_label_set_markup(GTK_LABEL(label), def);
110 if (sExpression == NULL)
111 sExpression = g_strdup(result->exp);
117 TransWin::CreateTransWindow(GList *results)
119 GtkWidget *alignment, *pannable, *vbox, *trans, *separator;
120 GList *result = NULL;
122 window = hildon_stackable_window_new();
123 gtk_window_set_title(GTK_WINDOW(window), _("Translation"));
125 alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
126 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
127 HILDON_MARGIN_DEFAULT,
128 HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DEFAULT);
129 gtk_container_add(GTK_CONTAINER(window), alignment);
131 pannable = hildon_pannable_area_new();
132 gtk_container_add(GTK_CONTAINER(alignment), pannable);
134 vbox = gtk_vbox_new(FALSE, 16);
135 hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable), vbox);
141 for (result = results; result != NULL; result = result->next) {
142 trans = CreateTransWidget((SearchResult *) result->data);
143 gtk_box_pack_start(GTK_BOX(vbox), trans, FALSE, FALSE, 0);
145 separator = gtk_hseparator_new();
146 gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
149 /* create translation menu */
152 gtk_widget_show_all(window);
156 TransWin::CreateTransMenu()
161 menu = HILDON_APP_MENU(hildon_app_menu_new());
162 hildon_window_set_app_menu(HILDON_WINDOW(window), menu);
165 if (oStarDict->oTts->IsEnabled()) {
166 item = hildon_gtk_button_new(HILDON_SIZE_AUTO);
167 gtk_button_set_label(GTK_BUTTON(item), _("Say"));
168 hildon_app_menu_append(menu, GTK_BUTTON(item));
169 g_signal_connect(item, "clicked", G_CALLBACK(onSayMenuItemClicked), this);
173 gtk_widget_show_all(GTK_WIDGET(menu));