Ejemplo n.º 1
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Node_Common    node = e.Argument as Node_Common;
            DownloaderInfo info = new DownloaderInfo(m_worker, e, null);

            node.ParsePage(info);
        }
Ejemplo n.º 2
0
 private void c_list_Drop(object sender, System.Windows.DragEventArgs e)
 {
     if (e.Data.GetDataPresent("myNode"))
     {
         Node_Common node = e.Data.GetData("myNode") as Node_Common;
         m_downloadList.Add(node);
     }
 }
Ejemplo n.º 3
0
        private void AddItem_Clicked(object sender, RoutedEventArgs e)
        {
            Node_Common selected = c_tree.SelectedItem as Node_Common;

            if (selected != null)
            {
                m_downloadList.Add(selected);
            }
        }
Ejemplo n.º 4
0
        public MainWindow()
        {
            GenericUpdater.Updater.DoUpdate("MusicDownloader", m_version, "MusicDownloader_Version.xml", "MusicDownloader.msi", new GenericUpdater.Updater.UpdateFiredDelegate(UpdateFired));
            InitializeComponent();

            m_rootNode     = null;
            m_downloader   = new Downloader(this);
            m_downloadList = new ObservableCollection <Node_Common>();

            c_destPath.Text          = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
            c_list.ItemsSource       = m_downloadList;
            c_category.SelectedIndex = 0;
        }
Ejemplo n.º 5
0
        private void childrenView_Filter(object sender, FilterEventArgs e)
        {
            Node_Common node = e.Item as Node_Common;

            if (string.IsNullOrEmpty(m_filterStringLowerCase) ||
                node.Name.ToLower().Contains(m_filterStringLowerCase))
            {
                e.Accepted = true;
            }
            else
            {
                e.Accepted = false;
            }
        }
Ejemplo n.º 6
0
        private void AddFailureNode(Node_Common node, string reason)
        {
            FailedNode errNode = new FailedNode();

            errNode.Node          = node;
            errNode.FailureReason = reason;

            if (node.NodeType == Node_Common.Type.T_DIR)
            {
                errorFolders.Add(errNode);
            }
            else if (node.NodeType == Node_Common.Type.T_SONG)
            {
                errorSongs.Add(errNode);
            }
        }
Ejemplo n.º 7
0
        public void TreeView_SelectItem(Node_Common node)
        {
            try
            {
                List <Node_Common> nodes = new List <Node_Common>();
                while (node != null)
                {
                    nodes.Add(node);
                    node = node.Parent;
                }

                nodes.Reverse();

                TreeViewItem item = null;
                while (nodes.Count > 0)
                {
                    Node_Common current = nodes[0];
                    nodes.RemoveAt(0);

                    DependencyObject obj = null;
                    if (item == null)
                    {
                        obj  = c_tree.ItemContainerGenerator.ContainerFromItem(current);
                        item = obj as TreeViewItem;
                    }
                    else
                    {
                        obj  = item.ItemContainerGenerator.ContainerFromItem(current);
                        item = obj as TreeViewItem;
                    }
                }

                MethodInfo selectMethod = typeof(TreeViewItem).GetMethod("Select", BindingFlags.NonPublic | BindingFlags.Instance);
                selectMethod.Invoke(item, new object[] { true });
            }
            catch { }
        }
Ejemplo n.º 8
0
        private void c_tree_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            // Get the current mouse position
            Point  mousePos = e.GetPosition(null);
            Vector diff     = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged ListViewItem
                System.Windows.Controls.TreeView treeView = sender as System.Windows.Controls.TreeView;
                TreeViewItem treeViewItem = Utils.FindAnchestor <TreeViewItem>((DependencyObject)e.OriginalSource);

                // Find the data behind the TreeViewItem
                Node_Common node = null;
                if (treeViewItem != null)
                {
                    if (treeViewItem.Header is Node_Common)
                    {
                        node = treeViewItem.Header as Node_Common;
                    }
                    else if (treeViewItem.DataContext is Node_Common)
                    {
                        node = treeViewItem.DataContext as Node_Common;
                    }
                }

                if (node != null)
                {
                    // Initialize the drag & drop operation
                    System.Windows.DataObject dragData = new System.Windows.DataObject("myNode", node);
                    DragDrop.DoDragDrop(treeViewItem, dragData, System.Windows.DragDropEffects.Copy);
                }
            }
        }
Ejemplo n.º 9
0
        private void TreeEntry_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (parent == null)
            {
                parent = Utils.FindAnchestor <TreeViewItem>(this);
            }

            context = (e.NewValue as Node_Common);
            if (parent != null)
            {
                ContextMenu menu = new ContextMenu();
                menu.DataContext = context;

                if (context != null)
                {
                    MenuItem item = null;

                    item           = new MenuItem();
                    item.Header    = context.Name;
                    item.IsEnabled = false;
                    menu.Items.Add(item);

                    menu.Items.Add(new Separator());

                    item        = new MenuItem();
                    item.Header = "Add to downloads";
                    item.Click += new RoutedEventHandler(Add_Item);
                    menu.Items.Add(item);

                    item        = new MenuItem();
                    item.Header = "Open containing folder";
                    item.Click += new RoutedEventHandler(Open_ContainingFolder);
                    menu.Items.Add(item);

                    item        = new MenuItem();
                    item.Header = "Open file/folder";
                    {
                        Binding bnd = null;
                        try
                        {
                            bnd        = new Binding("IsExisting");
                            bnd.Source = context;
                        }
                        catch (Exception)
                        {
                            bnd = null;
                        }

                        item.SetBinding(MenuItem.IsEnabledProperty, bnd);
                    }
                    item.Click += new RoutedEventHandler(Open_FileOrFolder);
                    menu.Items.Add(item);

                    item        = new MenuItem();
                    item.Header = "Parse file/folder";
                    item.Click += new RoutedEventHandler(Parse_FileOrFolder);
                    menu.Items.Add(item);

                    item        = new MenuItem();
                    item.Header = "Parse children file/folder";
                    if (context.NodeType == Node_Common.Type.T_DIR)
                    {
                        Binding bnd = null;
                        try
                        {
                            bnd        = new Binding("IsParsed");
                            bnd.Source = context;
                        }
                        catch (Exception)
                        {
                            bnd = null;
                        }

                        item.SetBinding(MenuItem.IsEnabledProperty, bnd);
                    }
                    else
                    {
                        item.IsEnabled = false;
                    }
                    item.Click += new RoutedEventHandler(ParseChildren_FileOrFolder);
                    menu.Items.Add(item);
                }

                parent.ContextMenu         = menu;
                parent.ContextMenu.Opened += new RoutedEventHandler(ContextMenu_Opened);
            }
        }
Ejemplo n.º 10
0
 private void RemoveNodeNow(Node_Common node)
 {
     (App.Current.MainWindow as MainWindow).m_downloadList.Remove(node);
 }
Ejemplo n.º 11
0
 private void RemoveNodeFromUIList(Node_Common node)
 {
     App.Current.Dispatcher.Invoke(new UpdateUIDispatcher(RemoveNodeNow), node);
 }
Ejemplo n.º 12
0
 private void AddNodeNow(Node_Common node)
 {
     (App.Current.MainWindow as MainWindow).m_downloadList.Insert(0, node);
 }
Ejemplo n.º 13
0
        private void DownloadWorker_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            errorFolders.Clear();
            errorSongs.Clear();

            List <Node_Common> downloadNodes = new List <Node_Common>();

            foreach (Node_Common node in (workArgs.Argument as ObservableCollection <Node_Common>))
            {
                downloadNodes.Add(node);
            }

            downloadNodes.Reverse();

            if (m_downloadWorker.CancellationPending)
            {
                workArgs.Cancel = true;
                return;
            }

            ReportProgressPrimary("Starting downloads.", 0);

            Stack <Node_Common> nodesToProcess = new Stack <Node_Common>();

            foreach (Node_Common node in downloadNodes)
            {
                if (m_downloadWorker.CancellationPending)
                {
                    workArgs.Cancel = true;
                    return;
                }

                m_logger.Addtext("Got download node - " + node.Name + " (" + node.URL + ")\n");
                nodesToProcess.Push(node);
            }

            if (m_downloadWorker.CancellationPending)
            {
                workArgs.Cancel = true;
                return;
            }

            double count = 0;
            double total = nodesToProcess.Count;

            while (nodesToProcess.Count > 0)
            {
                Node_Common node = nodesToProcess.Pop();

                if (m_downloadWorker.CancellationPending)
                {
                    workArgs.Cancel = true;
                    return;
                }

                if ((node.NodeType == Node_Common.Type.T_SONG) && (node.IsParsed))
                {
                    Node_Song song = node as Node_Song;
                    m_logger.Addtext("Downloading song - " + song.Name + " (" + song.Mp3Path + ")\n");
                    ReportProgressPrimary("Downloading Song - " + song.Name, 10 + ((count / total) * 90));
                    count++;

                    try
                    {
                        DownloaderInfo info = new DownloaderInfo(m_downloadWorker, workArgs, ReportProgressSecondary);
                        song.Download(m_destinationPath, info);
                        RemoveNodeFromUIList(song);
                    }
                    catch (Exception exp)
                    {
                        AddFailureNode(song, exp.Message);
                        continue;
                    }
                }
                else
                {
                    m_logger.Addtext("Processing subnodes of - " + node.Name + "\n");
                    ReportProgressPrimary("Gathering song list - " + node.Name, 10 + ((count / total) * 90));
                    count++;

                    try
                    {
                        DownloaderInfo info = new DownloaderInfo(m_downloadWorker, workArgs, ReportProgressSecondary);
                        node.ParsePage(info);
                        RemoveNodeFromUIList(node);
                    }
                    catch (Exception exp)
                    {
                        AddFailureNode(node, exp.Message);
                        continue;
                    }

                    if (node.NodeType == Node_Common.Type.T_DIR)
                    {
                        List <Node_Common> subNodes = new List <Node_Common>();
                        foreach (Node_Common subnode in (node as Node_Directory).Children)
                        {
                            if (m_downloadWorker.CancellationPending)
                            {
                                workArgs.Cancel = true;
                                return;
                            }

                            m_logger.Addtext("Added subnode for download - " + subnode.Name + " (" + subnode.URL + ")\n");
                            subNodes.Add(subnode);
                        }

                        subNodes.Reverse();
                        foreach (Node_Common subnode in subNodes)
                        {
                            nodesToProcess.Push(subnode);
                            AddNodeToUIList(subnode);
                        }

                        total += subNodes.Count;
                    }
                    else if (node.NodeType == Node_Common.Type.T_SONG)
                    {
                        m_logger.Addtext("Added song for download - " + node.Name + " (" + (node as Node_Song).Mp3Path + ")\n");
                        nodesToProcess.Push(node);
                        AddNodeToUIList(node);
                        total++;
                    }
                }
            }

            ReportProgressPrimary("Done downloading songs.", 100);
            workArgs.Result = true;
        }
Ejemplo n.º 14
0
 private void AddChildNow(Node_Common node)
 {
     node.Init();
     m_children.Add(node);
     NotifyPropertyChanged("Children");
 }
Ejemplo n.º 15
0
 private void AddNodeToUIList(Node_Common node)
 {
     App.Current.Dispatcher.Invoke(new UpdateUIDispatcher(AddNodeNow), node);
 }
Ejemplo n.º 16
0
 private void AddChild(Node_Common node)
 {
     App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new AddChildDelegate(AddChildNow), node);
 }
Ejemplo n.º 17
0
        private void Category_Changed(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem   selected = e.AddedItems[0] as ComboBoxItem;
            string         name     = selected.Content.ToString();
            Node_Directory root     = null;

            switch (name)
            {
            case "Movies":
                if (m_Movies == null)
                {
                    m_Movies = new Node_Directory(name, "/songs/Audio/indian/movies/");
                    m_Movies.Init();
                }
                root = m_Movies;
                break;

            case "Pop":
                if (m_Pop == null)
                {
                    m_Pop = new Node_Directory(name, "/songs/Audio/indian/POP/");
                    m_Pop.Init();
                }
                root = m_Pop;
                break;

            case "Artist (Hindi)":
                if (m_Artist_Hindi == null)
                {
                    m_Artist_Hindi = new Node_Directory(name, "/songs/Audio/indian/artists/Hindi/");
                    m_Artist_Hindi.Init();
                }
                root = m_Artist_Hindi;
                break;

            case "Artist (Punjabi)":
                if (m_Artist_Punjabi == null)
                {
                    m_Artist_Punjabi = new Node_Directory(name, "/songs/Audio/indian/artists/Punjabi/");
                    m_Artist_Punjabi.Init();
                }
                root = m_Artist_Punjabi;
                break;

            case "Bhangra":
                if (m_Bhangra == null)
                {
                    m_Bhangra = new Node_Directory(name, "/songs/Audio/indian/bhangra/");
                    m_Bhangra.Init();
                }
                root = m_Bhangra;
                break;

            case "Oldies":
                if (m_Oldies == null)
                {
                    m_Oldies = new Node_Directory(name, "/songs/Audio/indian/oldies/");
                    m_Oldies.Init();
                }
                root = m_Oldies;
                break;

            case "Instrumental":
                if (m_Instrumental == null)
                {
                    m_Instrumental = new Node_Directory(name, "http://apunkabollywood.net/songs/Audio/indian/Instrumentals/");
                    m_Instrumental.Init();
                }
                root = m_Instrumental;
                break;

            default:
                ErrorLog.Show("Invalid category.");
                return;
            }

            m_rootNode = root;
            c_tree.Items.Clear();
            c_filter.Text = "";
            c_tree.Items.Add(m_rootNode);
        }