From: <fr...@us...> - 2007-02-02 17:35:39
|
Revision: 82 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=82&view=rev Author: framug Date: 2007-02-02 09:35:27 -0800 (Fri, 02 Feb 2007) Log Message: ----------- Add My Recipes Was removed from MP, check //fmu Added Paths: ----------- trunk/plugins/My Recipes/ trunk/plugins/My Recipes/CatReader.cs trunk/plugins/My Recipes/GUIRecipes.cs trunk/plugins/My Recipes/My Recipes.csproj trunk/plugins/My Recipes/My Recipes.sln trunk/plugins/My Recipes/My Recipes.suo trunk/plugins/My Recipes/Properties/ trunk/plugins/My Recipes/Properties/AssemblyInfo.cs trunk/plugins/My Recipes/Recipe.cs trunk/plugins/My Recipes/RecipeDatabase.cs trunk/plugins/My Recipes/RecipePrinter.cs trunk/plugins/My Recipes/RecipeReader.cs trunk/plugins/My Recipes/SetupForm.cs trunk/plugins/My Recipes/SetupForm.resx Added: trunk/plugins/My Recipes/CatReader.cs =================================================================== --- trunk/plugins/My Recipes/CatReader.cs (rev 0) +++ trunk/plugins/My Recipes/CatReader.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005 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 + * + */ + +using System; +using System.Collections; +using System.IO; +using MediaPortal.GUI.Library; + +namespace GUIRecipes { + /// <summary> + /// Summary description for CatReader. + /// </summary> + public class CatReader { + + protected string cFileName; + + public int CatCount { + get { return catCount; } + } + + protected int catCount = 0; + + public CatReader( string fileName ) { + cFileName = fileName; + } + + public void GetCategories() { + StreamReader reader = new StreamReader( cFileName, System.Text.Encoding.Default ); + string line = reader.ReadLine(); + bool maincat=false; + bool sorts=false; + string content=""; + int num=0; + + while( line != null ) { + if (line.Trim().StartsWith( "#Main" )) { + maincat=true; + sorts=false; + line = reader.ReadLine(); + } + if (line.Trim().StartsWith( "#Sorts" )) { + sorts=true; + maincat=false; + line = reader.ReadLine(); + } + + string[] lines = line.Split( ';' ); + int l=0; + foreach( string lin in lines ) { + if (l==1) { + content=lin.Trim(); + l++; + } + if (l==0) { + num=Convert.ToInt16(lin); + l++; + } + } + if (maincat==true) { + catCount++; + RecipeDatabase.GetInstance().AddMainCat( content.TrimEnd(), num,0); + } + if (sorts==true) { + catCount++; + RecipeDatabase.GetInstance().AddMainCat( content.TrimEnd(), 0, num); + } + line = reader.ReadLine(); + } + reader.Close(); + } + } +} Added: trunk/plugins/My Recipes/GUIRecipes.cs =================================================================== --- trunk/plugins/My Recipes/GUIRecipes.cs (rev 0) +++ trunk/plugins/My Recipes/GUIRecipes.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,644 @@ +#region Copyright (C) 2005-2006 Team MediaPortal + +/* + * Copyright (C) 2005-2006 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 + +#region Usings +using System; +using System.Collections; +using System.Windows.Forms; +using MediaPortal.GUI.Library; +using MediaPortal.Dialogs; + +#endregion + +namespace GUIRecipes +{ + /// <summary> + /// Summary description for GUIRecipes. + /// </summary> + public class GUIRecipes : GUIWindow, ISetupForm, IShowPlugin + { + #region Private Enumerations + enum Controls + { + CONTROL_BACKBUTTON = 2, + CONTROL_SEARCH_TYP = 3, + CONTROL_SEARCH_TOG = 4, + CONTROL_SEARCH = 5, + CONTROL_FAVOR = 6, + CONTROL_DELETE = 7, + CONTROL_PRINT = 8, + CONTROL_SPIN = 9, + CONTROL_LIST = 10, + CONTROL_TEXTBOX = 11 + }; + #endregion + + #region Base variabeles + + Recipe rec = new Recipe(); + RecipePrinter rp = new RecipePrinter(); + string subcatstr = "";// contains actual subcategorie + string catstr = ""; // contains actual categorie + string titstr = ""; // contains actual title of recipe + string seastr = ""; // contains actual search string + bool search = false; // was search mode the last menu? + bool online = false; // online recipe update? + bool subcat = false; // show subcategories ? + + enum States + { + STATE_MAIN = 0, + STATE_CATEGORY = 1, + STATE_Recipe = 2, + STATE_SUB = 3, + STATE_FAVORITES = 4 + }; + + enum Search_Types + { + SEARCH_TITLE = 0, + SEARCH_Recipe = 1 + }; + + private States currentState = States.STATE_MAIN; + private Search_Types currentSearch = Search_Types.SEARCH_TITLE; + + #endregion + + #region Constructor + public GUIRecipes() + { + // + // TODO: Add constructor logic here + // + } + + #endregion + + #region ISetupForm + + public string PluginName() + { + return "My Recipes"; + } + + public string Description() + { + return "Browse your cooking recipes with MediaPortal"; + } + + public string Author() + { + return "Gucky62/Domi_fan"; + } + + public void ShowPlugin() + { + SetupForm form = new SetupForm(); + + form.ShowDialog(); + } + + public bool DefaultEnabled() + { + return false; + } + + public bool CanEnable() + { + return true; + } + + public bool HasSetup() + { + return true; + } + + public int GetWindowId() + { + return 750; + } + + /// <summary> + /// If the plugin should have its own button on the home screen 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) + { + + strButtonText = GUILocalizeStrings.Get(10); + strButtonImage = ""; + strButtonImageFocus = ""; + strPictureImage = @"hover_my recipes.png"; + return true; + } + + #endregion + + #region IShowPlugin Members + + public bool ShowDefaultHome() + { + return false; + } + + #endregion + + #region Overides + /// <summary> + /// Return the id of this window + /// </summary> + public override int GetID + { + get { return 750; } + set { base.GetID = value; } + } + + /// <summary> + /// Gets called by the runtime when a new window has been created + /// Every window window should override this method and load itself by calling + /// the Load() method + /// </summary> + /// <returns></returns> + public override bool Init() + { + LoadSettings(); + return Load(GUIGraphicsContext.Skin + @"\myrecipes.xml"); + } + + public override void OnAction(Action action) + { + if (action.wID == Action.ActionType.ACTION_PREVIOUS_MENU) + { + GUIWindowManager.ShowPreviousWindow(); + return; + } + if (action.wID == Action.ActionType.ACTION_KEY_PRESSED) + { + if (action.m_key.KeyChar == 89 || action.m_key.KeyChar == 121) + { + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + if (item != null) + { + if (item.Label.Length > 1) RecipeDatabase.GetInstance().AddFavorite(item.Label); + } + } + return; + } + if (action.wID == Action.ActionType.ACTION_QUEUE_ITEM) // add recipe to favorites + { + if (currentState == States.STATE_Recipe) + { + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + if (item != null) + { + if (item.Label.Length > 1) RecipeDatabase.GetInstance().AddFavorite(item.Label); + } + } + return; + } + if (action.wID == Action.ActionType.ACTION_DELETE_ITEM) + { + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + if (item != null) + { + GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); + if (null != dlgYesNo) + { + titstr = item.Label; + dlgYesNo.SetLine(1, ""); + dlgYesNo.SetLine(2, ""); + if (currentState == States.STATE_Recipe || currentState == States.STATE_CATEGORY) + { + dlgYesNo.SetHeading(GUILocalizeStrings.Get(2049)); + dlgYesNo.SetLine(1, titstr); + } + if (currentState == States.STATE_MAIN) + { + dlgYesNo.SetHeading(GUILocalizeStrings.Get(2050)); + dlgYesNo.SetLine(1, titstr); + } + if (currentState == States.STATE_FAVORITES) + { + dlgYesNo.SetHeading(GUILocalizeStrings.Get(933)); + dlgYesNo.SetLine(1, titstr); + } + dlgYesNo.DoModal(GetID); + + if (dlgYesNo.IsConfirmed) + { + switch (currentState) + { + case States.STATE_FAVORITES: + { + RecipeDatabase.GetInstance().DeleteFavorite(titstr); + ArrayList recipes = RecipeDatabase.GetInstance().GetRecipesForFavorites(); + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + currentState = States.STATE_FAVORITES; + UpdateButtons(); + } + break; + case States.STATE_CATEGORY: + case States.STATE_Recipe: + { + RecipeDatabase.GetInstance().DeleteRecipe(titstr); + currentState = States.STATE_CATEGORY; + UpdateButtons(); + ArrayList recipes = RecipeDatabase.GetInstance().GetRecipesForCategory(catstr); + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + } + break; + case States.STATE_MAIN: + { + } + break; + } + } + } + } + } + base.OnAction(action); + } + + public override bool OnMessage(GUIMessage message) + { + switch (message.Message) + { + case GUIMessage.MessageType.GUI_MSG_WINDOW_INIT: + base.OnMessage(message); + GUISpinControl cntlYieldInterval = GetControl((int)Controls.CONTROL_SPIN) as GUISpinControl; + if (cntlYieldInterval != null) + { + for (int i = 1; i <= 24; i++) cntlYieldInterval.AddLabel("", i); + cntlYieldInterval.Value = 1; + } + LoadAllCategories(); + currentState = States.STATE_MAIN; + UpdateButtons(); + return true; + case GUIMessage.MessageType.GUI_MSG_CLICKED: + int iControl = message.SenderControlId; + if (iControl == (int)Controls.CONTROL_SPIN) + { // Yield Calculator + if (currentState == States.STATE_Recipe) + { + GUISpinControl cntlYieldInt = GetControl((int)Controls.CONTROL_SPIN) as GUISpinControl; + int iInterval = (cntlYieldInt.Value) + 1; + rec.CYield = iInterval; + ShowDetails(rec); + UpdateButtons(); + } + } + else if (iControl == (int)Controls.CONTROL_SEARCH_TYP) + { // Select type of search + GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_SELECTED, GetID, 0, iControl, 0, 0, null); + OnMessage(msg); + switch (currentSearch) + { + case Search_Types.SEARCH_Recipe: // search by title + currentSearch = Search_Types.SEARCH_TITLE; + break; + case Search_Types.SEARCH_TITLE: // search by recipe + currentSearch = Search_Types.SEARCH_Recipe; + break; + } + UpdateButtons(); + GUIControl.FocusControl(GetID, iControl); + } + else if (iControl == (int)Controls.CONTROL_LIST) // Click on Control_List ? + { + GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_SELECTED, GetID, 0, iControl, 0, 0, null); + OnMessage(msg); + int iItem = (int)msg.Param1; + int iAction = (int)message.Param1; + if (iAction == (int)Action.ActionType.ACTION_SELECT_ITEM && iItem != -1) + { + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + if (currentState == States.STATE_CATEGORY || currentState == States.STATE_FAVORITES) // show recipe details + { + if (item.Label != GUILocalizeStrings.Get(2054)) + { + rec = RecipeDatabase.GetInstance().GetRecipe(item.Label); + titstr = item.Label; + GUISpinControl cntlYieldInt = GetControl((int)Controls.CONTROL_SPIN) as GUISpinControl; + cntlYieldInt.Value = rec.CYield; + ShowDetails(rec); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + currentState = States.STATE_Recipe; + UpdateButtons(); + } + } + else if (currentState == States.STATE_MAIN) + { // show category + // show list of items + ArrayList recipes; + if (subcat == true) + { + recipes = RecipeDatabase.GetInstance().GetSubsForCategory(item.Label); + currentState = States.STATE_SUB; + subcatstr = item.Label; + } + else + { + recipes = RecipeDatabase.GetInstance().GetRecipesForCategory(item.Label); + currentState = States.STATE_CATEGORY; + catstr = item.Label; + } + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + UpdateButtons(); + } + else if (currentState == States.STATE_SUB) + { // show category + // show list of items + ArrayList recipes = RecipeDatabase.GetInstance().GetRecipesForCategory(item.Label); + currentState = States.STATE_CATEGORY; + catstr = item.Label; + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + UpdateButtons(); + } + } + } + else if (iControl == (int)Controls.CONTROL_BACKBUTTON) + { // click on Backbutton + if (currentState == States.STATE_Recipe) + { // back from recipe detail + currentState = States.STATE_CATEGORY; + UpdateButtons(); + if (search == true) + { + byte styp = 0; + if (currentSearch == Search_Types.SEARCH_Recipe) styp = 0; + if (currentSearch == Search_Types.SEARCH_TITLE) styp = 1; + ArrayList recipes = RecipeDatabase.GetInstance().SearchRecipes(seastr, styp); + UpDateList(recipes); + } + else + { + ArrayList recipes = RecipeDatabase.GetInstance().GetRecipesForCategory(catstr); + UpDateList(recipes); + } + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + } + else if (currentState == States.STATE_CATEGORY || currentState == States.STATE_FAVORITES) + { + search = false; + if (subcat == true) + { + currentState = States.STATE_SUB; + // show list of items + ArrayList recipes = RecipeDatabase.GetInstance().GetSubsForCategory(subcatstr); + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + UpdateButtons(); + } + else + { + currentState = States.STATE_MAIN; + LoadAllCategories(); + } + UpdateButtons(); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_LIST); + } + else if (currentState == States.STATE_SUB) + { + currentState = States.STATE_MAIN; + LoadAllCategories(); + UpdateButtons(); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_LIST); + } + } + else if (iControl == (int)Controls.CONTROL_SEARCH) // click on Search Button + { + int activeWindow = (int)GUIWindowManager.ActiveWindow; + + //fmu VirtualSearchKeyboard keyBoard = (VirtualSearchKeyboard)GUIWindowManager.GetWindow(1001); + //fmu keyBoard.Text = ""; + //fmu keyBoard.Reset(); + //fmu keyBoard.TextChanged += new MediaPortal.Dialogs.VirtualSearchKeyboard.TextChangedEventHandler(keyboard_TextChanged); // add the event handler + //fmu keyBoard.DoModal(activeWindow); // show it... + //fmu keyBoard.TextChanged -= new MediaPortal.Dialogs.VirtualSearchKeyboard.TextChangedEventHandler(keyboard_TextChanged); // remove the handler + //fmu seastr = keyBoard.Text; + + VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); + keyboard.Text = ""; + keyboard.Reset(); + keyboard.TextChanged += new MediaPortal.Dialogs.VirtualKeyboard.TextChangedEventHandler(keyboard_TextChanged); // add the event handler + keyboard.DoModal(activeWindow); // show it... + keyboard.TextChanged -= new MediaPortal.Dialogs.VirtualKeyboard.TextChangedEventHandler(keyboard_TextChanged); // remove the handler + seastr = keyboard.Text; + + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + byte styp = 0; + if (currentSearch == Search_Types.SEARCH_Recipe) styp = 0; + if (currentSearch == Search_Types.SEARCH_TITLE) styp = 1; + search = true; + ArrayList recipes = RecipeDatabase.GetInstance().SearchRecipes(seastr, styp); + UpDateList(recipes); + currentState = States.STATE_CATEGORY; + UpdateButtons(); + } + else if (iControl == (int)Controls.CONTROL_FAVOR) // click on Favorites + { + // show list of items + GUIListItem item = GUIControl.GetSelectedListItem(GetID, (int)Controls.CONTROL_LIST); + ArrayList recipes = RecipeDatabase.GetInstance().GetRecipesForFavorites(); + UpDateList(recipes); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + currentState = States.STATE_FAVORITES; + UpdateButtons(); + } + else if (iControl == (int)Controls.CONTROL_DELETE) // click on delete button + { + Action action = new Action(Action.ActionType.ACTION_DELETE_ITEM, 0, 0); + OnAction(action); + } + else if (iControl == (int)Controls.CONTROL_PRINT) + { // click on Print button + if (currentState == States.STATE_Recipe) + { + rp.printRecipe(rec, catstr, titstr); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + } + } + break; + } + return base.OnMessage(message); + } + #endregion + + #region Private Methods + //loads list control with new values + void UpDateList(ArrayList recipes) + { + GUIControl.ClearControl(GetID, (int)Controls.CONTROL_LIST); + if (recipes.Count > 0) + { + foreach (Recipe r in recipes) + { + GUIListItem gli = new GUIListItem(r.Title); + GUIControl.AddListItemControl(GetID, (int)Controls.CONTROL_LIST, gli); + } + } + else + { + GUIListItem gli = new GUIListItem(GUILocalizeStrings.Get(2054)); + GUIControl.AddListItemControl(GetID, (int)Controls.CONTROL_LIST, gli); + } + string strObjects = String.Format("{0} {1}", recipes.Count, GUILocalizeStrings.Get(632)); + GUIPropertyManager.SetProperty("#itemcount", strObjects); + } + + + void UpdateButtons() + { + string strLine = ""; + switch (currentSearch) + { + case Search_Types.SEARCH_Recipe: + strLine = GUILocalizeStrings.Get(2052); + break; + case Search_Types.SEARCH_TITLE: + strLine = GUILocalizeStrings.Get(2051); + break; + } + GUIControl.SetControlLabel(GetID, (int)Controls.CONTROL_SEARCH_TYP, strLine); + switch (currentState) + { + case States.STATE_MAIN: + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.ShowControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_DELETE); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_PRINT); + break; + case States.STATE_FAVORITES: + case States.STATE_CATEGORY: + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.ShowControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_DELETE); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_PRINT); + break; + case States.STATE_SUB: + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.HideControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.ShowControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.FocusControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_DELETE); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_PRINT); + break; + case States.STATE_Recipe: + GUIControl.HideControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.DisableControl(GetID, (int)Controls.CONTROL_LIST); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.ShowControl(GetID, (int)Controls.CONTROL_TEXTBOX); + GUIControl.ShowControl(GetID, (int)Controls.CONTROL_SPIN); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_DELETE); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_BACKBUTTON); + GUIControl.EnableControl(GetID, (int)Controls.CONTROL_PRINT); + break; + } + } + + /// <summary> + /// Loads my status settings from the profile xml. + /// </summary> + /// + private void LoadSettings() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) + { + subcat = xmlreader.GetValueAsBool("recipe", "subcats", false); + online = xmlreader.GetValueAsBool("recipe", "online", false); + } + } + + private void ShowDetails(Recipe rec) // show recipe directions + { + GUITextControl control = (GUITextControl)this.GetControl((int)Controls.CONTROL_TEXTBOX); + control.OnMessage(new GUIMessage(GUIMessage.MessageType.GUI_MSG_LABEL_RESET, GetID, 0, (int)Controls.CONTROL_TEXTBOX, 0, 0, null)); + + GUIControl.SetControlLabel(GetID, (int)Controls.CONTROL_TEXTBOX, rec.ToString()); + GUIPropertyManager.SetProperty("#itemcount", " "); + } + + void keyboard_TextChanged(int kindOfSearch, string data) + { + // + } + + private void LoadAllCategories() // show all categories + { + ArrayList recipes; + GUIControl.ClearControl(GetID, (int)Controls.CONTROL_LIST); + if (subcat == true) + { + recipes = RecipeDatabase.GetInstance().GetMainCategories(); + } + else + { + recipes = RecipeDatabase.GetInstance().GetCategories(); + } + foreach (string cat in recipes) + { + GUIListItem gli = new GUIListItem(cat); + GUIControl.AddListItemControl(GetID, (int)Controls.CONTROL_LIST, gli); + } + string strObjects = String.Format("{0} {1}", recipes.Count, GUILocalizeStrings.Get(632)); + GUIPropertyManager.SetProperty("#itemcount", strObjects); + } + #endregion + + + + } +} Added: trunk/plugins/My Recipes/My Recipes.csproj =================================================================== --- trunk/plugins/My Recipes/My Recipes.csproj (rev 0) +++ trunk/plugins/My Recipes/My Recipes.csproj 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,79 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{44E2881F-457F-4CD9-969F-ECC0981FA0B2}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>GUIRecipes</RootNamespace> + <AssemblyName>My Recipes</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Core, Version=1.0.2589.32413, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath> + </Reference> + <Reference Include="Databases, Version=1.0.2589.32414, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Databases\bin\Release\Databases.dll</HintPath> + </Reference> + <Reference Include="Dialogs, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Dialogs\bin\Release\Dialogs.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=1.0.2589.32412, Culture=neutral, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="CatReader.cs" /> + <Compile Include="GUIRecipes.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Recipe.cs" /> + <Compile Include="RecipeDatabase.cs" /> + <Compile Include="RecipePrinter.cs" /> + <Compile Include="RecipeReader.cs" /> + <Compile Include="SetupForm.cs"> + <SubType>Form</SubType> + </Compile> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="SetupForm.resx"> + <DependentUpon>SetupForm.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: trunk/plugins/My Recipes/My Recipes.sln =================================================================== --- trunk/plugins/My Recipes/My Recipes.sln (rev 0) +++ trunk/plugins/My Recipes/My Recipes.sln 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C# Express 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "My Recipes", "My Recipes.csproj", "{44E2881F-457F-4CD9-969F-ECC0981FA0B2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {44E2881F-457F-4CD9-969F-ECC0981FA0B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {44E2881F-457F-4CD9-969F-ECC0981FA0B2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {44E2881F-457F-4CD9-969F-ECC0981FA0B2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {44E2881F-457F-4CD9-969F-ECC0981FA0B2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal Added: trunk/plugins/My Recipes/My Recipes.suo =================================================================== (Binary files differ) Property changes on: trunk/plugins/My Recipes/My Recipes.suo ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/My Recipes/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/My Recipes/Properties/AssemblyInfo.cs (rev 0) +++ trunk/plugins/My Recipes/Properties/AssemblyInfo.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("My Recipes")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("My Recipes")] +[assembly: AssemblyCopyright("Copyright © 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4c9ea42f-aeab-4c44-ab0d-af3adc79d8a5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Added: trunk/plugins/My Recipes/Recipe.cs =================================================================== --- trunk/plugins/My Recipes/Recipe.cs (rev 0) +++ trunk/plugins/My Recipes/Recipe.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2005 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 + * + */ + +using System; +using System.Collections; +using MediaPortal.GUI.Library; +namespace GUIRecipes +{ + /// <summary> + /// Summary description for Recipe. + /// </summary> + public class Recipe { + string mId; + string mTitle; + int mCYield; + ArrayList mCategories; + string mYield; + ArrayList mIngredients = new ArrayList(); + ArrayList mLot = new ArrayList(); + ArrayList mUnit = new ArrayList(); + ArrayList mRemarks = new ArrayList(); + string mDirections; + + public Recipe(){ + // + // TODO: Add constructor logic here + // + } + + public string Title { + get{ return mTitle; } + set{ mTitle = value; } + } + + public string Id { + get { return mId; } + set { mId = value; } + } + + public ArrayList Categories { + get{ return mCategories; } + set{ mCategories = value; } + } + + public void SetCategories( string Categories) { + mCategories = new ArrayList( Categories.Split( ',' ) ); + } + + public string Yield { + get{ return mYield; } + set{ mYield = value; } + } + + public int CYield { + get{ return mCYield; } + set{ mCYield = value; } + } + + public string Directions { + get{ return mDirections; } + set{ mDirections = value; } + } + + public ArrayList Ingredients { + get{ return mIngredients; } + set{ mIngredients = value; } + } + + public ArrayList Lot { + get{ return mLot; } + set{ mLot = value; } + } + + public ArrayList Unit { + get{ return mUnit; } + set{ mUnit = value; } + } + + public ArrayList Remarks { + get{ return mRemarks; } + set{ mRemarks = value; } + } + + public void AddIngredient( string ing ) { + Ingredients.Add( ing ); + } + + public void AddLot( string lot ) { + Lot.Add( lot ); + } + + public void AddUnit( string unit ) { + Unit.Add( unit ); + } + + public void AddRemarks( string rem ) { + Remarks.Add( rem ); + } + + public override string ToString() + { + int sunit=0; + double dsunit=0.0; + double dilot=0.0; + string s1 = ""; + string stunit = ""; + try { + if (CYield <= 1) { + stunit=Yield; + } else { + stunit=Yield.Trim(); + string[] s2 = stunit.Split( ' ' ); + dsunit=Convert.ToDouble(s2[0]); + stunit=Convert.ToString(CYield); + } + } + catch (Exception ) { + stunit=Yield; + dsunit=1.0; + } + string retval = String.Format("{0}: {1}\n{2}: {3}\n\n{4}:\n", + GUILocalizeStrings.Get(2006),Title, + GUILocalizeStrings.Get(2007),stunit, + GUILocalizeStrings.Get(2008)); + + for( int i=0; i < Ingredients.Count; i++ ) { + sunit=Convert.ToInt16(Unit[i]); + if (sunit > 10) { + stunit=GUILocalizeStrings.Get(sunit)+" "; + } else { + stunit=""; + } + s1=(string)Lot[i]; + s1=s1.Trim(); + if (s1!="") { + try { + if (CYield > 1) { + string SLot=(string)Lot[i]; + SLot=SLot.Trim(); + if (SLot.IndexOf("/",0) > 0) { + int l = SLot.IndexOf("/",0); + string b = SLot.Substring(l-1,3); + double x=0.0; + double y=0.0; + if (l>2) { + int k=SLot.IndexOf(" ",0); + y=Convert.ToDouble(SLot.Substring(0,k)); + } + switch (b) { + case "1/2" : // 1/2 + x=(y+0.5)/dsunit; + x=x*(double)CYield; + break; + case "1/4" : // 1/4 + x=(y+0.25)/dsunit; + x=x*(double)CYield; + break; + case "1/8" : // 1/8 + x=(y+0.125)/dsunit; + x=x*(double)CYield; + break; + case "3/8" : // 3/8 + x=(y+0.375)/dsunit; + x=x*(double)CYield; + break; + case "3/4" : // 3/4 + x=(y+0.75)/dsunit; + x=x*(double)CYield; + break; + } + s1=String.Format("{0:0.##} ",x); + } else { + dilot=Convert.ToDouble(Lot[i]); + dilot=dilot/dsunit; + dilot=dilot*(double)CYield; + s1=String.Format("{0:0.##} ",dilot); + } + } else s1=s1+" "; + } + catch (Exception ) { + s1=(string)Lot[i]; + s1=s1+" "; + } + } + if (i+1 < Ingredients.Count) { + if (Convert.ToInt16(Unit[i+1]) == 1) { // Line Break with "-" in first char + retval = retval + " " + s1 + stunit + Ingredients[i]+ Ingredients[i+1]+"\n"; + i++; + } else { + if (sunit == 2) { // Subtitle + retval = retval + "\n" + Ingredients[i]+ "\n";; + } else { // Normal Ingredients + retval = retval + " " + s1 + stunit + Ingredients[i]+ "\n";; + } + } + } else { + retval = retval + " " + s1 + stunit + Ingredients[i]+ "\n";; + } + } + retval = retval + String.Format("\n{0}:\n{1}",GUILocalizeStrings.Get(2009), Directions) ; + return retval; + } + } +} Added: trunk/plugins/My Recipes/RecipeDatabase.cs =================================================================== --- trunk/plugins/My Recipes/RecipeDatabase.cs (rev 0) +++ trunk/plugins/My Recipes/RecipeDatabase.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,385 @@ +/* + * Copyright (C) 2005 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 + * + */ + +using System.Collections; +using System.Windows.Forms; +using SQLite.NET; +using MediaPortal.GUI.Library; +using System; + +namespace GUIRecipes +{ + /// <summary> + /// Summary description for RecipeDatabase. + /// </summary> + public class RecipeDatabase + { + public enum M_Keys { + VERSION = 1, + ONLINE = 2, + O_NAME = 3, + O_PASS = 4, + SUB_CAT = 5 + } + + private int m_key=0; + private string m_content; + private int m_var1=0; + private int m_var2=0; + + public int M_Key { + get { return m_key; } + set { m_key = value; } + } + + public string M_Content { + get { return m_content; } + set { m_content = value; } + } + + public int M_Var1 { + get { return m_var1; } + set { m_var1 = value; } + } + + public int M_Var2 { + get { return m_var2; } + set { m_var2 = value; } + } + + private static RecipeDatabase instance=null; + private SQLiteClient m_db; + private bool dbExists; + + private RecipeDatabase() { + try { + // Open database + try + { + System.IO.Directory.CreateDirectory("database"); + } + catch(Exception){} + dbExists = System.IO.File.Exists( @"database\RecipeDatabaseV3.db3" ); + m_db = new SQLiteClient(@"database\RecipeDatabaseV3.db3"); + + MediaPortal.Database.DatabaseUtility.SetPragmas(m_db); + if( !dbExists ){ + CreateTables(); + } + } catch (SQLiteException ex){ + Console.Write("Recipedatabase exception err:{0} stack:{1}", ex.Message,ex.StackTrace); + } + } + + public static RecipeDatabase GetInstance() { + if( instance == null ) { + instance = new RecipeDatabase(); + } + return instance; + } + + private void CreateTables(){ + if( m_db == null ){ + return; + } + m_db.Execute("CREATE TABLE Recipe ( Recipe_ID integer primary key, TITLE text, YIELD text, DIRECTIONS text, VOTE text, VERSION integer)\n"); + m_db.Execute("CREATE TABLE INGREDIENT ( INGREDIENT_ID integer primary key, Recipe_ID integer, TITLE text, LOT text, UNIT text)\n"); + m_db.Execute("CREATE TABLE CATEGORY ( CATEGORY_ID integer primary key, TITLE text)\n" ); + m_db.Execute("CREATE TABLE Recipe_CATEGORY( Recipe_CATEGORY_ID integer primary key, CATEGORY_ID integer, Recipe_ID integer, TITLE text)\n" ); + m_db.Execute("CREATE TABLE FAVORITE ( CATEGORY_ID integer primary key, TITLE text)\n" ); + m_db.Execute("CREATE TABLE MAIN_CATEGORY ( CATEGORY_ID integer primary key, TITLE text, NUM integer, SUB integer)\n" ); + m_db.Execute("CREATE TABLE MAINTENANCE ( ID integer primary key, KEY integer, CONTENT text, VAR1 integer, VAR2 integer)\n" ); + m_db.Execute("CREATE TABLE DELETE ( ID integer primary key, STAT integer)\n" ); + AddMaintenance((int)M_Keys.ONLINE, "Init", 0,0); + AddMaintenance((int)M_Keys.SUB_CAT, "Init", 0,0); + AddMaintenance((int)M_Keys.VERSION, "Version", 0,3); + } + + private void BuildMaintenance(ArrayList row) { + if (row!=null) { + IEnumerator en = row.GetEnumerator(); + en.MoveNext(); + string Id = (string) en.Current; + en.MoveNext(); + M_Key = (int) en.Current; + en.MoveNext(); + M_Content=(string)en.Current; + en.MoveNext(); + M_Var1=(int)en.Current; + en.MoveNext(); + M_Var2=(int)en.Current; + } + } + + public bool CheckKey(int key) { + // look to exist key + string rSQL = String.Format("SELECT * FROM MAINTENANCE WHERE KEY = '{0}'",key); + SQLiteResultSet rs = m_db.Execute( rSQL ); + BuildMaintenance((ArrayList)rs.RowsList[0]); + if (M_Key==key) return true; + else return false; + } + + public void AddMainCat(string content, int num, int sub) { + string rSQL = String.Format( "INSERT INTO MAIN_CATEGORY VALUES ( null, '{0}', '{1}', '{2}' )", content, num, sub); + SQLiteResultSet rs = m_db.Execute( rSQL ); + } + + public void AddMaintenance(int key, string content, int var1, int var2) { + // look to exist key + M_Key=0; + string rSQL = String.Format("SELECT * FROM MAINTENANCE WHERE KEY = '{0}'",key.ToString() ); + SQLiteResultSet rs = m_db.Execute( rSQL ); + BuildMaintenance((ArrayList)rs.RowsList[0]); + + rSQL = String.Format( "INSERT INTO MAINTENANCE VALUES ( null, '{0}', '{1}', '{2}', {3} )", key.ToString(),content,var1,var2); + rs = m_db.Execute( rSQL ); + } + + public void AddRecipe( Recipe r ) // add recipe to database + { + if (r.Categories.Count==0) return; + + string rSql = String.Format( "INSERT INTO Recipe VALUES ( null, '{0}', '{1}', '{2}', {3}, {4} )", + RemoveInvalidChars( r.Title ), + RemoveInvalidChars( r.Yield ), + RemoveInvalidChars( r.Directions ), + "0","1"); + m_db.Execute( "BEGIN" ); + m_db.Execute( rSql ); + int rId = m_db.LastInsertID(); + AddCategories( r, rId ); + for (int i=0; i<r.Ingredients.Count; i++){ + string iSql = String.Format( "INSERT INTO INGREDIENT VALUES ( null, '{0}', '{1}', '{2}', '{3}')", rId, RemoveInvalidChars( (string)r.Ingredients[i] ),RemoveInvalidChars((string)r.Lot[i]),RemoveInvalidChars((string)r.Unit[i])); + m_db.Execute( iSql ); + } + m_db.Execute( "END" ); + } + + private void AddCategories(Recipe r, int id) // add category to database + { + ArrayList cat = r.Categories; + foreach( string category in cat ){ + string cSQL = String.Format( "Select * from CATEGORY where title = '{0}'", + RemoveInvalidChars( category.Trim() ) ); + SQLiteResultSet rs = m_db.Execute( cSQL ); + string cId = ""; + + if( rs.RowsList.Count > 0 ){ + // this category already exists + cId = rs.GetField( 0, 0 ); + } else { + // the category doesn't exist, so we need to add it + string iSQL = String.Format( "INSERT INTO CATEGORY VALUES ( null, '{0}')", + RemoveInvalidChars( category.Trim() )); + m_db.Execute( iSQL ); + cId = m_db.LastInsertID().ToString(); + } + + string crSQL = String.Format( "INSERT INTO Recipe_CATEGORY VALUES( null, {0}, {1}, '{2}' )", cId, id.ToString(),RemoveInvalidChars( r.Title ) ); + m_db.Execute( crSQL ); + } + } + + public Recipe GetRecipe( string title ) // get a recipe from database + { + string rSQL = String.Format("SELECT * FROM Recipe WHERE TITLE = '{0}'",title ); + SQLiteResultSet rs = m_db.Execute( rSQL ); + return BuildRecipe((ArrayList)rs.RowsList[0]); + } + + private Recipe BuildRecipe(ArrayList row){ + string stunit = ""; + + if (row==null) return null; + Recipe rec = new Recipe(); + IEnumerator en = row.GetEnumerator(); + en.MoveNext(); + rec.Id = (string) en.Current; + en.MoveNext(); + rec.Title = (string) en.Current; + en.MoveNext(); + + stunit=(string)en.Current; + stunit=stunit.Trim()+" "; + string[] s2 = stunit.Split( ' ' ); + + rec.Yield = stunit; + rec.CYield = Convert.ToInt16(s2[0]); + en.MoveNext(); + rec.Directions = (string)en.Current; + rec.Ingredients = BuildIngredients( rec.Id ); + rec.Lot = BuildLot( rec.Id ); + rec.Unit = BuildUnit( rec.Id ); + return rec; + } + + private Recipe BuildCategorie(ArrayList row){ + if (row==null) return null; + Recipe rec = new Recipe(); + IEnumerator en = row.GetEnumerator(); + en.MoveNext(); + rec.Id = (string) en.Current; + en.MoveNext(); + rec.Title = (string) en.Current; + return rec; + } + + private ArrayList BuildIngredients(string id){ + string aSQL = String.Format( "SELECT TITLE FROM INGREDIENT WHERE Recipe_ID = {0}", id ); + return m_db.Execute( aSQL ).GetColumn( 0 ); + } + + private ArrayList BuildLot(string id){ + string aSQL = String.Format( "SELECT LOT FROM INGREDIENT WHERE Recipe_ID = {0}", id ); + return m_db.Execute( aSQL ).GetColumn( 0 ); + } + + private ArrayList BuildUnit(string id){ + string aSQL = String.Format( "SELECT UNIT FROM INGREDIENT WHERE Recipe_ID = {0}", id ); + return m_db.Execute( aSQL ).GetColumn( 0 ); + } + + public ArrayList GetCategories(){ + string cSQL = "SELECT * FROM CATEGORY ORDER BY TITLE"; + SQLiteResultSet rs = m_db.Execute( cSQL ); + return rs.GetColumn( 1 ); + } + + public ArrayList GetMainCategories(){ + string cSQL = "SELECT * FROM MAIN_CATEGORY WHERE SUB = '0'"; + SQLiteResultSet rs = m_db.Execute( cSQL ); + return rs.GetColumn( 1 ); + } + + public void AddFavorite(string id ) { + string cSQL = String.Format( "INSERT INTO FAVORITE VALUES ( null, '{0}')",id); + SQLiteResultSet rs = m_db.Execute( cSQL ); + return; + } + + public void DeleteFavorite(string id ) + { + string cSQL = String.Format( "DELETE FROM FAVORITE WHERE TITLE = '{0}'", id ); + SQLiteResultSet rs = m_db.Execute( cSQL ); + return; + } + + public void DeleteRecipe(string id ) // delete a recipe from database + { + string cSQL = String.Format( "SELECT * FROM Recipe WHERE TITLE = '{0}'", id ); + SQLiteResultSet rs = m_db.Execute( cSQL ); + string recipeID = (string) rs.GetField(0,0); + + cSQL = String.Format( "DELETE FROM Recipe WHERE Recipe_ID = '{0}'", recipeID ); + rs = m_db.Execute( cSQL ); + cSQL = String.Format( "DELETE FROM Recipe_CATEGORY WHERE TITLE = '{0}'", id ); + rs = m_db.Execute( cSQL ); + cSQL = String.Format( "DELETE FROM FAVORITE WHERE TITLE = '{0}'", id ); + rs = m_db.Execute( cSQL ); + cSQL = String.Format( "DELETE FROM INGREDIENT WHERE Recipe_ID = '{0}'", recipeID); + rs = m_db.Execute( cSQL ); + return; + } + + public ArrayList SearchRecipes(string text,byte typ) //search recipe in database + { + string stext="%"+RemoveInvalidChars(text)+"%"; + string rSQL=""; + ArrayList recipes = new ArrayList(); + if (typ==1) {// Search in Title + rSQL = String.Format("SELECT recipe_id,title FROM Recipe WHERE TITLE LIKE '{0}'",stext); + } + else { // Search in all + rSQL = String.Format("SELECT recipe_id,title FROM Recipe WHERE TITLE LIKE '{0}' OR DIRECTIONS LIKE '{0}'",stext); + } + SQLiteResultSet rs = m_db.Execute( rSQL ); + + foreach( ArrayList row in rs.RowsList ) { + recipes.Add( BuildCategorie( row )); + } + return recipes; + } + + public ArrayList GetRecipesForFavorites() + { + ArrayList recipes = new ArrayList(); + string sql = String.Format( "Select * from favorite" ); + SQLiteResultSet rs = m_db.Execute( sql ); + foreach( ArrayList row in rs.RowsList ) + { + recipes.Add( BuildCategorie( row )); + } + return recipes; + } + + public ArrayList GetSubsForCategory( string category ) { + ArrayList recipes = new ArrayList(); + string sql = String.Format("SELECT * FROM MAIN_CATEGORY WHERE TITLE = '{0}'",category); + SQLiteResultSet rs = m_db.Execute( sql ); + string categoryID = (string) rs.GetField(0,2); + string sql2 = String.Format( "Select * from main_category where sub = {0}", categoryID ); + rs = m_db.Execute( sql2 ); + foreach( ArrayList row in rs.RowsList ) { + recipes.Add( BuildCategorie( row )); + } + return recipes; + } + + public ArrayList GetRecipesForCategory( string category ) + { + ArrayList recipes = new ArrayList(); + string sql = String.Format( "Select * from category where title = '{0}'", category ); + SQLiteResultSet rs = m_db.Execute( sql ); + + string categoryID = rs.GetField(0,0).ToString(); + string sql2 = String.Format( "Select recipe_id,title from recipe_category where category_id = {0}", categoryID ); + rs = m_db.Execute( sql2 ); + foreach( ArrayList row in rs.RowsList ) + { + recipes.Add( BuildCategorie( row )); + } + return recipes; + } + + string RemoveInvalidChars( string strTxt) + { + if( strTxt == null ) return ""; + string strReturn=""; + for (int i=0; i < (int)strTxt.Length; ++i) + { + char k=strTxt[i]; + int z=(int) k; + if (z<32 || z>255) k=' '; + if (k=='^' || k=='~' || k=='#') k=' '; + if (k=='\'') + { + strReturn += "'"; + } + strReturn += k; + } + if (strReturn=="") + strReturn=GUILocalizeStrings.Get(2014); + strTxt=strReturn.Trim(); + return strTxt; + } + } +} Added: trunk/plugins/My Recipes/RecipePrinter.cs =================================================================== --- trunk/plugins/My Recipes/RecipePrinter.cs (rev 0) +++ trunk/plugins/My Recipes/RecipePrinter.cs 2007-02-02 17:35:27 UTC (rev 82) @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2005 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 + * + */ + +using System; +using System.Collections; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Printing; +using System.IO; +using MediaPortal.GUI.Library; + +namespace GUIRecipes +{ + + public class RecipePrinter + { + private string cat; + private bool nextpage; // Is there a second Page to print? + private Font printFont; + private Font printBFont; + private Font printHFont; + private string Snextpage; + private Recipe recP = new Recipe(); + + public RecipePrinter() : base() + { + } + + // The Click event is raised when the user clicks the Print button. + public void printRecipe(Recipe rec, string scat, string stit) + { + cat=scat; + recP = rec; + nextpage = false; + Snextpage=""; + printFont = new Font("Arial", 11); + printHFont = new Font("Arial Black",13); + printBFont = new Font("Arial Black",10); + + PrintDocument pd = new PrintDocument(); + pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); + pd.Print(); + if (nextpage==true) + { + PrintDocument pd2 = new PrintDocument(); + pd2.PrintPage += new PrintPageEventHandler(this.pd_PrintPage); + pd2.Print(); + } + } + + // The PrintPage event is raised for each page to be printed. + private void pd_PrintPage(object sender, PrintPageEventArgs ev) + { + float linesPerPage = 0; + float yPos = 0; + int count = 0; + int start = 0; + int end = 0; + int mx = 0; + int len = 80; + + float leftMargin = ev.MarginBounds.Left; + float topMargin = ev.MarginBounds.Top; + string contents = recP.ToString(); + + // Calculate the number of lines per page. + linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics); + + string[] lines = contents.Split( '\n' ); + string pline = ""; + string lline = ""; + + // Create pen. + Pen blackPen = new Pen(Color.Black, 2); + ev.Graphics.DrawRectangle(blackPen,ev.MarginBounds.Left-50,ev.MarginBounds.Top-70,ev.MarginBounds.Width+50,21); + ev.Graphics.DrawRectangle(blackPen,ev.MarginBounds.Left-50,ev.MarginBounds.Top-49,ev.MarginBounds.Width+50,33); + ev.Graphics.DrawString(GUILocalizeStrings.Get(2053)+": "+cat, printBFont, Brushes.Black,leftMargin-30, ev.MarginBounds.Top-69, new StringFormat()); + ev.Graphics.DrawString(lines[0].Substring(8), printHFont, Brushes.Black,leftMargin-30, ev.MarginBounds.Top-47, new StringFormat()); + + // Print each line of the file. + foreach( string line in lines ) + { + if (nextpage==true) + { + if (Snextpage.Length > 1) + { + lline = Snextpage; + start = 0; + end = 0; + mx = len; + for( int i=0; i < Snextpage.Length; i++) + { + if (lline[i] == ' ') end=i; + if (i == mx) + { + pline = Snextpage.Substring(start,end-start); + mx = end + len; + start = end + 1; + pline = " " + pline; + yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); + ev.Graphics.DrawString(pline, printFont, Brushes.Black,leftMargin, yPos, new StringFormat()); + count++; + if (count >= linesPerPage) break; + } + } + pline = Snextpage.Substring(start); + pline = " " + pline; + yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); + ev.Graphics.DrawString(pline, printFont, Brushes.Black,leftMargin, yPos, new StringFormat()); + count++; + break; + } + } + if (line.Length > len && nextpage==false) + { + lline=line; + start = 0; + end = 0; + mx=len; + for( int i=0; i<line.Length; i++) + { + if (lline[i] == ' ') end=i; + if (i==mx) + { + pline=line.Substring(start,end-start); + mx=end+len; + start=end+1; + pline=" "+pline; + yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); + ev.Graphics.DrawString(pline, printFont, Brushes.Black,leftMargin, yPos, new StringFormat()); + count++; + if (count >= linesPerPage) + { + Snextpage=line.Substring(start); + nextpage=true; + break; + } + } + } + if (nextpage==false) + { + pline=line.Substring(start); + pline=" "+pline; + yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); + ev.Graphics.DrawString(pline, printFont, Brushes.Black,leftMargin, yPos, new StringFormat()); + count++; + } + else + { + break; + } + } + else + { + if (nextpage==false) + { + yPos = topMargin + (count * printFont.GetHeight(ev.Graphics)); + ev.Graphics.DrawString(line, printFont, Brushes.Black,leftMargin, yPos, new StringFormat()); + count++; + if (count >= linesPerPage) + { + nextpage=true; + break; + } + } + } + if (count >= linesPerPage) + { + nextpage=true; + break; + } + } + } + } +} Added: trunk/plugins/My Recipes/RecipeReader.cs ======================... [truncated message content] |