head_watchfolders.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
33 Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
34 Components.utils.import("resource://app/jsmodules/ArrayConverter.jsm");
35 
36 var Application = Cc["@mozilla.org/fuel/application;1"]
37  .getService(Ci.fuelIApplication);
38 
39 
44 function setWatchFolder(file) {
45  if (file) {
46  dump("WF is watching " + file.path + "\n");
47  Application.prefs.setValue("songbird.watch_folder.path", file.path);
48  }
49  Application.prefs.setValue("songbird.watch_folder.enable", !!file);
50  if (!file) {
51  Application.prefs.get("songbird.watch_folder.sessionguid").reset();
52  }
53 }
54 
59 function reportJobProgress(job, jobName) {
60  log("\n\n\nWatchFolder Job - " + jobName + " job progress - " +
61  job.progress + "/" + job.total + ", " + job.errorCount + " failed. " +
62  "Status " + job.statusText + " (" + job.status + "), Title: " + job.titleText);
63  var errorEnumerator = job.getErrorMessages();
64  while (errorEnumerator.hasMore()) {
65  log("WatchFolder Job " + jobName + " - error: " + errorEnumerator.getNext());
66  }
67  log("\n\n");
68 }
69 
70 
75 function getCopyOfFolder(folder, tempName) {
76  assertNotEqual(folder, null);
77  var tempFolder = getTempFolder();
78  folder.copyTo(tempFolder, tempName);
79  folder = tempFolder.clone();
80  folder.append(tempName);
81  assertEqual(folder.exists(), true);
82  return folder;
83 }
84 
85 
90 function getCopyOfFile(file, tempName, optionalLocation) {
92  var folder = optionalLocation ? optionalLocation : getTempFolder();
93  file.copyTo(folder, tempName);
94  file = folder.clone();
95  file.append(tempName);
96  assertEqual(file.exists(), true);
97  return file;
98 }
99 
105 function getTempFolder() {
106  if (gTempFolder) {
107  return gTempFolder;
108  }
109  gTempFolder = Components.classes["@mozilla.org/file/directory_service;1"]
110  .getService(Components.interfaces.nsIProperties)
111  .get("TmpD", Components.interfaces.nsIFile);
112  gTempFolder.append("songbird_watchfolder_tests" + Math.random() + ".tmp");
113  gTempFolder.createUnique(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
114  return gTempFolder;
115 }
116 
117 
122 function removeTempFolder() {
123  if (gTempFolder && gTempFolder.exists()) {
124  gTempFolder.remove(true);
125  } else {
126  log("\n\n\nWatch Folder Test may not have performed cleanup. Temp files may exist.\n\n\n");
127  }
128 }
const Cc
function assertNotEqual(aExpected, aActual, aMessage)
function log(s)
var Application
function setWatchFolder(file)
function getCopyOfFile(file, tempName, optionalLocation)
function reportJobProgress(job, jobName)
function assertEqual(aExpected, aActual, aMessage)
function removeTempFolder()
return null
Definition: FeedWriter.js:1143
const Ci
var gTempFolder
function getTempFolder()
function getCopyOfFolder(folder, tempName)
var file