From 170139b7c4c6c5da0c05d1b7bf0dcae1de5c33e2 Mon Sep 17 00:00:00 2001 From: Paul Woolcock <11843015+phw198@users.noreply.github.com> Date: Sat, 18 Nov 2023 13:45:46 +0000 Subject: [PATCH] GMeet checkbox added to Google tab. Only sync GMeet if option enabled. --- .../Forms/MainForm.Designer.cs | 24 ++++++++-- .../Forms/MainForm.cs | 48 ++++++++++++++----- .../GoogleOgcs/GoogleCalendar.cs | 20 ++++---- .../OutlookGoogleCalendarSync.csproj | 1 + .../OutlookOgcs/OutlookCalendar.cs | 12 +++-- .../SettingsStore/Calendar.cs | 3 ++ 6 files changed, 79 insertions(+), 29 deletions(-) diff --git a/src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs b/src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs index 8c3ba98c..88a79b9c 100644 --- a/src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs +++ b/src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs @@ -115,6 +115,7 @@ private void InitializeComponent() { this.lClientID = new System.Windows.Forms.Label(); this.lSecret = new System.Windows.Forms.Label(); this.gbGoogle_GConfig = new System.Windows.Forms.GroupBox(); + this.cbAddGMeet = new System.Windows.Forms.CheckBox(); this.cbDeleteWhenColourExcl = new System.Windows.Forms.CheckBox(); this.label35 = new System.Windows.Forms.Label(); this.cbColourFilter = new System.Windows.Forms.ComboBox(); @@ -1100,7 +1101,7 @@ private void InitializeComponent() { // this.pbExpandGoogleOauth.Cursor = System.Windows.Forms.Cursors.Hand; this.pbExpandGoogleOauth.Image = global::OutlookGoogleCalendarSync.Properties.Resources.expand; - this.pbExpandGoogleOauth.Location = new System.Drawing.Point(1, 394); + this.pbExpandGoogleOauth.Location = new System.Drawing.Point(1, 402); this.pbExpandGoogleOauth.Name = "pbExpandGoogleOauth"; this.pbExpandGoogleOauth.Size = new System.Drawing.Size(20, 20); this.pbExpandGoogleOauth.TabIndex = 50; @@ -1111,7 +1112,7 @@ private void InitializeComponent() { // cbShowDeveloperOptions // this.cbShowDeveloperOptions.AutoSize = true; - this.cbShowDeveloperOptions.Location = new System.Drawing.Point(23, 374); + this.cbShowDeveloperOptions.Location = new System.Drawing.Point(23, 382); this.cbShowDeveloperOptions.Name = "cbShowDeveloperOptions"; this.cbShowDeveloperOptions.Size = new System.Drawing.Size(193, 17); this.cbShowDeveloperOptions.TabIndex = 48; @@ -1154,7 +1155,7 @@ private void InitializeComponent() { this.gbGoogle_OAuth.Controls.Add(this.lSecret); this.gbGoogle_OAuth.Font = new System.Drawing.Font("Arial Black", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.gbGoogle_OAuth.ForeColor = System.Drawing.SystemColors.MenuHighlight; - this.gbGoogle_OAuth.Location = new System.Drawing.Point(10, 397); + this.gbGoogle_OAuth.Location = new System.Drawing.Point(10, 405); this.gbGoogle_OAuth.MinimumSize = new System.Drawing.Size(368, 0); this.gbGoogle_OAuth.Name = "gbGoogle_OAuth"; this.gbGoogle_OAuth.Size = new System.Drawing.Size(368, 174); @@ -1260,6 +1261,7 @@ private void InitializeComponent() { // this.gbGoogle_GConfig.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.gbGoogle_GConfig.Controls.Add(this.cbAddGMeet); this.gbGoogle_GConfig.Controls.Add(this.cbDeleteWhenColourExcl); this.gbGoogle_GConfig.Controls.Add(this.label35); this.gbGoogle_GConfig.Controls.Add(this.cbColourFilter); @@ -1271,11 +1273,24 @@ private void InitializeComponent() { this.gbGoogle_GConfig.Location = new System.Drawing.Point(10, 246); this.gbGoogle_GConfig.MinimumSize = new System.Drawing.Size(368, 0); this.gbGoogle_GConfig.Name = "gbGoogle_GConfig"; - this.gbGoogle_GConfig.Size = new System.Drawing.Size(368, 122); + this.gbGoogle_GConfig.Size = new System.Drawing.Size(368, 130); this.gbGoogle_GConfig.TabIndex = 45; this.gbGoogle_GConfig.TabStop = false; this.gbGoogle_GConfig.Text = " Sync Configuration"; // + // cbAddGMeet + // + this.cbAddGMeet.AutoSize = true; + this.cbAddGMeet.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.cbAddGMeet.ForeColor = System.Drawing.SystemColors.ControlText; + this.cbAddGMeet.Location = new System.Drawing.Point(13, 109); + this.cbAddGMeet.Name = "cbAddGMeet"; + this.cbAddGMeet.Size = new System.Drawing.Size(150, 17); + this.cbAddGMeet.TabIndex = 54; + this.cbAddGMeet.Text = "Include Meet conferences"; + this.cbAddGMeet.UseVisualStyleBackColor = true; + this.cbAddGMeet.CheckedChanged += new System.EventHandler(this.cbGMeet_CheckedChanged); + // // cbDeleteWhenColourExcl // this.cbDeleteWhenColourExcl.AutoSize = true; @@ -4203,5 +4218,6 @@ private void InitializeComponent() { public System.Windows.Forms.ComboBox cbColourFilter; public System.Windows.Forms.CheckedListBox clbColours; private System.Windows.Forms.CheckBox cbDeleteWhenColourExcl; + private System.Windows.Forms.CheckBox cbAddGMeet; } } diff --git a/src/OutlookGoogleCalendarSync/Forms/MainForm.cs b/src/OutlookGoogleCalendarSync/Forms/MainForm.cs index 70ceb955..299bf61c 100644 --- a/src/OutlookGoogleCalendarSync/Forms/MainForm.cs +++ b/src/OutlookGoogleCalendarSync/Forms/MainForm.cs @@ -95,6 +95,8 @@ private void updateGUIsettings() { "Include hidden calendars in the above drop down."); ToolTips.SetToolTip(cbDeleteWhenColourExcl, "If items are already synced in Outlook and subsequently excluded by a colour filter."); + ToolTips.SetToolTip(cbAddGMeet, + "Sync conference details embedded in Outlook appointment body."); //Settings ToolTips.SetToolTip(tbInterval, @@ -443,7 +445,8 @@ public void UpdateGUIsettings_Profile() { cbExcludeDeclinedInvites.Checked = profile.ExcludeDeclinedInvites; cbExcludeGoals.Checked = profile.ExcludeGoals; cbExcludeGoals.Enabled = GoogleOgcs.Calendar.IsDefaultCalendar() ?? true; - + cbAddGMeet.Checked = profile.AddGMeet; + if (Settings.Instance.UsingPersonalAPIkeys()) { cbShowDeveloperOptions.Checked = true; tbClientID.Text = Settings.Instance.PersonalClientIdentifier; @@ -607,23 +610,37 @@ public void FeaturesBlockedByCorpPolicy(Boolean isTrue) { } } if (isTrue) { - SetControlPropertyThreadSafe(cbAddAttendees, "Checked", false); - SetControlPropertyThreadSafe(cbAddDescription, "Checked", false); - SetControlPropertyThreadSafe(rbOutlookSharedCal, "Checked", false); //Mimic appearance of disabled control - but can't disable else tooltip doesn't work - cbAddAttendees.ForeColor = SystemColors.GrayText; - cbAddDescription.ForeColor = SystemColors.GrayText; - rbOutlookSharedCal.ForeColor = SystemColors.GrayText; + checkboxSoftRestrict(cbAddAttendees, true); + checkboxSoftRestrict(cbAddDescription, true); + checkboxSoftRestrict(rbOutlookSharedCal, true); + checkboxSoftRestrict(cbAddGMeet, true); //If a sync is running, disable relevant config in that profile SettingsStore.Calendar activeProfile = Settings.Profile.InPlay(); if (activeProfile != null) { activeProfile.AddAttendees = false; activeProfile.AddDescription = false; + activeProfile.AddGMeet = false; } } else { - cbAddAttendees.ForeColor = SystemColors.ControlText; - cbAddDescription.ForeColor = SystemColors.ControlText; - rbOutlookSharedCal.ForeColor = SystemColors.ControlText; + checkboxSoftRestrict(cbAddAttendees, false); + checkboxSoftRestrict(cbAddDescription, false); + checkboxSoftRestrict(rbOutlookSharedCal, false); + checkboxSoftRestrict(cbAddGMeet, false); + } + } + + /// + /// Make a checkbox look disabled, but still able to show a tooltip + /// + /// The form control + /// Disable or enable + private void checkboxSoftRestrict(Control cb, Boolean disable) { + if (disable) { + cb.ForeColor = SystemColors.GrayText; + SetControlPropertyThreadSafe(cb, "Checked", false); + } else { + cb.ForeColor = SystemColors.ControlText; } } @@ -1255,7 +1272,7 @@ private void groupboxSizing(GroupBox section, PictureBox sectionImage, Boolean? switch (section.Name.ToString().Split('_').LastOrDefault()) { //Google case "Account": section.Height = 242; break; - case "GConfig": section.Height = 122; break; + case "GConfig": section.Height = 130; break; case "OAuth": section.Height = 174; break; //Settings case "How": section.Height = btCloseRegexRules.Visible ? 251 : 198; break; @@ -1667,6 +1684,13 @@ private void cbExcludeDeclinedInvites_CheckedChanged(object sender, EventArgs e) private void cbExcludeGoals_CheckedChanged(object sender, EventArgs e) { ActiveCalendarProfile.ExcludeGoals = cbExcludeGoals.Checked; } + private void cbGMeet_CheckedChanged(object sender, EventArgs e) { + if (!cbAddDescription.Checked) { + cbAddGMeet.Checked = false; + } + ActiveCalendarProfile.AddGMeet = cbAddGMeet.Checked; + } + #endregion #region Developer Options @@ -2161,6 +2185,8 @@ private void cbAddDescription_CheckedChanged(object sender, EventArgs e) { } ActiveCalendarProfile.AddDescription = cbAddDescription.Checked; cbAddDescription_OnlyToGoogle.Enabled = cbAddDescription.Checked; + checkboxSoftRestrict(cbAddGMeet, !cbAddDescription.Checked); + ToolTips.SetToolTip(cbAddGMeet, cbAddDescription.Checked ? "Sync conference details embedded in Outlook appointment body." : "Requires sync of Description (under Options > What)"); showWhatPostit("Description"); } private void cbAddDescription_OnlyToGoogle_CheckedChanged(object sender, EventArgs e) { diff --git a/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs b/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs index fc4953b6..a6f5c14a 100644 --- a/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs +++ b/src/OutlookGoogleCalendarSync/GoogleOgcs/GoogleCalendar.cs @@ -664,7 +664,7 @@ private Event createCalendarEntry_save(Event ev, AppointmentItem ai) { ai.Save(); } - if (OutlookOgcs.GMeet.BodyHasGmeetUrl(ai)) { + if (profile.AddGMeet && OutlookOgcs.GMeet.BodyHasGmeetUrl(ai)) { log.Info("Adding GMeet conference details."); String outlookGMeet = OutlookOgcs.GMeet.RgxGmeetUrl().Match(ai.Body).Value; GMeet.GoogleMeet(createdEvent, outlookGMeet); @@ -904,14 +904,16 @@ public Event UpdateCalendarEntry(AppointmentItem ai, Event ev, ref int itemModif if (Sync.Engine.CompareAttribute("Description", Sync.Direction.OutlookToGoogle, ev.Description, bodyObfuscated, sb, ref itemModified)) ev.Description = bodyObfuscated; - String outlookGMeet = OutlookOgcs.GMeet.RgxGmeetUrl().Match(ai.Body)?.Value; - if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.OutlookToGoogle, ev.HangoutLink, outlookGMeet, sb, ref itemModified)) { - try { - GMeet.GoogleMeet(ev, outlookGMeet); - ev = patchEvent(ev) ?? ev; - log.Fine("Conference data change successfully saved."); - } catch (System.Exception ex) { - OGCSexception.Analyse("Could not update conference data in existing Event.", ex); + if (profile.AddGMeet) { + String outlookGMeet = OutlookOgcs.GMeet.RgxGmeetUrl().Match(ai.Body)?.Value; + if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.OutlookToGoogle, ev.HangoutLink, outlookGMeet, sb, ref itemModified)) { + try { + GMeet.GoogleMeet(ev, outlookGMeet); + ev = patchEvent(ev) ?? ev; + log.Fine("Conference data change successfully saved."); + } catch (System.Exception ex) { + OGCSexception.Analyse("Could not update conference data in existing Event.", ex); + } } } } diff --git a/src/OutlookGoogleCalendarSync/OutlookGoogleCalendarSync.csproj b/src/OutlookGoogleCalendarSync/OutlookGoogleCalendarSync.csproj index f7c45dbb..79180d55 100644 --- a/src/OutlookGoogleCalendarSync/OutlookGoogleCalendarSync.csproj +++ b/src/OutlookGoogleCalendarSync/OutlookGoogleCalendarSync.csproj @@ -326,6 +326,7 @@ TimezoneMap.cs + diff --git a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs index 504d37b8..bb68a97c 100644 --- a/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs +++ b/src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookCalendar.cs @@ -398,7 +398,7 @@ private void createCalendarEntry(Event ev, ref AppointmentItem ai) { } } else ai.ReminderSet = profile.UseOutlookDefaultReminder; - if (!String.IsNullOrEmpty(ev.HangoutLink)) { + if (profile.AddGMeet && !String.IsNullOrEmpty(ev.HangoutLink)) { ai.GoogleMeet(ev.HangoutLink); } @@ -610,11 +610,13 @@ public Boolean UpdateCalendarEntry(ref AppointmentItem ai, Event ev, ref int ite if (descriptionChanged = Sync.Engine.CompareAttribute("Description", Sync.Direction.GoogleToOutlook, bodyObfuscated, aiBody, sb, ref itemModified)) ai.Body = bodyObfuscated; } - if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.GoogleToOutlook, ev.HangoutLink, oGMeetUrl, sb, ref itemModified)) { - ai.GoogleMeet(ev.HangoutLink); - if (String.IsNullOrEmpty(ev.HangoutLink) && !String.IsNullOrEmpty(oGMeetUrl) && !descriptionChanged) - log.Debug("Removing GMeet information from body."); + if (profile.AddGMeet) { + if (Sync.Engine.CompareAttribute("Google Meet", Sync.Direction.GoogleToOutlook, ev.HangoutLink, oGMeetUrl, sb, ref itemModified)) { + ai.GoogleMeet(ev.HangoutLink); + if (String.IsNullOrEmpty(ev.HangoutLink) && !String.IsNullOrEmpty(oGMeetUrl) && !descriptionChanged) + log.Debug("Removing GMeet information from body."); ai.Body = bodyObfuscated; + } } } } diff --git a/src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs b/src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs index 9e12fe41..7897fb5e 100644 --- a/src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs +++ b/src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs @@ -52,6 +52,7 @@ private void setDefaults() { Colours = new List(); ExcludeDeclinedInvites = true; ExcludeGoals = true; + AddGMeet = true; //Sync Options //How @@ -137,6 +138,7 @@ [DataMember] public Boolean OutlookGalBlocked { [DataMember] public List Colours { get; set; } [DataMember] public Boolean ExcludeDeclinedInvites { get; set; } [DataMember] public Boolean ExcludeGoals { get; set; } + [DataMember] public Boolean AddGMeet { get; set; } #endregion #region Sync Options /// For O->G match on signatures. Useful for Appled iCals where immutable Outlook IDs change every sync. @@ -288,6 +290,7 @@ public void LogSettings() { log.Info(" Colours: " + String.Join(",", Colours.ToArray())); log.Info(" Exclude Declined Invites: " + ExcludeDeclinedInvites); log.Info(" Exclude Goals: " + ExcludeGoals); + log.Info(" Include Google Meet: " + AddGMeet); log.Info(" Cloak Email: " + CloakEmail); log.Info("SYNC OPTIONS:-");