private void buttonSave_Click(object sender, EventArgs e)
 {
     try
     {
         XMLManager.Export(Settings.Instance, FILENAME);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show("Error Saving:\r\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
        private static IAuthorizationState GetAuthentication(NativeApplicationClient arg)
        {
            // Get the auth URL:
            IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });

            state.Callback     = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
            state.RefreshToken = Settings.Instance.RefreshToken;
            Uri authUri = arg.RequestUserAuthorization(state);

            IAuthorizationState result = null;

            if (state.RefreshToken == "")
            {
                // Request authorization from the user (by opening a browser window):
                Process.Start(authUri.ToString());

                EnterAuthorizationCode eac = new EnterAuthorizationCode();
                if (eac.ShowDialog() == DialogResult.OK)
                {
                    // Retrieve the access/refresh tokens by using the authorization code:
                    result = arg.ProcessUserAuthorization(eac.authcode, state);

                    //save the refresh token for future use
                    Settings.Instance.RefreshToken = result.RefreshToken;
                    XMLManager.Export(Settings.Instance, MainForm.FILENAME);

                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                arg.RefreshToken(state, null);
                result = state;
                return(result);
            }
        }
        public MainForm()
        {
            InitializeComponent();
            labelAbout.Text = labelAbout.Text.Replace("{version}", System.Windows.Forms.Application.ProductVersion);

            //load settings/create settings file
            if (File.Exists(FILENAME))
            {
                Settings.Instance = XMLManager.import <Settings>(FILENAME);
            }
            else
            {
                XMLManager.Export(Settings.Instance, FILENAME);
            }

            //update GUI from Settings
            numericUpDownDaysInThePast.Value   = Settings.Instance.DaysInThePast;
            numericUpDownDaysInTheFuture.Value = Settings.Instance.DaysInTheFuture;
            textBoxMinuteOffsets.Text          = Settings.Instance.MinuteOffsets;
            comboBoxCalendars.Items.Add(Settings.Instance.SelectedGoogleCalendar);
            comboBoxCalendars.SelectedIndex    = 0;
            checkBoxSyncEveryHour.Checked      = Settings.Instance.SyncEveryHour;
            checkBoxShowBubbleTooltips.Checked = Settings.Instance.ShowBubbleTooltipWhenSyncing;
            checkBoxStartInTray.Checked        = Settings.Instance.StartInTray;
            checkBoxMinimizeToTray.Checked     = Settings.Instance.MinimizeToTray;
            checkBoxAddDescription.Checked     = Settings.Instance.AddDescription;
            checkBoxAddAttendees.Checked       = Settings.Instance.AddAttendeesToDescription;
            checkBoxAddReminders.Checked       = Settings.Instance.AddReminders;
            checkBoxCreateFiles.Checked        = Settings.Instance.CreateTextFiles;

            //set up timer (every 30s) for checking the minute offsets
            _ogstimer          = new Timer();
            _ogstimer.Interval = 30000;
            _ogstimer.Tick    += new EventHandler(ogstimer_Tick);
            _ogstimer.Start();
            _oldtime = DateTime.Now;

            _syncWorker.WorkerReportsProgress      = true;
            _syncWorker.WorkerSupportsCancellation = true;
            _syncWorker.DoWork             += syncWorker_DoWork;
            _syncWorker.ProgressChanged    += syncWorker_ProgressChanged;
            _syncWorker.RunWorkerCompleted += syncWorker_RunWorkerCompleted;

            //set up tooltips for some controls
            ToolTip toolTip1 = new ToolTip();

            toolTip1.AutoPopDelay = 10000;
            toolTip1.InitialDelay = 500;
            toolTip1.ReshowDelay  = 200;
            toolTip1.ShowAlways   = true;
            toolTip1.SetToolTip(comboBoxCalendars,
                                "The Google Calendar to synchonize with.");
            toolTip1.SetToolTip(textBoxMinuteOffsets,
                                "One ore more Minute Offsets at which the sync is automatically started each hour. \n" +
                                "Separate by comma (e.g. 5,15,25).");
            toolTip1.SetToolTip(checkBoxAddAttendees,
                                "While Outlook has fields for Organizer, RequiredAttendees and OptionalAttendees, Google has not.\n" +
                                "If checked, this data is added at the end of the description as text.");
            toolTip1.SetToolTip(checkBoxAddReminders,
                                "If checked, the reminder set in outlook will be carried over to the Google Calendar entry (as a popup reminder).");
            toolTip1.SetToolTip(checkBoxCreateFiles,
                                "If checked, all entries found in Outlook/Google and identified for creation/deletion will be exported \n" +
                                "to 4 separate text files in the application's directory (named \"export_*.txt\"). \n" +
                                "Only for debug/diagnostic purposes.");
            toolTip1.SetToolTip(checkBoxAddDescription,
                                "The description may contain email addresses, which Outlook may complain about (PopUp-Message: \"Allow Access?\" etc.). \n" +
                                "Turning this off allows OutlookGoogleSync to run without intervention in this case.");
            toolTip1.SetToolTip(buttonDeleteAll,
                                "Delete all calendar items from your Google calendar which were synced from your Outlook calendar in the set time range.");
        }