gitkLauncher.c

Go to the documentation of this file.
00001 
00014 #include "config.h"
00015 
00016 #include <glib.h>
00017 #include <stdio.h>
00018 
00019 #include <libgitk/gitk.h>
00020 
00021 /*
00022 intltool-extract --type=gettext/xml gitkLauncher_main.xml.in
00023 */
00024 
00026 gint menu_choice;
00028 gboolean ret=TRUE;
00029 
00030 //== various tools =============================================================
00031 
00038 gchar *strapp(gchar *src1,gchar *src2) {
00039   gchar *ret;
00040 
00041   g_assert(src2!=NULL);
00042 
00043   if(src1==NULL) ret=strdup(src2);
00044   else {
00045     ret=g_new(gchar,strlen(src1)+strlen(src2)-1);
00046     strcpy(ret,src1);
00047     strcat(ret,src2);
00048     g_free(src1);
00049   }
00050   return(ret);
00051 }
00052 
00053 
00054 //== global event handler ======================================================
00055 
00059 gboolean global_on_close(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00060   gitk_log("global_on_close()");
00061   ret=FALSE;
00062   return(TRUE);
00063 }
00064 
00065 
00067 gboolean global_on_dialog_show(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00068   gitk_log("global_on_dialog_show()");
00069   return(TRUE);
00070 }
00071 
00072 
00074 gboolean global_on_dialog_hide(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00075   gitk_log("global_on_dialog_hide()");
00076   return(TRUE);
00077 }
00078 
00079 
00080 //== main dialog ===============================================================
00081 
00083 gboolean main_on_clicked(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00084   gitk_log1("main_on_clicked(\"%s\")",widget_id);
00085   if(!strcmp(widget_id,"Cancel")) {
00086     gitk_event_loop_end();
00087     ret=FALSE;
00088     return(TRUE);
00089   }
00090   return(FALSE);
00091 }
00092 
00093 
00095 gboolean main_on_changed(gpointer dialog,gchar *widget_id,GitkEventPtr event,gpointer user_data) {
00096   char *value=gitk_widget_get_value(dialog,widget_id,"value");
00097 
00098   gitk_log2("main_on_changed(\"%s\") -> \"%s\"",widget_id, gitk_save_get_string(value));
00099   if(!strcmp(widget_id,"Menu")) {
00100     *(gint *)user_data=(value?atoi(value):0);
00101   }
00102   g_free(value);
00103   return(FALSE);
00104 }
00105 
00106 
00108 gboolean main_show(char *root) {
00109   gboolean result=FALSE;
00110   static gchar *dialog_desc_pre=\
00111   "<?xml version=\"1.0\" ?>"\
00112   "<!DOCTYPE giml SYSTEM \"http://gitk.sourceforge.net/giml.dtd\">"\
00113   "<giml xmlns=\""GITK_NS_URL"\""\
00114   " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""\
00115   " xmlns:i18n=\""I18N_NS_URL"\""\
00116   " >"\
00117   "  <dialog>"\
00118   "    <meta>"\
00119   "      <dc:title><i18n:text>context menu</i18n:text></dc:title"\
00120   "    </meta>"\
00121   "    <widgetgroup>"\
00122   "      <widget id=\"Menu\" type=\"optionchoice_single_expanded\">"\
00123   "        <label>Menu</label>"\
00124   "        <options>";
00125   static gchar *widget_desc_fmt=\
00126   "          <option>%s</option>";
00127   static gchar *dialog_desc_post=\
00128   "        </options>"\
00129   "      </widget>"\
00130   "    </widgetgroup>"\
00131   "  </dialog>"\
00132   "</giml>";
00133   gchar *dialog_desc=NULL;
00134 
00135   dialog_desc=strdup(dialog_desc_pre);
00137   dialog_desc=strapp(dialog_desc,widget_desc_fmt);
00138   dialog_desc=strapp(dialog_desc,dialog_desc_post);
00139 
00140   {
00141     gpointer const dialog=gitk_dialog_new_from_string(dialog_desc);
00142     if(dialog) {
00143       if(gitk_dialog_show(dialog,FALSE)) {
00144         gitk_log("dialog parsed and shown");
00145         //-- global callbacks
00146         gitk_dialog_attach_callback(NULL,NULL,GITK_EVENT_TYPE_ON_CLOSE,NULL,global_on_close);
00147         //-- main callbacks
00148         gitk_dialog_attach_callback(dialog,"Cancel",GITK_EVENT_TYPE_ON_CLICKED,NULL,main_on_clicked);
00149         gitk_dialog_attach_callback(dialog,"Menu",GITK_EVENT_TYPE_ON_CHANGED,&menu_choice,main_on_changed);
00150         //-- start event loop
00151         gitk_log("run");
00152         gitk_event_loop_start();
00153         gitk_log("hiding");
00154         gitk_dialog_hide(dialog);
00155         gitk_log("dialog done");
00156         result=TRUE;
00157       }
00158       else {
00159         //-- couldn't happen
00160       }
00161       gitk_dialog_free(dialog);
00162     }
00163     else {
00164       gitk_printf(_("error parsing dialog => %d : %s\n"),gitk_get_error_code(),gitk_get_error_str());
00165     }
00166   }
00167   g_free(dialog_desc);
00168   return(result);
00169 }
00170 
00171 //== main ======================================================================
00172 
00175 int main(int argc, char **argv) {
00176   guint logger_id;
00177   guint i;
00178   gboolean info_only=FALSE;
00179   gboolean info_help=FALSE, info_version=FALSE;
00180 
00181   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);
00182   gitk_log("-- beg -----------------------");
00183   gitk_log1("prog : %s",argv[0]);
00184 
00185 #ifdef ENABLE_NLS
00186   {
00187     gchar *_locale;
00188     //-- at programm startup locale will be set to "C", this initialises it to the env-var
00189     //_locale=setlocale(LC_ALL, "de");
00190     _locale=setlocale(LC_ALL,"");
00191     bindtextdomain(PACKAGE,LOCALEDIR);
00192     bind_textdomain_codeset(PACKAGE,"UTF-8");
00193     textdomain(PACKAGE);
00194     gitk_log3("\"%s\" NLS enabled for domain \"%s\" in dir \"%s\"",(_locale?_locale:"-"),PACKAGE,LOCALEDIR);
00195   }
00196 #endif
00197 
00198   //-- process commandline args
00199   for(i=1;i<(guint)argc;i++) {
00200     if(!strcmp("--help", argv[i]) || !strcmp("-h", argv[i])) {
00201       info_only=info_help=TRUE;
00202     }
00203     else if(!strcmp("--version", argv[i])) {
00204       info_only=info_version=TRUE;
00205     }
00206   }
00207   if(info_help) {
00208     gitk_printf(_("Usage: %s [OPTION...]\n\n"),argv[0]);
00209     gitk_puts(_("  -h, --help\t\t\tthis help screen"));
00210     gitk_puts(_("      --version\t\t\tshow program version"));
00211     putchar('\n');
00212   }
00213   if(info_version) printf(PACKAGE_NAME"::%s: version "PACKAGE_VERSION" by "PACKAGE_BUGREPORT"\n",argv[0]); 
00214 
00215   //-- init gitk
00216   gitk_init((guint *)&argc,&argv,PACKAGE,LOCALEDIR);
00217 
00218   if(!info_only) {
00220     //-- as long as not cancel or close has been issued
00221     while(ret) {
00222       //-- show with root dir     
00223       main_show("/");
00224       gitk_log2("ret=%d  menu_choice=%3d",ret,menu_choice);
00225       if(!ret) {
00227       }
00228     }
00229   }
00230 
00231   //-- done gitk
00232   gitk_done();
00233   gitk_log("-- end -----------------------\n\n");
00234   g_log_remove_handler(G_LOG_DOMAIN,logger_id);
00235   return(EXIT_SUCCESS);
00236 }

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