/[xmltv_parser]/trunk/xmltv_parser/main.cs
ViewVC logotype

Diff of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/xmltv_parser/main.cs	2013/03/14 13:57:36	145
+++ trunk/xmltv_parser/main.cs	2013/03/22 16:41:42	248
@@ -1,4 +1,4 @@
-//#define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
+#define DISABLE_RELEASE_MODE_KLOGLEVEL_DEBUG // when defined will turn off kLogLevel_Debug messages, in release mode
 //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
 //#define USE_DYNAMIC_SORTING_FILTERING_CONTROLS // when defined will setup dynamic sorting and filtering controls for XMLTV Data
 using System;
@@ -23,14 +23,45 @@
 
     public partial class main : Form
     {
+        const long MAX_LOG_FILESIZE_IN_BYTES = 250000; //250kb max
+        void TruncateLogFile(FileInfo log_file)
+        {
+            if (!log_file.Exists)
+            {
+                gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+            }
+            else
+            {
+                if (log_file.Length > MAX_LOG_FILESIZE_IN_BYTES)
+                {
+                    string match = string.Format("{0}.*", log_file.Name);
+                    var files = Directory.GetFiles(log_file.Directory.FullName, match).ToList();
+                    files.RemoveAt(0);
+                    files.TrimExcess();
+                    int count = files.Count;
+                    if (log_file.Exists)
+                    {
+                        File.Copy(log_file.FullName, string.Format("{0}.{1}", log_file.FullName, count));
+                    }
+                    gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+                }
+                else
+                {
+                    gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+                }
+            }
+        }
+
         public main()
         {
             InitializeComponent();
             ListViewSorter Sorter = new ListViewSorter();
             //lstPrograms.ListViewItemSorter = Sorter;
+
             string log_path = Application.StartupPath;
             string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
-            gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+            FileInfo log_file = new FileInfo(string.Format(@"{0}\{1}", log_path, log_filename));
+            TruncateLogFile(log_file);            
 #if DEBUG
             LogLevel gLevel = gLog.LogLevel;
 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
@@ -179,7 +210,7 @@
         #endregion
 
 
-        #region t
+        #region CreateControls
         void AutoResizeDataGridView()
         {
             //dataGrid.AutoResizeRow(2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
@@ -188,10 +219,10 @@
             {
                 dataGrid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
             }
-            for (int i = 0; i < dataGrid.RowCount; i++)
-            {
-                dataGrid.AutoResizeRow(i, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
-            }
+            //for (int i = 0; i < dataGrid.RowCount; i++)
+            //{
+            //    dataGrid.AutoResizeRow(i, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
+            //}
         }
         void CreateControls()
         {
@@ -220,8 +251,8 @@
 #if USE_DYNAMIC_SORTING_FILTERING_CONTROLS
               _CreatControlsFromType(data_type);
 #else
-            gLog.Warn.WriteLine("Dynamic creation of sorting and filtering controls has not been enabled.");
-            gLog.Warn.WriteLine("To enable: #define USE_DYNAMIC_SORTING_FILTERING_CONTROLS");
+            gLog.Verbose.Warn.WriteLine("Dynamic creation of sorting and filtering controls has not been enabled.");
+            gLog.Verbose.Warn.WriteLine("To enable: #define USE_DYNAMIC_SORTING_FILTERING_CONTROLS");
 #endif
         }
         [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
@@ -240,26 +271,73 @@
         void CreateDefaultControls(Type data_type)
         {
             // no default controls
-            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+            gLog.Verbose.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
         }
         [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
         void CreateSourceDefinitionControls(Type data_type)
         {
             // no controls needed
-            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+            gLog.Verbose.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
         }
         [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
         void CreateChannelDefinitionControls(Type data_type)
         {
-            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+            gLog.Verbose.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
         }
         [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
         void CreateProgramDefinitionControls(Type data_type)
         {
-            gLog.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
+            gLog.Verbose.Warn.WriteLine("No controls have been defined for: {0}", data_type.Name);
         }
         #endregion
 
+        #region Program Entry Display        
+        private int CurrentRowIndex = -1;
+        void DisplaySelectedProgramEntry(DataGridViewRow row)
+        {
+            int RowIndex = row.Index; // this is the index in the list
+
+            //if (CurrentRowIndex == -1) { AlreadyDisplayedProgramEntryForIndex = false; CurrentRowIndex = RowIndex; }
+            //if (CurrentRowIndex == RowIndex && AlreadyDisplayedProgramEntryForIndex) { 
+            bool DoDisplay = false;
+            if (CurrentRowIndex == -1)
+            {
+                DoDisplay = true;
+            }
+            if (CurrentRowIndex == RowIndex)
+            {
+                DoDisplay = false;
+            }
+            else
+            {
+                DoDisplay = true;
+            }
+
+            if (DoDisplay)
+            {
+                 CurrentRowIndex = RowIndex;
+                List<IProgramDefinition> list = (dataGrid.DataSource as List<IProgramDefinition>);
+                if (list == null)
+                {
+                    gLog.Warn.WriteLine("Unable to display program entry for rowindex: {0}", RowIndex);
+                   
+                    return;
+                }
+                try
+                {
+                    IProgramDefinition program = list[RowIndex];
+                    ProgramEntryControl c = new ProgramEntryControl(program);
+                    c.Dock = DockStyle.Fill;
+                    split_bottom.Panel2.Controls.Clear();
+                    split_bottom.Panel2.Controls.Add(c);                    
+                }
+                catch (Exception ex)
+                {
+                    gLog.Error.WriteLine(ex.ToString());
+                }
+            }
+        }
+        #endregion
         #region Datasource support / events
         private void dataGrid_SelectionChanged(object sender, EventArgs e)
         {
@@ -286,6 +364,7 @@
                     int index = GetColumnIndexForRadioButton(button);
                     data = row.Cells[index].Value.ToString();
                     txtFilterText.Text = data;
+                    DisplaySelectedProgramEntry(row);
                 }
             }
             catch (Exception ex)
@@ -325,6 +404,7 @@
             object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
             XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);
             dataGrid.DataSource = data;
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
         }
         private RadioButton GetSelectedFilteringControl()
         {
@@ -338,7 +418,7 @@
             }
             if (!control_selected)
             {
-                gLog.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, description, start, or stop.");
+                gLog.Verbose.Warn.WriteLine("Unkown filter value used.  Was not: channelname, title, subtitle, description, start, or stop.");
                 //throw new InvalidOperationException("No filtering control is currently selected.");
                 return button;
             }
@@ -405,6 +485,11 @@
             RadioButton radio = (sender as RadioButton);
             UpdateFilterText(radio, dataGrid);
         }
+        private void radio_filter_rating_CheckedChanged(object sender, EventArgs e)
+        {
+            RadioButton radio = (sender as RadioButton);
+            UpdateFilterText(radio, dataGrid);
+        }
         #endregion
         #region Sorting events
         private bool Descending = false;
@@ -416,6 +501,7 @@
             XMLTV.CreateSorterFromDataSource(ref data, Descending, column);
             dataGrid.DataSource = data;
             ToggleDescedning();
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
         }
         private RadioButton GetSelectedSortControl()
         {
@@ -441,6 +527,13 @@
             SortByColumn(button);
         }
         #endregion
+
+        private void dataGrid_Click(object sender, EventArgs e)
+        {
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
+        }
+
+       
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22