This is just some static backup of the original site, don't expect every link to work!

Ignore:
Timestamp:
Sep 25, 2011, 9:23:06 PM (11 years ago)
Author:
rene <rene@…>
Branches:
ng_0.9
Children:
284956
Parents:
7666cb
Message:

compatibility for conversation plugin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_rdfDatasource.js

    r7666cb r9cedc0  
    2929    if (this._rdfFileName) this.init();
    3030    if (!dontRegisterObserver) this.AccountManagerObserver.register();
     31    let window = Components.classes['@mozilla.org/appshell/window-mediator;1']
     32        .getService(Components.interfaces.nsIWindowMediator)
     33        .getMostRecentWindow("mail:3pane");
     34    this._extVersion = window.virtualIdentityExtension.extensionVersion;
    3135}
    3236
    3337rdfDatasource.prototype = {
     38    _extVersion :       null,
    3439    _rdfVersion :       "0.0.5",
    3540    _rdfService :       Components.classes["@mozilla.org/rdf/rdf-service;1"]
     
    6772            .createInstance(Components.interfaces.nsIRDFContainer),
    6873   
     74    _pref : Components.classes["@mozilla.org/preferences-service;1"]
     75        .getService(Components.interfaces.nsIPrefService)
     76        .getBranch("extensions.virtualIdentity."),
     77
    6978    getContainer : function (type) {
    7079        switch (type) {
     
    153162        var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
    154163            .getService(Components.interfaces.nsIVersionComparator);
    155         // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label
    156         // var extVersion = this.extensionManager.getItemForID(this._virtualIdentityID).version
    157         var extVersion = document.getElementById("extVersion").getAttribute("value");
    158         return (!oldExtVersion || versionChecker.compare(oldExtVersion, extVersion) < 0)   
     164        return (!oldExtVersion || versionChecker.compare(oldExtVersion, this._extVersion) < 0) 
    159165    },
    160166    // **************    RDF UPGRADE CODE    ****************************************************
     
    315321   
    316322    storeExtVersion: function() {
    317         // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label
    318         // var extVersion = this.extensionManager.getItemForID(this._virtualIdentityID).version
    319         var extVersion = document.getElementById("extVersion").getAttribute("value");
    320323        this._setRDFValue(
    321             this._rdfService.GetResource(this._rdfNS + "virtualIdentity"), "version", extVersion)
     324            this._rdfService.GetResource(this._rdfNS + "virtualIdentity"), "version", this._extVersion)
    322325        this._flush();
    323326    },
     
    584587        this._unsetRDFValue(resource, "name", this._getRDFValue(resource, "name"))
    585588       
    586         var extras = new vI.storageExtras(this, resource);
    587         extras.loopForRDF(this, resource, "unset");
     589        var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null;
     590        if (extras) extras.loopForRDF(this, resource, "unset");
    588591        this.getContainer(recType).RemoveElement(resource, true);
    589592    },
     
    614617            var smtp = this._getRDFValue(resource, "smtp")
    615618            if (!smtp) smtp = vI.NO_SMTP_TAG;
    616             var extras = new vI.storageExtras(this, resource);
     619            var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null;
    617620           
    618621            var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras)
     
    621624    },
    622625   
    623     findMatchingFilter : function (recDescription) {
     626    __getDescriptionAndType : function (recipient, recipientType) {
     627        if (recipientType == "addr_newsgroups") return { recDesc : recipient, recType : "newsgroup" }
     628        else if (this.__isMailingList(recipient)) {
     629            vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is MailList\n");
     630            return { recDesc : this.__getMailListName(recipient), recType : "maillist" }
     631        }
     632        else {
     633            vI.notificationBar.dump("## __getDescriptionAndType: '" + recipient + "' is no MailList\n");
     634            var localIdentityData = new vI.identityData(recipient, null, null, null, null, null, null);
     635            return { recDesc : localIdentityData.combinedName, recType : "email" }
     636        }
     637    },
     638   
     639    // --------------------------------------------------------------------
     640    // check if recipient is a mailing list.
     641    // Similiar to Thunderbird, if there are muliple cards with the same displayName the mailinglist is preferred
     642    // see also https://bugzilla.mozilla.org/show_bug.cgi?id=408575
     643    __isMailingList: function(recipient) {
     644        let abManager = Components.classes["@mozilla.org/abmanager;1"]
     645            .getService(Components.interfaces.nsIAbManager);
     646        let allAddressBooks = abManager.directories;
     647        while (allAddressBooks.hasMoreElements()) {
     648            let ab = allAddressBooks.getNext();
     649            if (ab instanceof Components.interfaces.nsIAbDirectory && !ab.isRemote) {
     650                let abdirectory = abManager.getDirectory(ab.URI +
     651                    "?(and(DisplayName,=," + encodeURIComponent(this.__getMailListName(recipient)) + ")(IsMailList,=,TRUE))");
     652                if (abdirectory) {
     653                    try {   // just try, sometimes there are no childCards at all...
     654                        let cards = abdirectory.childCards;
     655                        if (cards.hasMoreElements()) return true;   // only interested if there is at least one element...
     656                    } catch(e) { }
     657                }
     658            }
     659        }
     660        return false;
     661    }, 
     662   
     663    // --------------------------------------------------------------------
     664   
     665    __getMailListName : function(recipient) {
     666        if (recipient.match(/<[^>]*>/) || recipient.match(/$/)) {
     667            var mailListName = RegExp.leftContext + RegExp.rightContext
     668            mailListName = mailListName.replace(/^\s+|\s+$/g,"")
     669        }
     670        return mailListName;
     671    },
     672
     673    findMatchingFilter : function (recipient, recipientType) {
     674        var recDescription = this.__getDescriptionAndType(recipient, recipientType).recDesc;
    624675        if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: findMatchingFilter for " + recDescription + ".\n");
    625676        var enumerator = this._filterContainer.GetElements();
     
    660711    },
    661712   
    662     readVIdentityFromRDF : function (recDescription, recType) {
     713    readVIdentityFromRDF : function (recipient, recipientType) {
     714        var storedRecipient = this.__getDescriptionAndType(recipient, recipientType);
    663715        var email = this._rdfService.GetResource(this._rdfNS + "rdf#email");
    664         var resource = this._getRDFResourceForVIdentity(recDescription, recType);
     716        var resource = this._getRDFResourceForVIdentity(storedRecipient.recDesc, storedRecipient.recType);
    665717        if (!resource) return null;
    666718        if (!this._rdfDataSource.hasArcOut(resource, email)) {
     
    684736            "' fullName='" + fullName + "' id='" + id + "' smtp='" + smtp + "'\n");
    685737       
    686         var extras = new vI.storageExtras(this, resource);
    687         if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: extras:" + extras.status() + "\n");
     738        var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this, resource):null;
     739        var extras_status = (typeof(vI.storageExtras)=='function')?extras.status():" not used";
     740        if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: extras:" + extras_status + "\n");
    688741       
    689742        var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras)
     
    699752    },
    700753   
    701     updateRDFFromVIdentity : function(recDescription, recType) {
    702         this.updateRDF(recDescription, recType,
    703             document.getElementById("msgIdentity_clone").identityData,
    704             (vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true"),
    705             (vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true"),
     754    updateRDFFromVIdentity : function(identityData, recipientName, recipientType) {
     755        var recipient = this.__getDescriptionAndType(recipientName, recipientType)
     756        this.updateRDF(recipient.recDesc, recipient.recType, identityData,
     757            (!vI.statusmenu && this._pref.getBoolPref("storage_store_base_id")
     758                || vI.statusmenu.objSaveBaseIDMenuItem.getAttribute("checked") == "true"),
     759            (!vI.statusmenu && this._pref.getBoolPref("storage_store_SMTP")
     760                || vI.statusmenu.objSaveSMTPMenuItem.getAttribute("checked") == "true"),
    706761            null, null);
    707762    },
     
    745800        this._setRDFValue(resource, "name", recDescription);
    746801 
    747         localIdentityData.extras.loopForRDF(this, resource, "set");
     802        if (localIdentityData.extras) localIdentityData.extras.loopForRDF(this, resource, "set");
    748803       
    749804        if (vI.notificationBar) vI.notificationBar.dump("## rdfDatasource: updateRDF add " + resource.ValueUTF8 + " at position " + position + ".\n");
     
    765820        return value;
    766821    },
    767    
    768     //  code adapted from http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html
     822
     823    //  code adapted from http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html
    769824    AccountManagerObserver : {
    770825        _uninstall : false,
     
    795850}
    796851
     852
     853function rdfDatasourceAccess() {
     854    this._rdfDataSource = new rdfDatasource("virtualIdentity.rdf", false);
     855    this.stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties");
     856}
     857
     858rdfDatasourceAccess.prototype = {
     859    _rdfDataSource : null,
     860    stringBundle : null,
     861   
     862    _pref : Components.classes["@mozilla.org/preferences-service;1"]
     863        .getService(Components.interfaces.nsIPrefService)
     864        .getBranch("extensions.virtualIdentity."),
     865   
     866    clean : function() {
     867        this._rdfDataSource.clean();
     868    },
     869   
     870    updateVIdentityFromStorage : function(recipientName, recipientType, currentIdentity, currentIdentityIsVid, isNotFirstInputElement) {
     871        var localIdentities = new vI.identityCollection();
     872        localIdentities.addWithoutDuplicates(this._rdfDataSource.readVIdentityFromRDF(recipientName, recipientType));
     873        if (localIdentities.number == 1) vI.notificationBar.dump("## rdfDatasourceAccess: using data from direct match\n");
     874        localIdentities.addWithoutDuplicates(this._rdfDataSource.findMatchingFilter(recipientName, recipientType));
     875       
     876        var returnValue = {}; returnValue.identityCollection = localIdentities;
     877        if (localIdentities.number == 0) {
     878            vI.notificationBar.dump("## rdfDatasourceAccess: updateVIdentityFromStorage no usable Storage-Data found.\n");
     879        }
     880        else {
     881            vI.notificationBar.dump("## rdfDatasourceAccess: compare with current Identity\n");
     882            if (this._pref.getBoolPref("storage_getOneOnly") &&     // if requested to retrieve only storageID for first recipient entered
     883                isNotFirstInputElement &&                           // and it is now not the first recipient entered
     884                !localIdentities.identityDataCollection[0].equalsIdentity(currentIdentity, false).equal) {      // and this id is different than the current used one
     885                    vI.notificationBar.setNote(
     886                        this.stringBundle.GetStringFromName("vident.smartIdentity.vIStorageCollidingIdentity"), // than drop the potential changes
     887                        "storage_notification");
     888                    returnValue.result = "drop";
     889            }
     890            // only update fields if new Identity is different than old one.
     891            else {
     892                vI.notificationBar.dump("## rdfDatasourceAccess: updateVIdentityFromStorage check if storage-data matches current Identity.\n");
     893                var compResult = localIdentities.identityDataCollection[0].equalsIdentity(currentIdentity, true);
     894                if (!compResult.equal) {
     895                    var warning = this.__getWarning("replaceVIdentity", recipientName, compResult.compareMatrix);
     896                    if (    !currentIdentityIsVid ||
     897                        !this._pref.getBoolPref("storage_warn_vI_replace") ||
     898                        (this.__askWarning(warning) == "accept")) {
     899                            returnValue.result = "accept";
     900                    }
     901                }
     902                else {
     903                    returnValue.result = "equal";
     904                }
     905            }
     906        }
     907        return returnValue;
     908    },
     909   
     910    storeVIdentityToAllRecipients : function(identityData, recipients) {
     911        var multipleRecipients = (recipients.length > 1);
     912        var dontUpdateMultipleNoEqual = (this._pref.getBoolPref("storage_dont_update_multiple") && multipleRecipients)
     913        vI.notificationBar.dump("## rdfDatasource: storeVIdentityToAllRecipients dontUpdateMultipleNoEqual='" + dontUpdateMultipleNoEqual + "'\n")
     914       
     915        for (var j = 0; j < recipients.length; j++) {
     916            var returnValue = this.__updateStorageFromVIdentity(identityData, recipients[j].recipient, recipients[j].recipientType, dontUpdateMultipleNoEqual);
     917            if (returnValue.update != "accept")  break;
     918        }
     919        return returnValue;
     920    },
     921
     922    getVIdentityFromAllRecipients : function(allIdentities, recipients) {
     923        var initnumber = allIdentities.number;
     924        for (var j = 0; j < recipients.length; j++) {
     925            allIdentities.addWithoutDuplicates(this._rdfDataSource.readVIdentityFromRDF(recipients[j].recipient, recipients[j].recipientType));
     926            allIdentities.addWithoutDuplicates(this._rdfDataSource.findMatchingFilter(recipients[j].recipient, recipients[j].recipientType));
     927        }
     928        vI.notificationBar.dump("## storage: found " + (allIdentities.number-initnumber) + " address(es)\n")
     929    },
     930
     931    __updateStorageFromVIdentity : function(identityData, recipient, recipientType, dontUpdateMultipleNoEqual) {
     932        vI.notificationBar.dump("## rdfDatasource: __updateStorageFromVIdentity.\n")
     933        var storageDataByType = this._rdfDataSource.readVIdentityFromRDF(recipient, recipientType);
     934        var storageDataByFilter = this._rdfDataSource.findMatchingFilter(recipient, recipientType);
     935       
     936        // update (storing) of data by type is required if there is
     937        // no data stored by type (or different data stored) and no equal filter found
     938        var storageDataByTypeCompResult = storageDataByType?storageDataByType.equalsIdentity(identityData, true):null;
     939        var storageDataByTypeEqual = (storageDataByType && storageDataByTypeCompResult.equal);
     940        var storageDataByFilterEqual = (storageDataByFilter && storageDataByFilter.equalsIdentity(identityData, false).equal);
     941       
     942        var doUpdate = "accept";
     943        if (    (!storageDataByType && !storageDataByFilterEqual) ||
     944            (!storageDataByTypeEqual && !storageDataByFilterEqual && !dontUpdateMultipleNoEqual) ) {
     945            vI.notificationBar.dump("## storage: __updateStorageFromVIdentity updating\n")
     946            if (storageDataByType && !storageDataByTypeEqual && this._pref.getBoolPref("storage_warn_update")) {
     947                vI.notificationBar.dump("## storage: __updateStorageFromVIdentity overwrite warning\n");
     948                doUpdate = this.__askWarning(this.__getWarning("updateStorage", recipient, storageDataByTypeCompResult.compareMatrix));
     949            }
     950        }
     951        if (doUpdate == "accept") this._rdfDataSource.updateRDFFromVIdentity(identityData, recipient, recipientType);
     952        return { update : doUpdate, storedIdentity : storageDataByType };
     953    },
     954   
     955    __getWarning : function(warningCase, recipient, compareMatrix) {
     956        var warning = { title: null, recLabel : null, recipient : null, warning : null, css: null, query : null, class : null };
     957        warning.title = this.stringBundle.GetStringFromName("vident." + warningCase + ".title")
     958        warning.recLabel = this.stringBundle.GetStringFromName("vident." + warningCase + ".recipient") + ":";
     959        warning.recipient = recipient;
     960        warning.warning =
     961            "<table class='" + warningCase + "'><thead><tr><th class='col1'/>" +
     962                "<th class='col2'>" + this.stringBundle.GetStringFromName("vident." + warningCase + ".currentIdentity") + "</th>" +
     963                "<th class='col3'>" + this.stringBundle.GetStringFromName("vident." + warningCase + ".storedIdentity") + "</th>" +
     964            "</tr></thead>" +
     965            "<tbody>" + compareMatrix + "</tbody>" +
     966            "</table>"
     967        warning.css = "vI.DialogBrowser.css";
     968        warning.query = this.stringBundle.GetStringFromName("vident." + warningCase + ".query");
     969        warning.class = warningCase;
     970        return warning;
     971    },
     972
     973    __askWarning : function(warning) {
     974        var retVar = { returnValue: null };
     975        var answer = window.openDialog("chrome://v_identity/content/vI_Dialog.xul","",
     976                    "chrome, dialog, modal, alwaysRaised, resizable=yes",
     977                     warning, retVar)
     978        dump("retVar.returnValue=" + retVar.returnValue + "\n")
     979        return retVar.returnValue;
     980    },
     981}
     982
     983
    797984// create with name of the file to import into
    798985function rdfDatasourceImporter(rdfFileName) {
     
    9491136                    var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp")
    9501137                    smtp = (smtp && smtp != vI.DEFAULT_SMTP_TAG)?relevantSMTPs[smtp].smtp:smtp
    951                     var extras = new vI.storageExtras(this._rdfImportDataSource, resource);
     1138                    var extras = (typeof(vI.storageExtras)=='function')?new vI.storageExtras(this._rdfImportDataSource, resource):null;
    9521139                    var localIdentityData = new vI.identityData(email, fullName, id, smtp, extras)
    9531140                   
     
    9801167}
    9811168vI.rdfDatasource = rdfDatasource;
     1169vI.rdfDatasourceAccess = rdfDatasourceAccess;
    9821170vI.rdfDatasourceImporter = rdfDatasourceImporter;
    9831171}});
Note: See TracChangeset for help on using the changeset viewer.