~ubuntu-branches/ubuntu/raring/banshee/raring

« back to all changes in this revision

Viewing changes to .pc/0001-Debrand-the-interface-to-Netbook.patch/src/Extensions/Banshee.MeeGo/Banshee.MeeGo/MeeGoService.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2012-01-23 23:16:49 UTC
  • mfrom: (6.3.22 experimental)
  • Revision ID: package-import@ubuntu.com-20120123231649-safm1f8eycltcgsf
Tags: 2.3.4.ds-1ubuntu1
* Merge from Debian Experimental, remaining changes:
  + Enable and recommend SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and suggest u1ms
  + Move desktop file for Meego UI to /usr/share/une/applications
  + Change the url for the Amazon store redirector
  + [08dea2c] Revert "Fix invalid cast causing ftbfs with libgpod"
* [b617fe0] Convert Ubuntu-specific patches to gbp-pq patches
* Also fixes Launchpad bugs:
  - Fixes race condition while starting (LP: #766303)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// MeeGoService.cs
 
3
//
 
4
// Authors:
 
5
//   Aaron Bockover <abockover@novell.com>
 
6
//
 
7
// Copyright 2009-2010 Novell, Inc.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using Gtk;
 
31
using MeeGo.Panel;
 
32
 
 
33
using Hyena;
 
34
 
 
35
using Banshee.Base;
 
36
using Banshee.Collection;
 
37
using Banshee.Sources;
 
38
using Banshee.ServiceStack;
 
39
using Banshee.MediaEngine;
 
40
using Banshee.Gui;
 
41
 
 
42
namespace Banshee.MeeGo
 
43
{
 
44
    public class MeeGoService : IExtensionService
 
45
    {
 
46
        private GtkElementsService elements_service;
 
47
        private InterfaceActionService interface_action_service;
 
48
        private SourceManager source_manager;
 
49
        private PlayerEngineService player;
 
50
        private MeeGoPanel panel;
 
51
 
 
52
        void IExtensionService.Initialize ()
 
53
        {
 
54
            elements_service = ServiceManager.Get<GtkElementsService> ();
 
55
            interface_action_service = ServiceManager.Get<InterfaceActionService> ();
 
56
            source_manager = ServiceManager.SourceManager;
 
57
            player = ServiceManager.PlayerEngine;
 
58
 
 
59
            if (!ServiceStartup ()) {
 
60
                ServiceManager.ServiceStarted += OnServiceStarted;
 
61
            }
 
62
        }
 
63
 
 
64
        private void OnServiceStarted (ServiceStartedArgs args)
 
65
        {
 
66
            if (args.Service is Banshee.Gui.InterfaceActionService) {
 
67
                interface_action_service = (InterfaceActionService)args.Service;
 
68
            } else if (args.Service is GtkElementsService) {
 
69
                elements_service = (GtkElementsService)args.Service;
 
70
            } else if (args.Service is SourceManager) {
 
71
                source_manager = ServiceManager.SourceManager;
 
72
            } else if (args.Service is PlayerEngineService) {
 
73
                player = ServiceManager.PlayerEngine;
 
74
            }
 
75
 
 
76
            ServiceStartup ();
 
77
        }
 
78
 
 
79
        private bool ServiceStartup ()
 
80
        {
 
81
            if (elements_service == null || interface_action_service == null ||
 
82
                source_manager == null || player == null) {
 
83
                return false;
 
84
            }
 
85
 
 
86
            Initialize ();
 
87
 
 
88
            ServiceManager.ServiceStarted -= OnServiceStarted;
 
89
 
 
90
            return true;
 
91
        }
 
92
 
 
93
        private void Initialize ()
 
94
        {
 
95
            // If Banshee is running from the MeeGo client entry assembly,
 
96
            // the MeeGoPanel will have already been created. If not, we
 
97
            // assume we're probably not really running in a MeeGo environment,
 
98
            // so we just create the panel here (which is likely to just be
 
99
            // a separate top-level window for testing).
 
100
            panel = MeeGoPanel.Instance ?? new MeeGoPanel ();
 
101
 
 
102
            if (panel == null) {
 
103
                Log.Warning ("MeeGo extension initialized without a panel");
 
104
                return;
 
105
            }
 
106
 
 
107
            panel.BuildContents ();
 
108
 
 
109
            elements_service.PrimaryWindowClose = () => {
 
110
                elements_service.PrimaryWindow.Hide ();
 
111
                return true;
 
112
            };
 
113
 
 
114
            // Since the Panel is running, we don't actually ever want to quit!
 
115
            Banshee.ServiceStack.Application.ShutdownRequested += () => {
 
116
                elements_service.PrimaryWindow.Hide ();
 
117
                return false;
 
118
            };
 
119
        }
 
120
 
 
121
        public void PresentPrimaryInterface ()
 
122
        {
 
123
            elements_service.PrimaryWindow.Maximize ();
 
124
            elements_service.PrimaryWindow.Present ();
 
125
            if (panel != null) {
 
126
                panel.Hide ();
 
127
            }
 
128
        }
 
129
 
 
130
        public void Dispose ()
 
131
        {
 
132
            if (panel != null) {
 
133
                panel.Dispose ();
 
134
                panel = null;
 
135
            }
 
136
 
 
137
            interface_action_service = null;
 
138
            elements_service = null;
 
139
        }
 
140
 
 
141
        string IService.ServiceName {
 
142
            get { return "MeeGoService"; }
 
143
        }
 
144
    }
 
145
}