From: <nor...@us...> - 2007-08-27 18:35:39
|
Revision: 866 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=866&view=rev Author: northern_sky Date: 2007-08-25 15:33:24 -0700 (Sat, 25 Aug 2007) Log Message: ----------- cleanup Modified Paths: -------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramUtils.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Properties/AssemblyInfo.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Properties/Resources.Designer.cs Added Paths: ----------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.cs Removed Paths: ------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs Deleted: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-08-25 00:37:22 UTC (rev 865) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-08-25 22:33:24 UTC (rev 866) @@ -1,1519 +0,0 @@ -#region Copyright (C) 2005-2007 Team MediaPortal - -/* - * Copyright (C) 2005-2007 Team MediaPortal - * http://www.team-mediaportal.com - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#endregion - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Threading; -using System.Xml.Serialization; -using Microsoft.DirectX; -using Microsoft.DirectX.Direct3D; -using Direct3D = Microsoft.DirectX.Direct3D; - -using MediaPortal.Configuration; -using MediaPortal.Database; -using MediaPortal.Dialogs; -using MediaPortal.GUI.Library; -using MediaPortal.GUI.View; -using MediaPortal.Profile; -using MediaPortal.Util; - -using GUIPrograms.Items; -using GUIPrograms.Database; -using GUIPrograms.Design; -using System.Data.SQLite; -using System.Data; - -namespace GUIPrograms -{ - /// <summary> - /// The GUIPrograms plugin is used to list a collection of arbitrary files - /// and use them as arguments when launching external applications. - /// </summary> - /// - public class GUIPrograms : GUIWindow, ISetupForm, IShowPlugin - { - #region defaultOverrides - /// <summary> - /// If the plugin should have its own button on the main menu of Mediaportal then it - /// should return true to this method, otherwise if it should not be on home - /// it should return false - /// </summary> - /// <param name="strButtonText">text the button should have</param> - /// <param name="strButtonImage">image for the button, or empty for default</param> - /// <param name="strButtonImageFocus">image for the button, or empty for default</param> - /// <param name="strPictureImage">subpicture for the button or empty for none</param> - /// <returns>true : plugin needs its own button on home - /// false : plugin does not need its own button on home</returns> - public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) - { - string strText = dbHandlerInstance.ReadSetting(ProgramUtils.cPLUGINTITLE); - if ((strText != "") && (strText != null)) - { - strButtonText = strText; - } - else - { - strButtonText = GUILocalizeStrings.Get(0); - } - strButtonImage = ""; - strButtonImageFocus = ""; - strPictureImage = ""; - return true; - } - - public string PluginName() - { - return "My Programs Alt. 0.1"; - } - public string Description() - { - return "Launches external applications"; - } - public string Author() - { - return "Reconstruct by Northern,Chefkoch,Org. by waebard"; - } - public void ShowPlugin() - { - SetupForm setup = new SetupForm(); - setup.ShowDialog(); - } - - // Indicates whether plugin can be enabled/disabled - public bool CanEnable() - { - return true; - } - - // get ID of windowplugin belonging to this setup - public int GetWindowId() - { - return (int)GUIWindow.Window.WINDOW_FILES; - } - - public bool DefaultEnabled() - { - return false; - } - - public bool HasSetup() - { - return true; - } - - #region IShowPlugin Members - - public bool ShowDefaultHome() - { - return false; - } - - #endregion - - #endregion defaultOverrides - - #region Serialisation - - [Serializable] - public class MapSettings - { - protected int sortMethod; - protected int viewLayout; - protected bool sortAscending; - protected int lastApplicationID; - protected int lastFileID; - protected int lastViewLevel; - protected bool overviewVisible; - - public MapSettings() - { - sortMethod = 0; //name - viewLayout = 0; //list - sortAscending = true; - overviewVisible = true; - lastApplicationID = -1; - lastFileID = -1; - lastViewLevel = 0; - } - - - [XmlElement("SortMethod")] - public int SortMethod - { - get { return sortMethod; } - set { sortMethod = value; } - } - - [XmlElement("ViewLayout")] - public int ViewLayout - { - get { return viewLayout; } - set { viewLayout = value; } - } - - [XmlElement("SortAscending")] - public bool SortAscending - { - get { return sortAscending; } - set { sortAscending = value; } - } - - [XmlElement("OverviewVisible")] - public bool OverviewVisible - { - get { return overviewVisible; } - set { overviewVisible = value; } - } - - [XmlElement("LastAppID")] - public int LastAppID - { - get { return lastApplicationID; } - set { lastApplicationID = value; } - } - - [XmlElement("LastFileID")] - public int LastFileID - { - get { return lastFileID; } - set { lastFileID = value; } - } - - [XmlElement("LastViewLevelID")] - public int LastViewLevel - { - get { return lastViewLevel; } - set { lastViewLevel = value; } - } - - - public string ViewLayoutTextName - { - get { return GetViewLayoutAsText(); } - } - - public void SwitchToNextViewLayout() - { - switch ((Layout)ViewLayout) - { - case Layout.List: - ViewLayout = (int)Layout.Icons; - - break; - case Layout.Icons: - ViewLayout = (int)Layout.LargeIcons; - - break; - case Layout.LargeIcons: - ViewLayout = (int)Layout.FilmStrip; - - break; - case Layout.FilmStrip: - ViewLayout = (int)Layout.List; - - break; - } - } - - string GetViewLayoutAsText() - { - string result = ""; - switch ((Layout)ViewLayout) - { - case Layout.List: - result = GUILocalizeStrings.Get(101); - break; - case Layout.Icons: - result = GUILocalizeStrings.Get(100); - break; - case Layout.LargeIcons: - result = GUILocalizeStrings.Get(417); - break; - case Layout.FilmStrip: - result = GUILocalizeStrings.Get(733); - break; - } - return result; - } - } - - - void SaveSettings() - { - using (Settings xmlwriter = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - switch ((Layout)mapSettings.ViewLayout) - { - case Layout.List: - xmlwriter.SetValue("myprograms", "viewLayout", "list"); - break; - case Layout.Icons: - xmlwriter.SetValue("myprograms", "viewLayout", "icons"); - break; - case Layout.LargeIcons: - xmlwriter.SetValue("myprograms", "viewLayout", "largeicons"); - break; - case Layout.FilmStrip: - xmlwriter.SetValue("myprograms", "viewLayout", "filmstrip"); - break; - } - xmlwriter.SetValue("myprograms", "lastAppID", mapSettings.LastAppID.ToString()); - // xmlwriter.SetValue("myprograms", "lastViewLevel", mapSettings.LastViewLevel.ToString()); - xmlwriter.SetValue("myprograms", "lastViewLevel", ViewHandler.CurrentLevel); - xmlwriter.SetValue("myprograms", "sortMethod", mapSettings.SortMethod); - // avoid bool conversion...... don't wanna know why it doesn't work! :-( - if (mapSettings.SortAscending) - { - xmlwriter.SetValue("myprograms", "sortASC", "yes"); - } - else - { - xmlwriter.SetValue("myprograms", "sortASC", "no"); - } - - if (mapSettings.OverviewVisible) - { - xmlwriter.SetValue("myprograms", "overviewvisible", "yes"); - } - else - { - xmlwriter.SetValue("myprograms", "overviewvisible", "no"); - } - - xmlwriter.SetValue("myprograms", "startWindow", StartWindow.ToString()); - xmlwriter.SetValue("myprograms", "startview", (int)mapSettings.ViewLayout); - } - } - - void LoadSettings() - { - slideSpeed = ProgramUtils.GetSleepTime(); - - using (Settings xmlreader = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - string curText = ""; - curText = xmlreader.GetValueAsString("myprograms", "viewLayout", "list"); - - if (curText == "list") mapSettings.ViewLayout = (int)Layout.List; - else if (curText == "icons") mapSettings.ViewLayout = (int)Layout.Icons; - else if (curText == "largeicons") mapSettings.ViewLayout = (int)Layout.LargeIcons; - else if (curText == "filmstrip") mapSettings.ViewLayout = (int)Layout.FilmStrip; - else mapSettings.ViewLayout = (int)Layout.List; - - CurrentSortMethod = (ProgramSort.SortMethod)xmlreader.GetValueAsInt("myprograms", "sortMethod", (int)ProgramSort.SortMethod.Title); - - mapSettings.LastAppID = xmlreader.GetValueAsInt("myprograms", "lastAppID", -1); - mapSettings.LastViewLevel = xmlreader.GetValueAsInt("myprograms", "lastViewLevel", -1); - mapSettings.SortAscending = xmlreader.GetValueAsBool("myprograms", "sortASC", true); - mapSettings.OverviewVisible = xmlreader.GetValueAsBool("myprograms", "sortASC", true); - - StartWindow = xmlreader.GetValueAsInt("myprograms", "startWindow", GetID); - } - } - - - void LoadLastAppIDFromSettings() - { - using (Settings xmlreader = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) - { - mapSettings.LastAppID = xmlreader.GetValueAsInt("myprograms", "lastAppID", -1); - mapSettings.LastViewLevel = xmlreader.GetValueAsInt("myprograms", "lastViewLevel", -1); - mapSettings.SortMethod = xmlreader.GetValueAsInt("myprograms", "sortMethod", 0); - mapSettings.SortAscending = xmlreader.GetValueAsBool("myprograms", "sortAsc", true); - mapSettings.OverviewVisible = xmlreader.GetValueAsBool("myprograms", "overviewvisible", true); - } - } - - void LoadFolderSettings(string directoryName) - { - if (directoryName == "") - directoryName = "root"; - object o; - FolderSettings.GetFolderSetting(directoryName, "Programs", typeof(MapSettings), out o); - if (o != null) - mapSettings = o as MapSettings; - if (mapSettings == null) - mapSettings = new MapSettings(); - } - - void SaveFolderSettings(string directoryName) - { - if (directoryName == "") - directoryName = "root"; - FolderSettings.AddFolderSetting(directoryName, "Programs", typeof(MapSettings), mapSettings); - } - - #endregion Serialisation - - #region SkinControls - - public enum Layout - { - List = 0, - Icons = 1, - LargeIcons = 2, - FilmStrip = 3, - } - - // Buttons - [SkinControl(2)] - protected GUIButtonControl btnViewAs = null; - [SkinControlAttribute(3)] - protected GUISortButtonControl btnSortBy = null; - [SkinControl(4)] - protected GUIButtonControl btnViews = null; - [SkinControl(5)] - protected GUIButtonControl btnRefresh = null; - //Images - [SkinControl(6)] - protected GUIImage screenShotImage = null; - - // FacadeView - const int facadeIDConst = 50; - [SkinControl(facadeIDConst)] - protected GUIFacadeControl facadeView = null; - - #endregion - - #region Constructor / Destructor - - public GUIPrograms() - { - dbHandlerInstance.LoadAllApplicationItems(); - globalApplicationList = dbHandlerInstance.ApplicationItemList; - GetID = (int)Window.WINDOW_FILES; - LoadSettings(); - skipInit = true; - } - - - #endregion - #region Init / DeInit - - void DeInitMyPrograms() - { - SaveSettings(); - - // make sure the selected index wasn't reseted already - // and save the index only if it's non-zero - // otherwise: DXDevice.Reset clears selection - int itemIndex = GetSelectedItemNo(); - if (itemIndex > 0) - { - selectedItemIndex = GetSelectedItemNo(); - } - - - if (dbHandlerInstance.SqlLiteConn.State == ConnectionState.Open) - { - dbHandlerInstance.SqlLiteConn.Close(); - } - } - - void InitMyPrograms() - { - LoadFolderSettings(""); - - if (skipInit) - { - mapSettings.LastAppID = -1; - } - else - { - LoadLastAppIDFromSettings(); // hacky load back the last applicationItem id, otherwise this can get lost from dx resets.... - } - lastApp = this.dbHandlerInstance.GetAppByID(mapSettings.LastAppID); - if (lastApp != null) - { - prevFilepath = lastApp.DefaultFilepath(); - this.CurrentSortAsc = mapSettings.SortAscending; - ViewHandler.CurrentLevel = mapSettings.LastViewLevel; - //lastApp.ViewHandler = this.ViewHandler; - } - else - { - prevFilepath = ""; - } - UpdateListControl(); - ShowThumbPanel(); - skipInit = false; - } - - #endregion - - #region Base & Content Variables - - - static int startWindow = (int)GUIWindow.Window.WINDOW_FILES; - protected ProgramSort.SortMethod currentSortMethod = ProgramSort.SortMethod.Title; - protected DatabaseHandler dbHandlerInstance = DatabaseHandler.DBHandlerInstance; - - bool currentSortAsc = true; - ProgramViewHandler viewHandler = ProgramViewHandler.Instance; - - List<ApplicationItem> globalApplicationList;// dbHandlerInstance.ApplicationItemList; - public MapSettings mapSettings = new MapSettings(); - DirectoryHistory itemHistory = new DirectoryHistory(); - public ApplicationItem lastApp = null; - - public string prevFilepath = ""; - public int selectedItemIndex = -1; - int slideSpeed = 3000; // speed in milliseconds between two slides - long slideTime = 0; - public Layout currentLayout = Layout.List; - - bool skipInit = false; - - static string _thumbnailPath = string.Empty; - static string _lastThumbnailPath = string.Empty; - - #endregion - - #region Properties / Helper Routines - - public ProgramViewHandler ViewHandler - { - get { return viewHandler; } - set { viewHandler = value; } - } - - public static string ThumbnailPath - { - get - { - return _thumbnailPath; - } - set - { - if (value == "") - _thumbnailPath = ""; - else if (File.Exists(value)) - _thumbnailPath = value; - } - } - - public int StartWindow - { - get { return startWindow; } - set { startWindow = value; } - } - - public virtual Layout CurrentLayout - { - get { return currentLayout; } - set { currentLayout = value; } - } - - bool CurrentSortAsc - { - get { return currentSortAsc; } - set { currentSortAsc = value; } - } - - protected virtual ProgramSort.SortMethod CurrentSortMethod - { - get { return currentSortMethod; } - set { currentSortMethod = value; } - } - - GUIListItem GetSelectedItem() - { - return facadeView.SelectedListItem; - } - - public int GetSelectedItemNo() - { - return facadeView.SelectedListItemIndex; - } - - int GetCurrentFatherID() - { - if (lastApp != null) - { - return lastApp.ApplicationItemId; - } - else - { - return -1; // root - } - } - - - bool ThereAreAppsToDisplay() - { - if (lastApp == null) - { - return true; // root has globalApplicationList - } - else - { - return lastApp.SubItemsAllowed(); // grouper items for example - } - } - - bool ThereAreFilesOrLinksToDisplay() - { - return (lastApp != null); // all globalApplicationList can have files except the root - } - - bool IsBackButtonNecessary() - { - return (lastApp != null); // always show back button except for root - } - - #endregion - - #region Overrides - - public override bool Init() - { - return Load(GUIGraphicsContext.Skin + @"\myProgramsAlt.xml"); - } - - protected override void OnPageLoad() - { - base.OnPageLoad(); - - if (btnSortBy != null) - btnSortBy.SortChanged += new SortEventHandler(SortChanged); - - InitMyPrograms(); - } - - protected override void OnPageDestroy(int newWindowId) - { - DeInitMyPrograms(); - base.OnPageDestroy(newWindowId); - } - - void SortChanged(object sender, SortEventArgs args) - { - this.CurrentSortAsc = args.Order != System.Windows.Forms.SortOrder.Descending; - - OnSort(); - UpdateButtonStates(); - } - - public override void OnAction(Action action) - { - switch (action.wID) - { - case Action.ActionType.ACTION_PARENT_DIR: - case Action.ActionType.ACTION_PREVIOUS_MENU: - // <U> keypress - BackItemClicked(); - UpdateButtonStates(); - break; - case Action.ActionType.ACTION_CLOSE_DIALOG: - SaveFolderSettings(""); - GUIWindowManager.ShowPreviousWindow(); - break; - case Action.ActionType.ACTION_SHOW_INFO: - OnInfo(); - break; - default: - base.OnAction(action); - break; - } - } - - public override bool OnMessage(GUIMessage message) - { - switch (message.Message) - { - case GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS_CHANGED: - { - int iControl = message.SenderControlId; - if (iControl == facadeView.GetID) - { - if (lastApp != null) - { - lastApp.ResetThumbs(); - } - } - } - break; - } - return base.OnMessage(message); - } - - protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) - { - base.OnClicked(controlId, control, actionType); - - if (control == btnViewAs) - { - mapSettings.SwitchToNextViewLayout(); - - - ShowThumbPanel(); - - } - else if (control == btnRefresh) - { - if (lastApp != null) - { - lastApp.Refresh(true); - prevFilepath = lastApp.DefaultFilepath(); - // todo: reset viewHandler - UpdateButtonStates(); - UpdateListControl(); - } - } - else if (control == btnViews) - { - OnShowViews(); - } - else if (control == btnSortBy) - { - OnShowSort(); - } - else if (control == facadeView) - { - // application or file-item was clicked.... - if (actionType == Action.ActionType.ACTION_SELECT_ITEM) - { - OnClick(); - } - } - } - - protected override void OnShowContextMenu() - { - GUIListItem item = facadeView.SelectedListItem; - int itemNo = facadeView.SelectedListItemIndex; - if (item == null) - return; - - GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); - if (dlg == null) - return; - dlg.Reset(); - dlg.SetHeading(498); // menu - - if (!((item.MusicTag) is ApplicationItem)) - { - dlg.AddLocalizedString(13041); //Show File Info - } - - dlg.DoModal(GetID); - if (dlg.SelectedId == -1) - return; - switch (dlg.SelectedId) - { - case 13041: // Show file info - OnInfo(); - break; - } - } - - public override void Render(float timePassed) - { - base.Render(timePassed); - - if (ThumbnailPath != _lastThumbnailPath) - { - screenShotImage.FileName = ThumbnailPath; - facadeView.FilmstripView.InfoImageFileName = ThumbnailPath; - facadeView.FilmstripView.NeedRefresh(); - - _lastThumbnailPath = ThumbnailPath; - } - RenderThumbnail(timePassed); - } - #endregion - - #region Display - - protected virtual void UpdateButtonStates() - { - string sortBy = string.Empty; - - GUIPropertyManager.SetProperty("#view", ViewHandler.LocalizedCurrentView); - - if (lastApp == null) - { - btnRefresh.IsVisible = false; - } - else - { - btnRefresh.IsVisible = lastApp.RefreshGUIAllowed; - } - - facadeView.IsVisible = true; - - GUIControl.FocusControl(GetID, facadeView.GetID); - - // display apptitle if available..... - if (lastApp != null) - { - if ((ViewHandler.CurrentView != null) && (ViewHandler.MaxLevels > 0)) - { - GUIPropertyManager.SetProperty("#curheader", ViewHandler.LocalizedCurrentView); - } - else - { - GUIPropertyManager.SetProperty("#curheader", lastApp.Title); - } - } - else - { - string strText = dbHandlerInstance.ReadSetting(ProgramUtils.cPLUGINTITLE); - if ((strText != "") && (strText != null)) - { - GUIPropertyManager.SetProperty("#curheader", strText); - } - else - { - GUIPropertyManager.SetProperty("#curheader", GUILocalizeStrings.Get(0)); - } - } - - btnViewAs.Label = mapSettings.ViewLayoutTextName; - - switch (CurrentSortMethod) - { - case ProgramSort.SortMethod.Title: - sortBy = GUILocalizeStrings.Get(268); - break; - case ProgramSort.SortMethod.Filename: - sortBy = GUILocalizeStrings.Get(363); - break; - case ProgramSort.SortMethod.Rating: - sortBy = GUILocalizeStrings.Get(367); - break; - case ProgramSort.SortMethod.LastTimeLaunched: //tmp until mapped - sortBy = "Sort by: Date launched"; - break; - case ProgramSort.SortMethod.LaunchCount: - sortBy = "Sort by: Times launchedSort by: Date launched"; //tmp - break; - case ProgramSort.SortMethod.Platform: - sortBy = "Sort by: Platform"; //tmp - break; - } - - if (btnSortBy != null) - { - btnSortBy.Label = sortBy; - btnSortBy.IsAscending = CurrentSortAsc; - } - } - - void ShowThumbPanel() - { - int itemIndex = facadeView.SelectedListItemIndex; - - switch ((Layout)mapSettings.ViewLayout) - { - case Layout.List: - facadeView.View = GUIFacadeControl.ViewMode.List; - screenShotImage.Visible = true; - break; - case Layout.Icons: - facadeView.View = GUIFacadeControl.ViewMode.SmallIcons; - screenShotImage.Visible = false; - break; - case Layout.LargeIcons: - facadeView.View = GUIFacadeControl.ViewMode.LargeIcons; - screenShotImage.Visible = false; - break; - case Layout.FilmStrip: - facadeView.View = GUIFacadeControl.ViewMode.Filmstrip; - screenShotImage.Visible = false; - break; - } - facadeView.SelectedListItemIndex = itemIndex; - UpdateButtonStates(); - } - - void RenderThumbnail(float timePassed) - { - // does the thumb needs replacing?? - long now = (DateTime.Now.Ticks / 10000); - long timeElapsed = now - slideTime; - if (timeElapsed >= (slideSpeed)) - { - RefreshThumbnail(); - // only refresh the picture, don't refresh the other data otherwise scrolling of labels is interrupted! - } - } - - void RefreshThumbnail() - { - ApplicationItem appWithImg = lastApp; - GUIListItem item = GetSelectedItem(); - - // some preconditions... - if (item == null) return; - if (appWithImg == null) - { - if (item.MusicTag == null) return; - appWithImg = item.MusicTag as ApplicationItem; - if (appWithImg == null) return; - } - - ThumbnailPath = ""; - if (item.ThumbnailImage != "" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultAlbum.png" - ) - { - // only show big thumb if there is really one.... - ThumbnailPath = appWithImg.GetCurThumb(item); // some modes look for thumbs differently - } - appWithImg.NextThumb(); // try to find a next thumbnail - slideTime = (DateTime.Now.Ticks / 10000); // reset timer! - } - - void UpdateListControl() - { - GUIControl.ClearControl(GetID, facadeView.GetID); - if (IsBackButtonNecessary()) - ProgramUtils.AddBackButton(facadeView); - - int TotalItems = 0; - if (ThereAreAppsToDisplay()) - TotalItems += DisplayApps(); - if (ThereAreFilesOrLinksToDisplay()) - TotalItems += DisplayFiles(); - - if (lastApp != null) - facadeView.Sort(new ProgramSort(CurrentSortMethod, CurrentSortAsc)); - - //set object count label - GUIPropertyManager.SetProperty("#itemcount", Utils.GetObjectCountLabel(TotalItems)); - - if (selectedItemIndex >= 0) - { - GUIControl.SelectItemControl(GetID, facadeView.GetID, selectedItemIndex); - } - SetLabels(); - } - - int DisplayFiles() - { - if (lastApp == null) return 0; - - // Refresh FileList if view has changed, while this appItem was not active - if ((lastApp.CurrentView != ViewHandler.CurrentView) || (lastApp.filesAreLoaded == false)) - { - lastApp.LoadFiles(); - lastApp.CurrentView = ViewHandler.CurrentView; - } - int totalFiles = 0; - totalFiles = totalFiles + DisplayItemList(lastApp.ItemList, facadeView); - return (totalFiles); - } - - int DisplayApps() - { - int totalApps = 0; - - foreach (ApplicationItem applicationItem in AppsOfFatherID(GetCurrentFatherID())) - { - if (!applicationItem.Enabled) continue; - - totalApps++; - GUIListItem item = new GUIListItem(applicationItem.Title); - - // check whether to use thumbsdir or not - string imgFile = String.Empty; - if (ProgramUtils.UseThumbsDir()) - imgFile = ProgramUtils.GetApplicationImage(applicationItem); - else - imgFile = applicationItem.Imagefile; - - // use skin default image if file does not exist - if (File.Exists(imgFile)) - { - item.ThumbnailImage = imgFile; - item.IconImageBig = imgFile; - item.IconImage = imgFile; - } - else - { - item.ThumbnailImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - item.IconImageBig = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - item.IconImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderNF.png"; - } - - item.MusicTag = applicationItem; - //item.IsFolder = true; // pseudo-folder.... - item.OnItemSelected += new GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(item); - } - return (totalApps); - } - - string BuildHistoryKey(ApplicationItem app, int viewLevel, string pathSub) - { - int appID; - if (app != null) - { - appID = app.ApplicationItemId; - } - else - { - appID = 1; // root - } - return String.Format("applicationItem{0}#level{1}#sub_{2}", appID, viewLevel, pathSub); - } - - public void SaveItemIndex(string value, ApplicationItem app, string pathSub) - { - string key = BuildHistoryKey(app, ViewHandler.CurrentLevel, pathSub); - itemHistory.Set(value, key); - } - - void RestoreItemIndex(ApplicationItem app, string pathSub) - { - string key = BuildHistoryKey(app, ViewHandler.CurrentLevel, pathSub); - string itemHist = itemHistory.Get(key); - if (itemHist != "") - { - int itemIndex = ProgramUtils.StringToInteger(itemHist, -1); - if ((itemIndex >= 0) && (itemIndex <= facadeView.Count - 1)) - { - GUIControl.SelectItemControl(GetID, facadeView.GetID, itemIndex); - } - } - } - - #endregion - - #region EventHandlers - - void BackItemClicked() - { - if (lastApp != null) - { - if ((prevFilepath != null) && (prevFilepath != "") && (prevFilepath != lastApp.FileDirectory)) - { - // back item in filelist clicked - prevFilepath = Path.GetDirectoryName(prevFilepath); - } - else - { - if (ViewHandler.RemoveFilterItem()) - { - FilterItem curFilter; - // force reload, this will load the next filter-level..... - lastApp.LoadFiles(); - // auto-remove filters if there is only ONE EMPTY Filteritem - // displaying - bool doAutoRemove = ((lastApp.ItemList.Count == 1) && (ViewHandler.IsFilterQuery)); - while (doAutoRemove) - { - doAutoRemove = false; - if (lastApp.ItemList[0] is FilterItem) - { - curFilter = lastApp.ItemList[0] as FilterItem; - if ((curFilter.Title == "") && (curFilter.Title2 == "")) - { - if (ViewHandler.RemoveFilterItem()) - { - lastApp.LoadFiles(); - doAutoRemove = ((lastApp.ItemList.Count == 1) && (ViewHandler.IsFilterQuery)); - } - } - } - } - } - else - { - // back item in application list clicked - // go to father item - lastApp = this.dbHandlerInstance.GetAppByID(lastApp.FatherID); - if (lastApp != null) - { - mapSettings.LastAppID = lastApp.ApplicationItemId; - prevFilepath = lastApp.DefaultFilepath(); - } - else - { - // back to home screen..... - mapSettings.LastAppID = -1; - prevFilepath = ""; - } - } - } - UpdateButtonStates(); - UpdateListControl(); - RestoreItemIndex(lastApp, prevFilepath); - } - else - { - // from root.... go back to main menu - GUIWindowManager.ShowPreviousWindow(); - } - - - } - - public List<ApplicationItem> AppsOfFatherID(int FatherID) - { - List<ApplicationItem> applicationItemList = new List<ApplicationItem>(); - - foreach (ApplicationItem curApp in globalApplicationList) - { - if (curApp.FatherID == FatherID) - { - applicationItemList.Add(curApp); - } - } - return applicationItemList; - } - - public List<ApplicationItem> AppsOfFather(ApplicationItem father) - { - if (father == null) - { - return AppsOfFatherID(-1); // return children of root node! - } - else - { - return AppsOfFatherID(father.ApplicationItemId); - } - } - - public int GetMaxPosition(int fatherID) - { - int res = 0; - foreach (ApplicationItem curApp in globalApplicationList) - { - if ((curApp.FatherID == fatherID) && (curApp.Position > res)) - { - res = curApp.Position; - } - } - return res; - } - - - - /* public ApplicationItem CloneAppItem(ApplicationItem sourceApp) - { - ApplicationItem newApp = (ApplicationItem)ItemFactory.itemFactoryInstance.GetItem(sqlDB, sourceApp.Item_Type, null, 0); - newApp.Assign(sourceApp); - newApp.ApplicationItemId = -1; // to force a sql INSERT when written - Add(newApp); - return newApp; - }*/ - - //TO DO - //Fix this method - void ScrapeFileInfo(FileItem curFile) - { - int minRelevance = 30; - bool bSuccess = false; - ScraperSaveType saveType = ScraperSaveType.DataAndImages; - GUIDialogOK dlgOk = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); - GUIDialogProgress dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS); - dlgProgress.ShowWaitCursor = false; - dlgProgress.ShowProgressBar(false); - dlgProgress.SetHeading("Lookup Gameinfo"); - dlgProgress.SetLine(1, curFile.Title); - dlgProgress.SetLine(2, curFile.Platform); - dlgProgress.SetLine(3, ""); - dlgProgress.StartModal(GetID); - // dlgProgress.SetPercentage(60); - dlgProgress.Progress(); - bSuccess = curFile.FindFileInfo(ScraperType.ALLGAME); - if ((bSuccess && curFile.FileInfoList.Count > 0) && ((FileItemInfo)(curFile.FileInfoList[0])).RelevanceNorm >= minRelevance) - { - GUIDialogSelect pDlg = (GUIDialogSelect)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_SELECT); - if (null != pDlg) - { - pDlg.Reset(); - pDlg.SetHeading("Select Title"); - foreach (FileItemInfo item in curFile.FileInfoList) - { - if (item.RelevanceNorm >= minRelevance) - { - pDlg.Add(String.Format("{0} ({1})", item.Title, item.Platform)); - } - } - pDlg.DoModal(GetID); - - // and wait till user selects one - int iSelectedGame = pDlg.SelectedLabel; - if (iSelectedGame < 0) return; - - dlgProgress.StartModal(GetID); - dlgProgress.Progress(); - dlgProgress.ShowProgressBar(false); - curFile.FileInfoFavourite = (FileItemInfo)curFile.FileInfoList[iSelectedGame]; - - curFile.FindFileInfoDetail(lastApp, curFile.FileInfoFavourite, ScraperType.ALLGAME, saveType); - if ((saveType == ScraperSaveType.DataAndImages) || (saveType == ScraperSaveType.Data)) - { - // dlgProgress.SetPercentage(60); - dlgProgress.Progress(); - curFile.SaveFromFileInfoFavourite(false); - } - // dlgProgress.SetPercentage(100); - dlgProgress.Progress(); - dlgProgress.Close(); - dlgProgress = null; - } - OnInfo(); - } - else - { - string strMsg = ""; - if (!bSuccess) - { - strMsg = "Connection failed"; - Log.Info("myPrograms: RefreshData failed"); - } - else - { - strMsg = String.Format("No match for '{0}'", curFile.Title); - Log.Info("myPrograms: No data found for '{0}'", curFile.Title); - } - if (null != dlgOk) - { - dlgOk.SetHeading(187); - dlgOk.SetLine(1, strMsg); - dlgOk.SetLine(2, String.Empty); - dlgOk.DoModal(GetID); - } - } - } - - /* protected void OnItemSelected(GUIListItem item, GUIControl parent) - { - GUIPrograms.ThumbnailPath = ""; - if (item.ThumbnailImage != "" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultAlbum.png" - ) - { - // only show big thumb if there is really one.... - GUIPrograms.ThumbnailPath = item.ThumbnailImage; - } - }*/ - - void OnItemSelected(GUIListItem item, GUIControl parent) - { - ThumbnailPath = ""; - if (item.ThumbnailImage != "" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png" - && item.ThumbnailImage != GUIGraphicsContext.Skin + @"\media\DefaultAlbum.png") - { - // only show big thumb if there is really one.... - ThumbnailPath = item.ThumbnailImage; - } - - GUIFilmstripControl filmstrip = parent as GUIFilmstripControl; - if (filmstrip != null) - { - filmstrip.InfoImageFileName = ThumbnailPath; - } - } - - void OnClick() - { - GUIListItem selectedGUIListItem = GetSelectedItem(); - - if (selectedGUIListItem.MusicTag != null) - { - object item = selectedGUIListItem.MusicTag; - - if (item is ApplicationItem) - { - - lastApp = (ApplicationItem)item; - SaveItemIndex(GetSelectedItemNo().ToString(), lastApp, lastApp.lastFilepath); - mapSettings.LastAppID = lastApp.ApplicationItemId; - prevFilepath = lastApp.DefaultFilepath(); - ViewHandler.CurrentLevel = 0; - //lastApp.ViewHandler = ViewHandler; - } - else if (item is FileItem) - { - FileItem fileItem = (FileItem)item; - selectedItemIndex = GetSelectedItemNo(); - - if (lastApp != null) - { - mapSettings.LastAppID = lastApp.ApplicationItemId; - prevFilepath = lastApp.DefaultFilepath(); - lastApp.LaunchFile(fileItem); - } - } - else if (item is FilterItem) - { - FilterItem filterItem = (FilterItem)item; - - SaveItemIndex(GetSelectedItemNo().ToString(), lastApp, prevFilepath); - ViewHandler.AddFilterItem(filterItem); - if (lastApp != null) - { - // force reload, this will load the next filter-level..... - lastApp.LoadFiles(); - } - } - - - UpdateButtonStates(); - UpdateListControl(); - } - else if (selectedGUIListItem.Label.Equals(ProgramUtils.cBackLabel)) - { // folder-item clicked.... - selectedItemIndex = -1; - BackItemClicked(); - UpdateButtonStates(); - } - } - - #region moved from BaseItem - - public int DisplayItemList(List<object> dbItems, GUIFacadeControl facadeView) - { - int totalItems = 0; - - foreach (object baseItem in dbItems) - { - totalItems = totalItems + 1; - - if (baseItem is FileItem) - { - FileItem curFile = baseItem as FileItem; - GUIListItem gli = new GUIListItem(curFile.Title); - - gli.MusicTag = curFile; - // gli.IsFolder = curFile.IsFolder; - gli.OnRetrieveArt += new MediaPortal.GUI.Library.GUIListItem.RetrieveCoverArtHandler(OnRetrieveCoverArt); - gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(gli); - } - if (baseItem is FilterItem) - { - FilterItem curFile = baseItem as FilterItem; - GUIListItem gli = new GUIListItem(curFile.Title); - gli.MusicTag = curFile; - //gli.IsFolder = false; - gli.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected); - facadeView.Add(gli); - } - } - return totalItems; - } - - protected void OnRetrieveCoverArt(GUIListItem guiListItem) - { - if (guiListItem.MusicTag == null) return; - FileItem curFileItem = (FileItem)guiListItem.MusicTag; - if (curFileItem == null) return; - - string imgFile = String.Empty; - - if (ProgramUtils.UseThumbsDir()) - imgFile = ProgramUtils.GetFileImage(lastApp, curFileItem); - else - imgFile = curFileItem.Imagefile; - - if (File.Exists(imgFile)) - { - guiListItem.ThumbnailImage = imgFile; - guiListItem.IconImageBig = imgFile; - guiListItem.IconImage = imgFile; - } - else - { - guiListItem.ThumbnailImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - guiListItem.IconImageBig = GUIGraphicsContext.Skin + @"\media\DefaultFolderBig.png"; - guiListItem.IconImage = GUIGraphicsContext.Skin + @"\media\DefaultFolderNF.png"; - } - } - - #endregion - - protected void OnShowSort() - { - GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); - if (dlg == null) - return; - dlg.Reset(); - dlg.SetHeading(495); - - - dlg.AddLocalizedString(268); // title - dlg.AddLocalizedString(363); // filename - dlg.AddLocalizedString(367); // rating - dlg.Add("Sort by: Times launched");//"LaunchCount"//whats the mapping to these??? - dlg.Add("Sort by: Date launched"); - dlg.Add("Sort by: Platform"); - - - dlg.DoModal(GetID); - - if (dlg.SelectedLabel == -1) - return; - - switch (dlg.SelectedId) - { - case 268: - CurrentSortMethod = ProgramSort.SortMethod.Title; - break; - case 363: - CurrentSortMethod = ProgramSort.SortMethod.Filename; - break; - case 367: - CurrentSortMethod = ProgramSort.SortMethod.Rating; - break; - default: - CurrentSortMethod = ProgramSort.SortMethod.Title; - break; - } - //ToDo - //tmp fix until all mappings in place. - switch (dlg.SelectedLabelText) - { - case "Sort by: Times launched": - CurrentSortMethod = ProgramSort.SortMethod.LaunchCount; - break; - case "Sort by: Date launched": - CurrentSortMethod = ProgramSort.SortMethod.LastTimeLaunched; - break; - case "Sort by: Platform": - CurrentSortMethod = ProgramSort.SortMethod.Platform; - break; - default: - break; - } - - - OnSort(); - GUIControl.FocusControl(GetID, btnSortBy.GetID); - } - - protected virtual void OnSort() - { - SetLabels(); - facadeView.Sort(new ProgramSort(CurrentSortMethod, CurrentSortAsc)); - UpdateButtonStates(); - } - - protected void OnInfo() - { - - if (lastApp == null) return; - - selectedItemIndex = GetSelectedItemNo(); - GUIListItem item = GetSelectedItem(); - FileItem curFile = null; - - if (item.Label.Equals(ProgramUtils.cBackLabel)) return; - if (item.MusicTag == null) return; - if (item.MusicTag is ApplicationItem) return; - - if (item.MusicTag is FileItem) - { - curFile = (FileItem)item.MusicTag; - GUIProgramsAltFileInfo fileInfo = (GUIProgramsAltFileInfo)GUIWindowManager.GetWindow(9999); - fileInfo.CurrentFileItem = curFile; - fileInfo.CurrentApplicationItem = lastApp; - fileInfo.FolderForThumbs = string.Empty; - GUIWindowManager.ActivateWindow(9999); - } - } - - protected void SetLabels() - { - if (facadeView != null) - { - try - { - for (int i = 0; i < facadeView.Count; ++i) - { - GUIListItem item = facadeView[i]; - ViewHandler.SetLabel(item.MusicTag as FileItem, ref item); - } - } - catch (Exception ex) - { - Log.Error("GUIMusicPlaylist: exception occured - item without Albumtag? - {0} / {1}", ex.Message, ex.StackTrace); - } - } - } - - void OnShowViews() - { - GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); - if (dlg == null) return; - dlg.Reset(); - dlg.SetHeading(499); // Actions - dlg.Add(GUILocalizeStrings.Get(100000 + GetID)); // Files - foreach (ViewDefinition view in ViewHandler.Views) - { - dlg.Add(view.LocalizedName); - } - dlg.DoModal(GetID); - if (dlg.SelectedLabel == -1) return; - if (dlg.SelectedLabel == 0) - { - int nNewWindow = (int)Window.WINDOW_FILES; - StartWindow = nNewWindow; - mapSettings.ViewLayout = (int)Layout.List; - ViewHandler.CurrentView = GUILocalizeStrings.Get(100000 + GetID);//my files - if (nNewWindow != GetID) - { - GUIWindowManager.ReplaceWindow(nNewWindow); - } - } - else - { - ViewDefinition selectedView = (ViewDefinition)ViewHandler.Views[dlg.SelectedLabel - 1]; - ViewHandler.CurrentView = selectedView.Name; - int nNewWindow = (int)Window.WINDOW_FILES; - if (GetID != nNewWindow) - { - StartWindow = nNewWindow; - if (nNewWindow != GetID) - { - GUIWindowManager.ReplaceWindow(nNewWindow); - } - } - else - { - if (facadeView.Count <= 0) - { - GUIControl.FocusControl(GetID, btnViewAs.GetID); - } - } - } - - UpdateButtonStates(); - UpdateListControl(); - } - - #endregion - } -} \ No newline at end of file Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.cs 2007-08-25 22:33:24 UTC (rev 866) @@ -0,0 +1,1496 @@ +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Threading; +using System.Xml.Serialization; +using Microsoft.DirectX; +using Microsoft.DirectX.Direct3D; +using Direct3D = Microsoft.DirectX.Direct3D; + +using MediaPortal.Configuration; +using MediaPortal.Database; +using MediaPortal.Dialogs; +using MediaPortal.GUI.Library; +using MediaPortal.GUI.View; +using MediaPortal.Profile; +using MediaPortal.Util; + +using GUIPrograms.Items; +using GUIPrograms.Database; +using GUIPrograms.Design; +using System.Data.SQLite; +using System.Data; + +namespace GUIPrograms +{ + /// <summary> + /// The GUIProgramsAlt plugin is used to list a collection of arbitrary files + /// and use them as arguments when launching external applications. + /// </summary> + /// + public class GUIProgramsAlt : GUIWindow, ISetupForm, IShowPlugin + { + + #region Serialisation + + [Serializable] + public class MapSettings + { + protected int sortMethod; + protected int viewLayout; + protected bool sortAscending; + protected int lastApplicationID; + protected int lastFileID; + protected int lastViewLevel; + protected bool overviewVisible; + + public MapSettings() + { + sortMethod = 0; //name + viewLayout = 0; //list + sortAscending = true; + overviewVisible = true; + lastApplicationID = -1; + lastFileID = -1; + lastViewLevel = 0; + } + + + [XmlElement("SortMethod")] + public int SortMethod + { + get { return sortMethod; } + set { sortMethod = value; } + } + + [XmlElement("ViewLayout")] + public int ViewLayout + { + get { return viewLayout; } + set { viewLayout = value; } + } + + [XmlElement("SortAscending")] + public bool SortAscending + { + get { return sortAscending; } + set { sortAscending = value; } + } + + [XmlElement("OverviewVisible")] + public bool OverviewVisible + { + get { return overviewVisible; } + set { overviewVisible = value; } + } + + [XmlElement("LastAppID")] + public int LastAppID + { + get { return lastApplicationID; } + set { lastApplicationID = value; } + } + + [XmlElement("LastFileID")] + public int LastFileID + { + get { return lastFileID; } + set { lastFileID = value; } + } + + [XmlElement("LastViewLevelID")] + public int LastViewLevel + { + get { return lastViewLevel; } + set { lastViewLevel = value; } + } + + + public string ViewLayoutTextName + { + get { return GetViewLayoutAsText(); } + } + + public void SwitchToNextViewLayout() + { + switch ((Layout)ViewLayout) + { + case Layout.List: + ViewLayout = (int)Layout.Icons; + + break; + case Layout.Icons: + ViewLayout = (int)Layout.LargeIcons; + + break; + case Layout.LargeIcons: + ViewLayout = (int)Layout.FilmStrip; + + break; + case Layout.FilmStrip: + ViewLayout = (int)Layout.List; + + break; + } + } + + string GetViewLayoutAsText() + { + string result = ""; + switch ((Layout)ViewLayout) + { + case Layout.List: + result = GUILocalizeStrings.Get(101); + break; + case Layout.Icons: + result = GUILocalizeStrings.Get(100); + break; + case Layout.LargeIcons: + result = GUILocalizeStrings.Get(417); + break; + case Layout.FilmStrip: + result = GUILocalizeStrings.Get(733); + break; + } + return result; + } + } + + + void SaveSettings() + { + using (Settings xmlwriter = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + switch ((Layout)mapSettings.ViewLayout) + { + case Layout.List: + xmlwriter.SetValue("myprograms", "viewLayout", "list"); + break; + case Layout.Icons: + xmlwriter.SetValue("myprograms", "viewLayout", "icons"); + break; + case Layout.LargeIcons: + xmlwriter.SetValue("myprograms", "viewLayout", "largeicons"); + break; + case Layout.FilmStrip: + xmlwriter.SetValue("myprograms", "viewLayout", "filmstrip"); + break; + } + xmlwriter.SetValue("myprograms", "lastAppID", mapSettings.LastAppID.ToString()); + // xmlwriter.SetValue("myprograms", "lastViewLevel", mapSettings.LastViewLevel.ToString()); + xmlwriter.SetValue("myprograms", "lastViewLevel", ViewHandler.CurrentLevel); + xmlwriter.SetValue("myprograms", "sortMethod", mapSettings.SortMethod); + // avoid bool conversion...... don't wanna know why it doesn't work! :-( + if (mapSettings.SortAscending) + { + xmlwriter.SetValue("myprograms", "sortASC", "yes"); + } + else + { + xmlwriter.SetValue("myprograms", "sortASC", "no"); + } + + if (mapSettings.OverviewVisible) + { + xmlwriter.SetValue("myprograms", "overviewvisible", "yes"); + } + else + { + xmlwriter.SetValue("myprograms", "overviewvisible", "no"); + } + + xmlwriter.SetValue("myprograms", "startWindow", StartWindow.ToString()); + xmlwriter.SetValue("myprograms", "startview", (int)mapSettings.ViewLayout); + } + } + + void LoadSettings() + { + slideSpeed = ProgramUtils.GetSleepTime(); + + using (Settings xmlreader = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + string curText = ""; + curText = xmlreader.GetValueAsString("myprograms", "viewLayout", "list"); + + if (curText == "list") mapSettings.ViewLayout = (int)Layout.List; + else if (curText == "icons") mapSettings.ViewLayout = (int)Layout.Icons; + else if (curText == "largeicons") mapSettings.ViewLayout = (int)Layout.LargeIcons; + else if (curText == "filmstrip") mapSettings.ViewLayout = (int)Layout.FilmStrip; + else mapSettings.ViewLayout = (int)Layout.List; + + CurrentSortMethod = (ProgramSort.SortMethod)xmlreader.GetValueAsInt("myprograms", "sortMethod", (int)ProgramSort.SortMethod.Title); + + mapSettings.LastAppID = xmlreader.GetValueAsInt("myprograms", "lastAppID", -1); + mapSettings.LastViewLevel = xmlreader.GetValueAsInt("myprograms", "lastViewLevel", -1); + mapSettings.SortAscending = xmlreader.GetValueAsBool("myprograms", "sortASC", true); + mapSettings.OverviewVisible = xmlreader.GetValueAsBool("myprograms", "sortASC", true); + + StartWindow = xmlreader.GetValueAsInt("myprograms", "startWindow", GetID); + } + } + + + void LoadLastAppIDFromSettings() + { + using (Settings xmlreader = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) + { + mapSettings.LastAppID = xmlreader.GetValueAsInt("myprograms", "lastAppID", -1); + mapSettings.LastViewLevel = xmlreader.GetValueAsInt("myprograms", "lastViewLevel", -1); + mapSettings.SortMethod = xmlreader.GetValueAsInt("myprograms", "sortMethod", 0); + mapSettings.SortAscending = xmlreader.GetValueAsBool("myprograms", "sortAsc", true); + mapSettings.OverviewVisible = xmlreader.GetValueAsBool("myprograms", "overviewvisible", true); + } + } + + void LoadFolderSettings(string directoryName) + { + if (directoryName == "") + directoryName = "root"; + object o; + FolderSettings.GetFolderSetting(directoryName, "Programs", typeof(MapSettings), out o); + if (o != null) + mapSettings = o as MapSettings; + if (mapSettings == null) + mapSettings = new MapSettings(); + } + + void SaveFolderSettings(string directoryName) + { + if (directoryName == "") + directoryName = "root"; + FolderSettings.AddFolderSetting(directoryName, "Programs", typeof(MapSettings), mapSettings); + } + + #endregion Serialisation + + + #region Variables + + static int startWindow = (int)GUIWindow.Window.WINDOW_FILES; + bool currentSortAsc = true; + // FacadeView + const int facadeIDConst = 50; + ProgramViewHandler viewHandler = ProgramViewHandler.Instance; + List<ApplicationItem> globalApplicationList;// dbHandlerInstance.ApplicationItemList; + DirectoryHistory itemHistory = new DirectoryHistory(); + int slideSpeed = 3000; // speed in milliseconds between two slides + long slideTime = 0; + bool skipInit = false; + static string _thumbnailPath = string.Empty; + static string _lastThumbnailPath = string.Empty; + + ProgramSort.SortMethod currentSortMethod = ProgramSort.SortMethod.Title; + DatabaseHandler dbHandlerInstance = DatabaseHandler.DBHandlerInstance; + + MapSettings mapSettings = new MapSettings(); + ApplicationItem lastApp = null; + string prevFilepath = ""; + int selectedItemIndex = -1; + Layout currentLayout = Layout.List; + + // Buttons + [SkinControl(2)] + protected GUIButtonControl btnViewAs = null; + [SkinControlAttribute(3)] + protected GUISortButtonControl btnSortBy = null; + [SkinControl(4)] + protected GUIButtonControl btnViews = null; + [SkinControl(5)] + protected GUIButtonControl btnRefresh = null; + //Images + [SkinControl(6)] + protected GUIImage screenShotImage = null; + + [SkinControl(facadeIDConst)] + protected GUIFacadeControl facadeView = null; + + + + #endregion Variables + + #region Enums + + public enum Layout + { + List = 0, + Icons = 1, + LargeIcons = 2, + FilmStrip = 3, + } + + #endregion Enums + + #region Constructor / Destructor + + public GUIProgramsAlt() + { + GetID = (int)Window.WINDOW_FILES; + } + + + + #endregion Constructor / Destructor + + + #region Properties / Helper Routines + + public ProgramViewHandler ViewHandler + { + get { return viewHandler; } + set { viewHandler = value; } + } + + public static string ThumbnailPath + { + get + { + return _thumbnailPath; + } + set + { + if (value == "") + _thumbnailPath = ""; + else if (File.Exists(value)) + _thumbnailPath = value; + } + } + + public int StartWindow + { + get { return startWindow; } + set { startWindow = value; } + } + + public virtual Layout CurrentLayout + { + get { return currentLayout; } + set { currentLayout = value; } + } + + bool CurrentSortAsc + { + get { return currentSortAsc; } + set { currentSortAsc = value; } + } + + protected virtual ProgramSort.SortMethod CurrentSortMethod + { + get { return currentSortMethod; } + set { currentSortMethod = value; } + } + + GUIListItem GetSelectedItem() + { + return facadeView.SelectedListItem; + } + + public int GetSelectedItemNo() + { + return facadeView.SelectedListItemIndex; + } + + int GetCurrentFatherID() + { + if (lastApp != null) + { + return lastApp.ApplicationItemId; + } + else + { + return -1; // root + } + } + + + bool ThereAreAppsToDisplay() + { + if (lastApp == null) + { + return true; // root has globalApplicationList + } + else + { + return lastApp.SubItemsAllowed(); // grouper items for example + } + } + + bool ThereAreFilesOrLinksToDisplay() + { + return (lastApp != null); // all globalApplicationList can have files except the root + } + + bool IsBackButtonNecessary() + { + return (lastApp != null); // always show back button except for root + } + + #endregion + + #region Private Methods + + void InitGUIProgramsAlt() + { + dbHandlerInstance.LoadAllApplicationItems(); + globalApplicationList = dbHandlerInstance.ApplicationItemList; + LoadSettings(); + skipInit = true; + } + + void SortChanged(object sender, SortEventArgs args) + { + this.CurrentSortAsc = args.Order != System.Windows.Forms.SortOrder.Descending; + SortItems(); + UpdateButtonStates(); + } + + void UpdateButtonStates() + { + string sortBy = string.Empty; + + GUIPropertyManager.SetProperty("#view", ViewHandler.LocalizedCurrentView); + + if (lastApp == null) + { + btnRefresh.IsVisible = false; + } + else + { + btnRefresh.IsVisible = lastApp.RefreshGUIAllowed; + } + + facadeView.IsVisible = true; + + GUIControl.FocusControl(GetID, facadeView.GetID); + + // di... [truncated message content] |