popupmenu/src/main.c

Go to the documentation of this file.
00001 /*
00002  * File Name: main.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) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 //----------------------------------------------------------------------------
00028 // Include Files
00029 //----------------------------------------------------------------------------
00030 
00031 #include "config.h"
00032 
00033 // system include files, between < >
00034 #include <gtk/gtk.h>
00035 #include <string.h>
00036 #include <signal.h>
00037 #include <unistd.h>
00038 
00039 // ereader include files, between < >
00040 #include <libergtk/ergtk.h>
00041 
00042 // local include files, between " "
00043 #include "log.h"
00044 #include "dialog.h"
00045 #include "i18n.h"
00046 #include "ipc.h"
00047 #include "menustore.h"
00048 #include "statusbar.h"
00049 #include "taskbar.h"
00050 
00051 
00052 //----------------------------------------------------------------------------
00053 // Global Constants
00054 //----------------------------------------------------------------------------
00055 
00056 static const char  *rc_filename = DATADIR "/" PACKAGE_NAME ".rc";
00057 static guint wait_low_battery_sec = 10;
00058 
00059  
00060 //----------------------------------------------------------------------------
00061 // Static Variables
00062 //----------------------------------------------------------------------------
00063 
00064 static gboolean g_has_stylus    = FALSE;
00065 static gboolean g_has_wifi      = FALSE;
00066 static gboolean g_has_bluetooth = FALSE;
00067 static gboolean g_has_3g        = FALSE;
00068 
00069 //============================================================================
00070 // Functions Implementation
00071 //============================================================================
00072 
00073 
00074 static void on_sigterm(int signo)
00075 {
00076     WARNPRINTF("    -- entry " PACKAGE_NAME ", my pid [%d]", getpid());
00077 
00078     // stop main process, prepare to quit application
00079     gtk_main_quit();
00080 
00081     WARNPRINTF("    -- leave " PACKAGE_NAME);
00082 }
00083 
00084 
00085 static gboolean on_startup_complete (gpointer data)
00086 {
00087     ipc_send_startup_complete();
00088     return FALSE; // remove timer source
00089 }
00090 
00091 
00092 static gboolean on_check_low_battery(gpointer data)
00093 {
00094     gint level;
00095     gchar *state = NULL;
00096     
00097     if (ipc_get_battery_state(&level, &state, NULL))
00098     {
00099         statusbar_update_battery_state(level, state);
00100         if ((state != NULL) && g_ascii_strcasecmp(state, "low") == 0)
00101         {
00102             dialog_splash_show("batterylow");
00103         }
00104         g_free(state);
00105     }
00106     
00107     // remove timeout
00108     return FALSE;
00109 }
00110 
00111 
00112 int main (int argc, char **argv)
00113 {
00114     struct sigaction on_term;
00115     
00116     // catch the SIGTERM signal
00117     memset(&on_term, 0x00, sizeof(on_term));
00118     on_term.sa_handler = on_sigterm;
00119     sigaction(SIGTERM, &on_term, NULL);
00120 #if LOGGING_ON
00121     sigaction(SIGINT,  &on_term, NULL);
00122 #endif
00123  
00124     // init domain for translations
00125     textdomain(GETTEXT_PACKAGE);
00126 
00127     // init gtk
00128     gtk_init(&argc, &argv);
00129     
00130     // open the RC file associated with this program
00131     WARNPRINTF("gtk_rc_parse [%s]", rc_filename);
00132     gtk_rc_parse(rc_filename);
00133     
00134     // start IPC services first so it is ready to receive
00135     menustore_create(taskbar_select_folder);
00136     ipc_set_services();
00137 
00138     // init global
00139     dialog_create();
00140     
00141     ipc_get_device_capabilities(&g_has_stylus, &g_has_wifi, &g_has_bluetooth, &g_has_3g);
00142 
00143     statusbar_create(dialog_message_info);
00144 
00145     // set battery status
00146     gint level;
00147     gchar *state = NULL;
00148     if (ipc_get_battery_state(&level, &state, NULL))
00149     {
00150         statusbar_update_battery_state(level, state);
00151         g_free(state);
00152     }
00153 
00154 #if MACHINE_IS_DR1000S || MACHINE_IS_DR1000SW
00155     taskbar_create();
00156 #endif
00157 
00158     // report startup has completed
00159     g_idle_add(on_startup_complete, NULL);
00160 
00161     // wait for applications to be started and check battery again
00162     g_timeout_add_seconds(wait_low_battery_sec, on_check_low_battery, NULL);
00163     
00164     // enter GTK main loop
00165     WARNPRINTF("-- before gtk_main");
00166     gtk_main();
00167     WARNPRINTF("-- after gtk_main");
00168 
00169     return 0;
00170 }
Generated by  doxygen 1.6.2-20100208