[中秋零献] 神州数码802.1x局域网UDP拔号软件MyNet-Gnome源代码大分析(Part2)

/***
* Author: cc0cc
* E-mail: cc0cc@126.com
* WebSite: http://www.54chen.com * Date: the Mid-Autumn Festival of 2008
* FileName: main.c
***/
/*
* Initial main.c file generated by Glade. Edit as required.
* Glade will not overwrite this file.
*/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <gtk/gtk.h>
#include <pthread.h>

#include <gnome.h>
/*如果没记错的话eggtrayicon.h/tray.h都是在Linux用来做系统托盘的头文件,参见
*http://hi.baidu.com/cc0cc/blog/item/26da147a4a428ce92f73b3da.html
*/
#include "eggtrayicon.h"
#include "tray.h"
#include "interface.h"
#include "support.h"
#include "connect.h"

/*系统托盘*/
static void activate_action (GtkAction * action);
static void net_quit (GtkAction * action);
static const gchar *ui_info =
    "<ui>"
    " <popup name='PopupMenu'>"
    "    <menuitem action='About'/>"
    "    <separator/>"
    "    <menuitem action='Quit'/>"
    " </popup>"
    "</ui>";
static GtkActionEntry entries[] = {
    {"Quit", GTK_STOCK_QUIT,    /* name, stock id */
    N_("_断开"), "<control>Q",    /* label, accelerator */
    N_("Quit"),        /* tooltip */
    G_CALLBACK (net_quit)},
    {"About", GTK_STOCK_ABOUT,    /* name, stock id */
    N_( "_关于"), "<control>A",    /* label, accelerator 关于断开*/
    N_("About"),        /* tooltip */
    G_CALLBACK (activate_action)},
};static guint n_entries = G_N_ELEMENTS (entries);
/*系统托盘END*/

/*GTK程序入口*/
int
main (int argc, char *argv[])
{

    GtkUIManager *ui;
    GError *error = NULL;
    GtkActionGroup *actions;
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
                      argc, argv,
                      GNOME_PARAM_APP_DATADIR, PACKAGE_DATA_DIR,
                      NULL);
window1 = create_window1 ();//这是第一个界面,也就是一出来的时候等待输入密码进行连接的界面
    //g_thread_create(thread1,NULL,NULL,NULL);//wait for the book :)
     //pthread_create(&tid,NULL,thread1,NULL);//it is not so good!
     tray = g_new0 (tray_demo, 1);//这里开始弄系统托盘
    tray->window_main = window1;
    create_tray(tray);
    actions = gtk_action_group_new ("Actions");
    gtk_action_group_set_translation_domain (actions, GETTEXT_PACKAGE);
    gtk_action_group_add_actions (actions, entries, n_entries, NULL);
    ui = gtk_ui_manager_new ();
    gtk_ui_manager_insert_action_group (ui, actions, 0);
    gtk_window_add_accel_group (GTK_WINDOW (window1),
                    gtk_ui_manager_get_accel_group (ui));
    if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error))
    {
        g_message ("building menus failed: %s", error->message);
        g_error_free (error);
    }
    tray->ui = ui;
    tray->actions = actions;
    tray->menus = gtk_ui_manager_get_widget (ui, "/PopupMenu");//这段代码可以在gnome中国的网站上找到。。:)
g_message("ccc");   
gtk_widget_show (window1);
gtk_main ();g_message("here2!");
return 0;
}

//下面两个都是为系统托盘的事件做的
static void
activate_action (GtkAction * action)
{   GtkWidget *about;
    about = create_aboutdialog1 ();
     gtk_widget_show (about);
    return;
} static void
net_quit (GtkAction * action)
{     Acc_Keep_Link=-1;
    gtk_widget_show_all (window1);
    send_access_request();
    //g_message("net_quit!");
}

/***
* Author: cc0cc
* E-mail: cc0cc@126.com
* WebSite: http://www.54chen.com

* Date: the Mid-Autumn Festival of 2008
***/


原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com]

捐款订阅54chen
捐赠说明

Comments