/[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/08 13:40:32	59
+++ trunk/xmltv_parser/main.cs	2013/03/08 14:26:48	63
@@ -28,6 +28,8 @@
         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));
@@ -51,7 +53,7 @@
         private void gLog_ReportProgress(object sender, ReportProgressEventArgs e) { ReportProgress(e.Progress); }
 
         StringBuilder log_flusher = new StringBuilder();
-        
+
         void Log_OnFlush(object sender, LoggerOnFlushEventArgs e)
         {
             OnLogFlush(e.Buffer);
@@ -75,7 +77,7 @@
         }
 
         void UpdateStatus(string logmessage)
-        {            
+        {
             txtStatus.Text = logmessage.Replace(System.Environment.NewLine, "");
         }
         void UpdateLogOutput(string logmessage)
@@ -111,7 +113,7 @@
         {
             //XMLTV.CreateInstance(schedule_xml, new EventHandler<CancelEventArgs>(xmltv_cancelevent));
             XMLTV.CreateInstance(schedule_xml);
-            XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated);           
+            XMLTV.OnInstanceCreated += new EventHandler<EventArgs>(XMLTV_OnInstanceCreated);
         }
 
         void XMLTV_OnInstanceCreated(object sender, EventArgs e)
@@ -144,16 +146,21 @@
                 this.Invoke((Action)(delegate { CreateControls(); }));
                 return;
             }
+            List<ListViewItem> items = new List<ListViewItem>();
             foreach (var program in Programs)
             {
                 ListViewItem li = new ListViewItem(string.Format("{0} {1}", program.Channel.Number, program.Channel.CallSign));
+                li.Tag = program;
                 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Title));
                 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.SubTitle));
                 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Description));
                 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Start.ToString("yyyy/MM/dd hh:mm tt")));
                 li.SubItems.Add(new ListViewItem.ListViewSubItem(li, program.Stop.ToString("yyyy/MM/dd hh:mm tt")));
-                lstPrograms.Items.Add(li);
+                //lstPrograms.Items.Add(li);
+                items.Add(li);
             }
+
+            lstPrograms.Items.AddRange(items.ToArray());
         }
 
         private void mnuItemOpenXMLTVFile_Click(object sender, EventArgs e)
@@ -246,6 +253,33 @@
             this.Close();
         }
 
+        private void lstPrograms_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            IXMLTVProgram program = null;
+            var item = lstPrograms.SelectedItems[0];
+            int selected_index = lstPrograms.Items.IndexOf(item);
+            program = (item.Tag as IXMLTVProgram);
+            gLog.Debug.WriteLine("Selected ListViewItem at index: {0}", selected_index);
+            if (program == null) { return; }
+            txtStatus.Text = program.ToString();
+            //gLog.Debug.WriteLine(program.ToString());
+
+        }
+
+        private void lstPrograms_ColumnClick(object sender, ColumnClickEventArgs e)
+        {
+            if (!(lstPrograms.ListViewItemSorter is ListViewSorter)) return;
+            ListViewSorter Sorter = (ListViewSorter)lstPrograms.ListViewItemSorter;
+            Sorter.LastColumn = Sorter.CurrentColumn;
+            Sorter.CurrentColumn = e.Column;
+            if (Sorter.LastColumn == e.Column)
+            {
+                if (lstPrograms.Sorting == SortOrder.Ascending) { lstPrograms.Sorting = SortOrder.Descending; }
+                else { lstPrograms.Sorting = SortOrder.Ascending; }
+            }
+            else { lstPrograms.Sorting = SortOrder.Descending; }
+            lstPrograms.Sort();
+        }
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22