~ubuntu-branches/ubuntu/vivid/gmpc/vivid-proposed

« back to all changes in this revision

Viewing changes to .pc/0006-Fix-MetaData-object-vala-binding.-fix-vala-13.3-buil.patch/src/vala/gmpc-test-plugin.vala

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2011-12-18 16:09:43 UTC
  • Revision ID: package-import@ubuntu.com-20111218160943-9vk3xroitg1dm0j1
Tags: 11.8.16-2
* Install user manual (Closes: #647701)
* New patches :
    - Change volume slider sensitivity (Closes: #646803)
    - Bring back images for transport buttons (Closes: #646822)
    - Fix build with valac 0.14 (Thanks to Michael Biebl, Closes: #650219)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Gnome Music Player Client (GMPC)
 
2
 * Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
 
3
 * Project homepage: http://gmpclient.org/
 
4
 
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
*/
 
19
 
 
20
using Config;
 
21
using Gtk;
 
22
using Gmpc;
 
23
 
 
24
private const bool use_transition_tp = Gmpc.use_transition;
 
25
 
 
26
public class Gmpc.MetaData.EditWindow : Gtk.Window {
 
27
    private const string some_unique_name = Config.VERSION;
 
28
    private MPD.Song? song = null;
 
29
    private Gmpc.MetaData.Type query_type = Gmpc.MetaData.Type.ALBUM_ART;
 
30
 
 
31
    private GLib.List<unowned Gmpc.AsyncDownload.Handle> downloads = null;
 
32
    /** fetching handles */
 
33
    private void *handle = null;
 
34
    private void *handle2 = null;
 
35
 
 
36
    private Gtk.HBox pbox = null;
 
37
    private Gtk.Label warning_label = null;
 
38
    private Gtk.Entry artist_entry;
 
39
    private Gtk.Entry album_entry;
 
40
    private Gtk.Entry title_entry;
 
41
    private Gtk.Button cancel = null;
 
42
    private Gtk.Button refresh = null;
 
43
    private Gtk.ComboBox combo = null;
 
44
    private Gtk.ProgressBar bar = null;
 
45
 
 
46
    private Gtk.ScrolledWindow sw = null;
 
47
    private Gtk.EventBox ilevent = null;
 
48
    
 
49
    private Gtk.VBox itemslist = new Gtk.VBox(false, 6);
 
50
 
 
51
    construct {
 
52
        this.type = Gtk.WindowType.TOPLEVEL;
 
53
        int height = config.get_int_with_default(
 
54
                "Metadata Selector" , "window_height", 600);
 
55
        int width = config.get_int_with_default(
 
56
                "Metadata Selector" , "window_width", 480);
 
57
 
 
58
        this.resize(width,height);
 
59
        this.set_border_width(8);
 
60
        /* Connect to allocation changes so I can store new size */
 
61
        this.size_allocate.connect((source, alloc) => {
 
62
                config.set_int(
 
63
                    "Metadata Selector" , "window_width", alloc.width);
 
64
 
 
65
                config.set_int(
 
66
                    "Metadata Selector" , "window_height", alloc.height);
 
67
        });
 
68
    }
 
69
 
 
70
    private void add_entry_image(string? provider, string uri,Gdk.PixbufFormat? format, Gdk.Pixbuf pb, bool is_raw = false, bool is_thumbnail = false)
 
71
    {
 
72
        string a;
 
73
        a = "";// Markup.printf_escaped("<b>%s</b>: %s",_("Uri"),uri);
 
74
        if(provider != null) {
 
75
            a+= Markup.printf_escaped("\n<b>%s</b>:  %s",_("Provider"), provider);
 
76
        }
 
77
        if(format != null)
 
78
        {
 
79
            a+= Markup.printf_escaped("\n<b>%s</b>: %s",_("Filetype"), format.get_name());
 
80
        }
 
81
        if(pb != null)
 
82
        {
 
83
            if(is_thumbnail) {
 
84
                a+="\n<b>%s</b>: %ix%i (%s) (%s)".printf(_("Size"), pb.width, pb.height,_("width x height"), 
 
85
                        _("high-res image will be downloaded"));
 
86
            }else{
 
87
                a+="\n<b>%s</b>: %ix%i (%s)".printf(_("Size"), pb.width, pb.height,_("width x height"));
 
88
           }
 
89
 
 
90
        }
 
91
        int new_h, new_w;
 
92
        if(pb.width < pb.height) {
 
93
            new_h = 150;
 
94
            new_w = (int)((150.0/(double)pb.height)*pb.width);
 
95
        }
 
96
        else
 
97
        {
 
98
            new_w = 150;
 
99
            new_h = (int)((150.0/(double)pb.width)*pb.height);
 
100
        }
 
101
 
 
102
 
 
103
        var hbox = new Gtk.HBox(false, 6);
 
104
        var label = new Gtk.Label("");
 
105
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE);
 
106
        label.set_markup(a);
 
107
        label.set_line_wrap(true);
 
108
        label.set_alignment(0.0f, 0.5f);
 
109
 
 
110
        var image = new Gtk.Image.from_pixbuf(pb.scale_simple(new_w,new_h,Gdk.InterpType.BILINEAR));
 
111
        image.set_size_request(180,-1);
 
112
        hbox.pack_start(image, false, true, 0);
 
113
        hbox.pack_start(label, true, true, 0);
 
114
 
 
115
        
 
116
        var ali = new Gtk.Alignment(0f,0f,0f,0f);
 
117
        var button = new Gtk.Button.with_label(_("Set"));
 
118
        if(!is_raw) {
 
119
            button.set_data_full("path",(void *)uri.dup(),(GLib.DestroyNotify)g_free);
 
120
        }else{
 
121
            button.set_data_full("data",(void *)uri.dup(),(GLib.DestroyNotify)g_free);
 
122
        }
 
123
        ali.add(button);
 
124
        hbox.pack_start(ali, false, true, 0);
 
125
        button.clicked.connect(set_metadata);
 
126
 
 
127
        hbox.show_all();
 
128
        this.itemslist.pack_start(hbox,false, true, 0);
 
129
        var sep = new Gtk.HSeparator();
 
130
        sep.set_size_request(-1, 4);
 
131
        sep.show();
 
132
        this.itemslist.pack_start(sep, false, true, 0);
 
133
 
 
134
    }
 
135
 
 
136
    private void add_entry_text(string? provider, string uri,string text) 
 
137
    {
 
138
        string a;
 
139
        a = "";// "<b>%s</b>: %s".printf(_("Uri"),uri);
 
140
        if(provider != null) {
 
141
            a+="\n<b>%s</b>:  %s".printf(_("Provider"), provider);
 
142
        }
 
143
        var hbox = new Gtk.HBox(false, 6);
 
144
        var label = new Gtk.Label("");
 
145
        label.set_markup(a);
 
146
        label.set_ellipsize(Pango.EllipsizeMode.MIDDLE);
 
147
        label.set_line_wrap(true);
 
148
        label.set_alignment(0.0f, 0.0f);
 
149
        label.set_size_request(280,-1);
 
150
        hbox.pack_start(label, false, true, 0);
 
151
        
 
152
        var text_label = new Gtk.Label(text); 
 
153
        text_label.set_ellipsize(Pango.EllipsizeMode.END);
 
154
        text_label.set_alignment(0.0f, 0.0f);
 
155
        text_label.set_size_request(180,-1);
 
156
        hbox.pack_start(text_label, true, true, 0);
 
157
 
 
158
        var ali = new Gtk.Alignment(0f,0f,0f,0f);
 
159
        var button = new Gtk.Button.with_label(_("Set"));
 
160
        button.set_data_full("lyrics",(void *)text.dup(),(GLib.DestroyNotify)g_free);
 
161
        ali.add(button);
 
162
        hbox.pack_start(ali, false, true, 0);
 
163
        button.clicked.connect(set_metadata);
 
164
 
 
165
        hbox.show_all();
 
166
        this.itemslist.pack_start(hbox,false, true, 0);
 
167
        var sep = new Gtk.HSeparator();
 
168
        sep.set_size_request(-1, 4);
 
169
        sep.show();
 
170
        this.itemslist.pack_start(sep, false, true, 0);
 
171
    }
 
172
 
 
173
    public void image_downloaded(Gmpc.AsyncDownload.Handle handle, Gmpc.AsyncDownload.Status status, void *p)
 
174
    {
 
175
        MetaData.Item *item = (MetaData.Item *)p;
 
176
        GLib.assert(item != null);
 
177
        if(status == Gmpc.AsyncDownload.Status.PROGRESS) return;
 
178
        this.downloads.remove(handle);
 
179
        this.bar.pulse();
 
180
        if(status == Gmpc.AsyncDownload.Status.DONE)
 
181
        {
 
182
            unowned uchar[] data = handle.get_data<uchar[]>();
 
183
            if(this.query_type == Gmpc.MetaData.Type.ALBUM_ART || this.query_type == Gmpc.MetaData.Type.ARTIST_ART)
 
184
            {
 
185
                try{
 
186
                    var load = new Gdk.PixbufLoader();
 
187
                    try {
 
188
                        load.write(data);
 
189
                    }catch (Error e) {
 
190
                        GLib.debug("Failed to load file: %s::%s\n",e.message,handle.get_uri());
 
191
                    }
 
192
                    load.close();
 
193
 
 
194
                    Gdk.Pixbuf pb = load.get_pixbuf();
 
195
                    if(pb!= null)
 
196
                        this.add_entry_image((string)handle.get_user_data(),
 
197
                                            item->get_uri(),
 
198
                                            load.get_format(),
 
199
                                            pb,
 
200
                                            false,
 
201
                                            (item->get_thumbnail_uri() != null));
 
202
                }catch (Error e) {
 
203
                    GLib.debug("Failed to load file: %s::%s\n",e.message,handle.get_uri());
 
204
                }
 
205
            }
 
206
            else
 
207
            {
 
208
                this.add_entry_text((string)handle.get_user_data(),handle.get_uri(),(string)data);
 
209
            }
 
210
        }
 
211
        
 
212
        if(this.handle == null && this.handle2 == null && this.downloads == null)
 
213
        {
 
214
            this.pbox.hide();
 
215
            this.refresh.sensitive = true;
 
216
            this.ilevent.sensitive = true;
 
217
            this.combo.sensitive = true;
 
218
        }
 
219
        delete item;
 
220
    }
 
221
    public void callback(void *handle,string? plugin_name,GLib.List<MetaData.Item>? list)
 
222
    {
 
223
        bar.pulse();
 
224
        if(list == null) {
 
225
            if(this.handle == handle)
 
226
            {
 
227
                this.handle = null;
 
228
                if(this.handle == null && this.downloads == null)
 
229
                {
 
230
                    this.pbox.hide();
 
231
                    this.refresh.sensitive = true;
 
232
                    this.ilevent.sensitive = true;
 
233
                    this.combo.sensitive = true;
 
234
                }
 
235
            }
 
236
            if(this.handle2 == handle)
 
237
            {
 
238
                this.handle2 = null;
 
239
 
 
240
 
 
241
                if(this.handle == null && this.downloads == null)
 
242
                {
 
243
                    this.pbox.hide();
 
244
                    this.combo.sensitive = true;
 
245
                    this.ilevent.sensitive = true;
 
246
                    this.refresh.sensitive = true;
 
247
                }
 
248
            }
 
249
        }
 
250
        foreach(unowned MetaData.Item md in list)
 
251
        {
 
252
 
 
253
            if(this.query_type == Gmpc.MetaData.Type.ALBUM_ART || this.query_type == Gmpc.MetaData.Type.ARTIST_ART)
 
254
            {
 
255
                if(md.content_type == Gmpc.MetaData.ContentType.URI)
 
256
                {
 
257
                    if(md.content_type == Gmpc.MetaData.ContentType.URI)
 
258
                    {
 
259
                        unowned string uri = null;
 
260
                        if(md.get_thumbnail_uri() != null) {
 
261
                            uri = md.get_thumbnail_uri();
 
262
                        }else{
 
263
                            uri = md.get_uri();
 
264
                        }
 
265
                        if(uri[0] == '/'){
 
266
                            try{
 
267
                                Gdk.Pixbuf pb = new Gdk.Pixbuf.from_file(uri);
 
268
                                if(pb != null)
 
269
                                {
 
270
                                    int w,h;
 
271
                                    add_entry_image(plugin_name, uri,Gdk.Pixbuf.get_file_info(uri,out w, out h), pb);
 
272
                                }
 
273
                            }catch(Error e)
 
274
                            {
 
275
 
 
276
                            }
 
277
                        }else{
 
278
                            MetaData.Item *item = MetaData.Item.copy(md);
 
279
                            var h =  Gmpc.AsyncDownload.download_vala(uri,(void *)item,image_downloaded);                                 
 
280
                            if(h!=null)
 
281
                            {
 
282
                                h.set_user_data(md.plugin_name);
 
283
                                this.downloads.append(h);
 
284
                            } 
 
285
                        }
 
286
                    }
 
287
                }else if (md.content_type == Gmpc.MetaData.ContentType.RAW){
 
288
                  var data = md.get_raw();  
 
289
                    var load = new Gdk.PixbufLoader();
 
290
                    try {
 
291
                        load.write(data);
 
292
                    }catch (Error e) {
 
293
                        GLib.debug("Failed to load raw data: %s\n",e.message);
 
294
                    }
 
295
                    try {
 
296
                        load.close();
 
297
                    }catch (Error e) {
 
298
                        GLib.debug("Failed to close loader: %s\n",e.message);
 
299
                    }
 
300
 
 
301
                    Gdk.Pixbuf pb = load.get_pixbuf();
 
302
                    if(pb!= null){
 
303
                        var base16 = GLib.Base64.encode(data); 
 
304
                        this.add_entry_image(plugin_name,base16,load.get_format(),pb,true);
 
305
                    }
 
306
                }
 
307
            }else{
 
308
 
 
309
                if(md.content_type == Gmpc.MetaData.ContentType.TEXT)
 
310
                {
 
311
                    unowned string uri = md.get_text();
 
312
                    add_entry_text(plugin_name, "n/a", uri);
 
313
                }
 
314
                else 
 
315
                if(md.content_type == Gmpc.MetaData.ContentType.HTML)
 
316
                {
 
317
                    string uri = md.get_text_from_html();
 
318
                    add_entry_text(plugin_name, "n/a", uri);
 
319
                }
 
320
                else
 
321
                if(md.content_type == Gmpc.MetaData.ContentType.URI)
 
322
                {
 
323
                    unowned string uri = md.get_uri();
 
324
                    if(uri[0] == '/'){
 
325
                        try {
 
326
                            string content;
 
327
                            if(GLib.FileUtils.get_contents(uri,out content))
 
328
                            {
 
329
                               add_entry_text(plugin_name,uri, content);
 
330
                            }
 
331
                        }catch (Error e) {
 
332
 
 
333
                        }
 
334
                    }
 
335
 
 
336
                }
 
337
            }
 
338
 
 
339
        }
 
340
    }
 
341
 
 
342
    public void store_image(Gmpc.AsyncDownload.Handle handle, Gmpc.AsyncDownload.Status status)
 
343
    {
 
344
        if(status == Gmpc.AsyncDownload.Status.PROGRESS){
 
345
            unowned uchar[] data =handle.get_data<uchar[]>();
 
346
            this.sensitive = false;
 
347
            this.pbox.show();
 
348
            int64 total_size = handle.get_content_size(); 
 
349
            if(data.length > 0 && total_size > 0){
 
350
                double progress = data.length/(double)total_size;
 
351
                this.bar.set_fraction(progress);
 
352
            }
 
353
            else this.bar.pulse();
 
354
            return;
 
355
        }
 
356
        this.downloads.remove(handle);
 
357
        if(status == Gmpc.AsyncDownload.Status.DONE)
 
358
        {
 
359
            unowned uchar[] data = handle.get_data<uchar[]>();
 
360
            var file = Gmpc.MetaData.get_metadata_filename(this.query_type, this.song,null); 
 
361
            try {
 
362
                GLib.FileUtils.set_contents(file, (string)data, (long)data.length);
 
363
                var met = new MetaData.Item();
 
364
                met.type = this.query_type;
 
365
                met.plugin_name = "User set";
 
366
                met.content_type = MetaData.ContentType.URI;
 
367
                met.set_uri(file);
 
368
                Gmpc.MetaData.set_metadata(this.song, Gmpc.MetaData.Result.AVAILABLE, met); 
 
369
    
 
370
                var met_false = new MetaData.Item();
 
371
                met_false.type = this.query_type;
 
372
                met_false.plugin_name = "User set";
 
373
                met_false.content_type = MetaData.ContentType.EMPTY;
 
374
                metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.UNAVAILABLE, met_false);  
 
375
                metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.AVAILABLE, met);  
 
376
            }catch (Error e) {
 
377
 
 
378
            }
 
379
        }
 
380
        this.pbox.hide();
 
381
        this.sensitive = true;
 
382
 
 
383
    }
 
384
    private void
 
385
    set_metadata(Gtk.Button button)
 
386
    {
 
387
        string path = null;
 
388
        if(this.query_type == Gmpc.MetaData.Type.ALBUM_ART || this.query_type == Gmpc.MetaData.Type.ARTIST_ART)
 
389
        {
 
390
            path = (string)button.get_data<string>("path");
 
391
            if(path != null)
 
392
            {
 
393
                if(path[0]  == '/')
 
394
                {
 
395
                    var met = new MetaData.Item();
 
396
                    met.type = this.query_type;
 
397
                    met.plugin_name = "User set";
 
398
                    met.content_type = MetaData.ContentType.URI;
 
399
                    met.set_uri(path);
 
400
                    Gmpc.MetaData.set_metadata(this.song, Gmpc.MetaData.Result.AVAILABLE, met); 
 
401
 
 
402
                    var met_false = new MetaData.Item();
 
403
                    met_false.type = this.query_type;
 
404
                    met_false.plugin_name = "User set";
 
405
                    met_false.content_type = MetaData.ContentType.EMPTY;
 
406
                    metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.UNAVAILABLE, met_false);  
 
407
                    metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.AVAILABLE, met);  
 
408
                }else{
 
409
                    var h = Gmpc.AsyncDownload.download(path, store_image); 
 
410
                    if(h!=null)
 
411
                        this.downloads.append(h);
 
412
                }
 
413
            }else{
 
414
                string base64 =(string)button.get_data<string>("data");
 
415
                if(base64 != null) {
 
416
                    string filename = Gmpc.MetaData.get_metadata_filename(this.query_type,this.song, null); 
 
417
                    uchar[] data = GLib.Base64.decode(base64 );
 
418
                    try{
 
419
                    GLib.FileUtils.set_contents(filename, (string)data, (ssize_t)data.length);
 
420
 
 
421
                    var met = new MetaData.Item();
 
422
                    met.type = this.query_type;
 
423
                    met.plugin_name = "User set";
 
424
                    met.content_type = MetaData.ContentType.URI;
 
425
                    met.set_uri(filename);
 
426
                    Gmpc.MetaData.set_metadata(this.song, Gmpc.MetaData.Result.AVAILABLE, met); 
 
427
 
 
428
                    var met_false = new MetaData.Item();
 
429
                    met_false.type = this.query_type;
 
430
                    met_false.plugin_name = "User set";
 
431
                    met_false.content_type = MetaData.ContentType.EMPTY;
 
432
                    metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.UNAVAILABLE, met_false);  
 
433
                    metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.AVAILABLE, met);  
 
434
                    }catch (Error e) {
 
435
 
 
436
                    }
 
437
                }
 
438
            }
 
439
        }else{
 
440
            string lyric;
 
441
 
 
442
            lyric = (string)button.get_data<string>("lyrics");
 
443
            var file = Gmpc.MetaData.get_metadata_filename(this.query_type, this.song,null); 
 
444
            try {
 
445
                GLib.FileUtils.set_contents(file,lyric, -1); 
 
446
                var met = new MetaData.Item();
 
447
                met.type = this.query_type;
 
448
                met.plugin_name = "User set";
 
449
                met.content_type = MetaData.ContentType.URI;
 
450
                met.set_uri(file);
 
451
                Gmpc.MetaData.set_metadata(this.song, Gmpc.MetaData.Result.AVAILABLE, met); 
 
452
 
 
453
                var met_false = new MetaData.Item();
 
454
                met_false.type = this.query_type;
 
455
                met_false.plugin_name = "User set";
 
456
                met_false.content_type = MetaData.ContentType.EMPTY;
 
457
                metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.UNAVAILABLE, met_false);  
 
458
                metawatcher.data_changed(this.song, this.query_type, Gmpc.MetaData.Result.AVAILABLE, met);  
 
459
            }catch (Error e) {
 
460
 
 
461
            }
 
462
 
 
463
 
 
464
        }
 
465
    }
 
466
    public
 
467
    void
 
468
    destroy_popup(Gtk.Button button)
 
469
    {
 
470
        this.destroy();
 
471
    }
 
472
    private void clear_itemslist()
 
473
    {
 
474
        foreach(Gtk.Widget client in this.itemslist.get_children())
 
475
        {
 
476
           client.destroy();
 
477
        }
 
478
 
 
479
    }
 
480
    public void refresh_query(Gtk.Button button) 
 
481
    {
 
482
        clear_itemslist();
 
483
        GLib.log("MetadataSelector", GLib.LogLevelFlags.LEVEL_DEBUG, "Query metadata");
 
484
        MPD.Song ss = this.song.copy();
 
485
        ss.artist = this.artist_entry.get_text();
 
486
        ss.album = this.album_entry.get_text();
 
487
        ss.title = this.title_entry.get_text();
 
488
 
 
489
        if(this.handle == null && this.handle2 == null) {
 
490
            this.pbox.show();
 
491
            this.refresh.sensitive = false;
 
492
            this.combo.sensitive = false;
 
493
            this.ilevent.sensitive = false;
 
494
            GLib.log("MetadataSelector", GLib.LogLevelFlags.LEVEL_DEBUG,"Start metdata get_list query");
 
495
            this.handle = Gmpc.MetaData.get_list(ss, this.query_type, callback);
 
496
            GLib.log("MetadataSelector", GLib.LogLevelFlags.LEVEL_DEBUG,"Wait");
 
497
        }
 
498
        
 
499
    }
 
500
    private void combo_box_changed(Gtk.ComboBox comb)
 
501
    {
 
502
        clear_itemslist();
 
503
        int active = comb.active;
 
504
        this.title_entry.sensitive = false;
 
505
        this.album_entry.sensitive = false;
 
506
        this.artist_entry.sensitive = false;
 
507
        this.refresh.sensitive = false;
 
508
        this.warning_label.hide();
 
509
        if(active == 0)
 
510
        {
 
511
           this.query_type = Gmpc.MetaData.Type.ARTIST_ART;  
 
512
           if(this.song.artist != null)
 
513
           {
 
514
                this.artist_entry.sensitive = true;
 
515
                this.refresh.sensitive = true;
 
516
           }
 
517
           else this.warning_label.show();
 
518
        }else  if (active == 1) {
 
519
           this.query_type = Gmpc.MetaData.Type.ALBUM_ART;  
 
520
 
 
521
           if(this.song.artist != null && this.song.album != null)
 
522
           {
 
523
                this.artist_entry.sensitive = true;
 
524
                this.album_entry.sensitive = true;
 
525
                this.refresh.sensitive = true;
 
526
           }
 
527
           else this.warning_label.show();
 
528
        } else  if (active == 2) {
 
529
           this.query_type = Gmpc.MetaData.Type.SONG_TXT;  
 
530
 
 
531
           if(this.song.artist != null && this.song.title != null)
 
532
           {
 
533
                this.artist_entry.sensitive = true;
 
534
                this.title_entry.sensitive = true;
 
535
                this.refresh.sensitive = true;
 
536
           }
 
537
           else this.warning_label.show();
 
538
        }else  if (active == 3) {
 
539
           this.query_type = Gmpc.MetaData.Type.ALBUM_TXT;  
 
540
 
 
541
           if(this.song.artist != null && this.song.album != null)
 
542
           {
 
543
                this.artist_entry.sensitive = true;
 
544
                this.album_entry.sensitive = true;
 
545
                this.refresh.sensitive = true;
 
546
           }
 
547
           else this.warning_label.show();
 
548
        }else  if (active == 4) {
 
549
           this.query_type = Gmpc.MetaData.Type.ARTIST_TXT;  
 
550
 
 
551
           if(this.song.artist != null)
 
552
           {
 
553
                this.artist_entry.sensitive = true;
 
554
                this.refresh.sensitive = true;
 
555
           }
 
556
           else this.warning_label.show();
 
557
        }else  if (active == 5) {
 
558
           this.query_type = Gmpc.MetaData.Type.SONG_GUITAR_TAB;  
 
559
 
 
560
           if(this.song.artist != null && this.song.title != null)
 
561
           {
 
562
                this.artist_entry.sensitive = true;
 
563
                this.title_entry.sensitive = true;
 
564
                this.refresh.sensitive = true;
 
565
           }
 
566
           else this.warning_label.show();
 
567
        }
 
568
    }
 
569
 
 
570
    public
 
571
    EditWindow (MPD.Song song, Gmpc.MetaData.Type type) {
 
572
        var vbox = new Gtk.VBox(false, 6);
 
573
        this.song = song.copy();
 
574
        this.query_type = type;
 
575
        this.pbox = new Gtk.HBox(false, 6); 
 
576
        this.bar = new Gtk.ProgressBar();
 
577
        vbox.pack_start(this.pbox, false, false, 0);
 
578
        this.cancel = new Gtk.Button.from_stock("gtk-cancel");
 
579
        this.cancel.clicked.connect(this.b_cancel);
 
580
        this.pbox.pack_start(this.bar, true, true, 0);
 
581
        this.pbox.pack_start(this.cancel, false, false, 0);
 
582
        this.bar.show();
 
583
        this.cancel.show();
 
584
        this.pbox.no_show_all = true;
 
585
        this.pbox.hide();
 
586
 
 
587
        sw = new Gtk.ScrolledWindow(null, null);
 
588
 
 
589
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
 
590
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN);
 
591
        
 
592
 
 
593
        /* Button */
 
594
        var hbox = new Gtk.HBox(false, 6);
 
595
 
 
596
        var button = new Gtk.Button.from_stock("gtk-quit");
 
597
        button.clicked.connect(destroy_popup);
 
598
        hbox.pack_end(button, false, false, 0);
 
599
        vbox.pack_end(hbox, false, false,0);
 
600
 
 
601
        /** Change */
 
602
        this.warning_label = new Gtk.Label("");
 
603
        this.warning_label.set_markup("<span size='x-large'>%s</span>".printf(_("Insufficient information to store/fetch this metadata")));
 
604
        this.warning_label.set_alignment(0.0f, 0.5f);
 
605
        vbox.pack_start(this.warning_label, false, false, 0);
 
606
        this.warning_label.hide();
 
607
 
 
608
        var group = new Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL);
 
609
        var qhbox = new Gtk.HBox(false, 6);
 
610
        Gtk.Label label = null;
 
611
 
 
612
        var list = new Gtk.ListStore(2,typeof(string), typeof(string),-1);
 
613
        list.insert_with_values(null, -1, 0, "media-artist",    1, _("Artist art"));
 
614
        list.insert_with_values(null, -1, 0, "media-album",     1, _("Album art"));
 
615
        list.insert_with_values(null, -1, 0, "gtk-dnd",         1, _("Song lyrics"));
 
616
        list.insert_with_values(null, -1, 0, "media-album",     1, _("Album Info"));
 
617
        list.insert_with_values(null, -1, 0, "media-artist",    1, _("Artist Biography"));
 
618
        list.insert_with_values(null, -1, 0, "media-album",     1, _("Guitar Tab"));
 
619
 
 
620
        this.combo = new Gtk.ComboBox.with_model(list); 
 
621
       
 
622
        Gtk.CellRenderer renderer = new Gtk.CellRendererPixbuf();
 
623
        this.combo.pack_start(renderer,false);
 
624
        this.combo.add_attribute(renderer, "icon-name", 0);
 
625
        renderer = new Gtk.CellRendererText();
 
626
        this.combo.pack_start(renderer,true);
 
627
        this.combo.add_attribute(renderer, "text", 1);
 
628
 
 
629
        qhbox.pack_start(this.combo, true,true,0);
 
630
        this.combo.changed.connect(combo_box_changed);
 
631
 
 
632
        vbox.pack_start(qhbox, false, false, 0);
 
633
       
 
634
        
 
635
        qhbox = new Gtk.HBox(false, 6);
 
636
 
 
637
        label = new Gtk.Label(_("Artist"));
 
638
        label.set_alignment(0.0f, 0.5f);
 
639
        group.add_widget(label);
 
640
        qhbox.pack_start(label, false, false, 0);
 
641
        var image =  new Gtk.Image.from_icon_name("media-artist", Gtk.IconSize.BUTTON);
 
642
        qhbox.pack_start(image, false, false, 0);
 
643
 
 
644
        this.artist_entry = new Gtk.Entry();
 
645
        this.artist_entry.set_text(song.artist);
 
646
        qhbox.pack_start(this.artist_entry, true, true, 0);
 
647
        vbox.pack_start(qhbox, false, false, 0);
 
648
       
 
649
        qhbox = new Gtk.HBox(false, 6);
 
650
        label = new Gtk.Label(_("Album"));
 
651
        label.set_alignment(0.0f, 0.5f);
 
652
        group.add_widget(label);
 
653
        qhbox.pack_start(label, false, false, 0);
 
654
        image =  new Gtk.Image.from_icon_name("media-album", Gtk.IconSize.BUTTON);
 
655
        qhbox.pack_start(image, false, false, 0);
 
656
        this.album_entry = new Gtk.Entry();
 
657
        if(song.album != null)
 
658
            this.album_entry.set_text(song.album);
 
659
        qhbox.pack_start(this.album_entry, true, true, 0);
 
660
        vbox.pack_start(qhbox, false, false, 0);
 
661
 
 
662
        qhbox = new Gtk.HBox(false, 6);
 
663
        label = new Gtk.Label(_("Title"));
 
664
        label.set_alignment(0.0f, 0.5f);
 
665
        group.add_widget(label);
 
666
        qhbox.pack_start(label, false, false, 0);
 
667
        image =  new Gtk.Image.from_icon_name("media-audiofile", Gtk.IconSize.BUTTON);
 
668
        qhbox.pack_start(image, false, false, 0);
 
669
        this.title_entry = new Gtk.Entry();
 
670
        if(song.title != null)
 
671
            this.title_entry.set_text(song.title);
 
672
        qhbox.pack_start(this.title_entry, true, true, 0);
 
673
 
 
674
        vbox.pack_start(qhbox, false, false, 0);
 
675
 
 
676
        if(type != Gmpc.MetaData.Type.ALBUM_ART)
 
677
            this.album_entry.sensitive = false;
 
678
 
 
679
 
 
680
        this.refresh = button = new Gtk.Button.with_label(_("Query"));
 
681
        var ali = new Gtk.Alignment(1.0f, 0.5f, 0.0f, 0.0f);
 
682
        ali.add(button);
 
683
        vbox.pack_start(ali, false, false, 0);
 
684
        button.clicked.connect(refresh_query);
 
685
 
 
686
 
 
687
 
 
688
        vbox.pack_start(sw, true, true,0);
 
689
        this.add(vbox);
 
690
        this.hide_on_delete();
 
691
        //sw.add(iv);
 
692
        ilevent = new Gtk.EventBox();
 
693
        this.itemslist.border_width = 8;
 
694
        ilevent.visible_window = true;
 
695
        ilevent.modify_bg(Gtk.StateType.NORMAL,this.style.base[Gtk.StateType.NORMAL]);
 
696
        this.style_set.connect((source, old) => {
 
697
                this.itemslist.get_parent().modify_bg(Gtk.StateType.NORMAL,this.style.base[Gtk.StateType.NORMAL]);
 
698
        });
 
699
    //            ilevent.modify_bg(Gtk.StateType.NORMAL,this.style.base[Gtk.StateType.NORMAL]);
 
700
     //           });
 
701
        ilevent.add(itemslist);
 
702
        sw.add_with_viewport(ilevent);
 
703
        this.show_all();
 
704
 
 
705
        if(type == Gmpc.MetaData.Type.ARTIST_ART)  this.combo.set_active(0);
 
706
        else if(type == Gmpc.MetaData.Type.ALBUM_ART) this.combo.set_active(1);
 
707
        else if(type == Gmpc.MetaData.Type.SONG_TXT)  this.combo.set_active(2);
 
708
        else if(type == Gmpc.MetaData.Type.ALBUM_TXT)  this.combo.set_active(3);
 
709
        else if(type == Gmpc.MetaData.Type.ARTIST_TXT)this.combo.set_active(4);
 
710
        else if(type == Gmpc.MetaData.Type.SONG_GUITAR_TAB)this.combo.set_active(5);
 
711
        refresh_query(button);
 
712
    }
 
713
    public void b_cancel(){
 
714
        if(this.handle != null){
 
715
            Gmpc.MetaData.get_list_cancel(this.handle);
 
716
            this.handle = null;
 
717
        }
 
718
        if(this.handle2 != null){
 
719
            Gmpc.MetaData.get_list_cancel(this.handle2);
 
720
            this.handle2 = null;
 
721
        }
 
722
        this.downloads.first();
 
723
        while(this.downloads != null){
 
724
            Gmpc.AsyncDownload.Handle handle = this.downloads.data;
 
725
            
 
726
            handle.cancel(); 
 
727
            this.downloads.first();
 
728
        }
 
729
 
 
730
        this.pbox.hide();
 
731
        this.refresh.sensitive = true;
 
732
        this.combo.sensitive = true;
 
733
    }
 
734
    ~EditWindow() {
 
735
        this.b_cancel();
 
736
    }
 
737
}
 
738
 
 
739
 
 
740
 
 
741
public class  Gmpc.TestPlugin : Gmpc.Plugin.Base,Gmpc.Plugin.ToolMenuIface, Gmpc.Plugin.SongListIface {
 
742
    private const int[] version = {0,0,2};
 
743
    /*********************************************************************************
 
744
     * Plugin base functions 
 
745
     * These functions are required.
 
746
     ********************************************************************************/
 
747
    construct {
 
748
        /* Mark the plugin as an internal dummy */
 
749
        this.plugin_type = 8+4;
 
750
    }
 
751
    public override unowned int[] get_version() {
 
752
        return this.version;
 
753
    }
 
754
    /**
 
755
     * The name of the plugin
 
756
     */
 
757
    public override unowned string get_name() {
 
758
        return "Vala test plugin";
 
759
    }
 
760
 
 
761
    /**
 
762
     * Tells the plugin to save itself
 
763
     */
 
764
    public override void save_yourself()
 
765
    {
 
766
        /* nothing to save */
 
767
    }
 
768
 
 
769
    /**
 
770
     * Get set enabled
 
771
     */
 
772
    public override bool get_enabled() {
 
773
        return (bool)config.get_int_with_default(this.get_name(), "enabled", 1);
 
774
    }
 
775
    public override void set_enabled(bool state) {
 
776
       config.set_int(this.get_name(), "enabled", (int)state); 
 
777
    }
 
778
 
 
779
     
 
780
 
 
781
    /*********************************************************************************
 
782
     * Private  
 
783
     ********************************************************************************/
 
784
    private void menu_activate_tree(Gtk.MenuItem item)
 
785
    {
 
786
        Gtk.TreeIter iter;
 
787
        Gtk.TreeView tv = (Gtk.TreeView)item.get_data<string>("treeview");
 
788
        Gtk.TreeModel model = tv.get_model();
 
789
        var selection = tv.get_selection();
 
790
        foreach(unowned Gtk.TreePath path in selection.get_selected_rows(out model))
 
791
        {
 
792
            if(model.get_iter(out iter, path))
 
793
            {
 
794
                unowned MPD.Song? song = null;
 
795
                model.get(iter,0, out song);
 
796
                if(song != null)
 
797
                {
 
798
                    new Gmpc.MetaData.EditWindow(song,Gmpc.MetaData.Type.ALBUM_ART);
 
799
                }
 
800
            }
 
801
        }
 
802
 
 
803
    }
 
804
 
 
805
    public int song_list(Gtk.Widget tree, Gtk.Menu menu)
 
806
    {
 
807
        Gtk.TreeView tv = (Gtk.TreeView)tree;
 
808
        var selection = tv.get_selection();
 
809
        if(selection.count_selected_rows() > 0)
 
810
        {
 
811
            Gtk.ImageMenuItem item = new Gtk.ImageMenuItem.with_label(_("Metadata selector"));
 
812
            item.set_image( new Gtk.Image.from_stock("gtk-edit", Gtk.IconSize.MENU));
 
813
            item.set_data("treeview", tv);
 
814
            menu.append(item);
 
815
 
 
816
            item.activate.connect(menu_activate_tree);
 
817
            return 1;
 
818
        }
 
819
        return 0;
 
820
    }
 
821
 
 
822
    public void menu_activated_album(Gtk.MenuItem item)
 
823
    {
 
824
        unowned MPD.Song song = server.playlist_get_current_song();
 
825
        new Gmpc.MetaData.EditWindow(song,Gmpc.MetaData.Type.ALBUM_ART);
 
826
    }
 
827
    public int tool_menu_integration(Gtk.Menu menu)
 
828
    {
 
829
        Gtk.MenuItem item = new Gtk.MenuItem.with_label(_("Edit metadata current song"));
 
830
        menu.append(item);
 
831
        item.activate.connect(menu_activated_album);
 
832
        return 2;
 
833
    }
 
834
}
 
835