Beispiel #1
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            this.FadeToTransparent(grdLoginInfo.Name);
            this.FadeToOpaque(lblStatus.Name);

            Settings.Set("SavePassword", chkSave.IsChecked == true);
            Settings.Set("AutoLogin", chkAutoLogin.IsChecked == true);
            if ((bool)chkSave.IsChecked)
            {
                Settings.SetSecure("Password", txtPassword.Password.ToSecureString(), SessionModel.KEY);
            }
            Settings.Set("UserName", txtUserName.Text);
            Settings.Save();

            this.Try(() => windowsTaskbar.SetProgressState(TaskbarProgressBarState.Indeterminate));

            model = new SessionModel(txtUserName.Text, txtPassword.Password);

            model.OnLoginFailure += () =>
            {
                this.Invoke(() =>
                {
                    this.FadeToTransparent(lblStatus.Name);
                    this.FadeToOpaque(grdLoginInfo.Name);
                    windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress);
                    // gpLoginBox.Header = "Invalid Username or Password";
                });
            };
            model.OnLoginSuccess += () =>
            {
                this.Invoke(() =>
                {
                    Settings.Set("LoginCount", Settings.Get("LoginCount", 1) + 1);
                    int loginCount = Settings.Get("LoginCount", 0);
                    Trace.WriteLine("Login Count: " + loginCount);

                    /*
                     * if (loginCount > 5)
                     * {
                     *  if (!Settings.Get("donate14", false))
                     *  {
                     *      Debug.WriteLine("Welcome Open");
                     *      Welcome w = new Welcome();
                     *      w.Show();
                     *  }
                     * }
                     */

                    Title                   = "GVNotifier";
                    SizeToContent           = System.Windows.SizeToContent.Manual;
                    LoggedInPage.Visibility = System.Windows.Visibility.Visible;
                    LoginPage.Visibility    = System.Windows.Visibility.Hidden;
                    this.FadeToTransparent(LoginPage.Name);
                    this.FadeToOpaque(LoggedInPage.Name);
                    txtSearch.Focus();

                    lsvContacts.ItemsSource = model.Contacts;
                    ConfigureListView();
                    SyncContactsJumpList();

                    this.Try(() => windowsTaskbar.SetProgressState(TaskbarProgressBarState.Normal));

                    SelectedView = lsvContacts;
                    //DavuxLib2.Platform.DwmApi.DwmExtendFrameIntoClientArea(this, new Thickness(0, gLoginTop.ActualHeight * this.GetDPI(), 0, 1 + (bottomPanel.ActualHeight * this.GetDPI())));

                    model.account.Ready += () => this.Invoke(() => FitColumn(lsvVM, lsvNameColVM));
                });
            };
            model.OnLoginMessage += (s) =>
            {
                this.Invoke(() => lblStatus.Text = s);
            };

            model.account.ContactsManager.ContactsLoadingUpdate += (v, max) =>
            {
                if (windowsTaskbar != null)
                {
                    this.Try(() => windowsTaskbar.SetProgressState(TaskbarProgressBarState.Normal));
                    this.Invoke(() => TaskbarManager.Instance.SetProgressValue(v, max));
                }
            };

            model.Login();

            model.OnMessage         += new Action <GoogleVoice.Message, GoogleVoice.Contact>(model_OnMessage);
            model.OnContactsUpdated += () =>
            {
                this.Invoke(() =>
                {
                    if (windowsTaskbar != null)
                    {
                        this.Try(() => windowsTaskbar.SetProgressState(TaskbarProgressBarState.NoProgress));
                    }
                    Trace.WriteLine("Reloading Contacts View");
                    ResizeGridViewColumn(lsvNameCol);
                    SyncContactsJumpList();
                });
            };

            lblStatus.Text       = "Waiting...";
            lblStatus.Visibility = System.Windows.Visibility.Visible;

            // This does not still reliably steal foreground and activate the window.
            // However, this may be a platform limitation as the current process does
            // not have permission to steal foreground.
            model.OnJumpListContact += (c) =>
            {
                this.Invoke(() =>
                {
                    var mw = WindowForContact(c);
                    mw.Show();
                    this.InvokeDelay(100, () =>
                    {
                        mw.Activate();
                        mw.Focus();
                    });
                });
            };
        }
Beispiel #2
0
        public static void Init()
        {
            if (Settings.Get("ShowTrayIcon", false))
            {
                var t = new Thread(() =>
                {
                    NotifyIcon ni = new NotifyIcon();
                    ni.Icon       = GVNotifier.Properties.Resources.gv;
                    ni.Text       = "GVNotifier";
                    ni.Visible    = true;

                    ni.ContextMenu = new ContextMenu();

                    var m    = new MenuItem();
                    m.Text   = "About";
                    m.Click += (ss, ee) => SessionModel.ShowAbout();
                    ni.ContextMenu.MenuItems.Add(m);

                    m        = new MenuItem();
                    m.Text   = "Preferences";
                    m.Click += (ss, ee) => SessionModel.ShowPrefs();
                    ni.ContextMenu.MenuItems.Add(m);

                    ni.ContextMenu.MenuItems.Add(new MenuItem("-"));

                    m        = new MenuItem();
                    m.Text   = "Check for new messages";
                    m.Click += (ss, ee) => SessionModel.Check();
                    ni.ContextMenu.MenuItems.Add(m);

                    // TODO contact name sync won't work, and number sync
                    // won't work if the window has been opened in the session
                    // this comes together with the "switch to MVVM" change.
                    m        = new MenuItem();
                    m.Text   = "Sync Google Contacts Now";
                    m.Click += (ss, ee) => SessionModel.UpdateContacts();
                    ni.ContextMenu.MenuItems.Add(m);

                    ni.ContextMenu.MenuItems.Add(new MenuItem("-"));

                    m        = new MenuItem();
                    m.Text   = "Sign Out";
                    m.Click += (ss, ee) =>
                    {
                        ni.Visible = false;
                        SessionModel.SignOut();
                    };
                    ni.ContextMenu.MenuItems.Add(m);

                    m        = new MenuItem();
                    m.Text   = "Quit";
                    m.Click += (ss, ee) =>
                    {
                        ni.Visible = false;
                        SessionModel.CloseApp();
                    };
                    ni.ContextMenu.MenuItems.Add(m);

                    ni.DoubleClick += (_, __) => SessionModel.ShowMainWindow();
                    ni.MouseClick  += (ss, ee) =>
                    {
                        if (ee.Button == MouseButtons.Left)
                        {
                            SessionModel.ShowMainWindow();
                        }
                    };

                    Application.Run();
                });
                // this worked without STA, but UI controls should always be STA
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
            }
        }
Beispiel #3
0
        public SessionModel(string UserName, string Password)
        {
            this.UserName   = UserName;
            this.Password   = Password;
            Inst            = this;
            SearchContacts  = new ObservableCollectionEx <Contact>();
            Voicemails      = new ObservableCollectionEx <VoiceMessage>();
            SearchVoicemail = new ObservableCollectionEx <VoiceMessage>();
            Calls           = new ObservableCollectionEx <CallMessage>();
            SearchCalls     = new ObservableCollectionEx <CallMessage>();
            try
            {
                if (!Directory.Exists(DavuxLib2.App.DataDirectory + @"\cache\"))
                {
                    Directory.CreateDirectory(DavuxLib2.App.DataDirectory + @"\cache\");
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("SessionModel/SessionModel Create Cache Dir *** " + ex);
            }
            account = new Account(UserName, Password, DavuxLib2.Settings.Get <GVCookie>("SMSV", null), DavuxLib2.App.DataDirectory + @"\cache\");

            account.OnMessage += new Action <Message>(account_OnMessage);
            // account.OnPreInitMessage += new Action<Message>(account_OnPreInitMessage);
            account.OnLoginMessage += (s) =>
            {
                if (OnLoginMessage != null)
                {
                    OnLoginMessage(s);
                }
            };
            account.ContactsManager.OnContactsUpdated += () =>
            {
                Trace.WriteLine("Saving Contacts");
                account.ContactsManager.Save();
            };
            account.SMSVCookieUpdated += cookie =>
            {
                Trace.WriteLine("SMSV Cookie Updated: " + cookie);
                DavuxLib2.Settings.Set <GVCookie>("SMSV", cookie);
                DavuxLib2.Settings.Save();
            };
            account.GetSMSPinFromUser += () =>
            {
                Trace.WriteLine("Requesting PIN from user...");
                // this user has 2-step verification, and we need to get a PIN from them
                string PIN = "";
                Thread t   = new Thread(() =>
                {
                    GetPin pinWindow = new GetPin();
                    pinWindow.Show();
                    System.Windows.Threading.Dispatcher.Run();
                    PIN = pinWindow.PIN;
                });
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
                t.Join();
                Trace.WriteLine("Got PIN: " + PIN);
                return(PIN);
            };
        }