[go: up one dir, main page]

Menu

[9b8379]: / lat / Preferences.cs  Maximize  Restore  History

Download this file

433 lines (342 with data), 11.3 kB

  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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
//
// lat - Preferences.cs
// Author: Loren Bandiera
// Copyright 2005 MMG Security, Inc.
//
// 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; Version 2 .
//
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
using System;
using System.Collections.Generic;
using Gtk;
namespace lat
{
public class Preferences
{
public const string MAIN_WINDOW_MAXIMIZED = "/apps/lat/ui/maximized";
public const string MAIN_WINDOW_X = "/apps/lat/ui/main_window_x";
public const string MAIN_WINDOW_Y = "/apps/lat/ui/main_window_y";
public const string MAIN_WINDOW_WIDTH = "/apps/lat/ui/main_window_width";
public const string MAIN_WINDOW_HEIGHT = "/apps/lat/ui/main_window_height";
public const string MAIN_WINDOW_HPANED = "/apps/lat/ui/main_window_hpaned";
public const string BROWSER_SELECTION = "/apps/lat/ui/browser_selection";
static GConf.Client client;
static GConf.NotifyEventHandler changed_handler;
public static GConf.Client Client
{
get {
if (client == null) {
client = new GConf.Client ();
changed_handler = new GConf.NotifyEventHandler (OnSettingChanged);
client.AddNotify ("/apps/lat", changed_handler);
}
return client;
}
}
public static object GetDefault (string key)
{
switch (key)
{
case MAIN_WINDOW_X:
case MAIN_WINDOW_Y:
case MAIN_WINDOW_HEIGHT:
case MAIN_WINDOW_WIDTH:
case MAIN_WINDOW_HPANED:
return null;
case BROWSER_SELECTION:
return 2;
}
return null;
}
public static object Get (string key)
{
try {
return Client.Get (key);
} catch (GConf.NoSuchKeyException) {
object default_val = GetDefault (key);
if (default_val != null)
Client.Set (key, default_val);
return default_val;
}
}
public static void Set (string key, object value)
{
Client.Set (key, value);
}
public static event GConf.NotifyEventHandler SettingChanged;
static void OnSettingChanged (object sender, GConf.NotifyEventArgs args)
{
if (SettingChanged != null) {
SettingChanged (sender, args);
}
}
}
public class PreferencesDialog
{
Glade.XML ui;
[Glade.Widget] Gtk.Dialog preferencesDialog;
[Glade.Widget] RadioButton browserSingleClickButton;
[Glade.Widget] RadioButton browserDoubleClickButton;
[Glade.Widget] TreeView profilesTreeView;
ListStore profileStore;
Gnome.Program program;
bool gettingHelp = false;
public PreferencesDialog (Gnome.Program program)
{
ui = new Glade.XML (null, "lat.glade", "preferencesDialog", null);
ui.Autoconnect (this);
this.program = program;
profileStore = new ListStore (typeof (string));
profilesTreeView.Model = profileStore;
profileStore.SetSortColumnId (0, SortType.Ascending);
TreeViewColumn col;
col = profilesTreeView.AppendColumn ("Name", new CellRendererText (), "text", 0);
col.SortColumnId = 0;
UpdateProfileList ();
LoadPreference (Preferences.BROWSER_SELECTION);
preferencesDialog.Icon = Global.latIcon;
preferencesDialog.Resize (300, 400);
preferencesDialog.Run ();
if (gettingHelp) {
preferencesDialog.Run ();
gettingHelp = false;
}
preferencesDialog.Destroy ();
}
void UpdateProfileList ()
{
profileStore.Clear ();
foreach (string s in Global.Connections.ConnectionNames)
profileStore.AppendValues (s);
}
void LoadPreference (String key)
{
object val = Preferences.Get (key);
if (val == null)
return;
switch (key) {
case Preferences.BROWSER_SELECTION:
int b = (int) val;
if (b == 1)
browserSingleClickButton.Active = true;
else if (b == 2)
browserDoubleClickButton.Active = true;
break;
}
}
string GetSelectedProfileName ()
{
TreeIter iter;
TreeModel model;
if (profilesTreeView.Selection.GetSelected (out model, out iter)) {
string name = (string) model.GetValue (iter, 0);
return name;
}
return null;
}
public void OnAddProfileClicked (object o, EventArgs args)
{
new ProfileDialog ();
UpdateProfileList ();
}
public void OnEditProfileClicked (object o, EventArgs args)
{
string profileName = GetSelectedProfileName ();
if (profileName == null)
return;
Connection conn = Global.Connections [profileName];
new ProfileDialog (conn);
UpdateProfileList ();
}
public void OnDeleteProfileClicked (object o, EventArgs args)
{
string profileName = GetSelectedProfileName ();
string msg = null;
if (profileName == null) {
// show dialog; must select entry to edit
return;
}
msg = String.Format ("{0} {1}",
Mono.Unix.Catalog.GetString (
"Are you sure you want to delete the profile:"),
profileName);
if (Util.AskYesNo (preferencesDialog, msg)) {
Global.Connections.Delete (profileName);
Global.Connections.Save ();
UpdateProfileList ();
}
}
public void OnDoubleClickToggled (object o, EventArgs args)
{
if (browserSingleClickButton.Active)
Preferences.Set (Preferences.BROWSER_SELECTION, 1);
else
Preferences.Set (Preferences.BROWSER_SELECTION, 2);
}
public void OnHelpClicked (object o, EventArgs args)
{
try {
gettingHelp = true;
Gnome.Help.DisplayDesktopOnScreen (program,
Defines.PACKAGE,
"lat.xml",
"lat-preferences",
Gdk.Screen.Default);
} catch (Exception e) {
HIGMessageDialog dialog = new HIGMessageDialog (
null,
0,
Gtk.MessageType.Error,
Gtk.ButtonsType.Ok,
"Help error",
e.Message);
dialog.Run ();
dialog.Destroy ();
}
}
}
public class PluginConfigureDialog
{
Glade.XML ui;
[Glade.Widget] Gtk.Dialog pluginConfigureDialog;
[Glade.Widget] Gtk.Entry filterEntry;
[Glade.Widget] Gtk.Button newContainerButton;
[Glade.Widget] Gtk.Button searchBaseButton;
[Glade.Widget] TreeView columnsTreeView;
ListStore columnStore;
Connection conn;
ViewPlugin vp;
List<string> colNames;
List<string> colAttrs;
public PluginConfigureDialog (Connection connection, string pluginName)
{
conn = connection;
colNames = new List<string> ();
colAttrs = new List<string> ();
ui = new Glade.XML (null, "lat.glade", "pluginConfigureDialog", null);
ui.Autoconnect (this);
columnStore = new ListStore (typeof (string), typeof (string));
CellRendererText cell = new CellRendererText ();
cell.Editable = true;
cell.Edited += new EditedHandler (OnNameEdit);
columnsTreeView.AppendColumn ("Name", cell, "text", 0);
cell = new CellRendererText ();
cell.Editable = true;
cell.Edited += new EditedHandler (OnAttributeEdit);
columnsTreeView.AppendColumn ("Attribute", cell, "text", 1);
columnsTreeView.Model = columnStore;
vp = Global.Plugins.GetViewPlugin (pluginName, connection.Settings.Name);
if (vp != null) {
for (int i = 0; i < vp.ColumnNames.Length; i++) {
columnStore.AppendValues (vp.ColumnNames[i], vp.ColumnAttributes[i]);
colNames.Add (vp.ColumnNames[i]);
colAttrs.Add (vp.ColumnAttributes[i]);
}
filterEntry.Text = vp.Filter;
if (vp.DefaultNewContainer != "")
newContainerButton.Label = vp.DefaultNewContainer;
if (vp.SearchBase != "")
searchBaseButton.Label = vp.SearchBase;
} else {
Log.Error ("Unable to find view plugin {0}", pluginName);
}
pluginConfigureDialog.Icon = Global.latIcon;
pluginConfigureDialog.Resize (300, 400);
pluginConfigureDialog.Run ();
pluginConfigureDialog.Destroy ();
}
void OnAttributeEdit (object o, EditedArgs args)
{
TreeIter iter;
if (!columnStore.GetIterFromString (out iter, args.Path))
return;
string oldAttr = (string) columnStore.GetValue (iter, 1);
colAttrs.Remove (oldAttr);
colAttrs.Add (args.NewText);
columnStore.SetValue (iter, 1, args.NewText);
}
void OnNameEdit (object o, EditedArgs args)
{
TreeIter iter;
if (!columnStore.GetIterFromString (out iter, args.Path))
return;
string oldName = (string) columnStore.GetValue (iter, 0);
colNames.Remove (oldName);
colNames.Add (args.NewText);
columnStore.SetValue (iter, 0, args.NewText);
}
public void OnOkClicked (object o, EventArgs args)
{
ViewPluginConfig vpc = new ViewPluginConfig ();
vpc.ColumnAttributes = colAttrs.ToArray ();
vpc.ColumnNames = colNames.ToArray ();
vpc.PluginName = vp.Name;
vpc.Filter = filterEntry.Text;
if (newContainerButton.Label != "")
vpc.DefaultNewContainer = newContainerButton.Label;
if (searchBaseButton.Label != "")
vpc.SearchBase = searchBaseButton.Label;
if (vp.PluginConfiguration.Defaults == null)
vpc.Defaults = new Dictionary<string,string> ();
else
vpc.Defaults = vp.PluginConfiguration.Defaults;
vp.PluginConfiguration = vpc;
Global.Plugins.SetPluginConfiguration (conn.Settings.Name, vpc);
}
public void OnAddClicked (object o, EventArgs args)
{
columnStore.AppendValues ("Untitiled", "Unknown");
}
public void OnRemoveClicked (object o, EventArgs args)
{
TreeModel model;
TreeIter iter;
if (columnsTreeView.Selection.GetSelected (out model, out iter)) {
string name = (string) columnStore.GetValue (iter, 0);
string attr = (string) columnStore.GetValue (iter, 1);
colNames.Remove (name);
colAttrs.Remove (attr);
columnStore.Remove (ref iter);
}
}
public void OnFilterBuildClicked (object o, EventArgs args)
{
SearchBuilderDialog sbd = new SearchBuilderDialog ();
filterEntry.Text = sbd.UserFilter;
}
public void OnNewContainerClicked (object o, EventArgs args)
{
SelectContainerDialog scd = new SelectContainerDialog (conn, null);
scd.Message = String.Format (Mono.Unix.Catalog.GetString ("Select a container for new objects"));
scd.Title = Mono.Unix.Catalog.GetString ("Select container");
scd.Run ();
if (!scd.DN.Equals ("") && !scd.DN.Equals (conn.Settings.Host))
newContainerButton.Label = scd.DN;
}
public void OnSearchBaseClicked (object o, EventArgs args)
{
SelectContainerDialog scd = new SelectContainerDialog (conn, null);
scd.Message = String.Format (Mono.Unix.Catalog.GetString ("Select a search base"));
scd.Title = Mono.Unix.Catalog.GetString ("Select container");
scd.Run ();
if (!scd.DN.Equals ("") && !scd.DN.Equals (conn.Settings.Host))
searchBaseButton.Label = scd.DN;
}
public void OnSetDefaultValuesClicked (object o, EventArgs args)
{
vp.OnSetDefaultValues (conn);
Log.Debug ("OnSetDefaultValuesClicked vp.PluginConfiguration.Defaults.Count: {0}", vp.PluginConfiguration.Defaults.Count);
}
}
}