~ubuntu-branches/ubuntu/oneiric/tomboy/oneiric-proposed

« back to all changes in this revision

Viewing changes to .pc/02_sync_save_button_sensitive.patch/Tomboy/PreferencesDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine, Iain Lane, Ken VanDine
  • Date: 2011-10-14 09:38:21 UTC
  • mfrom: (4.4.10 sid)
  • Revision ID: james.westby@ubuntu.com-20111014093821-g2cuom2d0tvayzpc
Tags: 1.8.0-1ubuntu1.1
[ Iain Lane ]
* debian/control: Remove syncdaemon BD which is no longer required due to
  the dropping of the SSO patch in 1.8.0-1ubuntu1 

[ Ken VanDine ]
* debian/patches/02_sync_save_button_sensitive.patch
  - Set save button sensitive when needed (LP: #845321)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
using System.Text;
 
5
using Mono.Unix;
 
6
 
 
7
using Tomboy.Sync;
 
8
 
 
9
namespace Tomboy
 
10
{
 
11
        public class PreferencesDialog : Gtk.Dialog
 
12
        {
 
13
                Gtk.ListStore syncAddinStore;
 
14
                Dictionary<string, Gtk.TreeIter> syncAddinIters;
 
15
                Gtk.ComboBox syncAddinCombo;
 
16
                SyncServiceAddin selectedSyncAddin;
 
17
                Gtk.VBox syncAddinPrefsContainer;
 
18
                Gtk.Widget syncAddinPrefsWidget;
 
19
                Gtk.Button resetSyncAddinButton;
 
20
                Gtk.Button saveSyncAddinButton;
 
21
                Gtk.CheckButton autosyncCheck;
 
22
                Gtk.SpinButton autosyncSpinner;
 
23
                Gtk.ComboBox rename_behavior_combo;
 
24
                readonly AddinManager addin_manager;
 
25
                
 
26
                Gtk.Button font_button;
 
27
                Gtk.Label font_face;
 
28
                Gtk.Label font_size;
 
29
 
 
30
                Mono.Addins.Gui.AddinTreeWidget addin_tree;
 
31
 
 
32
                Gtk.Button enable_addin_button;
 
33
                Gtk.Button disable_addin_button;
 
34
                Gtk.Button addin_prefs_button;
 
35
                Gtk.Button addin_info_button;
 
36
 
 
37
                private Gtk.RadioButton promptOnConflictRadio;
 
38
                private Gtk.RadioButton renameOnConflictRadio;
 
39
                private Gtk.RadioButton overwriteOnConflictRadio;
 
40
 
 
41
                /// <summary>
 
42
                /// Keep track of the opened addin prefs dialogs so other windows
 
43
                /// can be interacted with (as opposed to opening these as modal
 
44
                /// dialogs).
 
45
                ///
 
46
                /// Key = Mono.Addins.Addin.Id
 
47
                /// </summary>
 
48
                Dictionary<string, Gtk.Dialog> addin_prefs_dialogs;
 
49
 
 
50
                /// <summary>
 
51
                /// Used to keep track of open AddinInfoDialogs.
 
52
                /// Key = Mono.Addins.Addin.Id
 
53
                /// </summary>
 
54
                Dictionary<string, Gtk.Dialog> addin_info_dialogs;
 
55
 
 
56
                public PreferencesDialog (AddinManager addin_manager)
 
57
: base ()
 
58
                {
 
59
                        this.addin_manager = addin_manager;
 
60
 
 
61
                        IconName = "tomboy";
 
62
                        HasSeparator = false;
 
63
                        BorderWidth = 5;
 
64
                        Resizable = true;
 
65
                        Title = Catalog.GetString ("Tomboy Preferences");
 
66
 
 
67
                        ActionArea.Layout = Gtk.ButtonBoxStyle.End;
 
68
 
 
69
                        addin_prefs_dialogs =
 
70
                                new Dictionary<string, Gtk.Dialog> ();
 
71
                        addin_info_dialogs =
 
72
                                new Dictionary<string, Gtk.Dialog> ();
 
73
 
 
74
                        // Notebook Tabs (Editing, Hotkeys)...
 
75
 
 
76
                        Gtk.Notebook notebook = new Gtk.Notebook ();
 
77
                        notebook.TabPos = Gtk.PositionType.Top;
 
78
                        notebook.Show ();
 
79
 
 
80
                        notebook.AppendPage (MakeEditingPane (),
 
81
                                             new Gtk.Label (Catalog.GetString ("Editing")));
 
82
                        if (! (Services.Keybinder is NullKeybinder))
 
83
                                notebook.AppendPage (MakeHotkeysPane (),
 
84
                                                     new Gtk.Label (Catalog.GetString ("Hotkeys")));
 
85
                        notebook.AppendPage (MakeSyncPane (),
 
86
                                             new Gtk.Label (Catalog.GetString ("Synchronization")));
 
87
                        notebook.AppendPage (MakeAddinsPane (),
 
88
                                             new Gtk.Label (Catalog.GetString ("Add-ins")));
 
89
                        
 
90
                        // TODO: Figure out a way to have these be placed in a specific order
 
91
                        foreach (PreferenceTabAddin tabAddin in addin_manager.GetPreferenceTabAddins ()) {
 
92
                                Logger.Debug ("Adding preference tab addin: {0}", tabAddin.GetType ().Name);
 
93
                                try {
 
94
                                        string tabName;
 
95
                                        Gtk.Widget tabWidget;
 
96
                                        if (tabAddin.GetPreferenceTabWidget (this, out tabName, out tabWidget) == true) {
 
97
                                                notebook.AppendPage (tabWidget, new Gtk.Label (tabName));
 
98
                                        }
 
99
                                } catch (Exception e) {
 
100
                                        Logger.Warn ("Problems adding preferences tab addin: {0}", tabAddin.GetType ().Name);
 
101
                                        Logger.Debug ("{0}:\n{1}", e.Message, e.StackTrace);
 
102
                                }
 
103
                        }
 
104
 
 
105
                        VBox.PackStart (notebook, true, true, 0);
 
106
 
 
107
                        addin_manager.ApplicationAddinListChanged += OnAppAddinListChanged;
 
108
 
 
109
 
 
110
                        // Ok button...
 
111
 
 
112
                        Gtk.Button button = new Gtk.Button (Gtk.Stock.Close);
 
113
                        button.CanDefault = true;
 
114
                        button.Show ();
 
115
 
 
116
                        Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
 
117
                        AddAccelGroup (accel_group);
 
118
 
 
119
                        button.AddAccelerator ("activate",
 
120
                                               accel_group,
 
121
                                               (uint) Gdk.Key.Escape,
 
122
                                               0,
 
123
                                               0);
 
124
 
 
125
                        AddActionWidget (button, Gtk.ResponseType.Close);
 
126
                        DefaultResponse = Gtk.ResponseType.Close;
 
127
 
 
128
                        Preferences.SettingChanged += HandlePreferencesSettingChanged;
 
129
                }
 
130
 
 
131
                void HandlePreferencesSettingChanged (object sender, NotifyEventArgs args)
 
132
                {
 
133
                        if (args.Key == Preferences.NOTE_RENAME_BEHAVIOR) {
 
134
                                int rename_behavior = (int) args.Value;
 
135
                                if (rename_behavior < 0 || rename_behavior > 2) {
 
136
                                        rename_behavior = 0;
 
137
                                        Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR, rename_behavior);
 
138
                                }
 
139
                                if (rename_behavior_combo.Active != rename_behavior)
 
140
                                        rename_behavior_combo.Active = rename_behavior;
 
141
                        } else if (args.Key == Preferences.SYNC_AUTOSYNC_TIMEOUT) {
 
142
                                int timeout = (int) args.Value;
 
143
                                if (timeout <= 0 && autosyncCheck.Active)
 
144
                                        autosyncCheck.Active = false;
 
145
                                else if (timeout > 0) {
 
146
                                        timeout = (timeout >= 5 && timeout < 1000) ? timeout : 5;
 
147
                                        if (!autosyncCheck.Active)
 
148
                                                autosyncCheck.Active = true;
 
149
                                        if ((int) autosyncSpinner.Value != timeout)
 
150
                                                autosyncSpinner.Value = timeout;
 
151
                                }
 
152
                        }
 
153
                }
 
154
                
 
155
                // Page 1
 
156
                // List of editing options
 
157
                public Gtk.Widget MakeEditingPane ()
 
158
                {
 
159
                        Gtk.Label label;
 
160
                        Gtk.CheckButton check;
 
161
                        Gtk.Alignment align;
 
162
                        IPropertyEditorBool peditor, font_peditor, bullet_peditor;
 
163
 
 
164
                        Gtk.VBox options_list = new Gtk.VBox (false, 12);
 
165
                        options_list.BorderWidth = 12;
 
166
                        options_list.Show ();
 
167
 
 
168
 
 
169
                        // Spell checking...
 
170
 
 
171
                        #if FIXED_GTKSPELL
 
172
                        if (NoteSpellChecker.GtkSpellAvailable) {
 
173
                                check = MakeCheckButton (
 
174
                                                Catalog.GetString ("_Spell check while typing"));
 
175
                                options_list.PackStart (check, false, false, 0);
 
176
 
 
177
                                peditor = Services.Factory.CreatePropertyEditorToggleButton (
 
178
                                        Preferences.ENABLE_SPELLCHECKING,
 
179
                                        check);
 
180
                                SetupPropertyEditor (peditor);
 
181
 
 
182
                                label = MakeTipLabel (
 
183
                                                Catalog.GetString ("Misspellings will be underlined " +
 
184
                                                                   "in red, with correct spelling " +
 
185
                                                                   "suggestions shown in the context " +
 
186
                                                                   "menu."));
 
187
                                options_list.PackStart (label, false, false, 0);
 
188
                        }
 
189
                        #endif
 
190
 
 
191
 
 
192
                        // WikiWords...
 
193
 
 
194
                        check = MakeCheckButton (Catalog.GetString ("Highlight _WikiWords"));
 
195
                        options_list.PackStart (check, false, false, 0);
 
196
 
 
197
                        peditor = Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_WIKIWORDS,
 
198
                                        check);
 
199
                        SetupPropertyEditor (peditor);
 
200
 
 
201
                        label = MakeTipLabel (
 
202
                                        Catalog.GetString ("Enable this option to highlight " +
 
203
                                                           "words <b>ThatLookLikeThis</b>. " +
 
204
                                                           "Clicking the word will create a " +
 
205
                                                           "note with that name."));
 
206
                        options_list.PackStart (label, false, false, 0);
 
207
 
 
208
                        // Auto bulleted list
 
209
                        check = MakeCheckButton (Catalog.GetString ("Enable auto-_bulleted lists"));
 
210
                        options_list.PackStart (check, false, false, 0);
 
211
                        bullet_peditor =
 
212
                                Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_AUTO_BULLETED_LISTS,
 
213
                                                                check);
 
214
                        SetupPropertyEditor (bullet_peditor);
 
215
 
 
216
                        // Custom font...
 
217
                        Gtk.HBox font_box = new Gtk.HBox (false, 0);
 
218
                        check = MakeCheckButton (Catalog.GetString ("Use custom _font"));
 
219
                        font_box.PackStart (check);
 
220
 
 
221
                        font_peditor =
 
222
                                Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_CUSTOM_FONT,
 
223
                                                                check);
 
224
                        SetupPropertyEditor (font_peditor);
 
225
 
 
226
                        font_button = MakeFontButton ();
 
227
                        font_button.Sensitive = check.Active;
 
228
                        font_box.PackStart (font_button);
 
229
                        font_box.ShowAll ();
 
230
                        options_list.PackStart (font_box, false, false, 0);
 
231
 
 
232
                        font_peditor.AddGuard (font_button);
 
233
 
 
234
                        // Note renaming bahvior
 
235
                        Gtk.HBox rename_behavior_box = new Gtk.HBox (false, 0);
 
236
                        label = MakeLabel (Catalog.GetString ("When renaming a linked note: "));
 
237
                        rename_behavior_box.PackStart (label);
 
238
                        rename_behavior_combo = new Gtk.ComboBox (new string [] {
 
239
                                Catalog.GetString ("Ask me what to do"),
 
240
                                Catalog.GetString ("Never rename links"),
 
241
                                Catalog.GetString ("Always rename links")});
 
242
                        int rename_behavior = (int) Preferences.Get (Preferences.NOTE_RENAME_BEHAVIOR);
 
243
                        if (rename_behavior < 0 || rename_behavior > 2) {
 
244
                                rename_behavior = 0;
 
245
                                Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR, rename_behavior);
 
246
                        }
 
247
                        rename_behavior_combo.Active = rename_behavior;
 
248
                        rename_behavior_combo.Changed += (o, e) =>
 
249
                                Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR,
 
250
                                                 rename_behavior_combo.Active);
 
251
                        rename_behavior_box.PackStart (rename_behavior_combo);
 
252
                        rename_behavior_box.ShowAll ();
 
253
                        options_list.PackStart (rename_behavior_box, false, false, 0);
 
254
                        
 
255
                        // New Note Template
 
256
                        // Translators: This is 'New Note' Template, not New 'Note Template'
 
257
                        label = MakeLabel (Catalog.GetString ("New Note Template"));
 
258
                        options_list.PackStart (label, false, false, 0);
 
259
 
 
260
                        label = MakeTipLabel (
 
261
                                Catalog.GetString ("Use the new note template to specify the text " +
 
262
                                                                   "that should be used when creating a new note."));
 
263
                        options_list.PackStart (label, false, false, 0);
 
264
                        
 
265
                        align = new Gtk.Alignment (0.5f, 0.5f, 0.4f, 1.0f);
 
266
                        align.Show ();
 
267
                        options_list.PackStart (align, false, false, 0);
 
268
                        
 
269
                        Gtk.Button open_template_button = new Gtk.Button ();
 
270
                        open_template_button.Label = Catalog.GetString ("Open New Note Template");
 
271
 
 
272
                        open_template_button.Clicked += OpenTemplateButtonClicked;
 
273
                        open_template_button.Show ();
 
274
                        align.Add (open_template_button);
 
275
 
 
276
                        return options_list;
 
277
                }
 
278
 
 
279
                Gtk.Button MakeFontButton ()
 
280
                {
 
281
                        Gtk.HBox font_box = new Gtk.HBox (false, 0);
 
282
                        font_box.Show ();
 
283
 
 
284
                        font_face = new Gtk.Label (null);
 
285
                        font_face.UseMarkup = true;
 
286
                        font_face.Show ();
 
287
                        font_box.PackStart (font_face, true, true, 0);
 
288
 
 
289
                        Gtk.VSeparator sep = new Gtk.VSeparator ();
 
290
                        sep.Show ();
 
291
                        font_box.PackStart (sep, false, false, 0);
 
292
 
 
293
                        font_size = new Gtk.Label (null);
 
294
                        font_size.Xpad = 4;
 
295
                        font_size.Show ();
 
296
                        font_box.PackStart (font_size, false, false, 0);
 
297
 
 
298
                        Gtk.Button button = new Gtk.Button ();
 
299
                        button.Clicked += OnFontButtonClicked;
 
300
                        button.Add (font_box);
 
301
                        button.Show ();
 
302
 
 
303
                        string font_desc = (string) Preferences.Get (Preferences.CUSTOM_FONT_FACE);
 
304
                        UpdateFontButton (font_desc);
 
305
 
 
306
                        return button;
 
307
                }
 
308
 
 
309
                // Page 2
 
310
                // List of Hotkey options
 
311
                public Gtk.Widget MakeHotkeysPane ()
 
312
                {
 
313
                        Gtk.Label label;
 
314
                        Gtk.CheckButton check;
 
315
                        Gtk.Alignment align;
 
316
                        Gtk.Entry entry;
 
317
                        IPropertyEditorBool keybind_peditor;
 
318
                        IPropertyEditor peditor;
 
319
 
 
320
                        Gtk.VBox hotkeys_list = new Gtk.VBox (false, 12);
 
321
                        hotkeys_list.BorderWidth = 12;
 
322
                        hotkeys_list.Show ();
 
323
 
 
324
 
 
325
                        // Hotkeys...
 
326
 
 
327
                        check = MakeCheckButton (Catalog.GetString ("Listen for _Hotkeys"));
 
328
                        hotkeys_list.PackStart (check, false, false, 0);
 
329
 
 
330
                        keybind_peditor =
 
331
                                Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_KEYBINDINGS,
 
332
                                                                check);
 
333
                        SetupPropertyEditor (keybind_peditor);
 
334
 
 
335
                        label = MakeTipLabel (
 
336
                                        Catalog.GetString ("Hotkeys allow you to quickly access " +
 
337
                                                           "your notes from anywhere with a keypress. " +
 
338
                                                           "Example Hotkeys: " +
 
339
                                                           "<b>&lt;Control&gt;&lt;Shift&gt;F11</b>, " +
 
340
                                                           "<b>&lt;Alt&gt;N</b>"));
 
341
                        hotkeys_list.PackStart (label, false, false, 0);
 
342
 
 
343
                        align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 1.0f);
 
344
                        align.Show ();
 
345
                        hotkeys_list.PackStart (align, false, false, 0);
 
346
 
 
347
                        Gtk.Table table = new Gtk.Table (4, 2, false);
 
348
                        table.ColumnSpacing = 6;
 
349
                        table.RowSpacing = 6;
 
350
                        table.Show ();
 
351
                        align.Add (table);
 
352
 
 
353
 
 
354
                        // Show notes menu keybinding...
 
355
 
 
356
                        label = MakeLabel (Catalog.GetString ("Show notes _menu"));
 
357
                        table.Attach (label, 0, 1, 0, 1);
 
358
 
 
359
                        entry = new Gtk.Entry ();
 
360
                        label.MnemonicWidget = entry;
 
361
                        entry.Show ();
 
362
                        table.Attach (entry, 1, 2, 0, 1);
 
363
 
 
364
                        peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_SHOW_NOTE_MENU,
 
365
                                                           entry);
 
366
                        SetupPropertyEditor (peditor);
 
367
 
 
368
                        keybind_peditor.AddGuard (entry);
 
369
 
 
370
 
 
371
                        // Open Start Here keybinding...
 
372
 
 
373
                        label = MakeLabel (Catalog.GetString ("Open \"_Start Here\""));
 
374
                        table.Attach (label, 0, 1, 1, 2);
 
375
 
 
376
                        entry = new Gtk.Entry ();
 
377
                        label.MnemonicWidget = entry;
 
378
                        entry.Show ();
 
379
                        table.Attach (entry, 1, 2, 1, 2);
 
380
 
 
381
                        peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_OPEN_START_HERE,
 
382
                                                           entry);
 
383
                        SetupPropertyEditor (peditor);
 
384
 
 
385
                        keybind_peditor.AddGuard (entry);
 
386
 
 
387
 
 
388
                        // Create new note keybinding...
 
389
 
 
390
                        label = MakeLabel (Catalog.GetString ("Create _new note"));
 
391
                        table.Attach (label, 0, 1, 2, 3);
 
392
 
 
393
                        entry = new Gtk.Entry ();
 
394
                        label.MnemonicWidget = entry;
 
395
                        entry.Show ();
 
396
                        table.Attach (entry, 1, 2, 2, 3);
 
397
 
 
398
                        peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_CREATE_NEW_NOTE,
 
399
                                                           entry);
 
400
                        SetupPropertyEditor (peditor);
 
401
 
 
402
                        keybind_peditor.AddGuard (entry);
 
403
 
 
404
 
 
405
                        // Open Search All Notes window keybinding...
 
406
 
 
407
                        label = MakeLabel (Catalog.GetString ("Open \"Search _All Notes\""));
 
408
                        table.Attach (label, 0, 1, 3, 4);
 
409
 
 
410
                        entry = new Gtk.Entry ();
 
411
                        label.MnemonicWidget = entry;
 
412
                        entry.Show ();
 
413
                        table.Attach (entry, 1, 2, 3, 4);
 
414
 
 
415
                        peditor = Services.Factory.CreatePropertyEditorEntry (
 
416
                                Preferences.KEYBINDING_OPEN_RECENT_CHANGES,
 
417
                                entry);
 
418
                        SetupPropertyEditor (peditor);
 
419
 
 
420
                        keybind_peditor.AddGuard (entry);
 
421
 
 
422
 
 
423
                        return hotkeys_list;
 
424
                }
 
425
 
 
426
                public Gtk.Widget MakeSyncPane ()
 
427
                {
 
428
                        Gtk.VBox vbox = new Gtk.VBox (false, 0);
 
429
                        vbox.Spacing = 4;
 
430
                        vbox.BorderWidth = 8;
 
431
 
 
432
                        Gtk.HBox hbox = new Gtk.HBox (false, 4);
 
433
 
 
434
                        Gtk.Label label = new Gtk.Label (Catalog.GetString ("Ser_vice:"));
 
435
                        label.Xalign = 0;
 
436
                        label.Show ();
 
437
                        hbox.PackStart (label, false, false, 0);
 
438
 
 
439
                        // Populate the store with all the available SyncServiceAddins
 
440
                        syncAddinStore = new Gtk.ListStore (typeof (SyncServiceAddin));
 
441
                        syncAddinIters = new Dictionary<string,Gtk.TreeIter> ();
 
442
                        SyncServiceAddin [] addins = Tomboy.DefaultNoteManager.AddinManager.GetSyncServiceAddins ();
 
443
                        Array.Sort (addins, CompareSyncAddinsByName);
 
444
                        foreach (SyncServiceAddin addin in addins) {
 
445
                                Gtk.TreeIter iter = syncAddinStore.Append ();
 
446
                                syncAddinStore.SetValue (iter, 0, addin);
 
447
                                syncAddinIters [addin.Id] = iter;
 
448
                        }
 
449
 
 
450
                        syncAddinCombo = new Gtk.ComboBox (syncAddinStore);
 
451
                        label.MnemonicWidget = syncAddinCombo;
 
452
                        Gtk.CellRendererText crt = new Gtk.CellRendererText ();
 
453
                        syncAddinCombo.PackStart (crt, true);
 
454
                        syncAddinCombo.SetCellDataFunc (crt,
 
455
                                                        new Gtk.CellLayoutDataFunc (ComboBoxTextDataFunc));
 
456
 
 
457
                        // Read from Preferences which service is configured and select it
 
458
                        // by default.  Otherwise, just select the first one in the list.
 
459
                        string addin_id = Preferences.Get (
 
460
                                                  Preferences.SYNC_SELECTED_SERVICE_ADDIN) as String;
 
461
 
 
462
                        Gtk.TreeIter active_iter;
 
463
                        if (addin_id != null && syncAddinIters.ContainsKey (addin_id)) {
 
464
                                active_iter = syncAddinIters [addin_id];
 
465
                                syncAddinCombo.SetActiveIter (active_iter);
 
466
                        } else {
 
467
                                if (syncAddinStore.GetIterFirst (out active_iter) == true) {
 
468
                                        syncAddinCombo.SetActiveIter (active_iter);
 
469
                                }
 
470
                        }
 
471
 
 
472
                        syncAddinCombo.Changed += OnSyncAddinComboChanged;
 
473
 
 
474
                        syncAddinCombo.Show ();
 
475
                        hbox.PackStart (syncAddinCombo, true, true, 0);
 
476
 
 
477
                        hbox.Show ();
 
478
                        vbox.PackStart (hbox, false, false, 0);
 
479
 
 
480
                        // Get the preferences GUI for the Sync Addin
 
481
                        if (active_iter.Stamp != Gtk.TreeIter.Zero.Stamp)
 
482
                                selectedSyncAddin = syncAddinStore.GetValue (active_iter, 0) as SyncServiceAddin;
 
483
 
 
484
                        if (selectedSyncAddin != null)
 
485
                                syncAddinPrefsWidget = selectedSyncAddin.CreatePreferencesControl (OnSyncAddinPrefsChanged);
 
486
                        if (syncAddinPrefsWidget == null) {
 
487
                                Gtk.Label l = new Gtk.Label (Catalog.GetString ("Not configurable"));
 
488
                                l.Yalign = 0.5f;
 
489
                                l.Yalign = 0.5f;
 
490
                                syncAddinPrefsWidget = l;
 
491
                        }
 
492
                        if (syncAddinPrefsWidget != null && addin_id != null &&
 
493
                                        syncAddinIters.ContainsKey (addin_id) && selectedSyncAddin.IsConfigured)
 
494
                                syncAddinPrefsWidget.Sensitive = false;
 
495
 
 
496
                        syncAddinPrefsWidget.Show ();
 
497
                        syncAddinPrefsContainer = new Gtk.VBox (false, 0);
 
498
                        syncAddinPrefsContainer.PackStart (syncAddinPrefsWidget, false, false, 0);
 
499
                        syncAddinPrefsContainer.Show ();
 
500
                        vbox.PackStart (syncAddinPrefsContainer, true, true, 10);
 
501
 
 
502
                        // Autosync preference
 
503
                        int timeout = (int) Preferences.Get (Preferences.SYNC_AUTOSYNC_TIMEOUT);
 
504
                        if (timeout > 0 && timeout < 5) {
 
505
                                timeout = 5;
 
506
                                Preferences.Set (Preferences.SYNC_AUTOSYNC_TIMEOUT, 5);
 
507
                        }
 
508
                        Gtk.HBox autosyncBox = new Gtk.HBox (false, 5);
 
509
                        // Translators: This is and the next string go together.
 
510
                        // Together they look like "Automatically Sync in Background Every [_] Minutes",
 
511
                        // where "[_]" is a GtkSpinButton.
 
512
                        autosyncCheck =
 
513
                                new Gtk.CheckButton (Catalog.GetString ("Automaticall_y Sync in Background Every"));
 
514
                        autosyncSpinner = new Gtk.SpinButton (5, 1000, 1);
 
515
                        autosyncSpinner.Value = timeout >= 5 ? timeout : 10;
 
516
                        Gtk.Label autosyncExtraText =
 
517
                                // Translators: See above comment for details on
 
518
                                // this string.
 
519
                                new Gtk.Label (Catalog.GetString ("Minutes"));
 
520
                        autosyncCheck.Active = autosyncSpinner.Sensitive = timeout >= 5;
 
521
                        EventHandler updateTimeoutPref = (o, e) => {
 
522
                                Preferences.Set (Preferences.SYNC_AUTOSYNC_TIMEOUT,
 
523
                                                 autosyncCheck.Active ? (int) autosyncSpinner.Value : -1);
 
524
                        };
 
525
                        autosyncCheck.Toggled += (o, e) => {
 
526
                                autosyncSpinner.Sensitive = autosyncCheck.Active;
 
527
                                updateTimeoutPref (o, e);
 
528
                        };
 
529
                        autosyncSpinner.ValueChanged += updateTimeoutPref;
 
530
 
 
531
                        autosyncBox.PackStart (autosyncCheck);
 
532
                        autosyncBox.PackStart (autosyncSpinner);
 
533
                        autosyncBox.PackStart (autosyncExtraText);
 
534
                        vbox.PackStart (autosyncBox, false, true, 0);
 
535
 
 
536
                        Gtk.HButtonBox bbox = new Gtk.HButtonBox ();
 
537
                        bbox.Spacing = 4;
 
538
                        bbox.LayoutStyle = Gtk.ButtonBoxStyle.End;
 
539
 
 
540
                        // "Advanced..." button to bring up extra sync config dialog
 
541
                        Gtk.Button advancedConfigButton = new Gtk.Button (Catalog.GetString ("_Advanced..."));
 
542
                        advancedConfigButton.Clicked += OnAdvancedSyncConfigButton;
 
543
                        advancedConfigButton.Show ();
 
544
                        bbox.PackStart (advancedConfigButton, false, false, 0);
 
545
                        bbox.SetChildSecondary (advancedConfigButton, true);
 
546
 
 
547
                        resetSyncAddinButton = new Gtk.Button (Gtk.Stock.Clear);
 
548
                        resetSyncAddinButton.Clicked += OnResetSyncAddinButton;
 
549
                        resetSyncAddinButton.Sensitive =
 
550
                                (selectedSyncAddin != null &&
 
551
                                 addin_id == selectedSyncAddin.Id &&
 
552
                                 selectedSyncAddin.IsConfigured);
 
553
                        resetSyncAddinButton.Show ();
 
554
                        bbox.PackStart (resetSyncAddinButton, false, false, 0);
 
555
 
 
556
                        // TODO: Tabbing should go directly from sync prefs widget to here
 
557
                        // TODO: Consider connecting to "Enter" pressed in sync prefs widget
 
558
                        saveSyncAddinButton = new Gtk.Button (Gtk.Stock.Save);
 
559
                        saveSyncAddinButton.Clicked += OnSaveSyncAddinButton;
 
560
                        saveSyncAddinButton.Sensitive =
 
561
                                (selectedSyncAddin != null &&
 
562
                                 (addin_id != selectedSyncAddin.Id || !selectedSyncAddin.IsConfigured));
 
563
                        saveSyncAddinButton.Show ();
 
564
                        bbox.PackStart (saveSyncAddinButton, false, false, 0);
 
565
 
 
566
                        syncAddinCombo.Sensitive =
 
567
                                (selectedSyncAddin == null ||
 
568
                                 addin_id != selectedSyncAddin.Id ||
 
569
                                 !selectedSyncAddin.IsConfigured);
 
570
 
 
571
                        bbox.Show ();
 
572
                        vbox.PackStart (bbox, false, false, 0);
 
573
 
 
574
                        vbox.ShowAll ();
 
575
                        return vbox;
 
576
                }
 
577
 
 
578
                private int CompareSyncAddinsByName (SyncServiceAddin addin1, SyncServiceAddin addin2)
 
579
                {
 
580
                        return addin1.Name.CompareTo (addin2.Name);
 
581
                }
 
582
 
 
583
                private void ComboBoxTextDataFunc (Gtk.CellLayout cell_layout, Gtk.CellRenderer cell,
 
584
                                                   Gtk.TreeModel tree_model, Gtk.TreeIter iter)
 
585
                {
 
586
                        Gtk.CellRendererText crt = cell as Gtk.CellRendererText;
 
587
                        SyncServiceAddin addin = tree_model.GetValue (iter, 0) as SyncServiceAddin;
 
588
                        if (addin == null) {
 
589
                                crt.Text = string.Empty;
 
590
                        } else {
 
591
                                crt.Text = addin.Name;
 
592
                        }
 
593
                }
 
594
 
 
595
                // Page 3
 
596
                // Extension Preferences
 
597
                public Gtk.Widget MakeAddinsPane ()
 
598
                {
 
599
                        Gtk.VBox vbox = new Gtk.VBox (false, 6);
 
600
                        vbox.BorderWidth = 6;
 
601
                        Gtk.Label l = new Gtk.Label (Catalog.GetString (
 
602
                                                             "The following add-ins are installed"));
 
603
                        l.Xalign = 0;
 
604
                        l.Show ();
 
605
                        vbox.PackStart (l, false, false, 0);
 
606
 
 
607
                        Gtk.HBox hbox = new Gtk.HBox (false, 6);
 
608
 
 
609
                        // TreeView of Add-ins
 
610
                        Gtk.TreeView tree = new Gtk.TreeView ();
 
611
                        addin_tree = new Mono.Addins.Gui.AddinTreeWidget (tree);
 
612
 
 
613
                        tree.Show ();
 
614
 
 
615
                        Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow ();
 
616
                        sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
 
617
                        sw.VscrollbarPolicy = Gtk.PolicyType.Automatic;
 
618
                        sw.ShadowType = Gtk.ShadowType.In;
 
619
                        sw.Add (tree);
 
620
                        sw.Show ();
 
621
                        Gtk.LinkButton get_more_link =
 
622
                                new Gtk.LinkButton ("http://live.gnome.org/Tomboy/PluginList",
 
623
                                                    Catalog.GetString ("Get More Add-Ins..."));
 
624
                        get_more_link.Show ();
 
625
                        Gtk.VBox tree_box = new Gtk.VBox (false, 0);
 
626
                        tree_box.Add (sw);
 
627
                        tree_box.PackEnd (get_more_link, false, false, 5);
 
628
                        tree_box.Show ();
 
629
                        hbox.PackStart (tree_box, true, true, 0);
 
630
 
 
631
                        // Action Buttons (right of TreeView)
 
632
                        Gtk.VButtonBox button_box = new Gtk.VButtonBox ();
 
633
                        button_box.Spacing = 4;
 
634
                        button_box.Layout = Gtk.ButtonBoxStyle.Start;
 
635
 
 
636
                        // TODO: In a future version, add in an "Install Add-ins..." button
 
637
 
 
638
                        // TODO: In a future version, add in a "Repositories..." button
 
639
 
 
640
                        enable_addin_button =
 
641
                                new Gtk.Button (Catalog.GetString ("_Enable"));
 
642
                        enable_addin_button.Sensitive = false;
 
643
                        enable_addin_button.Clicked += OnEnableAddinButton;
 
644
                        enable_addin_button.Show ();
 
645
 
 
646
                        disable_addin_button =
 
647
                                new Gtk.Button (Catalog.GetString ("_Disable"));
 
648
                        disable_addin_button.Sensitive = false;
 
649
                        disable_addin_button.Clicked += OnDisableAddinButton;
 
650
                        disable_addin_button.Show ();
 
651
 
 
652
                        addin_prefs_button =
 
653
                                new Gtk.Button (Gtk.Stock.Preferences);
 
654
                        addin_prefs_button.Sensitive = false;
 
655
                        addin_prefs_button.Clicked += OnAddinPrefsButton;
 
656
                        addin_prefs_button.Show ();
 
657
 
 
658
                        addin_info_button =
 
659
                                new Gtk.Button (Gtk.Stock.Info);
 
660
                        addin_info_button.Sensitive = false;
 
661
                        addin_info_button.Clicked += OnAddinInfoButton;
 
662
                        addin_info_button.Show ();
 
663
 
 
664
                        button_box.PackStart (enable_addin_button);
 
665
                        button_box.PackStart (disable_addin_button);
 
666
                        button_box.PackStart (addin_prefs_button);
 
667
                        button_box.PackStart (addin_info_button);
 
668
 
 
669
                        button_box.Show ();
 
670
                        hbox.PackStart (button_box, false, false, 0);
 
671
 
 
672
                        hbox.Show ();
 
673
                        vbox.PackStart (hbox, true, true, 0);
 
674
                        vbox.Show ();
 
675
 
 
676
                        tree.Selection.Changed += OnAddinTreeSelectionChanged;
 
677
                        LoadAddins ();
 
678
 
 
679
                        return vbox;
 
680
                }
 
681
 
 
682
                void OnAddinTreeSelectionChanged (object sender, EventArgs args)
 
683
                {
 
684
                        UpdateAddinButtons ();
 
685
                }
 
686
 
 
687
                /// <summary>
 
688
                /// Set the sensitivity of the buttons based on what is selected
 
689
                /// </summary>
 
690
                void UpdateAddinButtons ()
 
691
                {
 
692
                        Mono.Addins.Addin sinfo =
 
693
                                addin_tree.ActiveAddinData as Mono.Addins.Addin;
 
694
 
 
695
                        if (sinfo == null) {
 
696
                                enable_addin_button.Sensitive = false;
 
697
                                disable_addin_button.Sensitive = false;
 
698
                                addin_prefs_button.Sensitive = false;
 
699
                                addin_info_button.Sensitive = false;
 
700
                        } else {
 
701
                                enable_addin_button.Sensitive = !sinfo.Enabled;
 
702
                                disable_addin_button.Sensitive = sinfo.Enabled;
 
703
                                addin_prefs_button.Sensitive = addin_manager.IsAddinConfigurable (sinfo);
 
704
                                addin_info_button.Sensitive = true;
 
705
                        }
 
706
                }
 
707
 
 
708
                void LoadAddins ()
 
709
                {
 
710
                        object s = addin_tree.SaveStatus ();
 
711
 
 
712
                        addin_tree.Clear ();
 
713
                        foreach (Mono.Addins.Addin ainfo in addin_manager.GetAllAddins ()) {
 
714
                                addin_tree.AddAddin (
 
715
                                        Mono.Addins.Setup.SetupService.GetAddinHeader (ainfo),
 
716
                                        ainfo,
 
717
                                        ainfo.Enabled,
 
718
                                        ainfo.IsUserAddin);
 
719
                        }
 
720
 
 
721
                        addin_tree.RestoreStatus (s);
 
722
                        UpdateAddinButtons ();
 
723
                }
 
724
 
 
725
                void OnEnableAddinButton (object sender, EventArgs args)
 
726
                {
 
727
                        Mono.Addins.Addin sinfo =
 
728
                                addin_tree.ActiveAddinData as Mono.Addins.Addin;
 
729
 
 
730
                        if (sinfo == null)
 
731
                                return;
 
732
 
 
733
                        EnableAddin (sinfo, true);
 
734
                }
 
735
 
 
736
                void OnDisableAddinButton (object sender, EventArgs args)
 
737
                {
 
738
                        Mono.Addins.Addin sinfo =
 
739
                                addin_tree.ActiveAddinData as Mono.Addins.Addin;
 
740
 
 
741
                        if (sinfo == null)
 
742
                                return;
 
743
 
 
744
                        EnableAddin (sinfo, false);
 
745
                }
 
746
 
 
747
                void EnableAddin (Mono.Addins.Addin addin, bool enable)
 
748
                {
 
749
                        addin.Enabled = enable;
 
750
                        LoadAddins ();
 
751
                }
 
752
 
 
753
                void OnAddinPrefsButton (object sender, EventArgs args)
 
754
                {
 
755
                        Gtk.Dialog dialog = null;
 
756
                        Mono.Addins.Addin addin =
 
757
                                addin_tree.ActiveAddinData as Mono.Addins.Addin;
 
758
 
 
759
                        if (addin == null)
 
760
                                return;
 
761
 
 
762
                        if (addin_prefs_dialogs.ContainsKey (addin.Id) == false) {
 
763
                                // A preference dialog isn't open already so create a new one
 
764
                                Gtk.Image icon =
 
765
                                        new Gtk.Image (Gtk.Stock.Preferences, Gtk.IconSize.Dialog);
 
766
                                Gtk.Label caption = new Gtk.Label ();
 
767
                                caption.Markup = string.Format (
 
768
                                                         "<span size='large' weight='bold'>{0} {1}</span>",
 
769
                                                         addin.Name, addin.Version);
 
770
                                caption.Xalign = 0;
 
771
                                caption.UseMarkup = true;
 
772
                                caption.UseUnderline = false;
 
773
 
 
774
                                Gtk.Widget pref_widget =
 
775
                                        addin_manager.CreateAddinPreferenceWidget (addin);
 
776
 
 
777
                                if (pref_widget == null)
 
778
                                        pref_widget = new Gtk.Label (Catalog.GetString ("Not Implemented"));
 
779
 
 
780
                                Gtk.HBox hbox = new Gtk.HBox (false, 6);
 
781
                                Gtk.VBox vbox = new Gtk.VBox (false, 6);
 
782
                                vbox.BorderWidth = 6;
 
783
 
 
784
                                hbox.PackStart (icon, false, false, 0);
 
785
                                hbox.PackStart (caption, true, true, 0);
 
786
                                vbox.PackStart (hbox, false, false, 0);
 
787
 
 
788
                                vbox.PackStart (pref_widget, true, true, 0);
 
789
                                vbox.ShowAll ();
 
790
 
 
791
                                dialog = new Gtk.Dialog (
 
792
                                        string.Format (Catalog.GetString ("{0} Preferences"),
 
793
                                                       addin.Name),
 
794
                                        this,
 
795
                                        Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.NoSeparator,
 
796
                                        Gtk.Stock.Close, Gtk.ResponseType.Close);
 
797
 
 
798
                                dialog.VBox.PackStart (vbox, true, true, 0);
 
799
                                dialog.DeleteEvent += AddinPrefDialogDeleted;
 
800
                                dialog.Response += AddinPrefDialogResponse;
 
801
 
 
802
                                // Store this dialog off in the dictionary so it can be
 
803
                                // presented again if the user clicks on the preferences button
 
804
                                // again before closing the preferences dialog.
 
805
                                dialog.Data ["AddinId"] = addin.Id;
 
806
                                addin_prefs_dialogs [addin.Id] = dialog;
 
807
                        } else {
 
808
                                // It's already opened so just present it again
 
809
                                dialog = addin_prefs_dialogs [addin.Id];
 
810
                        }
 
811
 
 
812
                        dialog.Present ();
 
813
                }
 
814
 
 
815
                [GLib.ConnectBeforeAttribute]
 
816
                void AddinPrefDialogDeleted (object sender, Gtk.DeleteEventArgs args)
 
817
                {
 
818
                        // Remove the addin from the addin_prefs_dialogs Dictionary
 
819
                        Gtk.Dialog dialog = sender as Gtk.Dialog;
 
820
                        dialog.Hide ();
 
821
 
 
822
                        if (dialog.Data.ContainsKey ("AddinId")) {
 
823
                                addin_prefs_dialogs.Remove (dialog.Data ["AddinId"] as String);
 
824
                        }
 
825
 
 
826
                        dialog.Destroy ();
 
827
                }
 
828
 
 
829
                void AddinPrefDialogResponse (object sender, Gtk.ResponseArgs args)
 
830
                {
 
831
                        AddinPrefDialogDeleted (sender, null);
 
832
                }
 
833
 
 
834
                void OnAddinInfoButton (object sender, EventArgs args)
 
835
                {
 
836
                        Mono.Addins.Addin addin =
 
837
                                addin_tree.ActiveAddinData as Mono.Addins.Addin;
 
838
 
 
839
                        if (addin == null)
 
840
                                return;
 
841
 
 
842
                        Gtk.Dialog dialog = null;
 
843
                        if (addin_info_dialogs.ContainsKey (addin.Id) == false) {
 
844
                                dialog = new AddinInfoDialog (
 
845
                                        Mono.Addins.Setup.SetupService.GetAddinHeader (addin),
 
846
                                        this);
 
847
                                dialog.DeleteEvent += AddinInfoDialogDeleted;
 
848
                                dialog.Response += AddinInfoDialogResponse;
 
849
 
 
850
                                // Store this dialog off in a dictionary so it can be presented
 
851
                                // again if the user clicks on the Info button before closing
 
852
                                // the original dialog.
 
853
                                dialog.Data ["AddinId"] = addin.Id;
 
854
                                addin_info_dialogs [addin.Id] = dialog;
 
855
                        } else {
 
856
                                // It's already opened so just present it again
 
857
                                dialog = addin_info_dialogs [addin.Id];
 
858
                        }
 
859
 
 
860
                        dialog.Present ();
 
861
                }
 
862
 
 
863
                [GLib.ConnectBeforeAttribute]
 
864
                void AddinInfoDialogDeleted (object sender, Gtk.DeleteEventArgs args)
 
865
                {
 
866
                        // Remove the addin from the addin_prefs_dialogs Dictionary
 
867
                        Gtk.Dialog dialog = sender as Gtk.Dialog;
 
868
                        dialog.Hide ();
 
869
 
 
870
                        if (dialog.Data.ContainsKey ("AddinId")) {
 
871
                                addin_info_dialogs.Remove (dialog.Data ["AddinId"] as String);
 
872
                        }
 
873
 
 
874
                        dialog.Destroy ();
 
875
                }
 
876
 
 
877
                void AddinInfoDialogResponse (object sender, Gtk.ResponseArgs args)
 
878
                {
 
879
                        AddinInfoDialogDeleted (sender, null);
 
880
                }
 
881
 
 
882
                void SetupPropertyEditor (IPropertyEditor peditor)
 
883
                {
 
884
                        // Ensure the key exists
 
885
                        Preferences.Get (peditor.Key);
 
886
                        peditor.Setup ();
 
887
                }
 
888
 
 
889
                // Utilities...
 
890
 
 
891
                static Gtk.Label MakeLabel (string label_text, params object[] args)
 
892
                {
 
893
                        if (args.Length > 0)
 
894
                                label_text = String.Format (label_text, args);
 
895
 
 
896
                        Gtk.Label label = new Gtk.Label (label_text);
 
897
 
 
898
                        label.UseMarkup = true;
 
899
                        label.Justify = Gtk.Justification.Left;
 
900
                        label.SetAlignment (0.0f, 0.5f);
 
901
                        label.Show ();
 
902
 
 
903
                        return label;
 
904
                }
 
905
 
 
906
                static Gtk.CheckButton MakeCheckButton (string label_text)
 
907
                {
 
908
                        Gtk.Label label = MakeLabel (label_text);
 
909
 
 
910
                        Gtk.CheckButton check = new Gtk.CheckButton ();
 
911
                        check.Add (label);
 
912
                        check.Show ();
 
913
 
 
914
                        return check;
 
915
                }
 
916
 
 
917
                static Gtk.Label MakeTipLabel (string label_text)
 
918
                {
 
919
                        Gtk.Label label =  MakeLabel ("<small>{0}</small>", label_text);
 
920
                        label.LineWrap = true;
 
921
                        label.Xpad = 20;
 
922
                        return label;
 
923
                }
 
924
 
 
925
                // Font Change handler
 
926
 
 
927
                void OnFontButtonClicked (object sender, EventArgs args)
 
928
                {
 
929
                        Gtk.FontSelectionDialog font_dialog =
 
930
                                new Gtk.FontSelectionDialog (
 
931
                                Catalog.GetString ("Choose Note Font"));
 
932
 
 
933
                        string font_name = (string)
 
934
                                           Preferences.Get (Preferences.CUSTOM_FONT_FACE);
 
935
                        font_dialog.SetFontName (font_name);
 
936
 
 
937
                        if ((int) Gtk.ResponseType.Ok == font_dialog.Run ()) {
 
938
                                if (font_dialog.FontName != font_name) {
 
939
                                        Preferences.Set (Preferences.CUSTOM_FONT_FACE,
 
940
                                                         font_dialog.FontName);
 
941
 
 
942
                                        UpdateFontButton (font_dialog.FontName);
 
943
                                }
 
944
                        }
 
945
 
 
946
                        font_dialog.Destroy ();
 
947
                }
 
948
 
 
949
                void UpdateFontButton (string font_desc)
 
950
                {
 
951
                        Pango.FontDescription desc =
 
952
                                Pango.FontDescription.FromString (font_desc);
 
953
 
 
954
                        // Set the size label
 
955
                        font_size.Text = (desc.Size / Pango.Scale.PangoScale).ToString ();
 
956
 
 
957
                        desc.UnsetFields (Pango.FontMask.Size);
 
958
 
 
959
                        // Set the font name label
 
960
                        font_face.Markup = String.Format ("<span font_desc='{0}'>{1}</span>",
 
961
                                                          font_desc,
 
962
                                                          desc.ToString ());
 
963
                }
 
964
 
 
965
                private void OnAdvancedSyncConfigButton (object sender, EventArgs args)
 
966
                {
 
967
                        // Get saved behavior
 
968
                        SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel;
 
969
                        object dlgBehaviorPref = Preferences.Get (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
 
970
                        if (dlgBehaviorPref != null && dlgBehaviorPref is int) // TODO: Check range of this int
 
971
                                savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref;
 
972
 
 
973
                        // Create dialog
 
974
                        Gtk.Dialog advancedDlg =
 
975
                                new Gtk.Dialog (Catalog.GetString ("Other Synchronization Options"),
 
976
                                                this,
 
977
                                                Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal | Gtk.DialogFlags.NoSeparator,
 
978
                                                Gtk.Stock.Close, Gtk.ResponseType.Close);
 
979
                        // Populate dialog
 
980
                        Gtk.Label label =
 
981
                                new Gtk.Label (Catalog.GetString ("When a conflict is detected between " +
 
982
                                                                  "a local note and a note on the configured " +
 
983
                                                                  "synchronization server:"));
 
984
                        label.Wrap = true;
 
985
                        label.Xalign = 0;
 
986
 
 
987
                        promptOnConflictRadio =
 
988
                                new Gtk.RadioButton (Catalog.GetString ("Always ask me what to do."));
 
989
                        promptOnConflictRadio.Toggled += OnConflictOptionToggle;
 
990
 
 
991
                        renameOnConflictRadio =
 
992
                                new Gtk.RadioButton (promptOnConflictRadio, Catalog.GetString ("Rename my local note."));
 
993
                        renameOnConflictRadio.Toggled += OnConflictOptionToggle;
 
994
 
 
995
                        overwriteOnConflictRadio =
 
996
                                new Gtk.RadioButton (promptOnConflictRadio, Catalog.GetString ("Replace my local note with the server's update."));
 
997
                        overwriteOnConflictRadio.Toggled += OnConflictOptionToggle;
 
998
 
 
999
                        switch (savedBehavior) {
 
1000
                        case SyncTitleConflictResolution.RenameExistingNoUpdate:
 
1001
                                renameOnConflictRadio.Active = true;
 
1002
                                break;
 
1003
                        case SyncTitleConflictResolution.OverwriteExisting:
 
1004
                                overwriteOnConflictRadio.Active = true;
 
1005
                                break;
 
1006
                        default:
 
1007
                                promptOnConflictRadio.Active = true;
 
1008
                                break;
 
1009
                        }
 
1010
 
 
1011
                        Gtk.VBox vbox = new Gtk.VBox ();
 
1012
                        vbox.BorderWidth = 18;
 
1013
 
 
1014
                        vbox.PackStart (promptOnConflictRadio);
 
1015
                        vbox.PackStart (renameOnConflictRadio);
 
1016
                        vbox.PackStart (overwriteOnConflictRadio);
 
1017
 
 
1018
                        advancedDlg.VBox.PackStart (label, false, false, 6);
 
1019
                        advancedDlg.VBox.PackStart (vbox, false, false, 0);
 
1020
 
 
1021
                        advancedDlg.ShowAll ();
 
1022
 
 
1023
                        // Run dialog
 
1024
                        advancedDlg.Run ();
 
1025
                        advancedDlg.Destroy ();
 
1026
                }
 
1027
 
 
1028
                private void OnConflictOptionToggle (object sender, EventArgs args)
 
1029
                {
 
1030
                        SyncTitleConflictResolution newBehavior = SyncTitleConflictResolution.Cancel;
 
1031
 
 
1032
                        if (renameOnConflictRadio.Active)
 
1033
                                newBehavior = SyncTitleConflictResolution.RenameExistingNoUpdate;
 
1034
                        else if (overwriteOnConflictRadio.Active)
 
1035
                                newBehavior = SyncTitleConflictResolution.OverwriteExisting;
 
1036
 
 
1037
                        Preferences.Set (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
 
1038
                                         (int) newBehavior);
 
1039
                }
 
1040
 
 
1041
                private void OnAppAddinListChanged (object sender, EventArgs args)
 
1042
                {
 
1043
                        SyncServiceAddin [] newAddinsArray = Tomboy.DefaultNoteManager.AddinManager.GetSyncServiceAddins ();
 
1044
                        Array.Sort (newAddinsArray, CompareSyncAddinsByName);
 
1045
                        List<SyncServiceAddin> newAddins = new List<SyncServiceAddin> (newAddinsArray);
 
1046
 
 
1047
                        // Build easier-to-navigate list if addins currently in the combo
 
1048
                        List<SyncServiceAddin> currentAddins = new List<SyncServiceAddin> ();
 
1049
                        foreach (object [] currentRow in syncAddinStore) {
 
1050
                                SyncServiceAddin currentAddin = currentRow [0] as SyncServiceAddin;
 
1051
                                if (currentAddin != null)
 
1052
                                        currentAddins.Add (currentAddin);
 
1053
                        }
 
1054
 
 
1055
                        // Add new addins
 
1056
                        // TODO: Would be nice to insert these alphabetically instead
 
1057
                        foreach (SyncServiceAddin newAddin in newAddins) {
 
1058
                                if (!currentAddins.Contains (newAddin)) {
 
1059
                                        Gtk.TreeIter iter = syncAddinStore.Append ();
 
1060
                                        syncAddinStore.SetValue (iter, 0, newAddin);
 
1061
                                        syncAddinIters [newAddin.Id] = iter;
 
1062
                                }
 
1063
                        }
 
1064
 
 
1065
                        // Remove deleted addins
 
1066
                        foreach (SyncServiceAddin currentAddin in currentAddins) {
 
1067
                                if (!newAddins.Contains (currentAddin)) {
 
1068
                                        Gtk.TreeIter iter = syncAddinIters [currentAddin.Id];
 
1069
                                        syncAddinStore.Remove (ref iter);
 
1070
                                        syncAddinIters.Remove (currentAddin.Id);
 
1071
 
 
1072
                                        // FIXME: Lots of hacky stuff in here...rushing before freeze
 
1073
                                        if (currentAddin == selectedSyncAddin) {
 
1074
                                                if (syncAddinPrefsWidget != null &&
 
1075
                                                                !syncAddinPrefsWidget.Sensitive)
 
1076
                                                        OnResetSyncAddinButton (null, null);
 
1077
 
 
1078
                                                Gtk.TreeIter active_iter;
 
1079
                                                if (syncAddinStore.GetIterFirst (out active_iter) == true) {
 
1080
                                                        syncAddinCombo.SetActiveIter (active_iter);
 
1081
                                                } else {
 
1082
                                                        OnSyncAddinComboChanged (null, null);
 
1083
                                                }
 
1084
                                        }
 
1085
                                }
 
1086
                        }
 
1087
                }
 
1088
 
 
1089
                void OnSyncAddinComboChanged (object sender, EventArgs args)
 
1090
                {
 
1091
                        if (syncAddinPrefsWidget != null) {
 
1092
                                syncAddinPrefsContainer.Remove (syncAddinPrefsWidget);
 
1093
                                syncAddinPrefsWidget.Hide ();
 
1094
                                syncAddinPrefsWidget.Destroy ();
 
1095
                                syncAddinPrefsWidget = null;
 
1096
                        }
 
1097
 
 
1098
                        Gtk.TreeIter iter;
 
1099
                        if (syncAddinCombo.GetActiveIter (out iter)) {
 
1100
                                SyncServiceAddin newAddin =
 
1101
                                        syncAddinStore.GetValue (iter, 0) as SyncServiceAddin;
 
1102
                                if (newAddin != null) {
 
1103
                                        selectedSyncAddin = newAddin;
 
1104
                                        syncAddinPrefsWidget = selectedSyncAddin.CreatePreferencesControl (OnSyncAddinPrefsChanged);
 
1105
                                        if (syncAddinPrefsWidget == null) {
 
1106
                                                Gtk.Label l = new Gtk.Label (Catalog.GetString ("Not configurable"));
 
1107
                                                l.Yalign = 0.5f;
 
1108
                                                l.Yalign = 0.5f;
 
1109
                                                syncAddinPrefsWidget = l;
 
1110
                                        }
 
1111
 
 
1112
                                        syncAddinPrefsWidget.Show ();
 
1113
                                        syncAddinPrefsContainer.PackStart (syncAddinPrefsWidget, false, false, 0);
 
1114
 
 
1115
                                        resetSyncAddinButton.Sensitive = false;
 
1116
                                        saveSyncAddinButton.Sensitive = false;
 
1117
                                }
 
1118
                        } else {
 
1119
                                selectedSyncAddin = null;
 
1120
                                resetSyncAddinButton.Sensitive = false;
 
1121
                                saveSyncAddinButton.Sensitive = false;
 
1122
                        }
 
1123
 
 
1124
                }
 
1125
 
 
1126
                void OnResetSyncAddinButton (object sender, EventArgs args)
 
1127
                {
 
1128
                        if (selectedSyncAddin == null)
 
1129
                                return;
 
1130
 
 
1131
                        // User doesn't get a choice if this is invoked by disabling the addin
 
1132
                        // FIXME: null sender check is lame!
 
1133
                        if (sender != null) {
 
1134
                                // Prompt the user about what they're about to do since
 
1135
                                // it's not really recommended to switch back and forth
 
1136
                                // between sync services.
 
1137
                                HIGMessageDialog dialog =
 
1138
                                        new HIGMessageDialog (null,
 
1139
                                                              Gtk.DialogFlags.Modal,
 
1140
                                                              Gtk.MessageType.Question,
 
1141
                                                              Gtk.ButtonsType.YesNo,
 
1142
                                                              Catalog.GetString ("Are you sure?"),
 
1143
                                                              Catalog.GetString (
 
1144
                                                                      "Clearing your synchronization settings is not recommended.  " +
 
1145
                                                                      "You may be forced to synchronize all of your notes again " +
 
1146
                                                                      "when you save new settings."));
 
1147
                                int response = dialog.Run ();
 
1148
                                dialog.Destroy ();
 
1149
                                if (response != (int) Gtk.ResponseType.Yes)
 
1150
                                        return;
 
1151
                        } else { // FIXME: Weird place for this to go.  User should be able to cancel disabling of addin, anyway
 
1152
                                HIGMessageDialog dialog =
 
1153
                                        new HIGMessageDialog (null,
 
1154
                                                              Gtk.DialogFlags.Modal,
 
1155
                                                              Gtk.MessageType.Info,
 
1156
                                                              Gtk.ButtonsType.Ok,
 
1157
                                                              Catalog.GetString ("Resetting Synchronization Settings"),
 
1158
                                                              Catalog.GetString (
 
1159
                                                                      "You have disabled the configured synchronization service.  " +
 
1160
                                                                      "Your synchronization settings will now be cleared.  " +
 
1161
                                                                      "You may be forced to synchronize all of your notes again " +
 
1162
                                                                      "when you save new settings."));
 
1163
                                dialog.Run ();
 
1164
                                dialog.Destroy ();
 
1165
                        }
 
1166
 
 
1167
                        try {
 
1168
                                selectedSyncAddin.ResetConfiguration ();
 
1169
                        } catch (Exception e) {
 
1170
                                Logger.Debug ("Error calling {0}.ResetConfiguration: {1}\n{2}",
 
1171
                                              selectedSyncAddin.Id, e.Message, e.StackTrace);
 
1172
                        }
 
1173
 
 
1174
                        Preferences.Set (
 
1175
                                Preferences.SYNC_SELECTED_SERVICE_ADDIN,
 
1176
                                String.Empty);
 
1177
 
 
1178
                        // Reset conflict handling behavior
 
1179
                        Preferences.Set (
 
1180
                                Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
 
1181
                                Preferences.GetDefault (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR));
 
1182
 
 
1183
                        SyncManager.ResetClient ();
 
1184
 
 
1185
                        syncAddinCombo.Sensitive = true;
 
1186
                        resetSyncAddinButton.Sensitive = false;
 
1187
                        saveSyncAddinButton.Sensitive = true;
 
1188
                        if (syncAddinPrefsWidget != null)
 
1189
                                syncAddinPrefsWidget.Sensitive = true;
 
1190
                }
 
1191
 
 
1192
                /// <summary>
 
1193
                /// Attempt to save/test the connection to the sync addin.
 
1194
                /// </summary>
 
1195
                void OnSaveSyncAddinButton (object sender, EventArgs args)
 
1196
                {
 
1197
                        if (selectedSyncAddin == null)
 
1198
                                return;
 
1199
 
 
1200
                        bool saved = false;
 
1201
                        string errorMsg = null;
 
1202
                        try {
 
1203
                                GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Watch);
 
1204
                                GdkWindow.Display.Flush ();
 
1205
                                saved = selectedSyncAddin.SaveConfiguration ();
 
1206
                        } catch (TomboySyncException syncEx) {
 
1207
                                errorMsg = syncEx.Message;
 
1208
                        } catch (Exception e) {
 
1209
                                Logger.Debug ("Unexpected error calling {0}.SaveConfiguration: {1}\n{2}",
 
1210
                                              selectedSyncAddin.Id, e.Message, e.StackTrace);
 
1211
                        } finally {
 
1212
                                GdkWindow.Cursor = null;
 
1213
                                GdkWindow.Display.Flush ();
 
1214
                        }
 
1215
 
 
1216
                        HIGMessageDialog dialog;
 
1217
                        if (saved) {
 
1218
                                Preferences.Set (
 
1219
                                        Preferences.SYNC_SELECTED_SERVICE_ADDIN,
 
1220
                                        selectedSyncAddin.Id);
 
1221
 
 
1222
                                syncAddinCombo.Sensitive = false;
 
1223
                                syncAddinPrefsWidget.Sensitive = false;
 
1224
                                resetSyncAddinButton.Sensitive = true;
 
1225
                                saveSyncAddinButton.Sensitive = false;
 
1226
 
 
1227
                                SyncManager.ResetClient ();
 
1228
 
 
1229
                                // Give the user a visual letting them know that connecting
 
1230
                                // was successful.
 
1231
                                // TODO: Replace Yes/No with Sync/Close
 
1232
                                dialog =
 
1233
                                        new HIGMessageDialog (this,
 
1234
                                                              Gtk.DialogFlags.Modal,
 
1235
                                                              Gtk.MessageType.Info,
 
1236
                                                              Gtk.ButtonsType.YesNo,
 
1237
                                                              Catalog.GetString ("Connection successful"),
 
1238
                                                              Catalog.GetString (
 
1239
                                                                      "Tomboy is ready to synchronize your notes. Would you like to synchronize them now?"));
 
1240
                                int response = dialog.Run ();
 
1241
                                dialog.Destroy ();
 
1242
 
 
1243
                                if (response == (int) Gtk.ResponseType.Yes)
 
1244
                                        // TODO: Put this voodoo in a method somewhere
 
1245
                                        Tomboy.ActionManager ["NoteSynchronizationAction"].Activate ();
 
1246
                        } else {
 
1247
                                // TODO: Change the SyncServiceAddin API so the call to
 
1248
                                // SaveConfiguration has a way of passing back an exception
 
1249
                                // or other text so it can be displayed to the user.
 
1250
                                Preferences.Set (
 
1251
                                        Preferences.SYNC_SELECTED_SERVICE_ADDIN,
 
1252
                                        String.Empty);
 
1253
 
 
1254
                                syncAddinCombo.Sensitive = true;
 
1255
                                syncAddinPrefsWidget.Sensitive = true;
 
1256
                                resetSyncAddinButton.Sensitive = false;
 
1257
                                saveSyncAddinButton.Sensitive = true;
 
1258
 
 
1259
                                // Give the user a visual letting them know that connecting
 
1260
                                // was successful.
 
1261
                                if (errorMsg == null) {
 
1262
                                        errorMsg = Catalog.GetString ("Please check your information and " +
 
1263
                                                                      "try again.  The log file {0} may " +
 
1264
                                                                      "contain more information about the error.");
 
1265
                                        string logPath = System.IO.Path.Combine (Services.NativeApplication.LogDirectory,
 
1266
                                                                                 "tomboy.log");
 
1267
                                        errorMsg = String.Format (errorMsg, logPath);
 
1268
                                }
 
1269
                                dialog =
 
1270
                                        new HIGMessageDialog (this,
 
1271
                                                              Gtk.DialogFlags.Modal,
 
1272
                                                              Gtk.MessageType.Warning,
 
1273
                                                              Gtk.ButtonsType.Close,
 
1274
                                                              Catalog.GetString ("Error connecting"),
 
1275
                                                              errorMsg);
 
1276
                                dialog.Run ();
 
1277
                                dialog.Destroy ();
 
1278
                        }
 
1279
                }
 
1280
                
 
1281
                void OnSyncAddinPrefsChanged (object sender, EventArgs args)
 
1282
                {
 
1283
                        // Enable/disable the save button based on required fields
 
1284
                        if (selectedSyncAddin != null)
 
1285
                                saveSyncAddinButton.Sensitive = selectedSyncAddin.AreSettingsValid;
 
1286
                }
 
1287
 
 
1288
                void OpenTemplateButtonClicked (object sender, EventArgs args)
 
1289
                {
 
1290
                        NoteManager manager = Tomboy.DefaultNoteManager;
 
1291
                        Note template_note = manager.GetOrCreateTemplateNote ();
 
1292
 
 
1293
                        // Open the template note
 
1294
                        template_note.Window.Show ();
 
1295
                }
 
1296
        }
 
1297
 
 
1298
        // TODO: Figure out how to use Mono.Addins.Gui.AddinInfoDialog here instead.
 
1299
        // The class here is adapted directly from Mono.Addins.Gui.AddinInfoDialog.
 
1300
        class AddinInfoDialog : Gtk.Dialog
 
1301
        {
 
1302
                Mono.Addins.Setup.AddinHeader info;
 
1303
                Gtk.Label info_label;
 
1304
 
 
1305
                public AddinInfoDialog (
 
1306
                        Mono.Addins.Setup.AddinHeader info,
 
1307
                        Gtk.Window parent)
 
1308
: base (info.Name,
 
1309
                        parent,
 
1310
                        Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.NoSeparator,
 
1311
                        Gtk.Stock.Close, Gtk.ResponseType.Close)
 
1312
                {
 
1313
                        this.info = info;
 
1314
 
 
1315
                        // TODO: Change this icon to be an addin/package icon
 
1316
                        Gtk.Image icon =
 
1317
                                new Gtk.Image (Gtk.Stock.DialogInfo, Gtk.IconSize.Dialog);
 
1318
                        icon.Yalign = 0;
 
1319
 
 
1320
                        info_label = new Gtk.Label ();
 
1321
                        info_label.Xalign = 0;
 
1322
                        info_label.Yalign = 0;
 
1323
                        info_label.UseMarkup = true;
 
1324
                        info_label.UseUnderline = false;
 
1325
                        info_label.Wrap = true;
 
1326
 
 
1327
                        Gtk.HBox hbox = new Gtk.HBox (false, 6);
 
1328
                        Gtk.VBox vbox = new Gtk.VBox (false, 12);
 
1329
                        hbox.BorderWidth = 12;
 
1330
                        vbox.BorderWidth = 6;
 
1331
 
 
1332
                        hbox.PackStart (icon, false, false, 0);
 
1333
                        hbox.PackStart (vbox, true, true, 0);
 
1334
 
 
1335
                        vbox.PackStart (info_label, true, true, 0);
 
1336
 
 
1337
                        hbox.ShowAll ();
 
1338
 
 
1339
                        VBox.PackStart (hbox, true, true, 0);
 
1340
 
 
1341
                        Fill ();
 
1342
                }
 
1343
 
 
1344
                void Fill ()
 
1345
                {
 
1346
                        StringBuilder sb = new StringBuilder ();
 
1347
                        sb.Append ("<b><big>" + info.Name + "</big></b>\n\n");
 
1348
 
 
1349
                        if (info.Description != string.Empty)
 
1350
                                sb.Append (info.Description + "\n\n");
 
1351
 
 
1352
                        sb.Append ("<small>");
 
1353
 
 
1354
                        sb.Append (string.Format (
 
1355
                                           "<b>{0}</b>\n" +
 
1356
                                           "{1}\n\n",
 
1357
                                           Catalog.GetString ("Version:"),
 
1358
                                           info.Version));
 
1359
 
 
1360
                        if (info.Author != string.Empty)
 
1361
                                sb.Append (string.Format (
 
1362
                                                   "<b>{0}</b>\n" +
 
1363
                                                   "{1}\n\n",
 
1364
                                                   Catalog.GetString ("Author:"),
 
1365
                                                   info.Author));
 
1366
 
 
1367
                        if (info.Copyright != string.Empty)
 
1368
                                sb.Append (string.Format (
 
1369
                                                   "<b>{0}</b>\n" +
 
1370
                                                   "{1}\n\n",
 
1371
                                                   Catalog.GetString ("Copyright:"),
 
1372
                                                   info.Copyright));
 
1373
 
 
1374
                        if (info.Dependencies.Count > 0) {
 
1375
                                sb.Append (string.Format (
 
1376
                                                   "<b>{0}</b>\n",
 
1377
                                                   Catalog.GetString ("Add-in Dependencies:")));
 
1378
                                foreach (Mono.Addins.Description.Dependency dep in info.Dependencies) {
 
1379
                                        sb.Append (dep.Name + "\n");
 
1380
                                }
 
1381
                        }
 
1382
 
 
1383
                        sb.Append ("</small>");
 
1384
 
 
1385
                        info_label.Markup = sb.ToString ();
 
1386
                }
 
1387
        }
 
1388
}