File: splash.c

package info (click to toggle)
hotkeys 0.5.7.4-0.3
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 976 kB
  • ctags: 378
  • sloc: ansic: 3,253; sh: 350; makefile: 66; xml: 17
file content (156 lines) | stat: -rw-r--r-- 4,271 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Adpated from GIMP's app/gui/splash.c
 * Copyright (C) 2002 Anthony Wong
 */

/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <unistd.h>
#include <stdlib.h>

#if HAVE_CONFIG_H
#  include <config.h>
#endif

#if HAVE_GTK

#include <gtk/gtk.h>
#include <X11/X.h>
#include <X11/Xatom.h>

#include "splash.h"


static GtkWidget *win_initstatus = NULL;


void
splash_create (gchar* filename, int duration)
{
  GtkWidget *vbox;
  GdkPixbuf *pixbuf = NULL;
//  GdkAtom atom;

  win_initstatus = gtk_window_new (GTK_WINDOW_TOPLEVEL);
#if 0
  /* Not needed in these WMs: enlightenment, sawfish, metacity, fvwm2, wmaker */
  gtk_window_set_type_hint (GTK_WINDOW (win_initstatus),
                            GDK_WINDOW_TYPE_HINT_DIALOG);
#endif

  gtk_window_set_title (GTK_WINDOW (win_initstatus), filename);
  gtk_window_set_wmclass (GTK_WINDOW (win_initstatus), "hotkeys_splash", "Hotkeys");
  gtk_window_set_position (GTK_WINDOW (win_initstatus), GTK_WIN_POS_CENTER);
  gtk_window_set_resizable (GTK_WINDOW (win_initstatus), FALSE);
  gtk_window_set_modal (GTK_WINDOW (win_initstatus), TRUE);
  gtk_window_set_policy(GTK_WINDOW(win_initstatus), FALSE, FALSE, TRUE);
  gtk_widget_realize(win_initstatus);
  gdk_window_set_decorations(win_initstatus->window, 0);
#if 0
  /* Not needed in these WMs: enlightenment, sawfish, metacity, fvwm2, wmaker */
  atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_SPLASH", FALSE);
  gdk_property_change (win_initstatus->window,
          gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
          (GdkAtom)XA_ATOM, 32, GDK_PROP_MODE_REPLACE,
          (unsigned char *)&atom, 1);
#endif

  g_signal_connect (G_OBJECT (win_initstatus), "delete_event",
                    G_CALLBACK (gtk_true), NULL);

  vbox = gtk_vbox_new (FALSE, 4);
  gtk_container_add (GTK_CONTAINER (win_initstatus), vbox);
  gtk_widget_show (vbox);

  pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
      
  if (pixbuf)
  {
      GtkWidget *align;
      GtkWidget *image;

      image = gtk_image_new_from_pixbuf (pixbuf);
      g_object_unref (pixbuf);

      align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
      gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, TRUE, 0);
      gtk_widget_show (align);

      gtk_container_add (GTK_CONTAINER (align), image);
      gtk_widget_show (image);
  }
  else
  {
      g_message("Cannot open image");
      return;
  }

/*
  label1 = gtk_label_new ("");
  gtk_box_pack_start_defaults (GTK_BOX (vbox), label1);
  gtk_widget_show (label1);

  label2 = gtk_label_new ("");
  gtk_box_pack_start_defaults (GTK_BOX (vbox), label2);
  gtk_widget_show (label2);

  progress = gtk_progress_bar_new ();
  gtk_box_pack_start_defaults (GTK_BOX (vbox), progress);
  gtk_widget_show (progress);
*/

  gtk_widget_show (win_initstatus);
  gtk_timeout_add( duration, splash_destroy, NULL);
}

gint
splash_destroy ( gpointer data )
{
  if (win_initstatus)
    {
      gtk_widget_destroy (win_initstatus);
      win_initstatus = NULL;
    }
  exit(0);
}

#if 0
void
splash_update (const gchar *text1,
	       const gchar *text2,
	       gdouble      percentage)
{
  if (!win_initstatus)
    return;

  if (text1)
    gtk_label_set_text (GTK_LABEL (label1), text1);

  if (text2)
    gtk_label_set_text (GTK_LABEL (label2), text2);
  
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), 
                                 CLAMP (percentage, 0.0, 1.0));
  
  while (gtk_events_pending ())
    gtk_main_iteration ();
}
#endif

#endif /* HAVE_GTK */