diff --git a/SparkleShare/SparkleBubble.cs b/SparkleShare/SparkleBubble.cs new file mode 100644 index 00000000..db577b54 --- /dev/null +++ b/SparkleShare/SparkleBubble.cs @@ -0,0 +1,49 @@ +// 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 Notifications; +using SparkleShare; + +namespace SparkleShare { + + public class SparkleBubble : Notification { + + public SparkleBubble (string title, string subtext) : base (title, subtext) + { + + IconName = "folder-sparkleshare"; + Timeout = 4500; + Urgency = Urgency.Low; + + AttachToStatusIcon (SparkleUI.NotificationIcon); + + } + + + // Checks whether the system allows adding buttons to a notification, + // prevents error messages in Ubuntu. + new public void AddAction (string action, string label, ActionHandler handler) + { + + if (System.Array.IndexOf (Notifications.Global.Capabilities, "actions") > -1) + base.AddAction (action, label, handler); + + } + + } + +} diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 2e886a82..e234b8c1 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -29,32 +29,32 @@ namespace SparkleShare { public class SparkleIntro : Window { + public Entry NameEntry; + public Entry EmailEntry; + public Entry ServerEntry; + // Short alias for the translations public static string _ (string s) { return Catalog.GetString (s); } + public SparkleIntro () : base ("") { -// using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider()) - // { - // File.WriteAllText ("PublicKeyOnly.xml", rsa.ToXmlString (false)); - // File.WriteAllText ("PublicPrivate.xml", rsa.ToXmlString (true)); - //} - - BorderWidth = 0; - SetSizeRequest (640, 400); - Resizable = false; - IconName = "folder-sparkleshare"; - + BorderWidth = 0; + IconName = "folder-sparkleshare"; + Resizable = false; WindowPosition = WindowPosition.Center; - + + SetSizeRequest (640, 400); + ShowStepOne (); } - + + public void ShowStepOne () { @@ -63,139 +63,127 @@ namespace SparkleShare { // TODO: Fix the path Image side_splash = new Image ("/home/hbons/github/SparkleShare/data/side-splash.png"); - layout_horizontal.PackStart (side_splash, false, false, 0); + VBox wrapper = new VBox (false, 0); - VBox wrapper = new VBox (false, 0); - - VBox layout_vertical = new VBox (false, 0) { - BorderWidth = 30 - }; - - Label introduction = new Label ("" + - _("Welcome to SparkleShare!") + - "") { - UseMarkup = true, - Xalign = 0 - }; - - Label information = new Label (_("Before we can create a SparkleShare folder on this " + - "computer, we need a few bits of information from you.")) { - Xalign = 0, - Wrap = true - }; - - UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName); - - Label name_label = new Label ("" + _("Full Name:") + "") { - UseMarkup = true, - Xalign = 0 + VBox layout_vertical = new VBox (false, 0) { + BorderWidth = 30 }; + + Label introduction = new Label ("" + + _("Welcome to SparkleShare!") + + "") { + UseMarkup = true, + Xalign = 0 + }; + + Label information = new Label (_("Before we can create a SparkleShare folder on this " + + "computer, we need a few bits of information from you.")) { + Xalign = 0, + Wrap = true + }; - Entry name_entry = new Entry (unix_user_info.RealName); + UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName); + + Label name_label = new Label ("" + _("Full Name:") + "") { + UseMarkup = true, + Xalign = 0 + }; + + NameEntry = new Entry (unix_user_info.RealName); - Table table = new Table (6, 2, true) { - RowSpacing = 6 - }; - + Table table = new Table (6, 2, true) { + RowSpacing = 6 + }; - Entry email_entry = new Entry (""); - Label email_label = new Label ("" + _("Email:") + "") { - UseMarkup = true, - Xalign = 0 - }; + EmailEntry = new Entry (""); + Label email_label = new Label ("" + _("Email:") + "") { + UseMarkup = true, + Xalign = 0 + }; - Entry server_entry = new Entry ("ssh://gitorious.org/sparkleshare") { - Sensitive = false - }; + Entry server_entry = new Entry ("ssh://gitorious.org/sparkleshare") { + Sensitive = false + }; - Label server_label = new Label ("" + _("Folder Address:") + "") { - UseMarkup = true, - Xalign = 0, - Sensitive = false - }; + Label server_label = new Label ("" + _("Folder Address:") + "") { + UseMarkup = true, + Xalign = 0, + Sensitive = false + }; - CheckButton check_button; - check_button = new CheckButton (_("I already have access to an existing " + - "folder on a SparkleShare server")); + CheckButton check_button; + check_button = new CheckButton (_("I already subscribed to an existing " + + "folder on a SparkleShare server")); - check_button.Clicked += delegate { + check_button.Clicked += delegate { - if (check_button.Active) { + if (check_button.Active) { - server_label.Sensitive = true; - server_entry.Sensitive = true; - server_entry.HasFocus = true; + server_label.Sensitive = true; + server_entry.Sensitive = true; + server_entry.HasFocus = true; - } else { + } else { - server_label.Sensitive = false; - server_entry.Sensitive = false; + server_label.Sensitive = false; + server_entry.Sensitive = false; - } + } - ShowAll (); + ShowAll (); - }; + }; - table.Attach (name_label, 0, 1, 0, 1); - table.Attach (name_entry, 1, 2, 0, 1); - table.Attach (email_label, 0, 1, 1, 2); - table.Attach (email_entry, 1, 2, 1, 2); - table.Attach (check_button, 0, 2, 3, 4); - table.Attach (server_label, 0, 1, 4, 5); - table.Attach (server_entry, 1, 2, 4, 5); + table.Attach (name_label, 0, 1, 0, 1); + table.Attach (NameEntry, 1, 2, 0, 1); + table.Attach (email_label, 0, 1, 1, 2); + table.Attach (EmailEntry, 1, 2, 1, 2); + table.Attach (check_button, 0, 2, 3, 4); + table.Attach (server_label, 0, 1, 4, 5); + table.Attach (server_entry, 1, 2, 4, 5); - HButtonBox controls = new HButtonBox () { - BorderWidth = 12, - Layout = ButtonBoxStyle.End - }; + HButtonBox controls = new HButtonBox () { + BorderWidth = 12, + Layout = ButtonBoxStyle.End + }; - Button done_button = new Button (_("Next")); + Button done_button = new Button (_("Next")); - done_button.Clicked += delegate (object o, EventArgs args) { + done_button.Clicked += delegate (object o, EventArgs args) { - done_button.Remove (done_button.Child); + done_button.Remove (done_button.Child); - HBox hbox = new HBox (); + HBox hbox = new HBox (); - hbox.Add (new SparkleSpinner ()); - hbox.Add (new Label (_("Configuring…"))); + hbox.Add (new SparkleSpinner ()); + hbox.Add (new Label (_("Configuring…"))); - done_button.Add (hbox); + done_button.Add (hbox); - done_button.Sensitive = false; - table.Sensitive = false; + done_button.Sensitive = false; + table.Sensitive = false; - done_button.ShowAll (); + done_button.ShowAll (); - string user_name = name_entry.Text; - string user_email = email_entry.Text; + Configure (); - string config_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, ".gitconfig"); + ShowStepTwo (); - TextWriter writer = new StreamWriter (config_file_path); - writer.WriteLine ("[user]\n" + - "\tname = " + user_name + "\n" + - "\temail = " + user_email + "\n"); - writer.Close (); - - SparkleHelpers.DebugInfo ("Config", "Created '" + config_file_path + "'"); - - ShowStepTwo (); - - }; + }; - controls.Add (done_button); + controls.Add (done_button); - layout_vertical.PackStart (introduction, 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 (introduction, 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); - wrapper.PackStart (layout_vertical, true, true, 0); + wrapper.PackStart (layout_vertical, true, true, 0); - wrapper.PackStart (controls, false, true, 0); + wrapper.PackStart (controls, false, true, 0); + + layout_horizontal.PackStart (side_splash, false, false, 0); layout_horizontal.PackStart (wrapper, true, true, 0); Add (layout_horizontal); @@ -203,7 +191,8 @@ namespace SparkleShare { ShowAll (); } - + + public void ShowStepTwo () { @@ -240,6 +229,7 @@ namespace SparkleShare { HBox link_wrapper = new HBox (false, 0); LinkButton link = new LinkButton ("http://www.sparkleshare.org/", _("Learn how to host your own SparkleServer")); + link_wrapper.PackStart (link, false, false, 0); layout_vertical.PackStart (introduction, false, false, 0); @@ -270,6 +260,32 @@ namespace SparkleShare { } + + // Configure SparkleShare with the user's information + public void Configure () + { + + string config_file_path = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath, ".gitconfig"); + + TextWriter writer = new StreamWriter (config_file_path); + writer.WriteLine ("[user]\n" + + "\tname = " + NameEntry.Text + "\n" + + "\temail = " + EmailEntry.Text + "\n"); + writer.Close (); + + GenerateKeyPair (); + + SparkleHelpers.DebugInfo ("Config", "Created '" + config_file_path + "'"); + + } + + + // Generates an RSA keypair to identify this system + public void GenerateKeyPair () + { + + } + } } diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index b4598e3c..c48a0a1e 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -647,11 +647,16 @@ namespace SparkleShare { } + public class SparkleEventArgs : System.EventArgs { + + public string Message; + public SparkleEventArgs (string s) + { + Message = s; + } - - - + } } diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index f17d6434..e2f2deed 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -46,98 +46,23 @@ namespace SparkleShare { string SparklePath = SparklePaths.SparklePath; - - // Create .desktop entry in autostart folder to - // start SparkleShare on each login - switch (SparklePlatform.Name) { - case "GNOME": - - string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); - string desktopfile_path = SparkleHelpers.CombineMore (autostart_path, "sparkleshare.desktop"); - - if (!File.Exists (desktopfile_path)) { - - if (!Directory.Exists (autostart_path)) - Directory.CreateDirectory (autostart_path); - - TextWriter writer = new StreamWriter (desktopfile_path); - - writer.WriteLine ("[Desktop Entry]\n" + - "Type=Application\n" + - "Name=SparkleShare\n" + - "Exec=sparkleshare start\n" + - "Icon=folder-sparkleshare\n" + - "Terminal=false\n" + - "X-GNOME-Autostart-enabled=true"); - - writer.Close (); - - // Give the launcher the right permissions so it can be launched by the user - Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); - - SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); - - } - - break; - - } - - - // Create 'SparkleShare' folder in the user's home folder - // if it's not there already - if (!Directory.Exists (SparklePath)) { - - Directory.CreateDirectory (SparklePath); - SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePath + "'"); - - // Add a special icon to the SparkleShare folder - switch (SparklePlatform.Name) { - case "GNOME": - - Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = SparklePath + " metadata::custom-icon " + - "file:///usr/share/icons/hicolor/48x48/places/" + - "folder-sparkleshare.png"; - Process.Start (); - - break; - - } - - // Add the SparkleShare folder to the bookmarks - switch (SparklePlatform.Name) { - case "GNOME": - - string BookmarksFileName = - Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); - - if (File.Exists (BookmarksFileName)) { - TextWriter TextWriter = File.AppendText (BookmarksFileName); - TextWriter.WriteLine ("file://" + SparklePath + " SparkleShare"); - TextWriter.Close (); - } - - break; - - } - - } + EnableSystemAutostart (); + CreateSparkleShareFolder (); // Create a directory to store temporary files in if (!Directory.Exists (SparklePaths.SparkleTmpPath)) Directory.CreateDirectory (SparklePaths.SparkleTmpPath); - if (!HideUI) - NotificationIcon = new SparkleStatusIcon (); - UpdateRepositories (); // Don't create the window and status // icon when --disable-gui was given if (!HideUI) { + SparkleIntro intro = new SparkleIntro (); intro.ShowAll (); + + NotificationIcon = new SparkleStatusIcon (); // Show a notification if there are no folders yet if (SparkleShare.Repositories.Length == 0) { @@ -214,12 +139,110 @@ namespace SparkleShare { File.Create (NotifySettingFile); } + + // Creates .desktop entry in autostart folder to + // start SparkleShare automnatically at login + public void EnableSystemAutostart () + { + + switch (SparklePlatform.Name) { + + case "GNOME": + + string autostart_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".config", "autostart"); + string desktopfile_path = SparkleHelpers.CombineMore (autostart_path, "sparkleshare.desktop"); + + if (!File.Exists (desktopfile_path)) { + + if (!Directory.Exists (autostart_path)) + Directory.CreateDirectory (autostart_path); + + TextWriter writer = new StreamWriter (desktopfile_path); + + writer.WriteLine ("[Desktop Entry]\n" + + "Type=Application\n" + + "Name=SparkleShare\n" + + "Exec=sparkleshare start\n" + + "Icon=folder-sparkleshare\n" + + "Terminal=false\n" + + "X-GNOME-Autostart-enabled=true"); + + writer.Close (); + + // Give the launcher the right permissions so it can be launched by the user + Syscall.chmod (desktopfile_path, FilePermissions.S_IRWXU); + + SparkleHelpers.DebugInfo ("Config", "Created '" + desktopfile_path + "'"); + + } + + break; + + } + + } + + + public void AddToBookmarks () + { + + // Add the SparkleShare folder to the bookmarks + switch (SparklePlatform.Name) { + + case "GNOME": + + string bookmarks_file_name = Path.Combine (SparklePaths.HomePath, ".gtk-bookmarks"); + + if (File.Exists (bookmarks_file_name)) { + TextWriter writer = File.AppendText (bookmarks_file_name); + writer.WriteLine ("file://" + SparklePaths.SparklePath + " SparkleShare"); + writer.Close (); + } + + break; + + } + + } + + + // Creates the 'SparkleShare' folder in the user's home folder if + // it's not already there + public void CreateSparkleShareFolder () + { + + if (!Directory.Exists (SparklePaths.SparklePath)) { + + Directory.CreateDirectory (SparklePaths.SparklePath); + SparkleHelpers.DebugInfo ("Config", "Created '" + SparklePaths.SparklePath + "'"); + + // Add a special icon to the SparkleShare folder + switch (SparklePlatform.Name) { + + case "GNOME": + + Process.StartInfo.FileName = "gvfs-set-attribute"; + Process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " + + "file:///usr/share/icons/hicolor/48x48/places/" + + "folder-sparkleshare.png"; + Process.Start (); + + break; + + } + + AddToBookmarks (); + + } + + } public void Test (object o, SparkleEventArgs args) { Console.WriteLine ("AAAAAAAAAAAAAAAAAA"); } + public void UpdateRepositories () { @@ -228,12 +251,12 @@ namespace SparkleShare { SparkleRepo [] TmpRepos = new SparkleRepo [Directory.GetDirectories (SparklePath).Length]; int FolderCount = 0; - foreach (string Folder in Directory.GetDirectories (SparklePath)) { + foreach (string folder in Directory.GetDirectories (SparklePath)) { // Check if the folder is a git repo - if (Directory.Exists (SparkleHelpers.CombineMore (Folder, ".git"))) { + if (Directory.Exists (SparkleHelpers.CombineMore (folder, ".git"))) { - TmpRepos [FolderCount] = new SparkleRepo (Folder); + TmpRepos [FolderCount] = new SparkleRepo (folder); FolderCount++; // TODO: emblems don't show up in nautilus @@ -242,7 +265,7 @@ namespace SparkleShare { case "GNOME": Process.StartInfo.FileName = "gvfs-set-attribute"; - Process.StartInfo.Arguments = "-t string \"" + Folder + + Process.StartInfo.Arguments = "-t string \"" + folder + "\" metadata::emblems [synced]"; Process.Start (); @@ -255,7 +278,7 @@ namespace SparkleShare { } SparkleRepo a = TmpRepos [0]; - a.Added += new SparkleRepo.AddedEventHandler (Test); + a.Added += Test; SparkleShare.Repositories = new SparkleRepo [FolderCount]; @@ -264,21 +287,6 @@ namespace SparkleShare { } } - public class SparkleEventArgs : System.EventArgs { - - private string message; - - public SparkleEventArgs (string s) - { - this.message = s; - } - - public string Message () - { - return message; - } - -} }