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

« back to all changes in this revision

Viewing changes to src/Extensions/Banshee.UbuntuOneMusicStore/Banshee.UbuntuOneMusicStore/UbuntuOneMusicStoreSource.cs

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin, cd59790
  • Date: 2011-09-23 12:03:29 UTC
  • Revision ID: package-import@ubuntu.com-20110923120329-lmuugat60t1lyaz3
Tags: 2.2.0-1ubuntu2
[cd59790] Backport patch to add U1MS URI support (LP: #856542)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        // In the sources TreeView, sets the order value for this source, small on top
48
48
        const int sort_order = 190;
49
49
        CustomView custom_view;
 
50
        string cached_startup_uri;
50
51
 
51
52
        public UbuntuOneMusicStoreSource () : base (
52
53
            Catalog.GetString ("Ubuntu One Music Store"),
61
62
 
62
63
            // So we can handle u1ms:// URIs
63
64
            ServiceManager.Get<DBusCommandService> ().ArgumentPushed += OnCommandLineArgument;
 
65
            custom_view.store.UrlLoaded += OnDefaultStoreUrlLoaded;
 
66
 
 
67
            // make sure that the u1ms uri gets handled on banshee startup
 
68
            foreach (string uri in ApplicationContext.CommandLine.Files) {
 
69
                if (IsU1msUri (uri)) {
 
70
                    cached_startup_uri = uri;
 
71
                    break;
 
72
                }
 
73
            }
64
74
        }
65
75
 
66
76
        ~UbuntuOneMusicStoreSource ()
68
78
            ServiceManager.Get<DBusCommandService> ().ArgumentPushed -= OnCommandLineArgument;
69
79
        }
70
80
 
 
81
        // A count of 0 will be hidden in the source TreeView
 
82
        public override int Count {
 
83
            get { return 0; }
 
84
        }
 
85
 
 
86
        private void OnDefaultStoreUrlLoaded (object o, UbuntuOne.UrlLoadedArgs args)
 
87
        {
 
88
            if (args.Url.StartsWith( "http://stores.7digital.com/default")) {
 
89
                // we just do this the first time we load the default store view
 
90
                // so that we can switch to the passed u1ms uri and not have it switch out on us.
 
91
                custom_view.store.UrlLoaded -= OnDefaultStoreUrlLoaded;
 
92
                if (!string.IsNullOrEmpty (cached_startup_uri))
 
93
                    LoadU1msUri (cached_startup_uri);
 
94
            }
 
95
        }
 
96
 
71
97
        private void OnCommandLineArgument (string uri, object value, bool isFile)
72
98
        {
73
99
            if (!isFile || String.IsNullOrEmpty (uri)) {
74
100
                return;
75
101
            }
76
102
 
 
103
            LoadU1msUri (uri);
 
104
        }
 
105
 
 
106
        private void LoadU1msUri (string uri)
 
107
        {
77
108
            Log.Debug ("U1MS: URI requested: ", uri);
78
109
            // Handle u1ms:// URIs
79
 
            if (uri.StartsWith ("u1ms://")) {
 
110
            if (IsU1msUri (uri)) {
80
111
                string http_url = uri.Replace ("u1ms://", "http://");
81
112
                custom_view.Store.LoadStoreLink (http_url);
82
113
                ServiceManager.SourceManager.SetActiveSource (this);
83
114
            }
84
115
        }
85
116
 
86
 
        // A count of 0 will be hidden in the source TreeView
87
 
        public override int Count {
88
 
            get { return 0; }
 
117
        private bool IsU1msUri (string uri)
 
118
        {
 
119
            return uri.StartsWith ("u1ms://");
89
120
        }
90
121
 
91
122
        public class StoreWrapper: UbuntuOne.U1MusicStore, IDisableKeybindings
140
171
 
141
172
        private class CustomView : ISourceContents
142
173
        {
143
 
            StoreWrapper store = new StoreWrapper ();
 
174
            internal StoreWrapper store = new StoreWrapper ();
144
175
 
145
176
            public bool SetSource (ISource source) { return true; }
146
177
            public void ResetSource () { }