Skip to content

Commit

Permalink
Remove restriction of only single instance of PushSyncTimer.
Browse files Browse the repository at this point in the history
Correctly set Add Attendees and Reminders checkboxes.
Added "profile loading" banner.
#1307
  • Loading branch information
phw198 committed Nov 3, 2021
1 parent 7fb7c1c commit 746d2ed
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 43 deletions.
26 changes: 12 additions & 14 deletions src/OutlookGoogleCalendarSync/Extensions/MenuButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using System.Windows.Forms;

namespace OutlookGoogleCalendarSync.Extensions {
public class MenuButton : Button {
[DefaultValue(null), Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public partial class MenuButton : Button {
[DefaultValue(null), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public ContextMenuStrip Menu { get; set; }

[DefaultValue(20), Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[DefaultValue(20), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int SplitWidth { get; set; }

public MenuButton() {
Expand All @@ -20,18 +18,16 @@ protected override void OnMouseDown(MouseEventArgs mevent) {
var splitRect = new Rectangle(this.Width - this.SplitWidth, 0, this.SplitWidth, this.Height);

// Figure out if the button click was on the button itself or the menu split
if (Menu != null &&
mevent.Button == MouseButtons.Left &&
splitRect.Contains(mevent.Location)) {
if (Menu != null && mevent.Button == MouseButtons.Left && splitRect.Contains(mevent.Location)) {
Menu.Show(this, 0, this.Height); // Shows menu under button
//Menu.Show(this, mevent.Location); // Shows menu at click location
//Menu.Show(this, mevent.Location); // Shows menu at click location
} else {
base.OnMouseDown(mevent);
}
}

protected override void OnPaint(PaintEventArgs pevent) {
base.OnPaint(pevent);
protected override void OnPaint(PaintEventArgs pEvent) {
base.OnPaint(pEvent);

if (this.Menu != null && this.SplitWidth > 0) {
// Draw the arrow glyph on the right side of the button
Expand All @@ -40,14 +36,16 @@ protected override void OnPaint(PaintEventArgs pevent) {

var arrowBrush = Enabled ? SystemBrushes.ControlText : SystemBrushes.ButtonShadow;
var arrows = new[] { new Point(arrowX, arrowY), new Point(arrowX + 7, arrowY), new Point(arrowX + 3, arrowY + 4) };
pevent.Graphics.FillPolygon(arrowBrush, arrows);
pEvent.Graphics.FillPolygon(arrowBrush, arrows);

// Draw a dashed separator on the left of the arrow
int lineX = ClientRectangle.Width - this.SplitWidth;
int lineYFrom = arrowY - 4;
int lineYTo = arrowY + 8;
using (var separatorPen = new Pen(Brushes.DarkGray) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dot }) {
pevent.Graphics.DrawLine(separatorPen, lineX, lineYFrom, lineX, lineYTo);
using (var separatorPen = new Pen(Brushes.DarkGray) {
DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
}) {
pEvent.Graphics.DrawLine(separatorPen, lineX, lineYFrom, lineX, lineYTo);
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion src/OutlookGoogleCalendarSync/Forms/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions src/OutlookGoogleCalendarSync/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,8 +1024,26 @@ private void Save_Click(object sender, EventArgs e) {

private void ddProfile_SelectedIndexChanged(object sender, EventArgs e) {
foreach (SettingsStore.Calendar cal in Settings.Instance.Calendars) {
if (cal._ProfileName == ddProfile.Text)
cal.SetActive();
if (cal._ProfileName == ddProfile.Text) {
try {
try {
if (this.tabAppSettings.SelectedTab != this.tabOutlook) {
this.tabAppSettings.SelectedTab.Controls.Add(this.panelProfileLoading);
this.panelProfileLoading.BringToFront();
this.panelProfileLoading.Visible = true;
this.txtProfileLoading.Location = new Point((this.tabOutlook.Width - this.txtProfileLoading.Width) / 2, 9);
this.tabAppSettings.Enabled = false;
}
} catch (System.Exception ex) {
OGCSexception.Analyse(ex);
}
cal.SetActive();
break;
} finally {
this.panelProfileLoading.Visible = false;
this.tabAppSettings.Enabled = true;
}
}
}
}

Expand Down Expand Up @@ -1857,7 +1875,7 @@ private void cbAddDescription_OnlyToGoogle_CheckedChanged(object sender, EventAr
}

private void cbAddReminders_CheckedChanged(object sender, EventArgs e) {
if (this.Visible) ActiveCalendarProfile.AddReminders = cbAddReminders.Checked;
if (this.Visible && sender != null) ActiveCalendarProfile.AddReminders = cbAddReminders.Checked;
cbUseGoogleDefaultReminder.Enabled = ActiveCalendarProfile.SyncDirection != Sync.Direction.GoogleToOutlook;
cbUseOutlookDefaultReminder.Enabled = ActiveCalendarProfile.SyncDirection != Sync.Direction.OutlookToGoogle;
cbReminderDND.Enabled = cbAddReminders.Checked;
Expand Down Expand Up @@ -1888,7 +1906,7 @@ private void cbAddAttendees_CheckedChanged(object sender, EventArgs e) {
tbMaxAttendees.Enabled = false;
return;
}
if (this.Visible) ActiveCalendarProfile.AddAttendees = cbAddAttendees.Checked;
if (this.Visible && sender != null) ActiveCalendarProfile.AddAttendees = cbAddAttendees.Checked;
tbMaxAttendees.Enabled = cbAddAttendees.Checked;
cbCloakEmail.Visible = ActiveCalendarProfile.SyncDirection != Sync.Direction.GoogleToOutlook;
cbCloakEmail.Enabled = cbAddAttendees.Checked;
Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/OutlookOgcs/OutlookNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private void findCalendars(Folders folders, Dictionary<string, MAPIFolder> calen
findCalendars(folder.Folders, calendarFolders, excludeDeletedFolder, defaultCalendar);
}
} catch (System.Exception ex) {
if (oApp.Session.ExchangeConnectionMode.ToString().Contains("Disconnected") ||
if (oApp?.Session.ExchangeConnectionMode.ToString().Contains("Disconnected") ?? false ||
OGCSexception.GetErrorCode(ex) == "0xC204011D" || ex.Message.StartsWith("Network problems are preventing connection to Microsoft Exchange.") ||
OGCSexception.GetErrorCode(ex, 0x000FFFFF) == "0x00040115") {
log.Warn(ex.Message);
Expand Down
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/SettingsStore/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void RegisterForPushSync() {

log.Info("Start monitoring for Outlook appointments changes on profile: " + this._ProfileName);
if (this.OgcsPushTimer == null)
this.OgcsPushTimer = Sync.PushSyncTimer.Instance(this);
this.OgcsPushTimer = new Sync.PushSyncTimer(this);
if (!this.OgcsPushTimer.Running())
this.OgcsPushTimer.Activate(true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ public static String Name(Object settingsStore) {
public static SettingsStore.Calendar InPlay() {
SettingsStore.Calendar aProfile;

if (Program.CalledByProcess("manualSynchronize,updateGUIsettings,UpdateGUIsettings_Profile,miCatRefresh_Click," +
"GetMyGoogleCalendars_Click,btColourMap_Click,ColourPicker_Enter,ddGoogleColour_SelectedIndexChanged")) {
if (Program.CalledByProcess("manualSynchronize,Sync_Click,updateGUIsettings,UpdateGUIsettings_Profile,miCatRefresh_Click," +
"GetMyGoogleCalendars_Click,btColourMap_Click,ColourPicker_Enter,OnSelectedIndexChanged,OnCheckedChanged")) {
aProfile = Forms.Main.Instance.ActiveCalendarProfile;
log.Fine("Using profile Forms.Main.Instance.ActiveCalendarProfile");

Expand Down
32 changes: 12 additions & 20 deletions src/OutlookGoogleCalendarSync/Sync/Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,20 @@ public void SetNextSync() {
/// <param name="fromNow">From now or since last successful sync</param>
/// <param name="calculateInterval">Calculate milliseconds to next sync and activate timer</param>
public void SetNextSync(int delayMins, Boolean fromNow = false, Boolean calculateInterval = true) {
int syncInterval = 0;
if (owningProfile is SettingsStore.Calendar) {
syncInterval = SettingsStore.Calendar.GetCalendarProfile(owningProfile).SyncInterval;
}
SettingsStore.Calendar profile = null;
if (owningProfile is SettingsStore.Calendar)
profile = SettingsStore.Calendar.GetCalendarProfile(owningProfile);

if (syncInterval != 0) {
if (profile == null || profile.SyncInterval == 0) {
this.NextSyncDateText = (profile?.OutlookPush ?? false) ? "Push Sync Active" : "Inactive";
Activate(false);
log.Info("Schedule disabled.");
} else {
DateTime now = DateTime.Now;
this.nextSyncDate = fromNow ? now.AddMinutes(delayMins) : this.LastSyncDate.AddMinutes(delayMins);
if (calculateInterval) CalculateInterval();
else this.NextSyncDate = this.nextSyncDate;
log.Info("Next sync scheduled for profile '"+ Settings.Profile.Name(owningProfile) +"' at " + this.NextSyncDateText);
} else {
this.NextSyncDateText = "Inactive";
Activate(false);
log.Info("Schedule disabled.");
}
}

Expand Down Expand Up @@ -144,15 +143,7 @@ public class PushSyncTimer : Timer {
private DateTime lastRunTime;
private Int32 lastRunItemCount;
private Int16 failures = 0;
private static PushSyncTimer instance;
public static PushSyncTimer Instance(Object owningProfile) {
if (instance == null) {
instance = new PushSyncTimer(owningProfile);
}
return instance;
}

private PushSyncTimer(Object owningProfile) {
public PushSyncTimer(Object owningProfile) {
this.owningProfile = owningProfile;
ResetLastRun();
this.Tag = "PushTimer";
Expand All @@ -175,12 +166,13 @@ public void ResetLastRun() {

private void ogcsPushTimer_Tick(object sender, EventArgs e) {
if (Forms.ErrorReporting.Instance.Visible) return;
log.Fine("Push sync triggered.");

log.UltraFine("Push sync triggered.");
try {
if (OutlookOgcs.Calendar.Instance.IOutlook.NoGUIexists()) return;

SettingsStore.Calendar profile = this.owningProfile as SettingsStore.Calendar;
log.Fine("Push sync triggered for profile: " + Settings.Profile.Name(profile));
System.Collections.Generic.List<Microsoft.Office.Interop.Outlook.AppointmentItem> items = OutlookOgcs.Calendar.Instance.GetCalendarEntriesInRange(profile, true);

if (items.Count < this.lastRunItemCount || items.FindAll(x => x.LastModificationTime > this.lastRunTime).Count > 0) {
Expand Down

0 comments on commit 746d2ed

Please sign in to comment.