home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / firefox / ScrapBook.xpi / chrome / scrapbook.jar / content / backup.js < prev    next >
Encoding:
JavaScript  |  2005-06-04  |  3.1 KB  |  90 lines

  1. /**************************************************
  2. // backup.js
  3. // Implementation file for backup.xul
  4. // 
  5. // Description: 
  6. // Author: Gomita
  7. // Contributors: michael-brueggemann
  8. // 
  9. // Version: 
  10. // License: see LICENSE.txt
  11. **************************************************/
  12.  
  13.  
  14. var SBwizard;
  15. var SBstring;
  16.  
  17. var gProgPath;
  18. var gDestPath;
  19. var gArguments;
  20. var gDataPath;
  21.  
  22.  
  23. function SB_initBackup()
  24. {
  25.     SBwizard = document.getElementById("ScrapBookBackupWizard");
  26.     SBstring = document.getElementById("ScrapBookString");
  27.     gProgPath  = nsPreferences.copyUnicharPref("scrapbook.backup.program", "");
  28.     gDestPath  = nsPreferences.copyUnicharPref("scrapbook.backup.destination", "");
  29.     gArguments = nsPreferences.copyUnicharPref("scrapbook.backup.arguments", "");
  30.     gDataPath  = SBcommon.getScrapBookDir().path;
  31.     document.getElementById("ScrapBookBackupProgramTextbox").value     = gProgPath;
  32.     document.getElementById("ScrapBookBackupDestinationTextbox").value = gDestPath;
  33.     document.getElementById("ScrapBookBackupArgumentsMenulist").value  = gArguments;
  34.     document.documentElement.getButton("accept").label = SBstring.getString("START_BUTTON");
  35. }
  36.  
  37.  
  38. function SB_execBackup()
  39. {
  40.     gProgPath  = document.getElementById("ScrapBookBackupProgramTextbox").value;
  41.     gDestPath  = document.getElementById("ScrapBookBackupDestinationTextbox").value;
  42.     gArguments = document.getElementById("ScrapBookBackupArgumentsMenulist").value;
  43.     if ( !gProgPath || !gDestPath || !gArguments ) return;
  44.     nsPreferences.setUnicharPref("scrapbook.backup.program",     gProgPath);
  45.     nsPreferences.setUnicharPref("scrapbook.backup.destination", gDestPath);
  46.     nsPreferences.setUnicharPref("scrapbook.backup.arguments",   gArguments);
  47.     gProgPath = gProgPath.replace(/\\/g, "\\\\");
  48.     gDestPath = gDestPath.replace(/\\/g, "\\\\");
  49.     gDataPath = gDataPath.replace(/\\/g, "\\\\");
  50.     var args = gArguments.split(" ");
  51.     for ( var i=0; i<args.length; i++ )
  52.     {
  53.         if ( args[i] == "%dst" ) args[i] = gDestPath;
  54.         if ( args[i] == "%src" ) args[i] = gDataPath;
  55.     }
  56.     SBcommon.execProgram(gProgPath, args);
  57. }
  58.  
  59.  
  60. function SB_selectCompressionProgram()
  61. {
  62.     var FP = Components.classes['@mozilla.org/filepicker;1'].createInstance(Components.interfaces.nsIFilePicker);
  63.     FP.init(window, "Select Compression Program", FP.modeOpen);
  64.     FP.appendFilters(FP.filterApps);
  65.     var answer = FP.show();
  66.     if ( answer == FP.returnOK )
  67.     {
  68.         var theFile = FP.file;
  69.         document.getElementById("ScrapBookBackupProgramTextbox").value = theFile.path;
  70.     }
  71. }
  72.  
  73.  
  74. function SB_selectBackupDestination()
  75. {
  76.     var FP = Components.classes['@mozilla.org/filepicker;1'].createInstance(Components.interfaces.nsIFilePicker);
  77.     FP.init(window, "Select Destination File to Backup", FP.modeSave);
  78.     var ext, prog = document.getElementById("ScrapBookBackupProgramTextbox").value;
  79.     if ( prog.match(/WinRAR/i) ) { ext = "rar"; } else { ext = "zip"; }
  80.     FP.defaultString = "ScrapBook." + ext;
  81.     var answer = FP.show();
  82.     if ( answer == FP.returnOK || answer == FP.returnReplace )
  83.     {
  84.         var theFile = FP.file;
  85.         document.getElementById("ScrapBookBackupDestinationTextbox").value = theFile.path;
  86.     }
  87. }
  88.  
  89.  
  90.