[intro] code cleanup
This commit is contained in:
parent
38eb444e88
commit
06d41a13a7
File diff suppressed because it is too large
Load diff
|
@ -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 ();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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");
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
||||||
};
|
|
||||||
|
|
||||||
Button open_folder_button = new Button (_("Open Folder"));
|
VBox = new VBox (false, 0);
|
||||||
open_folder_button.Clicked += delegate (object o, EventArgs args) {
|
|
||||||
Process process = new Process ();
|
Wrapper = new VBox (false, 0) {
|
||||||
process.StartInfo.FileName = "xdg-open";
|
BorderWidth = 30
|
||||||
string path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
|
|
||||||
SparkleRepo.Name);
|
|
||||||
process.StartInfo.Arguments = path.Replace(" ", "\\ ");
|
|
||||||
process.Start ();
|
|
||||||
Destroy ();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Button close_button = new Button (Stock.Close);
|
VBox.PackStart (Wrapper, true, true, 0);
|
||||||
close_button.Clicked += delegate (object o, EventArgs args) {
|
VBox.PackStart (Buttons, false, false, 0);
|
||||||
Destroy ();
|
|
||||||
};
|
|
||||||
|
|
||||||
dialog_buttons.Add (open_folder_button);
|
HBox.PackStart (side_splash, false, false, 0);
|
||||||
dialog_buttons.Add (close_button);
|
HBox.PackStart (VBox, true, true, 0);
|
||||||
|
|
||||||
LayoutVertical.PackStart (dialog_buttons, false, false, 0);
|
base.Add (HBox);
|
||||||
|
|
||||||
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 ();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue