2 # LADITools - Linux Audio Desktop Integration Tools
3 # Copyright (C) 2011-2012 Alessio Treglia <quadrispro@ubuntu.com>
4 # Copyright (C) 2007-2010, Marc-Olivier Barre <marco@marcochapeau.org>
5 # Copyright (C) 2007-2009, Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from .controller
import LadiController
24 name_base
= 'org.ladish'
25 control_iface_name
= name_base
+ '.Control'
26 studio_iface_name
= name_base
+ '.Studio'
27 control_obj_path
= "/org/ladish/Control"
28 studio_obj_path
= "/org/ladish/Studio"
29 service_name
= name_base
31 LadishStatusType
= Enum("STUDIO_STOPPED",
36 class LadishProxyError(Exception): pass
37 class LadishStudioException(Exception): pass
40 """Connect to ladish and return its current status."""
43 except Exception as e
:
44 raise LadishProxyError("ladish proxy creation failed: %s" % e
.message
)
45 if not proxy
.is_available():
46 return LadishStatusType
.NOT_AVAILABLE
47 if not proxy
.studio_is_loaded():
48 return LadishStatusType
.NO_STUDIO_LOADED
50 if proxy
.studio_is_started():
51 return LadishStatusType
.STUDIO_RUNNING
53 return LadishStatusType
.STUDIO_STOPPED
55 class LadishProxy(LadiController
):
56 """Wrapper for controlling and monitoring ladish.
58 This class provides an (almost) complete control on LADI Session Handler.
61 LadiController
.__init
__(self
,
62 dbus_type
='SessionBus',
63 service_name
=service_name
,
64 obj_path
=control_obj_path
,
65 iface_name
=control_iface_name
)
66 self
.studio_obj
= self
.bus
.get_object(service_name
, studio_obj_path
)
67 self
.studio_iface
= dbus
.Interface(self
.studio_obj
, studio_iface_name
)
70 raise NotImplementedError
72 def is_available(self
):
73 """Check if the service is running and a studio is loaded."""
75 self
.studio_is_loaded()
80 def studio_list(self
):
81 """Return a list of configured studios."""
83 for studio
in self
.controller_iface
.GetStudioList():
84 studios
.append(studio
[0])
87 def studio_new(self
, name
=""):
88 """Setup a new studio and name it as <name>."""
89 self
.controller_iface
.NewStudio(name
)
91 def studio_is_loaded(self
):
92 """Check if a studio is loaded."""
93 return self
.controller_iface
.IsStudioLoaded()
95 def studio_load(self
, name
):
96 """Load the studio named <name>."""
97 self
.controller_iface
.LoadStudio(name
, {})
99 def studio_delete(self
, name
):
100 """Delete the studio named <name>."""
101 self
.controller_iface
.DeleteStudio(name
)
104 """Kill the service."""
105 self
.controller_iface
.Exit()
107 def studio_start(self
):
108 """Start the current studio."""
109 self
.studio_iface
.Start()
111 def studio_stop(self
):
112 """Stop the current studio."""
113 self
.studio_iface
.Stop()
115 def studio_rename(self
, new_name
):
116 """Rename the current studio to <new_name>."""
117 self
.studio_iface
.Rename(new_name
)
119 def studio_save(self
):
120 """Save the changes to the current studio."""
121 self
.studio_iface
.Save()
123 def studio_unload(self
):
124 """Unload the current studio."""
125 self
.studio_iface
.Unload()
127 def studio_name(self
):
128 """Return the current studio's name."""
129 return self
.studio_iface
.GetName()
131 def studio_is_started(self
):
132 """Check if the current studio is running."""
133 return self
.studio_iface
.IsStarted()