2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2013 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "claws-features.h"
26 #include <glib/gi18n.h>
34 GtkActionGroup
*cm_menu_create_action_group(const gchar
*name
, GtkActionEntry
*entries
,
35 gint num_entries
, gpointer data
)
37 GtkActionGroup
*group
= gtk_action_group_new(name
);
38 gtk_action_group_set_translate_func(group
, menu_translate
, NULL
, NULL
);
39 gtk_action_group_add_actions(group
, entries
, num_entries
, data
);
40 gtk_ui_manager_insert_action_group(gtkut_ui_manager(), group
, 0);
44 GtkActionGroup
*cm_menu_create_action_group_full(GtkUIManager
*manager
, const gchar
*name
, GtkActionEntry
*entries
,
45 gint num_entries
, gpointer data
)
47 GtkActionGroup
*group
= gtk_action_group_new(name
);
48 gtk_action_group_set_translate_func(group
, menu_translate
, NULL
, NULL
);
49 gtk_action_group_add_actions(group
, entries
, num_entries
, data
);
50 gtk_ui_manager_insert_action_group(manager
, group
, 0);
54 gchar
*menu_translate(const gchar
*path
, gpointer data
)
58 retval
= gettext(path
);
63 void cm_menu_set_sensitive(gchar
*menu
, gboolean sensitive
)
65 GtkUIManager
*gui_manager
= gtkut_ui_manager();
66 gchar
*path
= g_strdup_printf("Menus/%s", menu
);
68 cm_menu_set_sensitive_full(gui_manager
, path
, sensitive
);
72 void cm_toggle_menu_set_active(gchar
*menu
, gboolean active
)
74 GtkUIManager
*gui_manager
= gtkut_ui_manager();
75 gchar
*path
= g_strdup_printf("Menus/%s", menu
);
77 cm_toggle_menu_set_active_full(gui_manager
, path
, active
);
81 void cm_menu_set_sensitive_full(GtkUIManager
*gui_manager
, const gchar
*menu
, gboolean sensitive
)
84 gchar
*path
= g_strdup_printf("/%s/", menu
);
86 widget
= gtk_ui_manager_get_widget(gui_manager
, path
);
87 if( !GTK_IS_WIDGET(widget
) ) {
88 g_message("Blah, '%s' is not a widget.\n", path
);
91 if( !GTK_IS_MENU_ITEM(widget
) ) {
92 g_message("Blah, '%s' is not a menu item.\n", path
);
95 gtk_widget_set_sensitive(widget
, sensitive
);
97 if (strcmp(menu
, "Menus/SummaryViewPopup/Reedit") == 0)
98 (sensitive
)? gtk_widget_show(widget
) : gtk_widget_hide(widget
);
103 gchar
*cm_menu_item_get_shortcut(GtkUIManager
*gui_manager
, gchar
*menu
)
106 gchar
*path
= g_strdup_printf("/%s/", menu
);
107 const gchar
*accel
= NULL
;
110 widget
= gtk_ui_manager_get_widget(gui_manager
, path
);
111 if( !GTK_IS_WIDGET(widget
) ) {
112 g_message("Blah, '%s' is not a widget.\n", path
);
115 if( !GTK_IS_MENU_ITEM(widget
) ) {
116 g_message("Blah, '%s' is not a menu item.\n", path
);
121 accel
= gtk_menu_item_get_accel_path(GTK_MENU_ITEM(widget
));
123 if (accel
&& gtk_accel_map_lookup_entry(accel
, &key
))
124 return gtk_accelerator_get_label (key
.accel_key
, key
.accel_mods
);
126 return g_strdup(_("None"));
130 GtkWidget
*cm_menu_item_new_label_from_url(gchar
*url
)
132 gint len
= strlen(url
);
133 if (len
> MAX_MENU_LABEL_LENGTH
) {
134 g_message("Refusing a %d bytes string as menu label\n", len
);
135 url
[64] = '\0', url
[63] = url
[62] = url
[61] = '.', url
[60] = ' ';
136 GtkWidget
*newlabel
= gtk_menu_item_new_with_label(url
);
137 gtk_widget_set_tooltip_markup(GTK_WIDGET(newlabel
),
138 g_strconcat("<span><b>", _("Warning:"), "</b>",
139 _("This URL was too long for displaying and\n"
140 "has been truncated for safety. This message could be\n"
141 "corrupted, malformed or part of some DoS attempt."),
146 return gtk_menu_item_new_with_label(url
);
149 void cm_toggle_menu_set_active_full(GtkUIManager
*gui_manager
, gchar
*menu
, gboolean active
)
152 gchar
*path
= g_strdup_printf("/%s/", menu
);
154 widget
= gtk_ui_manager_get_widget(gui_manager
, path
);
155 if( !GTK_IS_WIDGET(widget
) ) {
156 g_message("Blah, '%s' is not a widget.\n", path
);
159 if( !GTK_CHECK_MENU_ITEM(widget
) ) {
160 g_message("Blah, '%s' is not a check menu item.\n", path
);
163 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget
), active
);
167 void menu_set_sensitive_all(GtkMenuShell
*menu_shell
, gboolean sensitive
)
169 GList
*children
= gtk_container_get_children(GTK_CONTAINER(menu_shell
));
172 for (cur
= children
; cur
!= NULL
; cur
= cur
->next
)
173 gtk_widget_set_sensitive(GTK_WIDGET(cur
->data
), sensitive
);
175 g_list_free(children
);