1 /*
2 * Copyright 2011 kubtek <kubtek@mail.com>
3 *
4 * This file is part of StarDict.
5 *
6 * StarDict is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * StarDict is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with StarDict. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include <glib/gi18n.h>
25 #include <gtk/gtk.h>
26
27 #include "conf.h"
28 #include "lib/utils.h"
29 #include "libcommon.h"
30
31 #include "splash.h"
32
33 splash_screen stardict_splash;
34
35 // this is the callback which will destroy the splash screen window.
on_mainwin_finish()36 void splash_screen::on_mainwin_finish()
37 {
38 gtk_widget_destroy(window);
39 }
40
splash_screen()41 splash_screen::splash_screen()
42 :
43 window(NULL),
44 text(NULL),
45 progress(NULL)
46 {
47 }
48
display_action(const std::string & actname)49 void splash_screen::display_action(const std::string& actname)
50 {
51 if ( NULL == text )
52 return;
53 gtk_label_set_text(text, actname.c_str());
54 gtk_progress_bar_pulse(progress);
55 while(gtk_events_pending())
56 gtk_main_iteration();
57 }
58
show()59 void splash_screen::show()
60 {
61 gtk_window_set_auto_startup_notification(FALSE);
62
63 //This function never failed
64 GtkWidget *image =
65 gtk_image_new_from_file(build_path(conf_dirs->get_data_dir(),
66 "pixmaps" G_DIR_SEPARATOR_S "splash.png").c_str());
67
68 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
69
70 #if GTK_MAJOR_VERSION >= 3
71 GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
72 #else
73 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
74 #endif
75 gtk_box_pack_start(GTK_BOX(vbox),image,false,false,0);
76 text = GTK_LABEL(gtk_label_new(_("Loading")));
77 int w = gdk_pixbuf_get_width(gtk_image_get_pixbuf(GTK_IMAGE(image)));
78 gtk_widget_set_size_request(GTK_WIDGET(text), w, -1);
79 gtk_label_set_line_wrap(text, TRUE);
80 gtk_label_set_justify(text, GTK_JUSTIFY_CENTER);
81 gtk_box_pack_start(GTK_BOX(vbox),GTK_WIDGET(text),false,false,0);
82 progress = GTK_PROGRESS_BAR(gtk_progress_bar_new());
83 gtk_widget_set_size_request(GTK_WIDGET(progress), w, 12);
84 gtk_box_pack_start(GTK_BOX(vbox),GTK_WIDGET(progress),false,false,0);
85
86 gtk_widget_show_all(vbox);
87 gtk_container_add(GTK_CONTAINER(window), vbox);
88
89 //gtk_widget_set_app_paintable(window, TRUE);
90 gtk_window_set_title (GTK_WINDOW (window), _("StarDict starting..."));
91 gtk_window_set_position(GTK_WINDOW (window), GTK_WIN_POS_CENTER);
92 //gtk_widget_set_size_request(window, w, h);
93 gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
94 gtk_window_set_type_hint (GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
95 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
96 gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON1_MOTION_MASK);
97 g_signal_connect (G_OBJECT (window), "button_press_event", G_CALLBACK (vButtonPressCallback), this);
98 g_signal_connect (G_OBJECT (window), "motion_notify_event", G_CALLBACK (vMotionNotifyCallback), this);
99 gtk_widget_show(window);
100 // go into main loop, processing events.
101 while(gtk_events_pending())
102 gtk_main_iteration();
103
104 gtk_window_set_auto_startup_notification(TRUE);
105 }
106
vButtonPressCallback(GtkWidget * widget,GdkEventButton * event,splash_screen * oWin)107 gboolean splash_screen::vButtonPressCallback (GtkWidget * widget, GdkEventButton * event , splash_screen *oWin)
108 {
109 if (event->type == GDK_BUTTON_PRESS && event->button == 1
110 /* check that this event is not redirected due to a grab enforced by a modal window */
111 && widget == gtk_get_event_widget((GdkEvent*)event)) {
112 gtk_window_get_position(GTK_WINDOW(widget),&(oWin->press_window_x),&(oWin->press_window_y));
113 oWin->press_x_root = (gint)(event->x_root);
114 oWin->press_y_root = (gint)(event->y_root);
115 }
116 return TRUE;
117 }
118
vMotionNotifyCallback(GtkWidget * widget,GdkEventMotion * event,splash_screen * oWin)119 gboolean splash_screen::vMotionNotifyCallback (GtkWidget * widget, GdkEventMotion * event , splash_screen *oWin)
120 {
121 if (event->state & GDK_BUTTON1_MASK
122 /* check that this event is not redirected due to a grab enforced by a modal window */
123 && widget == gtk_get_event_widget((GdkEvent*)event)) {
124 gint x,y;
125 x = oWin->press_window_x + (gint)(event->x_root) - oWin->press_x_root;
126 y = oWin->press_window_y + (gint)(event->y_root) - oWin->press_y_root;
127 if (x<0)
128 x = 0;
129 if (y<0)
130 y = 0;
131 gtk_window_move(GTK_WINDOW(oWin->window), x, y);
132 }
133
134 return TRUE;
135 }
136