Esempio n. 1
0
        public FsItem GetRootNode()
        {
            FsItem ret = this;

            while (ret.Parent != null)
            {
                ret = ret.Parent;
            }
            return(ret);
        }
Esempio n. 2
0
        protected override void DrawItem(Bitmap screen, int x, int y, int width, int height, ref int index, object it, Style cStyle)
        {
            bool   selected = _selIndex == index;
            FsItem item     = (FsItem)it;

            if (selected)
            {
                screen.DrawRectangle(Colors.Blue, 0, x, y, width, height, 0, 0,
                                     cStyle.ListBoxSelectedItemBack1, x, y,
                                     cStyle.ListBoxSelectedItemBack2, x, y + height, Enabled ? (ushort)256 : (ushort)128);
            }

            Color  textColor = _playing == it ? Colors.Green : (Enabled ? (selected ? cStyle.TextBoxPressedTextColor : cStyle.TextBoxEnabledTextColor) : cStyle.TextBoxDisabledTextColor);
            Bitmap toDraw    = item.IsBack ? fsBack : (item.IsDirectory ? fsFolder : (item.IsMusicFile ? fsMusic : fsNone));

            screen.DrawImage(x + 5, y + (ItemHeight - 16) / 2, toDraw, 0, 0, 16, 16);
            screen.DrawText(item.Name, nameFont, textColor, x + 26, y + (ItemHeight - nameFont.Height) / 2);
        }
Esempio n. 3
0
 public void RemoveItem(FsItem item)
 {
     _selIndex = -1;
     base.RemoveItem_(item);
 }
Esempio n. 4
0
 public void AddItem(FsItem item)
 {
     base.AddItem_(item);
 }
Esempio n. 5
0
 public FsItem(FsItem parent)
 {
     Parent = parent;
     Childs = null;
 }
Esempio n. 6
0
 public FsItem(FsItem parent)
 {
     Parent = parent;
     Childs = null;
 }
Esempio n. 7
0
 public void RemoveItem(FsItem item)
 {
     _selIndex = -1;
     base.RemoveItem_(item);
 }
Esempio n. 8
0
 public void AddItem(FsItem item)
 {
     base.AddItem_(item);
 }
Esempio n. 9
0
        private static void CreatePlayerPanel(Panel panel)
        {
            const int btSize = 50;
            const int margin = 5;

            Label title = new Label("Player", 5, 5, 200, Fonts.ArialMediumBold.Height) { Font = Fonts.ArialMediumBold };
            panel.AddChild(title);

            FsList fsList = new FsList(5, title.Y + title.Height + 5, panel.Width - margin * 3 - btSize, panel.Height - (title.Y + title.Height + margin * 3 + btSize));
            panel.AddChild(fsList);

            ArrayList rootItems = new ArrayList();

            FsItem currentPlaying = null;

            SimpleActionParamString playFile = (filePath) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Connecting: return false;
                    case VsStatus.PlayingRadio: return false;
                    case VsStatus.Playing: VsDriver.StopFile(); break;
                    case VsStatus.Paused: VsDriver.ResumeFile(); VsDriver.StopFile(); break;
                }
                int tries = 5;
                Exception lastEx = null;
                while (tries-- != 0)
                {
                    try
                    {
                        FileStream file = File.Open(filePath, FileMode.Open);
                        VsDriver.PlayFile(file);
                        lastEx = null;
                        break;
                    }
                    catch (Exception ex) { lastEx = ex; }
                }

                if (lastEx != null)
                {
                    new Thread(() =>
                    {
                        using (MessageBox mb = new MessageBox(lastEx.Message, "Error", MessageBoxButtons.Ok, MessageBoxIcons.Error)) mb.Show();
                    }).Start();
                    return false;
                }
                return true;
            };

            #region list double click
            fsList.OnDoubleClick += (s) =>
            {
                FsItem selectedItem = fsList.SelectedItem;
                if (selectedItem == null) return;

                if (selectedItem.IsBack)
                {
                    fsList.ClearItems();
                    fsList.Folder = selectedItem.Parent;

                    if (fsList.Folder.Parent != null)
                        fsList.AddItems(fsList.Folder.Parent.Childs);
                    else
                        fsList.AddItems(rootItems);
                }
                else if (selectedItem.IsDirectory)
                {
                    if (selectedItem.Childs == null)
                    {
                        selectedItem.Childs = new ArrayList();
                        string[] dirs = Directory.GetDirectories(selectedItem.Path);
                        selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = true, Name = "Back" });
                        foreach (string dir in dirs)
                            selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = false, IsDirectory = true, IsMusicFile = false, Name = Path.GetFileName(dir), Path = dir });

                        string[] files = Directory.GetFiles(selectedItem.Path);
                        foreach (string file in files)
                        {
                            string extension = Path.GetExtension(file).ToLower();
                            bool isMusicFile = extension.Equals(".mp3");
                            selectedItem.Childs.Add(new FsItem(selectedItem) { IsBack = false, IsDirectory = false, IsMusicFile = isMusicFile, Name = Path.GetFileName(file), Path = file });
                        }
                    }

                    fsList.Folder = selectedItem;
                    fsList.ClearItems();
                    fsList.AddItems(selectedItem.Childs);
                }
                else if (selectedItem.IsMusicFile)
                {
                    if (playFile(selectedItem.Path))
                    {
                        currentPlaying = selectedItem;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
            };
            #endregion

            #region removable media events
            RemovableMedia.Insert += (s, e) =>
            {
                FsItem newItem = new FsItem(null) { IsBack = false, IsDirectory = true, IsMusicFile = false, Name = e.Volume.Name, Path = e.Volume.RootDirectory };
                rootItems.Add(newItem);

                if (fsList.Folder == null)
                    fsList.AddItem(newItem);
            };

            RemovableMedia.Eject += (s, e) =>
            {
                FsItem toRemove = null;
                foreach (FsItem fsItem in rootItems) if (fsItem.Path == e.Volume.RootDirectory) { toRemove = fsItem; break; }
                if (toRemove != null)
                {
                    rootItems.Remove(toRemove);
                    if (fsList.Folder == null)
                        fsList.RemoveItem(toRemove);

                    else if (fsList.Folder.GetRootNode().Path == e.Volume.RootDirectory)
                    {
                        fsList.Folder = null;
                        fsList.ClearItems();
                        fsList.AddItems(rootItems);
                    }
                }
            };
            #endregion

            ImageButton btDelete;
            panel.AddChild(btDelete = new ImageButton(Images.GetBitmap(Images.BitmapResources.imgDelete), fsList.X + fsList.Width + margin, fsList.Y, btSize, btSize));
            btDelete.ButtonPressed += (s) =>
            {
                FsItem selectedItem = fsList.SelectedItem;
                if (selectedItem == null || selectedItem.IsBack || selectedItem.Parent == null) return;
                if (selectedItem == currentPlaying) VsDriver.StopFile();

                new Thread(new ThreadStart(() =>
                {
                    using (MessageBox mb = new MessageBox("Are you sure you want to delete\n" + selectedItem.Name + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcons.Delete))
                    {
                        if (mb.Show() == MessageBoxResult.Yes)
                        {
                            try
                            {
                                if (selectedItem.IsDirectory) Directory.Delete(selectedItem.Path);
                                else File.Delete(selectedItem.Path);

                                selectedItem.Parent.Childs.Remove(selectedItem);
                                fsList.RemoveItem(selectedItem);
                            }
                            catch (Exception)
                            {
                                using (MessageBox err = new MessageBox("Error deleting item", "Error", MessageBoxButtons.Ok, MessageBoxIcons.Error))
                                    err.Show();
                            }
                        }
                    }
                })).Start();
            };

            ImageButton btPlay, btStop, btNext, btPrev;
            int x = fsList.X, y = fsList.Y + fsList.Height + margin;

            Bitmap imgPlay = Images.GetBitmap(Images.BitmapResources.btPlay), imgPause = Images.GetBitmap(Images.BitmapResources.btPause);

            panel.AddChild(btPrev = new ImageButton(Images.GetBitmap(Images.BitmapResources.btBack), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btPlay = new ImageButton(Images.GetBitmap(Images.BitmapResources.btPlay), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btNext = new ImageButton(Images.GetBitmap(Images.BitmapResources.btForward), x, y, btSize, btSize)); x += margin + btSize;
            panel.AddChild(btStop = new ImageButton(Images.GetBitmap(Images.BitmapResources.btStop), x, y, btSize, btSize));

            #region prev/play/next/stop events
            bool ignore = false;
            UiEventHandler actionPrev = (s) =>
            {
                if (ignore) return;
                try
                {
                    ignore = true;

                    if (currentPlaying == null) return;
                    FsItem aux = currentPlaying;

                    int stIndex = aux.Parent.Childs.IndexOf(aux);
                    if (stIndex == -1) return;

                    FsItem nextToPlay;
                    do
                    {
                        stIndex--;
                        if (stIndex < 0) stIndex = aux.Parent.Childs.Count - 1;
                        nextToPlay = (FsItem)aux.Parent.Childs[stIndex];
                        if (nextToPlay.IsMusicFile) break;
                    } while (true);

                    if (playFile(nextToPlay.Path))
                    {
                        currentPlaying = nextToPlay;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
                finally
                {
                    ignore = false;
                }
            };

            UiEventHandler actionNext = (s) =>
            {
                if (ignore) return;
                try
                {
                    ignore = true;

                    if (currentPlaying == null) return;
                    FsItem aux = currentPlaying;

                    int stIndex = aux.Parent.Childs.IndexOf(aux);
                    if (stIndex == -1) return;

                    FsItem nextToPlay;
                    do
                    {
                        stIndex++;
                        if (stIndex == aux.Parent.Childs.Count) stIndex = 0;
                        nextToPlay = (FsItem)aux.Parent.Childs[stIndex];
                        if (nextToPlay.IsMusicFile) break;
                    } while (true);

                    if (playFile(nextToPlay.Path))
                    {
                        currentPlaying = nextToPlay;
                        fsList.CurrentPlaying = currentPlaying;
                    }
                }
                finally
                {
                    ignore = false;
                }
            };

            btPrev.ButtonPressed += actionPrev;
            btNext.ButtonPressed += actionNext;

            btPlay.ButtonPressed += (s) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Playing: VsDriver.PauseFile(); break;
                    case VsStatus.Paused: VsDriver.ResumeFile(); break;
                    case VsStatus.Stopped:
                        FsItem selectedItem = fsList.SelectedItem;
                        if (selectedItem != null && selectedItem.IsMusicFile)
                        {
                            if (playFile(selectedItem.Path))
                            {
                                currentPlaying = selectedItem;
                                fsList.CurrentPlaying = currentPlaying;
                            }
                        }
                        break;
                }
            };

            bool stopPressed = false;
            btStop.ButtonPressed += (s) =>
            {
                switch (VsDriver.Status)
                {
                    case VsStatus.Playing: stopPressed = true; VsDriver.StopFile(); break;
                    case VsStatus.Paused: stopPressed = true; VsDriver.ResumeFile(); VsDriver.StopFile(); break;
                }
            };
            #endregion

            VsDriver.VsStatusChanged += (status) =>
            {
                if (status == VsStatus.Playing)
                    btPlay.Image = imgPause;
                else
                {
                    if (status == VsStatus.Stopped)
                    {
                        if (!stopPressed)
                        {
                            if (currentPlaying != null)
                                actionNext(btNext);
                        }
                        else
                        {
                            currentPlaying = null;
                            fsList.CurrentPlaying = currentPlaying;
                            stopPressed = false;
                        }
                    }
                    btPlay.Image = imgPlay;
                }
            };
        }