~ubuntu-branches/ubuntu/precise/indicator-sound/precise-proposed

« back to all changes in this revision

Viewing changes to src/music-player-bridge.vala

Tags: 0.8.3.0-0ubuntu1
* New upstream release.
  - Fixed memory corruption issue (LP: #897218)
  - crashed with SIGABRT in pa_operation_unref (LP: #908682)
  - Banshee shown in sound menu after removal until reboot (LP: #771202)
  - Coverity PASS_BY_VALUE - CID 10620 (LP: #937451)
  - App icon and name are not aligned (LP: #939929)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
  private SettingsManager settings_manager;
29
29
  private Dbusmenu.Menuitem root_menu;
30
30
  private HashMap<string, PlayerController> registered_clients;
 
31
  private HashMap<string, string> file_monitors;
31
32
  private Mpris2Watcher watcher;
32
33
 
33
34
  public MusicPlayerBridge()
36
37
  
37
38
  construct{
38
39
    this.registered_clients = new HashMap<string, PlayerController> ();
 
40
    this.file_monitors = new HashMap<string, string> ();
39
41
    this.settings_manager = new SettingsManager();
40
42
    this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update );
41
43
  }
74
76
                                                     calculate_menu_position(),
75
77
                                                     null,
76
78
                                                     PlayerController.state.OFFLINE );
77
 
      this.registered_clients.set(mpris_key, ctrl);
78
 
    }
79
 
  }
 
79
      this.registered_clients.set(mpris_key, ctrl);  
 
80
      this.establish_file_monitoring (app_info, mpris_key);
 
81
    }
 
82
  }
 
83
  
 
84
  private void establish_file_monitoring (AppInfo info, string mpris_key){
 
85
      DesktopAppInfo desktop_info = info as DesktopAppInfo;
 
86
      var file_path = desktop_info.get_filename ();
 
87
      File f = File.new_for_path (file_path);
 
88
      FileMonitor monitor;
 
89
      try {
 
90
        monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null);
 
91
      }
 
92
      catch (Error e){
 
93
        warning ("Unable to create a file monitor for %s", info.get_name());
 
94
        return;
 
95
      }
 
96
      this.file_monitors.set (file_path, mpris_key);
 
97
      // Finally watch for a change.
 
98
      monitor.changed.connect ((desktop_file, other_file, event_type) => {
 
99
        this.relevant_desktop_file_changed (desktop_file, other_file, event_type, monitor);
 
100
      });
 
101
  }
 
102
  
 
103
  private void relevant_desktop_file_changed (File desktop_file,
 
104
                                              File? other_file,
 
105
                                              FileMonitorEvent event_type,
 
106
                                              FileMonitor monitor)
 
107
  {
 
108
    if (event_type != FileMonitorEvent.DELETED)
 
109
      return;
 
110
      
 
111
    string? path = desktop_file.get_path ();
 
112
    if (path == null){
 
113
      warning ("relevant_desktop_file_changed is returning a file with no path !");
 
114
      return;
 
115
    }
 
116
    if (!this.file_monitors.has_key (path)){
 
117
      warning ("relevant_desktop_file_changed is returning a file which we know nothing about - %s",
 
118
                path);
 
119
      return;
 
120
    }  
 
121
    this.registered_clients[this.file_monitors[path]].remove_from_menu();
 
122
    this.settings_manager.remove_interested (this.file_monitors[path]);
 
123
    this.registered_clients.unset (this.file_monitors[path]);    
 
124
    monitor.cancel ();
 
125
    monitor.unref();
 
126
  }                                              
80
127
 
81
128
  private int calculate_menu_position()
82
129
  {
125
172
      this.registered_clients.set ( mpris_key, ctrl );
126
173
      debug ( "Have not seen this %s before, new controller created.", desktop );        
127
174
      this.settings_manager.add_interested ( desktop );
 
175
      this.establish_file_monitoring (app_info, mpris_key);      
128
176
      debug ( "application added to the interested list" );
129
177
    }
130
178
    else{