示例#1
0
 private void textBox_textTicks_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Enter)
     {
         string t  = textBox_textTicks.Text;
         string op = JsonOptions.GetOption("textTicks");
         if (op == "")
         {
             return;
         }
         string val   = op;
         int    ticks = 250;
         if (!int.TryParse(t, out ticks))
         {
             textBox_textTicks.Text = val;
             return;
         }
         if (ticks < 10)
         {
             ticks = 10;
             textBox_textTicks.Text = val;
         }
         this.ActiveControl = null;
         e.Handled          = true;
         setCanUpdate(true);
     }
 }
示例#2
0
 public void load(bool colors)
 {
     // wow this part is bad.
     Console.WriteLine("load up");
     toast_timer.Stop();
     if (JsonOptions.GetAllOptions())
     {
         if (colors)
         {
             SetColors();
         }
         if (JsonOptions.GetOption("showSongBorder") != "")
         {
             bool songBorder = JsonOptions.GetOption("showSongBorder").Equals("true");
             pictureBox1.BorderStyle = (songBorder ? BorderStyle.Fixed3D : BorderStyle.None);
         }
         if (JsonOptions.GetOption("disableBorder") != "")
         {
             noBorder             = bool.Parse(JsonOptions.GetOption("disableBorder"));
             this.FormBorderStyle = (noBorder ? FormBorderStyle.None : FormBorderStyle.FixedToolWindow);
         }
         if (JsonOptions.GetOption("barColor") != "")
         {
             int[] cS = Array.ConvertAll(JsonOptions.GetOption("barColor").Split(new[] { " " }, StringSplitOptions.None), int.Parse);
             progressBar1.BarColor = Color.FromArgb(255, cS[0], cS[1], cS[2]);
         }
         if (JsonOptions.GetOption("barHeight") != "")
         {
             int barHeight = int.Parse(JsonOptions.GetOption("barHeight"));
             progressBar1.Size      = new Size(this.Size.Width, 3 + barHeight);
             progressBar1.Location  = new Point(0, 69 - barHeight);
             label_version.Location = new Point(246, 55 - barHeight);
         }
         if (this.toast_isEnabled || JsonOptions.GetOption("toastMode").Equals("true"))
         {
             this.ShowInTaskbar = false;
             string btt  = "Spotify Toast";
             string _btt = "Spotify Toast is now hidden to the system tray";
             notify.ShowBalloonTip(5000, btt, _btt, ToolTipIcon.Info);
             toast_isEnabled      = true;
             this.FormBorderStyle = FormBorderStyle.None;
             if (this.toast_fadeIn)
             {
                 this.BackColor = Color.FromArgb(0, 255, 255, 255);
             }
             toast_timer.Tick += new EventHandler(this.TimerTick_Toast_Push);
             toast_timer.Start();
         }
         else if (toast_isEnabled)
         {
             this.ShowInTaskbar   = true;
             this.toast_isEnabled = false;
             this.CenterToScreen();
             toast_timer.Stop();
         }
         if (JsonOptions.GetOption("dontShowVersion") != "")
         {
             label_version.Visible = !JsonOptions.GetOption("dontShowVersion").Equals("true");
         }
         if (JsonOptions.GetOption("showAmountOfPlays") != "")
         {
             label1.Visible             = JsonOptions.GetOption("showAmountOfPlays").Equals("true");
             text_amountOfPlays.Visible = JsonOptions.GetOption("showAmountOfPlays").Equals("true");
         }
         if (JsonOptions.GetOption("textTicks") != "")
         {
             int tick = 250;
             if (!int.TryParse(JsonOptions.GetOption("textTicks"), out tick))
             {
                 tick = 250;
             }
             if (this.scroll_timer.Interval != tick)
             {
                 this.scroll_timer.Interval = tick;
             }
         }
         if (JsonOptions.GetOption("toastTicks") != "")
         {
             int tick = 5;
             if (int.TryParse(JsonOptions.GetOption("toastTicks"), out tick))
             {
                 toast_timer.Interval = tick;
             }
         }
         if (JsonOptions.GetOption("toastStickTime") != "")
         {
             int tick = 5;
             if (int.TryParse(JsonOptions.GetOption("toastStickTime"), out tick))
             {
                 toast_stickTime = tick;
             }
         }
         if (JsonOptions.GetOption("toastPosition") != "")
         {
             string pos = JsonOptions.GetOption("toastPosition");
             if (pos == "Bottom Right")
             {
                 toast_placement = toastPlacement.bottom_right;
             }
             else if (pos == "Bottom Left")
             {
                 toast_placement = toastPlacement.bottom_left;
             }
             else if (pos == "Bottom Center")
             {
                 toast_placement = toastPlacement.bottom_center;
             }
             else if (pos == "Top Left")
             {
                 toast_placement = toastPlacement.top_left;
             }
             else if (pos == "Top Center")
             {
                 toast_placement = toastPlacement.top_center;
             }
             else if (pos == "Top Right")
             {
                 toast_placement = toastPlacement.top_right;
             }
         }
     }
     if (newLocation != null)
     {
         this.Location = (Point)newLocation;
     }
     UpdateTrack(true);
 }
示例#3
0
 private void SetColors()
 {
     if (JsonOptions.GetOption("changeColorWithSong").Equals("true"))
     {
         try {
             Color  color   = GetMostFrequentPixels((Bitmap)bp);
             double rV      = 255 - color.R; // R
             double gV      = 255 - color.G; // G
             double bV      = 255 - color.B; // B
             double rV_comp = rV - color.R;  // color - whatever color was inverted
             double gV_comp = rV - color.G;
             double bV_comp = bV - color.B;
             Console.WriteLine(rV_comp + " " + gV_comp + " " + bV_comp);
             if (rV_comp <= 50 && rV_comp >= -50)
             {
                 rV += (rV <= 55 ? 200 : (rV > 200 ? -150 : (rV > 100 ? -100 : -50)));
             }
             if (gV_comp <= 50 && gV_comp >= -50)
             {
                 gV += (gV <= 55 ? 200 : (gV > 200 ? -150 : (gV > 100 ? -100 : -50)));
             }
             if (bV_comp <= 50 && bV_comp >= -50)
             {
                 bV += (bV <= 55 ? 200 : (bV > 200 ? -150 : (bV > 100 ? -100 : -50)));
             }
             Console.WriteLine(rV + ", " + color.R);
             Console.WriteLine(gV + ", " + color.G);
             Console.WriteLine(bV + ", " + color.B);
             Color invert = Color.FromArgb(255, (int)rV, (int)gV, (int)bV);
             //progressBar1.BarColor = invert;
             text_songName.ForeColor      = invert;
             text_artistName.ForeColor    = invert;
             label1.ForeColor             = invert;
             label_version.ForeColor      = invert;
             text_amountOfPlays.ForeColor = invert;
             this.BackColor = currentColor = Color.FromArgb(this.toast_fadeIn ? this.BackColor.A : color.A, color.R, color.G, color.B);
         }
         catch (Exception e) { Console.WriteLine(e.Message); }
     }
     else
     {
         if (JsonOptions.GetOption("defaultColor") != "")
         {
             int[] cS    = Array.ConvertAll(JsonOptions.GetOption("defaultColor").Split(new[] { " " }, StringSplitOptions.None), int.Parse);
             Color color = Color.FromArgb(255, cS[0], cS[1], cS[2]);
             if (!JsonOptions.GetOption("defaultTextColor").Equals("true"))
             {
                 Color invert = Color.FromArgb(255, 255 - color.R, 255 - color.G, 255 - color.B);
                 //progressBar1.BarColor = invert;
                 text_songName.ForeColor   = invert;
                 text_artistName.ForeColor = invert;
             }
             this.BackColor = currentColor = Color.FromArgb(this.toast_fadeIn ? this.BackColor.A : color.A, color.R, color.G, color.B);
         }
         if (JsonOptions.GetOption("defaultTextColor") != "")
         {
             int[] cS    = Array.ConvertAll(JsonOptions.GetOption("defaultTextColor").Split(new[] { " " }, StringSplitOptions.None), int.Parse);
             Color color = Color.FromArgb(255, cS[0], cS[1], cS[2]);
             text_songName.ForeColor   = color;
             text_artistName.ForeColor = color;
         }
     }
 }
示例#4
0
        /// <summary>Update all info on the track
        /// <para><see cref="SpotifyLocalAPI.GetStatus()"/></para>
        /// </summary>
        public void UpdateTrack(bool canAdd)
        {
            if (bp != null)
            {
                bp.Dispose();
            }
            if (this.toast_isEnabled)
            {
                toast_timer.Start();
            }
            if (_spotify.GetStatus().Track != null && _spotify.GetStatus().Track.Length > 0 && _spotify.GetStatus().Running)
            {
                Size s = new Size(64, 64);
                bp = new Bitmap(_spotify.GetStatus().Track.GetAlbumArt(AlbumArtSize.Size160), s);
                pictureBox1.Image = bp;
                SetColors();
            }
            else
            {
                text_songName.Text   = (trackName = "No current song playing");
                trackNameLength      = 0;
                text_artistName.Text = "No artist";
                progressBar1.Maximum = 0;
                return;
            }
            text_songName.Text   = (trackName = _spotify.GetStatus().Track.TrackResource.Name + "              ");
            trackNameLength      = trackName.Length;
            text_artistName.Text = _spotify.GetStatus().Track.ArtistResource.Name;
            progressBar1.Maximum = _spotify.GetStatus().Track.Length;
            if (JsonOptions.GetOption("showAmountOfPlays").Equals("true") && canAdd)
            {
                int    plays    = 1;
                string songName = text_songName.Text.Trim();
                if (songName.Length > 10)
                {
                    songName = songName.Substring(0, 10);
                }
                string artistName = text_artistName.Text.Trim();
                if (artistName.Length > 7)
                {
                    artistName = artistName.Substring(0, 7);
                }

                for (int i = 0; i < songs.Count; i++)
                {
                    JObject _song = (JObject)songs[i];
                    if (((string)_song.GetValue("name")) == songName && ((string)_song.GetValue("artist")) == artistName)
                    {
                        string _p = (string)_song.GetValue("plays");
                        if (Int32.TryParse(_p, out plays))
                        {
                            plays += 1;
                        }
                        else
                        {
                            plays = 1;
                        }
                        songs.RemoveAt(i);
                        break;
                    }
                }
                JObject song = new JObject(
                    new JProperty("artist", artistName),
                    new JProperty("name", songName),
                    new JProperty("plays", plays)
                    );
                if (plays > 1)
                {
                    JObject oldSong = new JObject(
                        new JProperty("artist", artistName),
                        new JProperty("name", songName),
                        new JProperty("plays", plays - 1)
                        );
                    if (songs.Contains(oldSong))
                    {
                        songs.Remove(oldSong);
                    }
                }
                songs.Add(song);


                /*Song _Song = new Song();
                 * _Song.artist = text_artistName.Text;
                 * _Song.name = text_songName.Text.Trim();
                 * _Song.plays = plays;
                 * if(songHistory.Count >= 5) {
                 *  songHistory.RemoveAt(5);
                 * }
                 * songHistory.Add(_Song);*/

                string json = JsonConvert.SerializeObject(songs);
                File.WriteAllText("./songs.json", json);
                text_amountOfPlays.Text = plays.ToString();
            }
        }
示例#5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!Spotify.Spotify_Load(this))
            {
                return;
            }
            Application.AddMessageFilter(this);
            dragControls.Add(this);
            dragControls.Add(text_artistName);
            dragControls.Add(text_songName);
            dragControls.Add(text_amountOfPlays);
            dragControls.Add(label1);
            dragControls.Add(pictureBox1);
            progressBar1.Size   = new Size(this.Size.Width, 3);
            progressBar1.Click += progressBar1_Click;
            progressBar1.Parent = this;

            scroll_timer.Tick += new EventHandler(this.TimerTick_Scroll);
            scroll_timer.Start();
            label_version.Text = "v" + ToastTest.Program.version;
            load(false);
            if (notify.ContextMenu == null)
            {
                notify.DoubleClick += new EventHandler(this.notify_click);
                this.notify_contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.notify_menu1 });
                this.notify_contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.notify_menu2 });
                this.notify_menu1.Index  = 0;
                this.notify_menu1.Text   = "Open Options";
                this.notify_menu1.Click += new System.EventHandler(this.label3_click);
                this.notify_menu2.Index  = 1;
                this.notify_menu2.Text   = "E&xit";
                this.notify_menu2.Click += new System.EventHandler(this.notify_menu1_close);
            }
            notify.ContextMenu = this.notify_contextMenu;

            /*notify.BalloonTipClosed += (_sender, _e) => {
             *  var thisIcon = (NotifyIcon) _sender;
             *  thisIcon.Visible = false;
             *  thisIcon.Dispose();
             * };*/
            if (JsonOptions.GetOption("showAmountOfPlays").Equals("true"))
            {
                JsonSerializer serializer = new JsonSerializer();
                using (FileStream fs = File.Open("./songs.json", FileMode.Open))
                    using (StreamReader sr = new StreamReader(fs))
                        using (JsonReader reader = new JsonTextReader(sr)) {
                            while (reader.Read())
                            {
                                if (reader.TokenType == JsonToken.StartObject)
                                {
                                    Song    _song = serializer.Deserialize <Song>(reader);
                                    JObject song  = new JObject(
                                        new JProperty("artist", _song.artist),
                                        new JProperty("name", _song.name),
                                        new JProperty("plays", _song.plays)
                                        );
                                    songs.Add(song);
                                }
                            }
                            reader.Close();
                            sr.Close();
                            fs.Close();
                        }
            }
            Console.WriteLine("Spotify Toast started");
        }
示例#6
0
        private void Options_Load(object sender, EventArgs e)
        {
            if (JsonOptions.GetOption("alwaysOnTop") != "")
            {
                checkBox_alwaysOnTop.Checked = JsonOptions.GetOption("alwaysOnTop").Equals("true");
            }
            bool changeColorWithSong = false;

            if (JsonOptions.GetOption("changeColorWithSong") != "")
            {
                checkBox_changeColorWithSong.Checked = changeColorWithSong = JsonOptions.GetOption("changeColorWithSong").Equals("true");
            }
            if (changeColorWithSong)
            {
                button_selectColor.Visible     = false;
                button_selectTextColor.Visible = false;
            }
            else
            {
                button_selectColor.Visible     = true;
                button_selectTextColor.Visible = true;
            }
            if (JsonOptions.GetOption("toastMode") != "")
            {
                checkBox_toastMode.Checked = toastMode = JsonOptions.GetOption("toastMode").Equals("true");
            }
            if (toastMode)
            {
                if (JsonOptions.GetOption("toastMode_fadeIn") != "")
                {
                    checkBox_toast_fadeIn.Visible = true;
                    checkBox_toast_fadeIn.Checked = JsonOptions.GetOption("toastMode_fadeIn").Equals("true");
                }
                if (JsonOptions.GetOption("toastTicks") != "")
                {
                    int    toastTicks;
                    string ticks = JsonOptions.GetOption("toastTicks");
                    if (int.TryParse(ticks, out toastTicks))
                    {
                        defaultToastTicks  = toastTicks;
                        textBox_ticks.Text = ticks;
                    }
                    else
                    {
                        textBox_ticks.Text = "5";
                    }
                }
                else
                {
                    textBox_ticks.Text = "5";
                }
                if (JsonOptions.GetOption("toastStickTime") != "")
                {
                    int    toastTicks;
                    string ticks = JsonOptions.GetOption("toastStickTime");
                    if (int.TryParse(ticks, out toastTicks))
                    {
                        defaultToastStickTime       = toastTicks;
                        textBox_toastStickTime.Text = ticks;
                    }
                    else
                    {
                        textBox_toastStickTime.Text = "120";
                    }
                }
                else
                {
                    textBox_toastStickTime.Text = "120";
                }
            }
            else
            {
                checkBox_toast_fadeIn.Visible  = false;
                textBox_ticks.Visible          = false;
                textBox_toastStickTime.Visible = false;
                comboBox_toastPosition.Visible = false;
                label4.Visible = false;
                label1.Visible = false;
            }
            if (JsonOptions.GetOption("toastPosition") != "")
            {
                defaultToastPosition = JsonOptions.GetOption("toastPosition");
            }
            if (JsonOptions.GetOption("showAmountOfPlays") != "")
            {
                checkBox_amountPlayed.Checked = JsonOptions.GetOption("showAmountOfPlays").Equals("true");
            }
            if (JsonOptions.GetOption("dontShowVersion") != "")
            {
                checkBox_showVersion.Checked = JsonOptions.GetOption("dontShowVersion").Equals("true");
            }
            if (JsonOptions.GetOption("textTicks") != "")
            {
                textBox_textTicks.Text = JsonOptions.GetOption("textTicks");
            }
            if (JsonOptions.GetOption("barHeight") != "")
            {
                int trackBar = int.Parse(JsonOptions.GetOption("barHeight"));
                trackBar_barHeight.Value = trackBar;
            }
            if (JsonOptions.GetOption("showSongBorder") != "")
            {
                checkBox_showSongBorder.Checked = JsonOptions.GetOption("showSongBorder").Equals("true");
            }
            if (JsonOptions.GetOption("disableBorder") != "")
            {
                checkBox_disableBorder.Checked = JsonOptions.GetOption("disableBorder").Equals("true");
            }
            textColor      = JsonOptions.GetOption("defaultTextColor");
            color          = JsonOptions.GetOption("defaultColor");
            barColor       = JsonOptions.GetOption("barColor");
            updatingChecks = false;
            //int i = 0;

            /*foreach(Form1.Song song in Form1.songHistory) {
             *  i += 1;
             *  //radioButton_history[i] = song.name;
             * }*/
            Console.WriteLine("Options form loaded");
        }