Example #1
0
        private void DeleteNode(TreeNode nodeDeleted)
        {
            if (nodeDeleted != null) {
                List<string> resultMsg = null;
                string msgDlgCaption = string.Empty;

                bool hasSubtitles = false;
                bool hasDuplicateEpisode = false;
                bool hasLocalFiles = false;

                TreeNode seriesNode = null;

                DBEpisode episode = null;
                DBSeason season = null;
                DBSeries series = null;

                if (nodeDeleted.Name == DBSeries.cTableName)
                {
                    series = (DBSeries)nodeDeleted.Tag;
                    seriesNode = nodeDeleted;
                    if (series != null) hasLocalFiles = series[DBOnlineSeries.cHasLocalFiles];
                }
                else if (nodeDeleted.Name == DBSeason.cTableName)
                {
                    season = (DBSeason)nodeDeleted.Tag;
                    series = (DBSeries)nodeDeleted.Parent.Tag;
                    seriesNode = nodeDeleted.Parent;
                    if (season != null) hasLocalFiles = season[DBSeason.cHasLocalFiles];
                }
                else if (nodeDeleted.Name == DBEpisode.cTableName)
                {
                    episode = (DBEpisode)nodeDeleted.Tag;
                    season = (DBSeason)nodeDeleted.Parent.Tag;
                    series = (DBSeries)nodeDeleted.Parent.Parent.Tag;
                    seriesNode = nodeDeleted.Parent.Parent;
                    if (episode != null)
                    {
                        hasSubtitles = episode.checkHasLocalSubtitles();
                        hasDuplicateEpisode = episode.HasDuplicateEpisode;
                        hasLocalFiles = !string.IsNullOrEmpty(episode[DBEpisode.cFilename]);
                    }
                }

                DeleteDialog deleteDialog = new DeleteDialog(hasSubtitles, hasDuplicateEpisode, hasLocalFiles);
                DialogResult result = deleteDialog.ShowDialog(this);

                // nothing to do exit
                if (result != DialogResult.OK) return;

                #region Delete Subtitles
                if (deleteDialog.DeleteMode == TVSeriesPlugin.DeleteMenuItems.subtitles)
                {
                    msgDlgCaption = Translation.UnableToDeleteSubtitles;
                    switch (nodeDeleted.Name)
                    {
                        case DBEpisode.cTableName:
                            episode = (DBEpisode)nodeDeleted.Tag;
                            if (episode == null) return;
                            resultMsg = episode.deleteLocalSubTitles();
                            break;
                    }
                    try
                    {
                        TreeNode selectedTN = treeView_Library.SelectedNode;
                        treeView_Library.SelectedNode = null;
                        treeView_Library.SelectedNode = selectedTN;
                    }
                    catch
                    {
                    }                   
                }
                #endregion

                #region Delete From Disk, Database or Both
                if (deleteDialog.DeleteMode != TVSeriesPlugin.DeleteMenuItems.subtitles)
                {
                    msgDlgCaption = Translation.UnableToDelete;
                    switch (nodeDeleted.Name)
                    {
                        #region Delete Series
                        case DBSeries.cTableName:
                            if (result == DialogResult.OK)
                            {
                                resultMsg = series.deleteSeries(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion

                        #region Delete Season
                        case DBSeason.cTableName:
                            if (result == DialogResult.OK)
                            {
                                resultMsg = season.deleteSeason(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion

                        #region Delete Episode
                        case DBEpisode.cTableName:
                            if (result == DialogResult.OK)
                            {
                                resultMsg = episode.deleteEpisode(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion
                    }

                    #region Cleanup Nodes
                    // update nodes so that local episode data is removed
                    if (deleteDialog.DeleteMode == TVSeriesPlugin.DeleteMenuItems.disk)
                    {
                        // get the current series node index
                        int index = this.treeView_Library.Nodes.IndexOf(seriesNode);

                        // delete the series node
                        this.treeView_Library.Nodes.Remove(seriesNode);

                        // create new series node
                        CreateSeriesNode(DBSeries.Get(series[DBSeries.cID], false), null, index);

                        // find previously selected node
                        // it will still exist as we only deleted from disk
                        seriesNode = treeView_Library.Nodes[index];
                        seriesNode.Expand();
                        var selectedNode = seriesNode;

                        if (season != null)
                        {
                            foreach (TreeNode seasonNode in seriesNode.Nodes)
                            {
                                if ((seasonNode.Tag as DBSeason)[DBSeason.cIndex] == season[DBSeason.cIndex])
                                {
                                    seasonNode.Expand();
                                    selectedNode = seasonNode;
                                    
                                    if (episode != null)
                                    {
                                        foreach (TreeNode episodeNode in seasonNode.Nodes)
                                        {
                                            if ((episodeNode.Tag as DBEpisode)[DBEpisode.cEpisodeIndex] == episode[DBEpisode.cEpisodeIndex])
                                            {
                                                selectedNode = episodeNode;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // select the last deleted node
                        this.treeView_Library.SelectedNode = selectedNode;
                        this.treeView_Library.Select();
                    }

                    // always delete tree node if removing from database
                    if (resultMsg.Count == 0 && deleteDialog.DeleteMode != TVSeriesPlugin.DeleteMenuItems.disk)
                    {
                        this.treeView_Library.Nodes.Remove(nodeDeleted);

                        // get new selected node
                        TreeNode selectedNode = this.treeView_Library.SelectedNode;

                        // if we deleted a double episode from the database
                        // then find the 2nd or 1st episode and delete that node as well
                        if (selectedNode != null && selectedNode.Name == DBEpisode.cTableName && episode.IsDoubleEpisode)
                        {
                            string filename = episode[DBEpisode.cFilename];

                            if (episode.IsSecondOfDoubleEpisode)
                            {
                                // check current selected node
                                if ((selectedNode.Tag as DBEpisode)[DBEpisode.cFilename] == filename)
                                {
                                    this.treeView_Library.Nodes.Remove(selectedNode);
                                }
                                // check the previous node
                                else if (selectedNode.PrevNode != null && (selectedNode.PrevNode.Tag as DBEpisode)[DBEpisode.cFilename] == filename)
                                {
                                    this.treeView_Library.Nodes.Remove(selectedNode.PrevNode);
                                }
                            }
                            else
                            {
                                // check current selected node
                                if ((selectedNode.Tag as DBEpisode)[DBEpisode.cFilename] == filename)
                                {
                                    this.treeView_Library.Nodes.Remove(selectedNode);
                                }
                                // check the next node
                                else if (selectedNode.NextNode != null && (selectedNode.NextNode.Tag as DBEpisode)[DBEpisode.cFilename] == filename)
                                {
                                    this.treeView_Library.Nodes.Remove(selectedNode.NextNode);
                                }
                            }

                            // get new selected node
                            selectedNode = this.treeView_Library.SelectedNode;
                        }

                        // see if need to delete season/series tree nodes
                        // i.e. they're no underlying seasons/episodes
                        if (selectedNode != null && selectedNode.Name == DBSeason.cTableName)
                        {
                            // we may have removed the last episode of a season
                            // leaving no episode nodes for the selected season
                            if (selectedNode.GetNodeCount(false) == 0)
                            {
                                // delete selected season node
                                this.treeView_Library.Nodes.Remove(selectedNode);
                                // get new selected node - maybe a series now
                                selectedNode = this.treeView_Library.SelectedNode;
                            }
                        }

                        if (selectedNode != null && selectedNode.Name == DBSeries.cTableName)
                        {
                            if (selectedNode.GetNodeCount(true) == 0)
                            {
                                this.treeView_Library.Nodes.Remove(selectedNode);
                            }
                        }
                    }
                    #endregion

                    #region Clear Selected Images
                    if (this.treeView_Library.Nodes.Count == 0)
                    {
                        // also clear the data pane
                        this.dataGridView1.Rows.Clear();
                        try
                        {
                            if (this.pictureBox_Series.Image != null)
                            {
                                this.pictureBox_Series.Image.Dispose();
                                this.pictureBox_Series.Image = null;
                                this.comboBox_BannerSelection.Items.Clear();
                            }
                            if (this.pictureBox_SeriesPoster != null)
                            {
                                this.pictureBox_SeriesPoster.Image.Dispose();
                                this.pictureBox_SeriesPoster.Image = null;
                                this.comboBox_PosterSelection.Items.Clear();
                            }
                        }
                        catch { }
                    }
                    #endregion
                }
                #endregion

                // Show errors, if any
                if (resultMsg != null && resultMsg.Count > 0)
                {
                    MessageBox.Show(string.Join("\n", resultMsg.ToArray()), msgDlgCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }   
            }
        }
Example #2
0
        private void DeleteNode(TreeNode nodeDeleted)
        {
            if (nodeDeleted != null) {
                List<string> resultMsg = null;
                string msgDlgCaption = string.Empty;

                bool hasSubtitles = false;
                if (nodeDeleted.Name == DBEpisode.cTableName)
                {
                    DBEpisode episode = (DBEpisode)nodeDeleted.Tag;
                    if (episode != null && episode.checkHasLocalSubtitles())
                        hasSubtitles = true;
                }

                DeleteDialog deleteDialog = new DeleteDialog(hasSubtitles);
                DialogResult result = deleteDialog.ShowDialog(this);

                // nothing to do exit
                if (result != DialogResult.OK) return;

                #region Delete Subtitles
                if (deleteDialog.DeleteMode == TVSeriesPlugin.DeleteMenuItems.subtitles)
                {
                    msgDlgCaption = Translation.UnableToDeleteSubtitles;
                    switch (nodeDeleted.Name)
                    {
                        case DBEpisode.cTableName:
                            DBEpisode episode = (DBEpisode)nodeDeleted.Tag;
                            if (episode == null) return;
                            resultMsg = episode.deleteLocalSubTitles();
                            break;
                    }
                    try
                    {
                        TreeNode selectedTN = treeView_Library.SelectedNode;
                        treeView_Library.SelectedNode = null;
                        treeView_Library.SelectedNode = selectedTN;
                    }
                    catch
                    {
                    }
                }
                #endregion

                #region Delete From Disk, Database or Both
                if (deleteDialog.DeleteMode != TVSeriesPlugin.DeleteMenuItems.subtitles)
                {
                    msgDlgCaption = Translation.UnableToDelete;
                    switch (nodeDeleted.Name)
                    {
                        #region Delete Series
                        case DBSeries.cTableName:
                            if (result == DialogResult.OK)
                            {
                                DBSeries series = (DBSeries)nodeDeleted.Tag;
                                resultMsg = series.deleteSeries(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion

                        #region Delete Season
                        case DBSeason.cTableName:
                            if (result == DialogResult.OK)
                            {
                                DBSeason season = (DBSeason)nodeDeleted.Tag;
                                resultMsg = season.deleteSeason(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion

                        #region Delete Episode
                        case DBEpisode.cTableName:
                            if (result == DialogResult.OK)
                            {
                                DBEpisode episode = (DBEpisode)nodeDeleted.Tag;
                                resultMsg = episode.deleteEpisode(deleteDialog.DeleteMode);
                            }
                            break;
                        #endregion
                    }

                    // Delete tree node
                    if (resultMsg.Count == 0 && deleteDialog.DeleteMode != TVSeriesPlugin.DeleteMenuItems.disk)
                        treeView_Library.Nodes.Remove(nodeDeleted);

                    if (treeView_Library.Nodes.Count == 0)
                    {
                        // also clear the data pane
                        this.detailsPropertyBindingSource.Clear();
                        try
                        {
                            if (this.pictureBox_Series.Image != null)
                            {
                                this.pictureBox_Series.Image.Dispose();
                                this.pictureBox_Series.Image = null;
                            }
                        }
                        catch { }
                    }
                }
                #endregion

                // Show errors, if any
                if (resultMsg != null && resultMsg.Count > 0)
                {
                    MessageBox.Show(string.Join("\n", resultMsg.ToArray()), msgDlgCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }