This file is indexed.

/usr/share/xul-ext/form-history-control/chrome/content/FhcPreferences.js is in xul-ext-form-history-control 1.4.0.6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is FhcPreferences.
 *
 * The Initial Developer of the Original Code is Stephan Mahieu.
 * Portions created by the Initial Developer are Copyright (C) 2009
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Stephan Mahieu <stephanmahieu@yahoo.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

/**
 * Methods for the form history preferences dialog.
 * Only used within FhcPreferences.xul.
 *
 * Dependencies:
 *    FhcPreferences.xul, FhcPreferenceHandler.js, FhcDbHandler.js
 *    FhcRdfExtensionHandler.js, FhcUtil.js, FhcBundle.js,
 *    FhcCleanupFilter.js, FhcDateHandler.js
 */
var FhcPreferences = {
  prefHandler:   null,
  dbHandler:     null,
  extHandler:    null,
  bundle:        null,
  dateHandler:   null,
  cleanupFilter: null,
  keyBindings:   null,
  timer:         null,

  /*
   * Initialize on preference window startup.
   */
  init: function() {
    this.prefHandler   = new FhcPreferenceHandler();
    this.dbHandler     = new FhcDbHandler();
    this.extHandler    = new FhcRdfExtensionHandler();
    this.bundle        = new FhcBundle();
    this.dateHandler   = new FhcDateHandler(this.bundle);
    this.cleanupFilter = new FhcCleanupFilter(
                                this.prefHandler,
                                this.dbHandler,
                                this.dateHandler);
    this.keyBindings   = new FhcKeyBindings(this.prefHandler);

    // Initialize tree-skin
    var treeElm = document.getElementById("regexpTree");
    this.prefHandler.setCustomTreeSkin(treeElm);

    this.fillInformationPanel();
    this.adjustQuickFillPreview();
    this.toggleCustomDateFormatList();
    this.initDisplayPanel()
    this.mlexceptionRadioInit();
    this.initMultilinePanel();
    this.mngexceptionRadioInit();
    this.initManageFhcPanel();
    this.initCleanupPanel();
    this.fillKeyBindings();
    this.treeskinRadioInit();
    
    FhcRegexpView.init(
      this.dbHandler, this.bundle, this.prefHandler);

    var prefWin = document.getElementById("formhistoryPrefs");
    if ("arguments" in window && window.arguments.length > 0) {
      if (window.arguments[0] && window.arguments[0].pane) {
        var prefPane;
        var selectPane = window.arguments[0].pane;
        if (selectPane == "names" || selectPane == "values") {
          prefPane = document.getElementById("regexp");
          FhcRegexpView.setFilter(selectPane);
        } else {
          prefPane = document.getElementById(selectPane);
        }
        prefWin.showPane(prefPane);
      }
    }

    // fix size (height) problem on MacOS
    var curPane = prefWin.currentPane;
    prefWin.showPane(document.getElementById("regexp")); //largest pane
    prefWin.showPane(curPane);
  },

  /**
   * Preference window closes, cleanup
   */
  destroy: function() {
    if (this.timer != null) this.timer.cancel();
    FhcRegexpView.destroy();
    delete this.cleanupFilter;
    delete this.dateHandler;
    delete this.bundle;
    delete this.extHandler;
    delete this.dbHandler;
    delete this.prefHandler;
    return true;
  },

  /**
   * Show or hide the taskbar icon.
   *
   * @param elmCheckbox {checkbox}
   */
  showOrHideTaskbarIcon: function(elmCheckbox) {
    var doc = this._getParentDocument();
    var menuElem = doc.getElementById("formhistctrl-statusbarmenu");

    if (elmCheckbox.checked) {
      menuElem.removeAttribute("hidden");
    } else {
      menuElem.setAttribute("hidden", true);
    }
  },

  /**
   * Set the tree skin.
   *
   * @param elmRadio {radio}
   */
  treeskinPrefChecked: function(elmRadio) {
    switch (elmRadio.id) {
      case "auto":
        this.prefHandler.setBackgroundTree("auto");
        break;
      case "light":
        this.prefHandler.setBackgroundTree("light");
        break;
      case "dark":
        this.prefHandler.setBackgroundTree("dark");
        break;
      case "none":
        this.prefHandler.setBackgroundTree("none");
        break;
    }

    // Activate new skin based on color contrast of a tree element
    var treeElm = document.getElementById("regexpTree");
    this.prefHandler.setCustomTreeSkin(treeElm);
  },

  /**
   * Initialize the radiobuttons to reflect the current treeskin setting.
   */
  treeskinRadioInit: function() {
    var curProperty = this.prefHandler.getBackgroundTree();

    // default selection
    var radioElm = document.getElementById("auto");

    switch (curProperty) {
      case "dark":
        radioElm = document.getElementById("dark");
        break;
      case "light":
        radioElm = document.getElementById("light");
        break;
      case "none":
        radioElm = document.getElementById("none");
        break;
    }
    document.getElementById("treeskinRadiogroup").selectedItem = radioElm;
  },

  /**
   * Set the exceptin.
   *
   * @param elmRadio {radio}
   */
  mlexceptionPrefChecked: function(elmRadio) {
    switch (elmRadio.id) {
      case "multilinenoexception":
        this.prefHandler.setMultilineException("multilinenoexception");
        break;
      case "multilinewhitelist":
        this.prefHandler.setMultilineException("multilinewhitelist");
        break;
      case "multilineblacklist":
        this.prefHandler.setMultilineException("multilineblacklist");
        break;
    }
    this.initMultilinePanel();
  },

  /**
   * Initialize the radiobuttons to reflect the current exception setting.
   */
  mlexceptionRadioInit: function() {
    var curProperty = this.prefHandler.getMultilineException();

    // default selection
    var radioElm = document.getElementById("multilinenoexception");

    switch (curProperty) {
      case "multilinewhitelist":
        radioElm = document.getElementById("multilinewhitelist");
        break;
      case "multilineblacklist":
        radioElm = document.getElementById("multilineblacklist");
        break;
    }
    document.getElementById("multilineradioexceptions").selectedItem = radioElm;
  },

  mngByFhcChecked: function(elmCheckbox) {
    this.initManageFhcPanel();
  },

  /**
   * Set the exceptin.
   *
   * @param elmRadio {radio}
   */
  mngexceptionPrefChecked: function(elmRadio) {
    switch (elmRadio.id) {
      case "managefhcnoexception":
        this.prefHandler.setManageFhcException("managefhcnoexception");
        break;
      case "managefhcwhitelist":
        this.prefHandler.setManageFhcException("managefhcwhitelist");
        break;
      case "managefhcblacklist":
        this.prefHandler.setManageFhcException("managefhcblacklist");
        break;
    }
    this.initManageFhcPanel();
  },

  /**
   * Initialize the radiobuttons to reflect the current exception setting.
   */
  mngexceptionRadioInit: function() {
    var curProperty = this.prefHandler.getManageFhcException();

    // default selection
    var radioElm = document.getElementById("managefhcnoexception");

    switch (curProperty) {
      case "managefhcwhitelist":
        radioElm = document.getElementById("managefhcwhitelist");
        break;
      case "managefhcblacklist":
        radioElm = document.getElementById("managefhcblacklist");
        break;
    }
    document.getElementById("managefhcradioexceptions").selectedItem = radioElm;
  },

  /**
   * Adjust the preview to reflect changes to notification-preferences.
   */
  adjustQuickFillPreview: function() {
    var elem = document.getElementById("preview");

    var cssStyle = "width: 6em; height: 1.2em;\n" +
                   "display: inline-block;\n" +
                   "border-style: inset !important;\n" +
                   "padding: 1px 2px;\n";

    if (document.getElementById("changebgcolor").checked) {
      cssStyle += "background-color: " + document.getElementById("bgcolor").color + ";\n";
      document.getElementById("bgcolor").disabled = false;
    } else {
      cssStyle += "background-color: #FFFFFF;\n";
      document.getElementById("bgcolor").color = "#CCCCCC";
      document.getElementById("bgcolor").disabled = true;
    }

    if (document.getElementById("changebordrcolor").checked) {
      cssStyle += "border-color: " + document.getElementById("brdcolor").color + ";\n";
      document.getElementById("brdcolor").disabled = false;
    } else {
      cssStyle += "border-color: #999999;\n";
      document.getElementById("brdcolor").color = "#CCCCCC";
      document.getElementById("brdcolor").disabled = true;
    }

    if (document.getElementById("changebordrthickness").checked) {
      cssStyle += "border-width: " + document.getElementById("brdsize").value + "px;\n";
      document.getElementById("brdsize").disabled = false;
    } else {
      cssStyle += "border-width: 2px;\n";
      document.getElementById("brdsize").disabled = true;
    }

    elem.setAttribute("style", cssStyle);
  },

  /**
   * Set some information in the display panel.
   */
  fillInformationPanel: function() {
    // extension info
    document.getElementById("appname").value = this.extHandler.getName();
//    var appVersion = this.extHandler.getVersion();
//    document.getElementById("appversion").value =
//                  this.bundle.getString("prefwindow.information.fhcversion.label", [appVersion]);
    document.getElementById("appversion").value = this.extHandler.getVersion();
    document.getElementById("appcreator").value = this.extHandler.getCreator();

    // browser info
    document.getElementById("browsername").value = FhcUtil.getBrowserName();
    document.getElementById("browserversion").value = FhcUtil.getBrowserVersion();

    var geckoArr = FhcUtil.getGeckoVersion();
    var geckoVersion = "";
    for (var ii=0; ii<geckoArr.length; ii++) {
      geckoVersion += geckoArr[ii];
      if (ii<geckoArr.length-1) geckoVersion += '.';
    }
    document.getElementById("geckoversion").value = geckoVersion;

    document.getElementById("currentlocale").value = this.prefHandler.getCurrentLocale();

    // database info
    document.getElementById("moz-location").value = this.dbHandler.formHistoryFile.path;
    document.getElementById("moz-size").value = this.dbHandler.formHistoryFile.fileSize + " bytes";
    document.getElementById("moz-datacount").value = this.dbHandler.getNoOfItems();
    
    document.getElementById("fhc-location").value = this.dbHandler.cleanupFile.path;
    try {
      document.getElementById("fhc-size").value = this.dbHandler.cleanupFile.fileSize + " bytes";
      document.getElementById("fhc-datacount1").value =
        "criteria: " + this.dbHandler.getNoOfCleanupAndProtectItems();
      document.getElementById("fhc-datacount2").value =
        "regexp: " + this.dbHandler.getNoOfRegexpItems();
      document.getElementById("fhc-datacount3").value =
        "multiline: " + this.dbHandler.getNoOfMultilineItems();
      document.getElementById("fhc-datacount4").value =
        "customsave: " + this.dbHandler.getNoOfCustomsaveItems();
      document.getElementById("fhc-datacount5").value =
        "formelements: " + this.dbHandler.getNoOfFormelementItems();
    }
    catch(ex) {
      // when preferences is shown but the add-on itself has never been opened yet,
      // the cleanupFile does not exist yet causing an exception reading fileSizes.
    }
  },

  initDisplayPanel: function() {
    var mainDoc = this._getParentDocument();
    if (null == mainDoc.getElementById("appmenu-popup")) {
      // if no app-menu (introduced in FF4), hide the preference option
      document.getElementById("hideAppMenuItemCheckbox").hidden = true;
    }
  },
  
  initMultilinePanel: function() {
    var isEnabled = document.getElementById("multilineenable").checked;
    
    document.getElementById("newVersionAfterTime").disabled = !isEnabled;
    document.getElementById("newVersionAfterLength").disabled = !isEnabled;
    document.getElementById("deleteAfter").disabled = !isEnabled;
    document.getElementById("multilineradioexceptions").disabled = !isEnabled;
    
    var isExceptionListActive = !document.getElementById("multilinenoexception").selected;
    document.getElementById("multilineexceptionlist").disabled = !(isEnabled && isExceptionListActive);
    
    document.getElementById("multilineprivacysavealways").disabled = !isEnabled;
    document.getElementById("multilineprivacysanitizehtml").disabled = !isEnabled;
    //document.getElementById("multilineprivacysaveencrypted").disabled = !isEnabled;
  },

  initManageFhcPanel: function() {
    //var isGlobalRemember = this.prefHandler.isGlobalRememberFormEntriesActive();
    //document.getElementById("ismanagedbyfhc").disabled = !isGlobalRemember;
    var isManagedByFHC = document.getElementById("ismanagedbyfhc").checked;

    document.getElementById("managefhcwhitelist").disabled = !isManagedByFHC;
    document.getElementById("managefhcblacklist").disabled = !isManagedByFHC;
    if (!isManagedByFHC /*|| !isGlobalRemember*/) {
      document.getElementById("managefhcwhitelist").removeAttribute("selected");
      document.getElementById("managefhcblacklist").removeAttribute("selected");
      document.getElementById("managefhcnoexception").setAttribute("selected", true);
    }
    
    var isExceptionListActive = isManagedByFHC && !document.getElementById("managefhcnoexception").selected;
    document.getElementById("managefhcexceptionlist").disabled = !isExceptionListActive;
  },
  
  /**
   * Enable/disable textbox according to checkbox status.
   */
  initCleanupPanel: function() {
    document.getElementById("lastUsedDaysLimit").disabled = !document.getElementById("lastUsedCheck").checked;
    document.getElementById("timesUsedLimit").disabled = !document.getElementById("timesUsedCheck").checked;
  },

  cleanupPrefChecked: function(domElem) {
    switch (domElem.id) {
      case "lastUsedCheck":
        document.getElementById("lastUsedDaysLimit").disabled = !domElem.checked;
        break;
      case "timesUsedCheck":
        document.getElementById("timesUsedLimit").disabled = !domElem.checked;
        break;
    }
  },

  /**
   * Show or hide keybindings for manually saving formhistory depending on the
   * user preference.
   *
   * @param domElem {DOM Element}
   *        checkbox indicating if manual save is active (true) or inactive (false)
   */
  manualsavePrefChecked: function(domElem) {
    var saveEnabled = domElem.checked;
    
    var keySavefield = document.getElementById("saveThisFieldBindingRow");
    var keySavepage = document.getElementById("saveAllFieldsBindingRow");

    // show or hide keybindings for manually saving formhistory
    if (saveEnabled) {
      // show shortcutkey prefitems
      keySavefield.removeAttribute("hidden");
      keySavepage.removeAttribute("hidden");
    } else {
      // hide shortcutkey prefitems
      keySavefield.setAttribute("hidden", true);
      keySavepage.setAttribute("hidden", true);
      // disable the actual shortcutkeys
      this._disableKeybinding("shortcutSaveThisField");
      this._disableKeybinding("shortcutSaveThisPage");
    }
  },

  /**
   * Enable or disable the custom dateformat selector
   */
  toggleCustomDateFormatList: function() {
    var useCustom = document.getElementById("useCustomDateTimeFormat").checked
    document.getElementById("customDateTimeFormatList").disabled = !useCustom;
    document.getElementById("infoimage").hidden = !useCustom;
    
    var toolTip = document.getElementById("customDateFormatHelp");
    if (!useCustom && "open" == toolTip.state) {
      toolTip.hidePopup();
    }
  },

  /**
   * Popup/Hide the CustomDateFormat information tooltip.
   */
  showCustomDateFormatInfo: function() {
    var toolTip = document.getElementById("customDateFormatHelp");
    if ("open" == toolTip.state) {
      toolTip.hidePopup();
    } else {
      var anchorElem = document.getElementById("customDateBox");
      toolTip.openPopup(anchorElem, "before_start", 30, 0, false, false);
    }
  },

  /**
   * Hide the tooltip popup.
   */
  hideTooltipPopup: function() {
    var toolTip = document.getElementById("customDateFormatHelp");
    toolTip.hidePopup();
  },

  /**
   * Re-Create the CleanUp database optionally preserving existing data.
   *
   * @param preserveData {boolean}
   *        try to preserve existing data (uses xml-export/import).
   */
  recreateCleanupDb: function(preserveData) {
    // ask user confitmation
    if (!preserveData) {
      var answer = FhcUtil.confirmDialog(
        this.bundle.getString("prefwindow.prompt.recreate.title"),
        this.bundle.getString("prefwindow.prompt.recreate.confirm"), "");
      if (!answer.isOkay) {
        return;
      }
    }

    var dirServiceProp = Components.classes["@mozilla.org/file/directory_service;1"]
                           .getService(Components.interfaces.nsIProperties);
    var oldDbfile = dirServiceProp.get("ProfD", Components.interfaces.nsIFile);
    oldDbfile.append("cleanup.sqlite");

    var okay = false;
    try {
      // export contents in order to preserve existing data
      if (preserveData) {
        var exportFile = dirServiceProp.get("ProfD", Components.interfaces.nsIFile);
        exportFile.append("cleanup.sqlite.backup.xml");
        FhcUtil.exportCleanupDatabase(exportFile, this.dbHandler, this.prefHandler, this.dateHandler);
      }
      
      // rename databasefile
      oldDbfile.moveTo(null, "cleanup.sqlite.org");

      // Re-Create by triggering a lookup (and set checked flag to false)
      sessionStore.set("FhcCleanupDBSate", false);
      this.dbHandler.getNoOfCleanupAndProtectItems();

      // check presence of re-created file
      var newDbFile = dirServiceProp.get("ProfD", Components.interfaces.nsIFile);
      newDbFile.append("cleanup.sqlite");
      okay = newDbFile.exists();

      // import the xml data backup
      if (okay && preserveData) {
        var cleanupConfig = FhcUtil.importCleanupDatabase(exportFile, this.dateHandler);
        if (cleanupConfig && cleanupConfig.cleanup) {
          this.dbHandler.bulkAddCleanupCriteria(cleanupConfig.cleanup);
        }
        if (cleanupConfig && cleanupConfig.protect) {
          this.dbHandler.bulkAddProtectCriteria(cleanupConfig.protect);
        }
        if (cleanupConfig && cleanupConfig.regexp) {
          this.dbHandler.bulkAddRegexp(cleanupConfig.regexp);
        }
        if (cleanupConfig && cleanupConfig.multiline) {
          this.dbHandler.bulkAddMultilineItems(cleanupConfig.multiline);
        }
        if (cleanupConfig && cleanupConfig.multilineCfg && cleanupConfig.multilineCfg.exceptionlist) {
          this.dbHandler.bulkAddMultilineExceptions(cleanupConfig.multilineCfg.exceptionlist);
        }
        if (cleanupConfig && cleanupConfig.custSaveCfg && cleanupConfig.custSaveCfg.exceptionlist) {
          this.dbHandler.bulkAddCustomsaveExceptions(cleanupConfig.custSaveCfg.exceptionlist);
        }
      }
    }
    finally {
      if (okay) {
        // remove backup
        oldDbfile.remove(false /* not recursive */);
        // remove data-backup (xml)
        if (preserveData) {
          exportFile.remove(false /* not recursive */);
        }
      } else {
        // restore backup
        oldDbfile.moveTo(null, "cleanup.sqlite");
      }

      // Notify HistoryWindow of DB-changes
      Components.classes["@mozilla.org/observer-service;1"]
                .getService(Components.interfaces.nsIObserverService)
                .notifyObservers(null, "cleanup-db-changed", "");
    }
    this.fillInformationPanel();

    var statusText = "";
    if (okay) {
      statusText = this.bundle.getString("prefwindow.recreate.status.okay");
    } else {
      statusText = this.bundle.getString("prefwindow.recreate.status.failed");
    }
    var statusLbl = document.getElementById("recreate-status-text");
    var statusBox = document.getElementById("recreate-status");

    // display statusbox for max. 10 seconds
    statusLbl.value = statusText
    statusBox.height = 2;
    statusBox.collapsed = false;
    this._showRecreateStatus();
  },

  /**
   * Restore the builtin Regular Expressions.
   */
  restoreRegexp: function() {
    // delete old (not modified by user)
    this.dbHandler.deleteBuiltinRegexp();

    // get an array of all predefined regexps
    var predefHandler = new FhcPredefinedRegexp(this.dbHandler, this.bundle);
    var defRegexp = predefHandler.getPredefinedRegexp();

    // check for duplicates (may be the same as user-defined regexp)
    var uniqueRegexp = [], exist;
    var curRegexps = this.dbHandler.getAllRegexp();
    for (var jj=0; jj<defRegexp.length; jj++) {
      for (var ii=0; ii<curRegexps.length; ii++) {
        exist = ((defRegexp[jj].regexp   == curRegexps[ii].regexp) &&
                 (defRegexp[jj].caseSens == curRegexps[ii].caseSens));
        if (exist) break;
      }
      if (!exist) {
        uniqueRegexp.push(defRegexp[jj]);
      }
    }
    curRegexps = null;
    defRegexp = null;

    // add unique regexp
    this.dbHandler.bulkAddRegexp(uniqueRegexp);

    // display status
    var statusText = this.bundle.getString("prefwindow.cleanup.status.regexp",
                                           [uniqueRegexp.length])
    var statusLbl = document.getElementById("recreate-status-text");
    var statusBox = document.getElementById("recreate-status");

    // display statusbox for max. 10 seconds
    statusLbl.value = statusText
    statusBox.height = 2;
    statusBox.collapsed = false;
    this._showRecreateStatus();

    uniqueRegexp = null;

    // repopulate the regexp view
    FhcRegexpView.rePopulate();
  },

  /**
   * Fill the keybinding textboxes (can not use preferences directly).
   */
  fillKeyBindings: function() {
    var txtBoxIds = [
      "shortcutManager",
      "shortcutManageThis",
      "shortcutDeleteValueThis",
      "shortcutDeleteThis",
      "shortcutFillMostRecent",
      "shortcutFillMostUsed",
      "shortcutClearFields",
      "shortcutShowFormFields",
      "shortcutCleanupNow",
      "shortcutSaveThisField",
      "shortcutSaveThisPage"];
    for (var i=0; i<txtBoxIds.length; i++) {
      document.getElementById(txtBoxIds[i]).value =
        this.keyBindings.getFormattedKeybinding(
          this.keyBindings.getKeybinding(txtBoxIds[i])
        );
    }

    // initially hide or show the binding depending on the preference
    if (!this.prefHandler.isManualsaveEnabled()) {
      // hide shortcutkey prefitems
      var keySavefield = document.getElementById("saveThisFieldBindingRow");
      keySavefield.setAttribute("hidden", true);
      var keySavepage = document.getElementById("saveAllFieldsBindingRow");
      keySavepage.setAttribute("hidden", true);
    }
  },

  /**
   * Create a keybinding.
   *
   * @param event {DOM Event}
   *        the key-event which will be used as shortcut
   *
   * @param textboxObj {textbox}
   *        the textbox for displaying the shortcut
   *
   */
  createKeybinding: function(event, textboxObj) {
    var keybinding = this.keyBindings.recognizeKeys(event);
    if (!keybinding) {
      return;
    }
    this.keyBindings.saveKeybinding(textboxObj.id, keybinding);

    // Update textbox
    document.getElementById(textboxObj.id).value = 
      this.keyBindings.getFormattedKeybinding(keybinding);
  },

  /**
   * Disable a keybinding.
   *
   * @param buttonObj {DOM Element}
   *        the button with the same id as the textbox displaying the
   *        keybinding but prefixed with "btn_"
   */
  disableKeybinding: function(buttonObj) {
    var textboxId = buttonObj.id.replace("btn_", "");
    this._disableKeybinding(textboxId);
  },

  /**
   * Disable a keybinding.
   *
   * @param textboxId {String}
   *        the id of the textbox displaying the keybinding
   */
  _disableKeybinding: function(textboxId) {
    this.keyBindings.saveKeybinding(textboxId, null);

    // Update textbox
    document.getElementById(textboxId).value = "";
  },

  /**
   * Cleanup the formhistory database.
   */
  cleanupFormhistoryNow: function() {
    var delEntries = [];

    document.getElementById("button-now").hidden = true;

    var allEntries = this.dbHandler.getAllEntries();
    if (allEntries && allEntries.length > 0) {
      delEntries = this.cleanupFilter.getMatchingEntries(allEntries);
      if (delEntries && delEntries.length > 0) {
        if (this.dbHandler.deleteEntries(delEntries)) {
          this._notifyStoreChanged();
        }
      }
    }

    var statusText = "";
    if (delEntries && 0 < delEntries.length) {
      statusText = this.bundle.getString("prefwindow.cleanup.status.deleted", [delEntries.length])
    } else {
      statusText = this.bundle.getString("prefwindow.cleanup.status.nothingdeleted");
    }
    var statusLbl = document.getElementById("status-text");
    var statusBox = document.getElementById("cleanup-status");

    // display statusbox for max. 10 seconds
    statusLbl.value = statusText;
    statusBox.height = 2;
    statusBox.collapsed = false;
    this._showCleanupStatus();

    delEntries = null;
    allEntries = null;
  },

  /**
   * Fade-in the statusbox.
   */
  _showCleanupStatus: function() {
    var elem = document.getElementById("cleanup-status");

    var newHeight = FhcPreferences._getElemHeight(elem) + 1;
    if (newHeight <= 24) {
      // expand
      elem.height = newHeight;
      FhcPreferences._runAfterTimeout(FhcPreferences._showCleanupStatus, 15);
    }
    else {
      // auto hide after 10 seconds
      elem.height = 26;
      FhcPreferences._runAfterTimeout(FhcPreferences.hideCleanupStatus, 10000);
    }
  },

  /**
   * Fade-out the statusbox.
   */
  hideCleanupStatus: function() {
    var elem = document.getElementById("cleanup-status");

    var newHeight = FhcPreferences._getElemHeight(elem) - 2;
    if (newHeight <= 1) {
      // hide and restore height
      elem.collapsed = true;
      elem.height = 26;
      // enable cleanup button
      document.getElementById("button-now").hidden = false;
    }
    else {
      // collapse
      elem.height = newHeight;
      FhcPreferences._runAfterTimeout(FhcPreferences.hideCleanupStatus, 15);
    }
  },

  /**
   * Fade-in the recreate statusbox.
   */
  _showRecreateStatus: function() {
    var elem = document.getElementById("recreate-status");

    var newHeight = FhcPreferences._getElemHeight(elem) + 1;
    if (newHeight <= 24) {
      // expand
      elem.height = newHeight;
      FhcPreferences._runAfterTimeout(FhcPreferences._showRecreateStatus, 15);
    }
    else {
      // auto hide after 10 seconds
      elem.height = 26;
      FhcPreferences._runAfterTimeout(FhcPreferences.hideRecreateStatus, 10000);
    }
  },


  /**
   * Fade-out the recreate statusbox.
   */
  hideRecreateStatus: function() {
    var elem = document.getElementById("recreate-status");

    var newHeight = FhcPreferences._getElemHeight(elem) - 2;
    if (newHeight <= 1) {
      // hide and restore height
      elem.collapsed = true;
      elem.height = 26;
      // enable cleanup button
      document.getElementById("button-now").hidden = false;
    }
    else {
      // collapse
      elem.height = newHeight;
      FhcPreferences._runAfterTimeout(FhcPreferences.hideRecreateStatus, 15);
    }
  },

  /**
   * Open the edit regexp SubDialog.
   *
   * @param params {Array}
   *        array of input/output parameters
   */
  showFhcEditRegexp: function(params) {
    var prefWin = document.getElementById("formhistoryPrefs");
    prefWin.openSubDialog(
      "chrome://formhistory/content/FhcRegexpDialog.xul",
      "chrome, dialog, modal, resizable=yes", params)
    .focus();
  },

  /**
   * Get the height of an element.
   *
   * @param  elem {DOM Element}
   *         the XIL element
   *         
   * @return {Number}
   *         the height of the element
   * 
   */
  _getElemHeight: function(elem) {
    var height = elem.height;
    if ("" == height) {
      height = elem.clientHeight;
    }
    return parseInt(height, 10);
  },

  /**
   * Send notification to observers that the formhistory store has changed.
   */
  _notifyStoreChanged: function() {
    var observerService = Components.classes["@mozilla.org/observer-service;1"]
                            .getService(Components.interfaces.nsIObserverService);
    observerService.notifyObservers(null, "sessionstore-state-write-complete", "");
  },


  /**
   * Get the root document.
   * @return {DOM} the root document
   */
  _getParentDocument: function() {
    var theOpener;

    // get the root-parent
    for (theOpener = window.opener; (theOpener.opener); ) {
      theOpener = theOpener.opener;
    }
    
    return theOpener.document;
  },

  /**
   * Invoke a callBackFunction after a specified no of milliseconds.
   *
   * @param callBackFunc {Function}
   * @param timeMillisec {Number}
   * 
   */
  _runAfterTimeout: function(callBackFunc, timeMillisec) {
    var event = {
      notify: function(timer) {callBackFunc();}
    }

    if (this.timer == null) {
      this.timer = Components.classes["@mozilla.org/timer;1"]
                    .createInstance(Components.interfaces.nsITimer);
    } else {
      this.timer.cancel();
    }
    this.timer.initWithCallback(
       event,
       timeMillisec,
       Components.interfaces.nsITimer.TYPE_ONE_SHOT);
  }
};

Components.utils.import("chrome://formhistory/content/utils/FhcSessionStorage.jsm", FhcPreferences);