Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

features eliminated: animated window when minimizaed to system tray, …

…mutex to run a single instance.

active and inactive time columns added at the summary view.
  • Loading branch information...
commit d28d97c0b917a91f837404bf0afb43891ce5bc2c 1 parent 393f934
authored March 14, 2008
228  code/PTM/MainClass.cs
@@ -22,7 +22,7 @@ internal sealed class MainClass
22 22
 		/// <summary>
23 23
 		/// Boolean value to store single instance configuration 
24 24
 		/// </summary>
25  
-		private static bool runSingleInstance = true;
  25
+		//private static bool runSingleInstance = true;
26 26
 
27 27
 		/// <summary>
28 28
 		/// MemoryMappedFile to share between instances
@@ -45,14 +45,14 @@ private static void Main()
45 45
 		{
46 46
 			try
47 47
 			{
48  
-				if (runSingleInstance)
49  
-				{
50  
-					RunSingleInstance();
51  
-				}
52  
-				else
53  
-				{
  48
+                //if (runSingleInstance)
  49
+                //{
  50
+                //    RunSingleInstance();
  51
+                //}
  52
+                //else
  53
+                //{
54 54
 					Launch();
55  
-				} //if-else
  55
+				//} //if-else
56 56
 			}
57 57
 			catch(Exception ex)
58 58
 			{
@@ -64,89 +64,89 @@ private static void Main()
64 64
 			}
65 65
 		} //Main
66 66
 
67  
-		/// <summary>
68  
-		/// Validates that no other application is runnin.
69  
-		/// </summary>
70  
-		private static void RunSingleInstance()
71  
-		{
72  
-			// Used to check if we can create a new mutex
73  
-			bool newMutexCreated = false;
74  
-			// The name of the mutex is to be prefixed with Local\ to make sure that its is created in the per-session namespace, not in the global namespace.
75  
-			string mutexName = "Local\\" + Assembly.GetExecutingAssembly().GetName().Name;
76  
-
77  
-			Mutex mutex = null;
78  
-			try
79  
-			{
80  
-				// Create a new mutex object with a unique name
81  
-				mutex = new Mutex(false, mutexName, out newMutexCreated);
82  
-			}
83  
-			catch (Exception ex)
84  
-			{
85  
-				MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown",
86  
-				                MessageBoxButtons.OK, MessageBoxIcon.Error);
87  
-				Application.Exit();
88  
-			} //try-catch
89  
-
90  
-			// When the mutex is created for the first time we run the program since it is the first instance.
91  
-			if (newMutexCreated)
92  
-			{
93  
-				//Create the Shared Memory to store the window handle. This memory is shared between processes
94  
-				lock (typeof (MainForm))
95  
-				{
96  
-					sharedMemory = MemoryMappedFile.CreateMMF(
97  
-						"Local\\sharedMemoryPTM",
98  
-						MemoryMappedFile.FileAccess.ReadWrite, 8);
99  
-				} //lock
100  
-				Launch();
101  
-			}
102  
-			else
103  
-				// If the mutex already exists, no need to launch a new instance of the program because a previous instance is running .
104  
-			{
105  
-				try
106  
-				{
107  
-					// Get the Program's main window handle, which was previously stored in shared memory.
108  
-					IntPtr mainWindowHandle = IntPtr.Zero;
109  
-					lock (typeof (MainForm))
110  
-					{
111  
-						mainWindowHandle = MemoryMappedFile.ReadHandle(
112  
-							"Local\\sharedMemoryPTM");
113  
-					} //lock
114  
-					if (mainWindowHandle != IntPtr.Zero)
115  
-					{
116  
-						if (ViewHelper.IsIconic(mainWindowHandle))
117  
-						{
118  
-							// Restore the Window 
119  
-							ViewHelper.ShowWindow(mainWindowHandle, ViewHelper.SW_SHOWNORMAL);
120  
-						}
121  
-						else
122  
-						{
123  
-							// Restore the Window 
124  
-							ViewHelper.ShowWindow(mainWindowHandle, ViewHelper.SW_RESTORE);
125  
-						} //if-else
126  
-						ViewHelper.UpdateWindow(mainWindowHandle);
127  
-					} //if
128  
-					return;
129  
-				}
130  
-				catch (Exception ex)
131  
-				{
132  
-					MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown");
133  
-				} //try-catch
134  
-
135  
-				// Tell the garbage collector to keep the Mutex alive until the code 
136  
-				//execution reaches this point, ie. normally when the program is exiting.
137  
-				GC.KeepAlive(mutex);
138  
-				// Release the Mutex 
139  
-				try
140  
-				{
141  
-					mutex.ReleaseMutex();
142  
-				}
143  
-				catch (ApplicationException ex)
144  
-				{
145  
-					MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Exception thrown");
146  
-					GC.Collect();
147  
-				} //try-catch
148  
-			} //if-else
149  
-		} //RunSingleInstance
  67
+        ///// <summary>
  68
+        ///// Validates that no other application is runnin.
  69
+        ///// </summary>
  70
+        //private static void RunSingleInstance()
  71
+        //{
  72
+        //    // Used to check if we can create a new mutex
  73
+        //    bool newMutexCreated = false;
  74
+        //    // The name of the mutex is to be prefixed with Local\ to make sure that its is created in the per-session namespace, not in the global namespace.
  75
+        //    string mutexName = "Local\\" + Assembly.GetExecutingAssembly().GetName().Name;
  76
+
  77
+        //    Mutex mutex = null;
  78
+        //    try
  79
+        //    {
  80
+        //        // Create a new mutex object with a unique name
  81
+        //        mutex = new Mutex(false, mutexName, out newMutexCreated);
  82
+        //    }
  83
+        //    catch (Exception ex)
  84
+        //    {
  85
+        //        MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown",
  86
+        //                        MessageBoxButtons.OK, MessageBoxIcon.Error);
  87
+        //        Application.Exit();
  88
+        //    } //try-catch
  89
+
  90
+        //    // When the mutex is created for the first time we run the program since it is the first instance.
  91
+        //    if (newMutexCreated)
  92
+        //    {
  93
+        //        //Create the Shared Memory to store the window handle. This memory is shared between processes
  94
+        //        lock (typeof (MainForm))
  95
+        //        {
  96
+        //            sharedMemory = MemoryMappedFile.CreateMMF(
  97
+        //                "Local\\sharedMemoryPTM",
  98
+        //                MemoryMappedFile.FileAccess.ReadWrite, 8);
  99
+        //        } //lock
  100
+        //        Launch();
  101
+        //    }
  102
+        //    else
  103
+        //        // If the mutex already exists, no need to launch a new instance of the program because a previous instance is running .
  104
+        //    {
  105
+        //        try
  106
+        //        {
  107
+        //            // Get the Program's main window handle, which was previously stored in shared memory.
  108
+        //            IntPtr mainWindowHandle = IntPtr.Zero;
  109
+        //            lock (typeof (MainForm))
  110
+        //            {
  111
+        //                mainWindowHandle = MemoryMappedFile.ReadHandle(
  112
+        //                    "Local\\sharedMemoryPTM");
  113
+        //            } //lock
  114
+        //            if (mainWindowHandle != IntPtr.Zero)
  115
+        //            {
  116
+        //                if (ViewHelper.IsIconic(mainWindowHandle))
  117
+        //                {
  118
+        //                    // Restore the Window 
  119
+        //                    ViewHelper.ShowWindow(mainWindowHandle, ViewHelper.SW_SHOWNORMAL);
  120
+        //                }
  121
+        //                else
  122
+        //                {
  123
+        //                    // Restore the Window 
  124
+        //                    ViewHelper.ShowWindow(mainWindowHandle, ViewHelper.SW_RESTORE);
  125
+        //                } //if-else
  126
+        //                ViewHelper.UpdateWindow(mainWindowHandle);
  127
+        //            } //if
  128
+        //            return;
  129
+        //        }
  130
+        //        catch (Exception ex)
  131
+        //        {
  132
+        //            MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown");
  133
+        //        } //try-catch
  134
+
  135
+        //        // Tell the garbage collector to keep the Mutex alive until the code 
  136
+        //        //execution reaches this point, ie. normally when the program is exiting.
  137
+        //        GC.KeepAlive(mutex);
  138
+        //        // Release the Mutex 
  139
+        //        try
  140
+        //        {
  141
+        //            mutex.ReleaseMutex();
  142
+        //        }
  143
+        //        catch (ApplicationException ex)
  144
+        //        {
  145
+        //            MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Exception thrown");
  146
+        //            GC.Collect();
  147
+        //        } //try-catch
  148
+        //    } //if-else
  149
+        //} //RunSingleInstance
150 150
 
151 151
 		private static SplashForm splash;// = new SplashForm();
152 152
 
@@ -188,10 +188,10 @@ internal static void Launch()
188 188
 			IconsManager.Initialize();
189 189
 			Application.DoEvents();
190 190
 			MainForm main = new MainForm();
191  
-			if (runSingleInstance)
192  
-			{
193  
-				main.HandleCreated += new EventHandler(main_HandleCreated);
194  
-			}
  191
+            //if (runSingleInstance)
  192
+            //{
  193
+            //    main.HandleCreated += new EventHandler(main_HandleCreated);
  194
+            //}
195 195
 			GC.Collect();
196 196
             timer.Stop();
197 197
             timer.Close();
@@ -212,24 +212,24 @@ private static void timer_Elapsed(object sender, ElapsedEventArgs e)
212 212
 		} //timer_Elapsed
213 213
 
214 214
 
215  
-		private static void main_HandleCreated(object sender, EventArgs e)
216  
-		{
217  
-			IntPtr mainWindowHandle = ((MainForm) sender).Handle;
218  
-			try
219  
-			{
220  
-				lock (sender)
221  
-				{
222  
-					//Write the handle to the Shared Memory 
223  
-					sharedMemory.WriteHandle(mainWindowHandle);
224  
-				} //lock
225  
-			}
226  
-			catch (Exception ex)
227  
-			{
228  
-				MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" +
229  
-				                "Application Exiting...", "Exception thrown",
230  
-				                MessageBoxButtons.OK, MessageBoxIcon.Error);
231  
-				Application.Exit();
232  
-			} //try-catch
233  
-		} //main_HandleCreated
  215
+        //private static void main_HandleCreated(object sender, EventArgs e)
  216
+        //{
  217
+        //    IntPtr mainWindowHandle = ((MainForm) sender).Handle;
  218
+        //    try
  219
+        //    {
  220
+        //        lock (sender)
  221
+        //        {
  222
+        //            //Write the handle to the Shared Memory 
  223
+        //            sharedMemory.WriteHandle(mainWindowHandle);
  224
+        //        } //lock
  225
+        //    }
  226
+        //    catch (Exception ex)
  227
+        //    {
  228
+        //        MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" +
  229
+        //                        "Application Exiting...", "Exception thrown",
  230
+        //                        MessageBoxButtons.OK, MessageBoxIcon.Error);
  231
+        //        Application.Exit();
  232
+        //    } //try-catch
  233
+        //} //main_HandleCreated
234 234
 	} //end of class
235 235
 } //enf of namespace
104  code/PTM/MainForm.cs
@@ -34,7 +34,6 @@ internal class MainForm : Form
34 34
 		private MenuItem aboutMenuItem;
35 35
 		private MenuItem menuItem4;
36 36
 		private IContainer components;
37  
-		private bool systemShutdown = false;
38 37
 		private MenuItem menuItem5;
39 38
 		private MenuItem menuItem6;
40 39
 		private MenuItem menuItem3;
@@ -131,7 +130,7 @@ private void LoadAddin(AddinTabPage addin)
131 130
 	    }
132 131
 
133 132
 
134  
-	    private void UpdateStartUpPath()
  133
+	    private static void UpdateStartUpPath()
135 134
 		{
136 135
 			try
137 136
 			{
@@ -365,63 +364,50 @@ private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
365 364
 			pageAddinTabPage.OnTabPageSelected();
366 365
 		} //tabControl_SelectedIndexChanged
367 366
 
368  
-
369  
-		protected override void WndProc(ref Message m)
370  
-		{
371  
-			// Once the program recieves WM_QUERYENDSESSION message, set the boolean systemShutdown.
372  
-
373  
-			if (m.Msg == ViewHelper.WM_QUERYENDSESSION)
374  
-			{
375  
-				systemShutdown = true;
376  
-			}
377  
-
378  
-			base.WndProc(ref m);
379  
-		} //WndProc
380  
-
381  
-		protected override void OnClosing(CancelEventArgs e)
382  
-		{
383  
-			try
384  
-			{
385  
-				if (systemShutdown)
386  
-				{
387  
-					e.Cancel = false;
388  
-				}
389  
-				else
390  
-				{
391  
-					e.Cancel = true;
392  
-					this.AnimateWindow();
393  
-					this.Visible = false;
394  
-				}
395  
-			}
396  
-			catch (Exception ex)
397  
-			{
398  
-				MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown",
399  
-				                MessageBoxButtons.OK, MessageBoxIcon.Error);
400  
-			} //try-cacth
401  
-
402  
-			base.OnClosing(e);
403  
-		} //OnClosing
404  
-
405  
-		private void AnimateWindow()
406  
-		{
407  
-			// if the user has not disabled animating windows...
408  
-			if (!this.AnimationDisabled)
409  
-			{
410  
-				ViewHelper.RECT animateFrom = new ViewHelper.RECT();
411  
-				ViewHelper.GetWindowRect(this.Handle, ref animateFrom);
412  
-
413  
-				ViewHelper.RECT animateTo = new ViewHelper.RECT();
414  
-				IntPtr notifyAreaHandle = ViewHelper.GetNotificationAreaHandle();
415  
-
416  
-				if (notifyAreaHandle != IntPtr.Zero)
417  
-				{
418  
-					if (ViewHelper.GetWindowRect(notifyAreaHandle, ref animateTo))
419  
-					{
420  
-						ViewHelper.DrawAnimatedRects(this.Handle, ViewHelper.IDANI_CAPTION, ref animateFrom, ref animateTo);
421  
-					} //if
422  
-				} //if
423  
-			} //if
424  
-		} //AnimateWindow
  367
+        protected override void OnFormClosing(FormClosingEventArgs e)
  368
+        {
  369
+            try
  370
+            {
  371
+                if (e.CloseReason == CloseReason.UserClosing)
  372
+                {
  373
+                    e.Cancel = true;
  374
+                    //this.AnimateWindow();
  375
+                    this.Visible = false;                   
  376
+                }
  377
+                else
  378
+                {
  379
+                    e.Cancel = false;
  380
+                }
  381
+            }
  382
+            catch (Exception ex)
  383
+            {
  384
+                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace + "\n\n" + "Application Exiting...", "Exception thrown",
  385
+                                MessageBoxButtons.OK, MessageBoxIcon.Error);
  386
+            } //try-cacth
  387
+
  388
+            base.OnFormClosing(e);
  389
+        }
  390
+
  391
+        //private void AnimateWindow()
  392
+        //{
  393
+        //    // if the user has not disabled animating windows...
  394
+        //    if (!this.AnimationDisabled)
  395
+        //    {
  396
+        //        ViewHelper.RECT animateFrom = new ViewHelper.RECT();
  397
+        //        ViewHelper.GetWindowRect(this.Handle, ref animateFrom);
  398
+
  399
+        //        ViewHelper.RECT animateTo = new ViewHelper.RECT();
  400
+        //        IntPtr notifyAreaHandle = ViewHelper.GetNotificationAreaHandle();
  401
+
  402
+        //        if (notifyAreaHandle != IntPtr.Zero)
  403
+        //        {
  404
+        //            if (ViewHelper.GetWindowRect(notifyAreaHandle, ref animateTo))
  405
+        //            {
  406
+        //                ViewHelper.DrawAnimatedRects(this.Handle, ViewHelper.IDANI_CAPTION, ref animateFrom, ref animateTo);
  407
+        //            } //if
  408
+        //        } //if
  409
+        //    } //if
  410
+        //} //AnimateWindow
425 411
 
426 412
 		#endregion
427 413
 
89  code/PTM/View/Controls/SummaryControl.cs
@@ -46,6 +46,8 @@ internal class SummaryControl : AddinTabPage
46 46
         private BrightIdeasSoftware.ObjectListView taskList;
47 47
         private BrightIdeasSoftware.OLVColumn TaskHeader;
48 48
         private BrightIdeasSoftware.OLVColumn TimeHeader;
  49
+        private BrightIdeasSoftware.OLVColumn ActiveTimeHeader;
  50
+        private BrightIdeasSoftware.OLVColumn InactiveTimeHeader;
49 51
         private BrightIdeasSoftware.OLVColumn PercentHeader;
50 52
         private BrightIdeasSoftware.OLVColumn GoalHeader;
51 53
         private BrightIdeasSoftware.OLVColumn PercentGoalHeader;
@@ -57,7 +59,6 @@ internal class SummaryControl : AddinTabPage
57 59
         private ToolStripButton toolStripButton1;
58 60
         private ToolStripButton toolStripButton2;
59 61
         private ToolStripLabel toolStripLabel1;
60  
-        private ToolStripComboBox toolStripComboBox1;
61 62
         private BackgroundWorker worker;
62 63
 
63 64
 		internal SummaryControl()
@@ -143,10 +144,11 @@ private void InitializeComponent()
143 144
             this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
144 145
             this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
145 146
             this.toolStripButton2 = new System.Windows.Forms.ToolStripButton();
146  
-            this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox();
147 147
             this.taskList = new BrightIdeasSoftware.ObjectListView();
148 148
             this.TaskHeader = new BrightIdeasSoftware.OLVColumn();
149 149
             this.TimeHeader = new BrightIdeasSoftware.OLVColumn();
  150
+            this.ActiveTimeHeader = new BrightIdeasSoftware.OLVColumn();
  151
+            this.InactiveTimeHeader = new BrightIdeasSoftware.OLVColumn();
150 152
             this.PercentHeader = new BrightIdeasSoftware.OLVColumn();
151 153
             this.GoalHeader = new BrightIdeasSoftware.OLVColumn();
152 154
             this.PercentGoalHeader = new BrightIdeasSoftware.OLVColumn();
@@ -213,8 +215,7 @@ private void InitializeComponent()
213 215
             this.toolStripSeparator,
214 216
             this.toolStripLabel1,
215 217
             this.toolStripButton1,
216  
-            this.toolStripButton2,
217  
-            this.toolStripComboBox1});
  218
+            this.toolStripButton2});
218 219
             this.toolStrip1.Location = new System.Drawing.Point(3, 16);
219 220
             this.toolStrip1.Name = "toolStrip1";
220 221
             this.toolStrip1.Size = new System.Drawing.Size(386, 25);
@@ -269,11 +270,6 @@ private void InitializeComponent()
269 270
             this.toolStripButton2.Size = new System.Drawing.Size(38, 22);
270 271
             this.toolStripButton2.Text = "Down";
271 272
             // 
272  
-            // toolStripComboBox1
273  
-            // 
274  
-            this.toolStripComboBox1.Name = "toolStripComboBox1";
275  
-            this.toolStripComboBox1.Size = new System.Drawing.Size(190, 25);
276  
-            // 
277 273
             // taskList
278 274
             // 
279 275
             this.taskList.AllColumns.Add(this.TaskHeader);
@@ -281,6 +277,8 @@ private void InitializeComponent()
281 277
             this.taskList.AllColumns.Add(this.PercentHeader);
282 278
             this.taskList.AllColumns.Add(this.GoalHeader);
283 279
             this.taskList.AllColumns.Add(this.PercentGoalHeader);
  280
+            this.taskList.AllColumns.Add(this.ActiveTimeHeader);
  281
+            this.taskList.AllColumns.Add(this.InactiveTimeHeader);
284 282
             this.taskList.AllowColumnReorder = true;
285 283
             this.taskList.AlternateRowBackColor = System.Drawing.Color.Empty;
286 284
             this.taskList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
@@ -288,7 +286,9 @@ private void InitializeComponent()
288 286
             this.TimeHeader,
289 287
             this.PercentHeader,
290 288
             this.GoalHeader,
291  
-            this.PercentGoalHeader});
  289
+            this.PercentGoalHeader,
  290
+            this.ActiveTimeHeader,
  291
+            this.InactiveTimeHeader});
292 292
             this.taskList.FullRowSelect = true;
293 293
             this.taskList.GridLines = true;
294 294
             this.taskList.HideSelection = false;
@@ -333,6 +333,18 @@ private void InitializeComponent()
333 333
             this.PercentGoalHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
334 334
             this.PercentGoalHeader.Width = 50;
335 335
             // 
  336
+            // ActiveTimeHeader
  337
+            // 
  338
+            this.ActiveTimeHeader.AspectName = null;
  339
+            this.ActiveTimeHeader.Text = "Active Time";
  340
+            this.ActiveTimeHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  341
+            // 
  342
+            // InactiveTimeHeader
  343
+            // 
  344
+            this.InactiveTimeHeader.AspectName = null;
  345
+            this.InactiveTimeHeader.Text = "Inactive Time";
  346
+            this.InactiveTimeHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  347
+            // 
336 348
             // label2
337 349
             // 
338 350
             this.label2.Location = new System.Drawing.Point(8, 4);
@@ -736,26 +748,19 @@ private void UpdateTasksSummary(TaskSummaryResult taskSummaryResult)
736 748
 					if (summary.IsActive)
737 749
 						totalActiveTime += summary.TotalActiveTime;
738 750
 
739  
-					//TimeSpan activeTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalActiveTime));
740  
-					//TimeSpan inactiveTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalInactiveTime));
741  
-                    TimeSpan elapsedTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalActiveTime + summary.TotalInactiveTime));
742  
-                    TimeSpan estimationTimeSpan = new TimeSpan(0, Convert.ToInt32(summary.TotalEstimation), 0);
743  
-				    string estimation;
744  
-                    if (summary.TotalEstimation == 0)
745  
-                        estimation = "Not estimated";
746  
-                    else
747  
-                        estimation = ViewHelper.TimeSpanToTimeString(estimationTimeSpan);
748  
-					TreeListViewItem lvi =
749  
-						new TreeListViewItem(summary.Description,
750  
-						                     new string[]
751  
-						                     	{
752  
-						                     		ViewHelper.TimeSpanToTimeString(elapsedTimeSpan),
753  
-						                     		0.ToString("0.0%", CultureInfo.InvariantCulture),
754  
-                                                    estimation,
755  
-						                     		0.ToString("0.0%", CultureInfo.InvariantCulture),
756  
-						                     	});
757  
-					
758  
-					lvi.ImageIndex = summary.IconId;
  751
+                    TreeListViewItem lvi =
  752
+                        new TreeListViewItem(summary.Description,
  753
+                                             new string[]
  754
+                                                {
  755
+                                                    String.Empty,
  756
+                                                    0.ToString("0.0%", CultureInfo.InvariantCulture),
  757
+                                                    String.Empty,
  758
+                                                    0.ToString("0.0%", CultureInfo.InvariantCulture),
  759
+                                                    String.Empty,
  760
+                                                    String.Empty
  761
+                                                });
  762
+
  763
+                    lvi.ImageIndex = summary.IconId;
759 764
 
760 765
 					lvi.Tag = summary;
761 766
 					this.taskList.Items.Add(lvi);
@@ -777,14 +782,28 @@ private void CalculateTasksPercents()
777 782
 				double percent = 0;
778 783
 			    double goalPercent = 0;
779 784
 
780  
-				TaskSummary sum = (TaskSummary) item.Tag;
  785
+				TaskSummary summary = (TaskSummary) item.Tag;
781 786
 
782 787
 				if (totalTime > 0)
783  
-				    percent = (sum.TotalActiveTime + sum.TotalInactiveTime)/totalTime;
784  
-
785  
-                if (sum.TotalEstimation > 0)
786  
-                    goalPercent = sum.TotalTimeOverEstimation / (sum.TotalEstimation*60);
  788
+				    percent = (summary.TotalActiveTime + summary.TotalInactiveTime)/totalTime;
  789
+
  790
+                if (summary.TotalEstimation > 0)
  791
+                    goalPercent = summary.TotalTimeOverEstimation / (summary.TotalEstimation*60);
  792
+
  793
+                TimeSpan activeTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalActiveTime));
  794
+                TimeSpan inactiveTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalInactiveTime));
  795
+                TimeSpan elapsedTimeSpan = new TimeSpan(0, 0, Convert.ToInt32(summary.TotalActiveTime + summary.TotalInactiveTime));
  796
+                TimeSpan estimationTimeSpan = new TimeSpan(0, Convert.ToInt32(summary.TotalEstimation), 0);
  797
+                string estimation;
  798
+                if (summary.TotalEstimation == 0)
  799
+                    estimation = "Not estimated";
  800
+                else
  801
+                    estimation = ViewHelper.TimeSpanToTimeString(estimationTimeSpan);
787 802
 
  803
+                item.SubItems[TimeHeader.Index].Text = ViewHelper.TimeSpanToTimeString(elapsedTimeSpan);
  804
+                item.SubItems[ActiveTimeHeader.Index].Text = ViewHelper.TimeSpanToTimeString(activeTimeSpan);
  805
+                item.SubItems[InactiveTimeHeader.Index].Text = ViewHelper.TimeSpanToTimeString(inactiveTimeSpan);
  806
+                item.SubItems[GoalHeader.Index].Text = estimation;
788 807
 				item.SubItems[PercentHeader.Index].Text = percent.ToString("0.0%", CultureInfo.InvariantCulture);
789 808
                 item.SubItems[PercentGoalHeader.Index].Text = goalPercent.ToString("0.0%", CultureInfo.InvariantCulture);
790 809
 
142  code/PTM/View/ViewHelper.cs
@@ -22,22 +22,22 @@ private ViewHelper()
22 22
 		[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
23 23
 		internal static extern IntPtr GetParent(IntPtr hwnd);
24 24
 
25  
-		[DllImport("user32.dll", SetLastError=true)]
26  
-		internal static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out IntPtr ProcessId);
  25
+        //[DllImport("user32.dll", SetLastError=true)]
  26
+        //internal static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out IntPtr ProcessId);
27 27
 
28  
-		[DllImport("User32")]
29  
-		[return : MarshalAs(UnmanagedType.Bool)]
30  
-		internal static extern bool IsWindow(IntPtr hWnd);
  28
+        //[DllImport("User32")]
  29
+        //[return : MarshalAs(UnmanagedType.Bool)]
  30
+        //internal static extern bool IsWindow(IntPtr hWnd);
31 31
 
32 32
 
33  
-		internal const int WM_QUERYENDSESSION = 0x11;
34  
-		internal const int IDANI_CAPTION = 3;
  33
+        //internal const int WM_QUERYENDSESSION = 0x11;
  34
+		//internal const int IDANI_CAPTION = 3;
35 35
 		//		private const int SW_HIDE = 0;
36 36
 		//		private const int SW_MAX = 10;
37 37
 		//		private const int SW_MAXIMIZE = 3;
38 38
 		//		private const int SW_MINIMIZE = 6;
39 39
 		//		private const int SW_NORMAL = 1;
40  
-		internal const int SW_RESTORE = 9;
  40
+		//internal const int SW_RESTORE = 9;
41 41
 		//		private const int SW_SHOW = 5;
42 42
 		//		private const int SW_SHOWDEFAULT = 10;
43 43
 		//		private const int SW_SHOWMAXIMIZED = 3;
@@ -45,69 +45,69 @@ private ViewHelper()
45 45
 		//		private const int SW_SHOWMINNOACTIVE = 7;
46 46
 		//		private const int SW_SHOWNA = 8;
47 47
 		//		private const int SW_SHOWNOACTIVATE = 4;
48  
-		internal const int SW_SHOWNORMAL = 1;
49  
-
50  
-		[DllImport("User32.dll", EntryPoint="ShowWindow", CharSet=CharSet.Auto)]
51  
-		[return : MarshalAs(UnmanagedType.Bool)]
52  
-		internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
53  
-
54  
-		[DllImport("User32.dll", EntryPoint="UpdateWindow", CharSet=CharSet.Auto)]
55  
-		[return : MarshalAs(UnmanagedType.Bool)]
56  
-		internal static extern bool UpdateWindow(IntPtr hWnd);
57  
-
58  
-		[DllImport("user32.dll", EntryPoint="IsIconic", CharSet=CharSet.Auto)]
59  
-		[return : MarshalAs(UnmanagedType.Bool)]
60  
-		internal static extern bool IsIconic(IntPtr hWnd);
61  
-
62  
-		[DllImport("user32.dll", EntryPoint="FindWindowEx", CharSet=CharSet.Auto)]
63  
-		internal static extern IntPtr FindWindowEx(
64  
-			IntPtr hwndParent,
65  
-			IntPtr hwndChildAfter,
66  
-			[MarshalAs(UnmanagedType.LPTStr)] string lpszClass,
67  
-			[MarshalAs(UnmanagedType.LPTStr)] string lpszWindow);
68  
-
69  
-		[DllImport("user32.dll", EntryPoint="DrawAnimatedRects", CharSet=CharSet.Auto)]
70  
-		[return : MarshalAs(UnmanagedType.Bool)]
71  
-		internal static extern bool DrawAnimatedRects(IntPtr hwnd, int idAni, ref RECT lprcFrom, ref RECT lprcTo);
72  
-
73  
-		[StructLayout(LayoutKind.Sequential)]
74  
-		internal struct RECT
75  
-		{
76  
-			internal int left;
77  
-			internal int top;
78  
-			internal int right;
79  
-			internal int bottom;
80  
-
81  
-			public override string ToString()
82  
-			{
83  
-				return
84  
-					("Left :" + left.ToString(CultureInfo.InvariantCulture) + "," + "Top :" +
85  
-					 top.ToString(CultureInfo.InvariantCulture) + "," + "Right :" + right.ToString(CultureInfo.InvariantCulture) + "," +
86  
-					 "Bottom :" + bottom.ToString(CultureInfo.InvariantCulture));
87  
-			} //ToString
88  
-		} //RECT
89  
-
90  
-		[DllImport("user32.dll", EntryPoint="GetWindowRect", CharSet=CharSet.Auto)]
91  
-		[return : MarshalAs(UnmanagedType.Bool)]
92  
-		internal static extern bool GetWindowRect(IntPtr hwnd, ref RECT lpRect);
93  
-
94  
-		internal static IntPtr GetNotificationAreaHandle()
95  
-		{
96  
-			IntPtr hwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
97  
-			Console.WriteLine("Shell_TrayWnd" + hwnd.ToString());
98  
-			hwnd = FindWindowEx(hwnd, IntPtr.Zero, "TrayNotifyWnd", null);
99  
-			Console.WriteLine("TrayNotifyWnd" + hwnd.ToString());
100  
-			hwnd = FindWindowEx(hwnd, IntPtr.Zero, "SysPager", null);
101  
-			Console.WriteLine("SysPager" + hwnd.ToString());
102  
-
103  
-			if (hwnd != IntPtr.Zero)
104  
-			{
105  
-				hwnd = FindWindowEx(hwnd, IntPtr.Zero, null, "Notification Area");
106  
-			} //if
107  
-
108  
-			Console.WriteLine("Notification Area" + hwnd.ToString());
109  
-			return hwnd;
110  
-		} //GetNotificationAreaHandle
  48
+        //internal const int SW_SHOWNORMAL = 1;
  49
+
  50
+        //[DllImport("User32.dll", EntryPoint="ShowWindow", CharSet=CharSet.Auto)]
  51
+        //[return : MarshalAs(UnmanagedType.Bool)]
  52
+        //internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  53
+
  54
+        //[DllImport("User32.dll", EntryPoint="UpdateWindow", CharSet=CharSet.Auto)]
  55
+        //[return : MarshalAs(UnmanagedType.Bool)]
  56
+        //internal static extern bool UpdateWindow(IntPtr hWnd);
  57
+
  58
+        //[DllImport("user32.dll", EntryPoint="IsIconic", CharSet=CharSet.Auto)]
  59
+        //[return : MarshalAs(UnmanagedType.Bool)]
  60
+        //internal static extern bool IsIconic(IntPtr hWnd);
  61
+
  62
+        //[DllImport("user32.dll", EntryPoint="FindWindowEx", CharSet=CharSet.Auto)]
  63
+        //internal static extern IntPtr FindWindowEx(
  64
+        //    IntPtr hwndParent,
  65
+        //    IntPtr hwndChildAfter,
  66
+        //    [MarshalAs(UnmanagedType.LPTStr)] string lpszClass,
  67
+        //    [MarshalAs(UnmanagedType.LPTStr)] string lpszWindow);
  68
+
  69
+        //[DllImport("user32.dll", EntryPoint="DrawAnimatedRects", CharSet=CharSet.Auto)]
  70
+        //[return : MarshalAs(UnmanagedType.Bool)]
  71
+        //internal static extern bool DrawAnimatedRects(IntPtr hwnd, int idAni, ref RECT lprcFrom, ref RECT lprcTo);
  72
+
  73
+        //[StructLayout(LayoutKind.Sequential)]
  74
+        //internal struct RECT
  75
+        //{
  76
+        //    internal int left;
  77
+        //    internal int top;
  78
+        //    internal int right;
  79
+        //    internal int bottom;
  80
+
  81
+        //    public override string ToString()
  82
+        //    {
  83
+        //        return
  84
+        //            ("Left :" + left.ToString(CultureInfo.InvariantCulture) + "," + "Top :" +
  85
+        //             top.ToString(CultureInfo.InvariantCulture) + "," + "Right :" + right.ToString(CultureInfo.InvariantCulture) + "," +
  86
+        //             "Bottom :" + bottom.ToString(CultureInfo.InvariantCulture));
  87
+        //    } //ToString
  88
+        //} //RECT
  89
+
  90
+        //[DllImport("user32.dll", EntryPoint="GetWindowRect", CharSet=CharSet.Auto)]
  91
+        //[return : MarshalAs(UnmanagedType.Bool)]
  92
+        //internal static extern bool GetWindowRect(IntPtr hwnd, ref RECT lpRect);
  93
+
  94
+        //internal static IntPtr GetNotificationAreaHandle()
  95
+        //{
  96
+        //    IntPtr hwnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", null);
  97
+        //    Console.WriteLine("Shell_TrayWnd" + hwnd.ToString());
  98
+        //    hwnd = FindWindowEx(hwnd, IntPtr.Zero, "TrayNotifyWnd", null);
  99
+        //    Console.WriteLine("TrayNotifyWnd" + hwnd.ToString());
  100
+        //    hwnd = FindWindowEx(hwnd, IntPtr.Zero, "SysPager", null);
  101
+        //    Console.WriteLine("SysPager" + hwnd.ToString());
  102
+
  103
+        //    if (hwnd != IntPtr.Zero)
  104
+        //    {
  105
+        //        hwnd = FindWindowEx(hwnd, IntPtr.Zero, null, "Notification Area");
  106
+        //    } //if
  107
+
  108
+        //    Console.WriteLine("Notification Area" + hwnd.ToString());
  109
+        //    return hwnd;
  110
+        //} //GetNotificationAreaHandle
111 111
 
112 112
 		/// <summary>
113 113
 		/// TimeSpanToTimeString, returns a timeSpan as a formated string

0 notes on commit d28d97c

Please sign in to comment.
Something went wrong with that request. Please try again.