hook up linux event log to new controller
This commit is contained in:
parent
83ef70e069
commit
bff9eb0e5c
|
@ -41,17 +41,19 @@ namespace SparkleLib {
|
||||||
|
|
||||||
public static SparkleListenerBase CreateListener (string folder_name, string folder_identifier)
|
public static SparkleListenerBase CreateListener (string folder_name, string folder_identifier)
|
||||||
{
|
{
|
||||||
string announce_uri = SparkleConfig.DefaultConfig.GetAnnouncementUrlForFolder (folder_name);
|
string uri = SparkleConfig.DefaultConfig.GetAnnouncementUrlForFolder (folder_name);
|
||||||
|
|
||||||
if (announce_uri == null) {
|
if (uri == null) {
|
||||||
// This is SparkleShare's centralized notification service.
|
// This is SparkleShare's centralized notification service.
|
||||||
// Don't worry, we only use this server as a backup if you
|
// Don't worry, we only use this server as a backup if you
|
||||||
// don't have your own. All data needed to connect is hashed and
|
// don't have your own. All data needed to connect is hashed and
|
||||||
// we don't store any personal information ever
|
// we don't store any personal information ever
|
||||||
|
|
||||||
announce_uri = "irc://204.62.14.135/";
|
uri = "irc://204.62.14.135/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uri announce_uri = new Uri (uri);
|
||||||
|
|
||||||
// We use only one listener per server to keep
|
// We use only one listener per server to keep
|
||||||
// the number of connections as low as possible
|
// the number of connections as low as possible
|
||||||
foreach (SparkleListenerBase listener in listeners) {
|
foreach (SparkleListenerBase listener in listeners) {
|
||||||
|
|
|
@ -168,7 +168,6 @@ namespace SparkleShare {
|
||||||
if (this.progress_indicator.Superview == ContentView)
|
if (this.progress_indicator.Superview == ContentView)
|
||||||
this.progress_indicator.RemoveFromSuperview ();
|
this.progress_indicator.RemoveFromSuperview ();
|
||||||
|
|
||||||
// TODO: still causes some flashes
|
|
||||||
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
|
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
|
||||||
ContentView.AddSubview (this.web_view);
|
ContentView.AddSubview (this.web_view);
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,15 +30,14 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public class SparkleEventLog : Window {
|
public class SparkleEventLog : Window {
|
||||||
|
|
||||||
private ScrolledWindow ScrolledWindow;
|
private SparkleEventLogController controller = new SparkleEventLogController ();
|
||||||
|
|
||||||
|
private ScrolledWindow scrolled_window;
|
||||||
|
private WebView web_view;
|
||||||
|
private EventBox content_wrapper = new EventBox ();
|
||||||
private MenuBar MenuBar;
|
private MenuBar MenuBar;
|
||||||
private WebView WebView;
|
|
||||||
private string LinkStatus;
|
private string LinkStatus;
|
||||||
private SparkleSpinner Spinner;
|
private SparkleSpinner spinner = new SparkleSpinner (22);
|
||||||
private string HTML;
|
|
||||||
private EventBox LogContent;
|
|
||||||
private List<SparkleChangeSet> change_sets;
|
|
||||||
private string selected_log = null;
|
|
||||||
private ComboBox combo_box;
|
private ComboBox combo_box;
|
||||||
private HBox layout_horizontal;
|
private HBox layout_horizontal;
|
||||||
|
|
||||||
|
@ -63,28 +62,21 @@ namespace SparkleShare {
|
||||||
|
|
||||||
DeleteEvent += Close;
|
DeleteEvent += Close;
|
||||||
|
|
||||||
CreateEvents ();
|
|
||||||
UpdateEvents (false);
|
|
||||||
UpdateChooser ();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void CreateEvents ()
|
|
||||||
{
|
|
||||||
VBox layout_vertical = new VBox (false, 0);
|
VBox layout_vertical = new VBox (false, 0);
|
||||||
LogContent = new EventBox ();
|
|
||||||
|
|
||||||
ScrolledWindow = new ScrolledWindow ();
|
|
||||||
|
|
||||||
WebView = new WebView () {
|
this.scrolled_window = new ScrolledWindow ();
|
||||||
|
|
||||||
|
this.web_view = new WebView () {
|
||||||
Editable = false
|
Editable = false
|
||||||
};
|
};
|
||||||
|
|
||||||
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
|
||||||
LinkStatus = args.Link;
|
LinkStatus = args.Link;
|
||||||
};
|
};
|
||||||
|
|
||||||
WebView.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
|
||||||
if (args.Request.Uri == LinkStatus) {
|
if (args.Request.Uri == LinkStatus) {
|
||||||
Process process = new Process ();
|
Process process = new Process ();
|
||||||
process.StartInfo.FileName = "xdg-open";
|
process.StartInfo.FileName = "xdg-open";
|
||||||
|
@ -92,20 +84,20 @@ namespace SparkleShare {
|
||||||
process.Start ();
|
process.Start ();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
|
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
|
||||||
Match match = regex.Match (args.Request.Uri);
|
Match match = regex.Match (args.Request.Uri);
|
||||||
|
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
string folder_name = match.Groups [1].Value;
|
string folder_name = match.Groups [1].Value;
|
||||||
string revision = match.Groups [2].Value;
|
string revision = match.Groups [2].Value;
|
||||||
string note = match.Groups [3].Value.Replace ("%20", " ");
|
string note = match.Groups [3].Value;
|
||||||
|
|
||||||
Thread thread = new Thread (new ThreadStart (delegate {
|
Thread thread = new Thread (new ThreadStart (delegate {
|
||||||
SparkleShare.Controller.AddNoteToFolder (folder_name, revision, note);
|
SparkleShare.Controller.AddNoteToFolder (folder_name, revision, note);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
thread.Start ();
|
thread.Start ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't follow HREFs (as this would cause a page refresh)
|
// Don't follow HREFs (as this would cause a page refresh)
|
||||||
|
@ -113,44 +105,78 @@ namespace SparkleShare {
|
||||||
args.RetVal = 1;
|
args.RetVal = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
ScrolledWindow.Add (WebView);
|
this.scrolled_window.Add (this.web_view);
|
||||||
LogContent.Add (ScrolledWindow);
|
this.content_wrapper.Add (this.spinner);
|
||||||
|
|
||||||
|
this.spinner.Start ();
|
||||||
|
|
||||||
this.layout_horizontal = new HBox (true, 0);
|
this.layout_horizontal = new HBox (true, 0);
|
||||||
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
||||||
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
this.layout_horizontal.PackStart (new Label (""), true, true, 0);
|
||||||
|
|
||||||
layout_vertical.PackStart (layout_horizontal, false, false, 0);
|
layout_vertical.PackStart (this.layout_horizontal, false, false, 0);
|
||||||
layout_vertical.PackStart (LogContent, true, true, 0);
|
layout_vertical.PackStart (this.content_wrapper, true, true, 0);
|
||||||
|
|
||||||
// We have to hide the menubar somewhere...
|
// We have to hide the menubar somewhere...
|
||||||
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
|
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
|
||||||
|
|
||||||
Add (layout_vertical);
|
Add (layout_vertical);
|
||||||
|
|
||||||
|
|
||||||
|
UpdateChooser (null);
|
||||||
|
UpdateContent (null);
|
||||||
|
|
||||||
ShowAll ();
|
ShowAll ();
|
||||||
|
|
||||||
|
// Hook up the controller events
|
||||||
|
this.controller.UpdateChooserEvent += delegate (string [] folders) {
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
UpdateChooser (folders);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.controller.UpdateContentEvent += delegate (string html) {
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
UpdateContent (html);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
this.controller.ContentLoadingEvent += delegate {
|
||||||
|
Application.Invoke (delegate {
|
||||||
|
if (this.content_wrapper.Child == this.scrolled_window)
|
||||||
|
this.content_wrapper.Remove (this.scrolled_window);
|
||||||
|
|
||||||
|
this.content_wrapper.Add (this.spinner);
|
||||||
|
this.spinner.Start ();
|
||||||
|
this.content_wrapper.ShowAll ();
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateChooser ()
|
public void UpdateChooser (string [] folders)
|
||||||
{
|
{
|
||||||
|
if (folders == null)
|
||||||
|
folders = this.controller.Folders;
|
||||||
|
|
||||||
if (this.combo_box != null && this.combo_box.Parent != null)
|
if (this.combo_box != null && this.combo_box.Parent != null)
|
||||||
this.layout_horizontal.Remove (this.combo_box);
|
this.layout_horizontal.Remove (this.combo_box);
|
||||||
|
|
||||||
this.combo_box = new ComboBox ();
|
this.combo_box = new ComboBox ();
|
||||||
this.layout_horizontal.BorderWidth = 9;
|
|
||||||
|
|
||||||
CellRendererText cell = new CellRendererText();
|
CellRendererText cell = new CellRendererText();
|
||||||
this.combo_box.PackStart (cell, false);
|
this.combo_box.PackStart (cell, false);
|
||||||
this.combo_box.AddAttribute (cell, "text", 0);
|
this.combo_box.AddAttribute (cell, "text", 0);
|
||||||
|
|
||||||
ListStore store = new ListStore (typeof (string));
|
ListStore store = new ListStore (typeof (string));
|
||||||
this.combo_box.Model = store;
|
|
||||||
|
|
||||||
store.AppendValues (_("All Folders"));
|
store.AppendValues (_("All Folders"));
|
||||||
store.AppendValues ("---");
|
store.AppendValues ("---");
|
||||||
|
|
||||||
foreach (string folder_name in SparkleShare.Controller.Folders)
|
foreach (string folder in folders)
|
||||||
store.AppendValues (folder_name);
|
store.AppendValues (folder);
|
||||||
|
|
||||||
|
this.combo_box.Model = store;
|
||||||
this.combo_box.Active = 0;
|
this.combo_box.Active = 0;
|
||||||
|
|
||||||
this.combo_box.RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) {
|
this.combo_box.RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) {
|
||||||
|
@ -158,111 +184,68 @@ namespace SparkleShare {
|
||||||
return (item == "---");
|
return (item == "---");
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.selected_log != null &&
|
|
||||||
!SparkleShare.Controller.Folders.Contains (this.selected_log)) {
|
|
||||||
|
|
||||||
this.selected_log = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.combo_box.Changed += delegate {
|
this.combo_box.Changed += delegate {
|
||||||
TreeIter iter;
|
TreeIter iter;
|
||||||
this.combo_box.GetActiveIter (out iter);
|
this.combo_box.GetActiveIter (out iter);
|
||||||
|
|
||||||
string selection = (string) this.combo_box.Model.GetValue (iter, 0);
|
string selection = (string) this.combo_box.Model.GetValue (iter, 0);
|
||||||
|
|
||||||
if (selection.Equals (_("All Folders")))
|
if (selection.Equals (_("All Folders")))
|
||||||
this.selected_log = null;
|
this.controller.SelectedFolder = null;
|
||||||
else
|
else
|
||||||
this.selected_log = selection;
|
this.controller.SelectedFolder = selection;
|
||||||
|
|
||||||
UpdateEvents (false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.layout_horizontal.BorderWidth = 9;
|
||||||
this.layout_horizontal.PackStart (this.combo_box, true, true, 0);
|
this.layout_horizontal.PackStart (this.combo_box, true, true, 0);
|
||||||
this.layout_horizontal.ShowAll ();
|
this.layout_horizontal.ShowAll ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateEvents ()
|
public void UpdateContent (string html)
|
||||||
{
|
{
|
||||||
UpdateEvents (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void UpdateEvents (bool silent)
|
|
||||||
{
|
|
||||||
if (!silent) {
|
|
||||||
LogContent.Remove (LogContent.Child);
|
|
||||||
Spinner = new SparkleSpinner (22);
|
|
||||||
LogContent.Add (Spinner);
|
|
||||||
LogContent.ShowAll ();
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread thread = new Thread (new ThreadStart (delegate {
|
Thread thread = new Thread (new ThreadStart (delegate {
|
||||||
Stopwatch watch = new Stopwatch ();
|
if (html == null)
|
||||||
watch.Start ();
|
html = this.controller.HTML;
|
||||||
this.change_sets = SparkleShare.Controller.GetLog (this.selected_log);
|
|
||||||
GenerateHTML ();
|
|
||||||
watch.Stop ();
|
|
||||||
|
|
||||||
// A short delay is less annoying than
|
html = html.Replace ("<!-- $body-font-size -->", (double) (Style.FontDescription.Size / 1024 + 3) + "px");
|
||||||
// a flashing window
|
html = html.Replace ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
|
||||||
if (watch.ElapsedMilliseconds < 500 && !silent)
|
html = html.Replace ("<!-- $a-color -->", "#0085cf");
|
||||||
Thread.Sleep (500 - (int) watch.ElapsedMilliseconds);
|
html = html.Replace ("<!-- $a-hover-color -->", "#009ff8");
|
||||||
|
html = html.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
|
||||||
|
html = html.Replace ("<!-- $body-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal)));
|
||||||
|
html = html.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal)));
|
||||||
|
html = html.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal)));
|
||||||
|
html = html.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
||||||
|
html = html.Replace ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
||||||
|
html = html.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
|
||||||
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
|
"hicolor", "32x32", "status", "avatar-default.png"));
|
||||||
|
html = html.Replace ("<!-- $document-added-background-image -->", "file://" +
|
||||||
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
|
"hicolor", "12x12", "status", "document-added.png"));
|
||||||
|
html = html.Replace ("<!-- $document-edited-background-image -->", "file://" +
|
||||||
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
|
"hicolor", "12x12", "status", "document-edited.png"));
|
||||||
|
html = html.Replace ("<!-- $document-deleted-background-image -->", "file://" +
|
||||||
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
|
"hicolor", "12x12", "status", "document-deleted.png"));
|
||||||
|
html = html.Replace ("<!-- $document-moved-background-image -->", "file://" +
|
||||||
|
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
||||||
|
"hicolor", "12x12", "status", "document-moved.png"));
|
||||||
|
|
||||||
AddHTML ();
|
Application.Invoke (delegate {
|
||||||
|
this.spinner.Stop ();
|
||||||
|
this.web_view.LoadString (html, null, null, "file://");
|
||||||
|
this.content_wrapper.Remove (this.spinner);
|
||||||
|
this.content_wrapper.Add (this.scrolled_window);
|
||||||
|
this.content_wrapper.ShowAll ();
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
thread.Start ();
|
thread.Start ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void GenerateHTML ()
|
|
||||||
{
|
|
||||||
HTML = SparkleShare.Controller.GetHTMLLog (this.change_sets);
|
|
||||||
|
|
||||||
HTML = HTML.Replace ("<!-- $body-font-size -->", (double) (Style.FontDescription.Size / 1024 + 3) + "px");
|
|
||||||
HTML = HTML.Replace ("<!-- $day-entry-header-font-size -->", (Style.FontDescription.Size / 1024 + 3) + "px");
|
|
||||||
HTML = HTML.Replace ("<!-- $a-color -->", "#0085cf");
|
|
||||||
HTML = HTML.Replace ("<!-- $a-hover-color -->", "#009ff8");
|
|
||||||
HTML = HTML.Replace ("<!-- $body-font-family -->", "\"" + Style.FontDescription.Family + "\"");
|
|
||||||
HTML = HTML.Replace ("<!-- $body-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Normal)));
|
|
||||||
HTML = HTML.Replace ("<!-- $body-background-color -->", SparkleUIHelpers.GdkColorToHex (new TreeView ().Style.Base (StateType.Normal)));
|
|
||||||
HTML = HTML.Replace ("<!-- $day-entry-header-background-color -->", SparkleUIHelpers.GdkColorToHex (Style.Background (StateType.Normal)));
|
|
||||||
HTML = HTML.Replace ("<!-- $secondary-font-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
|
||||||
HTML = HTML.Replace ("<!-- $small-color -->", SparkleUIHelpers.GdkColorToHex (Style.Foreground (StateType.Insensitive)));
|
|
||||||
HTML = HTML.Replace ("<!-- $no-buddy-icon-background-image -->", "file://" +
|
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
|
||||||
"hicolor", "32x32", "status", "avatar-default.png"));
|
|
||||||
HTML = HTML.Replace ("<!-- $document-added-background-image -->", "file://" +
|
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
|
||||||
"hicolor", "12x12", "status", "document-added.png"));
|
|
||||||
HTML = HTML.Replace ("<!-- $document-edited-background-image -->", "file://" +
|
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
|
||||||
"hicolor", "12x12", "status", "document-edited.png"));
|
|
||||||
HTML = HTML.Replace ("<!-- $document-deleted-background-image -->", "file://" +
|
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
|
||||||
"hicolor", "12x12", "status", "document-deleted.png"));
|
|
||||||
HTML = HTML.Replace ("<!-- $document-moved-background-image -->", "file://" +
|
|
||||||
SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons",
|
|
||||||
"hicolor", "12x12", "status", "document-moved.png"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void AddHTML ()
|
|
||||||
{
|
|
||||||
Application.Invoke (delegate {
|
|
||||||
Spinner.Stop ();
|
|
||||||
LogContent.Remove (LogContent.Child);
|
|
||||||
|
|
||||||
WebView.LoadString (HTML, null, null, "file://");
|
|
||||||
|
|
||||||
LogContent.Add (ScrolledWindow);
|
|
||||||
LogContent.ShowAll ();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void Close (object o, DeleteEventArgs args)
|
public void Close (object o, DeleteEventArgs args)
|
||||||
{
|
{
|
||||||
HideAll ();
|
HideAll ();
|
||||||
|
@ -315,4 +298,3 @@ namespace SparkleShare {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue