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

View file

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

View file

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

View file

@ -28,232 +28,89 @@ namespace SparkleShare {
public class SparkleWindow : Window { public class SparkleWindow : Window {
// Short alias for the translations private HBox HBox;
public static string _ (string s) private VBox VBox;
{ private VBox Wrapper;
return Catalog.GetString (s); private HButtonBox Buttons;
}
private SparkleRepo SparkleRepo;
private VBox LayoutVertical;
private ScrolledWindow ScrolledWindow;
public SparkleWindow (SparkleRepo sparkle_repo) : base ("") public SparkleWindow () : base ("")
{ {
SparkleRepo = sparkle_repo; BorderWidth = 0;
SetSizeRequest (540, 640); IconName = "folder-sparkleshare";
SetPosition (WindowPosition.Center); Resizable = true;
BorderWidth = 12; WindowPosition = WindowPosition.Center;
// TRANSLATORS: {0} is a folder name, and {1} is a server address SetDefaultSize (640, 480);
Title = String.Format(_("Recent Events in {0}"), SparkleRepo.Name);
IconName = "folder";
LayoutVertical = new VBox (false, 12); Buttons = CreateButtonBox ();
LayoutVertical.PackStart (CreateEventLog (), true, true, 0); HBox = new HBox (false, 6);
HButtonBox dialog_buttons = new HButtonBox { string image_path = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "pixmaps", "side-splash.png");
Layout = ButtonBoxStyle.Edge, Image side_splash = new Image (image_path);
BorderWidth = 0
VBox = new VBox (false, 0);
Wrapper = new VBox (false, 0) {
BorderWidth = 30
}; };
Button open_folder_button = new Button (_("Open Folder")); VBox.PackStart (Wrapper, true, true, 0);
open_folder_button.Clicked += delegate (object o, EventArgs args) { VBox.PackStart (Buttons, false, false, 0);
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 ();
};
Button close_button = new Button (Stock.Close); HBox.PackStart (side_splash, false, false, 0);
close_button.Clicked += delegate (object o, EventArgs args) { HBox.PackStart (VBox, true, true, 0);
Destroy ();
};
dialog_buttons.Add (open_folder_button); base.Add (HBox);
dialog_buttons.Add (close_button);
LayoutVertical.PackStart (dialog_buttons, false, false, 0);
Add (LayoutVertical);
} }
public void UpdateEventLog () private HButtonBox CreateButtonBox ()
{ {
LayoutVertical.Remove (ScrolledWindow); return new HButtonBox () {
ScrolledWindow = CreateEventLog (); BorderWidth = 12,
LayoutVertical.PackStart (ScrolledWindow, true, true, 0); Layout = ButtonBoxStyle.End,
LayoutVertical.ReorderChild (ScrolledWindow, 0); Spacing = 6
};
}
public void AddButton (Button button)
{
Buttons.Add (button);
ShowAll (); ShowAll ();
} }
private ScrolledWindow CreateEventLog () new public void Add (Widget widget)
{ {
int number_of_events = 50; Wrapper.PackStart (widget, true, true, 0);
ShowAll ();
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;
} }
// Converts a UNIX timestamp to a more usable time object public void Reset ()
public DateTime UnixTimestampToDateTime (int timestamp)
{ {
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 ();
} }
}
} }