资源描述:
《linux应用程序开发指南之21-19.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、下载第五部分附录附录AGnomeHello源代码这里是本书中多次用到的GnomeHello的源代码。它是学习Gnome编程非常好的材料。源代码共分为五个文件,分别是hello.c、app.c、app.h、menu.c以及menu.h。A.1第一部分:hello.c#include#include#include"app.h"staticvoidsession_die(GnomeClient*client,gpointerclient_data);staticgintsave_session(GnomeClie
2、nt*client,gintphase,GnomeSaveStylesave_style,gintis_shutdown,GnomeInteractStyleinteract_style,gintis_fast,gpointerclient_data);staticintgreet_mode=FALSE;staticchar*message=NULL;staticchar*geometry=NULL;structpoptOptionoptions[]={{"greet",‘g’,POPT_ARG_NONE,&greet_mode,0,N_("Sa
3、yhellotospecificpeoplelistedonthecommandline"),NULL},{"message",‘m’,POPT_ARG_STRING,&message,0,N_("Specifyamessageotherthan"Hello,World!""),N_("MESSAGE")},294使用第五部分附录下载{"geometry",‘ ’,POPT_ARG_STRING,&geometry,0,N_("Specifythegeometryofthemainwindow"),N_("GEOMETRY")},{NULL
4、,‘ ’,0,NULL,0,NULL,NULL}};intmain(intargc,char*argv[]){GtkWidget*app;poptContextpctx;char**args;inti;GSList*greet=NULL;GnomeClient*client;bindtextdomain(PACKAGE,GNOMELOCALEDIR);textdomain(PACKAGE);gnome_init_with_popt_table(PACKAGE,VERSION,argc,argv,options,0,&pctx);/*参数分析*/
5、args=poptGetArgs(pctx);if(greet_mode&&args){i=0;while(args[i]!=NULL){greet=g_slist_prepend(greet,args[i]);++i;附录AGnomeHello源代码使用295下载}/*Puttheminorder*/greet=g_slist_reverse(greet);}elseif(greet_mode&&args==NULL){g_error(_("Youmustspecifysomeonetogreet."));}elseif(args!=NULL)
6、{g_error(_("Commandlineargumentsareonlyallowedwith--greet."));}else{g_assert(!greet_mode&&args==NULL);}poptFreeContext(pctx);/*会话管理*/client=gnome_master_client();gtk_signal_connect(GTK_OBJECT(client),"save_yourself",GTK_SIGNAL_FUNC(save_session),argv[0]);gtk_signal_connect(GT
7、K_OBJECT(client),"die",GTK_SIGNAL_FUNC(session_die),NULL);app=hello_app_new(message,geometry,greet);g_slist_free(greet);gtk_widget_show_all(app);gtk_main();return0;}staticgintsave_session(GnomeClient*client,gintphase,GnomeSaveStylesave_style,gintis_shutdown,GnomeInteractStyle
8、interact_style,gintis_fast,gpointerclient_data){gchar**argv;guintarg