Эх сурвалжийг харах

Merge pull request #1 from yorickr/gui

Merge gui into develop
Kenneth van Ewijk 10 жил өмнө
parent
commit
05bf1bce21

+ 13 - 12
MusicPlayer/MusicPlayer/APIHandler.cs

@@ -13,10 +13,11 @@ namespace MusicPlayer
     public class APIHandler
     public class APIHandler
     {
     {
         private NetworkHandler nw;
         private NetworkHandler nw;
-
+        private Image defaultCover;
         public APIHandler(NetworkHandler nw)
         public APIHandler(NetworkHandler nw)
         {
         {
             this.nw = nw;
             this.nw = nw;
+            defaultCover = Image.FromStream(nw.downloadArtwork("default-cover.png"));
         }
         }
 
 
         public string GetSongURLByID(string id)
         public string GetSongURLByID(string id)
@@ -94,26 +95,26 @@ namespace MusicPlayer
             return artistlist;
             return artistlist;
         }
         }
 
 
+        public Image getAlbumCover(string album)
+        {
+            MemoryStream stream = nw.downloadArtwork(album + ".jpg");
+            if(stream != null)
+            {
+                return Image.FromStream(stream);
+            }
+            return defaultCover;
+        }
+
         public List<Album> GetAlbums()
         public List<Album> GetAlbums()
         {
         {
             List<Album> albumlist = new List<Album>();
             List<Album> albumlist = new List<Album>();
-            return albumlist;
 
 
-            Image def = Image.FromStream(nw.downloadArtwork("default-cover.png"));
             JObject o = nw.SendString("getalbums?id=hallo");
             JObject o = nw.SendString("getalbums?id=hallo");
             if (o["result"].ToString() == "OK")
             if (o["result"].ToString() == "OK")
             {
             {
                 for (int i = 0; i < o["albums"].Count(); i++)
                 for (int i = 0; i < o["albums"].Count(); i++)
                 {
                 {
-                    MemoryStream stream = nw.downloadArtwork(o["albums"][i][0].ToString() + ".jpg");
-                    if (stream != null) { 
-                        albumlist.Add(new Album(o["albums"][i][0].ToString(), Image.FromStream(stream)));
-                        stream.Close();
-                    }
-                    else
-                    {
-                        albumlist.Add(new Album(o["albums"][i][0].ToString(), def));
-                    }
+                    albumlist.Add(new Album(o["albums"][i][0].ToString()));
                 }
                 }
             }
             }
 
 

+ 1 - 3
MusicPlayer/MusicPlayer/Album.cs

@@ -6,12 +6,10 @@ namespace MusicPlayer
     public class Album
     public class Album
     {
     {
         public string albumnaam { get; set; }
         public string albumnaam { get; set; }
-        public Image cover;
 
 
-        public Album(string albumnaam, Image c)
+        public Album(string albumnaam)
         {
         {
             this.albumnaam = albumnaam;
             this.albumnaam = albumnaam;
-            this.cover = c;
         }
         }
     }
     }
 }
 }

+ 44 - 5
MusicPlayer/MusicPlayer/Main.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
@@ -16,8 +17,7 @@ namespace MusicPlayer
         public AudioHandler audio;
         public AudioHandler audio;
 
 
         public SongsTable table;
         public SongsTable table;
-        private ImageList imagelist;
-
+       
         private List<string> genres;
         private List<string> genres;
         private List<string> artists;
         private List<string> artists;
 
 
@@ -33,7 +33,6 @@ namespace MusicPlayer
 
 
             audio = new AudioHandler(this);
             audio = new AudioHandler(this);
             table = new SongsTable();
             table = new SongsTable();
-            imagelist = new ImageList();
             form.SongsTableView.DataSource = table;
             form.SongsTableView.DataSource = table;
             form.SongsTableView.Columns[5].Visible = false;
             form.SongsTableView.Columns[5].Visible = false;
 
 
@@ -45,13 +44,53 @@ namespace MusicPlayer
             Populate();
             Populate();
         }
         }
 
 
+        public void SwitchServer(string server)
+        {
+            Clear();
+            nw.ip = server;
+            Populate();
+        }
+
+        private void Clear()
+        {
+            form.GenreListBox.Items.Clear();
+            form.ArtistListBox.Items.Clear();
+            form.AlbumListView.Items.Clear();
+            form.PlaylistBox.Items.Clear();
+            table.Clear();
+
+            genres = new List<string>();
+            artists = new List<string>();
+
+            currentPlayingList = new List<Song>();
+        }
+
         private void Populate()
         private void Populate()
         {
         {
-            form.AlbumListView.LargeImageList = imagelist;
-            this.api.GetAlbums().ForEach(a => { var item = form.AlbumListView.Items.Add(a.albumnaam); imagelist.Images.Add(a.albumnaam, a.cover); item.ImageKey = a.albumnaam;});
+            this.api.GetAlbums().ForEach(a => { form.AlbumListView.Items.Add(a.albumnaam);});
             this.api.GetArtists().ForEach(a => { artists.Add(a.naam); form.ArtistListBox.Items.Add(a.naam); });
             this.api.GetArtists().ForEach(a => { artists.Add(a.naam); form.ArtistListBox.Items.Add(a.naam); });
             this.api.GetGenres().ForEach(g => { genres.Add(g.name); form.GenreListBox.Items.Add(g.name); });
             this.api.GetGenres().ForEach(g => { genres.Add(g.name); form.GenreListBox.Items.Add(g.name); });
             this.pl.GetPlaylists().ForEach(p =>  form.PlaylistBox.Items.Add(p.name));
             this.pl.GetPlaylists().ForEach(p =>  form.PlaylistBox.Items.Add(p.name));
+            BackgroundWorker bw = new BackgroundWorker();
+            bw.DoWork += new DoWorkEventHandler(
+            delegate (object o, DoWorkEventArgs args)
+            {
+                BackgroundWorker b = o as BackgroundWorker;
+                ImageList imagelist = new ImageList();
+                foreach (ListViewItem item in form.AlbumListView.Items)
+                {
+                    imagelist.Images.Add(item.ToString(), api.getAlbumCover(item.Text));
+                }
+                Action action = () => {
+                    form.AlbumListView.LargeImageList = imagelist;
+                    foreach (ListViewItem item in form.AlbumListView.Items)
+                    {
+                        item.ImageKey = item.ToString(); 
+                    }
+                };
+                form.Invoke(action);
+            });
+            bw.RunWorkerAsync();
         }
         }
 
 
         public void Repopulate()
         public void Repopulate()

+ 54 - 20
MusicPlayer/MusicPlayer/MainForm.Designer.cs

@@ -40,10 +40,10 @@ namespace MusicPlayer
             this.MainPanel = new System.Windows.Forms.Panel();
             this.MainPanel = new System.Windows.Forms.Panel();
             this.SplitContainer = new System.Windows.Forms.SplitContainer();
             this.SplitContainer = new System.Windows.Forms.SplitContainer();
             this.PlaylistBox = new System.Windows.Forms.ListBox();
             this.PlaylistBox = new System.Windows.Forms.ListBox();
-            this.PlaylistListLabel = new System.Windows.Forms.Label();
             this.AlbumListLabel = new System.Windows.Forms.Label();
             this.AlbumListLabel = new System.Windows.Forms.Label();
             this.ArtistListLabel = new System.Windows.Forms.Label();
             this.ArtistListLabel = new System.Windows.Forms.Label();
             this.GenreListLabel = new System.Windows.Forms.Label();
             this.GenreListLabel = new System.Windows.Forms.Label();
+            this.PlaylistListLabel = new System.Windows.Forms.Label();
             this.MenuStrip = new System.Windows.Forms.MenuStrip();
             this.MenuStrip = new System.Windows.Forms.MenuStrip();
             this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
             this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
@@ -66,6 +66,9 @@ namespace MusicPlayer
             this.SearchArtistToolStripLabel = new System.Windows.Forms.ToolStripMenuItem();
             this.SearchArtistToolStripLabel = new System.Windows.Forms.ToolStripMenuItem();
             this.SearchArtistsTextBox = new System.Windows.Forms.ToolStripTextBox();
             this.SearchArtistsTextBox = new System.Windows.Forms.ToolStripTextBox();
             this.ClearArtistSearchButton = new System.Windows.Forms.ToolStripMenuItem();
             this.ClearArtistSearchButton = new System.Windows.Forms.ToolStripMenuItem();
+            this.serverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+            this.SelectServerJancoButton = new System.Windows.Forms.ToolStripMenuItem();
+            this.SelectServerYorickButton = new System.Windows.Forms.ToolStripMenuItem();
             this.ControlsPanel = new System.Windows.Forms.Panel();
             this.ControlsPanel = new System.Windows.Forms.Panel();
             this.NextButton = new System.Windows.Forms.Button();
             this.NextButton = new System.Windows.Forms.Button();
             this.PreviousButton = new System.Windows.Forms.Button();
             this.PreviousButton = new System.Windows.Forms.Button();
@@ -129,6 +132,9 @@ namespace MusicPlayer
             this.SongsTableView.Size = new System.Drawing.Size(760, 174);
             this.SongsTableView.Size = new System.Drawing.Size(760, 174);
             this.SongsTableView.TabIndex = 0;
             this.SongsTableView.TabIndex = 0;
             this.SongsTableView.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.SongsTableView_CellDoubleClick);
             this.SongsTableView.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.SongsTableView_CellDoubleClick);
+            this.SongsTableView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.SongsTableView_MouseDown);
+            this.SongsTableView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.SongsTableView_MouseMove);
+            this.SongsTableView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.SongsTableView_MouseUp);
             // 
             // 
             // GenreListBox
             // GenreListBox
             // 
             // 
@@ -136,7 +142,7 @@ namespace MusicPlayer
             | System.Windows.Forms.AnchorStyles.Left)));
             | System.Windows.Forms.AnchorStyles.Left)));
             this.GenreListBox.BackColor = System.Drawing.SystemColors.Control;
             this.GenreListBox.BackColor = System.Drawing.SystemColors.Control;
             this.GenreListBox.FormattingEnabled = true;
             this.GenreListBox.FormattingEnabled = true;
-            this.GenreListBox.Location = new System.Drawing.Point(3, 3);
+            this.GenreListBox.Location = new System.Drawing.Point(0, 0);
             this.GenreListBox.Name = "GenreListBox";
             this.GenreListBox.Name = "GenreListBox";
             this.GenreListBox.Size = new System.Drawing.Size(150, 121);
             this.GenreListBox.Size = new System.Drawing.Size(150, 121);
             this.GenreListBox.Sorted = true;
             this.GenreListBox.Sorted = true;
@@ -149,10 +155,10 @@ namespace MusicPlayer
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             | System.Windows.Forms.AnchorStyles.Right)));
             this.AlbumListView.BackColor = System.Drawing.SystemColors.Control;
             this.AlbumListView.BackColor = System.Drawing.SystemColors.Control;
-            this.AlbumListView.Location = new System.Drawing.Point(309, 3);
+            this.AlbumListView.Location = new System.Drawing.Point(312, 0);
             this.AlbumListView.MultiSelect = false;
             this.AlbumListView.MultiSelect = false;
             this.AlbumListView.Name = "AlbumListView";
             this.AlbumListView.Name = "AlbumListView";
-            this.AlbumListView.Size = new System.Drawing.Size(451, 121);
+            this.AlbumListView.Size = new System.Drawing.Size(448, 121);
             this.AlbumListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
             this.AlbumListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
             this.AlbumListView.TabIndex = 2;
             this.AlbumListView.TabIndex = 2;
             this.AlbumListView.TileSize = new System.Drawing.Size(140, 30);
             this.AlbumListView.TileSize = new System.Drawing.Size(140, 30);
@@ -166,7 +172,7 @@ namespace MusicPlayer
             | System.Windows.Forms.AnchorStyles.Left)));
             | System.Windows.Forms.AnchorStyles.Left)));
             this.ArtistListBox.BackColor = System.Drawing.SystemColors.Control;
             this.ArtistListBox.BackColor = System.Drawing.SystemColors.Control;
             this.ArtistListBox.FormattingEnabled = true;
             this.ArtistListBox.FormattingEnabled = true;
-            this.ArtistListBox.Location = new System.Drawing.Point(156, 3);
+            this.ArtistListBox.Location = new System.Drawing.Point(156, 0);
             this.ArtistListBox.Name = "ArtistListBox";
             this.ArtistListBox.Name = "ArtistListBox";
             this.ArtistListBox.Size = new System.Drawing.Size(150, 121);
             this.ArtistListBox.Size = new System.Drawing.Size(150, 121);
             this.ArtistListBox.Sorted = true;
             this.ArtistListBox.Sorted = true;
@@ -180,10 +186,10 @@ namespace MusicPlayer
             | System.Windows.Forms.AnchorStyles.Right)));
             | System.Windows.Forms.AnchorStyles.Right)));
             this.MainPanel.BackColor = System.Drawing.SystemColors.Window;
             this.MainPanel.BackColor = System.Drawing.SystemColors.Window;
             this.MainPanel.Controls.Add(this.SplitContainer);
             this.MainPanel.Controls.Add(this.SplitContainer);
-            this.MainPanel.Controls.Add(this.PlaylistListLabel);
             this.MainPanel.Controls.Add(this.AlbumListLabel);
             this.MainPanel.Controls.Add(this.AlbumListLabel);
             this.MainPanel.Controls.Add(this.ArtistListLabel);
             this.MainPanel.Controls.Add(this.ArtistListLabel);
             this.MainPanel.Controls.Add(this.GenreListLabel);
             this.MainPanel.Controls.Add(this.GenreListLabel);
+            this.MainPanel.Controls.Add(this.PlaylistListLabel);
             this.MainPanel.Location = new System.Drawing.Point(0, 24);
             this.MainPanel.Location = new System.Drawing.Point(0, 24);
             this.MainPanel.Name = "MainPanel";
             this.MainPanel.Name = "MainPanel";
             this.MainPanel.Size = new System.Drawing.Size(784, 351);
             this.MainPanel.Size = new System.Drawing.Size(784, 351);
@@ -215,6 +221,7 @@ namespace MusicPlayer
             // 
             // 
             // PlaylistBox
             // PlaylistBox
             // 
             // 
+            this.PlaylistBox.BackColor = System.Drawing.SystemColors.Control;
             this.PlaylistBox.Dock = System.Windows.Forms.DockStyle.Fill;
             this.PlaylistBox.Dock = System.Windows.Forms.DockStyle.Fill;
             this.PlaylistBox.FormattingEnabled = true;
             this.PlaylistBox.FormattingEnabled = true;
             this.PlaylistBox.Location = new System.Drawing.Point(0, 0);
             this.PlaylistBox.Location = new System.Drawing.Point(0, 0);
@@ -224,20 +231,10 @@ namespace MusicPlayer
             this.PlaylistBox.Visible = false;
             this.PlaylistBox.Visible = false;
             this.PlaylistBox.SelectedIndexChanged += new System.EventHandler(this.PlaylistBox_SelectedIndexChanged);
             this.PlaylistBox.SelectedIndexChanged += new System.EventHandler(this.PlaylistBox_SelectedIndexChanged);
             // 
             // 
-            // PlaylistListLabel
-            // 
-            this.PlaylistListLabel.AutoSize = true;
-            this.PlaylistListLabel.Location = new System.Drawing.Point(12, 8);
-            this.PlaylistListLabel.Name = "PlaylistListLabel";
-            this.PlaylistListLabel.Size = new System.Drawing.Size(39, 13);
-            this.PlaylistListLabel.TabIndex = 7;
-            this.PlaylistListLabel.Text = "Playlist";
-            this.PlaylistListLabel.Visible = false;
-            // 
             // AlbumListLabel
             // AlbumListLabel
             // 
             // 
             this.AlbumListLabel.AutoSize = true;
             this.AlbumListLabel.AutoSize = true;
-            this.AlbumListLabel.Location = new System.Drawing.Point(321, 9);
+            this.AlbumListLabel.Location = new System.Drawing.Point(321, 8);
             this.AlbumListLabel.Name = "AlbumListLabel";
             this.AlbumListLabel.Name = "AlbumListLabel";
             this.AlbumListLabel.Size = new System.Drawing.Size(36, 13);
             this.AlbumListLabel.Size = new System.Drawing.Size(36, 13);
             this.AlbumListLabel.TabIndex = 6;
             this.AlbumListLabel.TabIndex = 6;
@@ -246,7 +243,7 @@ namespace MusicPlayer
             // ArtistListLabel
             // ArtistListLabel
             // 
             // 
             this.ArtistListLabel.AutoSize = true;
             this.ArtistListLabel.AutoSize = true;
-            this.ArtistListLabel.Location = new System.Drawing.Point(165, 9);
+            this.ArtistListLabel.Location = new System.Drawing.Point(165, 8);
             this.ArtistListLabel.Name = "ArtistListLabel";
             this.ArtistListLabel.Name = "ArtistListLabel";
             this.ArtistListLabel.Size = new System.Drawing.Size(30, 13);
             this.ArtistListLabel.Size = new System.Drawing.Size(30, 13);
             this.ArtistListLabel.TabIndex = 5;
             this.ArtistListLabel.TabIndex = 5;
@@ -255,12 +252,22 @@ namespace MusicPlayer
             // GenreListLabel
             // GenreListLabel
             // 
             // 
             this.GenreListLabel.AutoSize = true;
             this.GenreListLabel.AutoSize = true;
-            this.GenreListLabel.Location = new System.Drawing.Point(12, 9);
+            this.GenreListLabel.Location = new System.Drawing.Point(9, 8);
             this.GenreListLabel.Name = "GenreListLabel";
             this.GenreListLabel.Name = "GenreListLabel";
             this.GenreListLabel.Size = new System.Drawing.Size(36, 13);
             this.GenreListLabel.Size = new System.Drawing.Size(36, 13);
             this.GenreListLabel.TabIndex = 4;
             this.GenreListLabel.TabIndex = 4;
             this.GenreListLabel.Text = "Genre";
             this.GenreListLabel.Text = "Genre";
             // 
             // 
+            // PlaylistListLabel
+            // 
+            this.PlaylistListLabel.AutoSize = true;
+            this.PlaylistListLabel.Location = new System.Drawing.Point(12, 9);
+            this.PlaylistListLabel.Name = "PlaylistListLabel";
+            this.PlaylistListLabel.Size = new System.Drawing.Size(39, 13);
+            this.PlaylistListLabel.TabIndex = 7;
+            this.PlaylistListLabel.Text = "Playlist";
+            this.PlaylistListLabel.Visible = false;
+            // 
             // MenuStrip
             // MenuStrip
             // 
             // 
             this.MenuStrip.BackColor = System.Drawing.SystemColors.WindowFrame;
             this.MenuStrip.BackColor = System.Drawing.SystemColors.WindowFrame;
@@ -269,7 +276,8 @@ namespace MusicPlayer
             this.viewToolStripMenuItem,
             this.viewToolStripMenuItem,
             this.playbackToolStripMenuItem,
             this.playbackToolStripMenuItem,
             this.playlistToolStripMenuItem,
             this.playlistToolStripMenuItem,
-            this.searchToolStripMenuItem});
+            this.searchToolStripMenuItem,
+            this.serverToolStripMenuItem});
             this.MenuStrip.Location = new System.Drawing.Point(0, 0);
             this.MenuStrip.Location = new System.Drawing.Point(0, 0);
             this.MenuStrip.Name = "MenuStrip";
             this.MenuStrip.Name = "MenuStrip";
             this.MenuStrip.Size = new System.Drawing.Size(784, 24);
             this.MenuStrip.Size = new System.Drawing.Size(784, 24);
@@ -440,6 +448,29 @@ namespace MusicPlayer
             this.ClearArtistSearchButton.Text = "Clear Search";
             this.ClearArtistSearchButton.Text = "Clear Search";
             this.ClearArtistSearchButton.Click += new System.EventHandler(this.ClearArtistSearchButton_Click);
             this.ClearArtistSearchButton.Click += new System.EventHandler(this.ClearArtistSearchButton_Click);
             // 
             // 
+            // serverToolStripMenuItem
+            // 
+            this.serverToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.SelectServerJancoButton,
+            this.SelectServerYorickButton});
+            this.serverToolStripMenuItem.Name = "serverToolStripMenuItem";
+            this.serverToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
+            this.serverToolStripMenuItem.Text = "Server";
+            // 
+            // SelectServerJancoButton
+            // 
+            this.SelectServerJancoButton.Name = "SelectServerJancoButton";
+            this.SelectServerJancoButton.Size = new System.Drawing.Size(148, 22);
+            this.SelectServerJancoButton.Text = "jancokock.me";
+            this.SelectServerJancoButton.Click += new System.EventHandler(this.SelectServerJancoButton_Click);
+            // 
+            // SelectServerYorickButton
+            // 
+            this.SelectServerYorickButton.Name = "SelectServerYorickButton";
+            this.SelectServerYorickButton.Size = new System.Drawing.Size(148, 22);
+            this.SelectServerYorickButton.Text = "imegumii.nl";
+            this.SelectServerYorickButton.Click += new System.EventHandler(this.SelectServerYorickButton_Click);
+            // 
             // ControlsPanel
             // ControlsPanel
             // 
             // 
             this.ControlsPanel.BackColor = System.Drawing.SystemColors.WindowFrame;
             this.ControlsPanel.BackColor = System.Drawing.SystemColors.WindowFrame;
@@ -754,6 +785,9 @@ namespace MusicPlayer
         private System.Windows.Forms.ToolStripMenuItem NotifyMenuStripPreviousButton;
         private System.Windows.Forms.ToolStripMenuItem NotifyMenuStripPreviousButton;
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
         private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
         private System.Windows.Forms.ToolStripMenuItem ViewCurrentPlaylistButton;
         private System.Windows.Forms.ToolStripMenuItem ViewCurrentPlaylistButton;
+        private System.Windows.Forms.ToolStripMenuItem serverToolStripMenuItem;
+        private System.Windows.Forms.ToolStripMenuItem SelectServerJancoButton;
+        private System.Windows.Forms.ToolStripMenuItem SelectServerYorickButton;
     }
     }
 }
 }
 
 

+ 82 - 2
MusicPlayer/MusicPlayer/MainForm.cs

@@ -19,6 +19,10 @@ namespace MusicPlayer
     public partial class MainForm : Form
     public partial class MainForm : Form
     {
     {
         bool songFinished;
         bool songFinished;
+        bool draggedstarted = false;
+        bool draggedcompleted = false;
+        int startx = 0;
+        int starty = 0;
 
 
         public Main main
         public Main main
         {
         {
@@ -85,7 +89,7 @@ namespace MusicPlayer
             else
             else
                 PositionTrackBar.Enabled = false;
                 PositionTrackBar.Enabled = false;
             if (!clicked)
             if (!clicked)
-                PositionTrackBar.Value = main.audio.Position;
+                PositionTrackBar.Value = Math.Max(main.audio.Position, 0);
 
 
             //Buffer display
             //Buffer display
             BufferBar.Value = main.audio.Buffered / 10;
             BufferBar.Value = main.audio.Buffered / 10;
@@ -99,7 +103,11 @@ namespace MusicPlayer
             if (main.audio.CurrentSong == null)
             if (main.audio.CurrentSong == null)
                 CurrentSongLabel.Text = "Not playing any songs";
                 CurrentSongLabel.Text = "Not playing any songs";
             else
             else
+            {
+                if (main.audio.CurrentSong.Seconds < 1)
+                    PositionTrackBar.Enabled = false;
                 CurrentSongLabel.Text = "Currently playing: " + main.audio.CurrentSong.Name;
                 CurrentSongLabel.Text = "Currently playing: " + main.audio.CurrentSong.Name;
+            }
 
 
             //Buttons and context menu
             //Buttons and context menu
             if (main.audio.AState == AudioHandler.AudioState.PLAYING)
             if (main.audio.AState == AudioHandler.AudioState.PLAYING)
@@ -118,6 +126,16 @@ namespace MusicPlayer
                 NotifyMenuStripPlayingSongLabel.Visible = false;
                 NotifyMenuStripPlayingSongLabel.Visible = false;
             }
             }
 
 
+            if (main.nw.ip == "http://jancokock.me")
+                SelectServerJancoButton.Enabled = false;
+            else
+                SelectServerJancoButton.Enabled = true;
+
+            if (main.nw.ip == "http://imegumii.nl")
+                SelectServerYorickButton.Enabled = false;
+            else
+                SelectServerYorickButton.Enabled = true;
+
             if (main.audio.AState == AudioHandler.AudioState.PAUSED)
             if (main.audio.AState == AudioHandler.AudioState.PAUSED)
             {
             {
                 PauseButton.Enabled = false;
                 PauseButton.Enabled = false;
@@ -440,7 +458,69 @@ namespace MusicPlayer
         {
         {
             main.FilterCurrentPlaying();
             main.FilterCurrentPlaying();
             int selected = main.currentPlayingList.IndexOf(main.audio.CurrentSong);
             int selected = main.currentPlayingList.IndexOf(main.audio.CurrentSong);
-            SongsTableView.CurrentCell = SongsTableView.Rows[selected].Cells[0];
+            if(main.currentPlayingList.Count >= 1)
+                SongsTableView.CurrentCell = SongsTableView.Rows[selected].Cells[0];
+        }
+
+   
+        private void SongsTableView_MouseDown(object sender, MouseEventArgs e)
+        {
+            draggedstarted = true;
+            draggedcompleted = false;
+            startx = e.X;
+            starty = e.Y;
+        }
+
+        private void SongsTableView_MouseUp(object sender, MouseEventArgs e)
+        {
+            if (draggedcompleted)
+            {
+                Cursor.Current = Cursors.Default;
+                Point point = PlaylistBox.PointToClient(Cursor.Position);
+                int index = PlaylistBox.IndexFromPoint(point);
+                if (index < 0) //nope, niet op een playlist gesleept
+                {
+                    draggedstarted = false;
+                    draggedcompleted = false;
+                    return;
+                }
+                Playlist currentPlaylist = main.pl.GetPlaylistByName(PlaylistBox.Items[index].ToString());
+                SongsTable s = new SongsTable();
+                if (SongsTableView.SelectedRows.Count > 0)
+                {
+                    var drv = SongsTableView.SelectedRows[0].DataBoundItem as DataRowView;
+                    var row = drv.Row as DataRow;
+                    s.ImportRow(row);
+                    currentPlaylist.AddSong((s.Rows[0][5] as Song));
+                    currentPlaylist.WriteToFile();
+                }
+            }
+
+            draggedcompleted = false;
+            draggedstarted = false;
+        }
+
+        private void SongsTableView_MouseMove(object sender, MouseEventArgs e)
+        {
+            int deltax = Math.Abs(startx - e.X);
+            int deltay = Math.Abs(starty - e.Y);
+
+            if ((deltax > 5 || deltay > 5) && draggedstarted && !draggedcompleted)
+            {
+                draggedcompleted = true;
+                playlistsToolStripMenuItem_Click(this, new EventArgs());
+                Cursor.Current = Cursors.Hand;
+            }
+        }
+
+        private void SelectServerJancoButton_Click(object sender, EventArgs e)
+        {
+            main.SwitchServer("http://jancokock.me");
+        }
+
+        private void SelectServerYorickButton_Click(object sender, EventArgs e)
+        {
+            main.SwitchServer("http://imegumii.nl");
         }
         }
     }
     }
 }
 }

+ 1 - 1
MusicPlayer/MusicPlayer/NetworkHandler.cs

@@ -14,7 +14,7 @@ namespace MusicPlayer
     public class NetworkHandler
     public class NetworkHandler
     {
     {
         private int port = 8585;
         private int port = 8585;
-        private string ip;
+        public string ip { get; set; }
  
  
         public NetworkHandler(string ip)
         public NetworkHandler(string ip)
         {
         {

+ 1 - 0
MusicPlayer/MusicPlayer/PlaylistMaker.Designer.cs

@@ -109,6 +109,7 @@ namespace MusicPlayer
             this.PlaylistNewInputfield.Name = "PlaylistNewInputfield";
             this.PlaylistNewInputfield.Name = "PlaylistNewInputfield";
             this.PlaylistNewInputfield.Size = new System.Drawing.Size(225, 20);
             this.PlaylistNewInputfield.Size = new System.Drawing.Size(225, 20);
             this.PlaylistNewInputfield.TabIndex = 5;
             this.PlaylistNewInputfield.TabIndex = 5;
+            this.PlaylistNewInputfield.KeyUp += new System.Windows.Forms.KeyEventHandler(this.PlaylistNewInputfield_KeyUp);
             // 
             // 
             // label1
             // label1
             // 
             // 

+ 13 - 1
MusicPlayer/MusicPlayer/PlaylistMaker.cs

@@ -120,7 +120,11 @@ namespace MusicPlayer
 
 
         private void PlaylistNewButton_Click(object sender, EventArgs e)
         private void PlaylistNewButton_Click(object sender, EventArgs e)
         {
         {
-            pl.MakeNewPlaylistByName(PlaylistNewInputfield.Text);
+            string name = PlaylistNewInputfield.Text;
+            PlaylistNewInputfield.Text = "";
+            name = name.Replace('/', '-');
+            name = name.Replace('\\', '-');
+            pl.MakeNewPlaylistByName(name);
             Repopulate(true);
             Repopulate(true);
         }
         }
 
 
@@ -133,5 +137,13 @@ namespace MusicPlayer
         {
         {
             SearchAllSongs(FilterTextBox.Text);
             SearchAllSongs(FilterTextBox.Text);
         }
         }
+
+        private void PlaylistNewInputfield_KeyUp(object sender, KeyEventArgs e)
+        {
+            if(e.KeyCode == Keys.Enter)
+            {
+                PlaylistNewButton_Click(sender, new EventArgs());
+            }
+        }
     }
     }
 }
 }

+ 2 - 1
MusicPlayer/MusicPlayer/Program.cs

@@ -17,7 +17,8 @@ namespace MusicPlayer
             Application.EnableVisualStyles();
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             Application.SetCompatibleTextRenderingDefault(false);
 
 
-            NetworkHandler nw = new NetworkHandler("http://imegumii.nl");
+            NetworkHandler nw = new NetworkHandler("http://jancokock.me");
+            //NetworkHandler nw = new NetworkHandler("http://imegumii.nl");
             APIHandler api = new APIHandler(nw);
             APIHandler api = new APIHandler(nw);
             MainForm form = new MainForm();
             MainForm form = new MainForm();
             PlaylistHandler pl = new PlaylistHandler(api);
             PlaylistHandler pl = new PlaylistHandler(api);

+ 17 - 25
MusicPlayer/MusicPlayer/Properties/Resources.Designer.cs

@@ -8,10 +8,10 @@
 // </auto-generated>
 // </auto-generated>
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 
 
-namespace MusicPlayer.Properties
-{
-
-
+namespace MusicPlayer.Properties {
+    using System;
+    
+    
     /// <summary>
     /// <summary>
     ///   A strongly-typed resource class, for looking up localized strings, etc.
     ///   A strongly-typed resource class, for looking up localized strings, etc.
     /// </summary>
     /// </summary>
@@ -22,48 +22,40 @@ namespace MusicPlayer.Properties
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    internal class Resources
-    {
-
+    internal class Resources {
+        
         private static global::System.Resources.ResourceManager resourceMan;
         private static global::System.Resources.ResourceManager resourceMan;
-
+        
         private static global::System.Globalization.CultureInfo resourceCulture;
         private static global::System.Globalization.CultureInfo resourceCulture;
-
+        
         [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
         [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
-        internal Resources()
-        {
+        internal Resources() {
         }
         }
-
+        
         /// <summary>
         /// <summary>
         ///   Returns the cached ResourceManager instance used by this class.
         ///   Returns the cached ResourceManager instance used by this class.
         /// </summary>
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Resources.ResourceManager ResourceManager
-        {
-            get
-            {
-                if ((resourceMan == null))
-                {
+        internal static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MusicPlayer.Properties.Resources", typeof(Resources).Assembly);
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MusicPlayer.Properties.Resources", typeof(Resources).Assembly);
                     resourceMan = temp;
                     resourceMan = temp;
                 }
                 }
                 return resourceMan;
                 return resourceMan;
             }
             }
         }
         }
-
+        
         /// <summary>
         /// <summary>
         ///   Overrides the current thread's CurrentUICulture property for all
         ///   Overrides the current thread's CurrentUICulture property for all
         ///   resource lookups using this strongly typed resource class.
         ///   resource lookups using this strongly typed resource class.
         /// </summary>
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        internal static global::System.Globalization.CultureInfo Culture
-        {
-            get
-            {
+        internal static global::System.Globalization.CultureInfo Culture {
+            get {
                 return resourceCulture;
                 return resourceCulture;
             }
             }
-            set
-            {
+            set {
                 resourceCulture = value;
                 resourceCulture = value;
             }
             }
         }
         }

+ 8 - 5
MusicPlayer/MusicPlayer/Properties/Resources.resx

@@ -46,7 +46,7 @@
     
     
     mimetype: application/x-microsoft.net.object.binary.base64
     mimetype: application/x-microsoft.net.object.binary.base64
     value   : The object must be serialized with 
     value   : The object must be serialized with 
-            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
             : and then encoded with base64 encoding.
             : and then encoded with base64 encoding.
     
     
     mimetype: application/x-microsoft.net.object.soap.base64
     mimetype: application/x-microsoft.net.object.soap.base64
@@ -60,6 +60,7 @@
             : and then encoded with base64 encoding.
             : and then encoded with base64 encoding.
     -->
     -->
   <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
   <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
     <xsd:element name="root" msdata:IsDataSet="true">
     <xsd:element name="root" msdata:IsDataSet="true">
       <xsd:complexType>
       <xsd:complexType>
         <xsd:choice maxOccurs="unbounded">
         <xsd:choice maxOccurs="unbounded">
@@ -68,9 +69,10 @@
               <xsd:sequence>
               <xsd:sequence>
                 <xsd:element name="value" type="xsd:string" minOccurs="0" />
                 <xsd:element name="value" type="xsd:string" minOccurs="0" />
               </xsd:sequence>
               </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" />
+              <xsd:attribute name="name" use="required" type="xsd:string" />
               <xsd:attribute name="type" type="xsd:string" />
               <xsd:attribute name="type" type="xsd:string" />
               <xsd:attribute name="mimetype" type="xsd:string" />
               <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
             </xsd:complexType>
             </xsd:complexType>
           </xsd:element>
           </xsd:element>
           <xsd:element name="assembly">
           <xsd:element name="assembly">
@@ -85,9 +87,10 @@
                 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                 <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
                 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
                 <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
               </xsd:sequence>
               </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
               <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
               <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
               <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
               <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
             </xsd:complexType>
             </xsd:complexType>
           </xsd:element>
           </xsd:element>
           <xsd:element name="resheader">
           <xsd:element name="resheader">
@@ -109,9 +112,9 @@
     <value>2.0</value>
     <value>2.0</value>
   </resheader>
   </resheader>
   <resheader name="reader">
   <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   </resheader>
   <resheader name="writer">
   <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   </resheader>
 </root>
 </root>