-
Notifications
You must be signed in to change notification settings - Fork 5
/
widgets.vala~
1298 lines (1073 loc) · 33.8 KB
/
widgets.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
/* Copyright 2016 Camilo Higuita(milohr)
*
* This file is part of Babe Music Player.
*
* Babe is free software: you can redistribute it
* and/or modify it under the terms of version 3 of the
* GNU General Public License as published by the Free Software Foundation.
*
* Babe 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 Babe. If not, see http://www.gnu.org/licenses/.
*/
using Gtk;
using Gst;
using Xml;
using Soup;
using BabeStream;
using CoverArt;
using BabeLyric;
using BabeList;
using BabePlayList;
namespace BabeWidgets {
const string playlist_path="./Playlist/";
public class BabeWindow : Gtk.Window //creates main window with all widgets alltogether...not ideal but...
{
public BabeStream.Stream babe_stream;
public LastFm artwork;
public BList main_list;
public BList queue_list;
public BList babes_list;
public BList playlist;
public BPlayList playlist_list;
public LyricsManiaFetcher babe_lyric;
public int queue_c=0;
public int c=0; //number of songs on the babed list
public int mini=0; //state of the mini/maxi view
public int shuffle=0; //whether the playback is on shuffle(0) or not(1)
public string check=""; //placeholder to check if we already have an album cover art
public string album_art; //placeholder to check if we already have an album cover art
public Gdk.Pixbuf cover_pixbuf; //the pixbuf of the coverart of the current song to use when wanted or needed
public Gtk.TreeIter iter_aux;
//control view mode. pretty useless right now
public int list_int=0;
public int info_int=0;
public int playlist_int=0;
public int babe_int=0;
public int queue_int=0;
public string song; //this is the main uri to send to the streamer and start playback
public string title=""; //title of current song
public string artist=""; //artist of the current song
public string album=""; //album of the current song
//headerbar
public Gtk.Image cover;//here the album artwork
public Gtk.EventBox art_header;
public Gtk.Popover playbox_popover;//still unused
public Gtk.EventBox playback_box_event;
public Gtk.Revealer playback_box_revealer; //reveals the playback actions box
public Gtk.Box playback_box;
public Gtk.Image options;
//main containers
public Gtk.Box main_container;
public Gtk.Box media_box;
public Gtk.Separator h_separator;
public Gtk.Revealer media_revealer;
//view modes
public Gtk.Stack media_stack;
public Gtk.Stack babe_info_stack;//to-do
public Gtk.Label info_box_label;
public Gtk.Box info_box;
public Gtk.Menu menu;
//playback box
public Gtk.Box playback_buttons;
public Gtk.Scale progressbar;
public Gtk.Image play_icon;
public Gtk.Image next_icon;
public Gtk.Image previous_icon;
public Gtk.Image babe_icon;
public Gtk.EventBox play_icon_event;
public Gtk.EventBox next_icon_event;
public Gtk.EventBox previous_icon_event;
public Gtk.EventBox babe_icon_event;
public Gtk.Label stream_dur;
public Gtk.Label stream_pos;
//PLAY LISTS IN MEDIA_BOX
private Gtk.TreeIter iter;
private Gtk.TreeModel model;
private Gtk.TreeModel previous_model;
//info view
private Gtk.Box info_view ;
private ScrolledWindow info_list_scroll;
//status bar
public Gtk.ActionBar statusbar;
public Gtk.Label status_label;
public Gtk.Popover add_playlist_popover;
public Gtk.Entry add_playlist_entry;
public Gtk.EventBox add_playlist_event;
public Gtk.EventBox shuffle_event;
public Gtk.EventBox open_event;
public Gtk.EventBox hide_event;
public Gtk.Image add_playlist_icon;
public Gtk.Image shuffle_icon;
public Gtk.Image open_icon;
public Gtk.Image hide_icon;
//sidebar
public Gtk.Popover settings_popover;
public Gtk.Box settings_box;
private Gtk.ListBox babe_sidebar;
private Gtk.ListBoxRow babe_list;
private Gtk.ListBoxRow babe_info;
private Gtk.ListBoxRow babe_babes;
private Gtk.ListBoxRow babe_playlist;
private Gtk.ListBoxRow babe_queue;
public BabeWindow()
{
this.get_style_context().add_class("babe-window");
this.title = "Babe...";
iter_aux = Gtk.TreeIter();
this.window_position = WindowPosition.CENTER;
this.set_resizable(false);
//this.set_decorated(false);
//this.set_default_size (200, 0);
this.destroy.connect(Gtk.main_quit);
cover=new Gtk.Image();
this.cover.set_from_file ("img/babe.png");
babe_stream=new BabeStream.Stream(); //this is the main pipeline for
streaming
artwork = new LastFm(); //this is to get the album art
babe_lyric= new LyricsManiaFetcher();
main_list = new BList(false,"");
babes_list=new BList(true,".Babes.txt");
queue_list=new BList(false,"");
playlist_list=new BPlayList();
set_playlists();
//Sets everything we need up
set_babe_sidebar();
set_babe_statusbar();
set_babe_playback_box();
set_babe_style();
/***
**SETUP HEADER WIDGETS
***/
//open music event
open_icon = new Gtk.Image.from_icon_name("folder-open-symbolic", Gtk.IconSize.MENU);
open_icon.get_style_context().add_class("options_icon");
open_event = new Gtk.EventBox();
open_event.add(open_icon);
open_icon.set_tooltip_text ("Open...");
open_event.button_press_event.connect (() => {
main_list.on_open();
return true;
});
//option event- to-finish
options= new Gtk.Image.from_icon_name("go-jump-symbolic", Gtk.IconSize.MENU);
options.get_style_context().add_class("options_icon");
var options_event=new Gtk.EventBox();
options_event.set_tooltip_text("Options");
options_event.add(options);
bool op=false;
options_event.button_press_event.connect (() => {
if(op==false)
{
cover.set_from_file("img/babe_back.png");
op=true;
}else
{
cover.set_from_pixbuf(cover_pixbuf);
op=false;
}
return true;
});
//playback box
playback_box = new Gtk.Box(Gtk.Orientation.VERTICAL,10);
h_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
playback_box.add(playback_buttons);
playback_box.add(progressbar);
//playback_box.add(h_separator);
playback_box.set_spacing(-1);
//pack playback_box inside an eventbox
playback_box_event=new Gtk.EventBox();
playback_box_event.add(playback_box);
playback_box_event.get_style_context().add_class("playback_box");
//let's pack now the playback_box_event into a revelaer
playback_box_revealer=new Gtk.Revealer();
playback_box_revealer.set_transition_type(RevealerTransitionType.CROSSFADE);
//playback_box_revealer.set_transition_duration(300);
playback_box_revealer.add(playback_box_event);
//let's fix their positions to overlap them
Gtk.Fixed fixed = new Gtk.Fixed ();
fixed.put(cover,0,0);
fixed.put(options_event,180,5);
fixed.put(open_event,5,5);
fixed.put(playback_box_revealer,45, 150);
//let's make sure here that the revealer works allright
playback_box_event.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
playback_box_event.enter_notify_event.connect (reveal_playback_box);
//art_header.leave_notify_event.connect (hide);
//art_header.set_vexpand(true);
//now we put the fixed box inside a new eventbox to make it the header/titlebar
art_header = new Gtk.EventBox();//
art_header.add(fixed);
art_header.add_events (Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK);
art_header.enter_notify_event.connect (reveal_playback_box);
art_header.leave_notify_event.connect (hide_playback_box);
//art_header.set_visible_child_name("head_cover");
this.set_titlebar(art_header); //this sets the album art as headerbar
/***
**SETUP ALL OTHER WIDGETS
***/
//main view: sidebar->lists view
media_box = new Gtk.Box(Gtk.Orientation.HORIZONTAL,0);
Gtk.Separator v_separator = new Gtk.Separator (Gtk.Orientation.VERTICAL);
media_box.add(babe_sidebar);
media_box.add(v_separator);
media_box.pack_end(media_stack,true,true,0);
//main container: main view->statusbar
main_container = new Gtk.Box(Gtk.Orientation.VERTICAL,0);
main_container.add(h_separator);
media_revealer=new Gtk.Revealer();
media_revealer.set_transition_type(RevealerTransitionType.SLIDE_UP);
media_revealer.add(media_box);
main_container.add(media_revealer);
main_container.pack_end(statusbar,false,false,0);
//the constant calls to needed functions
GLib.Timeout.add_seconds(30, (SourceFunc) this.hide_playback_box);
GLib.Timeout.add_seconds(8, (SourceFunc) this.update_status);
GLib.Timeout.add (1000, (SourceFunc) this.update_media_controls);
//add the main container to the babe window
media_revealer.set_reveal_child(true);
this.add(main_container);
}
public bool reveal_playback_box()
{
playback_box_revealer.set_reveal_child(true);
return true;
}
public bool hide_playback_box()
{
playback_box_revealer.set_reveal_child(false);
return true;
}
public void set_babe_playback_box()
{
//playbox_popover = new Gtk.Popover();
progressbar = new Gtk.Scale.with_range (Gtk.Orientation.HORIZONTAL, 0, 50, 1);
progressbar.hexpand = true;
progressbar.set_draw_value (false);
progressbar.set_sensitive(false);
progressbar.button_release_event.connect(on_media_seeked);
stream_pos = new Gtk.Label ("0:00");
stream_dur = new Gtk.Label ("0:00");
stream_pos.margin= 6;
stream_dur.margin = 6;
progressbar.margin_start=5;
progressbar.margin_end=5;
//setup playback icons
playback_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL,10);
play_icon = new Gtk.Image.from_icon_name("media-playback-start-symbolic", Gtk.IconSize.MENU);
next_icon = new Gtk.Image.from_icon_name("media-skip-forward-symbolic", Gtk.IconSize.MENU);
previous_icon = new Gtk.Image.from_icon_name("media-skip-backward-symbolic", Gtk.IconSize.MENU);
babe_icon= new Gtk.Image.from_icon_name("emblem-favorite-symbolic", Gtk.IconSize.MENU);
playback_buttons.margin_start=6;
playback_buttons.margin_end=6;
playback_buttons.margin_top=5;
//setup playback buttons event
play_icon_event=new Gtk.EventBox ();
next_icon_event=new Gtk.EventBox ();
previous_icon_event=new Gtk.EventBox ();
babe_icon_event =new Gtk.EventBox ();
play_icon_event.add(play_icon);
next_icon_event.add(next_icon);
previous_icon_event.add(previous_icon);
babe_icon_event.add(babe_icon);
//pack them in playback horizontal box
//playback_buttons.pack_start(stream_pos, false, false, 0);
playback_buttons.pack_start(previous_icon_event,true,true,1);
playback_buttons.pack_start(babe_icon_event,true,true,1);
playback_buttons.pack_start(play_icon_event,true,true,1);
playback_buttons.pack_start(next_icon_event,true,true,1);
//playback_buttons.pack_end(stream_dur, false, false, 0);
//progressbar.set_tooltip_text(stream_pos.get_text()+" of "+stream_dur.get_text());
}
public void set_babe_sidebar()
{
babe_sidebar = new Gtk.ListBox();
babe_list = new Gtk.ListBoxRow();
var icon = new Gtk.Image.from_icon_name("emblem-music-symbolic", Gtk.IconSize.MENU);
babe_list.add(icon);
babe_list.set_tooltip_text ("List");
babe_info = new Gtk.ListBoxRow();
icon = new Gtk.Image.from_icon_name("media-optical-cd-audio-symbolic", Gtk.IconSize.MENU);
babe_info.add(icon);
babe_info.set_tooltip_text ("Info");
babe_playlist= new Gtk.ListBoxRow();
icon = new Gtk.Image.from_icon_name("media-tape-symbolic", Gtk.IconSize.MENU);
babe_playlist.add(icon);
babe_playlist.set_tooltip_text ("Playlists");
babe_babes = new Gtk.ListBoxRow();
icon = new Gtk.Image.from_icon_name("emblem-favorite-symbolic", Gtk.IconSize.MENU);
babe_babes.add(icon);
babe_babes.set_tooltip_text ("Babes <3");
babe_queue = new Gtk.ListBoxRow();
icon = new Gtk.Image.from_icon_name("document-open-recent-symbolic", Gtk.IconSize.MENU);
babe_queue.add(icon);
babe_queue.set_tooltip_text ("Queued");
babe_sidebar.insert(babe_list, 0);
babe_sidebar.insert(babe_info, 1);
babe_sidebar.insert(babe_playlist, 2);
babe_sidebar.insert(babe_babes, 3);
babe_sidebar.insert(babe_queue, 4);
info_box_label=new Gtk.Label("No song");
info_view=new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
info_view.add(info_box_label);
icon = new Gtk.Image.from_icon_name("open-menu-symbolic", Gtk.IconSize.MENU);
Gtk.EventBox settings_event = new Gtk.EventBox();
settings_event.add(icon);
babe_sidebar.insert(settings_event,5);
var op1=new Gtk.MenuItem.with_label("Clean Babes");
var op2=new Gtk.MenuItem.with_label("Clean List");
op1.activate.connect(clean_babe_list); //empty the babe'd list
op2.activate.connect(() => {
//babe_stream.set_state(Gst.State.NULL);
main_list.get_liststore().clear();
//media_stack.set_visible_child_name("add");
});//empty the babe'd list
var caja = new Gtk.Box(Gtk.Orientation.VERTICAL,0);
caja.add(op1);
caja.add(op2);
settings_popover=new Gtk.Popover(settings_event);
settings_popover.add(caja);
settings_event.button_press_event.connect (() => {
settings_popover.show_all();
return true;
});
set_babe_lists();
}
public void clean_babe_list()
{
//babe_stream.set_state(Gst.State.NULL);
FileStream.open (".Babes.txt","w");
babes_list.get_liststore().clear();
c=0;
babe_babes.set_tooltip_text (c.to_string()+" Babes <3");
}
public void set_babe_lists()
{
info_box_label=new Gtk.Label("No song");
info_view=new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
info_view.add(info_box_label);
info_list_scroll.set_min_content_height(200);
info_list_scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
info_list_scroll.add (info_view);
set_babe_stacks();
}
public void set_babe_stacks()
{
media_stack= new Gtk.Stack();
media_stack.set_vexpand(true);//main list
media_stack.set_vexpand(true);//babes list
media_stack.set_vexpand(true);//playlists list
media_stack.set_vexpand(true);//queued list
media_stack.set_vexpand(true);//info list
//image holder to add music
/*add_music_img = new Gtk.Image();
add_music_img.set_from_file("img/add.png");
add_music_event = new Gtk.EventBox();
add_music_event.add(add_music_img);
add_music_event.button_press_event.connect (() => {
on_open();
return true;
});*/
//set up babe view modes
media_stack.add_named(main_list, "list");
media_stack.add_named(playlist_list, "playlist");
media_stack.add_named(babes_list, "babes");
media_stack.add_named(queue_list, "queue");
media_stack.add_named(info_list_scroll, "info");
//start by default empty list
//media_stack.set_visible_child_name("add");
//get the babe list
list_selected(main_list.get_treeview(), main_list.get_liststore());
list_selected(queue_list.get_treeview(), queue_list.get_liststore());
list_selected(babes_list.get_treeview(), babes_list.get_liststore());
//catch sidebar selection
babe_sidebar.row_activated.connect ((row => {
if(row==babe_list)
{
//babe_icon_event.set_sensitive(true);
print ("babe_list\n");
media_stack.set_visible_child_name("list");
list_int=1;
}
if(row==babe_info)
{
//set_babe_cover(get_babe_head());
print ("babe_info\n");
//media_stack.set_visible_child_name("list");
status_label.label="Info not avalible";
media_stack.set_visible_child_name("info");
info_int=1;
}
if(row==babe_playlist)
{
print ("babe_playlist\n");
media_stack.set_visible_child_name("playlist");
playlist_list.show_main_list();
status_label.label="000 Playlists";
playlist_int=1;
}
if(row==babe_babes)
{
//get_babe_list();//awful solution
print ("babe_babes\n");
media_stack.set_visible_child_name("babes");
babe_int=1;
}
if(row==babe_queue)
{
print ("babe_queue\n");
media_stack.set_visible_child_name("queue");
queue_int=1;
}
}));
}
public void set_babe_statusbar()
{
statusbar = new Gtk.ActionBar();
//events on the statusbar
shuffle_event = new Gtk.EventBox();
add_playlist_event = new Gtk.EventBox();
hide_event = new Gtk.EventBox();
//components
add_playlist_popover = new Gtk.Popover(add_playlist_event);
add_playlist_entry = new Gtk.Entry();
//main info label
status_label = new Gtk.Label("");
status_label.set_line_wrap(true);
status_label.set_max_width_chars (14);
status_label.set_ellipsize (Pango.EllipsizeMode.END);
//status_label.move_cursor(MovementStep.VISUAL_POSITIONS, 100, false);
status_label.set_lines(1);
//set playlist entry
add_playlist_entry.set_placeholder_text("Create new...");
add_playlist_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY,"media-tape-symbolic");//nombre
add_playlist_entry.icon_press.connect((pos, event)=>{
if(pos == Gtk.EntryIconPosition.SECONDARY){
this.add_playlist_entry.set_text("");
}
});
add_playlist_entry.activate.connect (() => {
string str = add_playlist_entry.get_text();
playlist_list.add_playlist(str);
add_playlist_entry.set_text("");
status_label.label="Playlist Created";
});
add_playlist_popover.add(add_playlist_entry);
//shuffle event //TO-DO
shuffle_icon= new Gtk.Image.from_icon_name("media-playlist-no-shuffle-symbolic", Gtk.IconSize.MENU);
shuffle_event.add(shuffle_icon);
shuffle_icon.set_tooltip_text ("Shuffle");
bool state=true;
shuffle_event.button_press_event.connect (() => {
if (state==true)
{
shuffle_icon.set_from_icon_name("media-playlist-shuffle-symbolic", Gtk.IconSize.MENU);
shuffle_icon.set_tooltip_text ("Normal");
shuffle=0;
state=false;
}else
{
shuffle_icon.set_from_icon_name("media-playlist-no-shuffle-symbolic", Gtk.IconSize.MENU);
shuffle_icon.set_tooltip_text ("Shuffle");
shuffle=1;
state=true;
}
return true;
});
//add new playlist event //TO-DO
add_playlist_icon = new Gtk.Image.from_icon_name("list-add-symbolic", Gtk.IconSize.MENU);
add_playlist_event.add(add_playlist_icon);
add_playlist_icon.set_tooltip_text ("Create Playlist");
add_playlist_event.button_press_event.connect (() => {
c++;
add_playlist_popover.show_all();
return true;
});
//hide event
hide_icon= new Gtk.Image.from_icon_name("go-up-symbolic", Gtk.IconSize.MENU);
hide_event.add(hide_icon);
hide_icon.set_tooltip_text ("Go Mini");
mini=0;
hide_event.button_press_event.connect (() => {
switch(mini)
{
case 0:
if(babe_stream.is_playing())
{
this.set_keep_above(true);
}else
{
this.set_keep_above(false);
}
playback_box_revealer.set_reveal_child(false);
media_revealer.set_reveal_child(false);
h_separator.hide();
hide_icon.set_tooltip_text ("Go Maxi");
hide_icon.set_from_icon_name("go-down-symbolic", Gtk.IconSize.MENU);
mini=1;
break;
case 1:
this.set_keep_above(false);
h_separator.show();
media_revealer.set_reveal_child(true);
hide_icon.set_from_icon_name("go-up-symbolic", Gtk.IconSize.MENU);
hide_icon.set_tooltip_text ("Go Mini");
mini=0;
break;
}
return true;
});
statusbar.pack_start(add_playlist_event);
statusbar.pack_start(shuffle_event);
statusbar.set_center_widget(status_label);
//statusbar.pack_end(open_event);
statusbar.pack_end(hide_event);
//statusbar.pack_start(shuffle_event);
}
public TagLib.File get_song_info(string uri)//it actually turn a uri into a path to be able to get the tags
{
var gfile = GLib.File.new_for_uri (uri);
string nm=gfile.get_path() ;
var info = new TagLib.File(nm);
return info;
}
public async void set_babe_cover(string cover_file)
{
if(cover_file=="img/babe.png"){
cover.set_from_file(cover_file);
}else
{
cover_pixbuf=artwork.download_cover_art(cover_file);
if (cover_pixbuf==null)
{
cover.set_from_file("img/babe.png");
}else
{
var scaled_buf = cover_pixbuf.scale_simple(200,200, Gdk.InterpType.BILINEAR);
cover_pixbuf=scaled_buf;
cover.set_from_pixbuf(scaled_buf);
}
}
//g.set_color(cover_file, playback_box);//to assign the most prominent color of coverart to certain widget
}
public string get_babe_cover()
{
string default_cover="img/babe.png";
if(check==album+artist)
{
print("We already got that album cover\n");
return album_art;
}else
{
print("Getting album art for: "+album+" by "+artist+"\n");
if(album==""||artist=="")
{
print("Not enought info to get the album cover. So let's try sth here'\n");
album_art=artwork.get_art_uri(title, artist);
if(album_art==null)
{
return default_cover;
}else
{
return album_art;
}
}else
{
check=album+artist;
album_art=artwork.get_art_uri(album, artist);
if(album_art==null)
{
return default_cover;
}else
{
return album_art;
}
}
}
}
public string get_babe_head()//to do
{
string artist_head;
if(artist=="")
{
return "babe.png";
}else
{
artist_head=artwork.get_artist_uri(artist);
if(artist_head==null)
{
return "babe.png";
}else
{
return artist_head;
}
}
}
public void list_selected(Gtk.TreeView view, Gtk.ListStore list)//actions done to the current list selected
{
//right click event
view.add_events (Gdk.EventType.BUTTON_PRESS);
view.button_press_event.connect (on_right_click);
//double click event
view.row_activated.connect(this.on_row_activated);
//var selection = view.get_selection ();
//selection.changed.connect (get_selection);
}
public bool on_right_click (Gtk.Widget widget, Gdk.EventButton event) //catches the right lcick event
{
var treeview = (Gtk.TreeView) widget;
Gtk.TreePath path=new Gtk.TreePath();
string song_uri, title_r, artist_r,album_r; //to avoid problems with global string of title, artist and album and song
if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3)
{
//var selection = main_list_view.get_selection();
if(treeview.get_path_at_pos((int)event.x,(int)event.y,out path,null, null, null))
{
var model=treeview.get_model();
if (treeview.model.get_iter (out iter, path)) {
model.get (iter,
4, out title_r,
1, out artist_r,
2, out song_uri,
3, out album_r);
set_list_action(song_uri, iter, model, treeview);
menu.popup(null,null,null,event.button, event.time);
print ("Single right click on the tree view: "+title_r+" +++ "+artist_r+" \n");
}
}
return true;
}else
{
return false;
}
}
public void set_list_action(string line, Gtk.TreeIter iter, Gtk.TreeModel model, Gtk.TreeView treeview )
{
menu = new Gtk.Menu();
var item1= new Gtk.MenuItem.with_label("Babe it \xe2\x99\xa1");
var item2= new Gtk.MenuItem.with_label("Remove it");
var item3= new Gtk.MenuItem.with_label("Queue it");
var item4= new Gtk.MenuItem.with_label("Add to playlist");
var submenu= new Gtk.Menu();
add_to_playlist_submenu(submenu, line);
submenu.show_all();
item4.set_submenu(submenu);
item1.activate.connect(()=>{
print("accion#1");
song=line;
add_babe(iter);
});
item2.activate.connect(()=>{
var list_store=(Gtk.ListStore) treeview.get_model();
list_store.remove(iter);
get_BList_object(model).modify_c();
print("accion#2");
});
item3.activate.connect(()=>{
print("accion#3");
song=line;
add_queue(iter);
});
item4.activate.connect(()=>{
print("accion#4");
});
menu.append(item1);
menu.append(item2);
menu.append(item3);
menu.append(item4);
menu.show_all();
}
private void add_to_playlist_submenu(Gtk.Menu submenu, string line)
{
var directory = GLib.File.new_for_path (playlist_path);
try
{
var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
FileInfo file_info;
while ((file_info = enumerator.next_file ()) != null)
{
GLib.File path = enumerator.get_child (file_info);
if( file_info.get_name ().has_suffix(".babe"))
{
var item= new Gtk.MenuItem.with_label(file_info.get_name ().replace(".babe",""));
submenu.append(item);
item.activate.connect(()=>{
print(item.get_label());
add_to_playlist(line, item.get_label()+".babe");
});
}
}
} catch (GLib.Error e)
{
stderr.printf ("Error: %s\n", e.message);
}
}
public void set_playlists()
{ string line;
var directory = GLib.File.new_for_path (playlist_path);
if (!(directory.query_exists()))
{
try
{
directory.make_directory();
}catch(GLib.Error e)
{
print("clound't create Playlist dir");
}
}
try
{
var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 0);
FileInfo file_info;
while ((file_info = enumerator.next_file ()) != null)
{
GLib.File path = enumerator.get_child (file_info);
if( file_info.get_name ().has_suffix(".babe"))
{
line=file_info.get_name ();
playlist=new BList(true,"./Playlist/"+file_info.get_name ());
playlist_list.populate(line, playlist);
list_selected(playlist.get_treeview(),playlist.get_liststore());
}
}
} catch (GLib.Error e)
{
stderr.printf ("Error: %s\n", e.message);
}
}
public bool list_store(Gtk.Widget widget, Gdk.EventButton event)
{
if (event.type == Gdk.EventType.BUTTON_PRESS && event.button == 3)
{
print("oooooootyyyy");
}else
{
var list=(BList) widget;
list.proff();
var aux=list.get_liststore();
}
return true;
}
public void add_to_playlist(string song_uri, string path )
{
string full_path=playlist_path+path;
FileStream file = FileStream.open (full_path,"a");
assert (file != null);
file.puts (song_uri+"\n");
status_label.label="Song added!";
//playlist.populate(song_uri);
notify("Song added to playlist!",get_song_info(song_uri).tag.title+" \xe2\x99\xa1 "+get_song_info(song_uri).tag.artist);
}
private void on_row_activated (Gtk.TreeView treeview, Gtk.TreePath path, Gtk.TreeViewColumn column) //double click starts playback
{
previous_model=model;
model=treeview.get_model();
if (treeview.model.get_iter (out iter, path)) {
model.get (iter,
4, out title,
1, out artist,
2, out song,
3, out album);
start_playback_actions();
}
//skipping songs
next_icon_event.button_press_event.connect (() => {
get_next_song();
notify(title,artist+" \xe2\x99\xa1 "+album);
return true;
});
previous_icon_event.button_press_event.connect (() => {
get_previous_song();
notify(title,artist+" \xe2\x99\xa1 "+album);
return true;
});
//check end of stream to start the next song
babe_stream.playbin.bus.add_watch (0, (bus, msg) => {
if (msg.type == Gst.MessageType.EOS)
{
get_next_song();
}
return true;
});
}
public bool test(string testing)
{
print("the test on: "+testing);
return true;
}
public Gtk.ListStore get_liststore(Gtk.TreeModel model)
{
if(model==main_list.get_liststore())
{
return main_list.get_liststore();
}else if(model==babes_list.get_liststore())
{
return babes_list.get_liststore();
}else if(model==queue_list.get_liststore())
{
return queue_list.get_liststore();
}else if(model==playlist.get_liststore())
{
return playlist.get_liststore();
} else
{return null;
}
}
public BList get_BList_object(Gtk.TreeModel model)
{
if(model==main_list.get_liststore())
{
return main_list;
}else if(model==babes_list.get_liststore())
{
return babes_list;
}else if(model==queue_list.get_liststore())
{
return queue_list;
}else
{return null;
}