=== modified file 'src/Core/LibraryWindow.vala' --- src/Core/LibraryWindow.vala 2012-06-14 22:45:34 +0000 +++ src/Core/LibraryWindow.vala 2012-06-20 13:41:46 +0000 @@ -24,6 +24,9 @@ using Gee; using Notify; +const string PROCESS_INDICATOR_SOUND = "indicator-sound-service"; +const string PROCESS_UNITY = "unity-panel-service"; + public class BeatBox.LibraryWindow : LibraryWindowInterface, Gtk.Window { // signals @@ -88,6 +91,10 @@ private Gtk.MenuItem fileRescanMusicFolder; private Gtk.MenuItem editEqualizer; private ImageMenuItem editPreferences; + + // Unity and sound menu integration flags + public bool enableUnityIntegration { get; private set; } + public bool enableSoundmenuIntegration { get; private set; } public Notify.Notification notification { get; private set; } @@ -106,21 +113,30 @@ //various objects mkl = new MediaKeyListener(lm, this); + + // Check for Unity and sound menu availability + enableUnityIntegration = is_process_running(PROCESS_UNITY); + enableSoundmenuIntegration = is_process_running(PROCESS_INDICATOR_SOUND); #if HAVE_INDICATE #if HAVE_DBUSMENU - message("Initializing MPRIS and sound menu\n"); - var mpris = new BeatBox.MPRIS(lm, this); - mpris.initialize(); + if (enableSoundmenuIntegration) { + message("Initializing MPRIS and sound menu\n"); + var mpris = new BeatBox.MPRIS(lm, this); + mpris.initialize(); + } #endif #endif #if HAVE_UNITY #if HAVE_DBUSMENU - message("Initializing Unity integration\n"); - unity = new BeatBox.UnityIntegration(lm, this); - if(!unity.initialize()) - warning("Unity integration failed\n"); + if (enableUnityIntegration) { + message("Initializing Unity integration\n"); + unity = new BeatBox.UnityIntegration(lm, this); + if(!unity.initialize()) { + warning("Unity integration failed\n"); + } + } #endif #endif @@ -996,7 +1012,7 @@ w.focus(DirectionType.UP); } - void on_quit() { + void on_quit() { lm.settings.setLastMediaPosition((int)((double)lm.player.getPosition()/1000000000)); if(lm.media_active) { lm.media_info.media.resume_pos = (int)((double)lm.player.getPosition()/1000000000); @@ -1421,5 +1437,21 @@ now_playing.hide_video_mode(); showSongInfo.set_image(Icons.INFO.render_image (IconSize.MENU, viewSelector.get_style_context())); } + + bool is_process_running(string process_name) { + bool is_running = false; + string cmd = "pidof " + process_name; + string pid; + try { + Process.spawn_command_line_sync(cmd, out pid); + debug("PID of %s: %s", process_name, pid); + if (pid.length > 0) { + is_running = true; + } + } catch (SpawnError e) { + debug("Unable to spawn process: %s", e.message); + } + return is_running; + } } === modified file 'src/DBus/MPRIS/MPRIS.vala' --- src/DBus/MPRIS/MPRIS.vala 2012-06-01 22:48:28 +0000 +++ src/DBus/MPRIS/MPRIS.vala 2012-06-20 13:24:19 +0000 @@ -49,18 +49,16 @@ warning("Could not initialize MPRIS session.\n"); } else { - bool have_unity = false; -#if HAVE_UNITY - have_unity = true; -#endif - - // If we have libunity, let the implementation in UnityIntegration + // If Unity is running, let the implementation in UnityIntegration // handle the sound menu since it is cleaner and has playlists. // Otherwise, use this as a backup. - if(!have_unity) { + if(lw.enableSoundmenuIntegration && !lw.enableUnityIntegration) { var soundMenu = new SoundMenuIntegration(lm, lw); soundMenu.initialize(); } + else { + debug("It's up to unity to take care for sound menu integration"); + } } }