ctb/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 ctb.
00007  *
00008  * ctb 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  * ctb 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 <gtk/gtk.h>
00032 #include <glib.h>
00033 #include <stdlib.h>
00034 #include <unistd.h>
00035 
00036 #include "ctb_log.h"
00037 #include "fileview.h"
00038 #include "filemodel.h"
00039 #include "i18n.h"
00040 #include "ipc.h"
00041 #include "menu.h"
00042 
00043 //----------------------------------------------------------------------------
00044 // Global Constants
00045 //----------------------------------------------------------------------------
00046 
00047 static const char  *rc_filename = DATADIR "/" PACKAGE_NAME ".rc";
00048 
00049 static const char  *EMULATOR_HOSTNAME = "qemuarm";
00050 
00051 
00052 void main_set_locale (const char *locale)
00053 {
00054     LOGPRINTF("entry: locale [%s]", locale);
00055 
00056     const char *old_locale = g_getenv("LANG");
00057     
00058     if (!old_locale || (strcmp(old_locale, locale) != 0))
00059     {
00060         LOGPRINTF("Locale has changed to %s", locale);
00061 
00062         // set locale in environment 
00063         g_setenv("LANG", locale, TRUE);
00064         setlocale(LC_ALL, "");
00065         
00066         // update text and refresh
00067         menu_set_text();
00068         fileview_update_screen_texts();
00069     }
00070 }
00071 
00072 
00073 void main_quit (void)
00074 {
00075     gtk_main_quit();
00076 }
00077 
00078 
00079 static gboolean on_startup_complete (gpointer data)
00080 {
00081     ipc_sys_startup_complete();
00082     return FALSE; // remove timer source
00083 }
00084 
00085 
00086 int main (int argc, char *argv[])
00087 {
00088     textdomain(GETTEXT_PACKAGE);
00089     
00090     gtk_init(&argc, &argv);
00091     gchar** files = gtk_rc_get_default_files();
00092     while (*files)
00093     {
00094         LOGPRINTF("gtk_rc_get_default_files [%s]", *files);
00095         files++;
00096     }
00097 
00098     ipc_init(main_quit, main_set_locale, fileview_media_mounted, fileview_media_unmounted);
00099     menu_init();
00100     fileview_init();
00101 
00102     LOGPRINTF("gtk_rc_parse [%s]", rc_filename);
00103     gtk_rc_parse(rc_filename);
00104 
00105     fileview_create();
00106 
00107     // debug: mount "internal SD" when running on emulator
00108     char hostname[100];
00109     int rc = gethostname(hostname, sizeof(hostname));
00110     if (   rc == 0
00111         && strcmp(hostname, EMULATOR_HOSTNAME) == 0 )
00112     {
00113         WARNPRINTF("Emulator mode: mounting fake card");
00114         storage_media_mounted(DIR_LIBRARY);
00115     }
00116 
00117     g_idle_add(on_startup_complete, NULL);
00118     gdk_threads_enter();
00119     gtk_main();
00120     gdk_threads_leave();
00121 
00122     filemodel_quit();
00123 
00124     return 0;
00125 }
00126 
Generated by  doxygen 1.6.2-20100208