From fc1219600e0dc26c90d84e198f5de7ea404bf946 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 31 Jul 2010 20:13:01 +0100 Subject: [PATCH] Add new fetcher class --- SparkleShare/Makefile.am | 1 + SparkleShare/SparkleFetcher.cs | 122 +++++++++++++++++ SparkleShare/SparkleIntro.cs | 238 ++++++++++++++++++++++++++++++--- SparkleShare/SparkleRepo.cs | 77 +---------- SparkleShare/SparkleShare.cs | 2 +- SparkleShare/SparkleUI.cs | 12 -- 6 files changed, 349 insertions(+), 103 deletions(-) create mode 100644 SparkleShare/SparkleFetcher.cs diff --git a/SparkleShare/Makefile.am b/SparkleShare/Makefile.am index e567a44c..faebde1d 100644 --- a/SparkleShare/Makefile.am +++ b/SparkleShare/Makefile.am @@ -10,6 +10,7 @@ LINK = $(REF_SPARKLESHARE) SOURCES = \ Defines.cs \ SparkleBubble.cs \ +SparkleFetcher.cs \ SparkleHelpers.cs \ SparkleIntro.cs \ SparklePaths.cs \ diff --git a/SparkleShare/SparkleFetcher.cs b/SparkleShare/SparkleFetcher.cs new file mode 100644 index 00000000..ad8c509e --- /dev/null +++ b/SparkleShare/SparkleFetcher.cs @@ -0,0 +1,122 @@ +// 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 System; +using System.IO; +using System.Diagnostics; + +namespace SparkleShare { + + public class SparkleFetcher { + + public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args); + public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args); + public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args); + + public event CloningStartedEventHandler CloningStarted; + public event CloningFinishedEventHandler CloningFinished; + public event CloningFailedEventHandler CloningFailed; + + private string Folder; + private string RemoteOriginUrl; + private string RepoName; + + + public SparkleFetcher (string url, string folder) + { + + RepoName = Path.GetDirectoryName (folder); + Folder = folder; + RemoteOriginUrl = url; + + } + + + public void Clone () + { + + SparkleEventArgs args = new SparkleEventArgs ("CloningStarted"); + + if (CloningStarted != null) + CloningStarted (this, args); + + Process process = new Process () { + EnableRaisingEvents = true + }; + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.FileName = "git"; + process.StartInfo.Arguments = "clone " + RemoteOriginUrl + " " + Folder; + + Console.WriteLine (Folder); + + Console.WriteLine (process.StartInfo.FileName + " " + process.StartInfo.Arguments); + + process.Exited += delegate { + + Console.WriteLine (process.ExitTime.ToString ()); + Console.WriteLine (process.ExitCode); + + if (process.ExitCode != 0) { + + args = new SparkleEventArgs ("CloningFailed"); + + if (CloningFailed != null) + CloningFailed (this, args); + + } else { + + InstallExcludeRules (); + + args = new SparkleEventArgs ("CloningFinished"); + + Console.WriteLine ("FINISHED"); + + if (CloningFinished != null) { + Console.WriteLine ("EVENT FIRED"); + CloningFinished (this, args); + } + + } + + }; + + process.Start (); + + } + + + // Add a .gitignore file to the repo + private void InstallExcludeRules () + { + + TextWriter writer; + writer = new StreamWriter (SparkleHelpers.CombineMore (SparklePaths.SparklePath, + RepoName, ".git/info/exclude")); + + writer.WriteLine ("*~"); // Ignore gedit swap files + writer.WriteLine (".*.sw?"); // Ignore vi swap files + writer.WriteLine (".DS_store"); // Ignore OSX's invisible directories + + writer.Close (); + + } + + } + +} diff --git a/SparkleShare/SparkleIntro.cs b/SparkleShare/SparkleIntro.cs index 961b598f..da5222de 100644 --- a/SparkleShare/SparkleIntro.cs +++ b/SparkleShare/SparkleIntro.cs @@ -74,7 +74,7 @@ namespace SparkleShare { BorderWidth = 30 }; - Label introduction = new Label ("" + + Label header = new Label ("" + _("Welcome to SparkleShare!") + "") { UseMarkup = true, @@ -146,7 +146,7 @@ namespace SparkleShare { controls.Add (NextButton); - layout_vertical.PackStart (introduction, false, false, 0); + 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); @@ -176,6 +176,7 @@ namespace SparkleShare { } + public void ShowStepTwo () { @@ -194,7 +195,7 @@ namespace SparkleShare { BorderWidth = 30 }; - Label introduction = new Label ("" + + Label header = new Label ("" + _("Where does your remote folder reside?") + "") { UseMarkup = true, @@ -223,13 +224,13 @@ namespace SparkleShare { ""; RadioButton radio_button_github = new RadioButton (radio_button, github_text); - + (radio_button_github.Child as Label).UseMarkup = true; (radio_button_github.Child as Label).Wrap = true; string gnome_text = "" + _("The GNOME Project") + "\n" + "" + - _("GNOME is an easy to understand interface to your computer.") + + _("GNOME is an easy to understand interface to your computer.") + " " + _("Select this option if you’re a developer or designer working on GNOME.") + ""; @@ -245,7 +246,7 @@ namespace SparkleShare { ""; RadioButton radio_button_gitorious = new RadioButton (radio_button, gitorious_text) { - Xalign = 0 + Xalign = 0 }; (radio_button_gitorious.Child as Label).UseMarkup = true; @@ -292,7 +293,7 @@ namespace SparkleShare { layout_folder.PackStart (folder_label, true, true, 12); layout_folder.PackStart (FolderEntry, true, true, 0); - + HButtonBox controls = new HButtonBox () { BorderWidth = 12, Layout = ButtonBoxStyle.End, @@ -303,9 +304,87 @@ namespace SparkleShare { AddButton.Clicked += delegate { - ShowStepTwoAndAHalf (); + string server = ""; - // TODO + if (radio_button.Active) { + + server = ServerEntry.Text; + + // Remove the trailing slash if there is one + if (server.EndsWith ("/")) + server = server.Trim ("/".ToCharArray ()); + + } + + if (radio_button_gitorious.Active) + server = "ssh://git@gitorious.org"; + + if (radio_button_github.Active) + server = "ssh://git@github.com"; + + if (radio_button_gnome.Active) + server = "ssh://git@gnome.org"; + + + string name = FolderEntry.Text; + + // Remove the starting slash if there is one + if (name.StartsWith ("/")) + name = name.Substring (1); + + + string url = server + "/" + name; + string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, name); + + SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder); + + Console.WriteLine (url); + + fetcher.CloningStarted += delegate { + + SparkleHelpers.DebugInfo ("Git", "[" + name + "] Cloning Repository"); + + }; + + + fetcher.CloningFinished += delegate { + + Console.WriteLine ("CLONING FINISHED"); + + SparkleHelpers.DebugInfo ("Git", "[" + name + "] Repository cloned"); + + Directory.Move (tmp_folder, + SparkleHelpers.CombineMore (SparklePaths.SparklePath, name)); + + // Install username and email from global file + + ShowFinishedStep (); + + }; + + + fetcher.CloningFailed += delegate { + + SparkleHelpers.DebugInfo ("Git", "[" + name + "] Cloning failed"); + + try { + + Directory.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, + name)); + + SparkleHelpers.DebugInfo ("Config", + "[" + name + "] Deleted temporary directory"); + + } catch (System.IO.DirectoryNotFoundException) { + + ShowErrorStep (); + + } + + }; + + ShowStepTwoAndAHalf (); + fetcher.Clone (); }; @@ -315,12 +394,13 @@ namespace SparkleShare { ShowStepThree (); }; + if (!StepTwoOnly) controls.Add (skip_button); controls.Add (AddButton); - layout_vertical.PackStart (introduction, false, false, 0); + layout_vertical.PackStart (header, false, false, 0); layout_vertical.PackStart (new Label (""), false, false, 3); layout_vertical.PackStart (table, false, false, 0); layout_vertical.PackStart (layout_folder, false, false, 6); @@ -340,6 +420,133 @@ namespace SparkleShare { } + private void ShowErrorStep () + { + + Remove (Child); + + Title = _("Error adding folder"); + + HBox layout_horizontal = new HBox (false, 6); + + Image side_splash = new Image (SparkleHelpers.CombineMore (Defines.PREFIX, "share", "pixmaps", + "side-splash.png")); + + VBox wrapper = new VBox (false, 0); + + VBox layout_vertical = new VBox (false, 0) { + BorderWidth = 30 + }; + + Label header = new Label ("" + + _("Something went wrong…") + + "") { + UseMarkup = true, + Xalign = 0 + }; + + Label information = new Label (_("Hey, it's an Alpha!")) { + Xalign = 0, + Wrap = true + }; + + + HButtonBox controls = new HButtonBox () { + BorderWidth = 12, + Layout = ButtonBoxStyle.End + }; + + Button try_again_button = new Button (_("Try again…")) { + Sensitive = true + }; + + try_again_button.Clicked += delegate (object o, EventArgs args) { + + ShowStepTwo (); + + }; + + controls.Add (try_again_button); + + layout_vertical.PackStart (header, false, false, 0); + layout_vertical.PackStart (information, false, false, 0); + + wrapper.PackStart (layout_vertical, true, 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); + + ShowAll (); + + } + + + private void ShowFinishedStep () + { + + Remove (Child); + + Title = _("Folder Added Successfully"); + + HBox layout_horizontal = new HBox (false, 6); + + Image side_splash = new Image (SparkleHelpers.CombineMore (Defines.PREFIX, "share", "pixmaps", + "side-splash.png")); + + VBox wrapper = new VBox (false, 0); + + VBox layout_vertical = new VBox (false, 0) { + BorderWidth = 30 + }; + + Label header = new Label ("" + + _("Done!") + + "") { + UseMarkup = true, + Xalign = 0 + }; + + Label information = new Label (_("Looks like the stars are aligned right for you!")) { + Xalign = 0, + Wrap = true + }; + + + HButtonBox controls = new HButtonBox () { + BorderWidth = 12, + Layout = ButtonBoxStyle.End + }; + + Button finish_button = new Button (_("Finish")); + + finish_button.Clicked += delegate (object o, EventArgs args) { + + SparkleShare.SparkleUI.UpdateRepositories (); + Destroy (); + + }; + + controls.Add (finish_button); + + layout_vertical.PackStart (header, false, false, 0); + layout_vertical.PackStart (information, false, false, 0); + + wrapper.PackStart (layout_vertical, true, 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); + + ShowAll (); + + } + + private void ShowStepTwoAndAHalf () { @@ -358,11 +565,12 @@ namespace SparkleShare { BorderWidth = 30 }; - Label introduction = new Label ("" + + Label header = new Label ("" + String.Format (_("Retrieving folder ‘{0}’…"), FolderEntry.Text) + "") { UseMarkup = true, - Xalign = 0 + Xalign = 0, + Wrap = true }; Label information = new Label ("" + @@ -411,7 +619,7 @@ namespace SparkleShare { HBox box = new HBox (false, 0); table.Attach (spinner, 0, 1, 0, 1); - table.Attach (introduction, 1, 2, 0, 1); + table.Attach (header, 1, 2, 0, 1); table.Attach (information, 1, 2, 1, 2); box.PackStart (table, false, false, 0); @@ -451,7 +659,7 @@ namespace SparkleShare { BorderWidth = 30 }; - Label introduction = new Label ("" + + Label header = new Label ("" + _("SparkleShare is ready to go!") + "") { UseMarkup = true, @@ -473,7 +681,7 @@ namespace SparkleShare { link_wrapper.PackStart (link, false, false, 0); - layout_vertical.PackStart (introduction, false, false, 0); + layout_vertical.PackStart (header, false, false, 0); layout_vertical.PackStart (information, false, false, 21); layout_vertical.PackStart (link_wrapper, false, false, 0); diff --git a/SparkleShare/SparkleRepo.cs b/SparkleShare/SparkleRepo.cs index 60389f78..a9c87391 100644 --- a/SparkleShare/SparkleRepo.cs +++ b/SparkleShare/SparkleRepo.cs @@ -52,9 +52,6 @@ namespace SparkleShare { public delegate void FetchingFinishedEventHandler (object o, SparkleEventArgs args); public delegate void NewCommitEventHandler (object o, NewCommitArgs args); public delegate void ConflictDetectedEventHandler (object o, SparkleEventArgs args); - public delegate void CloningStartedEventHandler (object o, SparkleEventArgs args); - public delegate void CloningFinishedEventHandler (object o, SparkleEventArgs args); - public delegate void CloningFailedEventHandler (object o, SparkleEventArgs args); public event AddedEventHandler Added; public event CommitedEventHandler Commited; @@ -64,15 +61,13 @@ namespace SparkleShare { public event FetchingFinishedEventHandler FetchingFinished; public event NewCommitEventHandler NewCommit; public event ConflictDetectedEventHandler ConflictDetected; - public event CloningStartedEventHandler CloningStarted; - public event CloningFinishedEventHandler CloningFinished; - public event CloningFailedEventHandler CloningFailed; public SparkleRepo (string path) { -// if (Directory.Exists) + if (!Directory.Exists (path)) + Directory.CreateDirectory (path); LocalPath = path; Name = Path.GetFileName (LocalPath); @@ -140,74 +135,6 @@ namespace SparkleShare { } - public void Clone () - { - - SparkleEventArgs args = new SparkleEventArgs ("CloningStarted"); - - if (CloningStarted != null) - CloningStarted (this, args); - - - Process process = new Process () { - EnableRaisingEvents = true - }; - - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - process.StartInfo.WorkingDirectory = SparklePaths.SparkleTmpPath; - process.StartInfo.Arguments = String.Format ("clone {0} {1}", RemoteOriginUrl, Name); - - process.Start (); - - process.Exited += delegate { - - if (Process.ExitCode != 0) { - - args = new SparkleEventArgs ("CloningFailed"); - - if (CloningFailed != null) - CloningFailed (this, args); - - - try { - Directory.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, Name)); - } catch (System.IO.DirectoryNotFoundException) { - SparkleHelpers.DebugInfo ("Config", "[" + Name + "] Temporary directory did not exist..."); - } - - } else { - - args = new SparkleEventArgs ("CloningFinished"); - - if (CloningFinished != null) - CloningFinished (this, args); - - - SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Repository cloned"); - - Directory.Move (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, Name), - SparkleHelpers.CombineMore (SparklePaths.SparklePath, Name)); - - // Add a .gitignore file to the repo - TextWriter writer = new StreamWriter (SparkleHelpers.CombineMore (SparklePaths.SparklePath, Name, - ".git/info/exclude")); - - writer.WriteLine ("*~"); // Ignore gedit swap files - writer.WriteLine (".*.sw?"); // Ignore vi swap files - writer.WriteLine (".DS_store"); // Ignore OSX's invisible directories - - writer.Close (); - - // TODO: Install username and email from global file - - } - - }; - - } - - private void CheckForChanges () { diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index 24931382..adbb9381 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -12,7 +12,7 @@ // 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 . +// along with this program. If not, see . using Gtk; using Mono.Unix; diff --git a/SparkleShare/SparkleUI.cs b/SparkleShare/SparkleUI.cs index 5eb690b3..33e61da6 100644 --- a/SparkleShare/SparkleUI.cs +++ b/SparkleShare/SparkleUI.cs @@ -308,18 +308,6 @@ namespace SparkleShare { Application.Invoke (UpdateStatusIconToIdle); }; - repo.CloningStarted += delegate { - Application.Invoke (UpdateStatusIconToSyncing); - }; - - repo.CloningFinished += delegate { - Application.Invoke (UpdateStatusIconToIdle); - }; - - repo.CloningFailed += delegate { - Application.Invoke (UpdateStatusIconToIdle); - }; - repo.PushingStarted += delegate { Application.Invoke (UpdateStatusIconToSyncing); };