partial void SetSyncPath(NSObject sender) {
			bool webSync = false;

			if (!String.IsNullOrEmpty (AppDelegate.settings.webSyncURL) || !String.IsNullOrWhiteSpace (AppDelegate.settings.webSyncURL)) {
				webSync = true;
				NSAlert syncWarning = new NSAlert() {
					MessageText = "Web Sync Found",
					InformativeText = "Setting the File System Sync Path will override the Web Sync Authorization",
					AlertStyle = NSAlertStyle.Informational
				};
				syncWarning.AddButton ("OK");
				syncWarning.BeginSheet (this.Window,this,null,IntPtr.Zero);
			}

            		var openPanel = new NSOpenPanel();
            		openPanel.ReleasedWhenClosed = true;
            		openPanel.CanChooseDirectories = true;
            		openPanel.CanChooseFiles = false;
            		openPanel.CanCreateDirectories = true;
            		openPanel.Prompt = "Select Directory";

            		var result = openPanel.RunModal();
            		if (result == 1) {
                		SyncPathTextField.Cell.Title = openPanel.DirectoryUrl.Path;
				//AppDelegate.FilesystemSyncPath = openPanel.DirectoryUrl.Path;

				AppDelegate.settings.syncURL = openPanel.DirectoryUrl.Path;


                		NSAlert alert = new NSAlert () {
                    			MessageText = "File System Sync",
                    			InformativeText = "File System Sync path has been set at:\n"+AppDelegate.settings.syncURL,
                    			AlertStyle = NSAlertStyle.Warning
                		};
                		alert.AddButton ("OK");
                		alert.BeginSheet (this.Window,
                    			this,
                    			null,
					IntPtr.Zero);

				if (webSync) {
					AppDelegate.settings.webSyncURL = String.Empty;
					AppDelegate.settings.token = String.Empty;
					AppDelegate.settings.secret = String.Empty;
				}

				try {
					if (AppDelegate.settings != null){
						SettingsSync.Write(AppDelegate.settings);
						Console.WriteLine ("WRITTEN PROPERLY");
					}
				} catch (NullReferenceException ex) {
					Console.WriteLine ("ERROR - "+ex.Message);
				}
			}
        	}
Exemplo n.º 2
0
		private void MessageBox(string message, string title)
		{
			var alert = new NSAlert();
			alert.AddButton ("OK");
			alert.MessageText = title;
			alert.InformativeText = message;
			
			alert.BeginSheet(this, delegate
			{
			    alert.Dispose();
			});
		}
		partial void UpdateNotebook ( NSObject sender) {
			string updatedName = NotebookNameTextField.StringValue;

			if (string.IsNullOrEmpty (updatedName) || string.IsNullOrWhiteSpace (updatedName)) {
				NSAlert alert = new NSAlert () {
					MessageText = "Notebook Empty",
					InformativeText = "The Notebook name cannot be empty.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (this.Window,
					this,
					null,
					IntPtr.Zero);

				NotebookNameTextField.SelectText(this);
			} else {
				if (AppDelegate.Notebooks.Contains(updatedName)) {
					NSAlert alert = new NSAlert () {
						MessageText = "Notebook Already Exists",
						InformativeText = "The Notebook " + updatedName+ " already exists.",
						AlertStyle = NSAlertStyle.Warning
					};
					alert.AddButton ("OK");
					alert.BeginSheet (this.Window,
						this,
						null,
						IntPtr.Zero);

					NotebookNameTextField.SelectText(this);
				}
				else {
					string oldName = AppDelegate.currentNotebook;
					AppDelegate.Notebooks.Remove (oldName);
					Dictionary<string, Note> allNotes = AppDelegate.NoteEngine.GetNotesForNotebook (oldName);

					foreach(KeyValuePair<string, Note> note in allNotes) {
						note.Value.Notebook = updatedName;
						AppDelegate.NoteEngine.SaveNote (note.Value);
					}


					AppDelegate.currentNotebook = updatedName;
					AppDelegate.Notebooks.Add (updatedName);
					AppDelegate.RefreshNotesWindowController ();

					this.Window.Close ();
				}

			}
		}
Exemplo n.º 4
0
		public static int Run (NSAlert view, Control parent)
		{
			int ret;
			if (parent != null) {
				var window = parent.ControlObject as NSWindow;
				if (window == null && parent.ControlObject is NSView)
					window = ((NSView)parent.ControlObject).Window;
				if (window == null || !view.RespondsToSelector (new Selector ("beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:")))
					ret = view.RunModal ();
				else {
					ret = 0;
					NSApplication.SharedApplication.InvokeOnMainThread (delegate {
						view.BeginSheet (window, new MacModal (), new Selector ("alertDidEnd:returnCode:contextInfo:"), IntPtr.Zero);
						ret = NSApplication.SharedApplication.RunModalForWindow (window);
					});
				}
			} else
				ret = view.RunModal ();
			return ret;
		}
		partial void AddNotebook (NSObject sender) {
            		string notebook = NotebookName.StringValue;

			if (AppDelegate.Notebooks.Contains(notebook, StringComparer.OrdinalIgnoreCase)) {
                		//The notebook already exists, hence should not be added again
                		NSAlert alert = new NSAlert () {
                    			MessageText = "Notebook Already Exists",
                    			InformativeText = "The Notebook " + notebook + " already exists.",
                    			AlertStyle = NSAlertStyle.Warning
                		};
                		alert.AddButton ("OK");
                		alert.BeginSheet (this.Window,
                    			this,
                    			null,
                    			IntPtr.Zero);

                		NotebookName.SelectText(this);
			} else if (string.IsNullOrEmpty (notebook) || string.IsNullOrWhiteSpace (notebook)) {
				NSAlert alert = new NSAlert () {
					MessageText = "Notebook Empty",
					InformativeText = "The Notebook name cannot be empty.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (this.Window,
					this,
					null,
					IntPtr.Zero);

				NotebookName.SelectText(this);
			} else {
                		AppDelegate.Notebooks.Add (notebook);
				AppDelegate.currentNotebook = notebook;
                		Window.PerformClose (this);
                		AppDelegate.RefreshNotesWindowController ();
            		}
        }
Exemplo n.º 6
0
partial         void DeleteNote(NSObject sender)
        {
            NSAlert alert = new NSAlert () {
                MessageText = "Really delete this note?",
                InformativeText = "You are about to delete this note, this operation cannot be undone",
                AlertStyle = NSAlertStyle.Warning
            };
            alert.AddButton ("OK");
            alert.AddButton ("Cancel");
            alert.BeginSheet (WindowForSheet,
                              this,
                              new MonoMac.ObjCRuntime.Selector ("alertDidEnd:returnCode:contextInfo:"),
                              IntPtr.Zero);
        }
Exemplo n.º 7
0
		/// <summary>
		/// Syncs the notes.
		/// </summary>
		/// <param name="sender">Sender.</param>
		partial void SyncNotes(NSObject sender) {

			bool success = false;

			if (!String.IsNullOrEmpty (settings.syncURL) || !String.IsNullOrWhiteSpace (settings.syncURL)) {

				var dest_manifest_path = Path.Combine (settings.syncURL, "manifest.xml");
				SyncManifest dest_manifest;
				if (!File.Exists (dest_manifest_path)) {
					using (var output = new FileStream (dest_manifest_path, FileMode.Create)) {
						SyncManifest.Write (new SyncManifest (), output);
					}
				}
				using (var input = new FileStream (dest_manifest_path, FileMode.Open)) {
					dest_manifest = SyncManifest.Read (input);
				}
				var dest_storage = new DiskStorage (settings.syncURL);
				var dest_engine = new Engine (dest_storage);

				var client = new FilesystemSyncClient (NoteEngine, manifestTracker.Manifest);
				var server = new FilesystemSyncServer (dest_engine, dest_manifest);
				new SyncManager(client, server).DoSync ();

				// write back the dest manifest
		        	using (var output = new FileStream (dest_manifest_path, FileMode.Create)) {
					SyncManifest.Write (dest_manifest, output);
				}

				PopulateNotebookList (false);
				RefreshNotesWindowController ();

				success = true;
			}

			else if (!String.IsNullOrEmpty (settings.webSyncURL) ||!String.IsNullOrWhiteSpace (settings.webSyncURL)) {

				ServicePointManager.CertificatePolicy = new DummyCertificateManager();

				OAuthToken reused_token = new OAuthToken { Token = settings.token, Secret = settings.secret };


				ISyncClient client = new FilesystemSyncClient (NoteEngine, manifestTracker.Manifest);
				ISyncServer server = new WebSyncServer (settings.webSyncURL, reused_token);

				new SyncManager (client, server).DoSync ();

				PopulateNotebookList (false);
				RefreshNotesWindowController ();

				success = true;
			}

			if (success) {
				NSAlert alert = new NSAlert () {
					MessageText = "Sync Successful",
					InformativeText = "The sync was successful",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (null);
				alert.Window.Title = "Sync Successful";
			} else {
				NSAlert alert = new NSAlert () {
					MessageText = "Sync Failed",
					InformativeText = "The sync was not successful. Please check the Sync Settings.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (null);
				alert.Window.Title = "Sync Failed";
			}
        	}
Exemplo n.º 8
0
        /// <summary>
        /// Log Exception/Error. To display alert requires source NSWindow
        /// </summary>
        /// <param name="exception">Exception.</param>
        /// <param name="message">Message.</param>
        /// <param name="displayAlert">If set to <c>true</c> display alert.</param>
        /// <param name="source">Source.</param>
        public static void AQ_Exception(AQ_EXCEPTION_CODE exception, string message, bool displayAlert = true, NSWindow source = null)
        {
            // build entry
            string sExceptionEntry = string.Format ("{0} {1}{2}Exception: {3}{2}{4}"
                , DateTime.Now.ToShortDateString()
                , DateTime.Now.ToShortTimeString()
                , Environment.NewLine
                , exception
                , message);

            // add to log
            m_sLog += sExceptionEntry + Environment.NewLine;

            // display alert
            if (displayAlert) {
                // create and display alert
                NSAlert alert = new NSAlert ();
                alert.AlertStyle = NSAlertStyle.Warning;
                alert.MessageText = sExceptionEntry;
                alert.BeginSheet (source);
            }
        }
		public static void AuthorizeAction (NSWindow window, String serverURL) {

			if (String.IsNullOrEmpty (serverURL) || String.IsNullOrWhiteSpace (serverURL)) {
				NSAlert alert = new NSAlert () {
					MessageText = "Incorrect URL",
					InformativeText = "The Sync URL cannot be empty",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (window,
					null,
					null,
					IntPtr.Zero);

				//SyncURL.StringValue = "";
				return;

			} else {
				if (!serverURL.EndsWith ("/"))
					serverURL += "/";
			}

			HttpListener listener = new HttpListener ();
			string callbackURL = "http://localhost:9001/";
			listener.Prefixes.Add (callbackURL);
			listener.Start ();

			var callback_delegate = new OAuthAuthorizationCallback ( url => {
				Process.Start (url);

				// wait (block) until the HttpListener has received a request 
				var context = listener.GetContext ();

				// if we reach here the authentication has most likely been successfull and we have the
				// oauth_identifier in the request url query as a query parameter
				var request_url = context.Request.Url;
				string oauth_verifier = System.Web.HttpUtility.ParseQueryString (request_url.Query).Get("oauth_verifier");

				if (string.IsNullOrEmpty (oauth_verifier)) {
					// authentication failed or error
					context.Response.StatusCode = 500;
					context.Response.StatusDescription = "Error";
					context.Response.Close();
					throw new ArgumentException ("oauth_verifier");
				} else {
					// authentication successfull
					context.Response.StatusCode = 200;
					using (var writer = new StreamWriter (context.Response.OutputStream)) {
						writer.WriteLine("<h1>Authorization successfull!</h1>Go back to the Tomboy application window.");
					}
					context.Response.Close();
					return oauth_verifier;
				}
			});

			try{
				//FIXME: see http://mono-project.com/UsingTrustedRootsRespectfully for SSL warning
				ServicePointManager.CertificatePolicy = new DummyCertificateManager ();

				IOAuthToken access_token = WebSyncServer.PerformTokenExchange (serverURL, callbackURL, callback_delegate);

				AppDelegate.settings.webSyncURL = serverURL;
				AppDelegate.settings.token = access_token.Token;
				AppDelegate.settings.secret = access_token.Secret;

				SettingsSync.Write (AppDelegate.settings);

				Console.WriteLine ("Received token {0} with secret key {1}",access_token.Token, access_token.Secret);

				listener.Stop ();

				NSAlert success = new NSAlert () {
					MessageText = "Authentication Successful",
					InformativeText = "The authentication with the server has been successful. You can sync with the web server now.",
					AlertStyle = NSAlertStyle.Informational
				};
				success.AddButton ("OK");
				success.BeginSheet (window,
					window,
					null,
					IntPtr.Zero);
				return;
			} catch (Exception ex) {

				if (ex is WebException || ex is System.Runtime.Serialization.SerializationException) {

					NSAlert alert = new NSAlert () {
						MessageText = "Incorrect URL",
						InformativeText = "The URL entered " + serverURL + " is not valid for syncing",
						AlertStyle = NSAlertStyle.Warning
					};
					alert.AddButton ("OK");
					alert.BeginSheet (window,
						null,
						null,
						IntPtr.Zero);

					listener.Abort ();

					return;
				} else {
					NSAlert alert = new NSAlert () {
						MessageText = "Some Issue has occured",
						InformativeText = "Something does not seem right!",
						AlertStyle = NSAlertStyle.Warning
					};
					alert.AddButton ("OK");
					alert.BeginSheet (window,
						null,
						null,
						IntPtr.Zero);

					listener.Abort ();
				}
			}
		}
		partial void ExportNotesAction(NSObject sender) {
            		if (ExportPathTextField.StringValue != null){
                		string rootDirectory = ExportPathTextField.StringValue;
				ExportNotes.Export(rootDirectory, AppDelegate.NoteEngine);

                	NSAlert alert = new NSAlert () {
                    		MessageText = "Note Imported",
                    		InformativeText = "All the notes have been imported to local storage. Please restart the Tomboy to see your old notes",
                    		AlertStyle = NSAlertStyle.Warning
                	};
                	alert.AddButton ("OK");
                	alert.BeginSheet (this.Window,
                    		this,
                    		null,
                    		IntPtr.Zero);
            		}

        	}
		partial void EditNotebook (NSObject sender) {
			if (_notebooksTableView.SelectedRow == 0) {
				NSAlert alert = new NSAlert () {
					MessageText = "Notebook Cannot Be Edited",
					InformativeText = "You cannot edit 'All Notebooks' selection.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (this.Window,
					this,
					null,
					IntPtr.Zero);	
			} else {
				notebookEditPrompt = new NotebookEditPromptController ();
				notebookEditPrompt.Window.MakeKeyAndOrderFront (this);
			}
		}
		partial void RemoveNotebook (NSObject sender) {
			int selectedRow = _notebooksTableView.SelectedRow;
			if(selectedRow == 0) {
				//Cannot delete the All Notebooks Row
				NSAlert alert = new NSAlert () {
					MessageText = "Notebook Cannot Be Deleted",
					InformativeText = "You cannot delete 'All Notebooks' selection.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (this.Window,
					this,
					null,
					IntPtr.Zero);
			} else if(selectedRow != -1) {
				NSAlert alert = new NSAlert () {
					MessageText = "Really delete notebook?",
					InformativeText = "You are about to delete Notebook "
						+ AppDelegate.Notebooks.ElementAt(selectedRow) 
						+ ". This operation could not be un-done.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.AddButton ("Cancel");
				alert.BeginSheet (this.Window,
					this,
					new MonoMac.ObjCRuntime.Selector ("alertDidEnd:returnCode:contextInfo:"),
					IntPtr.Zero);
			}
		}
		void HandleNotebookDoubleClick (object sender, EventArgs e) {
            		if (e == null)
                		throw new ArgumentNullException("e");
            		if (sender == null)
                		throw new ArgumentNullException("sender");

			if (_notebooksTableView.SelectedRow == 0) {
				NSAlert alert = new NSAlert () {
					MessageText = "Notebook Cannot Be Edited",
					InformativeText = "You cannot edit 'All Notebooks' selection.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("OK");
				alert.BeginSheet (this.Window,
					this,
					null,
					IntPtr.Zero);	
			} else if (_notebooksTableView.SelectedRow == -1) {
				//The empty region is double clicked, hence do nothing
				return;
			} else {
				notebookEditPrompt = new NotebookEditPromptController ();
				notebookEditPrompt.Window.MakeKeyAndOrderFront (this);
			}
        	}
Exemplo n.º 14
0
		void Run (NSAlert alert)
		{
			switch (AlertOptions.SelectedTag) {
			case 0:
				alert.BeginSheet (Window, response => ShowResponse (alert, response));
				break;
			case 1:
				ShowResponse (alert, alert.RunSheetModal (Window));
				break;
			case 2:
				ShowResponse (alert, alert.RunModal ());
				break;
			default:
				ResultLabel.StringValue = "Unknown Alert Option";
				break;
			}
		}
Exemplo n.º 15
0
		private void SaveData () {
			if (noteWebView == null)
				return;

			Logger.Info ("Saving Note ID {0}", currentNoteID);

			try {
				string results = translator.To (noteWebView.MainFrame.DomDocument);
				if (string.IsNullOrEmpty(noteTitleField.Title)) {
					/* 
					 *	We save the Empty Content as pointed out by David
					 *	in the discussion -> https://github.com/tomboy-notes/tomboy.osx/issues/21#issuecomment-43675874
					 *	
					 *	The note must only be discarded when requested by the user.
					 *
					 *	Hence giving out an Alert when the Title is Empty for the user to
					 *	enter Title.
					 *	-Rashid May,2014
					 */
					NSAlert alert = new NSAlert () {
						MessageText = "Note Title Cannot be Empty",
						InformativeText = "Note title is empty and this operation is not permitted.",
						AlertStyle = NSAlertStyle.Warning
					};
					alert.AddButton ("OK");
					alert.BeginSheet (WindowForSheet,
						this,
						null,
						IntPtr.Zero);
					Logger.Debug("note content empty or null. Nothing to save for {0}", currentNoteID);
					return;
				}
                		currentNote.Title = noteTitleField.Title;
				currentNote.Text = noteTitleField.Title;//FIXME Need to see if we should actually add the title to the contents.
				currentNote.Text += Environment.NewLine; 
				currentNote.Text += results;
                		AppDelegate.NoteEngine.SaveNote (currentNote);

				if (!currentNote.Title.Equals (DisplayName))
					SetDisplayName (currentNote.Title);

				UpdateLinks();
				/*
				 * Very important piece of code.(UpdateChangeCount)
				 * This allows us to trick NSDOcument into believing that we have saved the document
				 */
				UpdateChangeCount (NSDocumentChangeType.Cleared);
                		//LoadNote();
			} catch (Exception e) {
				Logger.Error ("Failed to Save Note {0}", e);
			}
		}
		partial void Authenticate (NSObject sender) {

			if (!String.IsNullOrEmpty (AppDelegate.settings.syncURL) || !String.IsNullOrWhiteSpace (AppDelegate.settings.syncURL)) {
				NSAlert alert = new NSAlert () {
					MessageText = "File System Sync Found",
					InformativeText = "The File System Sync option would be overriden with Rainy Web Sync.",
					AlertStyle = NSAlertStyle.Warning
				};
				alert.AddButton ("Override File System Sync");
				alert.AddButton ("Cancel");
				alert.BeginSheet (this.Window,
					this,
					new MonoMac.ObjCRuntime.Selector ("alertDidEnd:returnCode:contextInfo:"),
					IntPtr.Zero);

				AppDelegate.settings.syncURL = "";
				SettingsSync.Write (AppDelegate.settings);
			} else {
				SyncPrefDialogController.AuthorizeAction (this.Window, SyncURL.StringValue);
			}
		}
Exemplo n.º 17
0
 public void SyncCompleted()
 {
     InvokeOnMainThread(delegate {
         lblStatus.StringValue = "Sync completed";
         using(NSAlert alert = new NSAlert())
         {
             alert.MessageText = "Sync completed";
             alert.InformativeText = "The sync has completed successfully.";
             alert.AlertStyle = NSAlertStyle.Informational;
             alert.BeginSheet(this.Window, () => {
                 this.Window.Close();
             });
         }
     });
 }
		partial void SetSyncPath(NSObject sender) {
            		var openPanel = new NSOpenPanel();
            		openPanel.ReleasedWhenClosed = true;
            		openPanel.CanChooseDirectories = true;
            		openPanel.CanChooseFiles = false;
            		openPanel.CanCreateDirectories = true;
            		openPanel.Prompt = "Select Directory";

            		var result = openPanel.RunModal();
            		if (result == 1) {
                		SyncPathTextField.Cell.Title = openPanel.DirectoryUrl.Path;
				//AppDelegate.FilesystemSyncPath = openPanel.DirectoryUrl.Path;

				AppDelegate.settings.syncURL = openPanel.DirectoryUrl.Path;
				SettingsSync.Write(AppDelegate.settings);

                		NSAlert alert = new NSAlert () {
                    			MessageText = "File System Sync",
                    			InformativeText = "File System Sync path has been set at:\n"+AppDelegate.settings.syncURL,
                    			AlertStyle = NSAlertStyle.Warning
                		};
                		alert.AddButton ("OK");
                			alert.BeginSheet (this.Window,
                    			this,
                    			null,
                    			IntPtr.Zero);
			}

        	}