gitkLayout.c

Go to the documentation of this file.
00001 
00015 #include "config.h"
00016 
00017 #include <glib.h>
00018 #include <stdio.h>
00019 
00020 #include <libgitk/gitk.h>
00021 
00023 gboolean ret=TRUE;
00024 
00025 //== global event handler ======================================================
00026 
00030 gboolean global_on_close(GitkDialogPtr dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00031   gitk_log("global_on_close()");
00032   return(TRUE);
00033 }
00034 
00035 //== main dialog ===============================================================
00036 
00038 gboolean main_on_clicked(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00039   gitk_log1("main_on_clicked(\"%s\")",widget_id);
00040   if(!strcmp(widget_id,"Okay")) {
00041     gitk_event_loop_end();
00042     ret=TRUE;
00043     return(TRUE);
00044   }
00045   else if(!strcmp(widget_id,"Cancel")) {
00046     gitk_event_loop_end();
00047     ret=FALSE;
00048     return(TRUE);
00049   }
00050   return(FALSE);
00051 }
00052 
00054 gboolean main_show(gchar *dialog_filename) {
00055   gboolean result=FALSE;
00056   gpointer dialog;
00057   gchar *dialog_filepath=NULL;
00058 
00059   dialog_filepath=g_new(char,strlen(GIML_ROOT_PATH)+strlen(dialog_filename)+1);
00060   strcpy(dialog_filepath,GIML_ROOT_PATH);
00061   strcat(dialog_filepath,dialog_filename);
00062   gitk_log1("dialog filepath is \"%s\"",dialog_filepath);
00063 
00064   if((dialog=gitk_dialog_new_from_file(dialog_filepath))) {
00065     gitk_log("dialog parsed");
00066     if(gitk_dialog_show(dialog,FALSE)) {
00067       //-- main callbacks *just rty to connect them - they might not exist)
00068       gitk_dialog_attach_callback(dialog,"Okay",GITK_EVENT_TYPE_ON_CLICKED,NULL,main_on_clicked);
00069       gitk_dialog_attach_callback(dialog,"Cancel",GITK_EVENT_TYPE_ON_CLICKED,NULL,main_on_clicked);
00070       //-- start event loop
00071       gitk_log("run");
00072       gitk_event_loop_start();
00073       gitk_log("hiding");
00074       gitk_dialog_hide(dialog);
00075       gitk_log("dialog done");
00076       result=TRUE;
00077     }
00078     else {
00079       //-- couldn't happen
00080       gitk_dialog_free(dialog);
00081     }
00082   }
00083   else {
00084     gitk_printf(_("error parsing dialog => %d : %s\n"),gitk_get_error_code(),gitk_get_error_str());
00085   }
00086   g_free(dialog_filepath);
00087   return(result);
00088 }
00089 
00090 //== main ======================================================================
00091 
00095 int main(int argc, char **argv) {
00096   guint logger_id;
00097   guint i;
00098   gboolean info_only = FALSE;
00099   gboolean info_help=FALSE, info_version=FALSE;
00100   gchar *dialog_filename=NULL;
00101 
00102   logger_id=g_log_set_handler(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_WARNING|G_LOG_LEVEL_ERROR, gitk_log_handler, NULL);
00103   gitk_log("-- beg -----------------------");
00104   gitk_log1("prog : %s",argv[0]);
00105 
00106 #ifdef ENABLE_NLS
00107   {
00108     gchar *_locale;
00109     //-- at programm startup locale will be set to "C", this initialises it to the env-var
00110     //_locale=setlocale(LC_ALL, "de");
00111     _locale=setlocale(LC_ALL,"");
00112     bindtextdomain(PACKAGE,LOCALEDIR);
00113     bind_textdomain_codeset(PACKAGE,"UTF-8");
00114     textdomain(PACKAGE);
00115     gitk_log3("\"%s\" NLS enabled for domain \"%s\" in dir \"%s\"",(_locale?_locale:"-"),PACKAGE,LOCALEDIR);
00116   }
00117 #endif
00118 
00119   //-- process commandline args
00120   for(i=1;i<(guint)argc;i++) {
00121     if(!strcmp("--help", argv[i]) || !strcmp("-h", argv[i])) {
00122       info_only=info_help=TRUE;
00123     }
00124     else if(!strcmp("--version", argv[i])) {
00125       info_only=info_version=TRUE;
00126     } 
00127     else if(!strncmp("--", argv[i],2)) {
00128       if(!strchr(argv[i],(int)'=')) i++;
00129     }
00130     else {
00131       dialog_filename=argv[i];
00132       gitk_log1("dialog filename is \"%s\"",dialog_filename);
00133     }
00134   }
00135   if(info_help) {
00136     gitk_printf(_("Usage: %s [OPTION]... giml-dialog-file\n\n"),argv[0]);
00137     gitk_puts(_("A demo application for the GITK (Generalized Interface ToolKit - see http://gitk.sf.net)."));
00138     gitk_puts(_("It is able to present arbitrary GIML dialog description files.\n"));
00139     gitk_puts(_("  -h, --help\t\t\tthis help screen"));
00140     gitk_puts(_("      --version\t\t\tshow program version"));
00141     putchar('\n');
00142   }
00143   if(info_version) printf(PACKAGE_NAME"::%s: version "PACKAGE_VERSION" by "PACKAGE_BUGREPORT"\n",argv[0]); 
00144 
00145   //-- init gitk
00146   gitk_init((guint *)&argc,&argv,PACKAGE,LOCALEDIR);
00147   gitk_log("init ok");
00148 
00149   if(!info_only && dialog_filename!=NULL) {
00150     //-- global callbacks
00151     gitk_dialog_attach_callback(NULL,NULL,GITK_EVENT_TYPE_ON_CLOSE,NULL,global_on_close);
00152 
00153     main_show(dialog_filename);
00154   }
00155   //-- done gitk
00156   gitk_done();
00157   gitk_log("-- end -----------------------\n\n");
00158   g_log_remove_handler(G_LOG_DOMAIN,logger_id);
00159   return(EXIT_SUCCESS);
00160 }

Generated on Thu Oct 28 10:59:09 2004 for gitk by doxygen 1.3.6