more leaks plugged and more *_OPTIONAL
[dia.git] / app / splash.c
blob0253e1099838918cb3b789d3bf42188bfb2ad94a
1 #include <config.h>
3 #include <gtk/gtk.h>
4 #include <gdk-pixbuf/gdk-pixbuf.h>
6 #include "intl.h"
7 #include "dia_dirs.h"
8 #include "app_procs.h"
10 extern GdkPixbuf *logo;
12 static GtkWidget*
13 get_logo_pixmap (void)
15 GtkWidget* gpixmap = NULL;
16 gchar str[512];
18 if (!logo) {
19 gchar* datadir = dia_get_data_directory("");
20 g_snprintf(str, sizeof(str), "%s/dia_logo.png", datadir);
21 logo = gdk_pixbuf_new_from_file(str, NULL);
22 g_free(datadir);
25 if (logo) {
26 GdkPixmap *pixmap;
27 GdkBitmap *bitmap;
29 gdk_pixbuf_render_pixmap_and_mask(logo, &pixmap, &bitmap, 128);
30 gpixmap = gtk_pixmap_new(pixmap, bitmap);
31 gdk_pixmap_unref(pixmap);
32 if (bitmap) gdk_bitmap_unref(bitmap);
34 return gpixmap;
37 static GtkWidget* splash = NULL;
39 static void
40 splash_expose (GtkWidget *widget, GdkEventExpose *event)
42 /* this gets called after the splash screen gets exposed ... */
43 gtk_main_quit();
46 void
47 app_splash_init (const gchar* fname)
49 GtkWidget *vbox;
50 GtkWidget* gpixmap;
51 GtkWidget *label;
52 GtkWidget *frame;
53 gchar str[256];
54 gulong signal_id;
56 splash = gtk_window_new (GTK_WINDOW_TOPLEVEL);
57 gtk_window_set_role (GTK_WINDOW (splash), "start_dialog");
58 gtk_window_set_title (GTK_WINDOW (splash), _("Loading ..."));
59 gtk_window_set_resizable (GTK_WINDOW (splash), FALSE);
60 gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
62 vbox = gtk_vbox_new (FALSE, 2);
63 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
64 gtk_container_add (GTK_CONTAINER(splash), vbox);
66 gpixmap = get_logo_pixmap();
68 frame = gtk_frame_new (NULL);
69 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
70 gtk_container_set_border_width (GTK_CONTAINER (frame), 1);
71 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, TRUE, 1);
73 if (gpixmap)
74 gtk_container_add (GTK_CONTAINER(frame), gpixmap);
76 g_snprintf(str, sizeof(str), _("Dia v %s"), VERSION);
77 label = gtk_label_new (str);
78 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 1);
80 gtk_widget_show_all (splash);
82 signal_id = g_signal_connect_after(GTK_OBJECT(splash), "expose_event",
83 GTK_SIGNAL_FUNC(splash_expose), NULL);
85 /* splash_expose gets us out of this */
86 gtk_main();
87 g_signal_handler_disconnect(GTK_OBJECT(splash), signal_id);
90 void
91 app_splash_done (void)
93 if (splash)
95 gtk_widget_destroy (splash);
96 splash = NULL;