diff --git a/SparkleShare/Makefile.am b/SparkleShare/Makefile.am index e5b13290..e98fc57c 100644 --- a/SparkleShare/Makefile.am +++ b/SparkleShare/Makefile.am @@ -14,7 +14,6 @@ SOURCES = \ SparkleEntry.cs \ SparkleInfobar.cs \ SparkleIntro.cs \ - SparkleInvitation.cs \ SparkleLinController.cs \ SparkleLink.cs \ SparkleLog.cs \ diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index c117ea89..46d333b7 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -59,7 +59,7 @@ namespace SparkleShare { public delegate void OnErrorEventHandler (); public event OnInvitationEventHandler OnInvitation; - public delegate void OnInvitationEventHandler (string invitation_file_path); + public delegate void OnInvitationEventHandler (string server, string name, string token); public event ConflictNotificationRaisedEventHandler ConflictNotificationRaised; public delegate void ConflictNotificationRaisedEventHandler (); @@ -80,43 +80,7 @@ namespace SparkleShare { FolderSize = GetFolderSize (); - // Watch the SparkleShare folder - FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) { - IncludeSubdirectories = false, - EnableRaisingEvents = true, - Filter = "*" - }; - - // Remove the repository when a delete event occurs - watcher.Deleted += delegate (object o, FileSystemEventArgs args) { - - RemoveRepository (args.FullPath); - - }; - - // Add the repository when a create event occurs - watcher.Created += delegate (object o, FileSystemEventArgs args) { - - // Handle invitations when the user saves an - // invitation into the SparkleShare folder - if (args.Name.EndsWith (".sparkle")) { - - Console.WriteLine ("YYYYYYYYYYYQQ!!!!!!!"); - - if (OnInvitation != null) - OnInvitation (args.FullPath); - - } else if (Directory.Exists (Path.Combine (args.FullPath, ".git"))) { - - AddRepository (args.FullPath); - - } - - }; - - - CreateConfigurationFolders (); - + string global_config_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, "config"); // Show the introduction screen if SparkleShare isn't configured @@ -130,6 +94,51 @@ namespace SparkleShare { AddKey (); } + + + // Watch the SparkleShare folder + FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) { + IncludeSubdirectories = false, + EnableRaisingEvents = true, + Filter = "*" + }; + + // Remove the repository when a delete event occurs + watcher.Deleted += delegate (object o, FileSystemEventArgs args) { + + if (Directory.Exists (args.FullPath)) + RemoveRepository (args.FullPath); + + }; + + // Add the repository when a create event occurs + watcher.Created += delegate (object o, FileSystemEventArgs args) { + + // Handle invitations when the user saves an + // invitation into the SparkleShare folder + if (args.FullPath.StartsWith (".sparkle")) { + + XmlDocument xml_doc = new XmlDocument (); + xml_doc.Load (args.Name); + + string server = xml_doc.GetElementsByTagName ("server") [0].InnerText; + string folder = xml_doc.GetElementsByTagName ("folder") [0].InnerText; + string token = xml_doc.GetElementsByTagName ("token") [0].InnerText; + + if (OnInvitation != null) + OnInvitation (server, folder, token); + + + } else if (Directory.Exists (Path.Combine (args.FullPath, ".git"))) { + + AddRepository (args.FullPath); + + } + + }; + + + CreateConfigurationFolders (); Thread thread = new Thread ( new ThreadStart (PopulateRepositories) @@ -139,7 +148,45 @@ namespace SparkleShare { } - + + // Uploads the user's public key to the server + public bool AcceptInvitation (string server, string folder, string token) + { + + // The location of the user's public key for SparkleShare + string public_key_file_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".ssh", + "sparkleshare." + SparkleShare.Controller.UserEmail + ".key.pub"); + + if (!File.Exists (public_key_file_path)) + return false; + + StreamReader reader = new StreamReader (public_key_file_path); + string public_key = reader.ReadToEnd (); + reader.Close (); + + string url = "https://" + server + "/?folder=" + folder + + "&token=" + token + "&pubkey=" + public_key; + + SparkleHelpers.DebugInfo ("WebRequest", url); + + HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); + HttpWebResponse response = (HttpWebResponse) request.GetResponse(); + + if (response.StatusCode == HttpStatusCode.OK) { + + response.Close (); + return true; + + } else { + + response.Close (); + return false; + + } + + } + + public List Folders { @@ -309,13 +356,13 @@ namespace SparkleShare { private void RemoveRepository (string folder_path) { - string repo_name = Path.GetFileName (folder_path); + string folder_name = Path.GetFileName (folder_path); for (int i = 0; i < Repositories.Count; i++) { SparkleRepo repo = Repositories [i]; - if (repo.Name.Equals (repo_name)) { + if (repo.Name.Equals (folder_name)) { Repositories.Remove (repo); repo.Dispose (); @@ -659,6 +706,8 @@ namespace SparkleShare { public void FetchFolder (string url, string name) { + SparkleHelpers.DebugInfo ("Controller", "Formed URL: " + url); + // Strip the '.git' from the name string canonical_name = System.IO.Path.GetFileNameWithoutExtension (name); string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, canonical_name); diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 27d46bc0..c9bed7c9 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -48,12 +48,10 @@ namespace SparkleShare { ServerFormOnly = false; SecondaryTextColor = SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)); - ShowAccountForm (); - } - - private void ShowAccountForm () + + public void ShowAccountForm () { Reset (); @@ -430,6 +428,105 @@ namespace SparkleShare { } + public void ShowInvitationPage (string server, string folder, string token) + { + + VBox layout_vertical = new VBox (false, 0); + + Label header = new Label ("" + + _("Invitation received!") + + "") { + UseMarkup = true, + Xalign = 0 + }; + + Label information = new Label (_("You've received an invitation to join a shared folder.\n" + + "We're ready to hook you up immediately if you wish.")) { + Xalign = 0, + Wrap = true + }; + + Label question = new Label (_("Do you accept this invitation?")) { + Xalign = 0, + Wrap = true + }; + + Table table = new Table (2, 2, false) { + RowSpacing = 6 + }; + + Label server_label = new Label (_("Server Address:")) { + Xalign = 0 + }; + + Label server_text = new Label ("" + server + "") { + UseMarkup = true, + Xalign = 0 + }; + + Label folder_label = new Label (_("Folder Name:")) { + Xalign = 0 + }; + + Label folder_text = new Label ("" + folder + "") { + UseMarkup = true, + Xalign = 0 + }; + + table.Attach (folder_label, 0, 1, 0, 1); + table.Attach (folder_text, 1, 2, 0, 1); + table.Attach (server_label, 0, 1, 1, 2); + table.Attach (server_text, 1, 2, 1, 2); + + Button reject_button = new Button (_("Reject")); + Button accept_button = new Button (_("Accept and Sync")); + + reject_button.Clicked += delegate { + + Destroy (); + + }; + + accept_button.Clicked += delegate { + + string url = "ssh://git@" + server + "/" + folder; + + SparkleShare.Controller.FolderFetched += delegate { + + Application.Invoke (delegate { + ShowSuccessPage (folder); + }); + + }; + + SparkleShare.Controller.FolderFetchError += delegate { + + Application.Invoke (delegate { ShowErrorPage (); }); + + }; + + + SparkleShare.Controller.FetchFolder (url, folder); + + }; + + AddButton (reject_button); + AddButton (accept_button); + + layout_vertical.PackStart (header, false, false, 0); + layout_vertical.PackStart (information, false, false, 21); + layout_vertical.PackStart (new Label (""), false, false, 0); + layout_vertical.PackStart (table, false, false, 0); + layout_vertical.PackStart (new Label (""), false, false, 0); + layout_vertical.PackStart (question, false, false, 21); + + Add (layout_vertical); + + ShowAll (); + + } + + // The page shown when syncing has failed private void ShowErrorPage () { diff --git a/SparkleShare/SparkleInvitation.cs b/SparkleShare/SparkleInvitation.cs index a90b1a73..3f2ff2d6 100644 --- a/SparkleShare/SparkleInvitation.cs +++ b/SparkleShare/SparkleInvitation.cs @@ -1,351 +1,5 @@ -// SparkleShare, an instant update workflow to Git. -// Copyright (C) 2010 Hylke Bons -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -using Gtk; -using Mono.Unix; -using SparkleLib; -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Xml; -namespace SparkleShare { - class SparkleInvitation : SparkleWindow { - public string Server; - public string Folder; - public string InviteKey; - public string FilePath; - - // Short alias for the translations - public static string _ (string s) - { - return Catalog.GetString (s); - } - - - public SparkleInvitation (string file_path) - { - - if (!File.Exists (file_path)) - return; - - FilePath = file_path; - - XmlDocument xml_doc = new XmlDocument (); - xml_doc.Load (file_path); - - XmlNodeList server_xml = xml_doc.GetElementsByTagName ("server"); - XmlNodeList folder_xml = xml_doc.GetElementsByTagName ("folder"); - XmlNodeList invite_key_xml = xml_doc.GetElementsByTagName ("invite_key"); - - Server = server_xml [0].InnerText; - Folder = folder_xml [0].InnerText; - InviteKey = invite_key_xml [0].InnerText; - - } - - - // Uploads the user's public key to the - // server and starts the syncing process - public void Configure () - { - - // TODO: Move to controller - - // The location of the user's public key for SparkleShare - string public_key_file_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".ssh", - "sparkleshare." + SparkleShare.Controller.UserEmail + ".key.pub"); - - if (!File.Exists (public_key_file_path)) - return; - - StreamReader reader = new StreamReader (public_key_file_path); - string public_key = reader.ReadToEnd (); - reader.Close (); - - string url = "http://" + Server + "/folder=" + Folder + - "&invite=" + InviteKey + - "&key=" + public_key; - - SparkleHelpers.DebugInfo ("WebRequest", url); - - HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); - HttpWebResponse response = (HttpWebResponse) request.GetResponse(); - - if (response.StatusCode == HttpStatusCode.OK) - File.Delete (FilePath); - - response.Close (); - - } - - - new public void Present () - { - - VBox layout_vertical = new VBox (false, 0); - - Label header = new Label ("" + - _("Invitation received!") + - "") { - UseMarkup = true, - Xalign = 0 - }; - - Label information = new Label (_("You've received an invitation to join a shared folder.\n" + - "We're ready to hook you up immediately if you wish.")) { - Xalign = 0, - Wrap = true - }; - - Label question = new Label (_("Do you accept this invitation?")) { - Xalign = 0, - Wrap = true - }; - - Table table = new Table (2, 2, false) { - RowSpacing = 6 - }; - - Label server_label = new Label (_("Server Address:")) { - Xalign = 0 - }; - - Label server = new Label ("" + Server + "") { - UseMarkup = true, - Xalign = 0 - }; - - Label folder_label = new Label (_("Folder Name:")) { - Xalign = 0 - }; - - Label folder = new Label ("" + Folder + "") { - UseMarkup = true, - Xalign = 0 - }; - - table.Attach (folder_label, 0, 1, 0, 1); - table.Attach (folder, 1, 2, 0, 1); - table.Attach (server_label, 0, 1, 1, 2); - table.Attach (server, 1, 2, 1, 2); - - Button reject_button = new Button (_("Reject")); - Button accept_button = new Button (_("Accept and Sync")); - - reject_button.Clicked += delegate { - - Destroy (); - - }; - - accept_button.Clicked += delegate { - - string url = "ssh://git@" + Server + "/" + Folder; - SparkleHelpers.DebugInfo ("Git", "[" + Folder + "] Formed URL: " + url); - - - - SparkleShare.Controller.FolderFetched += delegate { - - Application.Invoke (delegate { - ShowSuccessPage (Folder); - }); - - }; - - SparkleShare.Controller.FolderFetchError += delegate { - - Application.Invoke (delegate { ShowErrorPage (); }); - - }; - - - SparkleShare.Controller.FetchFolder (url, Folder); - - }; - - AddButton (reject_button); - AddButton (accept_button); - - layout_vertical.PackStart (header, false, false, 0); - layout_vertical.PackStart (information, false, false, 21); - layout_vertical.PackStart (new Label (""), false, false, 0); - layout_vertical.PackStart (table, false, false, 0); - layout_vertical.PackStart (new Label (""), false, false, 0); - layout_vertical.PackStart (question, false, false, 21); - - Add (layout_vertical); - - ShowAll (); - - base.Present (); - - } - - - private void ShowErrorPage () - { - - Reset (); - - VBox layout_vertical = new VBox (false, 0); - - Label header = new Label ("" + - _("Something went wrong…") + - "\n") { - UseMarkup = true, - Xalign = 0 - }; - - Button close_button = new Button (_("Close")) { - Sensitive = true - }; - - close_button.Clicked += delegate (object o, EventArgs args) { - Destroy (); - }; - - AddButton (close_button); - - layout_vertical.PackStart (header, false, false, 0); - - Add (layout_vertical); - - ShowAll (); - - } - - - private void ShowSuccessPage (string name) - { - - Reset (); - - VBox layout_vertical = new VBox (false, 0); - - Label header = new Label ("" + - _("Folder synced successfully!") + - "") { - UseMarkup = true, - Xalign = 0 - }; - - Label information = new Label (String.Format(_("Now you can access the synced files from ‘{0}’ in your SparkleShare folder."), - name)) { - Xalign = 0, - Wrap = true, - UseMarkup = true - }; - - Button open_folder_button = new Button (_("Open Folder")); - - open_folder_button.Clicked += delegate (object o, EventArgs args) { - - string path = SparkleHelpers.CombineMore (SparklePaths.SparklePath, name); - - Process process = new Process (); - process.StartInfo.FileName = "xdg-open"; - process.StartInfo.Arguments = path.Replace (" ", "\\ "); // Escape space-characters - process.Start (); - - Destroy (); - - }; - - Button finish_button = new Button (_("Finish")); - - finish_button.Clicked += delegate (object o, EventArgs args) { - Destroy (); - }; - - AddButton (open_folder_button); - AddButton (finish_button); - - layout_vertical.PackStart (header, false, false, 0); - layout_vertical.PackStart (information, false, false, 21); - - Add (layout_vertical); - - ShowAll (); - - } - - // TODO: These pages are identical to the intro ones, - // find a way to remove duplication - private void ShowSyncingPage (string name) - { - - Reset (); - - VBox layout_vertical = new VBox (false, 0); - - Label header = new Label ("" + - String.Format (_("Syncing folder ‘{0}’…"), name) + - "") { - UseMarkup = true, - Xalign = 0, - Wrap = true - }; - - Label information = new Label (_("This may take a while.\n") + - _("You sure it’s not coffee o-clock?")) { - UseMarkup = true, - Xalign = 0 - }; - - - Button button = new Button () { - Sensitive = false, - Label = _("Finish") - }; - - button.Clicked += delegate { - Destroy (); - }; - - AddButton (button); - - SparkleSpinner spinner = new SparkleSpinner (22); - - Table table = new Table (2, 2, false) { - RowSpacing = 12, - ColumnSpacing = 9 - }; - - HBox box = new HBox (false, 0); - - table.Attach (spinner, 0, 1, 0, 1); - table.Attach (header, 1, 2, 0, 1); - table.Attach (information, 1, 2, 1, 2); - - box.PackStart (table, false, false, 0); - - layout_vertical.PackStart (box, false, false, 0); - - Add (layout_vertical); - - ShowAll (); - - } - - } - -} diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index f7b861d2..e3ee7f96 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -55,22 +55,22 @@ namespace SparkleShare { if (SparkleShare.Controller.FirstRun) { - SparkleIntro intro = new SparkleIntro (); - intro.ShowAll (); - intro.Present (); + SparkleIntro intro = new SparkleIntro (); + intro.ShowAccountForm (); } SparkleShare.Controller.OnQuitWhileSyncing += delegate { + // TODO: Pop up a warning when quitting whilst syncing + }; - SparkleShare.Controller.OnInvitation += delegate (string invitation_file_path) { + SparkleShare.Controller.OnInvitation += delegate (string server, string folder, string token) { Application.Invoke (delegate { - - Console.WriteLine ("INVITATION RECEIVED!!!!1"); - SparkleInvitation invitation = new SparkleInvitation (invitation_file_path); - invitation.Present (); + + SparkleIntro intro = new SparkleIntro (); + intro.ShowInvitationPage (server, folder, token); }); }; diff --git a/data/gnome-design.sparkle b/data/gnome-design.sparkle index 0f237b93..b44c8a77 100644 --- a/data/gnome-design.sparkle +++ b/data/gnome-design.sparkle @@ -1,7 +1,9 @@ + - - - - + + git.gnome.org + gnome-design + a22bc6f4b9ffe8e5acd4be0838d41aa10a1187dd + diff --git a/data/sparkleshare.invitation b/data/sparkleshare.invitation deleted file mode 100644 index 33b48b43..00000000 --- a/data/sparkleshare.invitation +++ /dev/null @@ -1,6 +0,0 @@ - - - git.gnome.org - gnome-design - a22bc6f4b9ffe8e5acd4be0838d41aa10a1187dd -