public int DoReorg()
        {
            /// Todo: move this statement to the GUI.
            /// Database Reorg now fully in music.database
            ///

            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            if (null == pDlgProgress)
            {
                return((int)Errors.ERROR_REORG_SONGS);
            }

            pDlgProgress.SetHeading(313);
            pDlgProgress.SetLine(2, "");
            pDlgProgress.SetLine(3, "");
            pDlgProgress.SetPercentage(0);
            pDlgProgress.Progress();
            pDlgProgress.SetLine(1, 316);
            pDlgProgress.ShowProgressBar(true);

            ///TFRO71 4 june 2005
            ///Connect the event to a method that knows what to do with the event.
            MusicDatabase.DatabaseReorgChanged += new MusicDBReorgEventHandler(SetPercentDonebyEvent);
            ///Execute the reorganisation
            int appel = m_dbs.MusicDatabaseReorg(null);

            ///Tfro Disconnect the event from the method.
            MusicDatabase.DatabaseReorgChanged -= new MusicDBReorgEventHandler(SetPercentDonebyEvent);

            pDlgProgress.SetLine(2, "Klaar");

            return((int)Errors.ERROR_OK);
        }
        public bool OnActorsStarting(IMDBFetcher fetcher)
        {
            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

            // show dialog that we're downloading the actor info
            pDlgProgress.Reset();
            pDlgProgress.SetHeading(986);
            pDlgProgress.SetLine(1, fetcher.MovieName);
            pDlgProgress.SetLine(2, string.Empty);
            pDlgProgress.SetObject(fetcher);
            pDlgProgress.StartModal(GUIWindowManager.ActiveWindow);
            return(true);
        }
        public bool OnSearchStarting(IMDBFetcher fetcher)
        {
            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

            // show dialog that we're busy querying www.imdb.com
            pDlgProgress.Reset();
            pDlgProgress.SetHeading(197);
            pDlgProgress.SetLine(1, fetcher.MovieName);
            pDlgProgress.SetLine(2, string.Empty);
            pDlgProgress.SetObject(fetcher);
            pDlgProgress.StartModal(GUIWindowManager.ActiveWindow);
            return(true);
        }
Example #4
0
        private void UpdateNews(bool bShowWarning)
        {
            GUIDialogProgress dlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

            try
            {
                if (m_strSiteURL.ToLowerInvariant().StartsWith("http://") == false &&
                    m_strSiteURL.ToLowerInvariant().StartsWith("file://") == false)
                {
                    m_strSiteURL = "http://" + m_strSiteURL;
                }

                long startTime = Environment.TickCount;
                dlgProgress.SetHeading(704);
                dlgProgress.SetLine(1, GUILocalizeStrings.Get(705) + " " + m_strSiteName);
                dlgProgress.SetLine(2, "");
                dlgProgress.SetLine(3, "");
                dlgProgress.ShowProgressBar(false);
                dlgProgress.StartModal(GetID);
                dlgProgress.Progress();

                Uri newURL = new Uri(m_strSiteURL);
                Download(newURL);
                UpdateButtons();

                // Leave dialog on screen for minimum of 1 seconds
                // to eliminate the horrible flash of dialog before user can reed it
                long endTime = Environment.TickCount;
                if (endTime - startTime < 1000)
                {
                    Thread.Sleep((int)(1000 - (endTime - startTime)));
                }
                dlgProgress.Close();
            }
            catch (Exception e)
            {
                dlgProgress.Close();
                if (bShowWarning)
                {
                    GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SHOW_WARNING, 0, 0, 0, 0, 0, 0);
                    msg.Param1 = 9;   //my news
                    msg.Param2 = 912; //Unable to download latest news
                    msg.Param3 = 0;
                    msg.Label3 = m_strSiteURL;
                    GUIWindowManager.SendMessage(msg);
                    Log.Error(e);
                }
            }
        }
 public void ShowDialog()
 {
     if (handler == null)
     {
         return;
     }
     handler.OnTaskProgress += new BackgroundTaskProgress(setProgress);
     closeProgDialog();
     dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
     if (dlgPrgrs != null)
     {
         dlgPrgrs.Reset();
         dlgPrgrs.DisplayProgressBar = true;
         dlgPrgrs.ShowWaitCursor     = false;
         dlgPrgrs.DisableCancel(true);
         dlgPrgrs.SetHeading("");
         dlgPrgrs.SetLine(1, "");
         dlgPrgrs.StartModal(GUIWindowManager.ActiveWindow);
     }
     else
     {
         GUIWaitCursor.Init(); GUIWaitCursor.Show();
     }
     if (!handler.Start())
     {
         closeProgDialog();
         return;
     }
 }
        public void OnProgress(string line1, string line2, string line3, int percent)
        {
            if (!GUIWindowManager.IsRouted)
            {
                return;
            }
            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);

            pDlgProgress.ShowProgressBar(true);
            pDlgProgress.SetLine(1, line1);
            pDlgProgress.SetLine(2, line2);
            if (percent > 0)
            {
                pDlgProgress.SetPercentage(percent);
            }
            pDlgProgress.Progress();
        }
 void VideoDownloader_ProgressChanged(object sender, DownloadEventArgs e)
 {
     if (dlgProgress != null)
     {
         dlgProgress.SetLine(2, string.Format("{0} Mb / {1} Mb ({2}%)", e.TotalFileSize / 1024 / 1024, e.CurrentFileSize / 1024 / 1024, e.PercentDone));
         dlgProgress.ShowProgressBar(true);
         dlgProgress.SetPercentage(e.PercentDone);
         dlgProgress.Progress();
     }
 }
 void setProgress(int percent, string info)
 {
     if (dlgPrgrs != null)
     {
         dlgPrgrs.SetPercentage(percent);
         dlgPrgrs.SetLine(1, info);
     }
     if (handler.IsComplete)
     {
         closeProgDialog();
     }
 }
        private void SetPercentDonebyEvent(object sender, DatabaseReorgEventArgs e)
        {
            GUIDialogProgress pDlgProgress =
                (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            if (null == pDlgProgress)
            {
                return;
            }
            pDlgProgress.SetPercentage(e.progress);
            pDlgProgress.SetLine(1, e.phase);
            pDlgProgress.Progress();
        }
Example #10
0
        private bool InternalGetAlbumCovers(string artist, string album, string filteredAlbumText)
        {
            if (amazonWS.AbortGrab)
            {
                return(false);
            }

            amazonWS.ArtistName = artist;
            amazonWS.AlbumName  = album;
            bool result = false;

            if (SearchMode == SearchDepthMode.Album)
            {
                GUIDialogProgress dlgProgress =
                    (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
                if (dlgProgress != null)
                {
                    dlgProgress.SetHeading(185);
                    dlgProgress.SetLine(1, album);
                    dlgProgress.SetLine(2, artist);
                    dlgProgress.SetLine(3, filteredAlbumText);
                    dlgProgress.SetPercentage(0);
                    dlgProgress.Progress();
                    dlgProgress.ShowProgressBar(false);

                    GUIWindowManager.Process();
                }

                result = amazonWS.GetAlbumInfo();
            }

            else
            {
                result = amazonWS.GetAlbumInfo();
            }

            return(result);
        }
        void filtersCreator_DoWork(object sender, DoWorkEventArgs e)
        {
            GUIDialogProgress progressDialog = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            progressDialog.Reset();
            progressDialog.ShowWaitCursor = true;
            progressDialog.SetHeading(Translation.CreatingFilters);
            progressDialog.Percentage = 0;
            progressDialog.SetLine(1, string.Empty);
            progressDialog.SetLine(2, string.Empty);
            progressDialog.StartModal(this.GetID);

            GUIWindowManager.Process();

            TraktHandlers.MovingPictures.CreateMovingPicturesFilters();

            progressDialog.SetHeading(Translation.UpdatingFilters);
            GUIWindowManager.Process();

            TraktHandlers.MovingPictures.UpdateMovingPicturesFilters();
            progressDialog.ShowWaitCursor = false;
            progressDialog.Close();
            GUIWindowManager.Process();
        }
Example #12
0
        public void UpdateSearchResults(string sortOrder)
        {
            GUIDialogProgress dlg = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);

            dlg.Reset();
            dlg.SetHeading("Torrents");
            dlg.SetLine(1, "Fetching torrents...");
            dlg.SetPercentage(0);
            dlg.ShowProgressBar(true);
            dlg.StartModal(GUIWindowManager.ActiveWindow);

            _progressDlg = new ProgressUpdater();
            _progressDlg.SetAutoUpdate(1000, 20);

            TorrentEngine.Instance().SearchTorrent(_searchEngine.Name, _searchString, sortOrder, dlg);
        }
Example #13
0
        private static void ThreadEncodeTrack()
        {
            m_Ripping = true;

            try
            {
                CreateTempFolder();
                if (mp3Background)
                {
                    GUIWaitCursor.Show();
                }
                else if (dlgProgress != null)
                {
                    dlgProgress.Reset();
                    dlgProgress.SetPercentage(0);
                    dlgProgress.StartModal(GetID);
                    dlgProgress.Progress();
                    dlgProgress.ShowProgressBar(true);
                }

                while (importQueue.Count > 0)
                {
                    TrackInfo trackInfo = (TrackInfo)importQueue.Dequeue();
                    if ((dlgProgress != null) && !mp3Background)
                    {
                        if (importQueue.Count > 0)
                        {
                            dlgProgress.SetHeading(
                                string.Format(GUILocalizeStrings.Get(1105) + " ({0} " + GUILocalizeStrings.Get(1104) + ")",
                                              importQueue.Count + 1));
                        }
                        else
                        {
                            dlgProgress.SetHeading(GUILocalizeStrings.Get(1103));
                        }

                        dlgProgress.SetLine(2,
                                            string.Format("{0:00}. {1} - {2}", trackInfo.MusicTag.Track, trackInfo.MusicTag.Artist,
                                                          trackInfo.MusicTag.Title));
                        //dlgProgress.SetLine(2, trackInfo.TempFileName);
                        if (dlgProgress.IsCanceled)
                        {
                            m_CancelRipping = true;
                        }
                    }

                    if (!m_CancelRipping)
                    {
                        m_Drive = new CDDrive();
                        SaveTrack(trackInfo);
                        if (File.Exists(trackInfo.TempFileName) && !m_CancelRipping)
                        {
                            #region Tagging

                            try
                            {
                                Tags tags = Tags.FromFile(trackInfo.TempFileName);
                                tags["TRCK"] = trackInfo.MusicTag.Track.ToString() + "/" + trackInfo.TrackCount.ToString();
                                tags["TALB"] = trackInfo.MusicTag.Album;
                                tags["TPE1"] = trackInfo.MusicTag.Artist;
                                tags["TIT2"] = trackInfo.MusicTag.Title;
                                tags["TCON"] = trackInfo.MusicTag.Genre;
                                if (trackInfo.MusicTag.Year > 0)
                                {
                                    tags["TYER"] = trackInfo.MusicTag.Year.ToString();
                                }
                                tags["TENC"] = "MediaPortal / Lame";
                                tags.Save(trackInfo.TempFileName);
                            }
                            catch
                            {
                            }

                            #endregion

                            #region Database

                            try
                            {
                                if (!Directory.Exists(trackInfo.TargetDir))
                                {
                                    Directory.CreateDirectory(trackInfo.TargetDir);
                                }

                                if (File.Exists(trackInfo.TargetFileName))
                                {
                                    if (mp3ReplaceExisting)
                                    {
                                        File.Delete(trackInfo.TargetFileName);
                                    }
                                }

                                if (!File.Exists(trackInfo.TargetFileName))
                                {
                                    File.Move(trackInfo.TempFileName, trackInfo.TargetFileName);
                                }

                                if (File.Exists(trackInfo.TargetFileName) && mp3Database)
                                {
                                    if (importUnknown || (trackInfo.MusicTag.Artist != "Unknown Artist") ||
                                        (trackInfo.MusicTag.Album != "Unknown Album"))
                                    {
                                        MusicDatabase dbs = MusicDatabase.Instance;
                                        dbs.AddSong(trackInfo.TargetFileName);
                                    }
                                }
                            }
                            catch
                            {
                                Log.Info("CDIMP: Error moving encoded file {0} to new location {1}", trackInfo.TempFileName,
                                         trackInfo.TargetFileName);
                            }

                            #endregion
                        }
                    }
                }
                if (mp3Background)
                {
                    GUIWaitCursor.Hide();
                }
                else
                {
                    dlgProgress.Close();
                }
            }
            finally
            {
                CleanupTempFolder();
            }
            m_CancelRipping = false;
            m_Ripping       = false;
        }
        protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType)
        {
            if (Gui2UtilConnector.Instance.IsBusy)
            {
                return;                                    // wait for any background action e.g. online sites retrieval to finish
            }
            if (control == GUI_btnSort)
            {
                GUIControl.SelectItemControl(GetID, GUI_btnSort.GetID, GUI_btnSort.SelectedItem);
                RefreshDisplayedOnlineSites();
            }
            else if (control == GUI_btnFilterState)
            {
                GUIControl.SelectItemControl(GetID, GUI_btnFilterState.GetID, GUI_btnFilterState.SelectedItem);
                RefreshDisplayedOnlineSites();
            }
            else if (control == GUI_btnFilterCreator)
            {
                GUIControl.SelectItemControl(GetID, GUI_btnFilterCreator.GetID, GUI_btnFilterCreator.SelectedItem);
                RefreshDisplayedOnlineSites();
            }
            else if (control == GUI_btnFilterLang)
            {
                GUIControl.SelectItemControl(GetID, GUI_btnFilterLang.GetID, GUI_btnFilterLang.SelectedItem);
                RefreshDisplayedOnlineSites();
            }
            else if (control == GUI_infoList && actionType == Action.ActionType.ACTION_SELECT_ITEM)
            {
                if (GUI_infoList.SelectedListItem.TVTag is OnlineVideosWebservice.Site)
                {
                    ShowOptionsForSite(GUI_infoList.SelectedListItem.TVTag as OnlineVideosWebservice.Site);
                }
            }
            else if (control == GUI_btnAutoUpdate)
            {
                if (CheckOnlineVideosVersion())
                {
                    Log.Instance.Info("SiteManager: Running AutoUpdate");
                    GUIDialogProgress dlgPrgrs = PrepareProgressDialog(Translation.Instance.AutomaticUpdate);
                    new System.Threading.Thread(delegate()
                    {
                        bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites((m, p) =>
                        {
                            if (dlgPrgrs != null)
                            {
                                if (!string.IsNullOrEmpty(m))
                                {
                                    dlgPrgrs.SetLine(1, m);
                                }
                                if (p != null)
                                {
                                    dlgPrgrs.SetPercentage(p.Value);
                                }
                                return(dlgPrgrs.ShouldRenderLayer());
                            }
                            else
                            {
                                return(true);
                            }
                        });
                        if (updateResult == true)
                        {
                            newDllsDownloaded = true;
                        }
                        else if (updateResult == null)
                        {
                            newDataSaved = true;
                        }
                        if (updateResult != false)
                        {
                            SiteImageExistenceCache.ClearCache();
                        }
                        if (dlgPrgrs != null)
                        {
                            dlgPrgrs.Close();
                        }
                        GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) => { RefreshDisplayedOnlineSites(); return(0); }, 0, 0, null);
                    })
                    {
                        Name = "OVAutoUpdate", IsBackground = true
                    }.Start();
                }
            }

            base.OnClicked(controlId, control, actionType);
        }
        void ShowOptionsForSite(OnlineVideosWebservice.Site site)
        {
            SiteSettings localSite      = null;
            int          localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(site.Name, out localSite);

            GUIDialogMenu dlgSel = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            dlgSel.ShowQuickNumbers = false;
            if (dlgSel != null)
            {
                dlgSel.Reset();
                dlgSel.SetHeading(Translation.Instance.Actions);

                if (localSiteIndex == -1)
                {
                    if (site.State != OnlineVideosWebservice.SiteState.Broken)
                    {
                        dlgSel.Add(Translation.Instance.AddToMySites);
                    }
                }
                else
                {
                    if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 2 && site.State != OnlineVideosWebservice.SiteState.Broken)
                    {
                        dlgSel.Add(Translation.Instance.UpdateMySite);
                        dlgSel.Add(Translation.Instance.UpdateMySiteSkipCategories);
                    }
                    dlgSel.Add(Translation.Instance.RemoveFromMySites);
                }

                if (GUI_infoList.Count > 1)
                {
                    dlgSel.Add(Translation.Instance.RemoveAllFromMySites);
                    dlgSel.Add(Translation.Instance.UpdateAll);
                    dlgSel.Add(Translation.Instance.UpdateAllSkipCategories);
                }

                if (!string.IsNullOrEmpty(site.Owner_FK) && localSiteIndex >= 0) // !only local && ! only global
                {
                    dlgSel.Add(Translation.Instance.ShowReports);
                    if (site.State != OnlineVideosWebservice.SiteState.Broken)
                    {
                        dlgSel.Add(Translation.Instance.ReportBroken);
                    }
                }
            }
            dlgSel.DoModal(GUIWindowManager.ActiveWindow);
            if (dlgSel.SelectedId == -1)
            {
                return;                          // ESC used, nothing selected
            }
            if (dlgSel.SelectedLabelText == Translation.Instance.AddToMySites ||
                dlgSel.SelectedLabelText == Translation.Instance.UpdateMySite ||
                dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories)
            {
                if (CheckOnlineVideosVersion())
                {
                    Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(
                        () =>
                    {
                        bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites(null, new List <OnlineVideosWebservice.Site> {
                            site
                        }, false,
                                                                                   dlgSel.SelectedLabelText == Translation.Instance.UpdateMySiteSkipCategories);
                        if (updateResult == true)
                        {
                            newDllsDownloaded = true;
                        }
                        else if (updateResult == null)
                        {
                            newDataSaved = true;
                        }
                        return(updateResult != false);
                    },
                        (success, result) =>
                    {
                        if (success && (bool)result)
                        {
                            SiteImageExistenceCache.UnCacheImageForSite(site.Name);
                            RefreshDisplayedOnlineSites();
                        }
                    },
                        Translation.Instance.GettingSiteXml, true);
                }
            }
            else if (dlgSel.SelectedLabelText == Translation.Instance.UpdateAll ||
                     dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories)
            {
                if (CheckOnlineVideosVersion())
                {
                    GUIDialogProgress dlgPrgrs = PrepareProgressDialog(Translation.Instance.FullUpdate);
                    new System.Threading.Thread(delegate()
                    {
                        bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites((m, p) =>
                        {
                            if (dlgPrgrs != null)
                            {
                                if (!string.IsNullOrEmpty(m))
                                {
                                    dlgPrgrs.SetLine(1, m);
                                }
                                if (p != null)
                                {
                                    dlgPrgrs.SetPercentage(p.Value);
                                }
                                return(dlgPrgrs.ShouldRenderLayer());
                            }
                            else
                            {
                                return(true);
                            }
                        }, GUI_infoList.ListItems.Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList(), dlgSel.SelectedLabelText == Translation.Instance.UpdateAllSkipCategories);
                        if (updateResult == true)
                        {
                            newDllsDownloaded = true;
                        }
                        else if (updateResult == null)
                        {
                            newDataSaved = true;
                        }
                        if (updateResult != false)
                        {
                            SiteImageExistenceCache.ClearCache();
                        }
                        if (dlgPrgrs != null)
                        {
                            dlgPrgrs.Close();
                        }
                        GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) => { RefreshDisplayedOnlineSites(); return(0); }, 0, 0, null);
                    })
                    {
                        Name = "OVSelectUpdate", IsBackground = true
                    }.Start();
                }
            }
            else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveFromMySites)
            {
                OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex);
                OnlineVideoSettings.Instance.SaveSites();
                newDataSaved = true;
                RefreshDisplayedOnlineSites(GUI_infoList.SelectedListItemIndex);
            }
            else if (dlgSel.SelectedLabelText == Translation.Instance.RemoveAllFromMySites)
            {
                bool needRefresh = false;
                foreach (var siteToRemove in GUI_infoList.ListItems.Where(g => g.IsPlayed).Select(g => g.TVTag as OnlineVideosWebservice.Site).ToList())
                {
                    localSiteIndex = OnlineVideoSettings.Instance.GetSiteByName(siteToRemove.Name, out localSite);
                    if (localSiteIndex >= 0)
                    {
                        OnlineVideoSettings.Instance.RemoveSiteAt(localSiteIndex);
                        needRefresh = true;
                    }
                }
                if (needRefresh)
                {
                    OnlineVideoSettings.Instance.SaveSites();
                    newDataSaved = true;
                    RefreshDisplayedOnlineSites();
                }
            }
            else if (dlgSel.SelectedLabelText == Translation.Instance.ShowReports)
            {
                Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(
                    () =>
                {
                    OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService();
                    return(ws.GetReports(site.Name));
                },
                    (success, result) =>
                {
                    if (success)
                    {
                        OnlineVideosWebservice.Report[] reports = result as OnlineVideosWebservice.Report[];

                        if (reports == null || reports.Length == 0)
                        {
                            GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                            if (dlg != null)
                            {
                                dlg.Reset();
                                dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon"));
                                dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                                dlg.SetText(Translation.Instance.NoReportsForSite);
                                dlg.DoModal(GUIWindowManager.ActiveWindow);
                            }
                        }
                        else
                        {
                            selectedSite = site.Name;
                            GUIControl.ClearControl(GetID, GUI_infoList.GetID);

                            Array.Sort(reports, new Comparison <OnlineVideosWebservice.Report>(delegate(OnlineVideosWebservice.Report a, OnlineVideosWebservice.Report b)
                            {
                                return(b.Date.CompareTo(a.Date));
                            }));

                            foreach (OnlineVideosWebservice.Report report in reports)
                            {
                                string shortMsg            = report.Message.Replace(Environment.NewLine, " ").Replace("\n", " ").Replace("\r", " ");
                                GUIListItem loListItem     = new GUIListItem(shortMsg.Length > 44 ? shortMsg.Substring(0, 40) + " ..." : shortMsg);
                                loListItem.TVTag           = report;
                                loListItem.Label2          = report.Type.ToString();
                                loListItem.Label3          = report.Date.ToString("g", OnlineVideoSettings.Instance.Locale);
                                loListItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnReportSelected);
                                GUI_infoList.Add(loListItem);
                            }
                            GUIControl.SelectItemControl(GetID, GUI_infoList.GetID, 0);
                            GUIPropertyManager.SetProperty("#itemcount", GUI_infoList.Count.ToString());
                            GUIPropertyManager.SetProperty("#itemtype", Translation.Instance.Reports);
                        }
                    }
                }, Translation.Instance.GettingReports, true);
            }
            else if (dlgSel.SelectedLabelText == Translation.Instance.ReportBroken)
            {
                if (CheckOnlineVideosVersion())
                {
                    if ((site.LastUpdated - localSite.LastUpdated).TotalMinutes > 1)
                    {
                        GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                        if (dlg != null)
                        {
                            dlg.Reset();
                            dlg.SetHeading(site.Name);
                            dlg.SetLine(1, Translation.Instance.PleaseUpdateLocalSite);
                            dlg.DoModal(GUIWindowManager.ActiveWindow);
                        }
                    }
                    else
                    {
                        string userReason = "";
                        if (GUIOnlineVideos.GetUserInputString(ref userReason, false))
                        {
                            if (userReason.Length < 15)
                            {
                                GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                if (dlg != null)
                                {
                                    dlg.Reset();
                                    dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                                    dlg.SetLine(1, Translation.Instance.PleaseEnterDescription);
                                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                                }
                            }
                            else
                            {
                                OnlineVideosWebservice.OnlineVideosService ws = new OnlineVideosWebservice.OnlineVideosService();
                                string      message = "";
                                bool        success = ws.SubmitReport(site.Name, userReason, OnlineVideosWebservice.ReportType.Broken, out message);
                                GUIDialogOK dlg     = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);
                                if (dlg != null)
                                {
                                    dlg.Reset();
                                    dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                                    dlg.SetLine(1, success ? Translation.Instance.Done : Translation.Instance.Error);
                                    dlg.SetLine(2, message);
                                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                                }
                                if (success)
                                {
                                    // reload online sites
                                    OnlineVideos.Sites.Updater.GetRemoteOverviews(true);
                                    RefreshDisplayedOnlineSites();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #16
0
        private static bool WakeupSystem(byte[] hwAddress, string wakeupTarget, int timeout)
        {
            int waited = 0;

            WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();

            Log.Debug("WOLMgr: Ping {0}", wakeupTarget);
            if (wakeOnLanManager.Ping(wakeupTarget, 200))
            {
                Log.Debug("WOLMgr: {0} already started", wakeupTarget);
                return(true);
            }

            GUIDialogProgress progressDialog =
                (GUIDialogProgress)GUIWindowManager.GetWindow(101); //(int)Window.WINDOW_DIALOG_PROGRESS

            progressDialog.Reset();
            progressDialog.SetHeading(GUILocalizeStrings.Get(1990));
            progressDialog.ShowProgressBar(true);
            progressDialog.SetLine(1, GUILocalizeStrings.Get(1991));
            progressDialog.StartModal(GUIWindowManager.ActiveWindow);

            // First, try to send WOL Packet
            if (!wakeOnLanManager.SendWakeOnLanPacket(hwAddress, IPAddress.Broadcast))
            {
                Log.Debug("WOLMgr: FAILED to send the first wake-on-lan packet!");
            }

            while (waited < timeout)
            {
                int percentange = (waited * 100) / timeout;

                progressDialog.SetPercentage(percentange);
                progressDialog.Progress();

                Log.Debug("WOLMgr: Ping {0}", wakeupTarget);
                if (wakeOnLanManager.Ping(wakeupTarget, 200))
                {
                    progressDialog.SetPercentage(100);
                    progressDialog.Progress();
                    progressDialog.Close();

                    int waittime;
                    using (Settings xmlreader = new MPSettings())
                    {
                        waittime = xmlreader.GetValueAsInt("WOL", "WaitTimeAfterWOL", 0);
                    }

                    if (waittime > 0)
                    {
                        GUIDialogProgress progressDialog2 =
                            (GUIDialogProgress)GUIWindowManager.GetWindow(101); //(int)Window.WINDOW_DIALOG_PROGRESS
                        progressDialog2.Reset();
                        progressDialog2.SetHeading(string.Empty);
                        progressDialog2.ShowProgressBar(true);
                        progressDialog2.SetLine(1, GUILocalizeStrings.Get(1994));
                        progressDialog2.StartModal(GUIWindowManager.ActiveWindow);

                        waited = waittime;

                        for (int i = waited; waited != 0; waited--)
                        {
                            percentange = (waited * 100) / waittime;

                            progressDialog2.SetPercentage(percentange);
                            progressDialog2.Progress();

                            System.Threading.Thread.Sleep(1000);
                        }

                        progressDialog2.SetPercentage(0);
                        progressDialog2.Progress();
                        progressDialog2.Close();
                    }
                    return(true);
                }
                // Send WOL Packet
                if (!wakeOnLanManager.SendWakeOnLanPacket(hwAddress, IPAddress.Broadcast))
                {
                    Log.Debug("WOLMgr: Sending the wake-on-lan packet failed (local network maybe not ready)! {0}s", waited);
                }
                Log.Debug("WOLMgr: System {0} still not reachable, waiting... {1}s", wakeupTarget, waited);

                System.Threading.Thread.Sleep(1000);
                waited++;
            }

            // Timeout was reached and WOL packet can't be send (we stop here)
            Log.Debug("WOLMgr: FAILED to send wake-on-lan packet after the timeout {0}, try increase the value!", timeout);

            progressDialog.SetPercentage(100);
            progressDialog.Progress();
            progressDialog.Close();

            GUIDialogOK dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK);

            dlgOk.SetHeading(GUILocalizeStrings.Get(1992)); // Not available
            dlgOk.SetLine(1, GUILocalizeStrings.Get(1993));
            dlgOk.DoModal(GUIWindowManager.ActiveWindow);

            return(false);
        }
 void DoSubsequentLoad()
 {
     if (PreviousWindowId != OnlineVideos.MediaPortal1.Player.GUIOnlineVideoFullscreen.WINDOW_FULLSCREEN_ONLINEVIDEO &&
         PluginConfiguration.Instance.updateOnStart != false &&
         PluginConfiguration.Instance.lastFirstRun.AddHours(PluginConfiguration.Instance.updatePeriod) < DateTime.Now)
     {
         bool?doUpdate = PluginConfiguration.Instance.updateOnStart;
         if (!PluginConfiguration.Instance.updateOnStart.HasValue && !preventDialogOnLoad)
         {
             GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
             if (dlg != null)
             {
                 dlg.Reset();
                 dlg.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlg.SetLine(1, Translation.Instance.PerformAutomaticUpdate);
                 dlg.SetLine(2, Translation.Instance.UpdateAllYourSites);
                 dlg.DoModal(GUIWindowManager.ActiveWindow);
                 doUpdate = dlg.IsConfirmed;
             }
         }
         PluginConfiguration.Instance.lastFirstRun = DateTime.Now;
         if (doUpdate == true || PluginConfiguration.Instance.ThumbsAge >= 0)
         {
             GUIDialogProgress dlgPrgrs = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
             if (dlgPrgrs != null)
             {
                 dlgPrgrs.Reset();
                 dlgPrgrs.DisplayProgressBar = true;
                 dlgPrgrs.ShowWaitCursor     = false;
                 dlgPrgrs.DisableCancel(true);
                 dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                 dlgPrgrs.StartModal(GUIWindowManager.ActiveWindow);
             }
             else
             {
                 GUIWaitCursor.Init(); GUIWaitCursor.Show();
             }
             new System.Threading.Thread(delegate()
             {
                 if (doUpdate == true)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(string.Format("{0} - {1}", PluginConfiguration.Instance.BasicHomeScreenName, Translation.Instance.AutomaticUpdate));
                     }
                     var onlineVersion = Sites.Updater.VersionOnline;
                     if (OnlineVideos.Sites.Updater.VersionCompatible)
                     {
                         bool?updateResult = OnlineVideos.Sites.Updater.UpdateSites((m, p) =>
                         {
                             if (dlgPrgrs != null)
                             {
                                 if (!string.IsNullOrEmpty(m))
                                 {
                                     dlgPrgrs.SetLine(1, m);
                                 }
                                 if (p != null)
                                 {
                                     dlgPrgrs.SetPercentage(p.Value);
                                 }
                                 return(dlgPrgrs.ShouldRenderLayer());
                             }
                             else
                             {
                                 return(true);
                             }
                         }
                                                                                    );
                         if (updateResult == true && OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             GUISiteUpdater.ReloadDownloadedDlls();
                         }
                         else if (updateResult == null || OnlineVideoSettings.Instance.SiteUtilsList.Count > 0)
                         {
                             OnlineVideoSettings.Instance.BuildSiteUtilsList();
                         }
                         if (updateResult != false)
                         {
                             PluginConfiguration.Instance.BuildAutomaticSitesGroups();
                             SiteImageExistenceCache.ClearCache();
                         }
                     }
                     else
                     {
                         // inform the user that autoupdate is disabled due to outdated version!
                         dlgPrgrs.SetLine(1, Translation.Instance.AutomaticUpdateDisabled);
                         dlgPrgrs.SetLine(2, onlineVersion != null ? string.Format(Translation.Instance.LatestVersionRequired, onlineVersion) : "Check your Internet Connection!");
                         Thread.Sleep(5000);
                         dlgPrgrs.SetLine(2, string.Empty);
                     }
                 }
                 if (PluginConfiguration.Instance.ThumbsAge >= 0)
                 {
                     if (dlgPrgrs != null)
                     {
                         dlgPrgrs.SetHeading(PluginConfiguration.Instance.BasicHomeScreenName);
                         dlgPrgrs.SetLine(1, Translation.Instance.DeletingOldThumbs);
                         dlgPrgrs.Percentage = 0;
                     }
                     ImageDownloader.DeleteOldThumbs(PluginConfiguration.Instance.ThumbsAge, r =>
                     {
                         if (dlgPrgrs != null)
                         {
                             dlgPrgrs.Percentage = r;
                         }
                         return(dlgPrgrs != null ? dlgPrgrs.ShouldRenderLayer() : true);
                     });
                 }
                 if (dlgPrgrs != null)
                 {
                     dlgPrgrs.Percentage = 100; dlgPrgrs.SetLine(1, Translation.Instance.Done); dlgPrgrs.Close();
                 }
                 else
                 {
                     GUIWaitCursor.Hide();
                 }
                 GUIWindowManager.SendThreadCallbackAndWait((p1, p2, data) =>
                 {
                     DoPageLoad();
                     return(0);
                 }, 0, 0, null);
             })
             {
                 Name = "OVLoad", IsBackground = true
             }.Start();
             return;
         }
     }
     DoPageLoad();
 }
Example #18
0
        public List <string> deleteSeason(TVSeriesPlugin.DeleteMenuItems type)
        {
            List <string> resultMsg = new List <string>();

            // Always delete from Local episode table if deleting from disk or database
            SQLCondition condition = new SQLCondition();

            condition.Add(new DBEpisode(), DBEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
            condition.Add(new DBEpisode(), DBEpisode.cSeasonIndex, this[DBSeason.cIndex], SQLConditionType.Equal);

            /* TODO will include hidden episodes as hidden attribute is only in onlineepisodes. maybe we should include it in localepisodes also..
             * if hidden episodes are excluded then the if (resultMsg.Count is wrong and should do another select to get proper count
             * if (!DBOption.GetOptions(DBOption.cShowHiddenItems))
             * {
             *  //don't include hidden seasons unless the ShowHiddenItems option is set
             *  condition.Add(new DBEpisode(), idden, 0, SQLConditionType.Equal);
             * }
             */

            List <DBEpisode> episodes = DBEpisode.Get(condition, false);

            if (episodes != null)
            {
                bool hasLocalEpisodesToDelete = episodes.Exists(e => !string.IsNullOrEmpty(e[DBEpisode.cFilename]));
                hasLocalEpisodesToDelete &= (type == TVSeriesPlugin.DeleteMenuItems.disk || type == TVSeriesPlugin.DeleteMenuItems.diskdatabase);

                DBSeries series     = Helper.getCorrespondingSeries(this[DBSeason.cSeriesID]);
                string   seriesName = series == null ? this[DBSeason.cSeriesID].ToString() : series.ToString();

                // show progress dialog as this can be a long process esp for network drives
                // will show new progress for each season if deleting from the series level
                GUIDialogProgress progressDialog = null;
                if (!Settings.isConfig)
                {
                    progressDialog = (GUIDialogProgress)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_PROGRESS);
                    progressDialog.Reset();
                    progressDialog.DisplayProgressBar = true;
                    progressDialog.ShowWaitCursor     = false;
                    progressDialog.DisableCancel(true);
                    progressDialog.SetHeading(Translation.Delete);
                    progressDialog.Percentage = 0;
                    progressDialog.SetLine(1, string.Format("{0} {1} {2}", seriesName, Translation.Season, this[DBSeason.cIndex]));
                    progressDialog.SetLine(2, string.Empty);

                    // only show progress dialog if we have local files in season
                    if (hasLocalEpisodesToDelete)
                    {
                        progressDialog.StartModal(GUIWindowManager.ActiveWindow);
                    }
                }

                int counter = 0;

                foreach (DBEpisode episode in episodes)
                {
                    string episodeName = string.Format("{0}x{1} - {2}", episode[DBOnlineEpisode.cSeasonIndex], episode[DBOnlineEpisode.cEpisodeIndex], episode[DBOnlineEpisode.cEpisodeName]);
                    if (!Settings.isConfig)
                    {
                        progressDialog.SetLine(2, episodeName);
                    }
                    if (!Settings.isConfig)
                    {
                        GUIWindowManager.Process();
                    }

                    resultMsg.AddRange(episode.deleteEpisode(type, true));

                    if (!Settings.isConfig)
                    {
                        progressDialog.Percentage = Convert.ToInt32(((double)++counter / (double)episodes.Count) * 100.0);
                    }
                    if (!Settings.isConfig)
                    {
                        GUIWindowManager.Process();
                    }
                }

                // close progress dialog
                if (!Settings.isConfig)
                {
                    progressDialog.Close();
                }

                // if we have removed all episodes in season without error, cleanup the online table
                if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk)
                {
                    condition = new SQLCondition();
                    condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeasonIndex, this[DBSeason.cIndex], SQLConditionType.Equal);
                    DBOnlineEpisode.Clear(condition);
                }
            }

            #region Facade Remote Color
            // if we were successful at deleting all episodes of season from disk, set HasLocalFiles to false
            // note: we only do this if the database entries still exist
            if (resultMsg.Count == 0 && type == TVSeriesPlugin.DeleteMenuItems.disk)
            {
                this[cHasLocalFiles] = false;
                this.Commit();
            }

            // if we were successful at deleting all episodes of season from disk,
            // also check if any local episodes exist on disk for series and set HasLocalFiles to false
            if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.database)
            {
                // Check Series for Local Files
                SQLCondition episodeConditions = new SQLCondition();
                episodeConditions.Add(new DBEpisode(), DBEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                List <DBEpisode> localEpisodes = DBEpisode.Get(episodeConditions);
                if (localEpisodes.Count == 0 && !DBSeries.IsSeriesRemoved)
                {
                    DBSeries series = DBSeries.Get(this[DBSeason.cSeriesID]);
                    if (series != null)
                    {
                        series[DBOnlineSeries.cHasLocalFiles] = false;
                        series.Commit();
                    }
                }
            }
            #endregion

            #region Cleanup

            // if there are no error messages and if we need to delete from db
            if (resultMsg.Count == 0 && type != TVSeriesPlugin.DeleteMenuItems.disk)
            {
                condition = new SQLCondition();
                condition.Add(new DBSeason(), DBSeason.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                condition.Add(new DBSeason(), DBSeason.cIndex, this[DBSeason.cIndex], SQLConditionType.Equal);
                DBSeason.Clear(condition);
            }

            DBSeries.IsSeriesRemoved = false;
            if (type != TVSeriesPlugin.DeleteMenuItems.disk)
            {
                // If local/online episode count is zero then delete the series and all seasons
                condition = new SQLCondition();
                condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                episodes = DBEpisode.Get(condition, false);
                if (episodes.Count == 0)
                {
                    // Delete Seasons
                    condition = new SQLCondition();
                    condition.Add(new DBSeason(), DBSeason.cSeriesID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBSeason.Clear(condition);

                    // Delete Local Series
                    condition = new SQLCondition();
                    condition.Add(new DBSeries(), DBSeries.cID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBSeries.Clear(condition);

                    // Delete Online Series
                    condition = new SQLCondition();
                    condition.Add(new DBOnlineSeries(), DBOnlineSeries.cID, this[DBSeason.cSeriesID], SQLConditionType.Equal);
                    DBOnlineSeries.Clear(condition);

                    DBSeries.IsSeriesRemoved = true;
                }
            }
            #endregion

            return(resultMsg);
        }
        /// <summary>
        /// Called when [show context menu].
        /// </summary>
        protected override void OnShowContextMenu()
        {
            GUIListItem selectedItem = listControl.SelectedListItem;

            YouTubeEntry    videoEntry;
            LocalFileStruct file = selectedItem.MusicTag as LocalFileStruct;

            if (file != null)
            {
                Uri   videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId);
                Video video         = Youtube2MP.request.Retrieve <Video>(videoEntryUrl);
                videoEntry = video.YouTubeEntry;
            }
            else
            {
                videoEntry = selectedItem.MusicTag as YouTubeEntry;
            }

            if (videoEntry == null)
            {
                return;
            }
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(498); // menu
            dlg.Add("Related Videos");
            dlg.Add("Video responses for this video");
            dlg.Add("All videos from this user : "******"Add to playlist");
            dlg.Add("Add All to playlist");
            dlg.Add("Add to favorites");
            dlg.Add("Options");
            dlg.Add("Download Video");
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            switch (dlg.SelectedLabel)
            {
            case 0: //relatated
            {
                if (videoEntry.RelatedVideosUri != null)
                {
                    YouTubeQuery query = new YouTubeQuery(videoEntry.RelatedVideosUri.Content);
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No item was found !");
                    }
                }
            }
            break;

            case 1: //respponse
            {
                if (videoEntry.VideoResponsesUri != null)
                {
                    YouTubeQuery query = new YouTubeQuery(videoEntry.VideoResponsesUri.Content);
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No response was found !");
                    }
                }
            }
            break;

            case 2: //relatated
            {
                if (videoEntry.RelatedVideosUri != null)
                {
                    Video        video = Youtube2MP.request.Retrieve <Video>(new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoEntry.VideoId));
                    YouTubeQuery query = new YouTubeQuery(string.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", video.Author));
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No item was found !");
                    }
                }
            }
            break;

            case 3:
            {
                VideoInfo inf = SelectQuality(videoEntry);
                if (inf.Quality != VideoQuality.Unknow)
                {
                    AddItemToPlayList(selectedItem, inf);
                }
            }
            break;

            case 4:
            {
                VideoInfo inf = SelectQuality(videoEntry);
                inf.Items = new Dictionary <string, string>();
                foreach (GUIListItem item in listControl.ListView.ListItems)
                {
                    AddItemToPlayList(item, new VideoInfo(inf));
                }
            }
            break;

            case 5:
            {
                try
                {
                    service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
                }
                catch (Exception)
                {
                    Err_message("Wrong request or wrong user identification");
                }
            }
            break;

            case 6:
                DoOptions();
                break;

            case 7: // download
            {
                if (Youtube2MP._settings.LocalFile.Get(videoEntry.VideoId) != null)
                {
                    Err_message("Item already downloaded !");
                }
                else
                {
                    if (VideoDownloader.IsBusy)
                    {
                        Err_message("Another donwnload is in progress");
                        dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
                        if (dlgProgress != null)
                        {
                            dlgProgress.Reset();
                            dlgProgress.SetHeading("Download progress");
                            dlgProgress.SetLine(1, "");
                            dlgProgress.SetLine(2, "");
                            dlgProgress.SetPercentage(0);
                            dlgProgress.Progress();
                            dlgProgress.ShowProgressBar(true);
                            dlgProgress.DoModal(GetID);
                        }
                    }
                    else
                    {
                        VideoInfo inf       = SelectQuality(videoEntry);
                        string    streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf);
                        VideoDownloader.AsyncDownload(streamurl,
                                                      Youtube2MP._settings.DownloadFolder + "\\" +
                                                      Utils.GetFilename(videoEntry.Title.Text + "{" + videoEntry.VideoId + "}") +
                                                      Path.GetExtension(streamurl));
                        VideoDownloader.Entry = videoEntry;
                    }
                }
            }
            break;
            }
        }
Example #20
0
        protected override void OnShowContextMenu()
        {
            if (listControl == null || listControl.SelectedListItem == null)
            {
                return;
            }
            GUIListItem   selectedItem = listControl.SelectedListItem;
            YouTubeEntry  videoEntry   = selectedItem.MusicTag as YouTubeEntry;
            GUIDialogMenu dlg          = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(498); // menu
            if (Youtube2MP.player.CurrentSong > -1 || Youtube2MP.temp_player.CurrentSong > -1)
            {
                dlg.Add(Translation.PlayNext);
            }
            dlg.Add(Translation.ShowPreviousWindow);
            dlg.Add(Translation.Fullscreen);
            if (videoEntry != null)
            {
                dlg.Add(Translation.AddPlaylist);
                dlg.Add(Translation.AddAllPlaylist);
                dlg.Add(Translation.Info);
                if (Youtube2MP.service.Credentials != null)
                {
                    dlg.Add(Translation.AddFavorites);
                    dlg.Add(Translation.AddWatchLater);
                }
            }
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            if (dlg.SelectedLabelText == Translation.ShowPreviousWindow)
            {
                GUIWindowManager.ShowPreviousWindow();
            }
            else if (dlg.SelectedLabelText == Translation.Fullscreen)
            {
                g_Player.ShowFullScreenWindow();
            }
            else if (dlg.SelectedLabelText == Translation.AddPlaylist)
            {
                VideoInfo inf = SelectQuality(videoEntry);
                if (inf.Quality != VideoQuality.Unknow)
                {
                    AddItemToPlayList(selectedItem, inf);
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddAllPlaylist)
            {
                VideoInfo inf = SelectQuality(videoEntry);
                inf.Items = new Dictionary <string, string>();
                if (inf.Quality != VideoQuality.Unknow)
                {
                    GUIDialogProgress dlgProgress =
                        (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
                    if (dlgProgress != null)
                    {
                        dlgProgress.Reset();
                        dlgProgress.SetHeading(Translation.AddAllPlaylist);
                        dlgProgress.SetLine(1, "");
                        dlgProgress.SetLine(2, "");
                        dlgProgress.SetPercentage(0);
                        dlgProgress.Progress();
                        dlgProgress.ShowProgressBar(true);
                        dlgProgress.StartModal(GetID);
                    }
                    int i = 0;
                    for (int j = 0; j < listControl.Count; j++)
                    {
                        GUIListItem item = listControl[j];
                        if (dlgProgress != null)
                        {
                            double pr = ((double)i / (double)listControl.Count) * 100;
                            dlgProgress.SetLine(1, item.Label);
                            dlgProgress.SetLine(2, i.ToString() + "/" + listControl.Count.ToString());
                            dlgProgress.SetPercentage((int)pr);
                            dlgProgress.Progress();
                            if (dlgProgress.IsCanceled)
                            {
                                break;
                            }
                        }
                        i++;
                        AddItemToPlayList(item, new VideoInfo(inf));
                    }
                    if (dlgProgress != null)
                    {
                        dlgProgress.Close();
                    }
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddFavorites)
            {
                try
                {
                    Youtube2MP.service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
                }
                catch (Exception)
                {
                    Err_message(Translation.WrongRequestWrongUser);
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddWatchLater)
            {
                PlayListMember pm = new PlayListMember();
                pm.Id = videoEntry.VideoId;
                Youtube2MP.request.Insert(new Uri("https://gdata.youtube.com/feeds/api/users/default/watch_later"), pm);
            }
            else if (dlg.SelectedLabelText == Translation.Info)
            {
                YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx)GUIWindowManager.GetWindow(29053);
                scr.YouTubeEntry = videoEntry;
                //if (entry!=null)
                //{
                //  ArtistItem artistItem=ent
                //}
                GUIWindowManager.ActivateWindow(29053);
            }
            else if (dlg.SelectedLabelText == Translation.PlayNext)
            {
                PlayNext(videoEntry);
            }
        }