Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / libanjuta / e-splash.c
blob04f1b5e38c591665ac266f0d9a370fd16560fd92
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 <gtk/gtk.h>
41 #include "e-splash.h"
43 struct _ESplashPrivate {
44 GnomeCanvas *canvas;
45 GnomeCanvasItem *canvas_icon;
46 GnomeCanvasItem *canvas_text;
47 GnomeCanvasItem *canvas_line;
48 GnomeCanvasItem *canvas_line_back;
49 GdkPixbuf *splash_image_pixbuf;
50 gint progressbar_position;
53 G_DEFINE_TYPE(ESplash, e_splash, GTK_TYPE_WINDOW)
55 /* Layout constants. These need to be changed if the splash changes. */
57 #define ICON_Y priv->progressbar_position
58 #define ICON_X 15
59 #define ICON_SIZE 48
60 #define PROGRESS_SIZE 5
62 /* GtkObject methods. */
64 static void
65 impl_destroy (GtkObject *object)
67 ESplash *splash;
68 ESplashPrivate *priv;
70 splash = E_SPLASH (object);
71 priv = splash->priv;
73 if (priv->splash_image_pixbuf != NULL)
74 gdk_pixbuf_unref (priv->splash_image_pixbuf);
75 g_free (priv);
78 static void
79 e_splash_finalize (GObject *obj)
81 G_OBJECT_CLASS (e_splash_parent_class)->finalize (obj);
84 static void
85 e_splash_class_init (ESplashClass *klass)
87 GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);;
88 GObjectClass *object_class = G_OBJECT_CLASS (klass);
90 gtkobject_class->destroy = impl_destroy;
92 object_class->finalize = e_splash_finalize;
95 static void
96 e_splash_init (ESplash *splash)
98 ESplashPrivate *priv;
100 priv = g_new (ESplashPrivate, 1);
101 priv->canvas = NULL;
102 priv->splash_image_pixbuf = NULL;
103 priv->progressbar_position = 100;
104 splash->priv = priv;
107 static gboolean
108 button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
110 ESplash *splash = (ESplash *) data;
112 gtk_widget_hide (GTK_WIDGET (splash));
114 return TRUE;
118 * e_splash_construct:
119 * @splash: A pointer to an ESplash widget
120 * @splash_image_pixbuf: The pixbuf for the image to appear in the splash dialog
122 * Construct @splash with @splash_image_pixbuf as the splash image.
124 void
125 e_splash_construct (ESplash *splash,
126 GdkPixbuf *splash_image_pixbuf,
127 gint progressbar_position)
129 ESplashPrivate *priv;
130 GtkWidget *canvas; /*, *frame; */
131 int image_width, image_height;
133 g_return_if_fail (splash != NULL);
134 g_return_if_fail (E_IS_SPLASH (splash));
135 g_return_if_fail (splash_image_pixbuf != NULL);
137 priv = splash->priv;
138 priv->progressbar_position = progressbar_position;
139 priv->splash_image_pixbuf = gdk_pixbuf_ref (splash_image_pixbuf);
141 canvas = gnome_canvas_new_aa ();
142 priv->canvas = GNOME_CANVAS (canvas);
144 image_width = gdk_pixbuf_get_width (splash_image_pixbuf);
145 image_height = gdk_pixbuf_get_height (splash_image_pixbuf);
147 gtk_widget_set_size_request (canvas, image_width, image_height);
148 gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0, 0, image_width, image_height);
149 gtk_widget_show (canvas);
151 gtk_container_add (GTK_CONTAINER (splash), canvas);
153 gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
154 GNOME_TYPE_CANVAS_PIXBUF,
155 "pixbuf", splash_image_pixbuf,
156 NULL);
157 priv->canvas_icon = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
158 GNOME_TYPE_CANVAS_PIXBUF,
159 "x", (double) (ICON_X),
160 "y", (double) (ICON_Y),
161 NULL);
162 priv->canvas_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
163 GNOME_TYPE_CANVAS_TEXT,
164 "fill_color", "black",
165 "size_points", (double)12,
166 "anchor", GTK_ANCHOR_SOUTH_WEST,
167 "x", (double)(ICON_X + ICON_SIZE + 10),
168 "y", (double)(ICON_Y + ICON_SIZE - PROGRESS_SIZE),
169 NULL);
170 priv->canvas_line = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
171 GNOME_TYPE_CANVAS_LINE,
172 "fill_color", "black",
173 "width_pixels", PROGRESS_SIZE,
174 NULL);
175 priv->canvas_line_back = gnome_canvas_item_new (GNOME_CANVAS_GROUP (priv->canvas->root),
176 GNOME_TYPE_CANVAS_LINE,
177 "fill_color", "blue",
178 "width_pixels", PROGRESS_SIZE,
179 NULL);
180 g_signal_connect (G_OBJECT (splash), "button-press-event",
181 G_CALLBACK (button_press_event), splash);
183 gtk_window_set_decorated(GTK_WINDOW(splash), FALSE);
184 gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
185 gtk_window_set_resizable (GTK_WINDOW (splash), FALSE);
186 gtk_window_set_default_size (GTK_WINDOW (splash), image_width, image_height);
187 gtk_window_set_title (GTK_WINDOW (splash), "Anjuta");
192 * e_splash_new:
193 * @image_file: Splash image file
195 * Create a new ESplash widget.
197 * Return value: A pointer to the newly created ESplash widget.
199 GtkWidget *
200 e_splash_new (const char *image_file, gint progressbar_position)
202 ESplash *splash;
203 GdkPixbuf *splash_image_pixbuf;
205 splash_image_pixbuf = gdk_pixbuf_new_from_file (image_file, NULL);
206 g_return_val_if_fail (splash_image_pixbuf != NULL, NULL);
208 splash = g_object_new (e_splash_get_type (), "type", GTK_WINDOW_TOPLEVEL, NULL);
209 e_splash_construct (splash, splash_image_pixbuf, progressbar_position);
211 /* gdk_pixbuf_unref (splash_image_pixbuf); */
213 return GTK_WIDGET (splash);
217 * e_splash_set:
218 * @splash: A pointer to an ESplash widget
219 * @icon_pixbuf: Pixbuf for the icon to be added
220 * @title: Title.
221 * @desc: Description.
222 * @progress_percentage: percentage of progress.
224 * Set the current progress/icon/text.
226 void
227 e_splash_set (ESplash *splash, GdkPixbuf *icon_pixbuf,
228 const gchar *title, const gchar *desc,
229 gfloat progress_percentage)
231 ESplashPrivate *priv;
232 GnomeCanvasPoints *points;
233 gint inc_width, progress_width;
235 g_return_if_fail (splash != NULL);
236 g_return_if_fail (E_IS_SPLASH (splash));
238 #ifdef GNOME2_CONVERSION_COMPLETE
239 if (GTK_OBJECT_DESTROYED (splash))
240 return;
241 #endif
243 priv = splash->priv;
245 if (icon_pixbuf)
247 GdkPixbuf *scaled_pixbuf;
249 scaled_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,
250 8, ICON_SIZE, ICON_SIZE);
251 gdk_pixbuf_scale (icon_pixbuf, scaled_pixbuf,
252 0, 0,
253 ICON_SIZE, ICON_SIZE,
254 0, 0,
255 (double) ICON_SIZE / gdk_pixbuf_get_width (icon_pixbuf),
256 (double) ICON_SIZE / gdk_pixbuf_get_height (icon_pixbuf),
257 GDK_INTERP_HYPER);
258 g_object_set (G_OBJECT (priv->canvas_icon),
259 "pixbuf", scaled_pixbuf, NULL);
260 gdk_pixbuf_unref (scaled_pixbuf);
263 if (title)
265 g_object_set (G_OBJECT (priv->canvas_text),
266 "markup", title, NULL);
269 inc_width = gdk_pixbuf_get_width (priv->splash_image_pixbuf);
270 inc_width -= (ICON_X + ICON_SIZE + 20);
271 progress_width = inc_width;
273 points = gnome_canvas_points_new (2);
274 points->coords[0] = ICON_X + ICON_SIZE + 10;
275 points->coords[1] = ICON_Y + ICON_SIZE;
276 points->coords[2] = ICON_X + ICON_SIZE + 10 + (progress_percentage * inc_width);
277 points->coords[3] = ICON_Y + ICON_SIZE;
279 g_object_set (G_OBJECT (priv->canvas_line),
280 "points", points, NULL);
281 gnome_canvas_points_unref (points);
283 points = gnome_canvas_points_new (2);
284 points->coords[0] = ICON_X + ICON_SIZE + 10 + (progress_percentage * inc_width);
285 points->coords[1] = ICON_Y + ICON_SIZE;
286 points->coords[2] = ICON_X + ICON_SIZE + 10 + progress_width;
287 points->coords[3] = ICON_Y + ICON_SIZE;
289 g_object_set (G_OBJECT (priv->canvas_line_back),
290 "points", points, NULL);
291 gnome_canvas_points_unref (points);