From: <che...@us...> - 2007-06-10 20:11:33
|
Revision: 509 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=509&view=rev Author: chef_koch Date: 2007-06-10 13:11:31 -0700 (Sun, 10 Jun 2007) Log Message: ----------- merged "mew"-view code from old-plugin known issue: - changing view in one appitem, and switching to new appitem, shows previous view for new item - CurrentView in GUIPrograms could be obsolete, not sure, whether we could use it, just implemented it from music, to get views working for first time Modified Paths: -------------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/ProgramViews.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramViewHandler.cs Added Paths: ----------- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramSort.cs Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/ProgramViews.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/ProgramViews.cs 2007-06-10 17:45:25 UTC (rev 508) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/Design/ProgramViews.cs 2007-06-10 20:11:31 UTC (rev 509) @@ -26,15 +26,16 @@ using System; using System.Collections; using System.ComponentModel; +using System.Data; using System.Drawing; -using System.Data; using System.IO; using System.Runtime.Serialization.Formatters.Soap; using System.Windows.Forms; + +using MediaPortal.Configuration; using MediaPortal.GUI.Library; using MediaPortal.GUI.View; using MediaPortal.Util; -using MediaPortal.Configuration; namespace GUIPrograms.Design { @@ -43,12 +44,14 @@ /// </summary> public class ProgramViews : UserControl { + #region Helper Classes + // two classes ripped from frodos MusicViews.cs public class SyncedCheckBox : CheckBox { - DataGrid grid; int cell; + public int Cell { get { return cell; } @@ -60,6 +63,7 @@ get { return grid; } set { grid = value; } } + protected override void OnLayout(LayoutEventArgs levent) { DataGridCell currentCell = Grid.CurrentCell; @@ -79,11 +83,19 @@ base.OnLayout(levent); } } - public class SyncedComboBox : ComboBox { DataGrid grid; int cell; + + public SyncedComboBox(string name) + { + this.Cursor = System.Windows.Forms.Cursors.Arrow; + this.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.Dock = DockStyle.Fill; + this.DisplayMember = name; + } + public int Cell { get { return cell; } @@ -95,6 +107,7 @@ get { return grid; } set { grid = value; } } + protected override void OnLayout(LayoutEventArgs levent) { try @@ -132,112 +145,37 @@ } } - private MediaPortal.UserInterface.Controls.MPTextBox tbViewName; - private MediaPortal.UserInterface.Controls.MPLabel label2; - private MediaPortal.UserInterface.Controls.MPButton btnDelete; - private MediaPortal.UserInterface.Controls.MPButton btnSave; - private MediaPortal.UserInterface.Controls.MPComboBox cbViews; - private MediaPortal.UserInterface.Controls.MPLabel label1; - private System.Windows.Forms.DataGrid dataGrid1; - private MediaPortal.UserInterface.Controls.MPLabel label3; - /// <summary> + #endregion Helper Classes + + #region Designer Code + + /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; - - ViewDefinition currentView; - ArrayList views; - DataSet ds = new DataSet(); - bool updating = false; - - string[] selections = new string[] - { - "title", - "filename", - "country", - "genre", - "year", - "manufacturer", - "rating", - "launchcount", - "lastTimeLaunched", - "genre2", - "genre3", - "genre4", - "genre5" - }; - string[] sqloperators = new string[] - { - "", - "=", - ">", - "<", - ">=", - "<=", - "<>", - "like", - "group", - }; - - public ProgramViews() - : this("Program Views") - { - } - string defaultProgramViews = Config.GetFile(Config.Dir.Base, "defaultMyProgramsAltViews.xml"); - string customProgramViews = Config.GetFile(Config.Dir.Config, "myProgramsAltViews.xml"); - public ProgramViews(string name) - { - - // This call is required by the Windows Form Designer. - InitializeComponent(); - views = new ArrayList(); - if (System.IO.File.Exists(customProgramViews)) - { - using (FileStream fileStream = new FileStream(customProgramViews, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) - { - try - { - SoapFormatter formatter = new SoapFormatter(); - views = (ArrayList)formatter.Deserialize(fileStream); - fileStream.Close(); - } - catch - { - } - } - } - else - { - Log.Info("Warning: customProgramViews not found!"); - } - LoadViews(); - } - - - /// <summary> + /// <summary> /// Clean up any resources being used. /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { - if (disposing) + if (disposing && (components != null)) { - if (components != null) - { - components.Dispose(); - } + components.Dispose(); } base.Dispose(disposing); } #region Component Designer generated code - /// <summary> - /// Required method for Designer support - do not modify + + /// <summary> + /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { - this.dataGrid1 = new System.Windows.Forms.DataGrid(); + this.dataGrid = new System.Windows.Forms.DataGrid(); this.label3 = new MediaPortal.UserInterface.Controls.MPLabel(); this.tbViewName = new MediaPortal.UserInterface.Controls.MPTextBox(); this.label2 = new MediaPortal.UserInterface.Controls.MPLabel(); @@ -245,39 +183,39 @@ this.btnSave = new MediaPortal.UserInterface.Controls.MPButton(); this.cbViews = new MediaPortal.UserInterface.Controls.MPComboBox(); this.label1 = new MediaPortal.UserInterface.Controls.MPLabel(); - ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).BeginInit(); this.SuspendLayout(); // - // dataGrid1 + // dataGrid // - this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender; - this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.dataGrid.AlternatingBackColor = System.Drawing.Color.Lavender; + this.dataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke; - this.dataGrid1.BackgroundColor = System.Drawing.Color.LightGray; - this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSteelBlue; - this.dataGrid1.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); - this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue; - this.dataGrid1.DataMember = ""; - this.dataGrid1.FlatMode = true; - this.dataGrid1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); - this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue; - this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro; - this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None; - this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue; - this.dataGrid1.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); - this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke; - this.dataGrid1.LinkColor = System.Drawing.Color.Teal; - this.dataGrid1.Location = new System.Drawing.Point(8, 112); - this.dataGrid1.Name = "dataGrid1"; - this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro; - this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue; - this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue; - this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke; - this.dataGrid1.Size = new System.Drawing.Size(426, 256); - this.dataGrid1.TabIndex = 14; + this.dataGrid.BackColor = System.Drawing.Color.WhiteSmoke; + this.dataGrid.BackgroundColor = System.Drawing.Color.LightGray; + this.dataGrid.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.dataGrid.CaptionBackColor = System.Drawing.Color.LightSteelBlue; + this.dataGrid.CaptionFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); + this.dataGrid.CaptionForeColor = System.Drawing.Color.MidnightBlue; + this.dataGrid.DataMember = ""; + this.dataGrid.FlatMode = true; + this.dataGrid.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); + this.dataGrid.ForeColor = System.Drawing.Color.MidnightBlue; + this.dataGrid.GridLineColor = System.Drawing.Color.Gainsboro; + this.dataGrid.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None; + this.dataGrid.HeaderBackColor = System.Drawing.Color.MidnightBlue; + this.dataGrid.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 8.25F); + this.dataGrid.HeaderForeColor = System.Drawing.Color.WhiteSmoke; + this.dataGrid.LinkColor = System.Drawing.Color.Teal; + this.dataGrid.Location = new System.Drawing.Point(8, 112); + this.dataGrid.Name = "dataGrid"; + this.dataGrid.ParentRowsBackColor = System.Drawing.Color.Gainsboro; + this.dataGrid.ParentRowsForeColor = System.Drawing.Color.MidnightBlue; + this.dataGrid.SelectionBackColor = System.Drawing.Color.CadetBlue; + this.dataGrid.SelectionForeColor = System.Drawing.Color.WhiteSmoke; + this.dataGrid.Size = new System.Drawing.Size(426, 256); + this.dataGrid.TabIndex = 14; // // label3 // @@ -294,7 +232,7 @@ this.tbViewName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tbViewName.Location = new System.Drawing.Point(72, 80); this.tbViewName.Name = "tbViewName"; - this.tbViewName.Size = new System.Drawing.Size(168, 20); + this.tbViewName.Size = new System.Drawing.Size(168, 21); this.tbViewName.TabIndex = 20; // // label2 @@ -330,6 +268,7 @@ // cbViews // this.cbViews.BorderColor = System.Drawing.SystemColors.ActiveCaptionText; + this.cbViews.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cbViews.Location = new System.Drawing.Point(72, 48); this.cbViews.Name = "cbViews"; this.cbViews.Size = new System.Drawing.Size(168, 21); @@ -346,7 +285,7 @@ // // ProgramViews // - this.Controls.Add(this.dataGrid1); + this.Controls.Add(this.dataGrid); this.Controls.Add(this.cbViews); this.Controls.Add(this.label3); this.Controls.Add(this.tbViewName); @@ -356,15 +295,130 @@ this.Controls.Add(this.label1); this.Name = "ProgramViews"; this.Size = new System.Drawing.Size(437, 408); - ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGrid)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } + #endregion + private MediaPortal.UserInterface.Controls.MPTextBox tbViewName; + private MediaPortal.UserInterface.Controls.MPLabel label2; + private MediaPortal.UserInterface.Controls.MPButton btnDelete; + private MediaPortal.UserInterface.Controls.MPButton btnSave; + private MediaPortal.UserInterface.Controls.MPComboBox cbViews; + private MediaPortal.UserInterface.Controls.MPLabel label1; + private System.Windows.Forms.DataGrid dataGrid; + private MediaPortal.UserInterface.Controls.MPLabel label3; + #endregion Designer Code + #region Variables + + ViewDefinition currentView; + ArrayList views; + DataSet ds = new DataSet(); + DataTable datasetFilters; //Data Table var + bool updating = false; + + string defaultProgramViews = Config.GetFile(Config.Dir.Base, "defaultMyProgramsAltViews.xml"); + string customProgramViews = Config.GetFile(Config.Dir.Config, "myProgramsAltViews.xml"); + + string[] selections = new string[] + { + "title", + "filename", + "country", + "genre", + "year", + "manufacturer", + "rating", + "launchcount", + "lastTimeLaunched", + "genre2", + "genre3", + "genre4", + "genre5", + }; + + string[] sqloperators = new string[] + { + "", + "=", + ">", + "<", + ">=", + "<=", + "<>", + "like", + "group", + }; + + string[] viewsAs = new string[] + { + "List", + "Icons", + "Big Icons", + "Filmstrip", + }; + + string[] sortBy = new string[] + { + "Name", + "Title", + "Filename", + "Rating", + "LaunchCount", + "LastTimeLaunched", + }; + + #endregion Variables + + #region Constructors + + public ProgramViews() + : this("Program Views") { } + + public ProgramViews(string name) + { + // This call is required by the Windows Form Designer. + InitializeComponent(); + + if (!File.Exists(customProgramViews)) + { + Log.Info("Warning: customProgramViews not found!"); + if (File.Exists(defaultProgramViews)) + { + Log.Info("Warning: defaultProgramViews will be restored!"); + File.Copy(defaultProgramViews, customProgramViews); + } + else + { + Log.Info("Warning: defaultProgramViews not found, please reinstall this plugin!"); + return; + } + } + + views = new ArrayList(); + using (FileStream fileStream = new FileStream(customProgramViews, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + try + { + SoapFormatter formatter = new SoapFormatter(); + views = (ArrayList)formatter.Deserialize(fileStream); + fileStream.Close(); + } + catch + { + } + } + + LoadViews(); + } + + #endregion Constructors + void LoadViews() { updating = true; @@ -373,10 +427,12 @@ { if (view.Name != String.Empty) { - cbViews.Items.Add(view.Name); + cbViews.Items.Add(view); } } - cbViews.Items.Add("new..."); + ViewDefinition newDef = new ViewDefinition(); + newDef.Name = "new..."; + cbViews.Items.Add(newDef); if (cbViews.Items.Count > 0) cbViews.SelectedIndex = 0; @@ -400,43 +456,54 @@ tbViewName.Text = currentView.Name; //Declare and initialize local variables used - DataColumn dtCol = null;//Data Column variable - string[] arrColumnNames = null;//string array variable - SyncedComboBox cbSelection, cbOperators; //combo box var - DataTable datasetFilters;//Data Table var + DataColumn dtCol = null; //Data Column variable + string[] arrColumnNames = null; //string array variable //Create the combo box object and set its properties - cbSelection = new SyncedComboBox(); - cbSelection.Cursor = System.Windows.Forms.Cursors.Arrow; - cbSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - cbSelection.Dock = DockStyle.Fill; - cbSelection.DisplayMember = "Selection"; + SyncedComboBox cbSelection = new SyncedComboBox("Selection"); foreach (string strText in selections) cbSelection.Items.Add(strText); - cbSelection.Grid = dataGrid1; + cbSelection.Grid = dataGrid; cbSelection.Cell = 0; //Event that will be fired when selected index in the combo box is changed - cbSelection.SelectionChangeCommitted += new EventHandler(cbSelection_SelectionChangeCommitted); + cbSelection.SelectionChangeCommitted += new EventHandler(ComboBox_SelectionChangeCommitted); //Create the combo box object and set its properties - cbOperators = new SyncedComboBox(); - cbOperators.Cursor = System.Windows.Forms.Cursors.Arrow; - cbOperators.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - cbOperators.Dock = DockStyle.Fill; - cbOperators.DisplayMember = "Operator"; + SyncedComboBox cbOperators = new SyncedComboBox("Operator"); foreach (string strText in sqloperators) cbOperators.Items.Add(strText); - cbOperators.Grid = dataGrid1; + cbOperators.Grid = dataGrid; cbOperators.Cell = 1; - cbOperators.SelectionChangeCommitted += new EventHandler(cbOperators_SelectionChangeCommitted); + //Event that will be fired when selected index in the combo box is changed + cbOperators.SelectionChangeCommitted += new EventHandler(ComboBox_SelectionChangeCommitted); + //Create the combo box object and set its properties + SyncedComboBox cbView = new SyncedComboBox("ViewAs"); + foreach (string strText in viewsAs) + cbView.Items.Add(strText); + cbView.Grid = dataGrid; + cbView.Cell = 4; + //Event that will be fired when selected index in the combo box is changed + cbView.SelectionChangeCommitted += new EventHandler(ComboBox_SelectionChangeCommitted); + + //Create the combo box object and set its properties + SyncedComboBox cbSort = new SyncedComboBox("SortBy"); + foreach (string strText in sortBy) + cbSort.Items.Add(strText); + cbSort.Grid = dataGrid; + cbSort.Cell = 5; + //Event that will be fired when selected index in the combo box is changed + cbSort.SelectionChangeCommitted += new EventHandler(ComboBox_SelectionChangeCommitted); + //Create the String array object, initialize the array with the column //names to be displayed - arrColumnNames = new string[4]; + arrColumnNames = new string[6]; arrColumnNames[0] = "Selection"; arrColumnNames[1] = "Operator"; arrColumnNames[2] = "Restriction"; arrColumnNames[3] = "Limit"; + arrColumnNames[4] = "ViewAs"; + arrColumnNames[5] = "SortBy"; //Create the Data Table object which will then be used to hold //columns and rows @@ -459,27 +526,44 @@ dtcCheck.ColumnName = "Sort Ascending"; datasetFilters.Columns.Add(dtcCheck);//Add the above column to the //Data Table + // Add the Action column + dtCol = new DataColumn("Act"); + dtCol.DataType = Type.GetType("System.String"); + dtCol.DefaultValue = ""; + datasetFilters.Columns.Add(dtCol); + //fill in all rows... for (int i = 0; i < currentView.Filters.Count; ++i) { FilterDefinition def = (FilterDefinition)currentView.Filters[i]; string limit = def.Limit.ToString(); if (def.Limit < 0) limit = ""; - datasetFilters.Rows.Add(new object[] { def.Where, def.SqlOperator, def.Restriction, limit, def.SortAscending }); + datasetFilters.Rows.Add( + new object[] { + def.Where, + def.SqlOperator, + def.Restriction, + limit, + def.DefaultView, + def.DefaultSort, + def.SortAscending, + "" + } + ); } //Set the Data Grid Source as the Data Table created above - dataGrid1.CaptionText = String.Empty; - dataGrid1.DataSource = datasetFilters; + dataGrid.CaptionText = String.Empty; + dataGrid.DataSource = datasetFilters; //set style property when first time the grid loads, next time onwards it //will maintain its property - if (!dataGrid1.TableStyles.Contains("Selection")) + if (!dataGrid.TableStyles.Contains("Selection")) { //Create a DataGridTableStyle object DataGridTableStyle dgdtblStyle = new DataGridTableStyle(); //Set its properties dgdtblStyle.MappingName = datasetFilters.TableName;//its table name of dataset - dataGrid1.TableStyles.Add(dgdtblStyle); + dataGrid.TableStyles.Add(dgdtblStyle); dgdtblStyle.RowHeadersVisible = false; dgdtblStyle.HeaderBackColor = Color.LightSteelBlue; dgdtblStyle.AllowSorting = false; @@ -489,18 +573,25 @@ dgdtblStyle.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); dgdtblStyle.GridLineColor = Color.DarkGray; dgdtblStyle.PreferredRowHeight = 22; - dataGrid1.BackgroundColor = Color.White; + dataGrid.BackgroundColor = Color.White; //Take the columns in a GridColumnStylesCollection object and set //the size of the //individual columns GridColumnStylesCollection colStyle; - colStyle = dataGrid1.TableStyles[0].GridColumnStyles; + colStyle = dataGrid.TableStyles[0].GridColumnStyles; colStyle[0].Width = 100; colStyle[1].Width = 80; colStyle[2].Width = 70; colStyle[3].Width = 70; - colStyle[4].Width = 102; + colStyle[4].Width = 80; + colStyle[5].Width = 80; + colStyle[6].Width = 102; + colStyle[7].Width = 30; + // Set an eventhandler to be fired, when entering something in the action column + DataGridTextBoxColumn tbAction = (DataGridTextBoxColumn)dgdtblStyle.GridColumnStyles[7]; + tbAction.TextBox.KeyPress += new KeyPressEventHandler(tbAction_KeyPress); + /* DataGridColumnStyle boolCol = new FormattableBooleanColumn(); boolCol.MappingName = "Sort Ascending"; @@ -509,92 +600,79 @@ dgdtblStyle.GridColumnStyles.Add(boolCol); */ } - DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[0]; + + DataGridTextBoxColumn dgtb = null; //Add the combo box to the text box taken in the above step + dgtb = (DataGridTextBoxColumn)dataGrid.TableStyles[0].GridColumnStyles[0]; dgtb.TextBox.Controls.Add(cbSelection); - - dgtb = (DataGridTextBoxColumn)dataGrid1.TableStyles[0].GridColumnStyles[1]; + dgtb = (DataGridTextBoxColumn)dataGrid.TableStyles[0].GridColumnStyles[1]; dgtb.TextBox.Controls.Add(cbOperators); + dgtb = (DataGridTextBoxColumn)dataGrid.TableStyles[0].GridColumnStyles[4]; + dgtb.TextBox.Controls.Add(cbView); + dgtb = (DataGridTextBoxColumn)dataGrid.TableStyles[0].GridColumnStyles[5]; + dgtb.TextBox.Controls.Add(cbSort); - DataGridBoolColumn boolColumn = (DataGridBoolColumn)dataGrid1.TableStyles[0].GridColumnStyles[4]; + DataGridBoolColumn boolColumn = (DataGridBoolColumn)dataGrid.TableStyles[0].GridColumnStyles[6]; boolColumn.AllowNull = false; - updating = false; } - - - private void cbViews_SelectedIndexChanged(object sender, System.EventArgs e) + void cbViews_SelectedIndexChanged(object sender, System.EventArgs e) { if (updating) return; StoreGridInView(); + dataGrid.DataSource = null; UpdateView(); } - private void cbSelection_SelectionChangeCommitted(object sender, EventArgs e) + void ComboBox_SelectionChangeCommitted(object sender, System.EventArgs e) { if (updating) return; SyncedComboBox box = sender as SyncedComboBox; if (box == null) return; - DataGridCell currentCell = dataGrid1.CurrentCell; - DataTable table = dataGrid1.DataSource as DataTable; + DataGridCell currentCell = dataGrid.CurrentCell; + DataTable table = dataGrid.DataSource as DataTable; if (currentCell.RowNumber == table.Rows.Count) - table.Rows.Add(new object[] { "", "", "", "" }); + table.Rows.Add(new object[] { "", "", "", "", "", "" }); table.Rows[currentCell.RowNumber][currentCell.ColumnNumber] = (string)box.SelectedItem; } - - private void cbOperators_SelectionChangeCommitted(object sender, EventArgs e) + void tbAction_KeyPress(object sender, KeyPressEventArgs e) { - if (updating) return; - SyncedComboBox box = sender as SyncedComboBox; - if (box == null) return; - DataGridCell currentCell = dataGrid1.CurrentCell; - DataTable table = dataGrid1.DataSource as DataTable; + DataRow row = datasetFilters.NewRow(); + row[0] = row[1] = row[2] = row[3] = row[4] = row[5] = row[7] = ""; + row[6] = false; - if (currentCell.RowNumber == table.Rows.Count) - table.Rows.Add(new object[] { "", "", "", "" }); - table.Rows[currentCell.RowNumber][currentCell.ColumnNumber] = (string)box.SelectedItem; + e.Handled = true; - } + int rowSelected = dataGrid.CurrentRowIndex; + if (rowSelected == -1) return; + if (rowSelected == datasetFilters.Rows.Count) return; - - private void btnSave_Click(object sender, System.EventArgs e) - { - StoreGridInView(); - try + switch (e.KeyChar) { - using (FileStream fileStream = new FileStream(customProgramViews, FileMode.Create, FileAccess.Write, FileShare.Read)) - { - SoapFormatter formatter = new SoapFormatter(); - formatter.Serialize(fileStream, views); - fileStream.Close(); - } + case 'a': + datasetFilters.Rows.InsertAt(row, rowSelected + 1); + break; + case 'b': + datasetFilters.Rows.InsertAt(row, rowSelected); + break; + case 'd': + datasetFilters.Rows.RemoveAt(rowSelected); + break; } - catch (Exception) - { - } - } void StoreGridInView() { if (updating) return; - if (dataGrid1.DataSource == null) return; + if (dataGrid.DataSource == null) return; if (currentView == null) return; - ViewDefinition view = null; - for (int i = 0; i < views.Count; ++i) - { - ViewDefinition tmp = views[i] as ViewDefinition; - if (tmp.Name == currentView.Name) - { - view = tmp; - break; - } - } - DataTable dt = dataGrid1.DataSource as DataTable; + + ViewDefinition view = currentView; + DataTable dt = dataGrid.DataSource as DataTable; if (view == null) { if (dt.Rows.Count == 0) return; @@ -602,23 +680,21 @@ view.Name = tbViewName.Text; views.Add(view); currentView = view; - cbViews.Items.Insert(cbViews.Items.Count - 1, view.Name); + cbViews.Items.Insert(cbViews.Items.Count - 1, view); updating = true; - cbViews.SelectedItem = view.Name; + cbViews.SelectedItem = view; updating = false; } else { updating = true; - for (int i = 0; i < cbViews.Items.Count; ++i) + view.Name = tbViewName.Text; + int index = cbViews.Items.IndexOf(view); + if (index >= 0) { - string label = (string)cbViews.Items[i]; - if (label == currentView.Name) - { - cbViews.Items[i] = tbViewName.Text; - break; - } + cbViews.Items[index] = view; } + cbViews.Update(); updating = false; } view.Name = tbViewName.Text; @@ -639,13 +715,33 @@ { def.Limit = -1; } - def.SortAscending = (bool)row[4]; + def.DefaultView = row[4].ToString(); + def.DefaultSort = row[5].ToString(); + def.SortAscending = (bool)row[6]; view.Filters.Add(def); } } - private void btnDelete_Click(object sender, System.EventArgs e) + void btnSave_Click(object sender, System.EventArgs e) { + StoreGridInView(); + try + { + using (FileStream fileStream = new FileStream(customProgramViews, FileMode.Create, FileAccess.Write, FileShare.Read)) + { + SoapFormatter formatter = new SoapFormatter(); + formatter.Serialize(fileStream, views); + fileStream.Close(); + } + } + catch (Exception) + { + } + + } + + void btnDelete_Click(object sender, System.EventArgs e) + { string viewName = cbViews.SelectedItem as string; if (viewName == null) return; for (int i = 0; i < views.Count; ++i) @@ -660,4 +756,4 @@ LoadViews(); } } -} +} \ No newline at end of file Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-06-10 17:45:25 UTC (rev 508) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIPrograms.cs 2007-06-10 20:11:31 UTC (rev 509) @@ -24,6 +24,7 @@ #endregion using System; +using System.Collections.Generic; using System.Drawing; using System.IO; using System.Threading; @@ -499,6 +500,10 @@ bool skipInit = false; + View[,] views; + bool[,] sortasc; + ProgramSort.SortMethod[,] sortby; + static string _thumbnailPath = string.Empty; static string _lastThumbnailPath = string.Empty; @@ -555,6 +560,117 @@ set { view = value; } } + View CurrentView + {//maybe we can remove this property, not sure if we would need it + get + { + if (DatabaseSettings.viewHandler.View == null) + return View.List; + + if (views == null) + { + views = new View[DatabaseSettings.viewHandler.Views.Count, 50]; + + List<String> viewStrings = new List<String>(); + viewStrings.Add("List"); + viewStrings.Add("Icons"); + viewStrings.Add("Big Icons"); + viewStrings.Add("Filmstrip"); + + for (int i = 0; i < DatabaseSettings.viewHandler.Views.Count; ++i) + { + for (int j = 0; j < DatabaseSettings.viewHandler.Views[i].Filters.Count; ++j) + { + FilterDefinition def = (FilterDefinition)DatabaseSettings.viewHandler.Views[i].Filters[j]; + int defaultView = viewStrings.IndexOf(def.DefaultView); + + if (defaultView != -1) + views[i, j] = (View)defaultView; + else + views[i, j] = View.List; + } + } + } + + return views[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel]; + } + set + { + views[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel] = value; + } + } + + bool CurrentSortAsc + { + get + { + if (DatabaseSettings.viewHandler.View == null) + return true; + + if (sortasc == null) + { + sortasc = new bool[DatabaseSettings.viewHandler.Views.Count, 50]; + + for (int i = 0; i < DatabaseSettings.viewHandler.Views.Count; ++i) + { + for (int j = 0; j < DatabaseSettings.viewHandler.Views[i].Filters.Count; ++j) + { + FilterDefinition def = (FilterDefinition)DatabaseSettings.viewHandler.Views[i].Filters[j]; + sortasc[i, j] = def.SortAscending; + } + } + } + + return sortasc[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel]; + } + set + { + sortasc[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel] = value; + } + } + + ProgramSort.SortMethod CurrentSortMethod + { + get + { + if (DatabaseSettings.viewHandler.View == null) + return ProgramSort.SortMethod.Name; + + if (sortby == null) + { + sortby = new ProgramSort.SortMethod[DatabaseSettings.viewHandler.Views.Count, 50]; + + List<String> sortStrings = new List<String>(); + sortStrings.Add("Name"); + sortStrings.Add("Title"); + sortStrings.Add("Filename"); + sortStrings.Add("Rating"); + sortStrings.Add("LaunchCount"); + sortStrings.Add("LastTimeLaunched"); + + for (int i = 0; i < DatabaseSettings.viewHandler.Views.Count; ++i) + { + for (int j = 0; j < DatabaseSettings.viewHandler.Views[i].Filters.Count; ++j) + { + FilterDefinition def = (FilterDefinition)DatabaseSettings.viewHandler.Views[i].Filters[j]; + int defaultSort = sortStrings.IndexOf(def.DefaultSort); + + if (defaultSort != -1) + sortby[i, j] = (ProgramSort.SortMethod)defaultSort; + else + sortby[i, j] = ProgramSort.SortMethod.Name; + } + } + } + + return sortby[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel]; + } + set + { + sortby[DatabaseSettings.viewHandler.Views.IndexOf(DatabaseSettings.viewHandler.View), DatabaseSettings.viewHandler.CurrentLevel] = value; + } + } + #endregion #region Overrides @@ -764,11 +880,11 @@ GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg == null) return; dlg.Reset(); - dlg.SetHeading(924); // menu - dlg.Add("Files"); + dlg.SetHeading(499); // Actions + dlg.Add(GUILocalizeStrings.Get(100000 + GetID)); // Files foreach (ViewDefinition view in DatabaseSettings.viewHandler.Views) { - dlg.Add(view.Name); //play + dlg.Add(view.LocalizedName); } dlg.DoModal(GetID); if (dlg.SelectedLabel == -1) return; @@ -902,7 +1018,8 @@ void UpdateButtons() { - GUIPropertyManager.SetProperty("#view", DatabaseSettings.viewHandler.CurrentView); + GUIPropertyManager.SetProperty("#view", DatabaseSettings.viewHandler.LocalizedCurrentView); + btnViewAs.Label = mapSettings.ViewAsText; btnRefresh.IsVisible = RefreshButtonVisible(); // display apptitle if available..... @@ -910,7 +1027,7 @@ { if ((DatabaseSettings.viewHandler.CurrentView != null) && (DatabaseSettings.viewHandler.MaxLevels > 0)) { - GUIPropertyManager.SetProperty("#curheader", ActualView); + GUIPropertyManager.SetProperty("#curheader", DatabaseSettings.viewHandler.LocalizedCurrentView); } else { @@ -929,7 +1046,6 @@ GUIPropertyManager.SetProperty("#curheader", GUILocalizeStrings.Get(0)); } } - btnViewAs.Label = mapSettings.ViewAsText; } void ShowThumbPanel() @@ -1063,10 +1179,9 @@ if (lastApp != null) { - lastApp.OnSort(facadeView, false); + facadeView.Sort(new ProgramSort(CurrentSortMethod, CurrentSortAsc)); } - string itemCountText = String.Format("{0} {1}", TotalItems, GUILocalizeStrings.Get(632)); GUIPropertyManager.SetProperty("#itemcount", itemCountText); Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj 2007-06-10 17:45:25 UTC (rev 508) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/GUIProgramsAlt.csproj 2007-06-10 20:11:31 UTC (rev 509) @@ -141,6 +141,7 @@ <Compile Include="Imports\AllGameScraper.cs" /> <Compile Include="Imports\GamebaseImport.cs" /> <Compile Include="Imports\MameImport.cs" /> + <Compile Include="ProgramSort.cs" /> <Compile Include="ProgramFilterItem.cs" /> <Compile Include="ProgramUtils.cs" /> <Compile Include="ProgramViewHandler.cs" /> Added: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramSort.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramSort.cs (rev 0) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramSort.cs 2007-06-10 20:11:31 UTC (rev 509) @@ -0,0 +1,163 @@ +#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.Globalization; + +using MediaPortal.GUI.Library; +using MediaPortal.Util; + +using GUIPrograms.Database; +using GUIPrograms.FileItems; + +namespace GUIPrograms +{ + /// <summary> + /// Summary description for ProgramSort. + /// </summary> + public class ProgramSort : IComparer<GUIListItem> + { + public enum SortMethod + { + Name = 0, + Title = 1, + Filename = 2, + Rating = 3, + LaunchCount = 4, + LastTimeLaunched = 5 + } + + SortMethod currentSortMethod; + bool sortAscending = true; + + public ProgramSort(SortMethod method, bool ascending) + { + currentSortMethod = method; + sortAscending = ascending; + } + + public int Compare(GUIListItem item1, GUIListItem item2) + { + if (item1 == item2) return 0; + if (item1 == null) return -1; + if (item2 == null) return -1; + if (item1.IsFolder && item1.Label == "..") return -1; + if (item2.IsFolder && item2.Label == "..") return -1; + if (item1.IsFolder && !item2.IsFolder) return -1; + else if (!item1.IsFolder && item2.IsFolder) return 1; + + string strSize1 = ""; + string strSize2 = ""; + if (item1.FileInfo != null) strSize1 = MediaPortal.Util.Utils.GetSize(item1.FileInfo.Length); + if (item2.FileInfo != null) strSize2 = MediaPortal.Util.Utils.GetSize(item2.FileInfo.Length); + + SortMethod method = currentSortMethod; + bool bAscending = sortAscending; + + switch (method) + { + case SortMethod.Name: + if (bAscending) + { + return String.Compare(item1.Label, item2.Label, true); + } + else + { + return String.Compare(item2.Label, item1.Label, true); + } + + case SortMethod.Title: + string strTitle1 = item1.Label; + string strTitle2 = item2.Label; + if (item1.MusicTag != null) strTitle1 = ((FileItem)item1.MusicTag).Title; + if (item2.MusicTag != null) strTitle2 = ((FileItem)item2.MusicTag).Title; + if (bAscending) + { + return String.Compare(strTitle1, strTitle2, true); + } + else + { + return String.Compare(strTitle2, strTitle1, true); + } + + case SortMethod.Filename: + string strFile1 = MediaPortal.Util.Utils.GetFilename(item1.Path); + string strFile2 = MediaPortal.Util.Utils.GetFilename(item2.Path); + if (bAscending) + { + return String.Compare(strFile1, strFile2, true); + } + else + { + return String.Compare(strFile2, strFile1, true); + } + + case SortMethod.Rating: + int iRating1 = 0; + int iRating2 = 0; + if (item1.MusicTag != null) iRating1 = ((FileItem)item1.MusicTag).Rating; + if (item2.MusicTag != null) iRating2 = ((FileItem)item2.MusicTag).Rating; + if (bAscending) + { + return (int)(iRating1 - iRating2); + } + else + { + return (int)(iRating2 - iRating1); + } + + case SortMethod.LaunchCount: + int iLaunchCount1 = 0; + int iLaunchCount2 = 0; + if (item1.MusicTag != null) iLaunchCount1 = ((FileItem)item1.MusicTag).LaunchCount; + if (item2.MusicTag != null) iLaunchCount2 = ((FileItem)item2.MusicTag).LaunchCount; + if (bAscending) + { + return (int)(iLaunchCount1 - iLaunchCount2); + } + else + { + return (int)(iLaunchCount2 - iLaunchCount1); + } + + case SortMethod.LastTimeLaunched: + DateTime dateLastTimeLaunched1 = DateTime.MinValue; + DateTime dateLastTimeLaunched2 = DateTime.MinValue; + if (item1.MusicTag != null) dateLastTimeLaunched1 = ((FileItem)item1.MusicTag).LastTimeLaunched; + if (item2.MusicTag != null) dateLastTimeLaunched2 = ((FileItem)item2.MusicTag).LastTimeLaunched; + if (bAscending) + { + return DateTime.Compare(dateLastTimeLaunched1, dateLastTimeLaunched2); + } + else + { + return DateTime.Compare(dateLastTimeLaunched2, dateLastTimeLaunched1); + } + } + return 0; + } + } +} \ No newline at end of file Modified: trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramViewHandler.cs =================================================================== --- trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramViewHandler.cs 2007-06-10 17:45:25 UTC (rev 508) +++ trunk/plugins/myGUIProgramsAlt/GUIProgramsAlt/ProgramViewHandler.cs 2007-06-10 20:11:31 UTC (rev 509) @@ -24,18 +24,19 @@ #endregion using System; +using System.Collections; using System.Collections.Generic; -using System.Collections; using System.IO; using System.Runtime.Serialization.Formatters.Soap; +using SQLite.NET; + +using MediaPortal.Configuration; +using MediaPortal.Database; using MediaPortal.GUI.Library; +using MediaPortal.GUI.View; using MediaPortal.Util; -using MediaPortal.GUI.View; -using MediaPortal.Database; using GUIPrograms.Database; -using SQLite.NET; -using MediaPortal.Configuration; namespace GUIPrograms { @@ -44,17 +45,21 @@ /// </summary> public class ProgramViewHandler { + #region Variables string defaultProgramViews = Config.GetFile(Config.Dir.Base, "defaultMyProgramsAltViews.xml"); string customProgramViews = Config.GetFile(Config.Dir.Config, "myProgramsAltViews.xml"); + int currentLevel = 0; ViewDefinition currentView = null; - int currentLevel = 0; - ArrayList views = new ArrayList(); + List<ViewDefinition> views = new List<ViewDefinition>(); + #endregion Variables + + #region Constructor + public ProgramViewHandler() { - //create default views if file not exist if (!System.IO.File.Exists(defaultProgramViews)) { @@ -143,11 +148,21 @@ formatter.Serialize(fileStream, listViews); fileStream.Close(); } + } - } if (!File.Exists(customProgramViews)) { - File.Copy(defaultProgramViews, customProgramViews); + Log.Info("Warning: customProgramViews not found!"); + if (File.Exists(defaultProgramViews)) + { + Log.Info("Warning: defaultProgramViews will be restored!"); + File.Copy(defaultProgramViews, customProgramViews); + } + else + { + Log.Info("Warning: defaultProgramViews not found, please reinstall this plugin!"); + return; + } } if (System.IO.File.Exists(customProgramViews)) @@ -157,8 +172,9 @@ try { SoapFormatter formatter = new SoapFormatter(); - views = (ArrayList)formatter.Deserialize(fileStream); - fileStream.Close(); + ArrayList viewlist = (ArrayList)formatter.Deserialize(fileStream); + foreach (ViewDefinition view in viewlist) + views.Add(view); } catch { @@ -167,19 +183,32 @@ } } + #endregion Constructor + + #region Properties / Helper Routines + public ViewDefinition View { get { return currentView; } set { currentView = value; } } - - public ArrayList Views + public List<ViewDefinition> Views { get { return views; } set { views = value; } } + public string LocalizedCurrentView + { + get + { + if (currentView == null) + return String.Empty; + return currentView.LocalizedName; + } + } + public string CurrentView { get @@ -247,6 +276,8 @@ } } + #endregion Properties / Helper Routines + public bool AddFilterItem(ProgramFilterItem filterItem) { bool res = false; @@ -271,13 +302,12 @@ return res; } - public string BuildQuery(int appID, string pathSubfolders) { SQLSelectBuilder sqlSelect = new SQLSelectBuilder(); // build the SQL query respecting all the filters and let // the query be executed from outside (this is different from MusicViewHandler) - sqlSelect.AddTable("tblFileItem"); + sqlSelect.AddTable("tblfile"); sqlSelect.AddWhereCond(String.Format("appid = {0}", appID)); if (currentView == null) { @@ -286,7 +316,7 @@ // a: "select file.*, '' as title2, '' as fieldtype2 from file where appid = {0} order by isfolder desc, uppertitle" // b: "select file.*, '' as title2, '' as fieldtype2 from file where appid = {0} and filepath = '{1}' order by isfolder desc, uppertitle" - sqlSelect.AddField("tblFileItem.*"); + sqlSelect.AddField("tblfile.*"); sqlSelect.AddField("'' as title2"); sqlSelect.AddField("'' as fieldtype2"); if (pathSubfolders != "") @@ -334,7 +364,7 @@ { return @"SELECT UPPER(SUBSTR(" + currentViewFilterFieldVariable + ",1," + currentViewFilterFieldRestriction + @")) AS title, - COUNT(*) FROM tblFileItem WHERE appid = " + appID + @" + COUNT(*) FROM tblfile WHERE appid = " + appID + @" GROUP BY UPPER(SUBSTR(title,1," + currentViewFilterFieldRestriction + @")) @@ -365,7 +395,7 @@ UPPER(SUBSTR(" + currentViewFilterFieldVariable + ",1," + currentViewFilterFieldRestriction + @")) AS title, Count(*) - FROM tblFileItem + FROM tblfile WHERE appid = " + appID + @" @@ -376,7 +406,7 @@ UPPER(SUBSTR(" + prevViewFilterFieldVariable + ",1," + prevViewFilterRestriciton + @")) AS title FROM - tblFileItem + tblfile WHERE appid = " + appID + @" @@ -397,11 +427,11 @@ else { return @"SELECT - tblFileItem.*, + tblfile.*, 'STR' AS fieldtype FROM - tblFileItem + tblfile WHERE UPPER(SUBSTR(" + prevViewFilterFieldVariable + ",1," + prevViewFilterRestriciton + @")) LIKE '" + prevViewFilterFieldSelectedValue + @"%' @@ -419,7 +449,6 @@ void BuildGroup(FilterDefinition filter, SQLSelectBuilder sqlSelect) { - sqlSelect.AddGroupField(" UPPER(SUBSTR(title,1,1)), Count(*) "); } @@ -494,7 +523,6 @@ } } - void BuildOrder(FilterDefinition filter, SQLSelectBuilder sqlSelect) { string orderClause = GetField(filter.Where); @@ -569,18 +597,18 @@ string res = ""; if (where == "launchcount") { - res = "tblFileItem.*"; + res = "tblfile.*"; } else if (where == "lastTimeLaunched") { - res = "tblFileItem.*"; + res = "tblfile.*"; } else { res = GetFieldName(where); if (res == "") { - res = "tblFileItem.*"; + res = "tblfile.*"; } else { @@ -650,7 +678,6 @@ else return false; } - string GetFieldValue(ProgramFilterItem filterItem, string where) { return filterItem.Title; @@ -665,7 +692,6 @@ */ } - public void SetLabel(ProgramFilterItem filterItem, ref GUIListItem guiListItem) { if (filterItem == null) return; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |