Use GtkUIManager instead of deprecated GtkItemFactory. Bug #572325
svn path=/trunk/; revision=9289
This commit is contained in:
parent
6f93ad356d
commit
1c29b115e6
2 changed files with 43 additions and 60 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2009-02-26 Thomas H.P. Andersen <phomes@gmail.com>
|
||||||
|
|
||||||
|
* typing-break/drwright.c: Use GtkUIManager instead of deprecated
|
||||||
|
GtkItemFactory. Bug #572325
|
||||||
|
|
||||||
2009-02-23 Thomas H.P. Andersen <phomes@gmail.com>
|
2009-02-23 Thomas H.P. Andersen <phomes@gmail.com>
|
||||||
|
|
||||||
* capplets/keyboard/gnome-keyboard-properties-xkbot.c:
|
* capplets/keyboard/gnome-keyboard-properties-xkbot.c:
|
||||||
|
|
|
@ -61,7 +61,7 @@ struct _DrWright {
|
||||||
|
|
||||||
DrwMonitor *monitor;
|
DrwMonitor *monitor;
|
||||||
|
|
||||||
GtkItemFactory *popup_factory;
|
GtkUIManager *ui_manager;
|
||||||
|
|
||||||
DrwState state;
|
DrwState state;
|
||||||
GTimer *timer;
|
GTimer *timer;
|
||||||
|
@ -105,31 +105,19 @@ static void break_window_postpone_cb (GtkWidget *window,
|
||||||
DrWright *dr);
|
DrWright *dr);
|
||||||
static void break_window_destroy_cb (GtkWidget *window,
|
static void break_window_destroy_cb (GtkWidget *window,
|
||||||
DrWright *dr);
|
DrWright *dr);
|
||||||
static void popup_break_cb (gpointer callback_data,
|
static void popup_break_cb (GtkAction *action,
|
||||||
guint action,
|
DrWright *dr);
|
||||||
GtkWidget *widget);
|
static void popup_preferences_cb (GtkAction *action,
|
||||||
static void popup_preferences_cb (gpointer callback_data,
|
DrWright *dr);
|
||||||
guint action,
|
static void popup_about_cb (GtkAction *action,
|
||||||
GtkWidget *widget);
|
DrWright *dr);
|
||||||
static void popup_about_cb (gpointer callback_data,
|
|
||||||
guint action,
|
|
||||||
GtkWidget *widget);
|
|
||||||
static gchar * item_factory_trans_cb (const gchar *path,
|
|
||||||
gpointer data);
|
|
||||||
static void init_tray_icon (DrWright *dr);
|
static void init_tray_icon (DrWright *dr);
|
||||||
static GList * create_secondary_break_windows (void);
|
static GList * create_secondary_break_windows (void);
|
||||||
|
|
||||||
|
static const GtkActionEntry actions[] = {
|
||||||
|
{"Preferences", GTK_STOCK_PREFERENCES, NULL, NULL, NULL, G_CALLBACK (popup_preferences_cb)},
|
||||||
#define GIF_CB(x) ((GtkItemFactoryCallback)(x))
|
{"About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK (popup_about_cb)},
|
||||||
|
{"TakeABreak", NULL, N_("_Take a Break"), NULL, NULL, G_CALLBACK (popup_break_cb)}
|
||||||
static GtkItemFactoryEntry popup_items[] = {
|
|
||||||
/* { N_("/_Enabled"), NULL, GIF_CB (popup_enabled_cb), POPUP_ITEM_ENABLED, "<ToggleItem>", NULL },*/
|
|
||||||
/* translators: keep the initial "/" */
|
|
||||||
{ N_("/_Preferences"), NULL, GIF_CB (popup_preferences_cb), 0, "<StockItem>", GTK_STOCK_PREFERENCES },
|
|
||||||
{ N_("/_About"), NULL, GIF_CB (popup_about_cb), 0, "<StockItem>", GTK_STOCK_ABOUT },
|
|
||||||
{ "/sep1", NULL, NULL, 0, "<Separator>", NULL },
|
|
||||||
{ N_("/_Take a Break"), NULL, GIF_CB (popup_break_cb), POPUP_ITEM_BREAK, "<Item>", NULL }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern gboolean debug;
|
extern gboolean debug;
|
||||||
|
@ -536,8 +524,8 @@ gconf_notify_cb (GConfClient *client,
|
||||||
dr->enabled = gconf_value_get_bool (entry->value);
|
dr->enabled = gconf_value_get_bool (entry->value);
|
||||||
dr->state = STATE_START;
|
dr->state = STATE_START;
|
||||||
|
|
||||||
item = gtk_item_factory_get_widget_by_action (dr->popup_factory,
|
item = gtk_ui_manager_get_widget (dr->ui_manager,
|
||||||
POPUP_ITEM_BREAK);
|
"/Pop/TakeABreak");
|
||||||
gtk_widget_set_sensitive (item, dr->enabled);
|
gtk_widget_set_sensitive (item, dr->enabled);
|
||||||
|
|
||||||
update_tooltip (dr);
|
update_tooltip (dr);
|
||||||
|
@ -548,12 +536,8 @@ gconf_notify_cb (GConfClient *client,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
popup_break_cb (gpointer callback_data,
|
popup_break_cb (GtkAction *action, DrWright *dr)
|
||||||
guint action,
|
|
||||||
GtkWidget *widget)
|
|
||||||
{
|
{
|
||||||
DrWright *dr = callback_data;
|
|
||||||
|
|
||||||
if (dr->enabled) {
|
if (dr->enabled) {
|
||||||
dr->state = STATE_BREAK_SETUP;
|
dr->state = STATE_BREAK_SETUP;
|
||||||
maybe_change_state (dr);
|
maybe_change_state (dr);
|
||||||
|
@ -561,14 +545,14 @@ popup_break_cb (gpointer callback_data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
popup_preferences_cb (gpointer callback_data,
|
popup_preferences_cb (GtkAction *action, DrWright *dr)
|
||||||
guint action,
|
|
||||||
GtkWidget *widget)
|
|
||||||
{
|
{
|
||||||
GdkScreen *screen;
|
GdkScreen *screen;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
GtkWidget *menu;
|
||||||
|
|
||||||
screen = gtk_widget_get_screen (widget);
|
menu = gtk_ui_manager_get_widget (dr->ui_manager, "/Pop");
|
||||||
|
screen = gtk_widget_get_screen (menu);
|
||||||
|
|
||||||
if (!gdk_spawn_command_line_on_screen (screen, "gnome-keyboard-properties --typing-break", &error)) {
|
if (!gdk_spawn_command_line_on_screen (screen, "gnome-keyboard-properties --typing-break", &error)) {
|
||||||
GtkWidget *error_dialog;
|
GtkWidget *error_dialog;
|
||||||
|
@ -589,9 +573,7 @@ popup_preferences_cb (gpointer callback_data,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
popup_about_cb (gpointer callback_data,
|
popup_about_cb (GtkAction *action, DrWright *dr)
|
||||||
guint action,
|
|
||||||
GtkWidget *widget)
|
|
||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
gchar *authors[] = {
|
gchar *authors[] = {
|
||||||
|
@ -620,7 +602,7 @@ popup_menu_cb (GtkWidget *widget,
|
||||||
{
|
{
|
||||||
GtkWidget *menu;
|
GtkWidget *menu;
|
||||||
|
|
||||||
menu = gtk_item_factory_get_widget (dr->popup_factory, "");
|
menu = gtk_ui_manager_get_widget (dr->ui_manager, "/Pop");
|
||||||
|
|
||||||
gtk_menu_popup (GTK_MENU (menu),
|
gtk_menu_popup (GTK_MENU (menu),
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -686,13 +668,6 @@ break_window_destroy_cb (GtkWidget *window,
|
||||||
dr->secondary_break_windows = NULL;
|
dr->secondary_break_windows = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
item_factory_trans_cb (const gchar *path,
|
|
||||||
gpointer data)
|
|
||||||
{
|
|
||||||
return _((gchar*) path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_tray_icon (DrWright *dr)
|
init_tray_icon (DrWright *dr)
|
||||||
{
|
{
|
||||||
|
@ -751,6 +726,17 @@ drwright_new (void)
|
||||||
DrWright *dr;
|
DrWright *dr;
|
||||||
GtkWidget *item;
|
GtkWidget *item;
|
||||||
GConfClient *client;
|
GConfClient *client;
|
||||||
|
GtkActionGroup *action_group;
|
||||||
|
|
||||||
|
const char ui_description[] =
|
||||||
|
"<ui>"
|
||||||
|
" <popup name='Pop'>"
|
||||||
|
" <menuitem action='Preferences'/>"
|
||||||
|
" <menuitem action='About'/>"
|
||||||
|
" <separator/>"
|
||||||
|
" <menuitem action='TakeABreak'/>"
|
||||||
|
" </popup>"
|
||||||
|
"</ui>";
|
||||||
|
|
||||||
dr = g_new0 (DrWright, 1);
|
dr = g_new0 (DrWright, 1);
|
||||||
|
|
||||||
|
@ -786,23 +772,15 @@ drwright_new (void)
|
||||||
setup_debug_values (dr);
|
setup_debug_values (dr);
|
||||||
}
|
}
|
||||||
|
|
||||||
dr->popup_factory = gtk_item_factory_new (GTK_TYPE_MENU,
|
dr->ui_manager = gtk_ui_manager_new ();
|
||||||
"<main>",
|
|
||||||
NULL);
|
|
||||||
gtk_item_factory_set_translate_func (dr->popup_factory,
|
|
||||||
item_factory_trans_cb,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
gtk_item_factory_create_items (dr->popup_factory,
|
action_group = gtk_action_group_new ("MenuActions");
|
||||||
G_N_ELEMENTS (popup_items),
|
gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
|
||||||
popup_items,
|
gtk_action_group_add_actions (action_group, actions, G_N_ELEMENTS (actions), dr);
|
||||||
dr);
|
gtk_ui_manager_insert_action_group (dr->ui_manager, action_group, 0);
|
||||||
|
gtk_ui_manager_add_ui_from_string (dr->ui_manager, ui_description, -1, NULL);
|
||||||
|
|
||||||
/*item = gtk_item_factory_get_widget_by_action (dr->popup_factory, POPUP_ITEM_ENABLED);
|
item = gtk_ui_manager_get_widget (dr->ui_manager, "/Pop/TakeABreak");
|
||||||
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), dr->enabled);*/
|
|
||||||
|
|
||||||
item = gtk_item_factory_get_widget_by_action (dr->popup_factory, POPUP_ITEM_BREAK);
|
|
||||||
gtk_widget_set_sensitive (item, dr->enabled);
|
gtk_widget_set_sensitive (item, dr->enabled);
|
||||||
|
|
||||||
dr->timer = g_timer_new ();
|
dr->timer = g_timer_new ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue