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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
/*
* transmission-remote-gtk - A GTK RPC client to Transmission
* Copyright (C) 2011 Alan Fitton
* 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; either version 2 of the License, or
* (at your option) any later version.
* 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 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <gtk/gtk.h>
#include "trg-main-window.h"
#include "trg-menu-bar.h"
enum {
PROP_0,
PROP_CONNECT_BUTTON,
PROP_DISCONNECT_BUTTON,
PROP_ADD_BUTTON,
PROP_ADD_URL_BUTTON,
PROP_REMOVE_BUTTON,
PROP_DELETE_BUTTON,
PROP_RESUME_BUTTON,
PROP_PAUSE_BUTTON,
PROP_VERIFY_BUTTON,
PROP_PROPS_BUTTON,
PROP_MOVE_BUTTON,
PROP_REMOTE_PREFS_BUTTON,
PROP_LOCAL_PREFS_BUTTON,
PROP_ABOUT_BUTTON,
PROP_VIEW_STATES_BUTTON,
PROP_VIEW_NOTEBOOK_BUTTON,
PROP_QUIT
};
G_DEFINE_TYPE(TrgMenuBar, trg_menu_bar, GTK_TYPE_MENU_BAR)
#define TRG_MENU_BAR_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), TRG_TYPE_MENU_BAR, TrgMenuBarPrivate))
typedef struct _TrgMenuBarPrivate TrgMenuBarPrivate;
struct _TrgMenuBarPrivate {
GtkWidget *mb_connect;
GtkWidget *mb_disconnect;
GtkWidget *mb_add;
GtkWidget *mb_add_url;
GtkWidget *mb_move;
GtkWidget *mb_remove;
GtkWidget *mb_delete;
GtkWidget *mb_resume;
GtkWidget *mb_pause;
GtkWidget *mb_verify;
GtkWidget *mb_props;
GtkWidget *mb_local_prefs;
GtkWidget *mb_remote_prefs;
GtkWidget *mb_view_states;
GtkWidget *mb_view_notebook;
GtkWidget *mb_about;
GtkWidget *mb_quit;
};
void trg_menu_bar_connected_change(TrgMenuBar * mb, gboolean connected)
{
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(mb);
gtk_widget_set_sensitive(priv->mb_add, connected);
gtk_widget_set_sensitive(priv->mb_add_url, connected);
gtk_widget_set_sensitive(priv->mb_connect, !connected);
gtk_widget_set_sensitive(priv->mb_disconnect, connected);
gtk_widget_set_sensitive(priv->mb_remote_prefs, connected);
}
void trg_menu_bar_torrent_actions_sensitive(TrgMenuBar * mb,
gboolean sensitive)
{
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(mb);
gtk_widget_set_sensitive(priv->mb_props, sensitive);
gtk_widget_set_sensitive(priv->mb_remove, sensitive);
gtk_widget_set_sensitive(priv->mb_delete, sensitive);
gtk_widget_set_sensitive(priv->mb_resume, sensitive);
gtk_widget_set_sensitive(priv->mb_pause, sensitive);
gtk_widget_set_sensitive(priv->mb_verify, sensitive);
gtk_widget_set_sensitive(priv->mb_move, sensitive);
}
static void
trg_menu_bar_get_property(GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(object);
switch (property_id) {
case PROP_CONNECT_BUTTON:
g_value_set_object(value, priv->mb_connect);
break;
case PROP_DISCONNECT_BUTTON:
g_value_set_object(value, priv->mb_disconnect);
break;
case PROP_ADD_BUTTON:
g_value_set_object(value, priv->mb_add);
break;
case PROP_ADD_URL_BUTTON:
g_value_set_object(value, priv->mb_add_url);
break;
case PROP_REMOVE_BUTTON:
g_value_set_object(value, priv->mb_remove);
break;
case PROP_DELETE_BUTTON:
g_value_set_object(value, priv->mb_delete);
break;
case PROP_MOVE_BUTTON:
g_value_set_object(value, priv->mb_move);
break;
case PROP_RESUME_BUTTON:
g_value_set_object(value, priv->mb_resume);
break;
case PROP_PAUSE_BUTTON:
g_value_set_object(value, priv->mb_pause);
break;
case PROP_VERIFY_BUTTON:
g_value_set_object(value, priv->mb_verify);
break;
case PROP_PROPS_BUTTON:
g_value_set_object(value, priv->mb_props);
break;
case PROP_REMOTE_PREFS_BUTTON:
g_value_set_object(value, priv->mb_remote_prefs);
break;
case PROP_LOCAL_PREFS_BUTTON:
g_value_set_object(value, priv->mb_local_prefs);
break;
case PROP_ABOUT_BUTTON:
g_value_set_object(value, priv->mb_about);
break;
case PROP_VIEW_STATES_BUTTON:
g_value_set_object(value, priv->mb_view_states);
break;
case PROP_VIEW_NOTEBOOK_BUTTON:
g_value_set_object(value, priv->mb_view_notebook);
break;
case PROP_QUIT:
g_value_set_object(value, priv->mb_quit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
trg_menu_bar_install_widget_prop(GObjectClass * class, guint propId,
const gchar * name, const gchar * nick)
{
g_object_class_install_property(class,
propId,
g_param_spec_object(name,
nick,
nick,
GTK_TYPE_WIDGET,
G_PARAM_READABLE
|
G_PARAM_STATIC_NAME
|
G_PARAM_STATIC_NICK
|
G_PARAM_STATIC_BLURB));
}
static
GtkWidget *trg_menu_bar_item_new(GtkMenuShell * shell, char *text,
char *stock_id, gboolean sensitive)
{
GtkWidget *item = gtk_image_menu_item_new_with_label(stock_id);
gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(item), TRUE);
gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM
(item), TRUE);
gtk_menu_item_set_label(GTK_MENU_ITEM(item), text);
gtk_widget_set_sensitive(item, sensitive);
gtk_menu_shell_append(shell, item);
return item;
}
static GtkWidget *trg_menu_bar_view_menu_new(TrgMenuBarPrivate * priv)
{
GtkWidget *view = gtk_menu_item_new_with_label("View");
GtkWidget *viewMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(view), viewMenu);
priv->mb_view_states =
gtk_check_menu_item_new_with_label("State selector");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
(priv->mb_view_states), TRUE);
priv->mb_view_notebook =
gtk_check_menu_item_new_with_label("Torrent details");
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM
(priv->mb_view_notebook), TRUE);
gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu), priv->mb_view_states);
gtk_menu_shell_append(GTK_MENU_SHELL(viewMenu),
priv->mb_view_notebook);
return view;
}
static
GtkWidget *trg_menu_bar_options_menu_new(TrgMenuBarPrivate * priv)
{
GtkWidget *opts = gtk_menu_item_new_with_label("Options");
GtkWidget *optsMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(opts), optsMenu);
priv->mb_local_prefs =
trg_menu_bar_item_new(GTK_MENU_SHELL(optsMenu),
"Local Preferences",
GTK_STOCK_PREFERENCES, TRUE);
priv->mb_remote_prefs =
trg_menu_bar_item_new(GTK_MENU_SHELL(optsMenu),
"Remote Preferences",
GTK_STOCK_NETWORK, FALSE);
return opts;
}
static
GtkWidget *trg_menu_bar_file_file_menu_new(TrgMenuBarPrivate * priv)
{
GtkWidget *file = gtk_menu_item_new_with_label("File");
GtkWidget *fileMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), fileMenu);
priv->mb_connect =
trg_menu_bar_item_new(GTK_MENU_SHELL(fileMenu), "Connect",
GTK_STOCK_CONNECT, TRUE);
priv->mb_disconnect =
trg_menu_bar_item_new(GTK_MENU_SHELL(fileMenu), "Disconnect",
GTK_STOCK_DISCONNECT, FALSE);
priv->mb_add =
trg_menu_bar_item_new(GTK_MENU_SHELL(fileMenu), "Add",
GTK_STOCK_ADD, FALSE);
priv->mb_add_url =
trg_menu_bar_item_new(GTK_MENU_SHELL(fileMenu), "Add from URL",
GTK_STOCK_ADD, FALSE);
priv->mb_quit = trg_menu_bar_item_new(GTK_MENU_SHELL(fileMenu), "Quit",
GTK_STOCK_QUIT, TRUE);
return file;
}
static
GtkWidget *trg_menu_bar_torrent_menu_new(TrgMenuBarPrivate * priv)
{
GtkWidget *torrent = gtk_menu_item_new_with_label("Torrent");
GtkWidget *torrentMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(torrent), torrentMenu);
priv->mb_props =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu),
"Properties", GTK_STOCK_PROPERTIES, FALSE);
priv->mb_resume =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Resume",
GTK_STOCK_MEDIA_PLAY, FALSE);
priv->mb_pause =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Pause",
GTK_STOCK_MEDIA_PAUSE, FALSE);
priv->mb_verify =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Verify",
GTK_STOCK_REFRESH, FALSE);
priv->mb_move =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Move",
GTK_STOCK_HARDDISK, FALSE);
priv->mb_remove =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu), "Remove",
GTK_STOCK_REMOVE, FALSE);
priv->mb_delete =
trg_menu_bar_item_new(GTK_MENU_SHELL(torrentMenu),
"Remove and Delete", GTK_STOCK_DELETE,
FALSE);
return torrent;
}
static
GtkWidget *trg_menu_bar_help_menu_new(TrgMenuBar * menuBar)
{
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(menuBar);
GtkWidget *help = gtk_menu_item_new_with_label("Help");
GtkWidget *helpMenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(menuBar), help);
priv->mb_about =
trg_menu_bar_item_new(GTK_MENU_SHELL(helpMenu), "About",
GTK_STOCK_ABOUT, TRUE);
return helpMenu;
}
static void trg_menu_bar_class_init(TrgMenuBarClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->get_property = trg_menu_bar_get_property;
g_type_class_add_private(klass, sizeof(TrgMenuBarPrivate));
trg_menu_bar_install_widget_prop(object_class, PROP_CONNECT_BUTTON,
"connect-button", "Connect Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_DISCONNECT_BUTTON,
"disconnect-button",
"Disconnect Button");
trg_menu_bar_install_widget_prop(object_class, PROP_ADD_BUTTON,
"add-button", "Add Button");
trg_menu_bar_install_widget_prop(object_class, PROP_ADD_URL_BUTTON,
"add-url-button", "Add URL Button");
trg_menu_bar_install_widget_prop(object_class, PROP_REMOVE_BUTTON,
"remove-button", "Remove Button");
trg_menu_bar_install_widget_prop(object_class, PROP_MOVE_BUTTON,
"move-button", "Move Button");
trg_menu_bar_install_widget_prop(object_class, PROP_DELETE_BUTTON,
"delete-button", "Delete Button");
trg_menu_bar_install_widget_prop(object_class, PROP_RESUME_BUTTON,
"resume-button", "Resume Button");
trg_menu_bar_install_widget_prop(object_class, PROP_VERIFY_BUTTON,
"verify-button", "Verify Button");
trg_menu_bar_install_widget_prop(object_class, PROP_PAUSE_BUTTON,
"pause-button", "Pause Button");
trg_menu_bar_install_widget_prop(object_class, PROP_PROPS_BUTTON,
"props-button", "Props Button");
trg_menu_bar_install_widget_prop(object_class, PROP_ABOUT_BUTTON,
"about-button", "About Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_VIEW_STATES_BUTTON,
"view-states-button",
"View states Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_VIEW_NOTEBOOK_BUTTON,
"view-notebook-button",
"View notebook Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_REMOTE_PREFS_BUTTON,
"remote-prefs-button",
"Remote Prefs Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_LOCAL_PREFS_BUTTON,
"local-prefs-button",
"Local Prefs Button");
trg_menu_bar_install_widget_prop(object_class,
PROP_QUIT,
"quit-button", "Quit Button");
}
static void trg_menu_bar_init(TrgMenuBar * self)
{
TrgMenuBarPrivate *priv = TRG_MENU_BAR_GET_PRIVATE(self);
gtk_menu_shell_append(GTK_MENU_SHELL(self),
trg_menu_bar_file_file_menu_new(priv));
gtk_menu_shell_append(GTK_MENU_SHELL(self),
trg_menu_bar_torrent_menu_new(priv));
gtk_menu_shell_append(GTK_MENU_SHELL(self),
trg_menu_bar_options_menu_new(priv));
gtk_menu_shell_append(GTK_MENU_SHELL(self),
trg_menu_bar_view_menu_new(priv));
trg_menu_bar_help_menu_new(TRG_MENU_BAR(self));
}
TrgMenuBar *trg_menu_bar_new(TrgMainWindow * win G_GNUC_UNUSED)
{
GObject *obj = g_object_new(TRG_TYPE_MENU_BAR, NULL);
return TRG_MENU_BAR(obj);
}
|