注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

jasy.ice 的小房子

iceplayer gtk linux c

 
 
 

日志

 
 

libunique  

2010-05-04 23:17:07|  分类: GTK |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |


不考虑ubuntu9.10之前的兼容性的话,这个lib做得不错。(ubuntu9.10之前没这个包)
不知道有什么用?

修改 单实例 (原来是已经有一个实例A时,再打开iceplayer(实例B),就会关闭实例A,用实例B代替,现在是实例B自动退出并显示实例A,这样就不会中断正在播放的音乐了)

详情?源码?
devhelp:
添加头文件:
#include <unique/unique.h>
链接库:
-lunique
-I/usr/include/unique-1.0/
示例:
#define COMMAND_QUIT             1
#define COMMAND_SEARCH           2
#define COMMAND_SEARCH_ASSISTANT 3
#define COMMAND_FOCUS_SEARCH     4
#define COMMAND_RAISE            5

static UniqueResponse
unique_app_message_cb (UniqueApp *unique_app,gint command,UniqueMessageData *data, guint timestamp,gpointer user_data){
    DhBase    *base = user_data;
    gchar     *search_string;
    GtkWidget *window;

    if (command == COMMAND_QUIT) {
        gtk_main_quit ();
        return UNIQUE_RESPONSE_OK;
    }

    if (command == COMMAND_SEARCH_ASSISTANT) {
        search_string = unique_message_data_get_text(data);
                search_assistant (base, search_string);
        g_free (search_string);
        return UNIQUE_RESPONSE_OK;
    }

    window = dh_base_get_window (base);
    if (command == COMMAND_SEARCH) {
        search_string = unique_message_data_get_text(data);
                search_normal (DH_WINDOW (window), search_string);
        g_free (search_string);
    }
    else if (command == COMMAND_FOCUS_SEARCH) {
        dh_window_focus_search (DH_WINDOW (window));
    }

#ifdef GDK_WINDOWING_X11
#if GTK_CHECK_VERSION (2,14,0)
    timestamp = gdk_x11_get_server_time (gtk_widget_get_window (window));
#else
    timestamp = gdk_x11_get_server_time (window->window);
#endif
#else
    timestamp = GDK_CURRENT_TIME;
#endif

    gtk_window_present_with_time (GTK_WINDOW (window), timestamp);
    return UNIQUE_RESPONSE_OK;
}

int main (int argc, char **argv){
    gchar                  *option_search = NULL;
    gchar                  *option_search_assistant = NULL;
    gboolean                option_quit = FALSE;
    gboolean                option_focus_search = FALSE;
    gboolean                option_version = FALSE;
    UniqueApp              *unique_app;
    DhBase                 *base;
    GtkWidget              *window;
    GError                 *error = NULL;
        GOptionEntry            options[] = {
                { "search", 's',
                  0, G_OPTION_ARG_STRING, &option_search,
                  _("Search for a keyword"),
                  NULL
                },
                { "quit", 'q',
                  0, G_OPTION_ARG_NONE, &option_quit,
                  _("Quit any running Devhelp"),
                  NULL
                },
                { "version", 'v',
                  0, G_OPTION_ARG_NONE, &option_version,
                  _("Display the version and exit"),
                  NULL
                },
                { "focus-search",       'f',
                  0, G_OPTION_ARG_NONE, &option_focus_search,
                  _("Focus the Devhelp window with the search field active"),
                  NULL
                },
                { "search-assistant", 'a',
                  0, G_OPTION_ARG_STRING, &option_search_assistant,
                  _("Search and display any hit in the assistant window"),
                  NULL
                },
                { NULL }
        };

#ifdef GDK_WINDOWING_QUARTZ
        {
                gint i;

                for (i = 0; i < argc; i++) {
                        if (g_str_has_prefix (argv[i], "-psn_")) {
                                for (; i < argc-1; i++) {
                                        argv[i] = argv[i+1];
                                }
                                argc--;
                                break;
                        }
                }
        }
#endif

    bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
    textdomain (GETTEXT_PACKAGE);

    g_thread_init (NULL);

    if (!gtk_init_with_args (&argc, &argv, NULL, options, GETTEXT_PACKAGE, &error)) {
        g_printerr ("%s\n", error->message);
        return 1;
    }

    if (option_version) {
        g_print ("%s\n", PACKAGE_STRING);
        return 0;
    }

    /* i18n: Please don't translate "Devhelp" (it's marked as translatable
     * for transliteration only) */
    g_set_application_name (_("Devhelp"));
    gtk_window_set_default_icon_name ("devhelp");

    unique_app = unique_app_new_with_commands ("org.gnome.Devhelp", NULL,
        "quit", COMMAND_QUIT,
        "search", COMMAND_SEARCH,
        "search_assistant", COMMAND_SEARCH_ASSISTANT,
        "focus_search", COMMAND_FOCUS_SEARCH,
        "raise", COMMAND_RAISE,
        NULL
        );

    if (unique_app_is_running (unique_app)) {
        UniqueMessageData *message_data = NULL;

        if (option_quit) {
            unique_app_send_message (unique_app, COMMAND_QUIT, NULL);
        }
        else if (option_search) {
            message_data = unique_message_data_new ();
            unique_message_data_set_text (message_data, option_search, -1);
            unique_app_send_message (unique_app, COMMAND_SEARCH, message_data);
            unique_message_data_free (message_data);
        }
        else if (option_search_assistant) {
            message_data = unique_message_data_new ();
            unique_message_data_set_text (message_data, option_search_assistant, -1);
            unique_app_send_message (unique_app, COMMAND_SEARCH_ASSISTANT, message_data);
            unique_message_data_free (message_data);
        }
        else if (option_focus_search) {
            unique_app_send_message (unique_app, COMMAND_FOCUS_SEARCH, NULL);
        } else {
            unique_app_send_message (unique_app, COMMAND_RAISE, NULL);
        }

        g_object_unref (unique_app);
        return 0;
    }

    if (option_quit) {
        /* No running Devhelps so just quit */
        return 0;
    }

    base = dh_base_new ();

    g_signal_connect (unique_app, "message-received",
          G_CALLBACK (unique_app_message_cb), base);

    if (!option_search_assistant) {
        window = dh_base_new_window (base);

                if (option_search) {
                        search_normal (DH_WINDOW (window), option_search);
                }

        gtk_widget_show (window);
    } else {
        if (!search_assistant (base, option_search_assistant)) {
                        return 0;
                }
    }

    gtk_main ();

    g_object_unref (base);
    g_object_unref (unique_app);

    return 0;
}

有点乱,要不自己下源码 apt-get source devhelp看
  评论这张
 
阅读(491)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018