forked from hbons/SparkleShare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SparkleEventLog.cs
executable file
·308 lines (238 loc) · 12.2 KB
/
SparkleEventLog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Threading;
using Gtk;
using Mono.Unix;
using WebKit;
namespace SparkleShare {
public class SparkleEventLog : Window {
public SparkleEventLogController Controller = new SparkleEventLogController ();
private Label size_label;
private Label history_label;
private HBox layout_horizontal;
private ComboBox combo_box;
private EventBox content_wrapper;
private ScrolledWindow scrolled_window;
private WebView web_view;
private SparkleSpinner spinner;
private string link_status;
// Short alias for the translations
public static string _ (string s)
{
return Catalog.GetString (s);
}
public SparkleEventLog () : base ("")
{
SetSizeRequest (480, 640);
SetPosition (WindowPosition.Center);
Resizable = true;
BorderWidth = 0;
Title = _("Recent Events");
IconName = "folder-sparkleshare";
DeleteEvent += delegate (object o, DeleteEventArgs args) {
Controller.WindowClosed ();
args.RetVal = true;
};
this.size_label = new Label () {
Markup = "<b>Size:</b> …",
Xalign = 0
};
this.history_label = new Label () {
Markup = "<b>History:</b> …",
Xalign = 0
};
HBox layout_sizes = new HBox (false, 12);
layout_sizes.Add (this.size_label);
layout_sizes.Add (this.history_label);
VBox layout_vertical = new VBox (false, 0);
this.spinner = new SparkleSpinner (22);
this.content_wrapper = new EventBox ();
this.scrolled_window = new ScrolledWindow ();
this.web_view = new WebView () {
Editable = false
};
this.web_view.HoveringOverLink += delegate (object o, WebKit.HoveringOverLinkArgs args) {
this.link_status = args.Link;
};
this.web_view.NavigationRequested += delegate (object o, WebKit.NavigationRequestedArgs args) {
if (args.Request.Uri == this.link_status)
Controller.LinkClicked (args.Request.Uri);
// Don't follow HREFs (as this would cause a page refresh)
if (!args.Request.Uri.Equals ("file:"))
args.RetVal = 1;
};
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 (layout_sizes, true, true, 12);
layout_vertical.PackStart (this.layout_horizontal, false, false, 0);
layout_vertical.PackStart (CreateShortcutsBar (), false, false, 0);
layout_vertical.PackStart (this.content_wrapper, true, true, 0);
Add (layout_vertical);
// Hook up the controller events
Controller.HideWindowEvent += delegate {
Application.Invoke (delegate {
HideAll ();
});
};
Controller.ShowWindowEvent += delegate {
Application.Invoke (delegate {
ShowAll ();
Present ();
UpdateChooser (null);
UpdateContent (null);
});
};
Controller.UpdateChooserEvent += delegate (string [] folders) {
Application.Invoke (delegate {
UpdateChooser (folders);
});
};
Controller.UpdateContentEvent += delegate (string html) {
Application.Invoke (delegate {
UpdateContent (html);
});
};
Controller.ContentLoadingEvent += delegate {
Application.Invoke (delegate {
if (this.content_wrapper.Child != null)
this.content_wrapper.Remove (this.content_wrapper.Child);
this.content_wrapper.Add (this.spinner);
this.spinner.Start ();
this.content_wrapper.ShowAll ();
});
};
Controller.UpdateSizeInfoEvent += delegate (string size, string history_size) {
Application.Invoke (delegate {
this.size_label.Markup = "<b>Size:</b> " + size;
this.history_label.Markup = "<b>History:</b> " + history_size;
this.size_label.ShowAll ();
this.history_label.ShowAll ();
});
};
}
public void UpdateChooser (string [] folders)
{
if (folders == null)
folders = Controller.Folders;
if (this.combo_box != null && this.combo_box.Parent != null)
this.layout_horizontal.Remove (this.combo_box);
this.combo_box = new ComboBox ();
CellRendererText cell = new CellRendererText();
this.combo_box.PackStart (cell, false);
this.combo_box.AddAttribute (cell, "text", 0);
ListStore store = new ListStore (typeof (string));
store.AppendValues (_("All Projects"));
store.AppendValues ("---");
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) {
string item = (string) this.combo_box.Model.GetValue (iter, 0);
return (item == "---");
};
this.combo_box.Changed += delegate {
TreeIter iter;
this.combo_box.GetActiveIter (out iter);
string selection = (string) this.combo_box.Model.GetValue (iter, 0);
TreePath path = this.combo_box.Model.GetPath (iter);
if (path.Indices [0] == 0)
Controller.SelectedFolder = null;
else
Controller.SelectedFolder = selection;
};
this.layout_horizontal.BorderWidth = 9;
this.layout_horizontal.PackStart (this.combo_box, true, true, 0);
this.layout_horizontal.ShowAll ();
}
public void UpdateContent (string html)
{
Thread thread = new Thread (new ThreadStart (delegate {
if (html == null)
html = Controller.HTML;
if (html == null)
return;
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://" +
new string [] {SparkleUI.AssetsPath, "icons",
"hicolor", "32x32", "status", "avatar-default.png"}.Combine ());
html = html.Replace ("<!-- $document-added-background-image -->", "file://" +
new string [] {SparkleUI.AssetsPath, "icons",
"hicolor", "12x12", "status", "document-added.png"}.Combine ());
html = html.Replace ("<!-- $document-edited-background-image -->", "file://" +
new string [] {SparkleUI.AssetsPath, "icons",
"hicolor", "12x12", "status", "document-edited.png"}.Combine ());
html = html.Replace ("<!-- $document-deleted-background-image -->", "file://" +
new string [] {SparkleUI.AssetsPath, "icons",
"hicolor", "12x12", "status", "document-deleted.png"}.Combine ());
html = html.Replace ("<!-- $document-moved-background-image -->", "file://" +
new string [] {SparkleUI.AssetsPath, "icons",
"hicolor", "12x12", "status", "document-moved.png"}.Combine ());
Application.Invoke (delegate {
this.spinner.Stop ();
this.web_view.LoadString (html, null, null, "file://");
this.content_wrapper.Remove (this.content_wrapper.Child);
this.content_wrapper.Add (this.scrolled_window);
this.content_wrapper.ShowAll ();
});
}));
thread.Start ();
}
private MenuBar CreateShortcutsBar ()
{
// Adds a hidden menubar that contains to enable keyboard
// shortcuts to close the log
MenuBar menu_bar = new MenuBar ();
MenuItem file_item = new MenuItem ("File");
Menu file_menu = new Menu ();
MenuItem close_1 = new MenuItem ("Close1");
MenuItem close_2 = new MenuItem ("Close2");
// adds specific Ctrl+W and Esc key accelerators to Log Window
AccelGroup accel_group = new AccelGroup ();
AddAccelGroup (accel_group);
// Close on Esc
close_1.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.W,
Gdk.ModifierType.ControlMask, AccelFlags.Visible));
close_1.Activated += delegate { Controller.WindowClosed (); };
// Close on Ctrl+W
close_2.AddAccelerator ("activate", accel_group, new AccelKey (Gdk.Key.Escape,
Gdk.ModifierType.None, AccelFlags.Visible));
close_2.Activated += delegate { Controller.WindowClosed (); };
file_menu.Append (close_1);
file_menu.Append (close_2);
file_item.Submenu = file_menu;
menu_bar.Append (file_item);
// Hacky way to hide the menubar, but the accellerators
// will simply be disabled when using Hide ()
menu_bar.HeightRequest = 1;
menu_bar.ModifyBg (StateType.Normal, Style.Background (StateType.Normal));
return menu_bar;
}
}
}