changed sock_read() in some files to sock_gets().
[claws.git] / src / menu.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include <glib.h>
25 #include <gtk/gtkwidget.h>
26 #include <gtk/gtkmenu.h>
27 #include <gtk/gtkmenubar.h>
28 #include <gtk/gtkitemfactory.h>
29
30 #include "intl.h"
31 #include "menu.h"
32
33 static gchar *menu_translate(const gchar *path, gpointer data);
34
35 GtkWidget *menubar_create(GtkWidget *window, GtkItemFactoryEntry *entries,
36                           guint n_entries, const gchar *path, gpointer data)
37 {
38         GtkItemFactory *factory;
39         GtkAccelGroup *accel_group;
40
41         accel_group = gtk_accel_group_new();
42         factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, path, accel_group);
43         gtk_item_factory_set_translate_func(factory, menu_translate,
44                                             NULL, NULL);
45         gtk_item_factory_create_items(factory, n_entries, entries, data);
46         gtk_accel_group_attach(accel_group, GTK_OBJECT(window));
47
48         return gtk_item_factory_get_widget(factory, path);
49 }
50
51 GtkWidget *menu_create_items(GtkItemFactoryEntry *entries,
52                              guint n_entries, const gchar *path,
53                              GtkItemFactory **factory, gpointer data)
54 {
55         *factory = gtk_item_factory_new(GTK_TYPE_MENU, path, NULL);
56         gtk_item_factory_set_translate_func(*factory, menu_translate,
57                                             NULL, NULL);
58         gtk_item_factory_create_items(*factory, n_entries, entries, data);
59
60         return gtk_item_factory_get_widget(*factory, path);
61 }
62
63 static gchar *menu_translate(const gchar *path, gpointer data)
64 {
65         gchar *retval;
66
67         retval = gettext(path);
68
69         return retval;
70 }
71
72 void menu_set_sensitive(GtkItemFactory *ifactory, const gchar *path,
73                         gboolean sensitive)
74 {
75         GtkWidget *widget;
76
77         g_return_if_fail(ifactory != NULL);
78
79         widget = gtk_item_factory_get_item(ifactory, path);
80         gtk_widget_set_sensitive(widget, sensitive);
81 }
82
83 void menu_set_insensitive_all(GtkMenuShell *menu_shell)
84 {
85         GList *cur;
86
87         for (cur = menu_shell->children; cur != NULL; cur = cur->next)
88                 gtk_widget_set_sensitive(GTK_WIDGET(cur->data), FALSE);
89 }