示例#1
0
        public void RefreshAndRestartTimer()
        {
            lock (_timerLock)
            {
                DisableButtons();

                _thumbForm.Invoke(new Action <bool>(_thumbForm.ShowAppropriateThumb), true);

                int currCount = _gmailClient.Emails.Count;
                CheckEmailResult currResult = _gmailClient.LastResult;

                _gmailClient.CheckEmail();

                //if status has changed or the number of emails has changed
                if ((currResult != _gmailClient.LastResult) || (currCount != _gmailClient.Emails.Count))
                {
                    UpdateIcon();
                }

                //
                if (_gmailClient.Updated && _gmailClient.Emails.Count > 0)
                {
                    _thumbForm.Invoke(new Action <int>(_thumbForm.UpdatePreviewThumb), 0);
                }

                //if we got mail, and it's not the first time
                if (_gmailClient.GotMail && (currResult != CheckEmailResult.None))
                {
                    ShowProgress();

                    NewMailSound();
                }

                _thumbForm.Invoke(new Action <bool>(_thumbForm.ShowAppropriateThumb), false);

                EnableAppropriateButtons();

                int interval = _checkInterval;

                if (_gmailClient.LastResult == CheckEmailResult.AccountError)
                {
                    interval = _errorInterval;
                }
                else if (_gmailClient.LastResult == CheckEmailResult.NetworkError)
                {
                    interval = _connRetryInterval;
                }

                _timer.Interval = interval;
                _timer.Start();
            }
        }
示例#2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(usernameBox.Text) || String.IsNullOrEmpty(passwordBox.Text))
            {
                ErrorBox("Please enter your username and password");
                return;
            }

            mainPanel.Enabled = false;

            GmailClient gmailClient = new GmailClient(usernameBox.Text, passwordBox.Text);

            if (gmailClient.CheckEmail() != CheckEmailResult.Success)
            {
                mainPanel.Enabled = true;
                ErrorBox("Could not login\r\n\r\n" + gmailClient.LastError.Message);
                return;
            }

            byte[] pass = System.Security.Cryptography.ProtectedData.Protect(UTF8Encoding.UTF8.GetBytes(passwordBox.Text), null, System.Security.Cryptography.DataProtectionScope.CurrentUser);

            RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\KwertyGmailNotifier");

            using (registry)
            {
                registry.SetValue("username", usernameBox.Text);
                registry.SetValue("password", pass);
            }

            _mainForm._gmailClient = gmailClient;

            _mainForm.Setup();

            _mainForm._timer.Start();

            _closed = true;
            Close();
        }