From 8453eb9d3f6e7503adcfe7dd8aad2345825edba6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sat, 20 Aug 2011 15:15:31 +0000 Subject: [PATCH] Let plug-ins show windows and trigger messages as well --- include/Phone/plugin.h | 1 + src/phone.c | 43 +++++++++++++++++++++++++ src/plugins/systray.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/include/Phone/plugin.h b/include/Phone/plugin.h index 2852aa1..57ab0b2 100644 --- a/include/Phone/plugin.h +++ b/include/Phone/plugin.h @@ -39,6 +39,7 @@ typedef struct _PhonePluginHelper char const * variable, char const * value); int (*error)(Phone * phone, char const * message, int ret); int (*event)(Phone * phone, PhoneEvent * event); + void (*message)(Phone * phone, PhoneMessage message, ...); int (*request)(Phone * phone, ModemRequest * request); int (*trigger)(Phone * phone, ModemEventType event); } PhonePluginHelper; diff --git a/src/phone.c b/src/phone.c index d2a48b6..0eb91e5 100644 --- a/src/phone.c +++ b/src/phone.c @@ -300,6 +300,8 @@ static GtkWidget * _phone_messages_get_view(Phone * phone); static GtkWidget * _phone_progress_delete(GtkWidget * widget); static void _phone_progress_pulse(GtkWidget * widget); +static void _phone_message(Phone * phone, PhoneMessage message, ...); + static int _phone_request(Phone * phone, ModemRequest * request); static void _phone_show_contacts_dialog(Phone * phone, gboolean show, @@ -376,6 +378,7 @@ Phone * phone_new(char const * plugin, int retry) phone->helper.config_set = _phone_config_set; phone->helper.error = phone_error; phone->helper.event = phone_event; + phone->helper.message = _phone_message; phone->helper.request = _phone_request; phone->helper.trigger = _phone_trigger; phone->helper.phone = phone; @@ -3255,6 +3258,46 @@ static void _phone_info(Phone * phone, GtkWidget * window, char const * message, } +/* phone_message */ +static void _phone_message(Phone * phone, PhoneMessage message, ...) +{ + va_list ap; + PhoneMessagePowerManagement power; + PhoneMessageShow show; + PhoneEvent event; + + memset(&event, 0, sizeof(event)); + va_start(ap, message); + switch(message) + { + case PHONE_MESSAGE_POWER_MANAGEMENT: + power = va_arg(ap, PhoneMessagePowerManagement); + if(power == PHONE_MESSAGE_POWER_MANAGEMENT_RESUME) + event.type = PHONE_EVENT_TYPE_SUSPEND; + else if(power == PHONE_MESSAGE_POWER_MANAGEMENT_SUSPEND) + event.type = PHONE_EVENT_TYPE_RESUME; + else + break; + phone_event(phone, &event); + break; + case PHONE_MESSAGE_SHOW: + show = va_arg(ap, PhoneMessageShow); + if(show == PHONE_MESSAGE_SHOW_CONTACTS) + phone_show_contacts(phone, TRUE); + else if(show == PHONE_MESSAGE_SHOW_DIALER) + phone_show_dialer(phone, TRUE); + else if(show == PHONE_MESSAGE_SHOW_LOGS) + phone_show_logs(phone, TRUE); + else if(show == PHONE_MESSAGE_SHOW_MESSAGES) + phone_show_messages(phone, TRUE); + else if(show == PHONE_MESSAGE_SHOW_SETTINGS) + phone_show_settings(phone, TRUE); + break; + } + va_end(ap); +} + + /* phone_messages_filter_all */ static gboolean _phone_messages_filter_all(GtkTreeModel * model, GtkTreeIter * iter, gpointer data) diff --git a/src/plugins/systray.c b/src/plugins/systray.c index 45907be..ed4a8cc 100644 --- a/src/plugins/systray.c +++ b/src/plugins/systray.c @@ -44,6 +44,8 @@ static int _systray_destroy(PhonePlugin * plugin); /* callbacks */ #if GTK_CHECK_VERSION(2, 10, 0) static void _systray_on_activate(gpointer data); +static void _systray_on_popup_menu(GtkStatusIcon * icon, guint button, + guint time, gpointer data); #endif @@ -90,6 +92,8 @@ static int _systray_init(PhonePlugin * plugin) systray->icon = gtk_status_icon_new_from_icon_name("phone-dialer"); g_signal_connect_swapped(systray->icon, "activate", G_CALLBACK( _systray_on_activate), plugin); + g_signal_connect(systray->icon, "popup-menu", G_CALLBACK( + _systray_on_popup_menu), plugin); systray->ab_window = NULL; return 0; #else @@ -144,4 +148,71 @@ static gboolean _activate_on_closex(gpointer data) gtk_widget_hide(systray->ab_window); return TRUE; } + + +/* systray_on_popup_menu */ +static void _popup_menu_on_show_dialer(gpointer data); +static void _popup_menu_on_show_logs(gpointer data); +static void _popup_menu_on_show_messages(gpointer data); +static void _popup_menu_on_show_settings(gpointer data); + +static void _systray_on_popup_menu(GtkStatusIcon * icon, guint button, + guint time, gpointer data) +{ + PhonePlugin * plugin = data; + GtkWidget * menu; + GtkWidget * menuitem; + + menu = gtk_menu_new(); + menuitem = gtk_menu_item_new_with_mnemonic("Show _dialer"); + g_signal_connect_swapped(menuitem, "activate", G_CALLBACK( + _popup_menu_on_show_dialer), plugin); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_menu_item_new_with_mnemonic("Show _logs"); + g_signal_connect_swapped(menuitem, "activate", G_CALLBACK( + _popup_menu_on_show_logs), plugin); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_menu_item_new_with_mnemonic("Show _messages"); + g_signal_connect_swapped(menuitem, "activate", G_CALLBACK( + _popup_menu_on_show_messages), plugin); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + menuitem = gtk_menu_item_new_with_mnemonic("Show _settings"); + g_signal_connect_swapped(menuitem, "activate", G_CALLBACK( + _popup_menu_on_show_settings), plugin); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + gtk_widget_show_all(menu); + gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, time); +} + +static void _popup_menu_on_show_dialer(gpointer data) +{ + PhonePlugin * plugin = data; + + plugin->helper->message(plugin->helper->phone, PHONE_MESSAGE_SHOW, + PHONE_MESSAGE_SHOW_DIALER); +} + +static void _popup_menu_on_show_logs(gpointer data) +{ + PhonePlugin * plugin = data; + + plugin->helper->message(plugin->helper->phone, PHONE_MESSAGE_SHOW, + PHONE_MESSAGE_SHOW_LOGS); +} + +static void _popup_menu_on_show_messages(gpointer data) +{ + PhonePlugin * plugin = data; + + plugin->helper->message(plugin->helper->phone, PHONE_MESSAGE_SHOW, + PHONE_MESSAGE_SHOW_MESSAGES); +} + +static void _popup_menu_on_show_settings(gpointer data) +{ + PhonePlugin * plugin = data; + + plugin->helper->message(plugin->helper->phone, PHONE_MESSAGE_SHOW, + PHONE_MESSAGE_SHOW_SETTINGS); +} #endif