Imported version 0.4-2
[mstardict] / src / transwin.cpp
1 /*
2  *  MStarDict - International dictionary for Maemo.
3  *  Copyright (C) 2010 Roman Moravcik
4  *
5  *  base on code of stardict:
6  *  Copyright (C) 2003-2007 Hu Zheng <huzheng_001@163.com>
7  *
8  *  based on code of sdcv:
9  *  Copyright (C) 2005-2006 Evgeniy <dushistov@mail.ru>
10  *
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.
15  *
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.
20  *
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
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #  include "config.h"
28 #endif
29
30 #include <string>
31 #include <vector>
32 #include <memory>
33 #include <list>
34
35 #include <glib.h>
36 #include <glib/gi18n.h>
37
38 #include <gtk/gtk.h>
39 #include <hildon/hildon.h>
40
41 #include "libwrapper.hpp"
42 #include "mstardict.hpp"
43 #include "transwin.hpp"
44
45 TransWin::TransWin(MStarDict *mStarDict)
46 {
47     oStarDict = mStarDict;
48     window = NULL;
49 }
50
51 TransWin::~TransWin()
52 {
53 }
54
55 GtkWidget *
56 TransWin::CreateTransWidget(SearchResult *result)
57 {
58     GtkWidget *vbox, *hbox, *label;
59     char *bookname = NULL, *def = NULL, *exp = NULL;
60
61     bookname = g_markup_printf_escaped("<span color=\"dimgray\" size=\"x-small\">%s</span>",
62                                        result->bookname);
63     def = g_markup_printf_escaped("<span color=\"darkred\" weight=\"heavy\" size=\"large\">%s</span>",
64                                   result->def);
65     exp = g_strdup(result->exp);
66
67     vbox = gtk_vbox_new(FALSE, 0);
68
69     hbox = gtk_hbox_new(FALSE, 0);
70     gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
71
72     label = gtk_label_new("Definition");
73     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
74     gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
75     if (def) {
76         gtk_label_set_markup(GTK_LABEL(label), def);
77         g_free(def);
78     }
79
80     label = gtk_label_new("Bookname");
81     gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
82     gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 0);
83     if (bookname) {
84         gtk_label_set_markup(GTK_LABEL(label), bookname);
85         g_free(bookname);
86     }
87
88     label = gtk_label_new("Expresion");
89     gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
90     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
91     gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
92     if (exp) {
93         gtk_label_set_markup(GTK_LABEL(label), exp);
94         g_free(exp);
95     }
96
97     return vbox;
98 }
99
100 void
101 TransWin::CreateTransWindow(GList *results)
102 {
103     GtkWidget *window, *alignment, *pannable, *vbox, *trans, *separator;
104     GList *result = NULL;
105
106     window = hildon_stackable_window_new();
107     gtk_window_set_title(GTK_WINDOW(window), _("Translation"));
108
109     alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
110     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment),
111                               HILDON_MARGIN_DEFAULT,
112                               HILDON_MARGIN_DEFAULT, HILDON_MARGIN_DOUBLE, HILDON_MARGIN_DEFAULT);
113     gtk_container_add(GTK_CONTAINER(window), alignment);
114
115     pannable = hildon_pannable_area_new();
116     gtk_container_add(GTK_CONTAINER(alignment), pannable);
117
118     vbox = gtk_vbox_new(FALSE, 16);
119     hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannable), vbox);
120
121     for (result = results; result != NULL; result = result->next) {
122         trans = CreateTransWidget((SearchResult *) result->data);
123         gtk_box_pack_start(GTK_BOX(vbox), trans, FALSE, FALSE, 0);
124
125         separator = gtk_hseparator_new();
126         gtk_box_pack_start(GTK_BOX(vbox), separator, FALSE, FALSE, 0);
127     }
128
129     gtk_widget_show_all(window);
130 }