28
using System.Collections.Generic;
36
31
using Banshee.ServiceStack;
38
33
using Banshee.Library;
39
34
using Banshee.Sources;
40
35
using Banshee.Sources.Gui;
41
36
using Banshee.Preferences;
37
using Banshee.Preferences.Gui;
45
41
namespace Banshee.ClutterFlow
48
internal static class ClutterFlowManager
43
public class ClutterFlowService : IExtensionService, IDisposable
50
private static int state = 0;
51
public static event EventHandler BeforeQuit;
53
public static void Init ()
56
//TODO provide a static class for initialisation that does not get destroyed when this service is
57
// it should hold reference to the ActorLoader instances, as they hold precious references to texture,
58
// data that apparently remains in memory
59
if (!GLib.Thread.Supported) GLib.Thread.Init();
60
Clutter.Threads.Init();
61
if (ClutterHelper.gtk_clutter_init (IntPtr.Zero, IntPtr.Zero) != InitError.Success)
62
throw new System.NotSupportedException ("Unable to initialize GtkClutter");
63
System.AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
68
static void HandleProcessExit(object sender, EventArgs e)
71
System.AppDomain.CurrentDomain.ProcessExit -= HandleProcessExit;
75
public static void Quit ()
78
EventHandler handler = BeforeQuit;
79
if (handler != null) {
80
handler (null, EventArgs.Empty);
82
Clutter.Application.Quit ();
83
filter_view.Dispose ();
89
private static ClutterFlowView filter_view;
90
public static ClutterFlowView FilterView {
92
if (filter_view==null)
93
filter_view = new ClutterFlowView ();
94
else if (!filter_view.Attached)
95
filter_view.AttachEvents ();
101
public class ClutterFlowService : IExtensionService, IDisposable
104
string IService.ServiceName {
105
get { return "ClutterFlowService"; }
108
private SourceManager source_manager;
109
private MusicLibrarySource music_library;
111
private PreferenceService preference_service;
112
private InterfaceActionService action_service;
46
string IService.ServiceName {
47
get { return "ClutterFlowService"; }
50
private SourceManager source_manager;
51
private MusicLibrarySource music_library;
53
private PreferenceService preference_service;
54
private InterfaceActionService action_service;
114
56
private uint ui_manager_id;
115
57
private ActionGroup clutterflow_actions;
116
private ToggleAction browser_action;
117
protected ToggleAction BrowserAction {
119
if (browser_action==null)
120
browser_action = (ToggleAction) action_service.FindAction("BrowserView.BrowserVisibleAction");
121
return browser_action;
124
private ToggleAction cfbrows_action;
125
protected ToggleAction CfBrowsAction {
127
if (cfbrows_action==null)
128
cfbrows_action = (ToggleAction) action_service.FindAction("ClutterFlowView.ClutterFlowVisibleAction");
129
return cfbrows_action;
132
private static string menu_xml = @"
134
<menubar name=""MainMenu"">
135
<menu name=""ViewMenu"" action=""ViewMenuAction"">
136
<placeholder name=""BrowserViews"">
137
<menuitem name=""ClutterFlow"" action=""ClutterFlowVisibleAction"" />
144
private ClutterFlowContents clutter_flow_contents;
147
#region Initialization
149
public ClutterFlowService ()
151
ClutterFlowManager.Init ();
154
void IExtensionService.Initialize ()
156
preference_service = ServiceManager.Get<PreferenceService> ();
157
action_service = ServiceManager.Get<InterfaceActionService> ();
159
source_manager = ServiceManager.SourceManager;
160
music_library = source_manager.MusicLibrary;
162
if (!SetupPreferences () || !SetupInterfaceActions ())
163
ServiceManager.ServiceStarted += OnServiceStarted;
164
else if (!SetupSourceContents ())
165
source_manager.SourceAdded += OnSourceAdded;
168
//--> TODO Banshee.ServiceStack.Application. register Exit event to close threads etc.
171
private void OnServiceStarted (ServiceStartedArgs args)
173
if (args.Service is Banshee.Preferences.PreferenceService) {
174
preference_service = (PreferenceService)args.Service;
176
} else if (args.Service is Banshee.Gui.InterfaceActionService) {
177
action_service = (InterfaceActionService)args.Service;
178
SetupInterfaceActions ();
181
if (!(preference_service==null || action_service==null)) {
182
ServiceManager.ServiceStarted -= OnServiceStarted;
183
if (!SetupSourceContents ())
184
source_manager.SourceAdded += OnSourceAdded;
188
private void OnSourceAdded (SourceAddedArgs args)
190
if (args.Source is MusicLibrarySource)
191
music_library = args.Source as MusicLibrarySource;
192
SetupSourceContents ();
197
private bool SetupSourceContents ()
199
if (music_library==null || preference_service==null || action_service==null
200
|| ServiceManager.SourceManager.ActiveSource == null)
58
private ToggleAction browser_action;
59
protected ToggleAction BrowserAction {
61
if (browser_action==null) {
62
browser_action = (ToggleAction) action_service.FindAction("BrowserView.BrowserVisibleAction");
64
return browser_action;
67
private ToggleAction cfbrows_action;
68
protected ToggleAction CfBrowsAction {
70
if (cfbrows_action==null) {
71
cfbrows_action = (ToggleAction) action_service.FindAction("ClutterFlowView.ClutterFlowVisibleAction");
73
return cfbrows_action;
76
private static string menu_xml = @"
78
<menubar name=""MainMenu"">
79
<menu name=""ViewMenu"" action=""ViewMenuAction"">
80
<placeholder name=""BrowserViews"">
81
<menuitem name=""ClutterFlow"" action=""ClutterFlowVisibleAction"" />
88
private ClutterFlowContents clutter_flow_contents;
91
#region Initialization
93
public ClutterFlowService ()
96
void IExtensionService.Initialize ()
98
ClutterHelper.Init ();
100
preference_service = ServiceManager.Get<PreferenceService> ();
101
action_service = ServiceManager.Get<InterfaceActionService> ();
103
source_manager = ServiceManager.SourceManager;
104
music_library = source_manager.MusicLibrary;
106
if (!SetupPreferences () || !SetupInterfaceActions ()) {
107
ServiceManager.ServiceStarted += OnServiceStarted;
108
} else if (!SetupSourceContents ()) {
109
source_manager.SourceAdded += OnSourceAdded;
112
//--> TODO Banshee.ServiceStack.Application. register Exit event to close threads etc.
115
private void OnServiceStarted (ServiceStartedArgs args)
117
if (args.Service is Banshee.Preferences.PreferenceService) {
118
preference_service = (PreferenceService)args.Service;
120
} else if (args.Service is Banshee.Gui.InterfaceActionService) {
121
action_service = (InterfaceActionService)args.Service;
122
SetupInterfaceActions ();
125
if (!(preference_service==null || action_service==null)) {
126
ServiceManager.ServiceStarted -= OnServiceStarted;
127
if (!SetupSourceContents ()) {
128
source_manager.SourceAdded += OnSourceAdded;
133
private void OnSourceAdded (SourceAddedArgs args)
135
if (args.Source is MusicLibrarySource) {
136
music_library = args.Source as MusicLibrarySource;
138
SetupSourceContents ();
143
private bool SetupSourceContents ()
145
if (music_library == null || preference_service == null || action_service == null
146
|| ServiceManager.SourceManager.ActiveSource == null) {
149
source_manager.SourceAdded -= OnSourceAdded;
203
151
clutter_flow_contents = new ClutterFlowContents ();
204
clutter_flow_contents.SetSource(music_library);
206
if (ClutterFlowSchemas.ShowClutterFlow.Get ()) {
207
BrowserAction.Active = false;
208
music_library.Properties.Set<ISourceContents> ("Nereid.SourceContents", clutter_flow_contents);
211
source_manager.SourceAdded -= OnSourceAdded;
215
private bool SetupPreferences ()
217
InstallPreferences ();
222
private bool SetupInterfaceActions ()
152
clutter_flow_contents.SetSource (music_library);
154
if (ClutterFlowSchemas.ShowClutterFlow.Get ()) {
155
BrowserAction.Active = false;
156
music_library.Properties.Set<ISourceContents> ("Nereid.SourceContents", clutter_flow_contents);
164
private bool SetupPreferences ()
166
InstallPreferences ();
171
private bool SetupInterfaceActions ()
225
174
action_service = ServiceManager.Get<InterfaceActionService> ();
227
176
if (action_service.FindActionGroup ("ClutterFlowView") == null) {
243
192
CfBrowsAction.Activated += OnToggleClutterFlow;
249
#region Action Handling
198
#region Action Handling
250
199
private void HandleActiveSourceChanged (SourceEventArgs args)
252
if (args.Source==music_library)
201
if (args.Source==music_library) {
253
202
clutterflow_actions.Visible = true;
255
204
clutterflow_actions.Visible = false;
258
private void OnToggleBrowser (object sender, EventArgs e)
260
if (BrowserAction.Active) {
208
private void OnToggleBrowser (object sender, EventArgs e)
210
if (BrowserAction.Active) {
261
211
ClutterFlowSchemas.OldShowBrowser.Set (true);
262
CfBrowsAction.Active = false;
263
ClutterFlowSchemas.ShowClutterFlow.Set (false);
268
private void OnToggleClutterFlow (object sender, EventArgs e)
270
if (CfBrowsAction.Active) {
271
ClutterFlowSchemas.ShowClutterFlow.Set (true);
212
CfBrowsAction.Active = false;
213
ClutterFlowSchemas.ShowClutterFlow.Set (false);
218
private void OnToggleClutterFlow (object sender, EventArgs e)
220
if (CfBrowsAction.Active) {
221
ClutterFlowSchemas.ShowClutterFlow.Set (true);
272
222
ClutterFlowSchemas.OldShowBrowser.Set (BrowserAction.Active);
273
BrowserAction.Active = false;
274
Clutter.Threads.Enter ();
275
music_library.Properties.Set<ISourceContents> ("Nereid.SourceContents", clutter_flow_contents);
276
Clutter.Threads.Leave ();
278
ClutterFlowSchemas.ShowClutterFlow.Set (false);
279
Clutter.Threads.Enter ();
280
music_library.Properties.Remove ("Nereid.SourceContents");
281
Clutter.Threads.Leave ();
282
BrowserAction.Active = ClutterFlowSchemas.OldShowBrowser.Get ();
223
BrowserAction.Active = false;
224
Clutter.Threads.Enter ();
225
music_library.Properties.Set<ISourceContents> ("Nereid.SourceContents", clutter_flow_contents);
226
Clutter.Threads.Leave ();
228
ClutterFlowSchemas.ShowClutterFlow.Set (false);
229
Clutter.Threads.Enter ();
230
music_library.Properties.Remove ("Nereid.SourceContents");
231
Clutter.Threads.Leave ();
232
BrowserAction.Active = ClutterFlowSchemas.OldShowBrowser.Get ();
286
private void RemoveClutterFlow ()
236
private void RemoveClutterFlow ()
288
238
Clutter.Threads.Enter ();
289
239
music_library.Properties.Remove ("Nereid.SourceContents");
290
240
Clutter.Threads.Leave ();
308
258
action_service = null;
309
259
browser_action = null;
310
260
cfbrows_action = null;
316
private bool pref_installed = false;
317
private Page pref_page;
266
private bool pref_installed = false;
267
private Page pref_page;
318
268
private Section general;
319
private Section dimensions;
321
protected void InstallPreferences ()
323
if (!pref_installed) {
324
pref_page = preference_service.Add(new Page("clutterflow",
269
private Section dimensions;
271
protected void InstallPreferences ()
273
if (!pref_installed) {
274
preference_service.InstallWidgetAdapters += OnPreferencesServiceInstallWidgetAdapters;
276
pref_page = preference_service.Add(new Page("clutterflow",
325
277
AddinManager.CurrentLocalizer.GetString ("ClutterFlow"), 10));
327
general = pref_page.Add (new Section ("general",
328
AddinManager.CurrentLocalizer.GetString ("General"), 1));
329
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.InstantPlayback, UpdateLabelVisibility);
279
general = pref_page.Add (new Section ("general",
280
AddinManager.CurrentLocalizer.GetString ("General"), 1));
281
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.InstantPlayback, null);
330
282
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.DisplayLabel, UpdateLabelVisibility);
331
283
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.DisplayTitle, UpdateTitleVisibility);
332
284
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.VisibleCovers, UpdateVisibleCovers);
333
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.DragSensitivity, UpdateDragSensitivity);
334
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.ThreadedArtwork, UpdateThreadedArtwork);
336
dimensions = pref_page.Add (new Section ("dimensions",
337
AddinManager.CurrentLocalizer.GetString ("Dimensions"), 2));
338
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.MinCoverSize, UpdateMinCoverSize);
339
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.MaxCoverSize, UpdateMinCoverSize);
340
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.TextureSize, UpdateMinCoverSize);
344
pref_installed = true;
348
private void LoadPreferences ()
350
UpdateThreadedArtwork ();
351
UpdateDragSensitivity ();
352
UpdateLabelVisibility ();
353
UpdateTitleVisibility ();
354
UpdateVisibleCovers ();
355
UpdateMinCoverSize ();
356
UpdateMaxCoverSize ();
357
UpdateTextureSize ();
360
private void UpdateThreadedArtwork ()
365
private void UpdateDragSensitivity ()
367
if (clutter_flow_contents != null)
368
clutter_flow_contents.FilterView.DragSensitivity =
369
(float) ClutterFlowSchemas.DragSensitivity.Get () * 0.1f;
372
private void UpdateLabelVisibility ()
374
if (clutter_flow_contents != null)
375
clutter_flow_contents.FilterView.LabelCoverIsVisible =
376
ClutterFlowSchemas.DisplayLabel.Get ();
379
private void UpdateTitleVisibility ()
381
if (clutter_flow_contents != null)
382
clutter_flow_contents.FilterView.LabelTrackIsVisible =
383
ClutterFlowSchemas.DisplayTitle.Get ();
386
private void UpdateVisibleCovers ()
388
if (clutter_flow_contents!=null)
389
clutter_flow_contents.FilterView.CoverManager.VisibleCovers =
390
((ClutterFlowSchemas.VisibleCovers.Get () + 1) * 2 + 1);
393
private void UpdateMinCoverSize ()
395
if (clutter_flow_contents != null)
396
clutter_flow_contents.FilterView.CoverManager.Behaviour.MinCoverWidth =
397
ClutterFlowSchemas.MinCoverSize.Get ();
400
private void UpdateMaxCoverSize ()
402
if (clutter_flow_contents != null)
403
clutter_flow_contents.FilterView.CoverManager.Behaviour.MaxCoverWidth =
404
ClutterFlowSchemas.MaxCoverSize.Get ();
407
private void UpdateTextureSize ()
409
if (clutter_flow_contents != null)
410
clutter_flow_contents.FilterView.CoverManager.TextureSize =
411
ClutterFlowSchemas.TextureSize.Get ();
285
ClutterFlowSchemas.AddToSection (general, ClutterFlowSchemas.DragSensitivity, UpdateDragSensitivity);
287
dimensions = pref_page.Add (new Section ("dimensions",
288
AddinManager.CurrentLocalizer.GetString ("Dimensions"), 2));
289
dimensions.Add (new VoidPreference ("dimensions-desc"));
290
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.MinCoverSize, UpdateMinCoverSize);
291
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.MaxCoverSize, UpdateMaxCoverSize);
292
ClutterFlowSchemas.AddToSection (dimensions, ClutterFlowSchemas.TextureSize, UpdateTextureSize);
294
pref_installed = true;
298
private void LoadPreferences ()
300
UpdateDragSensitivity ();
301
UpdateLabelVisibility ();
302
UpdateTitleVisibility ();
303
UpdateVisibleCovers ();
304
UpdateMinCoverSize ();
305
UpdateMaxCoverSize ();
306
UpdateTextureSize ();
309
private void UpdateDragSensitivity ()
311
if (clutter_flow_contents != null) {
312
clutter_flow_contents.FilterView.DragSensitivity =
313
(float) ClutterFlowSchemas.DragSensitivity.Get () * 0.1f;
317
private void UpdateLabelVisibility ()
319
if (clutter_flow_contents != null) {
320
clutter_flow_contents.FilterView.LabelCoverIsVisible =
321
ClutterFlowSchemas.DisplayLabel.Get ();
325
private void UpdateTitleVisibility ()
327
if (clutter_flow_contents != null) {
328
clutter_flow_contents.FilterView.LabelTrackIsVisible =
329
ClutterFlowSchemas.DisplayTitle.Get ();
333
private void UpdateVisibleCovers ()
335
if (clutter_flow_contents!=null) {
336
clutter_flow_contents.FilterView.CoverManager.VisibleCovers =
337
((ClutterFlowSchemas.VisibleCovers.Get () + 1) * 2 + 1);
341
private void UpdateMinCoverSize ()
343
if (clutter_flow_contents != null) {
344
clutter_flow_contents.FilterView.CoverManager.Behaviour.MinCoverWidth =
345
ClutterFlowSchemas.MinCoverSize.Get ();
349
private void UpdateMaxCoverSize ()
351
if (clutter_flow_contents != null) {
352
clutter_flow_contents.FilterView.CoverManager.Behaviour.MaxCoverWidth =
353
ClutterFlowSchemas.MaxCoverSize.Get ();
357
private void UpdateTextureSize ()
359
if (clutter_flow_contents != null) {
360
clutter_flow_contents.FilterView.CoverManager.TextureSize =
361
ClutterFlowSchemas.TextureSize.Get ();
414
365
private void UninstallPreferences ()
367
preference_service.InstallWidgetAdapters -= OnPreferencesServiceInstallWidgetAdapters;
416
369
preference_service.Remove (pref_page);
417
370
pref_page = null;
420
pref_installed = false;
373
pref_installed = false;
376
private void OnPreferencesServiceInstallWidgetAdapters (object o, EventArgs args)
378
if (dimensions == null) {
382
var description_label = new DescriptionLabel (AddinManager.CurrentLocalizer.GetString (
383
"For changes to these values to take effect, you need to restart Banshee"));
384
dimensions["dimensions-desc"].ShowLabel = false;
385
dimensions["dimensions-desc"].DisplayWidget = description_label;
424
390
private bool disposed = false;
425
public void Dispose ()
391
public void Dispose ()
431
398
ServiceManager.ServiceStarted -= OnServiceStarted;