Updated Spanish translation
[anjuta-git-plugin.git] / libanjuta / e-splash.c
blob0ef160a8169502ad21ba4a7d82e816ee3c58b628
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-splash.c
4 * Copyright (C) 2000, 2001 Ximian, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program 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 GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
21 * Author: Ettore Perazzoli
24 /**
25 * SECTION:e-splash
26 * @short_description: Splash screen
27 * @see_also:
28 * @stability: Unstable
29 * @include: libanjuta/e-splash.h
33 #ifdef HAVE_CONFIG_H
34 #include <config.h>
35 #endif
37 #include <libgnomecanvas/gnome-canvas-pixbuf.h>
38 #include <libgnomecanvas/libgnomecanvas.h>
39 #include <libgnome/gnome-macros.h>
40 #include <gtk/gtk.h>
42 #include "e-splash.h"
44 struct _ESplashPrivate {
45 GnomeCanvas *canvas;
46 GnomeCanvasItem *canvas_icon;
47 GnomeCanvasItem *canvas_text;
48 GnomeCanvasItem *canvas_line;
49 GnomeCanvasItem *canvas_line_back;
50 GdkPixbuf *splash_image_pixbuf;
51 gint progressbar_position;
54 GNOME_CLASS_BOILERPLATE (ESplash, e_splash, GtkWindow, GTK_TYPE_WINDOW);
56 /* Layout constants. These need to be changed if the splash changes. */
58 #define ICON_Y priv->progressbar_position
59 #define ICON_X 15
60 #define ICON_SIZE 48
61 #define PROGRESS_SIZE 5
63 /* GtkObject methods. */
65 static void
66 impl_destroy (GtkObject *object)
68 ESplash *splash;
69 ESplashPrivate *priv;
71 splash = E_SPLASH (object);
72 priv = splash->priv;
74 if (priv->splash_image_pixbuf != NULL)
75 gdk_pixbuf_unref (priv->splash_image_pixbuf);
76 g_free (priv);
79 static void
80 e_splash_class_init (ESplashClass *klass)
82 GtkObjectClass *object_class;
84 object_class = GTK_OBJECT_CLASS (klass);
85 object_class->destroy = impl_destroy;
87 parent_class = gtk_type_class (gtk_window_get_type ());
90 static void
91 e_splash_instance_init (ESplash *splash)
93 ESplashPrivate *priv;
95 priv = g_new (ESplashPrivate, 1);
96 priv->canvas = NULL;
97 priv->splash_image_pixbuf = NULL;
98 priv->progressbar_position = 100;
99 splash->priv = priv;
102 static gboolean
103 button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
105 ESplash *splash = (ESplash *) data;
107 gtk_widget_hide (GTK_WIDGET (splash));
109 return TRUE;
113 * e_splash_construct:
114 * @splash: A pointer to an ESplash widget
115 * @splash_image_pixbuf: The pixbuf for the image to appear in the splash dialog
117 * Construct @splash with @splash_image_pixbuf as the splash image.
119 void
120 e_splash_construct (ESplash *splash,
121 GdkPixbuf *splash_image_pixbuf,
122 gint progressbar_position)
124 ESplashPrivate *priv;
125 GtkWidget *canvas; /*, *frame; */
126 int image_width, image_height;
128 g_return_if_fail (splash != NULL);
129 g_return_if_fail (E_IS_SPLASH (splash));
130 g_return_if_fail (splash_image_pixbuf != NULL);
132 priv = splash->priv;
133 priv->progressbar_position = progressbar_position;
134 priv->splash_image_pixbuf = gdk_pixbuf_ref (splash_image_pixbuf);
136 canvas = gnome_canvas_new_aa ();
137 priv->canvas = GNOME_CANVAS (canvas);
139 image_width = gdk_pixbuf_get_width (splash_image_pixbuf);
140 image_height = gdk_pixbuf_get_height (splash_image_pixbuf);
142 gtk_widget_set_size_request (canvas, image_width, image_height);
143 gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0, 0, image_width, image_height);
144 gtk_widget_show (canvas);
146 gtk_container_add (GTK_CONTAINER (splash), canvas);
148 gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
149 GNOME_TYPE_CANVAS_PIXBUF,
150 "pixbuf", splash_image_pixbuf,
151 NULL);
152 priv->canvas_icon = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
153 GNOME_TYPE_CANVAS_PIXBUF,
154 "x", (double) (ICON_X),
155 "y", (double) (ICON_Y),
156 NULL);
157 priv->canvas_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
158 GNOME_TYPE_CANVAS_TEXT,
159 "fill_color", "black",
160 "size_points", (double)12,
161 "anchor", GTK_ANCHOR_SOUTH_WEST,
162 "x", (double)(ICON_X + ICON_SIZE + 10),
163 "y", (double)(ICON_Y + ICON_SIZE - PROGRESS_SIZE),
164 NULL);
165 priv->canvas_line = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
166 GNOME_TYPE_CANVAS_LINE,
167 "fill_color", "black",
168 "width_pixels", PROGRESS_SIZE,
169 NULL);
170 priv->canvas_line_back = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
171 GNOME_TYPE_CANVAS_LINE,
172 "fill_color", "blue",
173 "width_pixels", PROGRESS_SIZE,
174 NULL);
175 g_signal_connect (G_OBJECT (splash), "button-press-event",
176 G_CALLBACK (button_press_event), splash);
178 gtk_window_set_decorated(GTK_WINDOW(splash), FALSE);
179 gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
180 gtk_window_set_resizable (GTK_WINDOW (splash), FALSE);
181 gtk_window_set_default_size (GTK_WINDOW (splash), image_width, image_height);
182 gtk_window_set_title (GTK_WINDOW (splash), "Anjuta");
187 * e_splash_new:
188 * @image_file: Splash image file
190 * Create a new ESplash widget.
192 * Return value: A pointer to the newly created ESplash widget.
194 GtkWidget *
195 e_splash_new (const char *image_file, gint progressbar_position)
197 ESplash *splash;
198 GdkPixbuf *splash_image_pixbuf;
200 splash_image_pixbuf = gdk_pixbuf_new_from_file (image_file, NULL);
201 g_return_val_if_fail (splash_image_pixbuf != NULL, NULL);
203 splash = g_object_new (e_splash_get_type (), "type", GTK_WINDOW_TOPLEVEL, NULL);
204 e_splash_construct (splash, splash_image_pixbuf, progressbar_position);
206 /* gdk_pixbuf_unref (splash_image_pixbuf); */
208 return GTK_WIDGET (splash);
212 * e_splash_set:
213 * @splash: A pointer to an ESplash widget
214 * @icon_pixbuf: Pixbuf for the icon to be added
215 * @title: Title.
216 * @desc: Description.
217 * @progress_percentage: percentage of progress.
219 * Set the current progress/icon/text.
221 void
222 e_splash_set (ESplash *splash, GdkPixbuf *icon_pixbuf,
223 const gchar *title, const gchar *desc,
224 gfloat progress_percentage)
226 ESplashPrivate *priv;
227 GnomeCanvasPoints *points;
228 gint inc_width, progress_width;
230 g_return_if_fail (splash != NULL);
231 g_return_if_fail (E_IS_SPLASH (splash));
233 #ifdef GNOME2_CONVERSION_COMPLETE
234 if (GTK_OBJECT_DESTROYED (splash))
235 return;
236 #endif
238 priv = splash->priv;
240 if (icon_pixbuf)
242 GdkPixbuf *scaled_pixbuf;
244 scaled_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
245 8, ICON_SIZE, ICON_SIZE);
246 gdk_pixbuf_scale (icon_pixbuf, scaled_pixbuf,
247 0, 0,
248 ICON_SIZE, ICON_SIZE,
249 0, 0,
250 (double) ICON_SIZE / gdk_pixbuf_get_width (icon_pixbuf),
251 (double) ICON_SIZE / gdk_pixbuf_get_height (icon_pixbuf),
252 GDK_INTERP_HYPER);
253 g_object_set (G_OBJECT (priv->canvas_icon),
254 "pixbuf", scaled_pixbuf, NULL);
255 gdk_pixbuf_unref (scaled_pixbuf);
258 if (title)
260 g_object_set (G_OBJECT (priv->canvas_text),
261 "markup", title, NULL);
264 inc_width = gdk_pixbuf_get_width (priv->splash_image_pixbuf);
265 inc_width -= (ICON_X + ICON_SIZE + 20);
266 progress_width = inc_width;
268 points = gnome_canvas_points_new (2);
269 points->coords[0] = ICON_X + ICON_SIZE + 10;
270 points->coords[1] = ICON_Y + ICON_SIZE;
271 points->coords[2] = ICON_X + ICON_SIZE + 10 + (progress_percentage * inc_width);
272 points->coords[3] = ICON_Y + ICON_SIZE;
274 g_object_set (G_OBJECT (priv->canvas_line),
275 "points", points, NULL);
276 gnome_canvas_points_unref (points);
278 points = gnome_canvas_points_new (2);
279 points->coords[0] = ICON_X + ICON_SIZE + 10 + (progress_percentage * inc_width);
280 points->coords[1] = ICON_Y + ICON_SIZE;
281 points->coords[2] = ICON_X + ICON_SIZE + 10 + progress_width;
282 points->coords[3] = ICON_Y + ICON_SIZE;
284 g_object_set (G_OBJECT (priv->canvas_line_back),
285 "points", points, NULL);
286 gnome_canvas_points_unref (points);