[invitation] add cloning capability, [ui] don't get user data when not there
This commit is contained in:
parent
cf1f077eeb
commit
fce9a0a17e
|
@ -188,6 +188,26 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
// Recursively sets access rights of a folder to 'Normal'
|
||||
public static void ClearAttributes (string path)
|
||||
{
|
||||
|
||||
if (Directory.Exists (path)) {
|
||||
|
||||
string [] folders = Directory .GetDirectories (path);
|
||||
|
||||
foreach (string folder in folders)
|
||||
ClearAttributes (folder);
|
||||
|
||||
string [] files = Directory .GetFiles(path);
|
||||
|
||||
foreach (string file in files)
|
||||
File.SetAttributes (file, FileAttributes.Normal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -387,9 +387,7 @@ namespace SparkleShare {
|
|||
};
|
||||
|
||||
try_again_button.Clicked += delegate (object o, EventArgs args) {
|
||||
|
||||
ShowServerForm ();
|
||||
|
||||
};
|
||||
|
||||
AddButton (try_again_button);
|
||||
|
@ -482,24 +480,13 @@ namespace SparkleShare {
|
|||
|
||||
|
||||
Button button = new Button () {
|
||||
Sensitive = false
|
||||
Sensitive = false,
|
||||
Label = _("Finish")
|
||||
};
|
||||
|
||||
if (ServerFormOnly) {
|
||||
|
||||
button.Label = _("Finish");
|
||||
button.Clicked += delegate {
|
||||
Destroy ();
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
button.Label = _("Next");
|
||||
button.Clicked += delegate {
|
||||
ShowCompletedPage ();
|
||||
};
|
||||
|
||||
}
|
||||
button.Clicked += delegate {
|
||||
Destroy ();
|
||||
};
|
||||
|
||||
AddButton (button);
|
||||
|
||||
|
@ -584,7 +571,6 @@ namespace SparkleShare {
|
|||
{
|
||||
|
||||
string canonical_name = System.IO.Path.GetFileNameWithoutExtension (name);
|
||||
|
||||
string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, canonical_name);
|
||||
|
||||
SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder);
|
||||
|
@ -601,7 +587,7 @@ namespace SparkleShare {
|
|||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + canonical_name + "] Repository cloned");
|
||||
|
||||
ClearAttributes (tmp_folder);
|
||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||
|
||||
try {
|
||||
|
||||
|
@ -644,7 +630,7 @@ namespace SparkleShare {
|
|||
|
||||
if (Directory.Exists (tmp_folder)) {
|
||||
|
||||
ClearAttributes (tmp_folder);
|
||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||
Directory.Delete (tmp_folder, true);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "[" + name + "] Deleted temporary directory");
|
||||
|
@ -831,27 +817,6 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
// Recursively sets access rights of a folder to 'Normal'
|
||||
private void ClearAttributes (string path)
|
||||
{
|
||||
|
||||
if (Directory.Exists (path)) {
|
||||
|
||||
string [] folders = Directory .GetDirectories (path);
|
||||
|
||||
foreach (string folder in folders)
|
||||
ClearAttributes (folder);
|
||||
|
||||
string [] files = Directory .GetFiles(path);
|
||||
|
||||
foreach (string file in files)
|
||||
File.SetAttributes (file, FileAttributes.Normal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Converts a Gdk RGB color to a hex value.
|
||||
// Example: from "rgb:0,0,0" to "#000000"
|
||||
public string GdkColorToHex (Gdk.Color color)
|
||||
|
|
|
@ -18,6 +18,7 @@ using Gtk;
|
|||
using Mono.Unix;
|
||||
using SparkleLib;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Xml;
|
||||
|
@ -145,7 +146,7 @@ namespace SparkleShare {
|
|||
table.Attach (server, 1, 2, 1, 2);
|
||||
|
||||
Button reject_button = new Button (_("Reject"));
|
||||
Button accept_button = new Button (_("Accept"));
|
||||
Button accept_button = new Button (_("Accept and Sync"));
|
||||
|
||||
reject_button.Clicked += delegate {
|
||||
|
||||
|
@ -156,6 +157,15 @@ namespace SparkleShare {
|
|||
|
||||
};
|
||||
|
||||
accept_button.Clicked += delegate {
|
||||
|
||||
string url = "ssh://git@" + Server + "/projects/" + Folder;
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + Folder + "] Formed URL: " + url);
|
||||
|
||||
FetchFolder (url, Folder);
|
||||
|
||||
};
|
||||
|
||||
AddButton (reject_button);
|
||||
AddButton (accept_button);
|
||||
|
||||
|
@ -174,6 +184,232 @@ namespace SparkleShare {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private void FetchFolder (string url, string name)
|
||||
{
|
||||
|
||||
string canonical_name = System.IO.Path.GetFileNameWithoutExtension (name);
|
||||
string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, canonical_name);
|
||||
|
||||
SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder);
|
||||
|
||||
|
||||
fetcher.CloningStarted += delegate {
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + canonical_name + "] Cloning Repository");
|
||||
|
||||
};
|
||||
|
||||
|
||||
fetcher.CloningFinished += delegate {
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + canonical_name + "] Repository cloned");
|
||||
|
||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||
|
||||
try {
|
||||
|
||||
bool folder_exists = Directory.Exists (
|
||||
SparkleHelpers.CombineMore (SparklePaths.SparklePath, canonical_name));
|
||||
|
||||
int i = 1;
|
||||
while (folder_exists) {
|
||||
|
||||
i++;
|
||||
folder_exists = Directory.Exists (
|
||||
SparkleHelpers.CombineMore (SparklePaths.SparklePath, canonical_name + " (" + i + ")"));
|
||||
|
||||
}
|
||||
|
||||
string target_folder_name = canonical_name;
|
||||
|
||||
if (i > 1)
|
||||
target_folder_name += " (" + i + ")";
|
||||
|
||||
string target_folder_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
|
||||
target_folder_name);
|
||||
|
||||
Directory.Move (tmp_folder, target_folder_path);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + name + "] Error moving folder: " + e.Message);
|
||||
|
||||
}
|
||||
|
||||
Application.Invoke (delegate { ShowSuccessPage (canonical_name); });
|
||||
|
||||
};
|
||||
|
||||
|
||||
fetcher.CloningFailed += delegate {
|
||||
|
||||
SparkleHelpers.DebugInfo ("Git", "[" + canonical_name + "] Cloning failed");
|
||||
|
||||
if (Directory.Exists (tmp_folder)) {
|
||||
|
||||
SparkleHelpers.ClearAttributes (tmp_folder);
|
||||
Directory.Delete (tmp_folder, true);
|
||||
|
||||
SparkleHelpers.DebugInfo ("Config", "[" + name + "] Deleted temporary directory");
|
||||
|
||||
}
|
||||
|
||||
Application.Invoke (delegate { ShowErrorPage (); });
|
||||
|
||||
};
|
||||
|
||||
ShowSyncingPage (canonical_name);
|
||||
|
||||
fetcher.Clone ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void ShowErrorPage ()
|
||||
{
|
||||
|
||||
Reset ();
|
||||
|
||||
VBox layout_vertical = new VBox (false, 0);
|
||||
|
||||
Label header = new Label ("<span size='x-large'><b>" +
|
||||
_("Something went wrong…") +
|
||||
"</b></span>\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 ("<span size='x-large'><b>" +
|
||||
_("Folder synced successfully!") +
|
||||
"</b></span>") {
|
||||
UseMarkup = true,
|
||||
Xalign = 0
|
||||
};
|
||||
|
||||
Label information = new Label (_("Now you can access the synced files from ‘" + name + "’ " +
|
||||
"in your SparkleShare folder.")) {
|
||||
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 ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void ShowSyncingPage (string name)
|
||||
{
|
||||
|
||||
Reset ();
|
||||
|
||||
VBox layout_vertical = new VBox (false, 0);
|
||||
|
||||
Label header = new Label ("<span size='x-large'><b>" +
|
||||
String.Format (_("Syncing folder ‘{0}’…"), name) +
|
||||
"</b></span>") {
|
||||
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 ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,10 +74,6 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
UserName = GetUserName ();
|
||||
UserEmail = GetUserEmail ();
|
||||
|
||||
|
||||
bool HideUI = false;
|
||||
|
||||
// Parse the command line arguments
|
||||
|
|
|
@ -118,6 +118,11 @@ namespace SparkleShare {
|
|||
SparkleIntro intro = new SparkleIntro ();
|
||||
intro.ShowAll ();
|
||||
|
||||
} else {
|
||||
|
||||
SparkleShare.UserName = SparkleShare.GetUserName ();
|
||||
SparkleShare.UserEmail = SparkleShare.GetUserEmail ();
|
||||
|
||||
}
|
||||
|
||||
// Create the statusicon
|
||||
|
|
Loading…
Reference in a new issue