00001 using Gtk;
00002 using Gdk;
00003 using System;
00004 using Foodolini.Activities;
00005 using Foodolini.BusinessLogic;
00006 using System.Collections.Generic;
00007
00008 namespace Foodolini.Activities.Home
00009 {
00010 [FoodoliniActivity("Home", false, "Home.home.png")]
00011 [System.ComponentModel.ToolboxItem(true)]
00012 public partial class HomeActivity : Gtk.Bin, IActivity
00013 {
00014
00015 public HomeActivity()
00016 {
00017
00018 this.Build();
00019
00020
00021 this.styleFacilitator.ModifyBg(StateType.Normal, new Color(0xff, 0xff, 0xff));
00022 this.Shown += delegate {
00023 using(Pixbuf img = Pixbuf.LoadFromResource("Home.bg.png")){
00024 Pixmap pix, mask;
00025 img.RenderPixmapAndMaskForColormap(this.styleFacilitator.Colormap, out pix, out mask, 0);
00026 this.styleFacilitator.Style.SetBgPixmap(StateType.Normal, pix);
00027 pix.Dispose();
00028 mask.Dispose();
00029 }
00030 };
00031
00032
00033 this.PopulateInventoryView();
00034 }
00035
00036 #region IActivity implementation
00037
00038 private IOwner owner = null;
00039
00040 public void Register(IOwner owner){
00041 this.owner = owner;
00042 }
00043
00044 public void Unregister(){
00045 this.owner = null;
00046 }
00047
00048 public Widget Widget{
00049 get{return this;}
00050 }
00051
00052 #endregion
00053
00054 #region Inventory view
00055
00056 private NodeStore store;
00057
00058 private void PopulateInventoryView(){
00059 store = new NodeStore(typeof(FoodItemAdapter));
00060
00061
00062 List<FoodItem> items = new List<FoodItem>(FoodItem.ListFoodItems());
00063 items.Sort((f1, f2) => {
00064 if(f1.ExpirationDate < f2.ExpirationDate)
00065 return -1;
00066 if(f1.ExpirationDate == f2.ExpirationDate)
00067 return 0;
00068 return 1;
00069 });
00070
00071
00072 foreach(var item in items)
00073 store.AddNode (new FoodItemAdapter(item));
00074
00075 this.InventoryView.NodeStore = store;
00076
00077
00078 this.InventoryView.AppendColumn ("Food", new CellRendererText (), "text", 0);
00079 this.InventoryView.AppendColumn ("Quantity", new CellRendererText (), "text", 1);
00080 this.InventoryView.AppendColumn ("Expiration date", new CellRendererText (), (column, cell, node) =>
00081 {
00082 FoodItemAdapter n = (FoodItemAdapter)node;
00083 CellRendererText c = (CellRendererText)cell;
00084 c.Text = n.ExpirationDate.ToShortDateString();
00085 });
00086 this.InventoryView.AppendColumn ("Open/Closed", new CellRendererText(), "text", 3);
00087 }
00088
00089 #endregion
00090
00091 protected virtual void OnInventoryButtonClicked (object sender, System.EventArgs e){
00092 this.owner.LoadActivity("Inventory");
00093 }
00094
00095 protected virtual void OnRegisterFoodItemButtonClicked (object sender, System.EventArgs e){
00096 this.owner.LoadActivity("Food registration");
00097 }
00098
00099 protected virtual void OnCookbookButtonClicked (object sender, System.EventArgs e){
00100 this.owner.LoadActivity("Cookbook");
00101 }
00102
00103 protected virtual void OnNewRecipeButtonClicked (object sender, System.EventArgs e){
00104 this.owner.LoadActivity("Create recipe");
00105 }
00106
00107 protected virtual void OnIngredientsButtonClicked (object sender, System.EventArgs e){
00108 this.owner.LoadActivity("Ingredients");
00109 }
00110
00111 protected virtual void OnProfileButtonClicked (object sender, System.EventArgs e){
00112 this.owner.LoadActivity("User profile");
00113 }
00114
00115 protected virtual void OnAdminButtonClicked (object sender, System.EventArgs e){
00116 this.owner.LoadActivity("User administration");
00117 }
00118
00119 protected virtual void OnInventoryViewRowActivated (object o, Gtk.RowActivatedArgs args){
00120 this.owner.LoadActivity("Inventory");
00121 }
00122 }
00123 }