/[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

revision 143 by william, Thu Mar 14 13:43:21 2013 UTC revision 248 by william, Fri Mar 22 16:41:42 2013 UTC
# Line 1  Line 1 
1  //#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
2  //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode  //#define DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG // when defined will turn off kLogLevel_VerboseDebug message, in debug mode
3  //#define USE_DYNAMIC_SORTING_FILTERING_CONTROLS // when defined will setup dynamic sorting and filtering controls for XMLTV Data  //#define USE_DYNAMIC_SORTING_FILTERING_CONTROLS // when defined will setup dynamic sorting and filtering controls for XMLTV Data
4  using System;  using System;
# Line 23  namespace xmltv_parser Line 23  namespace xmltv_parser
23    
24      public partial class main : Form      public partial class main : Form
25      {      {
26            const long MAX_LOG_FILESIZE_IN_BYTES = 250000; //250kb max
27            void TruncateLogFile(FileInfo log_file)
28            {
29                if (!log_file.Exists)
30                {
31                    gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
32                }
33                else
34                {
35                    if (log_file.Length > MAX_LOG_FILESIZE_IN_BYTES)
36                    {
37                        string match = string.Format("{0}.*", log_file.Name);
38                        var files = Directory.GetFiles(log_file.Directory.FullName, match).ToList();
39                        files.RemoveAt(0);
40                        files.TrimExcess();
41                        int count = files.Count;
42                        if (log_file.Exists)
43                        {
44                            File.Copy(log_file.FullName, string.Format("{0}.{1}", log_file.FullName, count));
45                        }
46                        gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
47                    }
48                    else
49                    {
50                        gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
51                    }
52                }
53            }
54    
55          public main()          public main()
56          {          {
57              InitializeComponent();              InitializeComponent();
58              ListViewSorter Sorter = new ListViewSorter();              ListViewSorter Sorter = new ListViewSorter();
59              //lstPrograms.ListViewItemSorter = Sorter;              //lstPrograms.ListViewItemSorter = Sorter;
60    
61              string log_path = Application.StartupPath;              string log_path = Application.StartupPath;
62              string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);              string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
63              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));
64                TruncateLogFile(log_file);            
65  #if DEBUG  #if DEBUG
66              LogLevel gLevel = gLog.LogLevel;              LogLevel gLevel = gLog.LogLevel;
67  #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG  #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
# Line 179  namespace xmltv_parser Line 210  namespace xmltv_parser
210          #endregion          #endregion
211    
212    
213          #region t          #region CreateControls
214            void AutoResizeDataGridView()
215            {
216                //dataGrid.AutoResizeRow(2, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
217            
218                for (int i = 0; i < dataGrid.ColumnCount; i++)
219                {
220                    dataGrid.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
221                }
222                //for (int i = 0; i < dataGrid.RowCount; i++)
223                //{
224                //    dataGrid.AutoResizeRow(i, DataGridViewAutoSizeRowMode.AllCellsExceptHeader);
225                //}
226            }
227          void CreateControls()          void CreateControls()
228          {          {
229              try              try
# Line 192  namespace xmltv_parser Line 236  namespace xmltv_parser
236                  }                  }
237                  Type data_type;                  Type data_type;
238                  object datasource = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);                  object datasource = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
239                  CreatControlsFromType(data_type);                  CreatControlsFromType(data_type);                
                 //XMLTV.CreateSorterFromDataSource(ref datasource, "title");  
240                  dataGrid.DataSource = datasource;                  dataGrid.DataSource = datasource;
241                    AutoResizeDataGridView();
242                  flow_datagrid_sort.Enabled = true;                  flow_datagrid_sort.Enabled = true;
243                  btnSort.PerformClick();                  btnSort.PerformClick();
244              }              }
# Line 207  namespace xmltv_parser Line 251  namespace xmltv_parser
251  #if USE_DYNAMIC_SORTING_FILTERING_CONTROLS  #if USE_DYNAMIC_SORTING_FILTERING_CONTROLS
252                _CreatControlsFromType(data_type);                _CreatControlsFromType(data_type);
253  #else  #else
254              gLog.Warn.WriteLine("Dynamic creation of sorting and filtering controls has not been enabled.");              gLog.Verbose.Warn.WriteLine("Dynamic creation of sorting and filtering controls has not been enabled.");
255              gLog.Warn.WriteLine("To enable: #define USE_DYNAMIC_SORTING_FILTERING_CONTROLS");              gLog.Verbose.Warn.WriteLine("To enable: #define USE_DYNAMIC_SORTING_FILTERING_CONTROLS");
256  #endif  #endif
257          }          }
258          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
# Line 227  namespace xmltv_parser Line 271  namespace xmltv_parser
271          void CreateDefaultControls(Type data_type)          void CreateDefaultControls(Type data_type)
272          {          {
273              // no default controls              // no default controls
274              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);
275          }          }
276          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
277          void CreateSourceDefinitionControls(Type data_type)          void CreateSourceDefinitionControls(Type data_type)
278          {          {
279              // no controls needed              // no controls needed
280              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);
281          }          }
282          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
283          void CreateChannelDefinitionControls(Type data_type)          void CreateChannelDefinitionControls(Type data_type)
284          {          {
285              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);
286          }          }
287          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]          [Conditional("USE_DYNAMIC_SORTING_FILTERING_CONTROLS")]
288          void CreateProgramDefinitionControls(Type data_type)          void CreateProgramDefinitionControls(Type data_type)
289          {          {
290              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);
291          }          }
292          #endregion          #endregion
293    
294            #region Program Entry Display        
295            private int CurrentRowIndex = -1;
296            void DisplaySelectedProgramEntry(DataGridViewRow row)
297            {
298                int RowIndex = row.Index; // this is the index in the list
299    
300                //if (CurrentRowIndex == -1) { AlreadyDisplayedProgramEntryForIndex = false; CurrentRowIndex = RowIndex; }
301                //if (CurrentRowIndex == RowIndex && AlreadyDisplayedProgramEntryForIndex) {
302                bool DoDisplay = false;
303                if (CurrentRowIndex == -1)
304                {
305                    DoDisplay = true;
306                }
307                if (CurrentRowIndex == RowIndex)
308                {
309                    DoDisplay = false;
310                }
311                else
312                {
313                    DoDisplay = true;
314                }
315    
316                if (DoDisplay)
317                {
318                     CurrentRowIndex = RowIndex;
319                    List<IProgramDefinition> list = (dataGrid.DataSource as List<IProgramDefinition>);
320                    if (list == null)
321                    {
322                        gLog.Warn.WriteLine("Unable to display program entry for rowindex: {0}", RowIndex);
323                      
324                        return;
325                    }
326                    try
327                    {
328                        IProgramDefinition program = list[RowIndex];
329                        ProgramEntryControl c = new ProgramEntryControl(program);
330                        c.Dock = DockStyle.Fill;
331                        split_bottom.Panel2.Controls.Clear();
332                        split_bottom.Panel2.Controls.Add(c);                    
333                    }
334                    catch (Exception ex)
335                    {
336                        gLog.Error.WriteLine(ex.ToString());
337                    }
338                }
339            }
340            #endregion
341          #region Datasource support / events          #region Datasource support / events
342          private void dataGrid_SelectionChanged(object sender, EventArgs e)          private void dataGrid_SelectionChanged(object sender, EventArgs e)
343          {          {
# Line 273  namespace xmltv_parser Line 364  namespace xmltv_parser
364                      int index = GetColumnIndexForRadioButton(button);                      int index = GetColumnIndexForRadioButton(button);
365                      data = row.Cells[index].Value.ToString();                      data = row.Cells[index].Value.ToString();
366                      txtFilterText.Text = data;                      txtFilterText.Text = data;
367                        DisplaySelectedProgramEntry(row);
368                  }                  }
369              }              }
370              catch (Exception ex)              catch (Exception ex)
# Line 312  namespace xmltv_parser Line 404  namespace xmltv_parser
404              object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);              object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
405              XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);              XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);
406              dataGrid.DataSource = data;              dataGrid.DataSource = data;
407                dataGrid_SelectionChanged(dataGrid, new EventArgs());
408          }          }
409          private RadioButton GetSelectedFilteringControl()          private RadioButton GetSelectedFilteringControl()
410          {          {
# Line 325  namespace xmltv_parser Line 418  namespace xmltv_parser
418              }              }
419              if (!control_selected)              if (!control_selected)
420              {              {
421                  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.");
422                  //throw new InvalidOperationException("No filtering control is currently selected.");                  //throw new InvalidOperationException("No filtering control is currently selected.");
423                  return button;                  return button;
424              }              }
# Line 392  namespace xmltv_parser Line 485  namespace xmltv_parser
485              RadioButton radio = (sender as RadioButton);              RadioButton radio = (sender as RadioButton);
486              UpdateFilterText(radio, dataGrid);              UpdateFilterText(radio, dataGrid);
487          }          }
488            private void radio_filter_rating_CheckedChanged(object sender, EventArgs e)
489            {
490                RadioButton radio = (sender as RadioButton);
491                UpdateFilterText(radio, dataGrid);
492            }
493          #endregion          #endregion
494          #region Sorting events          #region Sorting events
495          private bool Descending = false;          private bool Descending = false;
# Line 403  namespace xmltv_parser Line 501  namespace xmltv_parser
501              XMLTV.CreateSorterFromDataSource(ref data, Descending, column);              XMLTV.CreateSorterFromDataSource(ref data, Descending, column);
502              dataGrid.DataSource = data;              dataGrid.DataSource = data;
503              ToggleDescedning();              ToggleDescedning();
504                dataGrid_SelectionChanged(dataGrid, new EventArgs());
505          }          }
506          private RadioButton GetSelectedSortControl()          private RadioButton GetSelectedSortControl()
507          {          {
# Line 428  namespace xmltv_parser Line 527  namespace xmltv_parser
527              SortByColumn(button);              SortByColumn(button);
528          }          }
529          #endregion          #endregion
530    
531            private void dataGrid_Click(object sender, EventArgs e)
532            {
533                dataGrid_SelectionChanged(dataGrid, new EventArgs());
534            }
535    
536          
537      }      }
538  }  }
539    

Legend:
Removed from v.143  
changed lines
  Added in v.248

  ViewVC Help
Powered by ViewVC 1.1.22