/
sidebar.vala
706 lines (563 loc) · 23.5 KB
/
sidebar.vala
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*
* This file is part of Haguichi, a graphical frontend for Hamachi.
* Copyright (C) 2007-2017 Stephen Brandt <stephen@stephenbrandt.com>
*
* Haguichi 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 3 of the License,
* or (at your option) any later version.
*/
using Gtk;
public class Sidebar : Box
{
private string current_tab;
private Member member;
private Network network;
private Label heading_label;
private Box heading_box;
private Box commands_box;
private Box info_box;
private Box network_box;
private Box member_box;
private ButtonBox info_button_box;
private ButtonBox network_button_box;
private ButtonBox member_button_box;
private ButtonBox approval_box;
private SidebarLabel version_label;
private SidebarLabel ipv4_label;
private SidebarLabel ipv6_label;
private SidebarLabel id_label;
private SidebarLabel account_label;
private SidebarLabel nick_label;
private SidebarEntry version_entry;
private SidebarEntry ipv4_entry;
private SidebarEntry ipv6_entry;
private SidebarEntry id_entry;
private SidebarEntry account_entry;
private SidebarEntry nick_entry;
private Button attach_button;
private SidebarLabel network_status_label;
private SidebarLabel network_id_label;
private SidebarLabel network_members_label;
private SidebarLabel network_owner_label;
private SidebarLabel network_capacity_label;
private SidebarLabel network_lock_label;
private SidebarLabel network_approval_label;
private SidebarEntry network_status_entry;
private SidebarEntry network_id_entry;
private SidebarEntry network_members_entry;
private SidebarEntry network_owner_entry;
private SidebarEntry network_capacity_entry;
private CheckButton network_lock_check;
private ComboBox network_approval_combo;
private Button network_password_button;
private Button delete_button;
private Button leave_button;
private Button online_button;
private Button offline_button;
private SidebarLabel member_status_label;
private SidebarLabel member_id_label;
private SidebarLabel member_ipv4_label;
private SidebarLabel member_ipv6_label;
private SidebarLabel member_tunnel_label;
private SidebarLabel member_connection_label;
private SidebarEntry member_status_entry;
private SidebarEntry member_id_entry;
private SidebarEntry member_ipv4_entry;
private SidebarEntry member_ipv6_entry;
private SidebarEntry member_tunnel_entry;
private SidebarEntry member_connection_entry;
private Button approve_button;
private Button reject_button;
private Button evict_button;
public Sidebar ()
{
heading_label = new Label(null);
heading_label.ellipsize = Pango.EllipsizeMode.END;
heading_box = new Box (Orientation.HORIZONTAL, 0);
heading_box.halign = Align.CENTER;
heading_box.margin_top = 15;
heading_box.margin_bottom = 18;
heading_box.pack_start (heading_label, false, false, 0);
version_label = new SidebarLabel ("Hamachi");
version_entry = new SidebarEntry();
ipv4_label = new SidebarLabel (Text.address_ipv4);
ipv4_entry = new SidebarEntry();
ipv6_label = new SidebarLabel (Text.address_ipv6);
ipv6_entry = new SidebarEntry();
id_label = new SidebarLabel (Text.client_id);
id_entry = new SidebarEntry();
account_label = new SidebarLabel (Text.account);
account_entry = new SidebarEntry();
nick_label = new SidebarLabel (Text.nick);
nick_entry = new SidebarEntry();
Grid info_grid = new Grid();
info_grid.row_spacing = 9;
info_grid.column_spacing = 9;
info_grid.halign = Align.CENTER;
info_grid.attach (version_label, 0, 1, 1, 1);
info_grid.attach (version_entry, 1, 1, 1, 1);
info_grid.attach (id_label, 0, 2, 1, 1);
info_grid.attach (id_entry, 1, 2, 1, 1);
info_grid.attach (account_label, 0, 3, 1, 1);
info_grid.attach (account_entry, 1, 3, 1, 1);
info_grid.attach (nick_label, 0, 4, 1, 1);
info_grid.attach (nick_entry, 1, 4, 1, 1);
info_grid.attach (ipv4_label, 0, 5, 1, 1);
info_grid.attach (ipv4_entry, 1, 5, 1, 1);
info_grid.attach (ipv6_label, 0, 6, 1, 1);
info_grid.attach (ipv6_entry, 1, 6, 1, 1);
attach_button = new Button.with_mnemonic (Text.attach_label);
attach_button.clicked.connect (GlobalEvents.attach);
info_button_box = new ButtonBox (Orientation.HORIZONTAL);
info_button_box.spacing = 6;
info_button_box.valign = Align.END;
info_button_box.margin_top = 18;
info_button_box.add (attach_button);
info_box = new Box (Orientation.VERTICAL, 0);
info_box.pack_start (info_grid, false, false, 0);
info_box.pack_start (info_button_box, true, true, 0);
network_status_label = new SidebarLabel (Text.status);
network_status_entry = new SidebarEntry();
network_id_label = new SidebarLabel (Text.network_id);
network_id_entry = new SidebarEntry();
network_members_label = new SidebarLabel (Text.members);
network_members_entry = new SidebarEntry();
network_owner_label = new SidebarLabel (Text.owner);
network_owner_entry = new SidebarEntry();
network_capacity_label = new SidebarLabel (Text.capacity);
network_capacity_entry = new SidebarEntry();
network_lock_label = new SidebarLabel (Text.locked);
network_lock_check = new CheckButton();
network_lock_check.halign = Align.START;
network_approval_label = new SidebarLabel (Text.approval);
CellRendererCombo cell = new CellRendererCombo();
cell.ellipsize = Pango.EllipsizeMode.END;
Gtk.ListStore store = new Gtk.ListStore (1, typeof (string));
TreeIter iter;
store.append (out iter);
store.set (iter, 0, Text.automatically, -1);
store.append (out iter);
store.set (iter, 0, Text.manually, -1);
network_approval_combo = new ComboBox();
network_approval_combo.halign = Align.START;
network_approval_combo.margin_start = 1;
network_approval_combo.pack_start (cell, false);
network_approval_combo.add_attribute (cell, "text", 0);
network_approval_combo.model = store;
network_password_button = new Button.with_mnemonic (Text.change_password_label);
network_password_button.halign = Align.CENTER;
network_password_button.margin_top = 24;
network_password_button.margin_bottom = 6;
network_password_button.clicked.connect (() =>
{
network.change_password();
});
Grid network_grid = new Grid();
network_grid.row_spacing = 9;
network_grid.column_spacing = 9;
network_grid.halign = Align.CENTER;
network_grid.attach (network_status_label, 0, 1, 1, 1);
network_grid.attach (network_status_entry, 1, 1, 1, 1);
network_grid.attach (network_id_label, 0, 2, 1, 1);
network_grid.attach (network_id_entry, 1, 2, 1, 1);
network_grid.attach (network_members_label, 0, 3, 1, 1);
network_grid.attach (network_members_entry, 1, 3, 1, 1);
network_grid.attach (network_owner_label, 0, 4, 1, 1);
network_grid.attach (network_owner_entry, 1, 4, 1, 1);
network_grid.attach (network_capacity_label, 0, 5, 1, 1);
network_grid.attach (network_capacity_entry, 1, 5, 1, 1);
network_grid.attach (network_lock_label, 0, 6, 1, 1);
network_grid.attach (network_lock_check, 1, 6, 1, 1);
network_grid.attach (network_approval_label, 0, 7, 1, 1);
network_grid.attach (network_approval_combo, 1, 7, 1, 1);
delete_button = new Button.with_mnemonic (Text.delete_label);
delete_button.clicked.connect (() =>
{
network.delete();
});
leave_button = new Button.with_mnemonic (Text.leave_label);
leave_button.clicked.connect (() =>
{
network.leave();
});
online_button = new Button.with_mnemonic (Text.go_online_label);
online_button.get_style_context().add_class ("suggested-action");
online_button.clicked.connect (() =>
{
network.go_online();
});
offline_button = new Button.with_mnemonic (Text.go_offline_label);
offline_button.clicked.connect (() =>
{
network.go_offline();
});
network_button_box = new ButtonBox (Orientation.HORIZONTAL);
network_button_box.spacing = 6;
network_button_box.valign = Align.END;
network_button_box.margin_top = 18;
network_button_box.set_layout (ButtonBoxStyle.EDGE);
network_button_box.add (online_button);
network_button_box.add (offline_button);
network_button_box.add (delete_button);
network_button_box.add (leave_button);
network_box = new Box (Orientation.VERTICAL, 0);
network_box.vexpand = true;
network_box.pack_start (network_grid, false, false, 0);
network_box.pack_start (network_password_button, false, false, 0);
network_box.pack_start (network_button_box, true, true, 0);
member_status_label = new SidebarLabel (Text.status);
member_status_entry = new SidebarEntry();
member_id_label = new SidebarLabel (Text.client_id);
member_id_entry = new SidebarEntry();
member_ipv4_label = new SidebarLabel (Text.address_ipv4);
member_ipv4_entry = new SidebarEntry();
member_ipv6_label = new SidebarLabel (Text.address_ipv6);
member_ipv6_entry = new SidebarEntry();
member_tunnel_label = new SidebarLabel (Text.tunnel);
member_tunnel_entry = new SidebarEntry();
member_connection_label = new SidebarLabel (Text.connection);
member_connection_entry = new SidebarEntry();
Grid member_grid = new Grid();
member_grid.row_spacing = 9;
member_grid.column_spacing = 9;
member_grid.halign = Align.CENTER;
member_grid.attach (member_status_label, 0, 1, 1, 1);
member_grid.attach (member_status_entry, 1, 1, 1, 1);
member_grid.attach (member_id_label, 0, 2, 1, 1);
member_grid.attach (member_id_entry, 1, 2, 1, 1);
member_grid.attach (member_ipv4_label, 0, 3, 1, 1);
member_grid.attach (member_ipv4_entry, 1, 3, 1, 1);
member_grid.attach (member_ipv6_label, 0, 4, 1, 1);
member_grid.attach (member_ipv6_entry, 1, 4, 1, 1);
member_grid.attach (member_tunnel_label, 0, 5, 1, 1);
member_grid.attach (member_tunnel_entry, 1, 5, 1, 1);
member_grid.attach (member_connection_label, 0, 6, 1, 1);
member_grid.attach (member_connection_entry, 1, 6, 1, 1);
commands_box = new Box (Orientation.VERTICAL, 6);
commands_box.margin_top = 18;
commands_box.margin_bottom = 24;
approve_button = new Button.with_mnemonic (Text.approve_label);
approve_button.clicked.connect (() =>
{
member.approve();
});
reject_button = new Button.with_mnemonic (Text.reject_label);
reject_button.clicked.connect (() =>
{
member.reject();
});
approval_box = new ButtonBox (Orientation.HORIZONTAL);
approval_box.spacing = 6;
approval_box.valign = Align.END;
approval_box.margin_top = 18;
approval_box.set_layout (ButtonBoxStyle.EDGE);
approval_box.add (approve_button);
approval_box.add (reject_button);
evict_button = new Button.with_mnemonic (Text.evict_label);
evict_button.clicked.connect (() =>
{
member.evict();
});
member_button_box = new ButtonBox (Orientation.HORIZONTAL);
member_button_box.spacing = 6;
member_button_box.valign = Align.END;
member_button_box.set_layout (ButtonBoxStyle.EDGE);
member_button_box.add (evict_button);
member_box = new Box (Orientation.VERTICAL, 0);
member_box.pack_start (member_grid, false, false, 0);
member_box.pack_start (commands_box, false, false, 0);
member_box.pack_start (approval_box, true, true, 0);
member_box.pack_start (member_button_box, true, true, 0);
pack_start (heading_box, false, false, 0);
pack_start (info_box, true, true, 0);
pack_start (network_box, true, true, 0);
pack_start (member_box, true, true, 0);
orientation = Orientation.VERTICAL;
margin = 12;
no_show_all = true;
heading_box.show_all();
info_box.show_all();
show_tab ("Info");
generate_command_buttons();
}
private void network_lock_changed ()
{
if (network_lock_check.active)
{
network.set_lock ("locked");
}
else
{
network.set_lock ("unlocked");
}
}
private void network_approval_changed ()
{
if (network_approval_combo.active == 1)
{
network.set_approval ("manual");
}
else
{
network.set_approval ("auto");
}
}
public void update ()
{
set_version();
set_address();
set_client_id();
}
public void generate_command_buttons ()
{
string[] commands = (string[]) Settings.custom_commands.val;
foreach (Widget cb in commands_box.get_children())
{
cb.destroy();
}
foreach (string c in commands)
{
string[] cArray = c.split (";", 6);
if ((cArray.length == 6) &&
(cArray[0] == "true"))
{
string label = cArray[2];
string command_ipv4 = cArray[3];
string command_ipv6 = cArray[4];
string priority = cArray[5];
if (Command.custom_exists (command_ipv4, command_ipv6))
{
CommandButton cb = new CommandButton (label, command_ipv4, command_ipv6, priority);
commands_box.pack_start (cb, false, false, 3);
}
}
}
}
private void set_version ()
{
string version = Hamachi.version;
if (version == null)
{
version = "<i>" + Text.unavailable + "</i>";
}
version_entry.set_markup (version);
}
private void set_address ()
{
string[] address = Hamachi.get_address();
string ipv4 = address[0];
string ipv6 = address[1];
if ((ipv4 == null) ||
(ipv4 == ""))
{
ipv4_label.hide();
ipv4_entry.hide();
}
else
{
ipv4_entry.set_text (ipv4);
ipv4_label.show();
ipv4_entry.show();
}
if (ipv6 == null)
{
ipv6_label.hide();
ipv6_entry.hide();
}
else
{
ipv6_entry.set_text (ipv6);
ipv6_label.show();
ipv6_entry.show();
}
}
private void set_client_id ()
{
string id = Hamachi.get_client_id();
if (id == "")
{
id_label.hide();
id_entry.hide();
}
else
{
id_entry.set_text (id);
id_label.show();
id_entry.show();
}
}
public void set_account (string? account)
{
if ((account == "") ||
(account == "-"))
{
account_label.hide();
account_entry.hide();
}
else
{
account_entry.set_text (account);
account_label.show();
account_entry.show();
}
}
public void set_nick (string _nick)
{
string nick = Markup.escape_text (_nick);
if (nick == "")
{
nick = "<i>" + Text.anonymous + "</i>";
}
nick_entry.set_markup (nick);
}
public void set_attach (bool visible, bool sensitive)
{
attach_button.visible = visible;
attach_button.sensitive = sensitive;
}
public void set_member (Member? _member)
{
member = _member;
}
public void set_network (Network _network)
{
network = _network;
}
public void refresh_tab ()
{
show_tab (current_tab);
}
public void show_tab (string tab)
{
current_tab = tab;
info_box.hide();
network_box.hide();
member_box.hide();
switch (current_tab)
{
case "Info":
info_box.show();
heading_label.set_markup ("<span size=\"large\"><b>" + Text.information_title + "</b></span>");
heading_label.selectable = false;
break;
case "Network":
if (!Haguichi.connection.has_network (network))
{
show_tab ("Info");
return;
}
network_box.show_all();
int member_count, member_online_count;
network.return_member_count (out member_count, out member_online_count);
network_status_entry.set_text (network.status.status_text);
network_id_entry.set_text (network.id);
network_members_entry.set_text (Utils.format (Text.member_count, member_online_count.to_string(), member_count.to_string(), null));
network_owner_entry.set_text (Markup.escape_text (network.return_owner_string()));
network_capacity_entry.set_text (network.capacity.to_string());
if (network.status.status_int == 1)
{
online_button.hide();
}
else
{
offline_button.hide();
}
if (network.capacity == 0)
{
network_capacity_label.hide();
network_capacity_entry.hide();
}
if (network.is_owner == 1)
{
network_lock_check.toggled.disconnect (network_lock_changed);
network_approval_combo.changed.disconnect (network_approval_changed);
if (network.lock_state == "unlocked")
{
network_lock_check.active = false;
}
if (network.lock_state == "locked")
{
network_lock_check.active = true;
}
if (network.approve == "auto")
{
network_approval_combo.active = 0;
}
if (network.approve == "manual")
{
network_approval_combo.active = 1;
}
network_lock_check.toggled.connect (network_lock_changed);
network_approval_combo.changed.connect (network_approval_changed);
leave_button.hide();
}
else
{
network_approval_label.hide();
network_approval_combo.hide();
network_lock_label.hide();
network_lock_check.hide();
network_password_button.hide();
delete_button.hide();
}
heading_label.set_markup ("<span size=\"large\"><b>" + Markup.escape_text (network.name) + "</b></span>");
heading_label.selectable = true;
break;
case "Member":
member_box.show_all();
member_status_entry.set_text (member.status.status_text);
member_id_entry.set_text (member.client_id);
member_ipv4_entry.set_text (member.ipv4);
member_ipv6_entry.set_text (member.ipv6);
member_tunnel_entry.set_text (member.tunnel);
member_connection_entry.set_text (member.status.connection_type);
if (member.ipv4 == null)
{
member_ipv4_label.hide();
member_ipv4_entry.hide();
}
if (member.ipv6 == null)
{
member_ipv6_label.hide();
member_ipv6_entry.hide();
}
if (member.tunnel == null)
{
member_tunnel_label.hide();
member_tunnel_entry.hide();
}
if (member.status.connection_type == "")
{
member_connection_label.hide();
member_connection_entry.hide();
}
heading_label.set_markup ("<span size=\"large\"><b>" + Markup.escape_text (member.nick) + "</b></span>");
heading_label.selectable = true;
if (member.status.status_int != 3)
{
approval_box.hide();
commands_box.show_all();
foreach (Widget cb in commands_box.get_children())
{
cb.sensitive = true;
if (member.status.status_int != 1)
{
cb.sensitive = false;
}
}
}
else
{
approval_box.show_all();
commands_box.hide();
}
if ((network.is_owner == 0) ||
(member.status.status_int == 3))
{
member_button_box.hide();
}
break;
}
}
}