Exemplo n.º 1
0
        private void MainFormLoad(object sender, EventArgs e)
        {
            // set window location, window size, editor's font, editor's word wrap setting,
            // encryption key, AutoSave and window's "always on top" option based on user settings

            if (Settings.Default.WindowLocation.X != 0 || Settings.Default.WindowLocation.Y != 0)
            {
                Location = Settings.Default.WindowLocation;
            }

            if (Location.X < 0 || Location.Y < 0)
            {
                Trace.WriteLine(string.Format("{0} - Location out of bounds: X: {1} - Y: {2}",
                                              DateTime.Now, Location.X, Location.Y));
                CenterToScreen();
                Settings.Default.WindowLocation = new Point(0, 0);
            }
            Size = Settings.Default.WindowSize;


            menuWordWrap.Checked = Settings.Default.WordWrap;
            TopMost = Settings.Default.AlwaysOnTop;
            menuAlwaysOnTop.Checked = Settings.Default.AlwaysOnTop;

            // ------------------------------------------------------------------------------------------------------

            // if Google login info hasn't been saved, let's show the Login form
            if (string.IsNullOrEmpty(Settings.Default.GoogleUsername) || string.IsNullOrEmpty(Settings.Default.GooglePassword))
            {
                var nocsLogin = new Login();
                nocsLogin.ShowDialog();

                // make sure user was validated
                if (!string.IsNullOrEmpty(NocsService.Username) && !string.IsNullOrEmpty(NocsService.Password))
                {
                    RetrieveDocuments();

                    // reset help variable
                    NocsService.AccountChanged = false;
                }
            }

            // if user has already used the application with proper Google credentials, we'll start the Google DocumentsList service
            else
            {
                // copy the account info from settings to NocsService
                NocsService.Username = Settings.Default.GoogleUsername;
                NocsService.Password = Tools.Decrypt(Settings.Default.GooglePassword);

                // if Google login info hasn't been saved, let's show the Login form
                if (string.IsNullOrEmpty(NocsService.Password))
                {
                    var nocsLogin = new Login();
                    nocsLogin.ShowDialog();

                    // make sure user was validated
                    if (!string.IsNullOrEmpty(NocsService.Username) && !string.IsNullOrEmpty(NocsService.Password))
                    {
                        RetrieveDocuments();

                        // reset help variable
                        NocsService.AccountChanged = false;
                    }
                }
                else
                {
                    // inform user that we are starting the service
                    Status(StatusType.Authorize, "Authenticating with Google..");

                    // disable menu options for changing the Google Account, for browsing Google Docs
                    // and for saving while items are being retrieved
                    menuGoogleAccount.Enabled = false;
                    menuBrowse.Enabled = false;
                    menuSave.Enabled = false;

                    // run the backgroundworker for starting the service
                    BgWorkerStartService.RunWorkerAsync(false);
                }
            }
        }
Exemplo n.º 2
0
        private void MainFormLoad(object sender, EventArgs e)
        {
            // set window location, window size, editor's font, editor's word wrap setting,
            // encryption key, AutoSave and window's "always on top" option based on user settings

            if (Settings.Default.WindowLocation.X != 0 || Settings.Default.WindowLocation.Y != 0)
            {
                Location = Settings.Default.WindowLocation;
            }

            if (Location.X < 0 || Location.Y < 0)
            {
                Trace.WriteLine(string.Format("{0} - Location out of bounds: X: {1} - Y: {2}",
                                              DateTime.Now, Location.X, Location.Y));
                CenterToScreen();
                Settings.Default.WindowLocation = new Point(0, 0);
            }
            Size = Settings.Default.WindowSize;


            menuWordWrap.Checked = Settings.Default.WordWrap;
            TopMost = Settings.Default.AlwaysOnTop;
            menuAlwaysOnTop.Checked = Settings.Default.AlwaysOnTop;

            // ------------------------------------------------------------------------------------------------------

            // if Google login info hasn't been saved, let's show the Login form
            if (string.IsNullOrEmpty(Settings.Default.GoogleUsername) || string.IsNullOrEmpty(Settings.Default.GooglePassword))
            {
                var nocsLogin = new Login();
                nocsLogin.ShowDialog();

                // make sure user was validated
                if (!string.IsNullOrEmpty(NocsService.Username) && !string.IsNullOrEmpty(NocsService.Password))
                {
                    RetrieveDocuments();

                    // reset help variable
                    NocsService.AccountChanged = false;
                }
            }

            // if user has already used the application with proper Google credentials, we'll start the Google DocumentsList service
            else
            {
                // copy the account info from settings to NocsService
                NocsService.Username = Settings.Default.GoogleUsername;
                NocsService.Password = Tools.Decrypt(Settings.Default.GooglePassword);

                // if Google login info hasn't been saved, let's show the Login form
                if (string.IsNullOrEmpty(NocsService.Password))
                {
                    var nocsLogin = new Login();
                    nocsLogin.ShowDialog();

                    // make sure user was validated
                    if (!string.IsNullOrEmpty(NocsService.Username) && !string.IsNullOrEmpty(NocsService.Password))
                    {
                        RetrieveDocuments();

                        // reset help variable
                        NocsService.AccountChanged = false;
                    }
                }
                else
                {
                    // inform user that we are starting the service
                    Status(StatusType.Authorize, "Authenticating with Google..");

                    // disable menu options for changing the Google Account, for browsing Google Docs
                    // and for saving while items are being retrieved
                    menuGoogleAccount.Enabled = false;
                    menuBrowse.Enabled        = false;
                    menuSave.Enabled          = false;

                    // run the backgroundworker for starting the service
                    BgWorkerStartService.RunWorkerAsync(false);
                }
            }
        }
Exemplo n.º 3
0
Arquivo: Main.cs Projeto: mikkoj/nocs
        private void MenuSaveClick(object sender, EventArgs e)
        {
            // let's first make sure the document content has changed
            var currentTab = tabs.SelectedTab as Noc;
            if (currentTab == null || (!currentTab.Document.IsDraft && !currentTab.ContentHasChanged))
            {
                return;
            }

            // let's stop here if we're already saving the current tab
            if (currentTab.SaveWorkerIsBusy())
            {
                return;
            }

            // make sure we are authenticated
            if (!NocsService.UserIsAuthenticated())
            {
                // user's not authenticated, let's ask for credentials to retrieve items
                var login = new Login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    RetrieveDocuments();
                }
                return;
            }

            // if current file is not new, let's just save it
            if (!currentTab.Document.IsDraft)
            {
                Status(StatusType.Save, "Saving...");
                currentTab.Save();
            }
            else
            {
                // ask for a name
                var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                {
                    Status(StatusType.Save, "Saving...");
                    currentTab.SaveAs(saveResponse);
                }
            }
        }
Exemplo n.º 4
0
Arquivo: Main.cs Projeto: mikkoj/nocs
        private void MenuGoogleAccountClick(object sender, EventArgs e)
        {
            // let's first stop all processing
            _synchronizer.Stop();
            _autoFetchAllEntriesTimer.Stop();

            // let's then find out if any of the open tabs are unsaved
            foreach (Noc tab in tabs.TabPages)
            {
                if (tab.ContentHasChanged && NocsService.UserIsAuthenticated())
                {
                    // display a msg asking the user to save changes or abort
                    var result = MessageBox.Show("Do you want to save the changes to " + tab.Text + "?", "Nocs", MessageBoxButtons.YesNoCancel);

                    if (result == DialogResult.Yes)
                    {
                        // let's stop here if we're already saving the current tab
                        if (tab.SaveWorkerIsBusy())
                        {
                            // re-enable all processing
                            _synchronizer.Start();
                            _autoFetchAllEntriesTimer.Start();
                            return;
                        }

                        // if current file is not new, let's just save it
                        if (!tab.Document.IsDraft)
                        {
                            Status(StatusType.Save, "Saving...");
                            tab.Save();
                        }
                        else
                        {
                            // ask for a name
                            var saveResponse = SaveDialog.SaveDialogBox("Enter a name for your file:", "Save", "Untitled");

                            if (!string.IsNullOrEmpty(saveResponse.DocumentName))
                            {
                                Status(StatusType.Save, "Saving...");
                                tab.SaveAs(saveResponse);
                            }
                        }

                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }

                    if (result == DialogResult.Cancel)
                    {
                        // re-enable all processing
                        _synchronizer.Start();
                        _autoFetchAllEntriesTimer.Start();
                        return;
                    }
                }
            }

            // we're past saving questions, let's show the Login dialog for changing Google account
            var login = new Login();
            login.ShowDialog();

            // let's check if user account was changed once the login window is closed
            if (NocsService.AccountChanged)
            {
                // inform the new user that we are retrieving items
                Status(StatusType.Retrieve, "Synchronizing with Google Docs...");

                // disable menu options for changing google account and opening documents while items are being retrieved
                menuGoogleAccount.Enabled = false;
                menuBrowse.Enabled = false;
                menuSave.Enabled = false;

                // reset helping variable
                NocsService.AccountChanged = false;

                // let's reset titlebar, clear tabs, etc.
                SetMainTitle(string.Empty);
                tabs.TabPages.Clear();

                // let's clear synchronizer queues
                _synchronizer.JobQueue.Clear();
                _synchronizer.ErrorQueue.Clear();

                // let's then create a new tab (Noc)
                AddNoc();

                // and finally let's run the backgroundworker to retrieve new items for this account
                BgWorkerGetAllItems.RunWorkerAsync(false);
            }
            
            // either way, let's re-enable timers
            _synchronizer.Start();
            _autoFetchAllEntriesTimer.Start();

        }
Exemplo n.º 5
0
Arquivo: Main.cs Projeto: mikkoj/nocs
        private void MenuPreferencesClick(object sender, EventArgs e)
        {
            // make sure we are authenticated
            if (!NocsService.UserIsAuthenticated())
            {
                // user's not authenticated, let's ask for credentials to retrieve items
                var login = new Login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    RetrieveDocuments();
                }
                return;
            }

            var nocsPreferences = new Preferences();
            if (nocsPreferences.ShowDialog() == DialogResult.OK)
            {
                // let's notify listeners
                if (SettingsChanged != null)
                {
                    SettingsChanged();
                }
            }

            // if proxy is enabled after preferences were saved, and for some reason the Browsing isn't enabled and
            // no worker is busy, let's try to re-retrieve all items
            if (Settings.Default.UseProxy && !menuBrowse.Enabled && !BgWorkerStartService.IsBusy && !BgWorkerGetAllItems.IsBusy)
            {
                // make sure user was validated
                if (!string.IsNullOrEmpty(NocsService.Username) && !string.IsNullOrEmpty(NocsService.Password))
                {
                    // inform user that we are retrieving items (documents)
                    Status(StatusType.Retrieve, "Retrieving the list of documents..");

                    // disable menu options for changing the Google Account and for browsing Google Docs while items are being retrieved
                    menuGoogleAccount.Enabled = false;
                    menuBrowse.Enabled = false;
                    menuSave.Enabled = false;

                    // reset help variable
                    NocsService.AccountChanged = false;

                    // run the backgroundworker for retrieving items
                    BgWorkerGetAllItems.RunWorkerAsync();
                }
            }
        }
Exemplo n.º 6
0
Arquivo: Main.cs Projeto: mikkoj/nocs
        private void MenuBrowseClick(object sender, EventArgs e)
        {
            // make sure we are authenticated
            if (!NocsService.UserIsAuthenticated())
            {
                // user's not authenticated, let's ask for credentials to retrieve items
                var login = new Login();
                if (login.ShowDialog() == DialogResult.OK)
                {
                    Status(StatusType.Retrieve, "Retrieving items...");
                    menuGoogleAccount.Enabled = false;
                    menuBrowse.Enabled = false;
                    menuSave.Enabled = false;
                    BgWorkerGetAllItems.RunWorkerAsync();
                }
                return;
            }

            var currentTab = tabs.SelectedTab as Noc;

            Browse nocsBrowse;

            // we will give the Browse-form the current selected documentId (from selected tab),
            // so the Browse-form can select it from its listBox on load
            // we'll also give Browse a reference to Synchronizer because AutoFetchAllEventFinished might fire
            if (currentTab != null && !currentTab.Document.IsDraft)
            {
                nocsBrowse = new Browse(ref _synchronizer, currentTab.Document.ResourceId);
            }
            else
            {
                nocsBrowse = new Browse(ref _synchronizer);
            }

            // Browse-form can tell us to add+load a document, or notify us of document renames/deletions
            nocsBrowse.AddDocumentToMainForm += BrowseAddDocumentToMainForm;
            nocsBrowse.DocumentRenamed += BrowseDocumentRenamed;
            nocsBrowse.DocumentDeleted += BrowseDocumentDeleted;

            nocsBrowse.ShowDialog();
        }