Erik Grinaker is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

erikg / Revelation

Revelation is a password manager for the GNOME desktop, released under the GNU GPL license. It stores all your accounts and passwords in a single, secure place, and gives you access to it through a user-friendly graphical interface.

Clone this repository (size: 2.1 MB): HTTPS / SSH
hg clone https://bitbucket.org/erikg/revelation
hg clone ssh://hg@bitbucket.org/erikg/revelation

Revelation / src / lib / dialog.py

  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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
#
# Revelation 0.3.2 - a password manager for GNOME 2
# http://oss.codepoet.no/revelation/
# $Id$
#
# Module containing dialog classes
#
#
# Copyright (c) 2003-2004 Erik Grinaker
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

import gtk, gnome.ui, revelation, time, gconf

RESPONSE_NEXT                   = 10
RESPONSE_PREVIOUS               = 11


# first we define a few base classes
class Dialog(gtk.Dialog):
        "Base class for dialogs"

        def __init__(self, parent, title, buttons, default = None):
                gtk.Dialog.__init__(
                        self, title, parent,
                        gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR
                )

                self.set_border_width(6)
                self.vbox.set_spacing(12)
                self.set_resizable(gtk.FALSE)
                self.connect("key-press-event", self.__cb_keypress)

                for stock, response in buttons:
                        self.add_button(stock, response)

                if default is not None:
                        self.set_default_response(default)

                else:
                        self.set_default_response(buttons[-1][1])


        def __cb_keypress(self, widget, data):
                "Callback for handling keypresses"

                # close the dialog on Escape
                if data.keyval == 65307:
                        self.response(gtk.RESPONSE_CLOSE)


        def get_button(self, index):
                "Get one of the dialogs buttons"

                buttons = self.action_area.get_children()

                if index < len(buttons):
                        return buttons[index]

                else:
                        return None



class Hig(Dialog):
        "A HIG-ified message dialog"

        def __init__(self, parent, pritext, sectext, stockimage, buttons, default = None):
                Dialog.__init__(self, parent, "", buttons, default)

                # hbox separating dialog image and contents
                hbox = revelation.widget.HBox()
                hbox.set_spacing(12)
                hbox.set_border_width(6)
                self.vbox.pack_start(hbox)

                # set up image
                if stockimage is not None:
                        image = revelation.widget.Image(stockimage, gtk.ICON_SIZE_DIALOG)
                        image.set_alignment(0.5, 0)
                        hbox.pack_start(image, gtk.FALSE, gtk.FALSE)

                # set up main content area
                self.contents = revelation.widget.VBox()
                self.contents.set_spacing(10)
                hbox.pack_start(self.contents)

                label = revelation.widget.Label("<span size=\"larger\" weight=\"bold\">" + revelation.misc.escape_markup(pritext) + "</span>\n\n" + sectext)
                label.set_alignment(0, 0)
                self.contents.pack_start(label)


        def run(self):
                "Display the dialog"

                self.show_all()
                response = gtk.Dialog.run(self)
                self.destroy()

                return response



class Property(Dialog):
        "A property dialog"

        def __init__(self, parent, title, buttons, default = None):
                Dialog.__init__(self, parent, title, buttons, default)

                self.set_border_width(12)
                self.vbox.set_spacing(18)

                self.sizegroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
                self.tooltips = gtk.Tooltips()


        def add_section(self, title, description = None):
                "Adds an input section to the dialog"

                section = revelation.widget.InputSection(title, self.sizegroup, description)
                self.vbox.pack_start(section)

                return section




# simple message dialogs

class Error(Hig):
        "Displays an error message"

        def __init__(self, parent, pritext, sectext):
                Hig.__init__(
                        self, parent, pritext, sectext, gtk.STOCK_DIALOG_ERROR,
                        [ [ gtk.STOCK_OK, gtk.RESPONSE_OK ] ]
                )



class FileChanged(Hig):
        "Asks the user if she wants to save her changes"

        def __init__(self, parent, pritext, sectext):
                Hig.__init__(
                        self, parent, pritext, sectext, gtk.STOCK_DIALOG_WARNING,
                        [ [ revelation.stock.STOCK_DISCARD, gtk.RESPONSE_CANCEL ], [ gtk.STOCK_CANCEL, gtk.RESPONSE_CLOSE ], [ gtk.STOCK_SAVE, gtk.RESPONSE_OK ] ]
                )


        def run(self):
                "Displays the dialog"

                response = Hig.run(self)

                # Cancel == RESPONSE_CLOSE, Discard == RESPONSE_CANCEL (in order to have
                # Escape etc trigger Cancel instead of Discard)
                if response == gtk.RESPONSE_OK:
                        return gtk.TRUE

                elif response == gtk.RESPONSE_CANCEL:
                        return gtk.FALSE

                else:
                        raise revelation.CancelError



class FileChangedNew(FileChanged):
        "Asks the user to save changes when creating a new file"

        def __init__(self, parent):
                FileChanged.__init__(
                        self, parent, "Save changes to current file?",
                        "You have made changes which have not been saved. If you create a new file without saving then these changes will be lost."
                )



class FileChangedOpen(FileChanged):
        "Asks the user to save changes when opening a different file"

        def __init__(self, parent):
                FileChanged.__init__(
                        self, parent, "Save changes before opening?",
                        "You have made changes which have not been saved. If you open a different file without saving then these changes will be lost."
                )



class FileChangedQuit(FileChanged):
        "Asks the user to save changes when quitting"

        def __init__(self, parent):
                FileChanged.__init__(
                        self, parent, "Save changes before quitting?",
                        "You have made changes which have not been saved. If you quit without saving, then these changes will be lost."
                )



class FileChangedRevert(Hig):
        "Alerts the user about unsaved changes when reverting"

        def __init__(self, parent):
                Hig.__init__(
                        self, parent, "Ignore unsaved changes?",
                        "You have made changes which have not yet been saved. If you revert to the saved file then these changes will be lost.",
                        gtk.STOCK_DIALOG_WARNING, [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ gtk.STOCK_REVERT_TO_SAVED, gtk.RESPONSE_OK ] ], 0
                )


        def run(self):
                "Displays the dialog, emulates the return codes of the FileChanged dialog"

                response = Hig.run(self)

                if response == gtk.RESPONSE_OK:
                        return gtk.FALSE

                else:
                        raise revelation.CancelError



class FileExportInsecure(Hig):
        "Dialog which warns about exporting to insecure data format"

        def __init__(self, parent):
                Hig.__init__(
                        self, parent, "Export to insecure file?",
                        "The file format you have chosen is not encrypted. If anyone has access to the file, they will be able to read your passwords.",
                        gtk.STOCK_DIALOG_WARNING, [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ revelation.stock.STOCK_EXPORT, gtk.RESPONSE_OK ] ], 0
                )


        def run(self):
                "Displays the dialog"

                response = Hig.run(self)

                if response == gtk.RESPONSE_OK:
                        return gtk.TRUE

                else:
                        raise revelation.CancelError



class FileOverwrite(Hig):
        "Asks for file overwrite confirmation"

        def __init__(self, parent, file):
                Hig.__init__(
                        self, parent, "Overwrite existing file?",
                        "The file '" + file + "' already exists. If you choose to overwrite the file, its contents will be lost.", gtk.STOCK_DIALOG_WARNING,
                        [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ revelation.stock.STOCK_OVERWRITE, gtk.RESPONSE_OK ] ],
                        gtk.RESPONSE_CANCEL
                )


        def run(self):
                "Displays the dialog"

                response = Hig.run(self)

                if response == gtk.RESPONSE_OK:
                        return gtk.TRUE

                else:
                        raise revelation.CancelError



# file selectors
class FileSelector(gtk.FileSelection):
        "A normal file selector"

        def __init__(self, parent, title = None):
                gtk.FileSelection.__init__(self, title)

                if parent is not None:
                        self.set_transient_for(parent)


        def add_widget(self, title, widget):
                "Adds a widget to the file selector"

                hbox = revelation.widget.HBox()
                self.main_vbox.pack_start(hbox)

                if title is not None:
                        hbox.pack_start(revelation.widget.Label(title + ":"), gtk.FALSE, gtk.FALSE)

                hbox.pack_start(widget)


        def run(self):
                "Displays and runs the file selector, returns the filename"

                self.show_all()
                response = gtk.FileSelection.run(self)
                filename = self.get_filename()
                self.destroy()

                if response == gtk.RESPONSE_OK:
                        return filename

                else:
                        raise revelation.CancelError



class ExportFileSelector(FileSelector):
        "A file selector for exporting files (with a filetype dropdown)"

        def __init__(self, parent):
                FileSelector.__init__(self, parent, "Select File to Export to")

                # set up a filetype dropdown
                self.dropdown = revelation.widget.OptionMenu()
                self.add_widget("Filetype", self.dropdown)

                for handler in revelation.datahandler.get_export_handlers():
                        item = gtk.MenuItem(handler.name)
                        item.handler = handler
                        self.dropdown.append_item(item)


        def run(self):
                "Displays and runs the dialog, returns a filename and file handler tuple"

                self.show_all()
                response = gtk.FileSelection.run(self)
                filename = self.get_filename()
                handler = self.dropdown.get_active_item().handler
                self.destroy()

                if response == gtk.RESPONSE_OK:
                        return filename, handler

                else:
                        raise revelation.CancelError



class ImportFileSelector(FileSelector):
        "A file selector for importing files (with a filetype dropdown)"

        def __init__(self, parent):
                FileSelector.__init__(self, parent, "Select File to Import")

                # set up a filetype dropdown
                self.dropdown = revelation.widget.OptionMenu()
                self.add_widget("Filetype", self.dropdown)

                item = gtk.MenuItem("Automatically detect")
                item.handler = None
                self.dropdown.append_item(item)

                self.dropdown.append_item(gtk.SeparatorMenuItem())

                for handler in revelation.datahandler.get_import_handlers():
                        item = gtk.MenuItem(handler.name)
                        item.handler = handler
                        self.dropdown.append_item(item)


        def run(self):
                "Displays and runs the dialog, returns a filename and file handler tuple"

                self.show_all()
                response = gtk.FileSelection.run(self)
                filename = self.get_filename()
                handler = self.dropdown.get_active_item().handler
                self.destroy()

                if response == gtk.RESPONSE_OK:
                        return filename, handler

                else:
                        raise revelation.CancelError
        


# entry-related dialogs

class EntryEdit(Property):
        "A dialog for editing entries"

        def __init__(self, parent, title, entry = None):
                Property.__init__(
                        self, parent, title,
                        [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ gtk.STOCK_OK, gtk.RESPONSE_OK ] ]
                )

                if entry is not None:
                        self.entry = entry.copy()

                else:
                        self.entry = revelation.entry.Entry(revelation.entry.ENTRY_ACCOUNT_GENERIC)

                self.sect_meta = self.add_section(title)
                self.sect_fields = None
                self.entry_field = {}

                # entry name input
                self.entry_name = revelation.widget.Entry(self.entry.name)
                self.entry_name.set_width_chars(50)
                self.tooltips.set_tip(self.entry_name, "The name of the entry")
                self.sect_meta.add_inputrow("Name", self.entry_name)

                # entry description input
                self.entry_desc = revelation.widget.Entry(self.entry.description)
                self.tooltips.set_tip(self.entry_desc, "A description of the entry")
                self.sect_meta.add_inputrow("Description", self.entry_desc)

                # entry type dropdown
                self.dropdown = revelation.widget.EntryDropdown()
                self.tooltips.set_tip(self.dropdown, "The type of entry - folders can contain other entries")
                self.sect_meta.add_inputrow("Type", self.dropdown)

                self.dropdown.connect("changed", self.__cb_dropdown_changed)
                self.dropdown.set_type(self.entry.type)


        def __cb_dropdown_changed(self, object):
                "Updates the entry type"

                type = self.dropdown.get_active_item().type

                if type == self.entry.type and self.sect_fields is not None:
                        return

                self.entry.set_type(type)
                fields = self.entry.get_fields()
                self.entry_field = {}

                if self.sect_fields is not None:
                        self.sect_fields.destroy()
                        self.sect_fields = None

                if len(fields) > 0:
                        self.sect_fields = self.add_section("Account data")
                        self.sect_fields.type = type

                for field in fields:
                        entry = field.generate_edit_widget()
                        self.tooltips.set_tip(entry, field.description)

                        self.entry_field[field.id] = entry
                        self.sect_fields.add_inputrow(field.name, entry)

                self.show_all()


        def run(self):
                "Displays the dialog"

                self.show_all()

                if Property.run(self) == gtk.RESPONSE_OK:

                        if self.entry_name.get_text() == "":
                                Error(self, "No name given", "You need to enter a name for the entry.").run()
                                return self.run()

                        self.entry.name = self.entry_name.get_text()
                        self.entry.desc = self.entry_desc.get_text()
                        self.entry.updated = int(time.time())

                        for id, entry in self.entry_field.items():
                                self.entry.set_field(id, entry.get_text())

                        self.destroy()
                        return self.entry

                else:
                        self.destroy()
                        raise revelation.CancelError


        def set_typechange_allowed(self, allow):
                "Sets whether to allow type changes"

                self.dropdown.set_sensitive(allow)



class EntryRemove(Hig):
        "Asks for confirmation when removing entries"

        def __init__(self, parent, entries):

                if len(entries) > 1:
                        pritext = "Really remove the " + str(len(entries)) + " selected entries?"
                        sectext = "By removing these entries you will also remove any entries they may contain."

                elif entries[0].type == revelation.entry.ENTRY_FOLDER:
                        pritext = "Really remove folder '" + entries[0].name + "'?"
                        sectext = "By removing this folder you will also remove all accounts and folders it contains."

                else:
                        pritext = "Really remove account '" + entries[0].name + "'?"
                        sectext = "Please confirm that you wish to remove this account."


                Hig.__init__(
                        self, parent, pritext, sectext, gtk.STOCK_DIALOG_WARNING,
                        [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ revelation.stock.STOCK_REMOVE, gtk.RESPONSE_OK ] ],
                        gtk.RESPONSE_CANCEL
                )


        def run(self):
                "Displays the dialog"

                if Hig.run(self) == gtk.RESPONSE_OK:
                        return gtk.TRUE

                else:
                        raise revelation.CancelError



# password entry dialogs

class Password(Hig):
        "A base dialog for asking for passwords"

        def __init__(self, parent, title, text):
                Hig.__init__(
                        self, parent, title, text, revelation.stock.STOCK_PASSWORD,
                        [ [ gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL ], [ gtk.STOCK_OK, gtk.RESPONSE_OK ] ]
                )

                self.entries = []

                self.sect_passwords = revelation.widget.InputSection()
                self.contents.pack_start(self.sect_passwords)

                self.set_default_size(300, -1)
                self.get_button(0).set_sensitive(gtk.FALSE)


        def __cb_entry_changed(self, widget, data = None):
                "Sets the OK button sensitivity based on the entries"

                for entry in self.entries:
                        if entry.get_text() == "":
                                self.get_button(0).set_sensitive(gtk.FALSE)
                                break

                else:
                        self.get_button(0).set_sensitive(gtk.TRUE)


        def add_entry(self, name):
                "Adds a password entry to the dialog"

                entry = revelation.widget.Entry()
                entry.set_visibility(gtk.FALSE)
                entry.set_max_length(32)
                entry.connect("changed", self.__cb_entry_changed)
                self.sect_passwords.add_inputrow(name, entry)

                self.entries.append(entry)

                return entry


        def run(self):
                "Displays the dialog"

                self.show_all()

                if len(self.entries) > 0:
                        self.entries[0].grab_focus()

                if gtk.Dialog.run(self) == gtk.RESPONSE_OK:
                        return gtk.RESPONSE_OK

                else:
                        raise revelation.CancelError



class PasswordChange(Password):
        "Lets the user change a password"

        def __init__(self, parent, password = None):
                Password.__init__(
                        self, parent, "Enter new password",
                        "Enter a new password for the current data file. The file must be saved before the new password is applied."
                )

                self.password = password

                if password is not None:        
                        self.entry_current = self.add_entry("Current password")

                self.entry_new = self.add_entry("New password")
                self.entry_confirm = self.add_entry("Confirm password")


        def run(self):
                "Displays the dialog"

                while 1:
                        if Password.run(self) == gtk.RESPONSE_OK:
                                if self.password is not None and self.entry_current.get_text() != self.password:
                                        Error(self, "Incorrect password", "The password you entered as the current file password is incorrect.").run()

                                elif self.entry_new.get_text() != self.entry_confirm.get_text():
                                        Error(self, "Passwords don't match", "The password and password confirmation you entered does not match.").run()

                                else:
                                        return self.entry_new.get_text()



class PasswordLoad(Password):
        "Asks for a password when opening a file"

        def __init__(self, parent, filename):
                Password.__init__(
                        self, parent, "Enter file password",
                        "The file '" + filename + "' is encrypted. Please enter the file password to open it."
                )

                self.entry_password = self.add_entry("Password")


        def run(self):
                "Displays the dialog"

                if Password.run(self) == gtk.RESPONSE_OK:
                        return self.entry_password.get_text()



class PasswordLock(Password):
        "Asks for a password when a file is locked"

        def __init__(self, parent):
                Password.__init__(
                        self, parent, "Enter password to unlock file",
                        "The current file has been locked. Please enter the file password to unlock it."
                )

                self.entry_password = self.add_entry("Password")

                self.get_button(1).destroy()


        def run(self):
                "Displays the dialog"

                try:
                        if Password.run(self) == gtk.RESPONSE_OK:
                                return self.entry_password.get_text()

                # do not respect cancel errors etc
                except revelation.CancelError:
                        pass



class PasswordSave(Password):
        "Asks for a new password when saving a file"

        def __init__(self, parent, filename):
                Password.__init__(
                        self, parent, "Enter new file password",
                        "Please enter a new password for the file '" + filename + "'. You will need this password to open the file at a later time."
                )

                self.entry_new = self.add_entry("New password")
                self.entry_confirm = self.add_entry("Confirm password")


        def run(self):
                "Displays the dialog"

                while 1:
                        if Password.run(self) != gtk.RESPONSE_OK:
                                continue

                        if self.entry_new.get_text() != self.entry_confirm.get_text():
                                Error(self, "Passwords don't match", "The password and password confirmation you entered does not match.").run()

                        else:
                                return self.entry_new.get_text()



# other dialogs
class About(gnome.ui.About):
        "An about dialog"

        def __init__(self, parent):
                gnome.ui.About.__init__(
                        self, revelation.APPNAME, revelation.VERSION, revelation.COPYRIGHT,
                        "\"" + revelation.RELNAME + "\"\n\nRevelation is a password manager for the GNOME 2 desktop.",
                        [ revelation.AUTHOR ], None, "",
                        gtk.gdk.pixbuf_new_from_file(revelation.DATADIR + "/pixmaps/revelation.png")
                )

                if parent is not None:
                        self.set_transient_for(parent)


        def run(self):
                "Displays the dialog"

                self.show_all()



class Find(Property):
        "A dialog for searching for entries"

        def __init__(self, parent, config):
                Property.__init__(
                        self, parent, "Find an entry",
                        [ [ gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE ], [ revelation.stock.STOCK_PREVIOUS, RESPONSE_PREVIOUS ], [ revelation.stock.STOCK_NEXT, RESPONSE_NEXT ] ]
                )

                self.config = config

                section = self.add_section("Find an entry")

                # the search string entry
                self.entry_phrase = revelation.widget.Entry()
                self.tooltips.set_tip(self.entry_phrase, "The text to search for")
                self.entry_phrase.connect("changed", self.__cb_entry_changed)
                section.add_inputrow("Search for", self.entry_phrase)

                # the account type dropdown
                self.dropdown = revelation.widget.EntryDropdown()
                self.tooltips.set_tip(self.dropdown, "The account type to search for")
                item = self.dropdown.get_item(0)
                item.set_stock("gnome-stock-about")
                item.set_text("Any")
                item.type = None
                section.add_inputrow("Account type", self.dropdown)

                # folder search checkbutton
                check = revelation.widget.CheckButton("Search for folders as well")
                self.tooltips.set_tip(check, "When enabled, folder names and descriptions will also be searched")
                self.config.bind_widget("search/folders", check)
                section.add_inputrow(None, check)

                check = revelation.widget.CheckButton("Only search in name and description")
                self.tooltips.set_tip(check, "When enabled, only entry names and descriptions will be searched")
                self.config.bind_widget("search/namedesc", check)
                section.add_inputrow(None, check)

                check = revelation.widget.CheckButton("Case sensitive")
                self.tooltips.set_tip(check, "When enabled, searches will be case sensitive")
                self.config.bind_widget("search/casesens", check)
                section.add_inputrow(None, check)

                # set up initial states
                self.entry_phrase.emit("changed")


        def __cb_entry_changed(self, widget, data = None):
                "Sets the Find button sensitivity based on entry contents"

                active = len(self.entry_phrase.get_text()) > 0
                self.get_button(0).set_sensitive(active)
                self.get_button(1).set_sensitive(active)


        def run(self):
                "Displays the dialog"

                self.show_all()
                self.entry_phrase.grab_focus()

                return Property.run(self)



class Preferences(Property):
        "The preference dialog"

        def __init__(self, parent, config):
                Property.__init__(self, parent, "Preferences", [ [ gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE ] ])
                self.config = config

                self.__init_section_file()
                self.__init_section_pwgen()


        def __init_section_file(self):
                "Sets up the file section"

                self.section_file = self.add_section("File Handling")

                # check-button for autoloading a file
                self.check_autoload = revelation.widget.CheckButton("Open file on startup")
                self.section_file.add_inputrow(None, self.check_autoload)

                self.config.bind_widget("file/autoload", self.check_autoload)
                self.tooltips.set_tip(self.check_autoload, "When enabled, a file will be opened when the program is started")


                # entry for file to autoload
                self.entry_autoload_file = revelation.widget.FileEntry("Select File to Automatically Open")
                self.entry_autoload_file.set_sensitive(self.check_autoload.get_active())
                self.section_file.add_inputrow("File to open", self.entry_autoload_file)

                self.config.bind_widget("file/autoload_file", self.entry_autoload_file)
                self.tooltips.set_tip(self.entry_autoload_file, "A file to be opened when the program is started")


                # check-button for autosave
                self.check_autosave = revelation.widget.CheckButton("Autosave data when changed")
                self.section_file.add_inputrow(None, self.check_autosave)

                self.tooltips.set_tip(self.check_autosave, "Automatically saves the data file when an entry is added, modified or removed")
                self.config.bind_widget("file/autosave", self.check_autosave)


                self.check_autoload.connect("toggled", self.__cb_autoload)


        def __init_section_pwgen(self):
                "Sets up the password generator section"

                self.section_pwgen = self.add_section("Password Generator")

                # password length spinbutton
                self.spin_pwlen = revelation.widget.SpinButton()
                self.spin_pwlen.set_range(4, 32)
                self.section_pwgen.add_inputrow("Password length", self.spin_pwlen)

                self.config.bind_widget("passwordgen/length", self.spin_pwlen)
                self.tooltips.set_tip(self.spin_pwlen, "The number of characters in generated passwords - 8 or more are recommended")


                # checkbox for avoiding ambiguous characters in password
                self.check_ambiguous = revelation.widget.CheckButton("Avoid ambiguous characters")
                self.section_pwgen.add_inputrow(None, self.check_ambiguous)

                self.tooltips.set_tip(self.check_ambiguous, "When enabled, generated passwords will not contain ambiguous characters - like 0 (zero) and O (capital o)")
                self.config.bind_widget("passwordgen/avoid_ambiguous", self.check_ambiguous)


        def __cb_autoload(self, widget, data = None):
                "Sets the autoload file entry sensitivity based on the autoload checkbutton state"

                self.entry_autoload_file.set_sensitive(self.check_autoload.get_active())


        def run(self):
                "Runs the preference dialog"

                self.show_all()
                Property.run(self)
                self.destroy()