[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

File diff suppressed because it is too large Load diff

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;
// TRANSLATORS: {0} is a folder name, and {1} is a server address
Title = String.Format(_("Recent Events in {0}"), SparkleRepo.Name);
IconName = "folder";
BorderWidth = 0;
IconName = "folder-sparkleshare";
Resizable = true;
WindowPosition = WindowPosition.Center;
LayoutVertical = new VBox (false, 12);
SetDefaultSize (640, 480);
LayoutVertical.PackStart (CreateEventLog (), true, true, 0);
Buttons = CreateButtonBox ();
HButtonBox dialog_buttons = new HButtonBox {
Layout = ButtonBoxStyle.Edge,
BorderWidth = 0
};
HBox = new HBox (false, 6);
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 ();
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 close_button = new Button (Stock.Close);
close_button.Clicked += delegate (object o, EventArgs args) {
Destroy ();
};
VBox.PackStart (Wrapper, true, true, 0);
VBox.PackStart (Buttons, false, false, 0);
dialog_buttons.Add (open_folder_button);
dialog_buttons.Add (close_button);
HBox.PackStart (side_splash, false, false, 0);
HBox.PackStart (VBox, true, true, 0);
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 ();
}
}
}