/// <summary> /// Load settings and register player events /// </summary> public void Start() { string currentUser = String.Empty; _alertTime = INFINITE_TIME; GUIWindowManager.OnNewAction += new OnActionHandler(OnNewAction); g_Player.PlayBackStarted += new g_Player.StartedHandler(OnPlayBackStarted); g_Player.PlayBackEnded += new g_Player.EndedHandler(OnPlayBackEnded); g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnPlayBackStopped); using (Settings xmlreader = new MPSettings()) { currentUser = xmlreader.GetValueAsString("audioscrobbler", "user", String.Empty); _announceNowPlaying = xmlreader.GetValueAsBool("audioscrobbler", "EnableNowPlaying", true); } MusicDatabase mdb = MusicDatabase.Instance; _doSubmit = (mdb.AddScrobbleUserSettings(Convert.ToString(mdb.AddScrobbleUser(currentUser)), "iSubmitOn", -1) == 1) ? true : false; Log.Info("Audioscrobbler plugin: Submit songs: {0}, announce Now Playing: {1}", Convert.ToString(_doSubmit), Convert.ToString(_announceNowPlaying)); if (_doSubmit) { OnManualConnect(null, null); } }
protected void LoadSettings() { try { MusicDatabase mdb = MusicDatabase.Instance; List <string> scrobbleusers = new List <string>(); string tmpuser = ""; string tmppass = ""; groupBoxProfile.Visible = false; using (Settings xmlreader = new MPSettings()) { tmpuser = xmlreader.GetValueAsString("audioscrobbler", "user", ""); checkBoxEnableNowPlaying.Checked = xmlreader.GetValueAsBool("audioscrobbler", "EnableNowPlaying", true); scrobbleusers = mdb.GetAllScrobbleUsers(); // no users in database if (scrobbleusers.Count == 0) { tabControlLiveFeeds.Enabled = false; tabControlSettings.TabPages.RemoveAt(1); tabControlSettings.TabPages.RemoveAt(1); tabControlSettings.TabPages.RemoveAt(1); labelNoUser.Visible = true; } // only load settings if a user is present else { int selected = 0; int count = 0; foreach (string scrobbler in scrobbleusers) { if (!comboBoxUserName.Items.Contains(scrobbler)) { comboBoxUserName.Items.Add(scrobbler); } if (scrobbler == tmpuser) { selected = count; } count++; } comboBoxUserName.SelectedIndex = selected; buttonDelUser.Enabled = true; tmppass = mdb.AddScrobbleUserPassword(Convert.ToString(mdb.AddScrobbleUser(_currentUser)), ""); EncryptDecrypt Crypter = new EncryptDecrypt(); if (tmppass != string.Empty) { try { EncryptDecrypt DCrypter = new EncryptDecrypt(); maskedTextBoxASPassword.Text = DCrypter.Decrypt(tmppass); } catch (Exception) { //Log.Info("Audioscrobbler: Password decryption failed {0}", ex.Message); } } int tmpNMode = 1; int tmpRand = 77; int tmpArtists = 2; int tmpPreferTracks = 2; int tmpOfflineMode = 0; string tmpUserID = Convert.ToString(mdb.AddScrobbleUser(_currentUser)); checkBoxLogVerbose.Checked = (mdb.AddScrobbleUserSettings(tmpUserID, "iDebugLog", -1) == 1) ? true : false; tmpRand = mdb.AddScrobbleUserSettings(tmpUserID, "iRandomness", -1); checkBoxEnableSubmits.Checked = (mdb.AddScrobbleUserSettings(tmpUserID, "iSubmitOn", -1) == 1) ? true : false; checkBoxScrobbleDefault.Checked = (mdb.AddScrobbleUserSettings(tmpUserID, "iScrobbleDefault", -1) == 1) ? true : false; tmpArtists = mdb.AddScrobbleUserSettings(tmpUserID, "iAddArtists", -1); //numericUpDownTracksPerArtist.Value = mdb.AddScrobbleUserSettings(tmpUserID, "iAddTracks", -1); tmpNMode = mdb.AddScrobbleUserSettings(tmpUserID, "iNeighbourMode", -1); tmpOfflineMode = mdb.AddScrobbleUserSettings(tmpUserID, "iOfflineMode", -1); tmpPreferTracks = mdb.AddScrobbleUserSettings(tmpUserID, "iPreferCount", -1); checkBoxReAddArtist.Checked = (mdb.AddScrobbleUserSettings(tmpUserID, "iRememberStartArtist", -1) == 1) ? true : false; numericUpDownSimilarArtist.Value = (tmpArtists > 0) ? tmpArtists : 2; trackBarRandomness.Value = (tmpRand >= 25) ? tmpRand : 25; trackBarConsiderCount.Value = (tmpPreferTracks >= 0) ? tmpPreferTracks : 2; comboBoxOfflineMode.SelectedIndex = tmpOfflineMode; lastFmLookup = AudioscrobblerUtils.Instance; switch (tmpNMode) { case 3: lastFmLookup.CurrentNeighbourMode = lastFMFeed.topartists; comboBoxNeighbourMode.SelectedIndex = 0; comboBoxNModeSelect.SelectedIndex = 0; break; case 1: lastFmLookup.CurrentNeighbourMode = lastFMFeed.weeklyartistchart; comboBoxNeighbourMode.SelectedIndex = 1; comboBoxNModeSelect.SelectedIndex = 1; break; case 0: lastFmLookup.CurrentNeighbourMode = lastFMFeed.recenttracks; comboBoxNeighbourMode.SelectedIndex = 2; comboBoxNModeSelect.SelectedIndex = 2; break; default: lastFmLookup.CurrentNeighbourMode = lastFMFeed.weeklyartistchart; comboBoxNeighbourMode.SelectedIndex = 1; comboBoxNModeSelect.SelectedIndex = 1; break; } LoadProfileDetails(tmpuser); } } } catch (Exception ex) { Log.Error("Audioscrobbler settings could not be loaded: {0}", ex.Message); } }
protected void SaveSettings() { MusicDatabase mdb = MusicDatabase.Instance; int usedebuglog = 0; int submitsenabled = 1; int scrobbledefault = 1; int randomness = 77; int artisttoadd = 3; int trackstoadd = 1; int neighbourmode = 1; int offlinemode = 0; int prefercount = 2; int rememberstartartist = 1; if (comboBoxUserName.Text != string.Empty) { using (Settings xmlwriter = new MPSettings()) { xmlwriter.SetValue("audioscrobbler", "user", comboBoxUserName.Text); xmlwriter.SetValueAsBool("audioscrobbler", "EnableNowPlaying", checkBoxEnableNowPlaying.Checked); string tmpPass = ""; string tmpUserID = ""; try { EncryptDecrypt Crypter = new EncryptDecrypt(); tmpPass = Crypter.Encrypt(maskedTextBoxASPassword.Text); } catch (Exception) { //Log.Info("Audioscrobbler: Password encryption failed {0}", ex.Message); } // checks and adds the user if necessary + updates the password; mdb.AddScrobbleUserPassword(Convert.ToString(mdb.AddScrobbleUser(comboBoxUserName.Text)), tmpPass); if (checkBoxLogVerbose != null) { usedebuglog = checkBoxLogVerbose.Checked ? 1 : 0; } if (checkBoxEnableSubmits != null) { submitsenabled = checkBoxEnableSubmits.Checked ? 1 : 0; } if (checkBoxScrobbleDefault != null) { scrobbledefault = checkBoxScrobbleDefault.Checked ? 1 : 0; } if (trackBarRandomness != null) { randomness = trackBarRandomness.Value; } if (numericUpDownSimilarArtist != null) { artisttoadd = (int)numericUpDownSimilarArtist.Value; } //if (numericUpDownTracksPerArtist != null) // trackstoadd = (int)numericUpDownTracksPerArtist.Value; if (lastFmLookup != null) { neighbourmode = (int)lastFmLookup.CurrentNeighbourMode; } else { Log.Info("DEBUG *** lastFMLookup was null. neighbourmode: {0}", Convert.ToString(neighbourmode)); } if (comboBoxOfflineMode != null) { offlinemode = comboBoxOfflineMode.SelectedIndex; } if (trackBarConsiderCount != null) { prefercount = trackBarConsiderCount.Value; } if (checkBoxReAddArtist != null) { rememberstartartist = checkBoxReAddArtist.Checked ? 1 : 0; } tmpUserID = Convert.ToString(mdb.AddScrobbleUser(comboBoxUserName.Text)); mdb.AddScrobbleUserSettings(tmpUserID, "iDebugLog", usedebuglog); mdb.AddScrobbleUserSettings(tmpUserID, "iRandomness", randomness); mdb.AddScrobbleUserSettings(tmpUserID, "iSubmitOn", submitsenabled); mdb.AddScrobbleUserSettings(tmpUserID, "iScrobbleDefault", scrobbledefault); mdb.AddScrobbleUserSettings(tmpUserID, "iAddArtists", artisttoadd); mdb.AddScrobbleUserSettings(tmpUserID, "iAddTracks", trackstoadd); mdb.AddScrobbleUserSettings(tmpUserID, "iNeighbourMode", neighbourmode); mdb.AddScrobbleUserSettings(tmpUserID, "iOfflineMode", offlinemode); mdb.AddScrobbleUserSettings(tmpUserID, "iPreferCount", prefercount); mdb.AddScrobbleUserSettings(tmpUserID, "iRememberStartArtist", rememberstartartist); //} } } }