~elementary-apps/noise/source-view-api

« back to all changes in this revision

Viewing changes to src/Views/Wrappers/MusicViewWrapper.vala

  • Committer: Corentin Noël
  • Date: 2012-11-17 13:48:05 UTC
  • Revision ID: tintou@mailoo.org-20121117134805-9ucj3bv31kp5oh9x
Last changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
        build_async.begin ();
28
28
    }
29
29
 
 
30
    private Gee.HashMap<unowned Device, int> _devices;
 
31
 
30
32
    private async void build_async () {
 
33
        Idle.add_full (VIEW_CONSTRUCT_PRIORITY, build_async.callback);
 
34
        yield;
31
35
        // Add grid view
32
36
        grid_view = new GridView (this);
33
37
 
42
46
        welcome_screen.append_with_pixbuf (music_folder_icon, _("Locate"), _("Change your music folder."));
43
47
 
44
48
        welcome_screen.activated.connect (welcome_screen_activated);
 
49
        _devices = new Gee.HashMap<Device, int> ();
45
50
 
46
51
        embedded_alert = new Granite.Widgets.EmbeddedAlert ();
47
52
 
48
53
        // Refresh view layout
49
54
        pack_views ();
50
55
 
 
56
        connect_data_signals ();
51
57
        yield set_media_async (lm.media ());
52
 
        connect_data_signals ();
53
58
    }
54
59
 
55
60
    private void connect_data_signals () {
58
63
         * possible with internal media. This view wrapper is not intended for use
59
64
         * with external (i.e. doesn't belong to library) media anyway.
60
65
         */
 
66
         lm.device_added.connect (on_device_added);
 
67
         lm.device_removed.connect (on_device_removed);
 
68
         lm.device_name_changed.connect (on_device_name_changed);
61
69
         lm.media_added.connect (on_library_media_added);
62
70
         lm.media_removed.connect (on_library_media_removed);
63
71
         lm.media_updated.connect (on_library_media_updated);
64
72
    }
65
73
 
 
74
    private void on_device_added (Device d) {
 
75
        int id = welcome_screen.append (d.get_icon().to_string (), _("Import your Music"), _("Import all your Music from %s into your library.").printf(d.getDisplayName()));
 
76
        _devices.set (d, id);
 
77
        welcome_screen.show_all ();
 
78
    }
 
79
 
 
80
    private void on_device_removed (Device d) {
 
81
        int id = _devices.get (d);
 
82
        if (id > 0) {
 
83
            welcome_screen.remove_item (_devices.get (d));
 
84
        }
 
85
        _devices.unset (d, null);
 
86
    }
 
87
 
 
88
    private void on_device_name_changed (Device d) {
 
89
        welcome_screen.remove_item (_devices.get (d));
 
90
        _devices.unset (d, null);
 
91
        int id = welcome_screen.append (d.get_icon().to_string (), _("Import your Music"), _("Import all your Music from %s into your library.").printf(d.getDisplayName()));
 
92
        _devices.set (d, id);
 
93
        welcome_screen.show_all ();
 
94
    }
 
95
 
66
96
    private void on_library_media_added (Gee.Collection<int> added_ids) {
67
97
        // Convert ids to real media
68
98
        var to_add = lm.media_from_ids (added_ids);
105
135
                if (!String.is_empty (folder, true))
106
136
                    lw.setMusicFolder (folder);
107
137
            }
 
138
        } else {
 
139
            foreach (var device_entry in _devices.entries) {
 
140
                if (device_entry.value == index) {
 
141
                    ((Device)device_entry.key).transfer_all_to_library();
 
142
                }
 
143
            }
108
144
        }
109
145
    }
110
146
}