[intro] code cleanup

This commit is contained in:
Hylke Bons 2010-08-14 15:08:04 +01:00
parent 38eb444e88
commit 06d41a13a7
4 changed files with 438 additions and 716 deletions

View file

@ -24,17 +24,18 @@ using System.Text.RegularExpressions;
namespace SparkleShare {
public class SparkleIntro : Window {
public class SparkleIntro : SparkleWindow {
private Entry NameEntry;
private Entry EmailEntry;
private SparkleEntry ServerEntry;
private SparkleEntry FolderEntry;
private Button NextButton;
private Button AddButton;
private bool StepTwoOnly;
private Button SyncButton;
private bool ServerFormOnly;
private string SecondaryTextColor;
// Short alias for the translations
public static string _ (string s)
{
@ -42,39 +43,23 @@ namespace SparkleShare {
}
public SparkleIntro () : base ("")
public SparkleIntro () : base ()
{
BorderWidth = 0;
IconName = "folder-sparkleshare";
Resizable = true;
WindowPosition = WindowPosition.Center;
ServerFormOnly = false;
SecondaryTextColor = GdkColorToHex (Style.Foreground (StateType.Insensitive));
StepTwoOnly = false;
SetDefaultSize (640, 480);
Window window = new Window ("");
SecondaryTextColor = GdkColorToHex (window.Style.Foreground (StateType.Insensitive));
ShowStepOne ();
ShowAccountForm ();
}
private void ShowStepOne ()
private void ShowAccountForm ()
{
HBox layout_horizontal = new HBox (false, 6);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
_("Welcome to SparkleShare!") +
@ -102,13 +87,13 @@ namespace SparkleShare {
NameEntry = new Entry (unix_user_info.RealName);
NameEntry.Changed += delegate {
CheckStepOneFields ();
CheckAccountForm ();
};
EmailEntry = new Entry (GetUserEmail ());
EmailEntry.Changed += delegate {
CheckStepOneFields ();
CheckAccountForm ();
};
Label email_label = new Label ("<b>" + _("Email:") + "</b>") {
@ -122,11 +107,6 @@ namespace SparkleShare {
table.Attach (email_label, 0, 1, 1, 2);
table.Attach (EmailEntry, 1, 2, 1, 2);
HButtonBox controls = new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End
};
NextButton = new Button (_("Next")) {
Sensitive = false
};
@ -142,58 +122,41 @@ namespace SparkleShare {
NextButton.ShowAll ();
Configure ();
ShowStepTwo ();
ShowServerForm ();
};
controls.Add (NextButton);
AddButton (NextButton);
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 (check_button, false, false, 0);
Add (layout_vertical);
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);
CheckStepOneFields ();
CheckAccountForm ();
ShowAll ();
}
public void ShowStepTwo (bool step_two_only)
public void ShowServerForm (bool server_form_only)
{
StepTwoOnly = step_two_only;
ShowStepTwo ();
ServerFormOnly = server_form_only;
ShowServerForm ();
}
public void ShowStepTwo ()
public void ShowServerForm ()
{
Remove (Child);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
_("Where is your remote folder?") +
@ -212,7 +175,7 @@ namespace SparkleShare {
ExampleText = _("ssh://address-to-my-server/")
};
ServerEntry.Changed += CheckStepTwoFields;
ServerEntry.Changed += CheckServerForm;
RadioButton radio_button = new RadioButton ("<b>" + _("On my own server:") + "</b>");
@ -281,12 +244,12 @@ namespace SparkleShare {
FolderEntry.ExampleText = "Folder";
ServerEntry.Sensitive = true;
CheckStepTwoFields ();
CheckServerForm ();
} else {
ServerEntry.Sensitive = false;
CheckStepTwoFields ();
CheckServerForm ();
}
@ -305,7 +268,7 @@ namespace SparkleShare {
ExampleText = "Folder"
};
FolderEntry.Changed += CheckStepTwoFields;
FolderEntry.Changed += CheckServerForm;
Label folder_label = new Label ("<b>" + _("Folder Name:") + "</b>") {
UseMarkup = true,
@ -317,16 +280,9 @@ namespace SparkleShare {
layout_folder.PackStart (folder_label, true, true, 12);
layout_folder.PackStart (FolderEntry, true, true, 0);
SyncButton = new Button (_("Sync"));
HButtonBox controls = new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End,
Spacing = 6
};
AddButton = new Button (_("Sync"));
AddButton.Clicked += delegate {
SyncButton.Clicked += delegate {
string name = FolderEntry.Text;
@ -374,7 +330,7 @@ namespace SparkleShare {
SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder);
Console.WriteLine (url);
SparkleHelpers.DebugInfo ("Git", "[" + name + "] Formed URL: " + url);
fetcher.CloningStarted += delegate {
@ -422,7 +378,7 @@ namespace SparkleShare {
}
Application.Invoke (delegate { ShowFinishedStep (); });
Application.Invoke (delegate { ShowSuccessPage (); });
};
@ -441,17 +397,17 @@ namespace SparkleShare {
}
Application.Invoke (delegate { ShowErrorStep (); });
Application.Invoke (delegate { ShowErrorPage (); });
};
ShowStepTwoAndAHalf ();
ShowSyncingPage ();
fetcher.Clone ();
};
if (StepTwoOnly) {
if (ServerFormOnly) {
Button cancel_button = new Button (_("Cancel"));
@ -459,7 +415,7 @@ namespace SparkleShare {
Destroy ();
};
controls.Add (cancel_button);
AddButton (cancel_button);
} else {
@ -467,51 +423,35 @@ namespace SparkleShare {
Button skip_button = new Button (_("Skip"));
skip_button.Clicked += delegate {
ShowStepThree ();
ShowCompletedPage ();
};
controls.Add (skip_button);
AddButton (skip_button);
}
controls.Add (AddButton);
AddButton (SyncButton);
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);
wrapper.PackStart (layout_vertical, true, true, 0);
wrapper.PackStart (controls, false, true, 0);
Add (layout_vertical);
layout_horizontal.PackStart (side_splash, false, false, 0);
layout_horizontal.PackStart (wrapper, true, true, 0);
Add (layout_horizontal);
CheckStepTwoFields ();
CheckServerForm ();
ShowAll ();
}
private void ShowErrorStep ()
private void ShowErrorPage ()
{
Remove (Child);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
_("Something went wrong…") +
@ -528,55 +468,34 @@ namespace SparkleShare {
UseMarkup = 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 ();
ShowServerForm ();
};
controls.Add (try_again_button);
AddButton (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);
Add (layout_vertical);
ShowAll ();
}
private void ShowFinishedStep ()
private void ShowSuccessPage ()
{
Remove (Child);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
_("Folder synced successfully!") +
@ -593,51 +512,30 @@ namespace SparkleShare {
UseMarkup = true
};
HButtonBox controls = new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End
};
Button finish_button = new Button (_("Finish"));
finish_button.Clicked += delegate (object o, EventArgs args) {
Destroy ();
};
controls.Add (finish_button);
AddButton (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);
Add (layout_vertical);
ShowAll ();
}
private void ShowStepTwoAndAHalf ()
private void ShowSyncingPage ()
{
Remove (Child);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
String.Format (_("Syncing folder {0}’…"), FolderEntry.Text) +
@ -655,17 +553,12 @@ namespace SparkleShare {
Xalign = 0
};
HButtonBox controls = new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End,
Spacing = 6
};
Button button = new Button () {
Sensitive = false
};
if (StepTwoOnly) {
if (ServerFormOnly) {
button.Label = _("Finish");
button.Clicked += delegate {
@ -676,12 +569,12 @@ namespace SparkleShare {
button.Label = _("Next");
button.Clicked += delegate {
ShowStepThree ();
ShowCompletedPage ();
};
}
controls.Add (button);
AddButton (button);
SparkleSpinner spinner = new SparkleSpinner (22);
@ -700,36 +593,19 @@ namespace SparkleShare {
layout_vertical.PackStart (box, 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);
CheckStepTwoFields ();
Add (layout_vertical);
ShowAll ();
}
private void ShowStepThree ()
private void ShowCompletedPage ()
{
Remove (Child);
Reset ();
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
};
VBox layout_vertical = new VBox (false, 0);
Label header = new Label ("<span size='x-large'><b>" +
_("SparkleShare is ready to go!") +
@ -757,11 +633,6 @@ namespace SparkleShare {
layout_vertical.PackStart (information, false, false, 21);
layout_vertical.PackStart (link_wrapper, false, false, 0);
HButtonBox controls = new HButtonBox () {
Layout = ButtonBoxStyle.End,
BorderWidth = 12
};
Button finish_button = new Button (_("Finish"));
finish_button.Clicked += delegate (object o, EventArgs args) {
@ -773,15 +644,9 @@ namespace SparkleShare {
};
controls.Add (finish_button);
AddButton (finish_button);
wrapper.PackStart (layout_vertical, true, true, 0);
wrapper.PackStart (controls, false, false, 0);
layout_horizontal.PackStart (side_splash, false, false, 0);
layout_horizontal.PackStart (wrapper, true, true, 0);
Add (layout_horizontal);
Add (layout_vertical);
ShowAll ();
@ -790,7 +655,7 @@ namespace SparkleShare {
// Enables or disables the 'Next' button depending on the
// entries filled in by the user
private void CheckStepOneFields ()
private void CheckAccountForm ()
{
if (NameEntry.Text.Length > 0 &&
@ -809,30 +674,30 @@ namespace SparkleShare {
// Enables the Add button when the fields are
// filled in correctly
public void CheckStepTwoFields (object o, EventArgs args)
public void CheckServerForm (object o, EventArgs args)
{
CheckStepTwoFields ();
CheckServerForm ();
}
// Enables the Add button when the fields are
// filled in correctly
public void CheckStepTwoFields ()
public void CheckServerForm ()
{
AddButton.Sensitive = false;
SyncButton.Sensitive = false;
bool IsFolder = !FolderEntry.Text.Trim ().Equals ("");
if (ServerEntry.Sensitive == true) {
if (IsGitUrl (ServerEntry.Text) && IsFolder)
AddButton.Sensitive = true;
SyncButton.Sensitive = true;
} else if (IsFolder) {
AddButton.Sensitive = true;
SyncButton.Sensitive = true;
}

View file

@ -243,7 +243,7 @@ namespace SparkleShare {
add_item.Activated += delegate {
SparkleIntro intro = new SparkleIntro ();
intro.ShowStepTwo (true);
intro.ShowServerForm (true);
intro.ShowAll ();
};

View file

@ -49,7 +49,7 @@ namespace SparkleShare {
BusG.Init ();
Gtk.Application.Init ();
SparkleInvitation i = new SparkleInvitation ("/home/hbons/SparkleShare/sparkleshare.invitation");
// SparkleInvitation i = new SparkleInvitation ("/home/hbons/SparkleShare/sparkleshare.invitation");
SetProcessName ("sparkleshare");

View file

@ -28,232 +28,89 @@ namespace SparkleShare {
public class SparkleWindow : Window {
// Short alias for the translations
public static string _ (string s)
{
return Catalog.GetString (s);
}
private HBox HBox;
private VBox VBox;
private VBox Wrapper;
private HButtonBox Buttons;
private SparkleRepo SparkleRepo;
private VBox LayoutVertical;
private ScrolledWindow ScrolledWindow;
public SparkleWindow (SparkleRepo sparkle_repo) : base ("")
public SparkleWindow () : base ("")
{
SparkleRepo = sparkle_repo;
SetSizeRequest (540, 640);
SetPosition (WindowPosition.Center);
BorderWidth = 12;
BorderWidth = 0;
IconName = "folder-sparkleshare";
Resizable = true;
WindowPosition = WindowPosition.Center;
// TRANSLATORS: {0} is a folder name, and {1} is a server address
Title = String.Format(_("Recent Events in {0}"), SparkleRepo.Name);
IconName = "folder";
SetDefaultSize (640, 480);
LayoutVertical = new VBox (false, 12);
Buttons = CreateButtonBox ();
LayoutVertical.PackStart (CreateEventLog (), true, true, 0);
HBox = new HBox (false, 6);
HButtonBox dialog_buttons = new HButtonBox {
Layout = ButtonBoxStyle.Edge,
BorderWidth = 0
string image_path = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "pixmaps", "side-splash.png");
Image side_splash = new Image (image_path);
VBox = new VBox (false, 0);
Wrapper = new VBox (false, 0) {
BorderWidth = 30
};
Button open_folder_button = new Button (_("Open Folder"));
open_folder_button.Clicked += delegate (object o, EventArgs args) {
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
string path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
SparkleRepo.Name);
process.StartInfo.Arguments = path.Replace(" ", "\\ ");
process.Start ();
Destroy ();
};
VBox.PackStart (Wrapper, true, true, 0);
VBox.PackStart (Buttons, false, false, 0);
Button close_button = new Button (Stock.Close);
close_button.Clicked += delegate (object o, EventArgs args) {
Destroy ();
};
HBox.PackStart (side_splash, false, false, 0);
HBox.PackStart (VBox, true, true, 0);
dialog_buttons.Add (open_folder_button);
dialog_buttons.Add (close_button);
LayoutVertical.PackStart (dialog_buttons, false, false, 0);
Add (LayoutVertical);
base.Add (HBox);
}
public void UpdateEventLog ()
private HButtonBox CreateButtonBox ()
{
LayoutVertical.Remove (ScrolledWindow);
ScrolledWindow = CreateEventLog ();
LayoutVertical.PackStart (ScrolledWindow, true, true, 0);
LayoutVertical.ReorderChild (ScrolledWindow, 0);
return new HButtonBox () {
BorderWidth = 12,
Layout = ButtonBoxStyle.End,
Spacing = 6
};
}
public void AddButton (Button button)
{
Buttons.Add (button);
ShowAll ();
}
private ScrolledWindow CreateEventLog ()
new public void Add (Widget widget)
{
int number_of_events = 50;
Process process = new Process ();
process.EnableRaisingEvents = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath;
process.StartInfo.FileName = "git";
process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -" + number_of_events;
process.Start ();
string output = process.StandardOutput.ReadToEnd ().Trim ();
output = output.TrimStart ("\n".ToCharArray ());
string [] lines = Regex.Split (output, "\n");
int linesLength = lines.Length;
if (output == "")
linesLength = 0;
// Sort by time and get the last 25
Array.Sort (lines);
Array.Reverse (lines);
List <ActivityDay> activity_days = new List <ActivityDay> ();
for (int i = 0; i < number_of_events && i < linesLength; i++) {
string line = lines [i];
// Look for the snowman!
string [] parts = Regex.Split (line, "☃");
int unix_timestamp = int.Parse (parts [0]);
string user_name = parts [1];
string user_email = parts [2];
string message = parts [3];
DateTime date_time = UnixTimestampToDateTime (unix_timestamp);
message = message.Replace ("/", " ‣ ");
message = message.Replace ("\n", " ");
ChangeSet change_set = new ChangeSet (user_name, user_email, message, date_time);
bool change_set_inserted = false;
foreach (ActivityDay stored_activity_day in activity_days) {
if (stored_activity_day.DateTime.Year == change_set.DateTime.Year &&
stored_activity_day.DateTime.Month == change_set.DateTime.Month &&
stored_activity_day.DateTime.Day == change_set.DateTime.Day) {
stored_activity_day.Add (change_set);
change_set_inserted = true;
break;
}
}
if (!change_set_inserted) {
ActivityDay activity_day = new ActivityDay (change_set.DateTime);
activity_day.Add (change_set);
activity_days.Add (activity_day);
}
}
VBox layout_vertical = new VBox (false, 0);
foreach (ActivityDay activity_day in activity_days) {
TreeIter iter = new TreeIter ();
ListStore list_store = new ListStore (typeof (Gdk.Pixbuf),
typeof (string),
typeof (string));
foreach (ChangeSet change_set in activity_day) {
iter = list_store.Append ();
list_store.SetValue (iter, 0, SparkleHelpers.GetAvatar (change_set.UserEmail , 32));
list_store.SetValue (iter, 1, "<b>" + change_set.UserName + "</b>\n" +
"<span fgcolor='#777'>" + change_set.Message + "</span>");
list_store.SetValue (iter, 2, change_set.UserEmail);
}
Label date_label = new Label ("") {
UseMarkup = true,
Xalign = 0,
Xpad = 9,
Ypad = 9
};
DateTime today = DateTime.Now;
DateTime yesterday = DateTime.Now.AddDays (-1);
if (today.Day == activity_day.DateTime.Day &&
today.Month == activity_day.DateTime.Month &&
today.Year == activity_day.DateTime.Year) {
date_label.Markup = "<b>Today</b>";
} else if (yesterday.Day == activity_day.DateTime.Day &&
yesterday.Month == activity_day.DateTime.Month &&
yesterday.Year == activity_day.DateTime.Year) {
date_label.Markup = "<b>Yesterday</b>";
} else {
date_label.Markup = "<b>" + activity_day.DateTime.ToString ("ddd MMM d, yyyy") + "</b>";
}
layout_vertical.PackStart (date_label, false, false, 0);
IconView icon_view = new IconView (list_store) {
ItemWidth = 470,
MarkupColumn = 1,
Orientation = Orientation.Horizontal,
PixbufColumn = 0,
Spacing = 9
};
icon_view.SelectionChanged += delegate {
icon_view.UnselectAll ();
};
layout_vertical.PackStart (icon_view, false, false, 0);
}
ScrolledWindow = new ScrolledWindow ();
ScrolledWindow.ShadowType = ShadowType.None;
ScrolledWindow.AddWithViewport (layout_vertical);
return ScrolledWindow;
Wrapper.PackStart (widget, true, true, 0);
ShowAll ();
}
// Converts a UNIX timestamp to a more usable time object
public DateTime UnixTimestampToDateTime (int timestamp)
public void Reset ()
{
DateTime unix_epoch = new DateTime (1970, 1, 1, 0, 0, 0, 0);
return unix_epoch.AddSeconds (timestamp);
}
if (Wrapper.Children.Length > 0)
Wrapper.Remove (Wrapper.Children [0]);
foreach (Button button in Buttons)
Buttons.Remove (button);
ShowAll ();
}
}
}