This repository has been archived by the owner on Oct 24, 2018. It is now read-only.
/
manager_window.vala
2628 lines (2501 loc) · 91.6 KB
/
manager_window.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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* pamac-vala
*
* Copyright (C) 2014-2017 Guillaume Benoit <guillaume@manjaro.org>
*
* 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 get of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const string VERSION = "6.2.4";
namespace Pamac {
class ActivableCellRendererPixbuf : Gtk.CellRendererPixbuf {
public signal void activated (Gtk.TreePath path);
public ActivableCellRendererPixbuf () {
Object ();
this.mode = Gtk.CellRendererMode.ACTIVATABLE;
}
public override bool activate (Gdk.Event event, Gtk.Widget widget, string path, Gdk.Rectangle background_area,
Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
activated (new Gtk.TreePath.from_string (path));
return true;
}
}
[GtkTemplate (ui = "/org/manjaro/pamac/manager/manager_window.ui")]
class ManagerWindow : Gtk.ApplicationWindow {
// icons
Gdk.Pixbuf? installed_icon;
Gdk.Pixbuf? uninstalled_icon;
Gdk.Pixbuf? to_install_icon;
Gdk.Pixbuf? to_reinstall_icon;
Gdk.Pixbuf? to_remove_icon;
Gdk.Pixbuf? to_upgrade_icon;
Gdk.Pixbuf? installed_locked_icon;
Gdk.Pixbuf? available_locked_icon;
Gdk.Pixbuf? package_icon;
// manager objects
[GtkChild]
public Gtk.Stack main_stack;
[GtkChild]
Gtk.Button button_back;
[GtkChild]
Gtk.Button select_all_button;
[GtkChild]
Gtk.Label header_filter_label;
[GtkChild]
Gtk.ModelButton preferences_button;
[GtkChild]
Gtk.TreeView packages_treeview;
[GtkChild]
Gtk.TreeViewColumn packages_state_column;
[GtkChild]
Gtk.TreeView aur_treeview;
[GtkChild]
Gtk.TreeViewColumn aur_state_column;
[GtkChild]
Gtk.Revealer sidebar_revealer;
[GtkChild]
public Gtk.Stack filters_stack;
[GtkChild]
public Gtk.ToggleButton search_button;
[GtkChild]
Gtk.SearchBar searchbar;
[GtkChild]
Gtk.ComboBoxText search_comboboxtext;
[GtkChild]
Gtk.Entry search_entry;
[GtkChild]
Gtk.ListBox filters_listbox;
[GtkChild]
Gtk.ListBox categories_listbox;
[GtkChild]
Gtk.ListBox groups_listbox;
[GtkChild]
Gtk.ListBox installed_listbox;
[GtkChild]
Gtk.ListBox repos_listbox;
[GtkChild]
Gtk.Stack origin_stack;
[GtkChild]
Gtk.ListBox updates_listbox;
[GtkChild]
Gtk.ListBox pending_listbox;
[GtkChild]
Gtk.ListBox search_listbox;
[GtkChild]
Gtk.ScrolledWindow packages_scrolledwindow;
[GtkChild]
Gtk.ScrolledWindow aur_scrolledwindow;
[GtkChild]
Gtk.Label updated_label;
[GtkChild]
Gtk.Label no_item_label;
[GtkChild]
Gtk.Label checking_label;
[GtkChild]
Gtk.Spinner checking_spinner;
[GtkChild]
Gtk.Stack properties_stack;
[GtkChild]
Gtk.ListBox properties_listbox;
[GtkChild]
Gtk.Grid deps_grid;
[GtkChild]
Gtk.Grid details_grid;
[GtkChild]
Gtk.Label name_label;
[GtkChild]
Gtk.Image app_image;
[GtkChild]
Gtk.Image app_screenshot;
[GtkChild]
Gtk.Label desc_label;
[GtkChild]
Gtk.Label long_desc_label;
[GtkChild]
Gtk.Label link_label;
[GtkChild]
Gtk.Label licenses_label;
[GtkChild]
Gtk.ToggleButton remove_togglebutton;
[GtkChild]
Gtk.ToggleButton reinstall_togglebutton;
[GtkChild]
Gtk.ToggleButton install_togglebutton;
[GtkChild]
Gtk.TextView files_textview;
[GtkChild]
Gtk.Box transaction_infobox;
[GtkChild]
Gtk.Revealer transaction_infobox_revealer;
[GtkChild]
Gtk.Button details_button;
[GtkChild]
Gtk.Button apply_button;
[GtkChild]
Gtk.Button cancel_button;
// menu
Gtk.Menu right_click_menu;
Gtk.MenuItem deselect_item;
Gtk.MenuItem upgrade_item;
Gtk.MenuItem install_item;
Gtk.MenuItem remove_item;
Gtk.MenuItem details_item;
GLib.List<string> selected_pkgs;
GLib.List<string> selected_aur;
// liststores
Gtk.ListStore packages_list;
Gtk.ListStore aur_list;
int sort_column_id;
Gtk.SortType sort_order;
bool restore_sort_order;
public Queue<string> display_package_queue;
string current_package_displayed;
public Transaction transaction;
delegate void TransactionAction ();
bool refreshing;
bool important_details;
bool transaction_running;
bool sysupgrade_running;
bool generate_mirrors_list;
bool waiting;
bool force_refresh;
AlpmPackage[] repos_updates;
AURPackage[] aur_updates;
bool extern_lock;
uint search_entry_timeout_id;
string search_string;
Gtk.Label pending_label;
Gtk.ListBoxRow pending_row;
Gtk.ListBoxRow files_row;
public ManagerWindow (Gtk.Application application) {
Object (application: application);
button_back.visible = false;
select_all_button.visible = false;
searchbar.connect_entry (search_entry);
refreshing = false;
important_details = false;
transaction_running = false;
sysupgrade_running = false;
generate_mirrors_list = false;
updated_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "Your system is up-to-date")));
no_item_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "No package found")));
checking_label.set_markup ("<big><b>%s</b></big>".printf (dgettext (null, "Checking for Updates")));
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
right_click_menu = new Gtk.Menu ();
deselect_item = new Gtk.MenuItem.with_label (dgettext (null, "Deselect"));
deselect_item.activate.connect (on_deselect_item_activate);
right_click_menu.append (deselect_item);
upgrade_item = new Gtk.MenuItem.with_label (dgettext (null, "Upgrade"));
upgrade_item.activate.connect (on_upgrade_item_activate);
right_click_menu.append (upgrade_item);
install_item = new Gtk.MenuItem.with_label (dgettext (null, "Install"));
install_item.activate.connect (on_install_item_activate);
right_click_menu.append (install_item);
remove_item = new Gtk.MenuItem.with_label (dgettext (null, "Remove"));
remove_item.activate.connect (on_remove_item_activate);
right_click_menu.append (remove_item);
var separator_item = new Gtk.SeparatorMenuItem ();
right_click_menu.append (separator_item);
details_item = new Gtk.MenuItem.with_label (dgettext (null, "Details"));
details_item.activate.connect (on_details_item_activate);
right_click_menu.append (details_item);
right_click_menu.show_all ();
packages_list = new Gtk.ListStore (9,
typeof (uint), //origin
typeof (string), //pkgname
typeof (string), //name+desc
typeof (string), //version
typeof (string), //repo
typeof (uint64), //isize
typeof (string), //GLib.format (isize)
typeof (string), //app_name
typeof (Gdk.Pixbuf)); //icon
// sort packages by app_name by default
packages_list.set_sort_column_id (2, Gtk.SortType.ASCENDING);
restore_sort_order = false;
packages_treeview.set_model (packages_list);
// add custom cellrenderer to packages_treeview and aur_treewiew
var packages_state_renderer = new ActivableCellRendererPixbuf ();
packages_state_column.pack_start (packages_state_renderer, false);
packages_state_column.set_cell_data_func (packages_state_renderer, (celllayout, cellrenderer, treemodel, treeiter) => {
Gdk.Pixbuf pixbuf;
uint origin;
string pkgname;
treemodel.get (treeiter, 0, out origin, 1, out pkgname);
if (origin == 2) { //origin == Alpm.Package.From.LOCALDB
if (unlikely (transaction.transaction_summary.contains (pkgname))) {
pixbuf = installed_locked_icon;
} else if (unlikely (transaction.should_hold (pkgname))) {
pixbuf = installed_locked_icon;
} else if (unlikely (transaction.to_install.contains (pkgname))) {
pixbuf = to_reinstall_icon;
} else if (unlikely (transaction.to_remove.contains (pkgname))) {
pixbuf = to_remove_icon;
} else {
pixbuf = installed_icon;
}
} else if (unlikely (transaction.transaction_summary.contains (pkgname))) {
pixbuf = available_locked_icon;
} else if (unlikely (transaction.to_install.contains (pkgname))) {
pixbuf = to_install_icon;
} else if (unlikely (transaction.to_update.contains (pkgname))) {
pixbuf = to_upgrade_icon;
} else {
pixbuf = uninstalled_icon;
}
cellrenderer.set ("pixbuf", pixbuf);
});
packages_state_renderer.activated.connect (on_packages_state_icon_activated);
aur_list = new Gtk.ListStore (7,
typeof (uint), //origin
typeof (string), //name
typeof (string), //name+desc
typeof (string), //version
typeof (double), //popularity
typeof (string), //populariy to string
typeof (Gdk.Pixbuf)); //icon
// sort packages by popularity by default
aur_list.set_sort_column_id (4, Gtk.SortType.DESCENDING);
aur_treeview.set_model (aur_list);
// add custom cellrenderer to aur_treewiew
var aur_state_renderer = new ActivableCellRendererPixbuf ();
aur_state_column.pack_start (aur_state_renderer, false);
aur_state_column.set_cell_data_func (aur_state_renderer, (celllayout, cellrenderer, treemodel, treeiter) => {
Gdk.Pixbuf pixbuf;
uint origin;
string pkgname;
treemodel.get (treeiter, 0, out origin, 1, out pkgname);
if (filters_stack.visible_child_name == "updates") {
if (unlikely (transaction.temporary_ignorepkgs.contains (pkgname))) {
pixbuf = uninstalled_icon;
} else {
pixbuf = to_upgrade_icon;
}
} else if ((uint) origin == 2) { //origin == Alpm.Package.From.LOCALDB
if (unlikely (transaction.transaction_summary.contains (pkgname))) {
pixbuf = installed_locked_icon;
} else if (unlikely (transaction.should_hold (pkgname))) {
pixbuf = installed_locked_icon;
} else if (unlikely (transaction.to_install.contains (pkgname))) {
pixbuf = to_reinstall_icon;
} else if (unlikely (transaction.to_remove.contains (pkgname))) {
pixbuf = to_remove_icon;
} else {
pixbuf = installed_icon;
}
} else if (unlikely (transaction.to_build.contains (pkgname))) {
pixbuf = to_install_icon;
} else {
pixbuf = uninstalled_icon;
}
cellrenderer.set ("pixbuf", pixbuf);
});
aur_state_renderer.activated.connect (on_aur_state_icon_activated);
try {
installed_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-updated.png");
uninstalled_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-available.png");
to_install_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-install.png");
to_reinstall_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-reinstall.png");
to_remove_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-remove.png");
to_upgrade_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-upgrade.png");
installed_locked_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-installed-locked.png");
available_locked_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-available-locked.png");
package_icon = new Gdk.Pixbuf.from_resource ("/org/manjaro/pamac/manager/package-generic.png");
} catch (GLib.Error e) {
stderr.printf ("%s\n", e.message);
}
transaction = new Transaction (this as Gtk.ApplicationWindow);
transaction.start_downloading.connect (on_start_downloading);
transaction.stop_downloading.connect (on_stop_downloading);
transaction.start_building.connect (on_start_building);
transaction.stop_building.connect (on_stop_building);
transaction.important_details_outpout.connect (on_important_details_outpout);
transaction.finished.connect (on_transaction_finished);
transaction.write_pamac_config_finished.connect (on_write_pamac_config_finished);
transaction.set_pkgreason_finished.connect (on_set_pkgreason_finished);
transaction.generate_mirrors_list.connect (on_generate_mirrors_list);
transaction.run_preferences_dialog_finished.connect (on_run_preferences_dialog_finished);
transaction.get_updates_finished.connect (on_get_updates_finished);
// integrate progress box and term widget
main_stack.add_named (transaction.term_window, "term");
transaction_infobox.pack_start (transaction.progress_box);
Timeout.add (500, check_extern_lock);
display_package_queue = new Queue<string> ();
main_stack.notify["visible-child"].connect (on_main_stack_visible_child_changed);
filters_stack.notify["visible-child"].connect (on_filters_stack_visible_child_changed);
origin_stack.notify["visible-child"].connect (on_origin_stack_visible_child_changed);
properties_stack.notify["visible-child"].connect (on_properties_stack_visible_child_changed);
searchbar.notify["search-mode-enabled"].connect (on_search_mode_enabled);
// enable "type to search"
this.key_press_event.connect ((event) => {
return searchbar.handle_event (event);
});
// create screenshots tmp dir
string screenshots_tmp_dir = "/tmp/pamac-app-screenshots";
try {
Process.spawn_command_line_sync ("mkdir -p %s".printf (screenshots_tmp_dir));
Process.spawn_command_line_sync ("chmod -R 777 %s".printf (screenshots_tmp_dir));
} catch (SpawnError e) {
stderr.printf ("SpawnError: %s\n", e.message);
}
}
bool check_extern_lock () {
if (extern_lock) {
if (!transaction.lockfile.query_exists ()) {
extern_lock = false;
transaction.refresh_handle ();
refresh_packages_list ();
}
} else {
if (transaction.lockfile.query_exists ()) {
if (!transaction_running && !refreshing && !sysupgrade_running) {
extern_lock = true;
}
}
}
return true;
}
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period, bool no_update_hide_icon,
bool enable_aur) {
support_aur (enable_aur);
}
void on_set_pkgreason_finished () {
transaction.unlock ();
transaction.refresh_handle ();
refresh_packages_list ();
if (main_stack.visible_child_name == "details") {
if (transaction.get_installed_pkg (current_package_displayed).name != ""
|| transaction.get_sync_pkg (current_package_displayed).name != "") {
display_package_properties (current_package_displayed);
} else {
display_aur_properties (current_package_displayed);
}
}
}
void support_aur (bool enable_aur) {
if (filters_stack.visible_child_name == "search") {
if (enable_aur) {
show_sidebar ();
} else {
hide_sidebar ();
origin_stack.visible_child_name = "repos";
}
}
}
void hide_sidebar () {
sidebar_revealer.set_reveal_child (false);
}
void show_sidebar () {
sidebar_revealer.set_reveal_child (true);
}
void hide_transaction_infobox () {
transaction_infobox_revealer.set_reveal_child (false);
}
void show_transaction_infobox () {
transaction_infobox_revealer.set_reveal_child (true);
}
void try_lock_and_run (TransactionAction action) {
if (transaction.get_lock ()) {
action ();
} else {
waiting = true;
transaction.progress_box.action_label.label = dgettext (null, "Waiting for another package manager to quit") + "...";
transaction.start_progressbar_pulse ();
cancel_button.sensitive = true;
show_transaction_infobox ();
Timeout.add (5000, () => {
bool locked = transaction.get_lock ();
if (locked) {
waiting = false;
transaction.stop_progressbar_pulse ();
action ();
}
return !locked;
});
}
}
void set_pendings_operations () {
refresh_state_icons ();
if (!transaction_running && !generate_mirrors_list && !refreshing && !sysupgrade_running) {
if (filters_stack.visible_child_name == "updates") {
uint64 total_dsize = 0;
packages_list.foreach ((model, path, iter) => {
string name;
uint64 dsize;
packages_list.get (iter, 1, out name, 5, out dsize);
if (transaction.to_update.contains (name)) {
total_dsize += dsize;
}
return false;
});
if (total_dsize > 0) {
transaction.progress_box.action_label.set_markup("<b>%s: %s</b>".printf (dgettext (null, "Total download size"), format_size (total_dsize)));
} else {
transaction.progress_box.action_label.label = "";
}
if (!transaction_running && !generate_mirrors_list && !refreshing && !sysupgrade_running
&& (transaction.to_update.length > 0)) {
apply_button.sensitive = true;
} else {
apply_button.sensitive = false;
}
cancel_button.sensitive = false;
show_transaction_infobox ();
} else {
uint total_pending = transaction.to_install.length + transaction.to_remove.length + transaction.to_build.length;
if (total_pending == 0) {
if (filters_stack.visible_child_name != "pending") {
active_pending_row (false);
}
transaction.progress_box.action_label.label = "";
cancel_button.sensitive = false;
apply_button.sensitive = false;
if (important_details) {
show_transaction_infobox ();
}
} else {
active_pending_row (true);
string info = dngettext (null, "%u pending operation", "%u pending operations", total_pending).printf (total_pending);
transaction.progress_box.action_label.label = info;
cancel_button.sensitive = true;
apply_button.sensitive = true;
show_transaction_infobox ();
}
}
}
}
void show_default_pkgs () {
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
origin_stack.visible_child_name = "repos";
transaction.get_installed_apps.begin ((obj, res) => {
populate_packages_list (transaction.get_installed_apps.end (res));
});
}
Gtk.Label create_list_label (string str) {
var label = new Gtk.Label (str);
label.visible = true;
label.margin = 12;
label.xalign = 0;
return label;
}
int sort_list_row (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
var label1 = row1.get_child () as Gtk.Label;
var label2 = row2.get_child () as Gtk.Label;
return strcmp (label1.label, label2.label);
}
void active_pending_row (bool active) {
pending_row.activatable = active;
pending_label.sensitive = active;
}
public void update_lists () {
Gtk.Label label;
label = create_list_label (dgettext (null, "Categories"));
filters_listbox.add (label);
label = create_list_label (dgettext (null, "Groups"));
filters_listbox.add (label);
label = create_list_label (dgettext (null, "Repositories"));
filters_listbox.add (label);
label = create_list_label (dgettext (null, "Installed"));
filters_listbox.add (label);
label = create_list_label (dgettext (null, "Updates"));
filters_listbox.add (label);
pending_label = create_list_label (dgettext (null, "Pending"));
pending_row = new Gtk.ListBoxRow ();
pending_row.visible = true;
pending_row.add (pending_label);
filters_listbox.add (pending_row);
active_pending_row (false);
filters_listbox.select_row (filters_listbox.get_row_at_index (0));
foreach (unowned string repo in transaction.get_repos_names ()) {
label = create_list_label (repo);
repos_listbox.add (label);
}
repos_listbox.select_row (repos_listbox.get_row_at_index (0));
foreach (unowned string group in transaction.get_groups_names ()) {
label = create_list_label (group);
groups_listbox.add (label);
}
groups_listbox.set_sort_func (sort_list_row);
groups_listbox.select_row (groups_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Installed"));
installed_listbox.add (label);
label = create_list_label (dgettext (null, "Explicitly installed"));
installed_listbox.add (label);
label = create_list_label (dgettext (null, "Orphans"));
installed_listbox.add (label);
label = create_list_label (dgettext (null, "Foreign"));
installed_listbox.add (label);
installed_listbox.select_row (installed_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Accessories"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Audio & Video"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Development"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Education"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Games"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Graphics"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Internet"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Office"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Science"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "Settings"));
categories_listbox.add (label);
label = create_list_label (dgettext (null, "System Tools"));
categories_listbox.add (label);
categories_listbox.set_sort_func (sort_list_row);
categories_listbox.select_row (categories_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Repositories"));
updates_listbox.add (label);
label = create_list_label (dgettext (null, "AUR"));
updates_listbox.add (label);
updates_listbox.select_row (updates_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Repositories"));
pending_listbox.add (label);
label = create_list_label (dgettext (null, "AUR"));
pending_listbox.add (label);
pending_listbox.select_row (pending_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Repositories"));
search_listbox.add (label);
label = create_list_label (dgettext (null, "AUR"));
search_listbox.add (label);
search_listbox.select_row (search_listbox.get_row_at_index (0));
label = create_list_label (dgettext (null, "Details"));
properties_listbox.add (label);
label = create_list_label (dgettext (null, "Dependencies"));
properties_listbox.add (label);
label = create_list_label (dgettext (null, "Files"));
files_row = new Gtk.ListBoxRow ();
files_row.visible = true;
files_row.add (label);
properties_listbox.add (files_row);
properties_listbox.select_row (properties_listbox.get_row_at_index (0));
}
void on_mark_explicit_button_clicked (Gtk.Button button) {
if (transaction.get_lock ()) {
transaction.start_set_pkgreason (current_package_displayed, 0); //Alpm.Package.Reason.EXPLICIT
}
}
Gtk.Widget populate_details_grid (string detail_type, string detail, Gtk.Widget? previous_widget) {
var label = new Gtk.Label ("<b>%s</b>".printf (detail_type + ":"));
label.use_markup = true;
label.halign = Gtk.Align.START;
label.valign = Gtk.Align.START;
details_grid.attach_next_to (label, previous_widget, Gtk.PositionType.BOTTOM);
if (!transaction_running
&& !sysupgrade_running
&& detail_type == dgettext (null, "Install Reason")
&& detail == dgettext (null, "Installed as a dependency for another package")) {
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
box.homogeneous = false;
var label2 = new Gtk.Label (detail);
label2.halign = Gtk.Align.START;
box.pack_start (label2, false);
var mark_explicit_button = new Gtk.Button.with_label (dgettext (null, "Mark as explicitly installed"));
mark_explicit_button.halign = Gtk.Align.START;
mark_explicit_button.clicked.connect (on_mark_explicit_button_clicked);
box.pack_start (mark_explicit_button, false);
details_grid.attach_next_to (box, label, Gtk.PositionType.RIGHT);
} else {
var label2 = new Gtk.Label (detail);
label2.use_markup = true;
label2.halign = Gtk.Align.START;
details_grid.attach_next_to (label2, label, Gtk.PositionType.RIGHT);
}
return label as Gtk.Widget;
}
string find_install_button_dep_name (Gtk.Button button) {
string dep_name = "";
Gtk.Container container = button.get_parent ();
container.foreach ((widget) => {
if (widget.name == "GtkButton") {
var dep_button = widget as Gtk.Button;
AlpmPackage pkg = transaction.find_sync_satisfier (dep_button.label);
if (pkg.name != "") {
dep_name = pkg.name;
}
}
});
return dep_name;
}
void on_install_dep_button_toggled (Gtk.ToggleButton button) {
string dep_name = find_install_button_dep_name (button);
if (button.active) {
button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
transaction.to_install.add (dep_name);
} else {
button.get_style_context ().remove_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
transaction.to_install.remove (dep_name);
}
set_pendings_operations ();
}
Gtk.Widget populate_dep_grid (string dep_type, string[] dep_list, Gtk.Widget? previous_widget, bool add_install_button = false) {
var label = new Gtk.Label ("<b>%s</b>".printf (dep_type + ":"));
label.use_markup = true;
label.halign = Gtk.Align.START;
label.valign = Gtk.Align.START;
label.margin_top = 6;
deps_grid.attach_next_to (label, previous_widget, Gtk.PositionType.BOTTOM);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 3);
box.hexpand = true;
foreach (unowned string dep in dep_list) {
if (add_install_button) {
var box2 = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
box2.homogeneous = false;
var dep_button = new Gtk.Button.with_label (dep);
dep_button.relief = Gtk.ReliefStyle.NONE;
dep_button.clicked.connect (on_dep_button_clicked);
box2.pack_start (dep_button, false);
if (transaction.find_installed_satisfier (dep).name == "") {
var install_dep_button = new Gtk.ToggleButton.with_label (dgettext (null, "Install"));
install_dep_button.margin = 3;
install_dep_button.toggled.connect (on_install_dep_button_toggled);
box2.pack_end (install_dep_button, false);
string dep_name = find_install_button_dep_name (install_dep_button);
install_dep_button.active = (dep_name in transaction.to_install);
}
box.pack_start (box2);
} else {
var dep_button = new Gtk.Button.with_label (dep);
dep_button.relief = Gtk.ReliefStyle.NONE;
dep_button.halign = Gtk.Align.START;
dep_button.clicked.connect (on_dep_button_clicked);
box.pack_start (dep_button, false);
}
}
deps_grid.attach_next_to (box, label, Gtk.PositionType.RIGHT);
return label as Gtk.Widget;
}
void destroy_widget (Gtk.Widget widget) {
widget.destroy ();
}
async Gdk.Pixbuf get_screenshot_pixbuf (string url) {
var uri = File.new_for_uri (url);
var cached_screenshot = File.new_for_path ("/tmp/pamac-app-screenshots/%s".printf (uri.get_basename ()));
Gdk.Pixbuf pixbuf = null;
if (cached_screenshot.query_exists ()) {
try {
pixbuf = new Gdk.Pixbuf.from_file (cached_screenshot.get_path ());
} catch (GLib.Error e) {
stderr.printf ("%s: %s\n", url, e.message);
}
} else {
// download screenshot
var session = new Soup.Session ();
var utsname = Posix.utsname();
session.user_agent = "pamac (%s %s)".printf (utsname.sysname, utsname.machine);
try {
var request = session.request (url);
try {
var inputstream = yield request.send_async (null);
pixbuf = new Gdk.Pixbuf.from_stream (inputstream);
// scale pixbux at a width of 600 pixels
int width = pixbuf.get_width ();
if (width > 600) {
float ratio = (float) width / (float) pixbuf.get_height ();
int new_height = (int) (600 / ratio);
pixbuf = pixbuf.scale_simple (600, new_height, Gdk.InterpType.BILINEAR);
}
// save scaled image in tmp
FileOutputStream os = cached_screenshot.append_to (FileCreateFlags.NONE);
pixbuf.save_to_stream (os, "png");
} catch (GLib.Error e) {
stderr.printf ("%s: %s\n", url, e.message);
}
} catch (GLib.Error e) {
stderr.printf ("%s: %s\n", url, e.message);
}
}
return pixbuf;
}
void set_package_details (string pkgname, string app_name) {
AlpmPackageDetails details = transaction.get_pkg_details (pkgname, app_name);
// download screenshot
app_screenshot.pixbuf = null;
if (details.screenshot != "") {
get_screenshot_pixbuf.begin (details.screenshot, (obj, res) => {
var pixbuf = get_screenshot_pixbuf.end (res);
app_screenshot.pixbuf = pixbuf;
});
}
// infos
if (details.app_name == "") {
name_label.set_markup ("<big><b>%s %s</b></big>".printf (details.name, details.version));
app_image.pixbuf = package_icon;
} else {
name_label.set_markup ("<big><b>%s (%s) %s</b></big>".printf (Markup.escape_text (details.app_name), details.name, details.version));
if (details.icon != "") {
try {
var pixbuf = new Gdk.Pixbuf.from_file (details.icon);
app_image.pixbuf = pixbuf;
} catch (GLib.Error e) {
// some icons are not in the right repo
string icon = details.icon;
if ("extra" in details.icon) {
icon = details.icon.replace ("extra", "community");
} else if ("community" in details.icon) {
icon = details.icon.replace ("community", "extra");
}
try {
var pixbuf = new Gdk.Pixbuf.from_file (icon);
app_image.pixbuf = pixbuf;
} catch (GLib.Error e) {
app_image.pixbuf = package_icon;
stderr.printf ("%s: %s\n", details.icon, e.message);
}
}
} else {
app_image.pixbuf = package_icon;
}
}
desc_label.set_text (details.desc);
if (details.long_desc == "") {
long_desc_label.visible = false;
} else {
long_desc_label.set_text (details.long_desc);
long_desc_label.visible = true;
}
string escaped_url = Markup.escape_text (details.url);
link_label.set_markup ("<a href=\"%s\">%s</a>".printf (escaped_url, escaped_url));
StringBuilder licenses = new StringBuilder ();
licenses.append (dgettext (null, "Licenses"));
licenses.append (":");
foreach (unowned string license in details.licenses) {
licenses.append (" ");
licenses.append (license);
}
licenses_label.set_text (licenses.str);
if (details.origin == 2) { //Alpm.Package.From.LOCALDB
install_togglebutton.visible = false;
remove_togglebutton.visible = true;
remove_togglebutton.active = transaction.to_remove.contains (details.name);
reinstall_togglebutton.visible = false;
AlpmPackage find_pkg = transaction.get_sync_pkg (details.name);
if (find_pkg.name != "") {
if (find_pkg.version == details.version) {
reinstall_togglebutton.visible = true;
reinstall_togglebutton.active = transaction.to_install.contains (details.name);
}
} else {
transaction.get_aur_details.begin (details.name, (obj, res) => {
AURPackageDetails aur_details = transaction.get_aur_details.end (res);
if (aur_details.name != "") {
// always show reinstall button for VCS package
if (aur_details.name.has_suffix ("-git") ||
aur_details.name.has_suffix ("-svn") ||
aur_details.name.has_suffix ("-bzr") ||
aur_details.name.has_suffix ("-hg") ||
aur_details.version == details.version) {
reinstall_togglebutton.visible = true;
reinstall_togglebutton.active = transaction.to_build.contains (details.name);
}
}
});
}
} else if (details.origin == 3) { //Alpm.Package.From.SYNCDB
remove_togglebutton.visible = false;
reinstall_togglebutton.visible = false;
install_togglebutton.visible = true;
install_togglebutton.active = transaction.to_install.contains (details.name);
}
// details
details_grid.foreach (destroy_widget);
Gtk.Widget? previous_widget = null;
if (details.repo != "") {
previous_widget = populate_details_grid (dgettext (null, "Repository"), details.repo, previous_widget);
}
if (details.groups.length > 0) {
var label = new Gtk.Label ("<b>%s</b>".printf (dgettext (null, "Groups") + ":"));
label.use_markup = true;
label.halign = Gtk.Align.START;
label.valign = Gtk.Align.START;
details_grid.attach_next_to (label, previous_widget, Gtk.PositionType.BOTTOM);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
foreach (unowned string name in details.groups) {
var label2 = new Gtk.Label (name);
label2.halign = Gtk.Align.START;
box.pack_start (label2);
}
details_grid.attach_next_to (box, label, Gtk.PositionType.RIGHT);
previous_widget = label as Gtk.Widget;
}
// make packager mail clickable
string[] splitted = details.packager.split ("<", 2);
string packager_name = splitted[0];
if (splitted.length > 1) {
string packager_mail = splitted[1].split (">", 2)[0];
string packager_detail = "%s <a href=\"mailto:%s\">%s</a>".printf (packager_name, packager_mail, packager_mail);
previous_widget = populate_details_grid (dgettext (null, "Packager"), packager_detail, previous_widget);
} else {
previous_widget = populate_details_grid (dgettext (null, "Packager"), details.packager, previous_widget);
}
previous_widget = populate_details_grid (dgettext (null, "Build Date"), details.builddate, previous_widget);
if (details.installdate != "") {
previous_widget = populate_details_grid (dgettext (null, "Install Date"), details.installdate, previous_widget);
}
if (details.reason != "") {
previous_widget = populate_details_grid (dgettext (null, "Install Reason"), details.reason, previous_widget);
}
if (details.has_signature != "") {
previous_widget = populate_details_grid (dgettext (null, "Signatures"), details.has_signature, previous_widget);
}
if (details.backups.length > 0) {
var label = new Gtk.Label ("<b>%s</b>".printf (dgettext (null, "Backup files") + ":"));
label.use_markup = true;
label.halign = Gtk.Align.START;
label.valign = Gtk.Align.START;
details_grid.attach_next_to (label, previous_widget, Gtk.PositionType.BOTTOM);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
foreach (unowned string name in details.backups) {
var label2 = new Gtk.Label (name);
label2.halign = Gtk.Align.START;
box.pack_start (label2);
}
details_grid.attach_next_to (box, label, Gtk.PositionType.RIGHT);
}
details_grid.show_all ();
// deps
deps_grid.foreach (destroy_widget);
previous_widget = null;
if (details.depends.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Depends On"), details.depends, previous_widget);
}
if (details.optdepends.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Optional Dependencies"), details.optdepends, previous_widget, true);
}
if (details.requiredby.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Required By"), details.requiredby, previous_widget);
}
if (details.optionalfor.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Optional For"), details.optionalfor, previous_widget);
}
if (details.provides.length > 0) {
var label = new Gtk.Label ("<b>%s</b>".printf (dgettext (null, "Provides") + ":"));
label.use_markup = true;
label.halign = Gtk.Align.START;
label.valign = Gtk.Align.START;
label.margin_top = 6;
deps_grid.attach_next_to (label, previous_widget, Gtk.PositionType.BOTTOM);
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 12);
box.margin = 3;
foreach (unowned string name in details.provides) {
var label2 = new Gtk.Label (name);
label2.halign = Gtk.Align.START;
label2.margin_start = 12;
box.pack_start (label2);
}
deps_grid.attach_next_to (box, label, Gtk.PositionType.RIGHT);
previous_widget = label as Gtk.Widget;
}
if (details.replaces.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Replaces"), details.replaces, previous_widget);
}
if (details.conflicts.length > 0) {
previous_widget = populate_dep_grid (dgettext (null, "Conflicts With"), details.conflicts, previous_widget);
}
deps_grid.show_all ();
// files
// will be populated on properties_stack switch
if (properties_stack.visible_child_name == "files") {
on_properties_stack_visible_child_changed ();
}
}
void set_aur_details (string pkgname) {
app_image.pixbuf = null;
app_screenshot.pixbuf = null;
name_label.set_text ("");
desc_label.set_text ("");
link_label.set_text ("");
licenses_label.set_text ("");
long_desc_label.visible = false;
remove_togglebutton.visible = false;
reinstall_togglebutton.visible = false;
install_togglebutton.visible = false;
properties_listbox.visible = false;
details_grid.foreach (destroy_widget);
deps_grid.foreach (destroy_widget);
this.get_window ().set_cursor (new Gdk.Cursor.for_display (Gdk.Display.get_default (), Gdk.CursorType.WATCH));
while (Gtk.events_pending ()) {
Gtk.main_iteration ();
}
transaction.get_aur_details.begin (pkgname, (obj, res) => {
AURPackageDetails details = transaction.get_aur_details.end (res);
// infos