~bratsche/indicator-sound/icon-placement

« back to all changes in this revision

Viewing changes to src/mpris-controller.vala

  • Committer: Conor Curran
  • Date: 2010-06-22 14:03:33 UTC
  • mfrom: (85.1.12 indicator-sound)
  • Revision ID: conor.curran@canonical.com-20100622140333-gg7hhrt0ob5b7t34
merged refactoring branch plus automatic status updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
using Gee;
22
22
 
23
 
 
24
23
public class MprisController : GLib.Object
25
24
{
26
25
  private DBus.Connection connection;
33
32
    public int32 endless;
34
33
  }
35
34
                
36
 
        
37
35
        public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){
38
36
    try {
39
37
      this.connection = DBus.Bus.get (DBus.BusType.SESSION);
43
41
                this.controller = controller;
44
42
                this.mpris_player = this.connection.get_object ("org.mpris.".concat(name.down()) , "/Player", mpris_interface);                         
45
43
    this.mpris_player.TrackChange += onTrackChange;     
46
 
    this.mpris_player.StatusChange += onStatusChange;           
47
 
                this.controller.update_playing_info(get_track_data());
48
 
        }
49
 
 
50
 
        public HashMap<string, string> get_track_data()
51
 
        {
52
 
                return format_metadata(this.mpris_player.GetMetadata());
53
 
        }
 
44
    this.mpris_player.StatusChange += onStatusChange;   
 
45
 
 
46
                status st = this.mpris_player.GetStatus();
 
47
                int play_state =  st.playback;
 
48
                debug("GetStatusChange - play state %i", play_state);
 
49
                (this.controller.custom_items[this.controller.TRANSPORT] as TransportMenuitem).change_play_state(play_state);
 
50
                this.controller.custom_items[this.controller.METADATA].update(this.mpris_player.GetMetadata(),
 
51
                                            MetadataMenuitem.attributes_format());
 
52
                
 
53
        }
 
54
 
54
55
 
55
56
        private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht)
56
57
        {
57
 
                this.controller.update_playing_info(format_metadata(ht));
 
58
                debug("onTrackChange");
 
59
                this.controller.custom_items[this.controller.METADATA].update(ht,
 
60
                                            MetadataMenuitem.attributes_format());
58
61
        }
59
62
 
60
63
        /**
76
79
        private void onStatusChange(dynamic DBus.Object mpris_client, status st)
77
80
  {
78
81
    debug("onStatusChange - signal received");  
79
 
                //ValueArray a = new ValueArray(4);
80
 
                //Value v = new Value(typeof(int32));          
81
 
                //v.set_int(st.playback);
82
 
                //a.append(v);
83
 
                //debug("onStatusChange - play %i", a.get_nth(0).get_int());
84
 
                //int playback = (ValueArray)st.get_nth(0).get_int();
85
 
                //int shuffle = ar.get_nth(1).get_int();
86
 
                //int repeat = ar.get_nth(2).get_int();
87
 
                //int endless = ar.get_nth(3).get_int();                
 
82
                status* status = &st;
 
83
                unowned ValueArray ar = (ValueArray)status;             
 
84
                int play_state = ar.get_nth(0).get_int();
 
85
                debug("onStatusChange - play state %i", play_state);
 
86
                HashTable<string, Value?> ht = new HashTable<string, Value?>(str_hash, str_equal);
 
87
                Value v = Value(typeof(int));
 
88
                v.set_int(play_state);
 
89
                ht.insert("state", v); 
 
90
                this.controller.custom_items[this.controller.TRANSPORT].update(ht, TransportMenuitem.attributes_format());
88
91
        }
89
92
 
90
 
        private static HashMap<string, string> format_metadata(HashTable<string,Value?> data)
91
 
        {
92
 
                HashMap<string,string> results = new HashMap<string, string>();
93
 
                debug("format_metadata - title = %s", (string)data.lookup("title"));
94
 
                results.set("title", (string)data.lookup("title"));
95
 
    results.set("artist", (string)data.lookup("artist"));
96
 
    results.set("album", (string)data.lookup("album"));
97
 
    results.set("arturl", (string)data.lookup("arturl"));
98
 
                return results;                                                         
99
 
        }
100
93
        
101
94
}