Changeset 40
- Timestamp:
- 2007-01-23 16:05:18 (2 years ago)
- Files:
-
- trunk/chrome/content/common (added)
- trunk/chrome/content/common/internalFunctions.js (moved) (moved from trunk/chrome/content/dta/internalFunctions.js) (1 diff)
- trunk/chrome/content/common/overlayFunctions.js (moved) (moved from trunk/chrome/content/dta/overlayFunctions.js) (17 diffs)
- trunk/chrome/content/common/regconvert.js (added)
- trunk/install.rdf (modified) (1 diff)
- trunk/notice.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/chrome/content/common/internalFunctions.js
r33 r40 205 205 } 206 206 }; 207 208 function updateIcon(link, elem, metalink) { 209 210 var ico = null; 211 207 function getIcon(link, metalink) { 212 208 try { 213 214 var uri = Components.classes["@mozilla.org/network/standard-url;1"] 215 .createInstance(Components.interfaces.nsIURI); 216 uri.spec = link; 209 var url, uri; 210 if (link instanceof String) { 211 url = link; 212 } 213 else if (link instanceof DTA_URL) { 214 url = link.url; 215 } 216 else if (link instanceof Components.interfaces.nsIURI) { 217 uri = link; 218 } 219 else if ('url' in link) { 220 url = link.url; 221 } 222 if (!uri) { 223 uri = Components.classes["@mozilla.org/network/standard-url;1"] 224 .createInstance(Components.interfaces.nsIURI); 225 uri.spec = url; 226 } 217 227 var ext = uri.path.match(/\.([^/.]+)$/); 218 228 ext = ext ? ext[1] : null; 229 Debug.dump(url + "\n" + uri.path); 219 230 220 231 if (metalink) { 221 ico ="chrome://dta/skin/icons/metalink.png";232 return "chrome://dta/skin/icons/metalink.png"; 222 233 } 223 234 else if ((new String()).findSystemSlash() == "/") { 224 235 if (!ext) {} 225 236 else if (ext.search(/^z(?:ip|\d{2})|r(?:ar|\d{2})|jar|bz2|gz|tar|rpm|deb|xpi|ace|7z(?:ip)$/i) != -1) { 226 ico ="chrome://dta/skin/icons/zip.png";237 return "chrome://dta/skin/icons/zip.png"; 227 238 } 228 239 else if (ext.search(/^mp(?:eg?|g|4)|rmv?|ram|avi|mov|qt|asf|wmv?|mkv$/i) != -1) { 229 ico ="chrome://dta/skin/icons/mpg.png";240 return "chrome://dta/skin/icons/mpg.png"; 230 241 } 231 242 else if (ext.search(/^jp(?:eg?|g|2)|gif|png|tiff?|w?bmp|psd|icon?|tga$/i) != -1) { 232 ico ="chrome://dta/skin/icons/jpg.png";243 return "chrome://dta/skin/icons/jpg.png"; 233 244 } 234 245 else if (ext.search(/^wav|mp[2-4]?a?|mka|flac|og[ga]|mid$/i) != -1) { 235 ico ="chrome://dta/skin/icons/mp3.png";246 return "chrome://dta/skin/icons/mp3.png"; 236 247 } 237 248 else if (ext.search(/^cp{0,3}|hh?|txt|rtf|p(?:l|m|yc?)|xls|doc|odt$/i) != 1) { 238 ico ="chrome://dta/skin/icons/doc.png";249 return "chrome://dta/skin/icons/doc.png"; 239 250 } 240 251 else if (ext.search(/^x?html?|css|rss|atom|js|xml|xslt?$/i) != -1) { 241 ico ="chrome://dta/skin/icons/htm.png";252 return "chrome://dta/skin/icons/htm.png"; 242 253 } 243 254 } else { 244 ico ="moz-icon://" + uri.prePath + uri.path + "?size=16";255 return "moz-icon://" + uri.prePath + uri.path + "?size=16"; 245 256 } 246 257 } 247 258 catch (ex) { 259 Debug.dump(link); 248 260 Debug.dump("updateIcon: failed to grab icon", ex); 249 261 } 250 if (!ico) {251 ico = "chrome://dta/skin/icons/other.png" 252 } 253 elem.setAttribute('src', ico);254 } 262 return "chrome://dta/skin/icons/other.png" 263 } 264 function updateIcon(link, elem, metalink) { 265 elem.setAttribute('src', getIcon(link, metalink)); 266 } trunk/chrome/content/common/overlayFunctions.js
r33 r40 39 39 * File relicensed under MPL-Tri, as it contained mostly my code, even before "forking" and I never signed over the copyright nor did I grant for GPL-only. 40 40 */ 41 41 42 function DTA_include(uri) { 43 Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 44 .getService(Components.interfaces.mozIJSSubScriptLoader) 45 .loadSubScript(uri); 46 } 47 DTA_include("chrome://dta/content/common/regconvert.js"); 48 49 var DTA_FilterManager = Components.classes['@tn123.ath.cx/dtamod/filtermanager;1'] 50 .getService(Components.interfaces.dtaIFilterManager); 51 42 52 function DTA_showPreferences() { 43 53 window.openDialog( … … 65 75 return this._pref['get' + this._conv[typeof(def)]](key); 66 76 } catch (ex) { 67 Components.utils.reportError('key: ' + key + ' / set' + this._conv[typeof(def)]); 68 Components.utils.reportError(ex); 69 this._pref['set' + this._conv[typeof(def)]](key, def); 77 //Components.utils.reportError('DTAP: key miss: ' + key + ' / set' + this._conv[typeof(def)]); 78 //this._pref['set' + this._conv[typeof(def)]](key, def); 70 79 return def; 71 80 } … … 84 93 }, 85 94 reset: function DP_reset(key) { 86 return this._pref s.clearUserPref(key);95 return this._pref.clearUserPref(key); 87 96 }, 88 97 resetDTA: function DP_resetDTA(key) { … … 90 99 }, 91 100 resetBranch: function DP_resetBranch(key) { 92 return this._pref s.resetBranch('extensions.dta.' + key);93 }, 94 resetAll (): function DP_reset() {95 this._pref s.resetBranch('extensions.dta.');101 return this._pref.resetBranch('extensions.dta.' + key); 102 }, 103 resetAll: function DP_reset() { 104 this._pref.resetBranch('extensions.dta.'); 96 105 } 97 106 }; … … 113 122 _loaded : false, 114 123 _load : function() { 115 this._dumpEnabled = DTA_preferences.get ("extensions.dta.directory.visibledump", false);124 this._dumpEnabled = DTA_preferences.getDTA("logging", false); 116 125 this._consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); 117 126 this._logPointer = DTA_profileFile.get('dta_log.txt'); … … 147 156 text += message.replace(/\n/g, "\x0D\x0A\t") + " "; 148 157 } 149 if ( typeof(e) == "object") {158 if (e instanceof Components.Exception) { 150 159 text += (e.message + " (" + e.fileName +" line " + e.lineNumber + ")"); 160 } 161 else if (e instanceof String) { 162 text += e; 163 } 164 else if (e) { 165 text += e.toSource(); 151 166 } 152 167 text += "\x0D\x0A"; … … 209 224 get url() { 210 225 return this._url; 226 }, 227 set url(nv) { 228 this._url = this.str(nv); 229 this.usable = ''; 230 this.decode(); 211 231 }, 212 232 decode: function DU_decode() { … … 264 284 } 265 285 }; 266 // turbo: 4 stati:267 // 0: dta normale268 // 1: tdta269 // 2: dta di un singolo link270 // 3: tdta di un singolo link271 // sends valid links to dialog win272 286 273 287 var DTA_AddingFunctions = { 288 ios: Components.classes["@mozilla.org/network/io-service;1"] 289 .getService(Components.interfaces.nsIIOService), 290 274 291 isLinkOpenable : function(url) { 275 var t = (url.url) ? url.url : url; 276 return t.match(/^(http|ftp|https):\/\/.+/i); 292 if (url instanceof DTA_URL) { 293 url = url.url; 294 } 295 try { 296 var scheme = this.ios.extractScheme(url); 297 return ['http', 'https', 'ftp'].some(function(e) { return e = scheme; }); 298 } 299 catch (ex) { 300 } 301 return false; 277 302 }, 278 303 … … 312 337 }, 313 338 314 getCurrentDropdownValue : function(name) { 315 return nsPreferences.getLocalizedUnicharPref("extensions.dta.dropdown."+name+"-current", ""); 339 getDropDownValue : function(name) { 340 var values = eval(DTA_preferences.getDTA(name, '[]')); 341 return values.length ? values[0] : null; 316 342 }, 317 343 … … 319 345 try { 320 346 // XXX: error to localize 321 if (this.getCurrentDropdownValue('renaming').length==0 || this.getCurrentDropdownValue('directory').length==0) { 347 var dir = this.getDropDownValue('directory'); 348 var mask = this.getDropDownValue('renaming'); 349 if (!mask || !dir) { 322 350 alert("You have not set a valid renaming mask or a valid destination directory."); 323 351 DTA_debug.dump("User has not set a valid renaming mask or a valid destination directory."); … … 325 353 } 326 354 327 var num = DTA_preferences.get("extensions.dta.numistance", 1); 328 num = (num<999)?(++num):1; 329 DTA_preferences.set("extensions.dta.numistance", num); 330 331 for (var i=0; i<urlsArray.length; i++) { 332 urlsArray[i].mask = this.getCurrentDropdownValue('renaming'); 333 urlsArray[i].dirSave = this.getCurrentDropdownValue('directory'); 355 var num = DTA_preferences.getDTA("counter", 1); 356 if (++num > 999) { 357 num = 1; 358 } 359 DTA_preferences.setDTA("counter", num); 360 361 for (var i = 0; i < urlsArray.length; i++) { 362 urlsArray[i].mask = mask; 363 urlsArray[i].dirSave = dir; 334 364 urlsArray[i].numIstance = num; 335 365 } … … 343 373 }, 344 374 345 createFilters : function(type) { 346 347 var convertToRegExp = function(f) { 348 349 // f is a String object. 350 351 // removes leading and final white chars 352 f.replace(/^\s*|\s*$/gi,""); 353 354 // if it's regexp 355 if (f.substring(0,1) == "/" && f.substring(f.length - 1, f.length) == "/") { 356 return (f.length==2)?[]:[new RegExp(f.substring(1, f.length - 1), "i")]; 357 } 358 // uses wildcards.. needs to be converted into regexp 359 else { 360 f = f.replace(/\./gi, "\\.") 361 .replace(/\*/gi, "(.)*") 362 .replace(/\$/gi, "\\$") 363 .replace(/\^/gi, "\\^") 364 .replace(/\+/gi, "\\+") 365 .replace(/\?/gi, ".") 366 .replace(/\|/gi, "\\|") 367 .replace(/\[/gi, "\\["); 375 saveLinkArray : function(turbo, urls, images) { 376 377 try { 378 if (urls.length==0 && images.length==0) { 379 // localization hack 380 alert(document.getElementById("context-dta").attributes.error1.value); 381 } 382 383 if (turbo) { 384 385 DTA_debug.dump("saveLinkArray(): DtaOneClick filtering started"); 368 386 369 var filters = []; 370 var a = f.split(","); 371 for (var i=0; i<a.length; i++) 372 if (a[i].replace(/^\s*|\s*$/gi,"") != "") 373 filters.push(new RegExp(a[i].replace(/^\s*|\s*$/gi, ""))); 374 375 return filters; 376 } 377 }; 378 379 var checkedFilters = []; 380 var filtertxt = this.getCurrentDropdownValue('filter'); 381 if (filtertxt.length > 0) checkedFilters = checkedFilters.concat(convertToRegExp(filtertxt)); 382 383 var nfilters = DTA_preferences.get("extensions.dta.context.numfilters", 0); 384 385 for (var t=0; t<nfilters; t++) { 386 if (DTA_preferences.get("extensions.dta.context.filter" + t + ".is"+type+"Filter", false) 387 && 388 DTA_preferences.get("extensions.dta.context.filter" + t + ".checked", false) 389 ) { 390 checkedFilters = checkedFilters.concat(convertToRegExp(nsPreferences.getLocalizedUnicharPref("extensions.dta.context.filter" + t + ".filter"))); 391 } 392 } 393 394 return checkedFilters; 395 }, 396 saveLinkArray : function(turbo, urls, images) { 397 try { 398 399 if (urls.length==0 && images.length==0) { 400 // localization hack 401 alert(document.getElementById("context-dta").attributes.error1.value); 402 } 403 404 if (turbo) { 405 DTA_debug.dump("saveLinkArray(): DtaOneClick filtering started"); 406 407 var arrayObject = (DTA_preferences.get("extensions.dta.context.seltab", 0)==0)?urls:images; 408 var links = []; 409 var filters = this.createFilters((arrayObject==urls)?"Link":"Image"); 410 411 for (i in arrayObject) { 412 if (i == "length" || typeof(arrayObject[i])!="object") continue; 387 var arrayObject; 388 var type; 389 if (DTA_preferences.getDTA("seltab", 0)) { 390 arrayObject = images; 391 type = 2; 392 } 393 else { 394 arrayObject = urls; 395 type = 1; 396 } 397 var links = []; 398 399 var additional = this.getDropDownValue('filter'); 400 if (!additional); 401 else if (DTA_preferences.getDTA('filterRegex', false)) { 402 additional = DTA_regToRegExp(additional); 403 } 404 else { 405 additional = DTA_strToRegExp(additional); 406 } 407 408 for (i in arrayObject) { 409 if (i == "length" || typeof(arrayObject[i]) != "object") { 410 continue; 411 } 412 var matched = DTA_FilterManager.matchActive(i, type); 413 if (!matched && additional) { 414 matched = additional.test(i); 415 } 416 417 if (!matched) { 418 continue; 419 } 420 421 links.push({ 422 url : arrayObject[i].url, 423 description : arrayObject[i].description, 424 ultDescription : arrayObject[i].ultDescription, 425 refPage : arrayObject[i].refPage 426 }); 427 } 413 428 414 var positiveToFilters = false; 415 for (var j = 0; j<filters.length && !positiveToFilters; j++) 416 if ( 417 i.match(filters[j]) 418 || 419 (arrayObject[i].description && arrayObject[i].description.match(filters[j])) 420 || 421 (arrayObject[i].ultDescription && arrayObject[i].ultDescription.match(filters[j])) 422 ) positiveToFilters = true; 429 DTA_debug.dump("saveLinkArray(): DtaOneClick has filtered " + links.length + " URLs"); 423 430 424 if (!positiveToFilters) continue; 425 426 links.push({ 427 url : arrayObject[i].url, 428 description : arrayObject[i].description, 429 ultDescription : arrayObject[i].ultDescription, 430 refPage : arrayObject[i].refPage 431 }); 432 } 433 434 DTA_debug.dump("saveLinkArray(): DtaOneClick has filtered " + links.length + " URLs"); 435 436 // if i cannot start with oneclick open select.xul 437 if (links.length == 0) { 438 alert(document.getElementById("context-dta").attributes.error1.value); 439 } else if (this.turboSendToDown(links)) { 440 return; 441 } else { 442 DTA_debug.dump("saveLinkArray(): turboSendToDown() returned false.. i'm opening Select window"); 443 } 444 } 445 446 window.openDialog("chrome://dta/content/dta/select.xul","_blank","chrome, centerscreen, resizable=yes, dialog=no, all, modal=no, dependent=no", urls, images); 447 448 } catch(e) { 449 DTA_debug.dump("saveLinkArray(): ", e); 450 } 451 }, 452 453 openManager : function () {try { 454 455 var win = DTA_Mediator.get("chrome://dta/content/dta/manager.xul"); 456 if (win) { 457 win.focus(); 458 return; 459 } 460 window.openDialog("chrome://dta/content/dta/manager.xul", "", "chrome, centerscreen, resizable=yes, dialog=no, all, modal=no, dependent=no"); 461 462 } catch(e) { 463 Components.utils.reportError(e); 464 DTA_debug.dump("openManager():", e); 465 } 466 }, 467 468 _pref : Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch), 469 // XXX: write this 470 getPreference : function (stringa, predefinito) { 471 try { 472 if (typeof(predefinito) == "boolean") 473 var scelta = this._pref.getBoolPref(stringa); 474 else if (typeof(predefinito) == "string") 475 var scelta = this._pref.getCharPref(stringa); 476 else if (typeof(predefinito) == "number") 477 var scelta = this._pref.getIntPref(stringa); 478 return scelta; 479 } catch (e) { 480 if (typeof(predefinito) == "boolean") 481 var scelta = this._pref.setBoolPref(stringa, predefinito); 482 else if (typeof(predefinito) == "string") 483 var scelta = this._pref.setCharPref(stringa, predefinito); 484 else 485 var scelta = this._pref.setIntPref(stringa, predefinito); 486 return predefinito; 487 } 431 // if i cannot start with oneclick open select.xul 432 if (links.length == 0) { 433 alert(document.getElementById("context-dta").attributes.error1.value); 434 } else if (this.turboSendToDown(links)) { 435 return; 436 } else { 437 DTA_debug.dump("saveLinkArray(): turboSendToDown() returned false.. i'm opening Select window"); 438 } 439 } 440 441 window.openDialog( 442 "chrome://dta/content/dta/select.xul", 443 "_blank", 444 "chrome, centerscreen, resizable=yes, dialog=no, all, modal=no, dependent=no", 445 urls, 446 images 447 ); 448 } catch(ex) { 449 DTA_debug.dump("saveLinkArray(): ", ex); 450 } 451 }, 452 453 openManager : function (quite) { 454 try { 455 var win = DTA_Mediator.get("chrome://dta/content/dta/manager.xul"); 456 if (win) { 457 if (!quite) { 458 win.focus(); 459 } 460 return win; 461 } 462 window.openDialog( 463 "chrome://dta/content/dta/manager.xul", 464 "_blank", 465 "chrome, centerscreen, resizable=yes, dialog=no, all, modal=no, dependent=no" 466 ); 467 return DTA_Mediator.get("chrome://dta/content/dta/manager.xul"); 468 } catch(ex) { 469 DTA_debug.dump("openManager():", ex); 470 } 471 return null; 488 472 }, 489 473 490 474 sendToDown : function(notQueue, links) { 491 var win = DTA_Mediator.get("chrome://dta/content/dta/manager.xul"); 492 if (win) { 493 win.self.startnewDownloads(notQueue, links); 494 return; 495 } 496 window.openDialog("chrome://dta/content/dta/manager.xul", "", "chrome, centerscreen, resizable=yes, dialog=no, all, modal=no, dependent=no", notQueue, links); 475 var win = this.openManager(true); 476 return win.self.startnewDownloads(notQueue, links); 497 477 } 498 478 } … … 508 488 }, 509 489 'get': function(url) { 490 if (!url) { 491 return null; 492 } 493 if (url instanceof DTA_URL) { 494 url = url.url; 495 } 496 if (url instanceof Components.interfaces.nsIURI) { 497 url = url.spec; 498 } 510 499 var enumerator = this._m.getEnumerator(null); 511 500 while (enumerator.hasMoreElements()) { … … 517 506 return null; 518 507 }, 519 openTab: function WM_openTab(url) { 508 openTab: function WM_openTab(url, ref) { 509 if (!url) { 510 return; 511 } 520 512 var win = this.getMostRecent(); 521 if (win) 522 { 523 // Use an existing browser window 524 win.delayedOpenTab(url); 525 return; 526 } 527 // No browser windows are open, so open a new one. 528 window.open(url); 513 if (!win) { 514 window.open(); 515 win = this.getMostRecent(); 516 } 517 if (url instanceof DTA_URL) { 518 url = url.url; 519 } 520 if (ref instanceof DTA_URL) { 521 ref = ref.url; 522 } 523 if (ref && !(ref instanceof Components.interfaces.nsIURI)) { 524 try { 525 ref = DTA_AddingFunctions.ios.newURI(ref, null, null); 526 } catch (ex) { 527 alert(ex); 528 ref = null; 529 } 530 } 531 win.delayedOpenTab(url, ref); 529 532 } 530 533 }; … … 550 553 }, 551 554 load: function dd_load() { 552 var values = eval( Preferences.getDTA(this.name, this.predefined));553 var max = Preferences.getDTA("context.history", 5);555 var values = eval(DTA_preferences.getDTA(this.name, this.predefined)); 556 var max = DTA_preferences.getDTA("history", 5); 554 557 555 558 var drop = document.getElementById(this.dropDown); … … 586 589 } 587 590 588 var inValues = eval( Preferences.getDTA(this.name, this.predefined));589 var max = Preferences.getDTA("context.history", 5);591 var inValues = eval(DTA_preferences.getDTA(this.name, this.predefined)); 592 var max = DTA_preferences.getDTA("history", 5); 590 593 591 594 var outValues = [n]; … … 596 599 } 597 600 } 598 Debug.dump(outValues); 599 Preferences.setDTA(this.name, outValues); 601 DTA_preferences.setDTA(this.name, outValues); 600 602 }, 601 603 clear: function dd_save() { trunk/install.rdf
r32 r40 9 9 10 10 <creator>Nils Maier</creator> 11 <developer>Nils Maier</developer> 11 12 <developer>Federico Parodi</developer> 12 13 <developer>Stefano Verna</developer> 13 14 14 < !--<aboutURL>chrome://dta/content/about/about.xul</aboutURL>-->15 <iconURL>chrome://dta/ content/immagini/icon.png</iconURL>15 <aboutURL>chrome://dta/content/about/about.xul</aboutURL> 16 <iconURL>chrome://dta/skin/common/icon.png</iconURL> 16 17 <homepageURL>http://tn123.ath.cx/dtamod/</homepageURL> 17 18 <optionsURL>chrome://dta/content/preferences/newPref.xul</optionsURL> 19 <updateURL>http://tn123.ath.cx/dtamod/update.rdf</updateURL> 18 20 19 21 <!-- Firefox --> trunk/notice.txt
r4 r40 4 4 * DTA - DownThemAll! 5 5 * Copyright (C) 2004-2006 Federico Parodi and Stefano Verna 6 * 7 * DTA! Mod 8 * Copyright (C) 2007 Nils Maier 6 9 * 7 10 * DTA contains pieces of code taken from: … … 25 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 29 * 27 *28 * DTA - DownThemAll!29 * Copyright (C) 2004-2006 Federico Parodi e Stefano Verna30 *31 * Contiene frammenti di codice di:32 * Linky33 * Copyright (C) 2002-2003 Henrik Gemal34 *35 * Questo programma è software libero; è lecito redistribuirlo o36 * modificarlo secondo i termini della Licenza Pubblica Generica GNU37 * come Ë pubblicata dalla Free Software Foundation; o la versione 238 * della licenza o (a propria scelta) una versione successiva.39 *40 * Questo programma è distribuito nella speranza che sia utile, ma41 * SENZA ALCUNA GARANZIA; senza neppure la garanzia implicita di42 * NEGOZIABILITA' o di APPLICABILITA' PER UN PARTICOLARE SCOPO. Si43 * veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.44 *45 * Questo programma deve essere distribuito assieme ad una copia46 * della Licenza Pubblica Generica GNU; in caso contrario, se ne puÚ47 * ottenere una scrivendo alla Free Software Foundation, Inc., 5948 * Temple Place, Suite 330, Boston, MA 02111-1307 USA49 30 * ***** END LICENSE BLOCK ***** -->
