Ejemplo n.º 1
0
        /// <summary>
        /// load videos from disk into list
        /// </summary>
        /// <param name="source">source to load, or all if null</param>
        public void LoadFromDisk(ConfigSettings.Source source)
        {
            stopwatch = Stopwatch.StartNew(); // stopped when background worker completed

            subFormFilterForm.Enabled = false;
            subFormListView.Enabled   = false;
            subFormVideoForm.Enabled  = false;
            subFormGallery.Enabled    = false;

            // TODO are these really needed here?
            //FilterInfo filterInfo = subFormFilterForm.GetFilterForm();
            //subFormListView.listViewColumnSorter.SortColumnIndex = FilterEnums.sortColumn.GetValueByKey(filterInfo.sortColumn);
            //subFormListView.listViewColumnSorter.SortOrderIndex = filterInfo.sortOrderIndex;

            List <string> directories = new List <string>();

            if (source != null)
            {
                directories.Add(source.directory);
            }
            else
            {
                foreach (ConfigSettings.Source settingsSource in Config.settings.sources)
                {
                    directories.Add(settingsSource.directory);
                }
            }
            MyLog.Add("Scan sources " + String.Join(", ", directories) + " -->");
            backgroundWorkerScanSource.Run(directories);
        }
Ejemplo n.º 2
0
        private void listViewSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (scanning)
            {
                // revert to scanning source
                if (currentSource != null)
                {
                    ListViewItem listViewItem = listViewSource.FindItemWithText(currentSource.alias);
                    if (listViewItem != null)
                    {
                        listViewItem.Selected = true;
                    }
                }
                return;
            }

            if (listViewSource.SelectedItems.Count == 0)
            {
                ClearSourceForm();

                buttonRemoveSource.Enabled = false;
                buttonScanSource.Enabled   = false;
                buttonAddSource.Enabled    = true;
            }
            else
            {
                ListViewItem selectedItem = listViewSource.SelectedItems[0];
                string       alias        = selectedItem.SubItems[0].Text;

                ConfigSettings.Source source = Config.GetSourceByAlias(alias);
                if (source == null)
                {
                    return;
                }

                currentSource = source;

                MyFormField.SetTextBoxText(textBoxAlias, source.alias);
                MyFormField.SetComboBoxValue(comboBoxType, source.type);
                MyFormField.SetLabelText(labelLastScanned, source.lastScanned);
                MyFormField.SetTextBoxText(textBoxDirectory, source.directory);

                CalcStatsForSource(source);

                textBoxAlias.Enabled     = false;
                textBoxDirectory.Enabled = false;
                comboBoxType.Enabled     = false;

                buttonAddSource.Enabled       = true;
                buttonSourceDirectory.Enabled = false;
                buttonRemoveSource.Enabled    = true;
                buttonSaveSource.Enabled      = false;
                buttonScanSource.Enabled      = true;
                subFormProgressOptions.Text("Ready");
            }
        }
Ejemplo n.º 3
0
        private void buttonRemoveSource_Click(object sender, EventArgs e)
        {
            MyFormField.DelayButtonClick(buttonRemoveSource);

            if (currentSource == null)
            {
                return;
            }

            string message = "Are you sure you want to remove this Video Source?" + Environment.NewLine;

            message += "Alias: " + currentSource.alias + Environment.NewLine;
            message += "Type: " + currentSource.type + Environment.NewLine;
            message += "Directory: " + currentSource.directory + Environment.NewLine;
            string lastScanned = currentSource.lastScanned.ToLocalTime().ToString();

            if (currentSource.lastScanned == DateTime.MinValue)
            {
                lastScanned = "Not yet";
            }
            message += "Last Scanned: " + lastScanned + Environment.NewLine;

            if (MessageBox.Show(message, "Confirm Removal",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                listViewSource.SelectedItems[0].Remove();


                // remove entry from settings
                Config.settings.sources.Remove(currentSource);

                List <VideoInfo> currentVideoInfos = ListVideoInfo.GetList();
                int nbrOrigVideoInfos = currentVideoInfos.Count();
                currentVideoInfos.RemoveAll(s => s.sourceAlias == currentSource.alias);
                int nbrRemovedVideoInfos = nbrOrigVideoInfos - currentVideoInfos.Count();
                ListVideoInfo.SetList(currentVideoInfos);

                // meh, but works
                FormMain        formMain        = (FormMain)this.Owner;
                SubFormListView subFormListView = formMain.GetSubFormListView();
                subFormListView.SetListViewInfos(ListVideoInfo.GetList());

                MyLog.Add("Removed " + currentSource.alias + " and it's " + nbrRemovedVideoInfos + " VideoItems");

                // datatable xml will be updated on main form close
                // settings xml will be updated on main form close

                currentSource = null;
                buttonRemoveSource.Enabled = false;
            }
        }
Ejemplo n.º 4
0
        private void CalcStatsForSource(ConfigSettings.Source source)
        {
            List <VideoInfo> listVideoInfos = ListVideoInfo.GetList();

            if (listVideoInfos == null)
            {
                return;
            }

            listVideoInfos = listVideoInfos.FindAll(x => x.sourceAlias == source.alias).ToList();
            if (listVideoInfos == null)
            {
                return;
            }

            int nbrVideos = listVideoInfos.Where(x => x.files != null && x.files.video != null).Count();

            // int nbrPosters = listVideoInfos.Where(x => x.files != null && x.files.poster != null).Count();
            // int nbrFanarts = listVideoInfos.Where(x => x.files != null && x.files.fanart != null).Count();
            // int nbrImages = listVideoInfos.Where(x => x.files != null && x.files.images != null).Count();

            // int nbrMBs = listVideoInfos.Where(x => x.files != null && x.files.mb != null).Count();
            // int nbrMVEs = listVideoInfos.Where(x => x.files != null && x.files.mve != null).Count();
            // int nbrXBMCs = listVideoInfos.Where(x => x.files != null && x.files.xbmc != null).Count();

            // int nbrOthers = listVideoInfos.Where(x => x.files != null && x.files.others != null).Count();

            int nbrFiles = listVideoInfos.Where(x => x.files != null).Sum(x => x.files.qty);

            // int nbrNonVideos = nbrImages + nbrMBs + nbrMVEs + nbrXBMCs + nbrOthers;
            int nbrNonVideos = nbrFiles - nbrVideos;


            labelVideoFileQty.Text = nbrVideos.ToString();


            labelOtherFilesQty.Text = nbrNonVideos.ToString();
        }
Ejemplo n.º 5
0
        private void buttonSaveSource_Click(object sender, EventArgs e)
        {
            string alias     = textBoxAlias.Text.Trim();
            string type      = VideoFileEnums.sourceType.GetTextByValue(comboBoxType.SelectedValue);
            string directory = textBoxDirectory.Text.Trim();

            string message = "";

            if (alias == "")
            {
                message += "Enter an Alias for this Video Source." + Environment.NewLine;
            }
            if (directory.Length < 3)
            {
                message += "Select a Directory for this Video Source" + Environment.NewLine;
            }
            foreach (ListViewItem listViewItemCheck in listViewSource.Items)
            {
                string aliasCheck     = listViewItemCheck.SubItems[0].Text;
                string directoryCheck = listViewItemCheck.SubItems[1].Text;

                if (alias == aliasCheck)
                {
                    message += "Alias [" + alias + "] already exists." + Environment.NewLine;
                    message += "Enter an unique Alias for this Video Source." + Environment.NewLine;
                }
                if (directory == directoryCheck)
                {
                    message += "Directory [" + directory + "] already exists." + Environment.NewLine;
                    message += "Select an unique Directory for this Video Source." + Environment.NewLine;
                }
            }
            if (message != "")
            {
                MessageBox.Show(message);
                return;
            }

            // add to source list
            alias     = MyFile.SafeFileName(alias);
            directory = MyFile.SafeDirectory(directory);
            ListViewItem listViewItem = new ListViewItem(alias);

            listViewItem.SubItems.Add(type);
            listViewItem.SubItems.Add("");
            listViewSource.Items.Add(listViewItem);

            // add to settings
            ConfigSettings.Source source = new ConfigSettings.Source();
            source.alias     = alias;
            source.directory = directory;
            source.type      = type;
            Config.settings.sources.Add(source);

            // clear form
            ClearSourceForm();

            buttonSaveSource.Enabled = false; // no edits

            // select added item and infer scan
            listViewItem = listViewSource.FindItemWithText(source.alias);
            if (listViewItem != null)
            {
                listViewItem.Selected = true;
            }
            buttonScanSource.Focus();

            // video list ui will be update when user rescans
            // video list xml will be updated on main form close
            // settings xml will be updated on main form close, and options form closes
        }