splash.c

Go to the documentation of this file.
00001 /*
00002  * File Name: splash.c
00003  */
00004 
00005 /*
00006  * This file is part of popupmenu.
00007  *
00008  * popupmenu is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * popupmenu is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2010 IREX Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #define LOGGING_ON 1
00028 
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <errno.h>
00032 #include <unistd.h>
00033 #include <math.h>
00034 #include <string.h>
00035 #include <sys/ioctl.h>
00036 
00037 #include <glib.h>
00038 #include <gtk/gtk.h>
00039 #include <gdk/gdk.h>
00040 #include <gdk/gdkx.h>
00041 
00042 #include "log.h"
00043 #include "i18n.h"
00044 #include "dialog.h"
00045 
00046 
00047 // screen layout
00048 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00049 static const int        TEXT_TOP_PADDING         =  40 + 5;
00050 static const int        TEXT_BOTTOM_PADDING      =  830 + 5;
00051 static const int        TEXT_LEFT_PADDING        =  150 + 5;
00052 static const int        TEXT_RIGHT_PADDING       =  100 + 5;
00053 
00054 static const int        TITLE_TOP_PADDING        =  0;
00055 static const int        TITLE_BOTTOM_PADDING     =  0;
00056 static const int        TITLE_LEFT_PADDING       =  0;
00057 static const int        TITLE_RIGHT_PADDING      =  0;
00058 
00059 static const int        MESSAGE_TOP_PADDING      =   0;
00060 static const int        MESSAGE_BOTTOM_PADDING   =   0;
00061 static const int        MESSAGE_LEFT_PADDING     =   0;
00062 static const int        MESSAGE_RIGHT_PADDING    =   0;
00063 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00064 static const int        TITLE_TOP_PADDING        =   0;
00065 static const int        TITLE_BOTTOM_PADDING     =  25;
00066 static const int        TITLE_LEFT_PADDING       =  25;
00067 static const int        TITLE_RIGHT_PADDING      =  25;
00068 
00069 static const int        MESSAGE_TOP_PADDING      =   0;
00070 static const int        MESSAGE_BOTTOM_PADDING   =  80;
00071 static const int        MESSAGE_LEFT_PADDING     =   0;
00072 static const int        MESSAGE_RIGHT_PADDING    =   0;
00073 #else
00074 #error "Unhandled machine type"
00075 #endif
00076 
00077 static GtkWidget *splash_window  = NULL;
00078 static GtkWidget *splash_title   = NULL;
00079 static GtkWidget *splash_message = NULL;
00080 static GdkPixbuf *splash_pixbuf  = NULL;
00081 
00082 
00083 static gboolean on_splash_expose(GtkWidget      *widget,
00084                                  GdkEventExpose *event,
00085                                  gpointer       data)
00086 { 
00087     LOGPRINTF("entry [%p]", splash_pixbuf);
00088     gdk_draw_pixbuf(widget->window, NULL, splash_pixbuf, 0, 0, 0, 0, -1, -1, GDK_RGB_DITHER_MAX, 0, 0);
00089     
00090     GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget));
00091     if (child)
00092     {
00093         gtk_container_propagate_expose(GTK_CONTAINER(widget), child, event);
00094     }
00095     return TRUE;
00096 }
00097 
00098 
00099 static void change_splash(const char* filename, const char* title, const char* message)
00100 {
00101     LOGPRINTF("entry");
00102     
00103     if (splash_pixbuf) g_object_unref(splash_pixbuf);
00104     splash_pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
00105     gtk_widget_show_all(splash_window);
00106     
00107     gtk_label_set_text(GTK_LABEL(splash_title), title);
00108     gtk_label_set_text(GTK_LABEL(splash_message), message);
00109     
00110     GdkRectangle rect;
00111     rect.x = 0;
00112     rect.y = 0;
00113     rect.width  = 1024;
00114     rect.height = 1268;
00115 
00116     gdk_window_invalidate_rect(splash_window->window, &rect, TRUE);
00117 }
00118 
00119 
00120 static void create_splash()
00121 {
00122     LOGPRINTF("entry");
00123     
00124     GtkWidget *window     = NULL;
00125     GtkWidget *widget     = NULL;
00126     GtkBox    *vbox       = NULL;
00127     GtkWidget *alignment  = NULL;
00128 
00129     // object hierarchy:
00130     //    
00131     // window
00132     //  |
00133     widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00134     window = widget;
00135     splash_window = GTK_WIDGET(widget);
00136     gtk_window_set_resizable(GTK_WINDOW(splash_window), FALSE);
00137     gtk_window_fullscreen(GTK_WINDOW(splash_window)); 
00138     gtk_window_set_type_hint(GTK_WINDOW(splash_window), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
00139     gtk_widget_set_app_paintable(splash_window, TRUE); 
00140 
00141 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00142     //    |--alignment
00143     //       |
00144     widget = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
00145     gtk_alignment_set_padding(GTK_ALIGNMENT(widget),
00146             TEXT_TOP_PADDING,
00147             TEXT_BOTTOM_PADDING,
00148             TEXT_LEFT_PADDING,
00149             TEXT_RIGHT_PADDING);
00150     gtk_container_add(GTK_CONTAINER(window), widget);
00151     gtk_widget_show(widget);
00152     alignment = widget;
00153     //       |
00154     //       |-- vbox
00155     //             |
00156     widget = gtk_vbox_new(FALSE, 0);
00157     gtk_container_add(GTK_CONTAINER(alignment), widget);
00158     gtk_widget_show(widget);
00159     vbox = GTK_BOX(widget);   
00160 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00161     //       |
00162     //       |-- vbox
00163     //             |
00164     widget = gtk_vbox_new(FALSE, 0);
00165     gtk_container_add(GTK_CONTAINER(window), widget);
00166     gtk_widget_show(widget);
00167     vbox = GTK_BOX(widget);   
00168     //             |
00169     //             |-- alignment (filler)
00170     //             |    
00171     widget = gtk_alignment_new(0.0, 0.0, 0.0, 0.0);
00172     gtk_box_pack_start(vbox, widget, TRUE, TRUE, 0);
00173     gtk_widget_show(widget);
00174 #else
00175 #error "Unhandled machine type"
00176 #endif     
00177     //             |
00178     //             |-- alignment
00179     //             |     |
00180     widget = gtk_alignment_new(0.5, 0.5, 0.5, 0.5);
00181     gtk_alignment_set_padding( GTK_ALIGNMENT(widget),
00182                                TITLE_TOP_PADDING,
00183                                TITLE_BOTTOM_PADDING,
00184                                TITLE_LEFT_PADDING,
00185                                TITLE_RIGHT_PADDING);
00186     gtk_box_pack_start(vbox, widget, FALSE, FALSE, 0);
00187     gtk_widget_show(widget);
00188     alignment = widget;
00189     
00190     //             |     |    
00191     //             |     |-- title
00192     //             |        
00193     widget = gtk_label_new(NULL);
00194 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00195     int LABEL_WIDTH = 768 - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING 
00196                           - TITLE_LEFT_PADDING - TITLE_RIGHT_PADDING; 
00197     gtk_widget_set_size_request(widget, LABEL_WIDTH, -1);
00198     gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
00199     gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
00200 #endif    
00201     gtk_widget_set_name(widget, "irex-splash-title");
00202     gtk_container_add(GTK_CONTAINER(alignment), widget);
00203     gtk_widget_show(widget);
00204     splash_title = widget;
00205 
00206     //             |
00207     //             |-- alignment
00208     //                   |
00209     widget = gtk_alignment_new(0.5, 0.5, 0.5, 0.5);
00210     gtk_alignment_set_padding( GTK_ALIGNMENT(widget),
00211                                MESSAGE_TOP_PADDING,
00212                                MESSAGE_BOTTOM_PADDING,
00213                                MESSAGE_LEFT_PADDING,
00214                                MESSAGE_RIGHT_PADDING);
00215     gtk_box_pack_start(vbox, widget, FALSE, FALSE, 0);
00216     gtk_widget_show(widget);
00217     alignment = widget;
00218     
00219     //                   |    
00220     //                   |-- message
00221     //                     
00222     widget = gtk_label_new(NULL);
00223 #if MACHINE_IS_DR800SG || MACHINE_IS_DR800S || MACHINE_IS_DR800SW
00224     LABEL_WIDTH = 768 - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING 
00225                       - MESSAGE_LEFT_PADDING - MESSAGE_RIGHT_PADDING; 
00226     gtk_widget_set_size_request(widget, LABEL_WIDTH, -1);
00227 #elif MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00228     gtk_widget_set_size_request(widget, 1024, -1);
00229 #else
00230 #error "Unhandled machine type"
00231 #endif    
00232     gtk_widget_set_name(widget, "irex-splash-message");
00233     gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_CENTER);
00234     gtk_label_set_line_wrap(GTK_LABEL(widget), TRUE);
00235     gtk_container_add(GTK_CONTAINER(alignment), widget);
00236     gtk_widget_show(widget);   
00237     splash_message = widget;
00238 
00239     // force non-decorated full screen splash
00240     gint w, h;
00241     gdk_window_get_geometry(gdk_get_default_root_window(), NULL, NULL, &w, &h, NULL);
00242     gtk_widget_set_size_request(splash_window, w,  h);
00243     
00244     g_signal_connect(GTK_OBJECT(splash_window), "expose_event", G_CALLBACK (on_splash_expose), NULL);
00245 }
00246 
00247 
00248 static gboolean on_timeout(gpointer data)
00249 {
00250     LOGPRINTF("entry");
00251     change_splash("/usr/share/popupmenu/background_general.png", "Second splash", "Break to exit");
00252     return FALSE;
00253 }
00254 
00255 
00256 int main (int argc, char *argv[])
00257 {
00258     LOGPRINTF("entry");
00259     
00260     // init domain for translations
00261     textdomain(GETTEXT_PACKAGE);
00262 
00263     // Initialise
00264     gtk_init(&argc, &argv);
00265 
00266     create_splash();
00267     change_splash("/usr/share/popupmenu/background_usbconnect.png", "First splash", "Next in a few seconds");
00268 
00269     g_timeout_add_seconds(4, on_timeout, NULL);
00270     
00271     gtk_main();
00272     
00273     return 0;
00274 }
Generated by  doxygen 1.6.2-20100208