41 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
42 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
43 Components.utils.import(
"resource://app/jsmodules/StringUtils.jsm");
52 if (typeof(
Cc) ==
"undefined")
53 var
Cc = Components.classes;
54 if (typeof(
Ci) ==
"undefined")
55 var
Ci = Components.interfaces;
56 if (typeof(
Cr) ==
"undefined")
57 var
Cr = Components.results;
58 if (typeof(
Cu) ==
"undefined")
59 var
Cu = Components.utils;
74 folderPathChanged:
false,
77 shouldSetWFPathPref:
false,
89 doPaneLoad:
function watchFolderPrefsPane_doPaneLoad() {
96 var sysInfo = Cc[
"@mozilla.org/system-info;1"]
97 .getService(Ci.nsIPropertyBag2);
98 if (sysInfo.getProperty(
"name") !=
"Windows_NT") {
99 this.shouldSetWFPathPref =
true;
105 if (this.shouldSetWFPathPref) {
107 document.getElementById(
"watch_folder_path_textbox")
108 .removeAttribute(
"preference");
112 this._updateUIState();
115 function forceCheck(
event) {
116 if (
event.type ==
"dialogcancel" &&
117 !
Application.prefs.getValue(
"browser.preferences.instantApply",
true))
121 if (!
self._checkForValidPref(
false)) {
122 event.preventDefault();
123 event.stopPropagation();
127 var watchFolderEnablePrefElem =
128 document.getElementById(
"watch_folder_enable_pref");
129 var watchFolderPathPrefElem =
130 document.getElementById(
"watch_folder_path_pref");
131 var watchFolderEnableCheckboxElem =
132 document.getElementById(
"watch_folder_enable_checkbox");
133 var watchFolderPathTextboxElem =
134 document.getElementById(
"watch_folder_path_textbox");
137 watchFolderEnablePrefElem.valueFromPreferences = watchFolderEnableCheckboxElem.checked;
138 watchFolderPathPrefElem.valueFromPreferences = watchFolderPathTextboxElem.value;
140 var watchFolderEnableCheckbox =
141 document.getElementById(
"watch_folder_enable_checkbox");
142 var shouldPrompt =
self.folderPathChanged;
145 shouldPrompt &= watchFolderEnableCheckbox.checked;
150 var watchFolderDir = Cc[
"@mozilla.org/file/local;1"]
151 .createInstance(Ci.nsILocalFile);
152 var watchFolderPath =
153 watchFolderPathPrefElem.getElementValue(watchFolderPathTextboxElem);
154 watchFolderDir.initWithPath(watchFolderPath);
155 self._rescan(watchFolderDir);
158 window.addEventListener(
'dialogaccept', forceCheck,
true);
159 window.addEventListener(
'dialogcancel', forceCheck,
true);
169 doImportOptionsChange:
170 function watchFolderPrefsPane_doImportOptionsChange(aEvent) {
172 this._checkForValidPref(
true);
182 doBrowseCommand:
function watchFolderPrefsPane_doBrowseCommand(aEvent) {
184 var watchFolderPathPrefElem =
185 document.getElementById(
"watch_folder_path_pref");
186 var watchFolderPathTextboxElem =
187 document.getElementById(
"watch_folder_path_textbox");
188 var watchFolderDir = Cc[
"@mozilla.org/file/local;1"]
189 .createInstance(Ci.nsILocalFile);
191 watchFolderDir.initWithPath(watchFolderPathPrefElem.value);
192 if (!watchFolderDir.exists() ||
193 !watchFolderDir.isDirectory() ||
194 watchFolderDir.isSymlink()) {
195 watchFolderDir =
null;
198 watchFolderDir =
null;
202 var filePicker = Cc[
"@mozilla.org/filepicker;1"]
203 .createInstance(Ci.nsIFilePicker);
204 var filePickerMsg =
SBString(
"watch_folder.file_picker_msg");
205 filePicker.init(
window, filePickerMsg, Ci.nsIFilePicker.modeGetFolder);
209 filePicker.displayDirectory = watchFolderDir;
212 var result = filePicker.show();
215 if ((result == Ci.nsIFilePicker.returnOK) &&
216 (filePicker.file.isDirectory())) {
219 watchFolderPathTextboxElem.value = filePicker.file.path;
220 this.onPathChanged(aEvent);
223 this._checkForValidPref();
229 onPathChanged:
function watchFolderPrefsPane_onPathChanged(aEvent) {
230 this.folderPathChanged =
true;
231 this._updateUIState();
242 _updateUIState:
function()
244 this._checkManageMedia();
245 var checkbox = document.getElementById(
"watch_folder_enable_checkbox");
246 var enabled = checkbox.checked;
247 var broadcaster = document.getElementById(
"watch_folder_disabled_broadcaster");
250 broadcaster.removeAttribute(
"disabled");
252 broadcaster.setAttribute(
"disabled",
"true");
255 this._checkForValidPref();
258 _checkManageMedia:
function()
260 var manageMediaValue =
Application.prefs.getValue(
"songbird.media_management.library.enabled",
false);
261 var watchFolderEnableWarning = document.getElementById(
"watch_folder_enable_warning");
262 if (!manageMediaValue) {
263 watchFolderEnableWarning.setAttribute(
"hidden",
"true");
267 _removeErrorNotifications:
function()
269 var oldNotif, notifBox = document.getElementById(
"watch_folder_notification_box");
271 while ((oldNotif = notifBox.getNotificationWithValue(
"watch_folder_error"))) {
272 notifBox.removeNotification(oldNotif);
276 _showErrorNotification:
function(aMsg)
278 var notifBox = document.getElementById(
"watch_folder_notification_box");
281 var pane = document.getElementById(
"paneImportMedia");
282 document.documentElement.showPane(pane);
283 document.getElementById(
"import_media_tabs").selectedItem = document.getElementById(
"watch_folder_tab");
286 this._removeErrorNotifications();
287 notifBox.appendNotification(aMsg,
"watch_folder_error",
null,
288 notifBox.PRIORITY_CRITICAL_LOW, []);
296 _checkForValidPref:
function watchFolderPrefsPane__checkForValidPref(aSilent)
298 this._removeErrorNotifications();
301 function showErrorNotification(aMsg)
304 self._showErrorNotification(aMsg);
310 var watchFolderSupported = (
"@songbirdnest.com/watch-folder-service;1" in
Cc);
311 if (watchFolderSupported) {
312 watchFolderSupported = Cc[
"@songbirdnest.com/watch-folder-service;1"]
313 .getService(Ci.sbIWatchFolderService)
316 var watchFolderHiddenElem =
317 document.getElementById(
"watch_folder_hidden_broadcaster");
318 if (watchFolderSupported) {
319 watchFolderHiddenElem.removeAttribute(
"hidden");
321 watchFolderHiddenElem.setAttribute(
"hidden",
"true");
324 var checkbox = document.getElementById(
"watch_folder_enable_checkbox");
325 var enabled = checkbox.checked;
332 var watchFolderPathPrefElem =
333 document.getElementById(
"watch_folder_path_pref");
334 var watchFolderPathTextboxElem =
335 document.getElementById(
"watch_folder_path_textbox");
338 if (!this.folderPathChanged)
341 var
path = watchFolderPathPrefElem.getElementValue(watchFolderPathTextboxElem);
344 showErrorNotification(
SBString(
"prefs.watch_folder.error.no_path"));
350 dir = Cc[
"@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
351 dir.initWithPath(path);
353 showErrorNotification(
SBFormattedString(
"prefs.watch_folder.error.not_exist", [dir.path]));
356 if (!dir.isDirectory()) {
357 showErrorNotification(
SBFormattedString(
"prefs.watch_folder.error.not_directory", [dir.path]));
360 if (!dir.isReadable()) {
361 showErrorNotification(
SBFormattedString(
"prefs.watch_folder.error.not_readable", [dir.path]));
366 Components.utils.reportError(e);
367 showErrorNotification(
SBFormattedString(
"prefs.watch_folder.error.generic", [path]));
373 if (this.shouldSetWFPathPref) {
374 document.getElementById(
"watch_folder_path_pref")
375 .valueFromPreferences =
path;
384 _rescan:
function watchFolderPrefsPane__rescan(aFile) {
385 var shouldImportTitle =
386 SBString(
"watch_folder.new_folder.scan_title");
387 var shouldImportMsg =
390 var
promptService = Cc[
'@mozilla.org/embedcomp/prompt-service;1']
391 .getService(Ci.nsIPromptService);
393 promptService.STD_YES_NO_BUTTONS + promptService.BUTTON_POS_1_DEFAULT;
396 var result = promptService.confirmEx(
window,
406 var
importer = Cc[
'@songbirdnest.com/Songbird/DirectoryImportService;1']
407 .getService(Ci.sbIDirectoryImportService);
408 var directoryArray = ArrayConverter.nsIArray([aFile]);
410 var job = importer.import(directoryArray);
411 SBJobUtils.showProgressDialog(job,
window, 0);
function SBFormattedString(aKey, aParams, aDefault, aStringBundle)
function SBString(aKey, aDefault, aStringBundle)