~elementary-apps/noise/0.4.x

« back to all changes in this revision

Viewing changes to src/Views/ListView/ListView.vala

  • Committer: Corentin Noël
  • Author(s): Baptiste Gelez
  • Date: 2017-11-03 10:39:06 UTC
  • Revision ID: git-v1:e56cb30d9beaa45b13c71ab9fb978d7100144cfa
Change the queue mechanism to make it less confusing (#65)

* Change the queue mechanism to make it less confusing

Fix #2

Now, when you double-click on a song, it is played and other songs of
the current list are added to the queue.

Also improved the style of some parts of the code, and changed many
Gee.HashMap<int, Media> to ArrayList<int, Media> (they were acting as
arrays, I don't know why they were maps).

* Remove `this` when possible

* Use GObject construction as much as possible

* Use Playlist.get, Playlist.set and Playlist.iterator when possible

* Soft-copy lists in ListView.vala

* construct accessor on properties needing it

* Make Noise.Plugins.CDView.dev public to support construct

* Fix many GObject warninsgs and segfaults

* Make it possible to jump to a specific track from the queue

* Fix duplicated queue bug

* Order the queue correctly

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 * Contains the column browser and list view.
31
31
 */
32
32
public class Noise.ListView : ContentView, Gtk.Box {
33
 
 
34
33
    public signal void reordered ();
35
34
 
36
35
    // Wrapper for the list view and miller columns
37
36
    private Gtk.Paned browser_hpane; // for left mode
38
37
    private Gtk.Paned browser_vpane; // for top mode
39
38
 
40
 
    public ColumnBrowser column_browser { get; private set; }
41
 
    public MusicListView   list_view    { get; private set; }
 
39
    public ColumnBrowser column_browser { get; construct set; }
 
40
    public MusicListView list_view { get; construct set; }
42
41
 
43
42
    private int browser_hpane_position = -1;
44
43
    private int browser_vpane_position = -1;
45
44
 
46
 
    private ViewWrapper view_wrapper;
 
45
    public ViewWrapper view_wrapper { get; construct set; }
47
46
    private ViewTextOverlay list_text_overlay;
48
47
 
49
48
    private bool obey_column_browser = false;
82
81
    }
83
82
 
84
83
    public ListView (ViewWrapper view_wrapper, TreeViewSetup tvs, bool add_browser = false) {
85
 
        this.view_wrapper = view_wrapper;
86
 
 
87
 
        list_view = new MusicListView (view_wrapper, tvs);
88
 
 
 
84
        Object (view_wrapper: view_wrapper,
 
85
                list_view: new MusicListView (view_wrapper, tvs),
 
86
                column_browser: add_browser ? new MusicColumnBrowser (view_wrapper) : null);
 
87
    }
 
88
 
 
89
    construct {
89
90
        var list_scrolled = new Gtk.ScrolledWindow (null, null);
90
91
        list_scrolled.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
91
92
        list_scrolled.add (list_view);
103
104
            import_requested (to_import);
104
105
        });
105
106
 
106
 
        if (add_browser)
107
 
            column_browser = new MusicColumnBrowser (view_wrapper);
108
 
 
109
107
        list_view.set_search_func (view_search_func);
110
 
        view_wrapper.library.search_finished.connect (() => {this.list_view.research_needed = true;});
 
108
        view_wrapper.library.search_finished.connect (() => { list_view.research_needed = true; });
111
109
 
112
110
        if (has_column_browser) {
113
111
            browser_hpane = new Gtk.Paned (Gtk.Orientation.HORIZONTAL);
120
118
 
121
119
            // Add hpaned (the most-external wrapper) to the view container
122
120
            browser_hpane.expand = true;
123
 
            this.add (browser_hpane);
 
121
            add (browser_hpane);
124
122
 
125
123
            // Now pack the list view
126
124
            browser_vpane.pack2 (list_text_overlay, true, false);
130
128
 
131
129
            // Connect signals once the widget has been realized to avoid writing to settings
132
130
            // on startup
133
 
            this.realize.connect (connect_column_browser_ui_signals);
 
131
            realize.connect (connect_column_browser_ui_signals);
134
132
 
135
133
            column_browser_enabled = Settings.SavedState.get_default ().column_browser_enabled;
136
134
 
137
135
            // Connect data signals
138
136
            column_browser.changed.connect (column_browser_changed);
139
 
        }
140
 
        else {
141
 
            this.add (list_text_overlay);
 
137
        } else {
 
138
            add (list_text_overlay);
142
139
        }
143
140
    }
144
141
 
151
148
        if (actual_position == ColumnBrowser.Position.AUTOMATIC) {
152
149
            // Decide what orientation to use based on the view area size
153
150
 
154
 
            int view_width = this.get_allocated_width ();
 
151
            int view_width = get_allocated_width ();
155
152
            const int MIN_RECOMMENDED_COLUMN_WIDTH = 160;
156
153
 
157
154
            int visible_columns = 0;
200
197
            return;
201
198
 
202
199
        // For automatic position stuff
203
 
        this.size_allocate.connect (() => {
 
200
        size_allocate.connect (() => {
204
201
            if (!App.main_window.initialization_finished)
205
202
                return;
206
203
 
269
266
    }
270
267
 
271
268
    public Gee.Collection<Media> get_media () {
272
 
        var media_list = new Gee.ArrayQueue<Media> ();
273
 
        media_list.add_all (list_view.get_table ().values);
274
 
        return media_list;
 
269
        var media = new Gee.ArrayList<Media> ();
 
270
        media.add_all (list_view.get_table ());
 
271
        return media;
275
272
    }
276
273
 
277
274
    public Gee.Collection<Media> get_visible_media () {
278
 
        var media_list = new Gee.ArrayQueue<Media> ();
279
 
        media_list.add_all (list_view.get_visible_table ().values);
280
 
        return media_list;
 
275
        var media = new Gee.ArrayList<Media> ();
 
276
        media.add_all (list_view.get_visible_table ());
 
277
        return media;
281
278
    }
282
279
 
283
280
    private void column_browser_changed () {
298
295
 
299
296
    public void add_media (Gee.Collection<Media> to_add) {
300
297
        list_view.add_media (to_add);
301
 
        this.list_view.research_needed = true;
 
298
        list_view.research_needed = true;
302
299
        refilter ();
303
300
    }
304
301
 
305
302
    public void remove_media (Gee.Collection<Media> to_remove) {
306
303
        list_view.remove_media (to_remove);
307
 
        this.list_view.research_needed = true;
 
304
        list_view.research_needed = true;
308
305
        refilter ();
309
306
    }
310
307
 
312
309
        obey_column_browser = false;
313
310
 
314
311
        list_view.set_media (media);
315
 
        this.list_view.research_needed = true;
 
312
        list_view.research_needed = true;
316
313
 
317
 
        if (has_column_browser)
 
314
        if (has_column_browser) {
318
315
            column_browser.set_media (media);
 
316
        }
319
317
 
320
318
        obey_column_browser = true;
321
319
    }
385
383
        return status_text;
386
384
    }
387
385
 
388
 
    private void view_search_func (string search, Gee.HashMap<int, Media> table, Gee.HashMap<int, Media> showing) {
 
386
    private void view_search_func (string search, Gee.ArrayList<Media> table, Gee.ArrayList<Media> showing) {
389
387
        list_text_overlay.message_visible = false;
390
388
        var result = view_wrapper.library.get_search_result ();
391
389
 
393
391
        // because it wil be refreshed after this search based on the new 'showing' table
394
392
        // (populated by this method).
395
393
        bool obey_column_browser = column_browser_enabled && this.obey_column_browser;
396
 
        int show_index = 0;
397
 
        
 
394
 
398
395
        if (result.size != view_wrapper.library.get_medias ().size) {
399
 
            /* 
400
 
             * Please don't change back to a foreach implementation
401
 
             * until you fully understand the proper behavior
402
 
             * since this change produces the bug 1346678
403
 
             * Leave this "for loop" for now.                   */
404
396
            foreach (var m in table) {
405
 
                if (obey_column_browser && !column_browser.match_media (m))
 
397
                if (obey_column_browser && !column_browser.match_media (m)) {
406
398
                    continue;
 
399
                }
407
400
 
408
 
                if (result.contains (m)) {
409
 
                    showing.set (show_index++, m);
 
401
                if (m in result) {
 
402
                    showing.add (m);
410
403
                }
411
404
            }
412
405
        } else {
413
 
            /* 
414
 
             * Please don't change back to a foreach implementation
415
 
             * until you fully understand the proper behavior
416
 
             * since this change produces the bug 1346678
417
 
             * Leave this "for loop" for now.                   */
418
406
            foreach (var m in table) {
419
 
                if (obey_column_browser && !column_browser.match_media (m))
 
407
                if (obey_column_browser && !column_browser.match_media (m)) {
420
408
                    continue;
 
409
                }
421
410
 
422
 
                showing.set (show_index++, m);
 
411
                showing.add (m);
423
412
            }
424
413
        }
425
414