1194e802c4efa7f0ebb4121b05365b6bdf5c49f6
[mdictionary] / gui / src / ws_gui.c
1 /********************************************************************************
2 Copyright 2006, ComArch S.A
3 All rights reserved
4
5 Terms of use
6
7
8 READ THE TERMS OF USE CAREFULLY BEFORE INSTALALTION OF THIS SOFTWARE. BY
9 INSTALALTION OF THIS SOFTWARE, YOU AGREE TO THE FOLLOWING TERMS OF USE.
10
11 1. LICENSE TO USE. ComArch grants you a non-exclusive and non-transferable
12 license for the internal use only of the accompanying software and
13 documentation and any error corrections provided by ComArch (collectively
14 "Software"), by the one user.
15
16 2. RESTRICTIONS. Software is confidential and copyrighted. Title to Software
17 and all associated intellectual property rights is retained by ComArch
18 and/or its licensors. Unless enforcement is prohibited by applicable law,
19 you may not modify, decompile, or reverse engineer Software. You acknowledge
20 that Software is not designed, licensed or intended for use in the design,
21 construction, operation or maintenance of any nuclear facility. Sun ComArch
22 disclaims any express or implied warranty of fitness for such uses. No
23 right, title or interest in or to any trademark, service mark, logo or trade
24 name of ComArch or its licensors is granted under this terms of use.
25
26
27 3. DISCLAIMER OF WARRANTY. UNLESS SPECIFIED IN THIS AGREEMENT TERMS OF USE,
28 ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
29 ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
30 NON-INFRINGEMENT ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT THESE DISCLAIMERS
31 ARE HELD TO BE LEGALLY INVALID.
32
33 4. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT
34 WILL COMARCH OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR
35 DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
36 DAMAGES, HOWEVER CAUSED REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT
37 OF OR RELATED TO THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF COMARCH
38 HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event will
39 ComArch's liability to you, whether in contract, tort (including
40 negligence), or otherwise, exceed []. The foregoing limitations will apply
41 even if the above stated warranty fails of its essential purpose.
42
43 5. Termination. This license is effective until terminated. You may
44 terminate this license at any time by destroying all copies of Software.
45 This license will terminate immediately without notice from ComArch if you
46 fail to comply with any provision of this license. Upon Termination, you
47 must destroy all copies of Software.
48
49 6. Export Regulations. All Software and technical data delivered under this
50 terms of use are subject to Polish export control laws and may be subject to
51 export or import regulations in other countries. You agree to comply
52 strictly with all such laws and regulations and acknowledge that you have
53 the responsibility to obtain such licenses to export, re-export, or import
54 as may be required after delivery to you.
55
56 7. Governing Law. Any action related to this license will be governed by
57 Polish Law.
58
59 8. Severability. If any provision of this terms of use is held to be
60 unenforceable, this terms of use will remain in effect with the provision
61 omitted, unless omission would frustrate the intent of the parties, in which
62 case this terms of use will immediately terminate.
63
64 9. Integration. This document is the entire  agreement between you and
65 ComArch relating to its subject matter. It supersedes all prior or
66 contemporaneous oral or written communications, proposals, representations
67 and warranties and prevails over any conflicting or additional terms of any
68 quote, order, acknowledgment, or other communication between the parties
69 relating to its subject matter during the term of these terms of use. No
70 modification of this Agreement will be binding, unless in writing and signed
71 by an authorized representative of each party.
72
73 *********************************************************************************/
74
75 #include "../../include/ws_gui.h"
76 #include "../../include/ws_gui_callbacks.h"
77 #include "../../include/ws_gui_layout.h"
78 /*#include "../dbus/ws_dbus.h"*/
79
80 //int ws_gui_init(int argc, char *argv[])
81 int main(int argc, char *argv[])
82 {       
83         gtk_init(&argc, &argv);
84         
85         gconf_init(argc, argv, NULL);
86         
87         WSGuiApp *ws_gui_app;
88         ws_gui_app = (WSGuiApp*)g_malloc(sizeof(WSGuiApp));     
89
90
91         ws_gui_app->ws_gui_w_list = (struct WSGuiList*)g_malloc(sizeof(struct WSGuiList));
92         ws_gui_app->ws_gui_menu = (struct WSGuiMenu*)g_malloc(sizeof(struct WSGuiMenu));
93         
94         ws_gui_app->selection_data= g_malloc(sizeof(GtkSelectionData));
95
96         ws_gui_create_window(ws_gui_app);
97         ws_gui_read_adjustment(ws_gui_app);
98         
99         /*gonf*/
100         ws_gui_app->client = gconf_client_get_default();
101         //g_printf(".::GUI::. client: %p", ws_gui_app->client);
102         /*gconf_client_add_dir (ws_gui_app->client, "/Apps/Dictionaries/Niemiecki", GCONF_CLIENT_PRELOAD_NONE, NULL);
103         if (gconf_client_set_bool (ws_gui_app->client, "/Apps/Dictionaries/Niemiecki/active", TRUE, NULL))
104         {
105                 g_printf ("\n\n.::GUI::. ustawiono wartosc\n\n");
106         }*/
107         
108
109         /*dbus*/        
110         ws_gui_app->dbus_data = ws_dbus_create ("WhiteStorkGui", "v1.0");
111
112         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_SERVICE, "org.maemo.WhiteStorkGui");
113         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_OBJECT, "/org/maemo/WhiteStorkGui");
114         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_IFACE, "org.maemo.WhiteStorkGui");
115         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_REMOTE_SERVICE, "org.maemo.WhiteStorkManager");
116         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_REMOTE_OBJECT, "/org/maemo/WhiteStorkManager");
117         ws_dbus_config (ws_gui_app->dbus_data, WS_DBUS_CONFIG_REMOTE_IFACE, "org.maemo.WhiteStorkManager");
118         
119         ws_dbus_connect (ws_gui_app->dbus_data);
120         
121
122         ws_dbus_set_cb (ws_gui_app->dbus_data, "return_words", ws_gui_dbus_return_words, ws_gui_app);
123
124         ws_dbus_set_cb (ws_gui_app->dbus_data, "return_translations", ws_gui_dbus_return_translation, ws_gui_app);
125         ws_dbus_set_cb (ws_gui_app->dbus_data, "update_progressbar", ws_dbus_progress_bar, ws_gui_app);
126         ws_dbus_set_cb (ws_gui_app->dbus_data, "signal", ws_gui_signal_hander, ws_gui_app);
127         
128         
129         
130         ws_gui_app->ws_gui_clipboard = gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html), GDK_SELECTION_CLIPBOARD);
131         
132         g_signal_connect (G_OBJECT (ws_gui_app->ws_gui_w_list->ws_gui_selection), "changed", G_CALLBACK (ws_gui_tree_selection_changed), ws_gui_app);
133         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window), "key-press-event", G_CALLBACK(hildon_key_press_listener), ws_gui_app);
134
135         //g_signal_handler_block(G_OBJECT(ws_gui_app->ws_gui_html), GDK_BUTTON_PRESS);
136         //g_signal_stop_emission_by_name(G_OBJECT(ws_gui_app->ws_gui_html), "button-press-event");
137
138         //g_signal_handlers_block_by_func(G_OBJECT(ws_gui_app->ws_gui_html), G_CALLBACK(button), ws_gui_app);
139         
140         
141
142
143         ws_gui_app->ws_gui_clipboard_primary = gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html), GDK_SELECTION_PRIMARY);
144         ws_gui_app->ws_gui_clipboard = gtk_widget_get_clipboard (GTK_WIDGET(ws_gui_app->ws_gui_html), GDK_SELECTION_CLIPBOARD);
145
146         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html), "tap-and-hold", G_CALLBACK(button), ws_gui_app);
147         //g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_html), "button-press-event", G_CALLBACK(button), ws_gui_app);
148
149         //g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_scrolledwindow_right), "selection-notify-event", G_CALLBACK(selection_received), ws_gui_app);
150         
151         ws_gui_app->ws_gui_menu->ws_gui_popup_menu = ws_gui_create_popup_menu(ws_gui_app);      
152
153         gtk_widget_tap_and_hold_setup(GTK_WIDGET(ws_gui_app->ws_gui_html), GTK_WIDGET(ws_gui_app->ws_gui_menu->ws_gui_popup_menu), NULL, GTK_TAP_AND_HOLD_PASS_PRESS);
154         
155         g_signal_connect(G_OBJECT(ws_gui_app->ws_gui_hildon_window), "delete-event", G_CALLBACK(ws_gui_on_exit), ws_gui_app);
156
157         
158         gchar *path = g_strconcat(GCONF_CONF, "/licence", NULL);
159         if (gconf_client_get_bool(ws_gui_app->client, path, NULL) == FALSE)
160         {
161                 ws_gui_app->licence_dialog = licence_dialog(ws_gui_app);
162                 if (gtk_dialog_run(ws_gui_app->licence_dialog) == GTK_RESPONSE_OK)
163                         {
164                                 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "License OK");
165                                 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->licence_dialog));
166                                 gconf_client_set_bool (ws_gui_app->client, path, TRUE, NULL);
167                                 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_ERROR_UNKNOWN);
168                                 gtk_main();
169                         }
170                 else
171                 {
172                                 g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "License CLOSE");
173                                 gtk_widget_destroy(GTK_WIDGET(ws_gui_app->licence_dialog));
174                                 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_INFO_TERMINATE);
175                                 ws_dbus_destroy (ws_gui_app->dbus_data);
176                                 ws_gui_free_memory(ws_gui_app);
177                                 exit(0);
178                                 //gtk_main_quit();
179                 }
180         }
181         else
182         {
183                 ws_dbus_notify(ws_gui_app->dbus_data, WS_DBUS_ERROR_UNKNOWN);
184                 gtk_main();
185         }
186         
187         return 0;
188 }
189