From 69a47f6652dda5c4bab7a9653e50be5f014bc449 Mon Sep 17 00:00:00 2001 From: gamosoft_cp Date: Thu, 18 Jul 2013 18:16:35 +0000 Subject: [PATCH] Added initial support for multiple calendars. Added friendly group header names (yesterday, today and tomorrow). Some minor refactoring. --- Outlook2013TodoAddIn/AppointmentsControl.cs | 73 ++++++++++++++++--- Outlook2013TodoAddIn/Constants.cs | 42 +++++++++++ Outlook2013TodoAddIn/CustomCalendar.cs | 2 +- .../Forms/FormConfiguration.Designer.cs | 50 +++++++++++-- .../Forms/FormConfiguration.cs | 44 +++++++++++ Outlook2013TodoAddIn/Forms/NewMailAlert.cs | 2 +- .../Outlook2013TodoAddIn.csproj | 1 + .../Properties/Settings.Designer.cs | 25 ++++++- .../Properties/Settings.settings | 6 ++ Outlook2013TodoAddIn/ThisAddIn.cs | 4 +- Outlook2013TodoAddIn/app.config | 3 + 11 files changed, 232 insertions(+), 20 deletions(-) create mode 100644 Outlook2013TodoAddIn/Constants.cs diff --git a/Outlook2013TodoAddIn/AppointmentsControl.cs b/Outlook2013TodoAddIn/AppointmentsControl.cs index 0e4a560..89ef6fa 100644 --- a/Outlook2013TodoAddIn/AppointmentsControl.cs +++ b/Outlook2013TodoAddIn/AppointmentsControl.cs @@ -1,6 +1,7 @@ using Outlook2013TodoAddIn.Forms; using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; @@ -30,6 +31,16 @@ namespace Outlook2013TodoAddIn /// public bool ShowPastAppointments { get; set; } + /// + /// Gets/sets a list of all stores/accounts to retrieve information from + /// + public StringCollection Accounts { get; set; } + + /// + /// Gets/sets whether to show friendly group headers (yesterday, today, tomorrow) + /// + public bool ShowFriendlyGroupHeaders { get; set; } + /// /// Gets/sets the selected calendar date /// @@ -116,17 +127,29 @@ namespace Outlook2013TodoAddIn } /// - /// Retrieve all appointments for the current configurations for all stores + /// Retrieve all appointments for the current configurations for all selected stores /// public void RetrieveAppointments() { - //foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) + List appts = new List(); + foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) + { + if (Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName)) + { + Outlook.Folder calFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder; + appts.AddRange(this.RetrieveAppointmentsForFolder(calFolder)); + // TODO: Shared calendars? + } + } + // We need to sort them because they may come from different accounts already ordered + appts.Sort(CompareAppointments); + // Get the Outlook folder for the calendar to retrieve the appointments - Outlook.Folder calFolder = - Globals.ThisAddIn.Application.Session.GetDefaultFolder( - Outlook.OlDefaultFolders.olFolderCalendar) - as Outlook.Folder; - List appts = this.RetrieveAppointmentsForFolder(calFolder); + //Outlook.Folder calFolder = + // Globals.ThisAddIn.Application.Session.GetDefaultFolder( + // Outlook.OlDefaultFolders.olFolderCalendar) + // as Outlook.Folder; + //List appts = this.RetrieveAppointmentsForFolder(calFolder); // Highlight dates with appointments in the current calendar this.apptCalendar.BoldedDates = appts.Select(a => a.Start.Date).Distinct().ToArray(); @@ -150,7 +173,26 @@ namespace Outlook2013TodoAddIn { if (i.Start.Day != sameDay) { - grp = new ListViewGroup(i.Start.ToShortDateString(), HorizontalAlignment.Left); + string groupHeaderText = i.Start.ToShortDateString(); + if (this.ShowFriendlyGroupHeaders) + { + int daysDiff = (int)(i.Start.Date - DateTime.Today).TotalDays; + switch (daysDiff) + { + case -1: + groupHeaderText = Constants.Yesterday + ": " + groupHeaderText; + break; + case 0: + groupHeaderText = Constants.Today + ": " + groupHeaderText; + break; + case 1: + groupHeaderText = Constants.Tomorrow + ": " + groupHeaderText; + break; + default: + break; + } + } + grp = new ListViewGroup(groupHeaderText, HorizontalAlignment.Left); this.listView1.Groups.Add(grp); // TODO: Style it? sameDay = i.Start.Day; }; @@ -192,6 +234,17 @@ namespace Outlook2013TodoAddIn this.apptCalendar.UpdateCalendar(); } + /// + /// Comparer method to sort appointments based on start date/time + /// + /// First appointment + /// Second appointment + /// + private static int CompareAppointments(Outlook.AppointmentItem x, Outlook.AppointmentItem y) + { + return x.Start.CompareTo(y.Start); + } + /// /// Retrieve all appointments for the current configurations for a specific folder /// @@ -320,7 +373,7 @@ namespace Outlook2013TodoAddIn } } mail.Body = Environment.NewLine + Environment.NewLine + appt.Body; - mail.Subject = "RE: " + appt.Subject; + mail.Subject = Constants.SubjectRE + ": " + appt.Subject; mail.Display(); } } @@ -356,6 +409,8 @@ namespace Outlook2013TodoAddIn this.NumDays = cfg.NumDays; this.MailAlertsEnabled = cfg.MailAlertsEnabled; this.ShowPastAppointments = cfg.ShowPastAppointments; + this.Accounts = cfg.Accounts; + this.ShowFriendlyGroupHeaders = cfg.ShowFriendlyGroupHeaders; this.RetrieveAppointments(); } } diff --git a/Outlook2013TodoAddIn/Constants.cs b/Outlook2013TodoAddIn/Constants.cs new file mode 100644 index 0000000..6c164f3 --- /dev/null +++ b/Outlook2013TodoAddIn/Constants.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Outlook2013TodoAddIn +{ + /// + /// New class to localize some texts and get some constants, pending proper resource localization + /// + public class Constants + { + #region "Variables" + + /// + /// Today + /// + public const string Today = "Today"; + + /// + /// Yesterday + /// + public const string Yesterday = "Yesterday"; + + /// + /// Tomorrow + /// + public const string Tomorrow = "Tomorrow"; + + /// + /// Reply header prefix for the subject + /// + public const string SubjectRE = "RE"; + + /// + /// Follow Up email flag (can't be changed) + /// + public const string FollowUp = "Follow up"; + + #endregion "Variables" + } +} \ No newline at end of file diff --git a/Outlook2013TodoAddIn/CustomCalendar.cs b/Outlook2013TodoAddIn/CustomCalendar.cs index 32b2e47..b688201 100644 --- a/Outlook2013TodoAddIn/CustomCalendar.cs +++ b/Outlook2013TodoAddIn/CustomCalendar.cs @@ -266,7 +266,7 @@ namespace Outlook2013TodoAddIn { // All controls are previously created, just need to update labels, etc... this.lnkCurrentRange.Text = this.SelectedDate.ToString("MMM yyyy"); - this.lnkToday.Text = "Today: " + DateTime.Today.ToShortDateString(); + this.lnkToday.Text = Constants.Today + ": " + DateTime.Today.ToShortDateString(); string[] daysOfWeek = Enum.GetNames(typeof(DayOfWeek)); string sFirstDayOfWeek = Enum.GetName(typeof(DayOfWeek), this.FirstDayOfWeek); diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs index 63d8271..6ecfe7b 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.Designer.cs @@ -34,13 +34,16 @@ this.btnCancel = new System.Windows.Forms.Button(); this.btnOK = new System.Windows.Forms.Button(); this.chkShowPastAppointments = new System.Windows.Forms.CheckBox(); + this.chkListCalendars = new System.Windows.Forms.CheckedListBox(); + this.lblAccounts = new System.Windows.Forms.Label(); + this.chkFriendlyGroupHeaders = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.numRangeDays)).BeginInit(); this.SuspendLayout(); // // chkMailAlerts // this.chkMailAlerts.AutoSize = true; - this.chkMailAlerts.Location = new System.Drawing.Point(59, 134); + this.chkMailAlerts.Location = new System.Drawing.Point(45, 94); this.chkMailAlerts.Name = "chkMailAlerts"; this.chkMailAlerts.Size = new System.Drawing.Size(143, 21); this.chkMailAlerts.TabIndex = 8; @@ -50,7 +53,7 @@ // lblRangeDays // this.lblRangeDays.AutoSize = true; - this.lblRangeDays.Location = new System.Drawing.Point(55, 60); + this.lblRangeDays.Location = new System.Drawing.Point(55, 29); this.lblRangeDays.Name = "lblRangeDays"; this.lblRangeDays.Size = new System.Drawing.Size(44, 17); this.lblRangeDays.TabIndex = 7; @@ -58,7 +61,7 @@ // // numRangeDays // - this.numRangeDays.Location = new System.Drawing.Point(115, 58); + this.numRangeDays.Location = new System.Drawing.Point(115, 27); this.numRangeDays.Maximum = new decimal(new int[] { 30, 0, @@ -81,7 +84,7 @@ // btnCancel // this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnCancel.Location = new System.Drawing.Point(169, 181); + this.btnCancel.Location = new System.Drawing.Point(168, 291); this.btnCancel.Name = "btnCancel"; this.btnCancel.Size = new System.Drawing.Size(87, 37); this.btnCancel.TabIndex = 11; @@ -91,7 +94,7 @@ // btnOK // this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.btnOK.Location = new System.Drawing.Point(27, 181); + this.btnOK.Location = new System.Drawing.Point(26, 291); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(87, 37); this.btnOK.TabIndex = 10; @@ -102,20 +105,50 @@ // chkShowPastAppointments // this.chkShowPastAppointments.AutoSize = true; - this.chkShowPastAppointments.Location = new System.Drawing.Point(59, 98); + this.chkShowPastAppointments.Location = new System.Drawing.Point(45, 67); this.chkShowPastAppointments.Name = "chkShowPastAppointments"; this.chkShowPastAppointments.Size = new System.Drawing.Size(186, 21); this.chkShowPastAppointments.TabIndex = 12; this.chkShowPastAppointments.Text = "Show Past Appointments"; this.chkShowPastAppointments.UseVisualStyleBackColor = true; // + // chkListCalendars + // + this.chkListCalendars.FormattingEnabled = true; + this.chkListCalendars.Location = new System.Drawing.Point(26, 176); + this.chkListCalendars.Name = "chkListCalendars"; + this.chkListCalendars.Size = new System.Drawing.Size(229, 106); + this.chkListCalendars.TabIndex = 13; + // + // lblAccounts + // + this.lblAccounts.AutoSize = true; + this.lblAccounts.Location = new System.Drawing.Point(23, 156); + this.lblAccounts.Name = "lblAccounts"; + this.lblAccounts.Size = new System.Drawing.Size(70, 17); + this.lblAccounts.TabIndex = 14; + this.lblAccounts.Text = "Accounts:"; + // + // chkFriendlyGroupHeaders + // + this.chkFriendlyGroupHeaders.AutoSize = true; + this.chkFriendlyGroupHeaders.Location = new System.Drawing.Point(45, 121); + this.chkFriendlyGroupHeaders.Name = "chkFriendlyGroupHeaders"; + this.chkFriendlyGroupHeaders.Size = new System.Drawing.Size(176, 21); + this.chkFriendlyGroupHeaders.TabIndex = 15; + this.chkFriendlyGroupHeaders.Text = "Show Friendly Headers"; + this.chkFriendlyGroupHeaders.UseVisualStyleBackColor = true; + // // FormConfiguration // this.AcceptButton = this.btnOK; this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btnCancel; - this.ClientSize = new System.Drawing.Size(282, 253); + this.ClientSize = new System.Drawing.Size(282, 343); + this.Controls.Add(this.chkFriendlyGroupHeaders); + this.Controls.Add(this.lblAccounts); + this.Controls.Add(this.chkListCalendars); this.Controls.Add(this.chkShowPastAppointments); this.Controls.Add(this.btnCancel); this.Controls.Add(this.btnOK); @@ -144,5 +177,8 @@ private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.CheckBox chkShowPastAppointments; + private System.Windows.Forms.CheckedListBox chkListCalendars; + private System.Windows.Forms.Label lblAccounts; + private System.Windows.Forms.CheckBox chkFriendlyGroupHeaders; } } \ No newline at end of file diff --git a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs index 4745796..231152a 100644 --- a/Outlook2013TodoAddIn/Forms/FormConfiguration.cs +++ b/Outlook2013TodoAddIn/Forms/FormConfiguration.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; +using Outlook = Microsoft.Office.Interop.Outlook; namespace Outlook2013TodoAddIn.Forms { @@ -40,6 +42,31 @@ namespace Outlook2013TodoAddIn.Forms set { this.chkShowPastAppointments.Checked = value; } } + /// + /// Gets/sets a list of all stores/accounts to retrieve information from + /// + public StringCollection Accounts + { + get + { + StringCollection col = new StringCollection(); + foreach (object item in this.chkListCalendars.CheckedItems) + { + col.Add(item.ToString()); + } + return col; + } + } + + /// + /// Gets/sets whether to show friendly group headers (yesterday, today, tomorrow) + /// + public bool ShowFriendlyGroupHeaders + { + get { return this.chkFriendlyGroupHeaders.Checked; } + set { this.chkFriendlyGroupHeaders.Checked = value; } + } + #endregion "Properties" #region "Methods" @@ -62,6 +89,21 @@ namespace Outlook2013TodoAddIn.Forms this.numRangeDays.Value = Properties.Settings.Default.NumDays; this.chkMailAlerts.Checked = Properties.Settings.Default.MailAlertsEnabled; this.chkShowPastAppointments.Checked = Properties.Settings.Default.ShowPastAppointments; + this.chkFriendlyGroupHeaders.Checked = Properties.Settings.Default.ShowFriendlyGroupHeaders; + this.LoadStores(); + } + + /// + /// Loads all the stores (accounts) in the current session + /// + private void LoadStores() + { + foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores) + { + bool itemChecked = Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName); + int index = this.chkListCalendars.Items.Add(store.DisplayName, itemChecked); + // TODO: Use StoreID instead? + } } /// @@ -74,6 +116,8 @@ namespace Outlook2013TodoAddIn.Forms Properties.Settings.Default.NumDays = this.numRangeDays.Value; Properties.Settings.Default.MailAlertsEnabled = this.chkMailAlerts.Checked; Properties.Settings.Default.ShowPastAppointments = this.chkShowPastAppointments.Checked; + Properties.Settings.Default.Accounts = this.Accounts; + Properties.Settings.Default.ShowFriendlyGroupHeaders = this.chkFriendlyGroupHeaders.Checked; } #endregion "Methods" diff --git a/Outlook2013TodoAddIn/Forms/NewMailAlert.cs b/Outlook2013TodoAddIn/Forms/NewMailAlert.cs index 131075e..6f97aa6 100644 --- a/Outlook2013TodoAddIn/Forms/NewMailAlert.cs +++ b/Outlook2013TodoAddIn/Forms/NewMailAlert.cs @@ -129,7 +129,7 @@ namespace Outlook2013TodoAddIn.Forms private void btnFlag_Click(object sender, EventArgs e) { //Microsoft.Office.Interop.Outlook.OlFlagIcon.olYellowFlagIcon - this.Email.FlagRequest = "Follow up"; + this.Email.FlagRequest = Constants.FollowUp; this.Email.Save(); this.Close(); } diff --git a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj index bf1c50d..31e2545 100644 --- a/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj +++ b/Outlook2013TodoAddIn/Outlook2013TodoAddIn.csproj @@ -183,6 +183,7 @@ can be found. --> + UserControl diff --git a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs index 6101d15..4175c5b 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.Designer.cs +++ b/Outlook2013TodoAddIn/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18046 +// Runtime Version:4.0.30319.18051 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -94,5 +94,28 @@ namespace Outlook2013TodoAddIn.Properties { this["ShowPastAppointments"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection Accounts { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["Accounts"])); + } + set { + this["Accounts"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool ShowFriendlyGroupHeaders { + get { + return ((bool)(this["ShowFriendlyGroupHeaders"])); + } + set { + this["ShowFriendlyGroupHeaders"] = value; + } + } } } diff --git a/Outlook2013TodoAddIn/Properties/Settings.settings b/Outlook2013TodoAddIn/Properties/Settings.settings index 181a83b..b849e14 100644 --- a/Outlook2013TodoAddIn/Properties/Settings.settings +++ b/Outlook2013TodoAddIn/Properties/Settings.settings @@ -20,5 +20,11 @@ True + + + + + True + \ No newline at end of file diff --git a/Outlook2013TodoAddIn/ThisAddIn.cs b/Outlook2013TodoAddIn/ThisAddIn.cs index 93da445..c16713d 100644 --- a/Outlook2013TodoAddIn/ThisAddIn.cs +++ b/Outlook2013TodoAddIn/ThisAddIn.cs @@ -41,7 +41,9 @@ namespace Outlook2013TodoAddIn this.AppControl = new AppointmentsControl(); this.AppControl.MailAlertsEnabled = Properties.Settings.Default.MailAlertsEnabled; - this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments; + this.AppControl.ShowPastAppointments = Properties.Settings.Default.ShowPastAppointments; + this.AppControl.Accounts = Properties.Settings.Default.Accounts; + this.AppControl.ShowFriendlyGroupHeaders = Properties.Settings.Default.ShowFriendlyGroupHeaders; this.AppControl.NumDays = Properties.Settings.Default.NumDays; // Setting the value will load the appointments ToDoTaskPane = this.CustomTaskPanes.Add(this.AppControl, "Appointments"); diff --git a/Outlook2013TodoAddIn/app.config b/Outlook2013TodoAddIn/app.config index db38990..0390c6d 100644 --- a/Outlook2013TodoAddIn/app.config +++ b/Outlook2013TodoAddIn/app.config @@ -25,6 +25,9 @@ True + + True +