hook up linux event log to new controller

This commit is contained in:
Hylke Bons 2011-07-23 16:57:46 +01:00
parent 6e4ace9643
commit 89bb89afe8
3 changed files with 110 additions and 127 deletions

View file

@ -41,17 +41,19 @@ namespace SparkleLib {
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.
// 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
// 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
// the number of connections as low as possible
foreach (SparkleListenerBase listener in listeners) {

View file

@ -168,7 +168,6 @@ namespace SparkleShare {
if (this.progress_indicator.Superview == ContentView)
this.progress_indicator.RemoveFromSuperview ();
// TODO: still causes some flashes
this.web_view.MainFrame.LoadHtmlString (html, new NSUrl (""));
ContentView.AddSubview (this.web_view);
});

View file

@ -30,15 +30,14 @@ namespace SparkleShare {
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 WebView WebView;
private string LinkStatus;
private SparkleSpinner Spinner;
private string HTML;
private EventBox LogContent;
private List<SparkleChangeSet> change_sets;
private string selected_log = null;
private SparkleSpinner spinner = new SparkleSpinner (22);
private ComboBox combo_box;
private HBox layout_horizontal;
@ -63,28 +62,21 @@ namespace SparkleShare {
DeleteEvent += Close;
CreateEvents ();
UpdateEvents (false);
UpdateChooser ();
}
private void CreateEvents ()
{
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
};
WebView.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
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) {
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
@ -92,20 +84,20 @@ namespace SparkleShare {
process.Start ();
} else {
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (args.Request.Uri);
Regex regex = new Regex (@"(.+)~(.+)~(.+)");
Match match = regex.Match (args.Request.Uri);
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value.Replace ("%20", " ");
if (match.Success) {
string folder_name = match.Groups [1].Value;
string revision = match.Groups [2].Value;
string note = match.Groups [3].Value;
Thread thread = new Thread (new ThreadStart (delegate {
SparkleShare.Controller.AddNoteToFolder (folder_name, revision, note);
}));
Thread thread = new Thread (new ThreadStart (delegate {
SparkleShare.Controller.AddNoteToFolder (folder_name, revision, note);
}));
thread.Start ();
}
thread.Start ();
}
}
// Don't follow HREFs (as this would cause a page refresh)
@ -113,44 +105,78 @@ namespace SparkleShare {
args.RetVal = 1;
};
ScrolledWindow.Add (WebView);
LogContent.Add (ScrolledWindow);
this.scrolled_window.Add (this.web_view);
this.content_wrapper.Add (this.spinner);
this.spinner.Start ();
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);
layout_vertical.PackStart (layout_horizontal, false, false, 0);
layout_vertical.PackStart (LogContent, true, true, 0);
layout_vertical.PackStart (this.layout_horizontal, false, false, 0);
layout_vertical.PackStart (this.content_wrapper, true, true, 0);
// We have to hide the menubar somewhere...
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
Add (layout_vertical);
UpdateChooser (null);
UpdateContent (null);
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)
this.layout_horizontal.Remove (this.combo_box);
this.combo_box = new ComboBox ();
this.layout_horizontal.BorderWidth = 9;
CellRendererText cell = new CellRendererText();
this.combo_box.PackStart (cell, false);
this.combo_box.AddAttribute (cell, "text", 0);
ListStore store = new ListStore (typeof (string));
this.combo_box.Model = store;
store.AppendValues (_("All Folders"));
store.AppendValues ("---");
foreach (string folder_name in SparkleShare.Controller.Folders)
store.AppendValues (folder_name);
foreach (string folder in folders)
store.AppendValues (folder);
this.combo_box.Model = store;
this.combo_box.Active = 0;
this.combo_box.RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) {
@ -158,111 +184,68 @@ namespace SparkleShare {
return (item == "---");
};
if (this.selected_log != null &&
!SparkleShare.Controller.Folders.Contains (this.selected_log)) {
this.selected_log = null;
}
this.combo_box.Changed += delegate {
TreeIter iter;
this.combo_box.GetActiveIter (out iter);
string selection = (string) this.combo_box.Model.GetValue (iter, 0);
if (selection.Equals (_("All Folders")))
this.selected_log = null;
this.controller.SelectedFolder = null;
else
this.selected_log = selection;
UpdateEvents (false);
this.controller.SelectedFolder = selection;
};
this.layout_horizontal.BorderWidth = 9;
this.layout_horizontal.PackStart (this.combo_box, true, true, 0);
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 {
Stopwatch watch = new Stopwatch ();
watch.Start ();
this.change_sets = SparkleShare.Controller.GetLog (this.selected_log);
GenerateHTML ();
watch.Stop ();
if (html == null)
html = this.controller.HTML;
// A short delay is less annoying than
// a flashing window
if (watch.ElapsedMilliseconds < 500 && !silent)
Thread.Sleep (500 - (int) watch.ElapsedMilliseconds);
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"));
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 ();
}
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)
{
HideAll ();
@ -315,4 +298,3 @@ namespace SparkleShare {
}
}
}