private void bg_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { try { BackgroundFacadeLoadingArgument arg = e.UserState as BackgroundFacadeLoadingArgument; if (bg.CancellationPending) { MPTVSeriesLog.Write("bg_ProgressChanged cancelled", MPTVSeriesLog.LogLevel.Debug); return; } PerfWatcher.GetNamedWatch("FacadeLoading changed").Start(); if (arg == null || arg.Type == BackGroundLoadingArgumentType.None) return; switch (arg.Type) { case BackGroundLoadingArgumentType.FullElement: case BackGroundLoadingArgumentType.ElementForDelayedImgLoading: { PerfWatcher.GetNamedWatch("FacadeLoading addElem").Start(); GUIListItem gli = arg.Argument as GUIListItem; if (m_Facade != null && gli != null) { // Messages are not recieved in OnMessage for Filmstrip/Coverflow, instead subscribe to OnItemSelected if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip) gli.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected); if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow) gli.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected); bFacadeEmpty = false; m_Facade.Add(gli); if (arg.Type == BackGroundLoadingArgumentType.ElementForDelayedImgLoading) { if (itemsForDelayedImgLoading == null) itemsForDelayedImgLoading = new Dictionary<int, GUIListItem>(); itemsForDelayedImgLoading.Add(arg.IndexArgument, gli); } } else { MPTVSeriesLog.Write(string.Format("ElementForDelayedImgLoading: Facade or GUIListItem was null. Skipping index: {0}", arg.IndexArgument), MPTVSeriesLog.LogLevel.Debug); } PerfWatcher.GetNamedWatch("FacadeLoading addElem").Stop(); } break; case BackGroundLoadingArgumentType.DelayedImgLoading: { PerfWatcher.GetNamedWatch("FacadeLoading addDelayedImage").Start(); if (itemsForDelayedImgLoading != null && itemsForDelayedImgLoading.Count > arg.IndexArgument) { string image = arg.Argument as string; if (itemsForDelayedImgLoading.ContainsKey(arg.IndexArgument)) { if (itemsForDelayedImgLoading[arg.IndexArgument] != null) { itemsForDelayedImgLoading[arg.IndexArgument].IconImageBig = image; } else { MPTVSeriesLog.Write(string.Format("DelayedImgLoading: Could not find item with index: {0}", arg.IndexArgument), MPTVSeriesLog.LogLevel.Debug); } } } /*if (itemsForDelayedImgLoading != null) { string image = arg.Argument as string; foreach (var item in itemsForDelayedImgLoading) { DBSeries seriesOfListItem = item.TVTag as DBSeries; if (seriesOfListItem != null && seriesOfListItem[DBSeries.cID] == arg.IndexArgument) { //MPTVSeriesLog.Write(string.Format("series:{0}, image:{1}", Helper.getCorrespondingSeries(seriesOfListItem[DBSeries.cID]).ToString(), image)); item.IconImageBig = image; break; } } }*/ PerfWatcher.GetNamedWatch("FacadeLoading addDelayedImage").Stop(); } break; case BackGroundLoadingArgumentType.ElementSelection: { // thread told us which element it'd like to select // however the user might have already started moving around // if that is the case, we don't select anything MPTVSeriesLog.Write("Element Selection: " + arg.IndexArgument.ToString(), MPTVSeriesLog.LogLevel.Debug); if (this.m_Facade != null && this.m_Facade.SelectedListItemIndex < 1) { this.m_Facade.Focus = true; this.m_Facade.SelectedListItemIndex = arg.IndexArgument; // if we are in the filmstrip/coverflow layout also send a message /*if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip || m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow) { GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_SELECT, m_Facade.WindowId, 0, m_Facade.FilmstripLayout.GetID, arg.IndexArgument, 0, null); GUIGraphicsContext.SendMessage(msg); MPTVSeriesLog.Write("Sending a selection postcard to FilmStrip/Coverflow.",MPTVSeriesLog.LogLevel.Debug); }*/ // Hack for 'set' SelectedListItemIndex not being implemented in Filmstrip/Coverflow Layout // Navigate to selected using OnAction instead if (m_Facade.CurrentLayout == GUIFacadeControl.Layout.Filmstrip || m_Facade.CurrentLayout == GUIFacadeControl.Layout.CoverFlow) { if (this.listLevel == Listlevel.Series) { List<DBSeries> seriesList = m_CurrLView.getSeriesItems(m_CurrViewStep, m_stepSelection); if (arg.IndexArgument > 0) { m_bQuickSelect = true; for (int i = m_Facade.SelectedListItemIndex; i < seriesList.Count - 1; i++) { if (i == arg.IndexArgument) break; // Now push fields to skin if (i == (arg.IndexArgument - 1)) m_bQuickSelect = false; OnAction(new Action(Action.ActionType.ACTION_MOVE_RIGHT, 0, 0)); } m_bQuickSelect = false; } else { if (seriesList.Count > 0) { GUIListItem selected = new GUIListItem(); selected.TVTag = seriesList[0]; Series_OnItemSelected(selected); } } } else if (this.listLevel == Listlevel.Season) { List<DBSeason> seasonList = m_CurrLView.getSeasonItems(m_CurrViewStep, m_stepSelection); if (arg.IndexArgument > 0) { m_bQuickSelect = true; for (int i = m_Facade.SelectedListItemIndex; i < seasonList.Count - 1; i++) { if (i == arg.IndexArgument) break; // Now push fields to skin if (i == (arg.IndexArgument - 1)) m_bQuickSelect = false; OnAction(new Action(Action.ActionType.ACTION_MOVE_RIGHT, 0, 0)); } m_bQuickSelect = false; } else { if (seasonList.Count > 0) { GUIListItem selected = new GUIListItem(); selected.TVTag = seasonList[0]; Season_OnItemSelected(selected); } } } } } } break; case BackGroundLoadingArgumentType.DelayedImgInit: itemsForDelayedImgLoading = null; break; case BackGroundLoadingArgumentType.SkipSeasonDown: SkipSeasonCode = SkipSeasonCodes.SkipSeasonDown; break; case BackGroundLoadingArgumentType.SkipSeasonUp: SkipSeasonCode = SkipSeasonCodes.SkipSeasonUp; break; case BackGroundLoadingArgumentType.SetFacadeMode: GUIFacadeControl.Layout viewMode = (GUIFacadeControl.Layout)arg.Argument; setFacadeMode(viewMode); break; } PerfWatcher.GetNamedWatch("FacadeLoading changed").Stop(); } catch (Exception ex) { MPTVSeriesLog.Write(string.Format("Error in bg_ProgressChanged: {0}: {1}", ex.Message, ex.InnerException)); MPTVSeriesLog.Write(ex.StackTrace); } }
private void bgFacadeDone(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { try { aclib.Performance.PerfWatcher.GetNamedWatch("FacadeLoading").Stop(); foreach (aclib.Performance.Watch w in aclib.Performance.PerfWatcher.InstantiatedWatches) { MPTVSeriesLog.Write(w.Info, MPTVSeriesLog.LogLevel.Debug); w.Reset(); } } catch (Exception ex) { MPTVSeriesLog.Write("Error writing performance statistics to log " + ex.InnerException); } // ZF - seems to be crashing because of facade being null sometimes, before getting inside the plugin if (m_Facade == null) return; if (e.Cancelled) { MPTVSeriesLog.Write("Background Load Facade detected cancel - performing delayed userclick"); SkipSeasonCode = SkipSeasonCodes.none; skipSeasonIfOne_DirectionDown = true; LoadFacade(); // we only cancel if the user clicked something while we were still loading // whatever was selected we will enter (this is because m_selected whatever will not get updated // even if the user selects somethign else while we wait for cancellation due to it being a different listlevel) return; } MPTVSeriesLog.Write("Background Load Facade Complete", MPTVSeriesLog.LogLevel.Debug); if (m_Facade == null) return; if (!bFacadeEmpty && m_Facade.Count == 0) { MPTVSeriesLog.Write("Facade is not suppose to be empty, retrying reload"); LoadFacade(); } if (!bFacadeEmpty && this.listLevel == Listlevel.Episode && m_Facade.Count != itemsToDisplay) { MPTVSeriesLog.Write("Facade count is not correct, retrying reload"); LoadFacade(); } if (!CheckSkinFanartSettings()) DisableFanart(); m_Facade.Focus = true; if (bFacadeEmpty) { if (m_CurrViewStep == 0) { setFacadeMode(GUIFacadeControl.Layout.List); GUIListItem item = new GUIListItem(Translation.No_items); item.IsRemote = true; this.m_Facade.Add(item); #region Clear GUI Properties clearGUIProperty(guiProperty.Title); clearGUIProperty(guiProperty.Subtitle); clearGUIProperty(guiProperty.Description); clearGUIProperty(guiProperty.SeriesBanner); clearGUIProperty(guiProperty.SeriesPoster); clearGUIProperty(guiProperty.SeasonPoster); clearGUIProperty(guiProperty.EpisodeImage); clearGUIProperty(guiProperty.Logos); clearFieldsForskin("Series"); clearFieldsForskin("Season"); clearFieldsForskin("Episode"); #endregion } else { // probably something was removed MPTVSeriesLog.Write("Nothing to display, going out"); OnAction(new Action(Action.ActionType.ACTION_PREVIOUS_MENU, 0, 0)); } } if (skipSeasonIfOne_DirectionDown && SkipSeasonCode == SkipSeasonCodes.SkipSeasonDown) { OnClicked(m_Facade.GetID, m_Facade, Action.ActionType.ACTION_SELECT_ITEM); } else if (!skipSeasonIfOne_DirectionDown && SkipSeasonCode == SkipSeasonCodes.SkipSeasonUp) { OnAction(new Action(Action.ActionType.ACTION_PREVIOUS_MENU, 0, 0)); } SkipSeasonCode = SkipSeasonCodes.none; skipSeasonIfOne_DirectionDown = true; }