aboutsummaryrefslogtreecommitdiff
path: root/hardinfo2/shell/menu.c
blob: 6b96e271fc1588cf04e2f609cbbdcb0fdd8a4984 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
 * HardInfo
 * Copyright(C) 2003-2007 Leandro A. F. Pereira.
 *
 * menu.c is based on UI Manager tutorial by Ryan McDougall
 * Copyright(C) 2005 Ryan McDougall.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <gtk/gtk.h>
#include <menu.h>
#include <config.h>

#include <stock.h>

#include <callbacks.h>
#include <hardinfo.h>

#include "uidefs.h"

static GtkActionEntry entries[] = {
    {"InformationMenuAction", NULL, "_Information"},	/* name, stock id, label */
    {"RemoteMenuAction", NULL, "_Remote"},
    {"ViewMenuAction", NULL, "_View"},
    {"HelpMenuAction", NULL, "_Help"},
    {"HelpMenuModulesAction", HI_STOCK_ABOUT_MODULES, "About _Modules"},
    {"MainMenuBarAction", NULL, ""},

    {"ReportAction", HI_STOCK_REPORT,	/* name, stock id */
     "Generate _Report", "<control>R",	/* label, accelerator */
     NULL,			/* tooltip */
     G_CALLBACK(cb_generate_report)},

    {"SyncManagerAction", HI_STOCK_SYNC_MENU,
     "_Network Updater...", NULL,
     NULL,
     G_CALLBACK(cb_sync_manager)},

    {"OpenAction", GTK_STOCK_OPEN,
     "_Open...", NULL,
     NULL,
     G_CALLBACK(cb_sync_manager)},
     
    {"ConnectToAction", GTK_STOCK_CONNECT,
     "_Connect to...", NULL,
     NULL,
     G_CALLBACK(cb_connect_to)},

    {"ManageAction", NULL,
     "_Manage hosts...", NULL,
     NULL,
     G_CALLBACK(cb_manage_hosts)},
    
    {"LocalComputerAction", GTK_STOCK_HOME,
     "_Local computer", NULL,
     NULL,
     G_CALLBACK(cb_local_computer)},

    {"CopyAction", GTK_STOCK_COPY,
     "_Copy to Clipboard", "<control>C",
     "Copy to clipboard",
     G_CALLBACK(cb_copy_to_clipboard)},

    {"SaveGraphAction", GTK_STOCK_SAVE_AS,
     "_Save image as...", "<control>S",
     NULL,
     G_CALLBACK(cb_save_graphic)},

    {"RefreshAction", GTK_STOCK_REFRESH,
     "_Refresh", "F5",
     NULL,
     G_CALLBACK(cb_refresh)},

    {"OnlineDocsAction", GTK_STOCK_HELP,
     "Contents", "F1",
     NULL,
     G_CALLBACK(cb_open_online_docs)},

    {"ContextHelpAction", NULL,
     "Context help", "<Ctrl>F1",
     NULL,
     G_CALLBACK(cb_open_online_docs_context)},

    {"HomePageAction", HI_STOCK_INTERNET,
     "_Open HardInfo Web Site", NULL,
     NULL,
     G_CALLBACK(cb_open_web_page)},

    {"ReportBugAction", HI_STOCK_INTERNET,
     "_Report bug", NULL,
     NULL,
     G_CALLBACK(cb_report_bug)},

    {"DonateAction", HI_STOCK_DONATE,
     "_Donate to the project", NULL,
     NULL,
     G_CALLBACK(cb_donate)},

    {"AboutAction", GTK_STOCK_ABOUT,
     "_About HardInfo", NULL,
     "Displays program version information",
     G_CALLBACK(cb_about)},

    {"QuitAction", GTK_STOCK_QUIT,
     "_Quit", "<control>Q",
     NULL,
     G_CALLBACK(cb_quit)}
};

static GtkToggleActionEntry toggle_entries[] = {
    {"SidePaneAction", NULL,
     "_Side Pane", NULL,
     "Toggles side pane visibility",
     G_CALLBACK(cb_side_pane)},
    {"ToolbarAction", NULL,
     "_Toolbar", NULL,
     NULL,
     G_CALLBACK(cb_toolbar)},
    {"ActAsServerAction", NULL,
      "_Accept connections", NULL,
      NULL,
      G_CALLBACK(cb_act_as_server) }
};

/* Implement a handler for GtkUIManager's "add_widget" signal. The UI manager
 * will emit this signal whenever it needs you to place a new widget it has. */
static void
menu_add_widget(GtkUIManager * ui, GtkWidget * widget,
		GtkContainer * container)
{
    gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0);
    gtk_widget_show(widget);
}

void menu_init(Shell * shell)
{
    GtkWidget *menu_box;	/* Packing box for the menu and toolbars */
    GtkActionGroup *action_group;	/* Packing group for our Actions */
    GtkUIManager *menu_manager;	/* The magic widget! */
    GError *error;		/* For reporting exceptions or errors */
    GtkAccelGroup *accel_group;

    /* Create our objects */
    menu_box = shell->vbox;
    action_group = gtk_action_group_new("HardInfo");
    menu_manager = gtk_ui_manager_new();

    shell->action_group = action_group;
    shell->ui_manager = menu_manager;

    /* Pack up our objects:
     * menu_box -> window
     * actions -> action_group
     * action_group -> menu_manager */
    gtk_action_group_add_actions(action_group, entries,
				 G_N_ELEMENTS(entries), NULL);
    gtk_action_group_add_toggle_actions(action_group, toggle_entries,
					G_N_ELEMENTS(toggle_entries),
					NULL);
    gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);

    /* Read in the UI from our XML file */
    error = NULL;
    gtk_ui_manager_add_ui_from_string(menu_manager, uidefs_str, -1,
				      &error);

    if (error) {
	g_error("Building menus failed: %s", error->message);
	g_error_free(error);
	return;
    }

    /* Enable menu accelerators */
    accel_group = gtk_ui_manager_get_accel_group(menu_manager);
    gtk_window_add_accel_group(GTK_WINDOW(shell->window), accel_group);

    /* Connect up important signals */
    /* This signal is necessary in order to place widgets from the UI manager
     * into the menu_box */
    g_signal_connect(menu_manager, "add_widget",
		     G_CALLBACK(menu_add_widget), menu_box);

    /* Show the window and run the main loop, we're done! */
    gtk_widget_show(menu_box);

    gtk_toolbar_set_style(GTK_TOOLBAR
			  (gtk_ui_manager_get_widget
			   (shell->ui_manager, "/MainMenuBarAction")),
			  GTK_TOOLBAR_BOTH_HORIZ);
}