~ubuntu-branches/ubuntu/maverick/indicator-sound/maverick

« back to all changes in this revision

Viewing changes to src/mpris2-controller.vala

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-08-26 11:38:07 UTC
  • mfrom: (28.9.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20100826113807-ykjlenc44or3ourt
Tags: 0.4.1-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
*/
20
20
using DBus;
21
21
 
 
22
 
22
23
[DBus (name = "org.mpris.MediaPlayer2")]
23
24
public interface MprisRoot : DBus.Object {
24
25
        // properties
89
90
                        this.properties_interface.PropertiesChanged += property_changed_cb;                     
90
91
                        
91
92
                } catch (DBus.Error e) {
92
 
      error("Problems connecting to the session bus - %s", e.message);
 
93
        error("Problems connecting to the session bus - %s", e.message);
93
94
    }           
94
95
        }
95
96
 
106
107
                        debug("new playback state = %s", state);                        
107
108
                        int p = this.determine_play_state(state);
108
109
                        (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);                   
109
 
                        (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(p);                    
110
110
                }
111
111
                
112
112
                Value? pos_v = changed_properties.lookup("Position");
113
113
                if(pos_v != null){
114
114
                        int64 pos = pos_v.get_int64();
115
115
                        debug("new position = %i", (int)pos);
116
 
                        (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_position((int32)pos);                                            
117
116
                }
118
117
 
119
118
                Value? meta_v = changed_properties.lookup("Metadata");
120
119
                if(meta_v != null){
121
 
                        debug("metadata is not empty");
122
 
                        debug("artist : %s", this.player.Metadata.lookup("artist").get_string());                       
123
 
                        this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format());                    
124
 
                        this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata,
 
120
                        GLib.HashTable<string, Value?> changed_updates = clean_metadata();      
 
121
                        this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
 
122
                        this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates,
125
123
                                                                                                                                                                                                                                 MetadataMenuitem.attributes_format());                 
126
 
                        this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format());  
127
 
                        if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 ||
128
 
                           (int)this.player.Metadata.lookup("artist").get_string().len() > 0){
129
 
                                this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata,
130
 
                                                                                                                                                                                                                                                ScrubMenuitem.attributes_format());                     
131
 
                        }
132
 
                        (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus));                        
133
 
                        
134
124
                }
135
125
        }
 
126
 
 
127
        private GLib.HashTable<string, Value?> clean_metadata()
 
128
        { 
 
129
                GLib.HashTable<string, Value?> changed_updates = this.player.Metadata; 
 
130
    Value? artist_v = this.player.Metadata.lookup("xesam:artist");
 
131
    if(artist_v != null){
 
132
                  string[] artists = (string[])this.player.Metadata.lookup("xesam:artist");
 
133
                  string display_artists = string.joinv(", ", artists);
 
134
                  changed_updates.replace("xesam:artist", display_artists);
 
135
                  debug("artist : %s", display_artists);
 
136
    }
 
137
    Value? length_v = this.player.Metadata.lookup("mpris:length");
 
138
    if(length_v != null){
 
139
                  int64 duration = this.player.Metadata.lookup("mpris:length").get_int64();
 
140
                  changed_updates.replace("mpris:length", duration/1000000); 
 
141
    }
 
142
                return changed_updates;
 
143
        }
 
144
        
136
145
        
137
146
        private int determine_play_state(string status){
138
147
                if(status == null)
157
166
                debug("initial update - play state %i", status);
158
167
                
159
168
                (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status);
160
 
                this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata,
 
169
                GLib.HashTable<string, Value?> cleaned_metadata = this.clean_metadata();
 
170
                this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata,
161
171
                                                  MetadataMenuitem.attributes_format());
162
 
                this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata,
163
 
                                              ScrubMenuitem.attributes_format());               
164
172
        }
165
173
 
166
174
        public void transport_event(TransportMenuitem.action command)
202
210
        public void set_position(double position)
203
211
        {                       
204
212
                debug("Set position with pos (0-100) %f", position);
205
 
                HashTable<string, Value?> data = this.player.Metadata;
206
 
                Value? time_value = data.lookup("time");
 
213
                Value? time_value = this.player.Metadata.lookup("mpris:length");
207
214
                if(time_value == null){
208
215
                        warning("Can't fetch the duration of the track therefore cant set the position");
209
216
                        return;
210
217
                }
211
 
                // work in microseconds (scale up by 10 TTP-of 3)
212
 
                uint32 total_time = time_value.get_uint() * 1000;
 
218
                // work in microseconds (scale up by 10 TTP-of 6)
 
219
                int64 total_time = time_value.get_int64();
213
220
                debug("total time of track = %i", (int)total_time);                             
214
 
                double new_time_position = total_time * position/100.0;
 
221
                double new_time_position = total_time * (position/100.0);
215
222
                debug("new position = %f", (new_time_position));                
216
223
 
217
 
                Value? v = this.player.Metadata.lookup("trackid");
 
224
                Value? v = this.player.Metadata.lookup("mpris:trackid");
218
225
                if(v != null){
219
226
                        if(v.holds (typeof (string))){
220
 
                                debug("the trackid = %s", v.get_string());
221
227
                                DBus.ObjectPath path = new ObjectPath(v.get_string());
222
228
                                try{
223
 
                                        //this.player.SetPosition(path, (int64)(new_time_position));
 
229
                                        this.player.SetPosition(path, (int64)(new_time_position));
 
230
                                        //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
 
231
                                        //scrub.update_position(((int32)new_time_position) / 1000);                     
224
232
                                }
225
233
                                catch(DBus.Error e){
226
234
                                        error("DBus Error calling the player objects SetPosition method %s",
232
240
 
233
241
        public void onSeeked(int64 position){
234
242
                debug("Seeked signal callback with pos = %i", (int)position/1000);
235
 
                ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
236
 
                scrub.update_position((int32)position/1000);                    
 
243
                //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
 
244
                //scrub.update_position((int32)position/1000);                  
237
245
        }
238
246
        
239
247
        public bool connected()