示例#1
0
        public static void ShutDown()
        {
            bool wasLoggedIn = Session.IsLoggedIn;

            lock (_syncObj)
            {
                if (wasLoggedIn)
                {
                    libspotify.sp_session_player_unload(Session.GetSessionPtr());
                    libspotify.sp_session_logout(Session.GetSessionPtr());
                    try
                    {
                        if (PlaylistContainer.GetSessionContainer() != null)
                        {
                            PlaylistContainer.GetSessionContainer().Dispose();
                        }
                    }
                    catch { }
                }
                if (_mainSignal != null)
                {
                    _mainSignal.Set();
                }
                _shutDown = true;
            }
            if (_programSignal != null)
            {
                _programSignal.WaitOne(2000, false);
            }
        }
示例#2
0
 public static List <PlaylistContainer.PlaylistInfo> GetPlaylists(PlaylistContainer.PlaylistInfo playlist)
 {
     waitFor(delegate
     {
         return(PlaylistContainer.GetSessionContainer().IsLoaded &&
                PlaylistContainer.GetSessionContainer().PlaylistsAreLoaded);
     }, REQUEST_TIMEOUT);
     return(PlaylistContainer.GetSessionContainer().GetChildren(playlist));
 }
示例#3
0
 public static List <PlaylistContainer.PlaylistInfo> GetAllSessionPlaylists()
 {
     waitFor(delegate
     {
         return(PlaylistContainer.GetSessionContainer().IsLoaded &&
                PlaylistContainer.GetSessionContainer().PlaylistsAreLoaded);
     }, REQUEST_TIMEOUT);
     return(PlaylistContainer.GetSessionContainer().GetAllPlaylists());
 }
示例#4
0
        public List <PlaylistContainer.PlaylistInfo> GetAllSessionPlaylists()
        {
            var sessionContainer = PlaylistContainer.GetSessionContainer();

            WaitFor(() =>
            {
                return(sessionContainer.IsLoaded && sessionContainer.PlaylistsAreLoaded);
            }, RequestTimeout);
            return(sessionContainer.GetAllPlaylists());
        }
示例#5
0
        protected override void OnLoad(EventArgs e)
        {
            if (settings.UpdatesInterestedIn != UserSettings.UpdateType.None)
            {
                updater.CheckForNewVersion();
            }

            if (downloadedUpdate)
            {
                this.Close();
                return;
            }
            SpotifyController.Initialize();
            var appKeyBytes = Properties.Resources.spotify_appkey;

            LoadBufferWindowCommands();
            KeyManager = BufferHotkeyManager.LoadFromTextFile(this);
            string username = "", password = "";
            // the first one controls the loop, the second is the response from Libspotify's login call
            bool isLoggedIn = false, logInResponse = false;

            while (!isLoggedIn)
            {
                using (LoginWindow logon = new LoginWindow())
                {
                    var response = logon.ShowDialog();
                    if (response != DialogResult.OK)
                    {
                        this.Close();
                        output.OutputMessage(StringStore.ExitingProgram);
                        return;
                    }
                    username = logon.Username;
                    password = logon.Password;
                }
                try
                {
                    output.OutputMessage(StringStore.LoggingIn);
                    logInResponse = SpotifyController.Login(appKeyBytes, username, password);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(StringStore.ErrorDuringLoad + "\\r\\nInitialization: " + ex.Message, StringStore.Oops, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
                if (logInResponse)
                {
                    output.OutputMessage(StringStore.LoggedInToSpotify);
                    UserSettings.Instance.Username = username;
                    UserSettings.Save();
                    spotify.SetPrivateSession(UserSettings.Instance.StartInPrivateSession);
                    isLoggedIn = true;
                }
                else
                {
                    var reason = spotify.GetLoginError().Message;
                    MessageBox.Show(reason, StringStore.LogInFailure, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            output.OutputMessage(StringStore.LoadingPlaylists, false);
            var playlists = LoadUserPlaylists();

            if (playlists == null)
            {
                return;
            }

            var playlistsBuffer = Buffers[1] as PlaylistContainerBufferList;

            if (playlistsBuffer == null)
            {
                throw new NullReferenceException("PlaylistsBuffer is null");
            }

            playlistsBuffer.Clear();
            playlists.ForEach(p =>
            {
                playlistsBuffer.Add(new PlaylistBufferItem(p));
            });
            // we put a reference to the session container on the playlists buffer
            // so that it can subscribe to playlist added and removed events and in future maybe other things
            playlistsBuffer.Model = PlaylistContainer.GetSessionContainer();

            output.OutputMessage(String.Format("{0} {1}", playlists.Count, StringStore.PlaylistsLoaded), false);
            Buffers.CurrentListIndex = 1; // start on the playllists list
            output.OutputBufferListState(Buffers, NavigationDirection.None, false);
        }