~audience-members/audience/trunk

« back to all changes in this revision

Viewing changes to src/Widgets/TagView.vala

  • Committer: Cody Garver
  • Author(s): Daniel Fore, Corentin Noël, Robert Roth, Corentin Noël, Tom Beckmann, Cody Garver, Daniel Foré
  • Date: 2014-07-19 22:14:06 UTC
  • mfrom: (333.1.22 gtk-3.12)
  • Revision ID: cody_garver-20140719221406-se3ipec1aleu4vah
Ported all UI widgets to pure Gtk 3.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/*
3
 
  The panel on the right hand side
4
 
*/
5
 
 
6
 
public const string LIGHT_WINDOW_STYLE = """
7
 
    .content-view-window {
8
 
        background-image:none;
9
 
        background-color:@bg_color;
10
 
        
11
 
        border-radius: 6px;
12
 
        
13
 
        border-width:1px;
14
 
        border-style: solid;
15
 
        border-color: alpha (#000, 0.25);
16
 
    }
17
 
""";
18
 
 
19
 
namespace Audience.Widgets
20
 
{
21
 
    public class TagView : GtkClutter.Actor
22
 
    {
23
 
        public bool expanded;
24
 
        public Gtk.Grid taggrid;
25
 
        public Audience.App app;
26
 
        
27
 
        public Gtk.ComboBoxText languages;
28
 
        public Gtk.ComboBoxText subtitles;
29
 
        private Gtk.FileChooserButton external_subtitle_file;
30
 
        
31
 
        private Granite.Drawing.BufferSurface buffer;
32
 
        int shadow_blur = 30;
33
 
        int shadow_x    = 0;
34
 
        int shadow_y    = 0;
35
 
        double shadow_alpha = 0.5;
36
 
 
37
 
        bool currently_parsing = false;
38
 
 
39
 
        public signal void select_external_subtitle (string uri);
40
 
        
41
 
        public TagView (Audience.App app) {
42
 
            this.app      = app;
43
 
            this.reactive = true;
44
 
            this.buffer   = new Granite.Drawing.BufferSurface (100, 100);
45
 
            
46
 
            var notebook = new Granite.Widgets.StaticNotebook (false);
47
 
            
48
 
            /*tags*/
49
 
            var tagview = new Gtk.ScrolledWindow (null, null);
50
 
            taggrid = new Gtk.Grid ();
51
 
            taggrid.column_spacing = 10;
52
 
            taggrid.margin = 12;
53
 
            tagview.add_with_viewport (taggrid);
54
 
            
55
 
            /*setup*/
56
 
            var setupgrid  = new Gtk.Grid ();
57
 
            this.languages = new Gtk.ComboBoxText ();
58
 
            this.subtitles = new Gtk.ComboBoxText ();
59
 
            this.external_subtitle_file = new Gtk.FileChooserButton (_("External Subtitles"), Gtk.FileChooserAction.OPEN);
60
 
            var lang_lbl   = new LLabel.right (_("Audio")+":");
61
 
            var sub_lbl    = new LLabel.right (_("Subtitles")+":");
62
 
            var sub_ext_lbl = new LLabel.right (_("External Subtitles") + ":");
63
 
            setupgrid.attach (lang_lbl,  0, 1, 1, 1);
64
 
            setupgrid.attach (languages,                   1, 1, 1, 1);
65
 
            setupgrid.attach (sub_lbl, 0, 2, 1, 1);
66
 
            setupgrid.attach (subtitles,                   1, 2, 1, 1);
67
 
            setupgrid.attach (sub_ext_lbl, 0, 3, 1, 1);
68
 
            setupgrid.attach (this.external_subtitle_file, 1, 3, 1, 1);
69
 
            setupgrid.column_homogeneous = true;
70
 
            setupgrid.margin = 12;
71
 
            setupgrid.column_spacing = 12;
72
 
            
73
 
            external_subtitle_file.file_set.connect (() => {
74
 
                select_external_subtitle (external_subtitle_file.get_uri ());
75
 
            });
76
 
            app.video_player.external_subtitle_changed.connect ( (uri) => {
77
 
                external_subtitle_file.set_uri (uri);
78
 
            });
79
 
            this.subtitles.changed.connect ( () => {
80
 
                if (subtitles.active_id == null || currently_parsing)
81
 
                    return;
82
 
                var id = int.parse (this.subtitles.active_id);
83
 
                app.video_player.current_text = id;
84
 
            });
85
 
            
86
 
            languages.changed.connect ( () => { //place it here to not get problems
87
 
                if (languages.active_id == null || currently_parsing)
88
 
                    return;
89
 
                app.video_player.current_audio = int.parse (this.languages.active_id);
90
 
            });
91
 
            
92
 
            var playlist_scrolled = new Gtk.ScrolledWindow (null, null);
93
 
            playlist_scrolled.add (this.app.playlist);
94
 
            
95
 
            notebook.append_page (playlist_scrolled, new Gtk.Label (_("Playlist")));
96
 
            notebook.append_page (setupgrid, new Gtk.Label (_("Options")));
97
 
            
98
 
            /*draw the window stylish!*/
99
 
            var css = new Gtk.CssProvider ();
100
 
            try {
101
 
                css.load_from_data (LIGHT_WINDOW_STYLE, -1);
102
 
            } catch (Error e) { warning (e.message); }
103
 
            
104
 
            var draw_ref = new Gtk.Window ();
105
 
            draw_ref.get_style_context ().add_class ("content-view-window");
106
 
            draw_ref.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
107
 
            
108
 
            var w = -1; var h = -1;
109
 
            this.get_widget ().size_allocate.connect ( () => {
110
 
                if (w == this.get_widget ().get_allocated_width () && 
111
 
                    h == this.get_widget ().get_allocated_height ())
112
 
                    return;
113
 
                w = this.get_widget ().get_allocated_width ();
114
 
                h = this.get_widget ().get_allocated_height ();
115
 
                
116
 
                this.buffer = new Granite.Drawing.BufferSurface (w, h);
117
 
                
118
 
                this.buffer.context.rectangle (shadow_blur + shadow_x, 
119
 
                    shadow_blur + shadow_y, w - shadow_blur*2 + shadow_x, h - shadow_blur*2 + shadow_y);
120
 
                this.buffer.context.set_source_rgba (0, 0, 0, shadow_alpha);
121
 
                this.buffer.context.fill ();
122
 
                this.buffer.exponential_blur (shadow_blur / 2);
123
 
                
124
 
                draw_ref.get_style_context ().render_activity (this.buffer.context, 
125
 
                    shadow_blur + shadow_x, shadow_blur + shadow_y, 
126
 
                    w - shadow_blur*2 + shadow_x, h - shadow_blur*2 + shadow_y);
127
 
            });
128
 
            this.get_widget ().draw.connect ( (ctx) => {
129
 
                ctx.set_operator (Cairo.Operator.SOURCE);
130
 
                ctx.rectangle (0, 0, this.width, this.height);
131
 
                ctx.set_source_rgba (0.0, 0.0, 0.0, 0.0);
132
 
                ctx.fill ();
133
 
                
134
 
                ctx.set_source_surface (this.buffer.surface, 0, 0);
135
 
                ctx.paint ();
136
 
                
137
 
                return false;
138
 
            });
139
 
            
140
 
            var no_bg = new Gtk.CssProvider ();
141
 
            try {
142
 
                no_bg.load_from_data ("""
143
 
                * {
144
 
                    background-color: alpha(#fff, 0);
145
 
                }
146
 
                .view:selected:focused {
147
 
                    color: @selected_bg_color;
148
 
                }
149
 
                """, -1);
150
 
            } catch (Error e) { warning (e.message); }
151
 
            setupgrid.get_parent ().get_style_context ().add_provider (no_bg, 20000);
152
 
            app.playlist.get_style_context ().add_provider (no_bg, 20000);
153
 
            
154
 
            playlist_scrolled.margin = 3;
155
 
            notebook.margin = shadow_blur + 2;
156
 
            notebook.margin_top += 3;
157
 
            this.get_widget ().get_style_context ().add_class ("content-view");
158
 
            ((Gtk.Bin)this.get_widget ()).add (notebook);
159
 
            this.get_widget ().show_all ();
160
 
            this.width = 350;
161
 
            this.opacity = 0;
162
 
            this.expanded = false;
163
 
        }
164
 
        
165
 
        public override void allocate (Clutter.ActorBox box, Clutter.AllocationFlags flags) {
166
 
            //have a minimum height in order to not get the negative allocation warnings
167
 
            if (box.y2 - box.y1 < 100) {
168
 
                box.y2 = box.y1 + 100;
169
 
            }
170
 
            base.allocate (box, flags);
171
 
        }
172
 
        
173
 
        public void expand (){
174
 
            //make sure it comes from right bounds
175
 
            x = get_stage ().width + 100;
176
 
            
177
 
            var x2 = this.get_stage ().width - this.width + 10;
178
 
            this.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 400, x:x2);
179
 
            this.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 400, opacity:255);
180
 
            this.expanded = true;
181
 
        }
182
 
        
183
 
        public void collapse (){
184
 
            var x2 = this.get_stage ().width;
185
 
            this.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 400, x:x2);
186
 
            this.animate (Clutter.AnimationMode.EASE_OUT_QUAD, 400, opacity:0);
187
 
            this.expanded = false;
188
 
        }
189
 
        
190
 
        public void setup_text_setup  () { setup_setup ("text"); }
191
 
        public void setup_audio_setup () { setup_setup ("audio"); }
192
 
        /*target is either "text" or "audio"*/
193
 
        public void setup_setup (string target) {
194
 
            currently_parsing = true;
195
 
            
196
 
            if (target == "audio" && languages.model.iter_n_children (null) > 0)
197
 
                languages.remove_all ();
198
 
            else if (target == "text" && subtitles.model.iter_n_children (null) > 0)
199
 
                subtitles.remove_all ();
200
 
            
201
 
            Value num = 0;
202
 
            app.video_player.playbin.get_property ("n-"+target, ref num);
203
 
            
204
 
            int used = 0;
205
 
            for (var i=0;i<num.get_int ();i++) {
206
 
                Gst.TagList tags = null;
207
 
                Signal.emit_by_name (app.video_player.playbin, "get-"+target+"-tags", i, out tags);
208
 
                if (tags == null)
209
 
                    continue;
210
 
                
211
 
                string desc;
212
 
                string readable = null;
213
 
                tags.get_string (Gst.Tags.LANGUAGE_CODE, out desc);
214
 
                if (desc == null)
215
 
                    tags.get_string (Gst.Tags.CODEC, out desc);
216
 
 
217
 
                if (desc != null)
218
 
                    readable = Gst.Tag.get_language_name (desc);
219
 
 
220
 
                if (target == "audio" && desc != null) {
221
 
                    this.languages.append (i.to_string (), readable == null ? desc : readable);
222
 
                    used ++;
223
 
                } else if (desc != null) {
224
 
                    var language = Gst.Tag.get_language_name (desc);
225
 
                    this.subtitles.append (i.to_string (), language == null ? desc : language);
226
 
                    used ++;
227
 
                }
228
 
            }
229
 
 
230
 
            if (target == "audio") {
231
 
                
232
 
                if (used == 0) {
233
 
                    languages.append ("def", _("Default"));
234
 
                    languages.active = 0;
235
 
                    languages.sensitive = false;
236
 
                } else {
237
 
                    languages.sensitive = true;
238
 
                    languages.active_id = app.video_player.current_audio.to_string ();
239
 
                }
240
 
            } else {
241
 
                if (used == 0)
242
 
                    subtitles.sensitive = false;
243
 
                else
244
 
                    subtitles.sensitive = true;
245
 
                
246
 
                subtitles.append ("-1", _("None"));
247
 
                subtitles.active_id = app.video_player.current_text.to_string ();
248
 
            }
249
 
 
250
 
            currently_parsing = false;
251
 
        }
252
 
    }
253
 
}