Home Forums Wiki Doc Install Extras Screenshots Source Code Projects Blog Users Groups Register
Glx-Dock / Cairo-Dock List of forums Applets | Applets Thunderbird Unread Count Add-On broken
The latest stable release is the *3.4.0* : How to install it here.
Note: We just switched from BZR to Git on Github! (only to host the code and your future pull requests)
Applets | Applets

Subjects Author Language Messages Last message
[Locked] Thunderbird Unread Count Add-On broken
Page : 1 2
Guest 25 exscape [Read]
17 December 2014 à 08:41

Guest, Sunday 03 November 2013 à 23:58

found a error on line 44
        try {
            path=(new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
        } catch (e) {
            alert(error);
        }

should be alert(e); unless you make e error on line 43

Guest, Monday 04 November 2013 à 00:26

I updated the file to be complaint with strict JavaScript rules, this should allow Thunderbird to process it faster.
main rule is declare all variables and you should only use [i]var[/i] once per function
the string [i]use strict[/i] enables this
// The dump function requires browser.dom.window.dump.enabled be set to true in prefs.js
var cairounread = {
    MSG_FOLDER_FLAG_INBOX: 0x1000,
    onLoad : function(e) {
        'use strict';
        dump("Loading Cairo Unread Count...\n");

        // read all the preferences
        const PREF_SERVICE = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
        this.prefs = PREF_SERVICE.getBranch("extensions.cairo-dock-unread-messages@glxdock.org.");
        this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
        this.prefs.addObserver("", this, false);

    this.traverseDeep = this.prefs.getBoolPref("traverse-deep");
    this.animateType = this.prefs.getCharPref("animation-type");
    this.animation = this.prefs.getCharPref("animation");
    this.animateTime = this.prefs.getIntPref("animate-time");

        // initialization code
        this.initialized = true;
    },

    onClose: function(e) {
        'use strict';
        dump("Closing Cairo Unread Count...\n");

        this.prefs.removeObserver("", this);

        this.initialized = true;
        this.resetUnreadCount();
    },

    resetUnreadCount: function() {
        'use strict';
        dump("Resetting unread emblem\n");
        this.updateUnreadCount(0, true);
        this.updateUnreadAnimate(false);
    },

    updateUnreadCount: function(x, blockingProcess){
        'use strict';
        dump("Calling update count\n");
        dump("Finding path...\n");
        var path, file, args, process;
        const DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
        try {
            path=(new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
        }
        catch(e) {
            alert(e);
        }

        path = path + "/extensions/cairo-dock-unread-messages@glxdock.org/chrome/content/cairo-SetQuickInfo.py";

        dump("Found path: " + path + "\n");

        file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        args = ["python", path, x];
        process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        file.initWithPath("/usr/bin/env");
        process.init(file);

        dump("Initialising process with arguments " + args + " is blocking = " + blockingProcess + "\n");
        process.run(blockingProcess, args, args.length);
    },
    updateUnreadAnimate: function(start){
        'use strict';
        dump("Calling update animate\n");
        dump("Finding path...\n");
        var path, file, args, process, animateType, animateTime, animation;
        const DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
        try {
            path=(new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
        }
        catch (e) {
            alert(e);
        }

        path = path + "/extensions/cairo-dock-unread-messages@glxdock.org/chrome/content/cairo-Animate.py";

        dump("Found path: " + path + "\n");

        file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile),
        file.initWithPath("/usr/bin/env");

        animateType = this.prefs.getCharPref("animation-type");
        if (start) {
            animateTime = this.prefs.getIntPref("animate-time");
            animation = this.prefs.getCharPref("animation");
        } else {
            animateTime = 0;
            animation = '';
        }
        args = ["python", path, animateTime, animation, animateType];
        process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        process.init(file);

        dump("Initialising process with arguments " + args + "\n");
        process.run(false, args, args.length); // false = non-blocking
    },

    onItemCountChanged : function() {
        'use strict';
        dump("Item count changed...\n");
        if (this.timeoutId != -1) {
            window.clearTimeout(this.timeoutId);
        }
        // Schedule on the main thread
        this.timeoutId = window.setTimeout(this.performUnreadCount, 1000, this);
    },

    performUnreadCount: function(that) {
        'use strict';
        dump("Counting unread messages...\n");
        var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager),
            accounts = acctMgr.accounts,
            totalCount = 0,
            count = accounts.length,
            account, rootFolder, i;
        dump("Found " + count + " accounts\n");
        for(i = 0; i < count; i++) {
            account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount),
            rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
            if (rootFolder.hasSubFolders) {
                totalCount += that.getTotalCount(rootFolder);
            }
        }
        dump("Found total : " + totalCount + "\n");
        that.updateUnreadCount(totalCount, false);
        // Add an animation if the count has gone up
        that.updateUnreadAnimate(that.lastCount < totalCount);
        that.lastCount = totalCount
    },

    getTotalCount: function(rootFolder) {
        'use strict';
        if(rootFolder.getAllFoldersWithFlag) {
            return this._getTotalCountTB2(rootFolder);
        }
        else{
            return this._getTotalCountTB3(rootFolder);
        }
    },

    _getTotalCountTB2: function(rootFolder) {
        'use strict';
        dump("Using _getTotalCountTB2\n");
        var totalCount = 0, subFolders, folder, i;
        dump("Finding all folders with inbox flag : " + this.MSG_FOLDER_FLAG_INBOX + "\n");
        subFolders = rootFolder.getAllFoldersWithFlag(this.MSG_FOLDER_FLAG_INBOX); //nsISupportsArray
        dump("Found " + subFolders.Count() + "folders\n");

        for(i = 0; i < subFolders.Count(); i++) {
            folder = subFolders.GetElementAt(i).QueryInterface(Components.interfaces.nsIMsgFolder);
            dump("Get Number of unread messages with travese deep = " + this.traverseDeep + "\n");
            totalCount += folder.getNumUnread(this.traverseDeep);
        }

        dump("Found total " + totalCount + " in all subFolders\n");
        return totalCount;
    },

    _getTotalCountTB3: function(rootFolder) {
        'use strict';
        dump("Using _getTotalCountTB3\n");
        dump("Finding all folders with inbox flag : " + this.MSG_FOLDER_FLAG_INBOX + "\n");
        var totalCount = 0,
            folder,
            subFolders = rootFolder.getFoldersWithFlags(this.MSG_FOLDER_FLAG_INBOX), //nsIArray
            subFoldersEnumerator = subFolders.enumerate();

        while(subFoldersEnumerator.hasMoreElements()) {
            folder = subFoldersEnumerator.getNext().QueryInterface(Components.interfaces.nsIMsgFolder);
            dump("Get Number of unread messages with travese deep = " + this.traverseDeep + "\n");
            totalCount += folder.getNumUnread(this.traverseDeep);
        }

        dump("Found total " + totalCount + " in all subFolders\n");
        return totalCount;
    },

    folderListener : {
        OnItemAdded : function(parent, item, viewString) {
            'use strict';
            cairounread.onItemCountChanged();
        },
        OnItemRemoved : function(parent, item, viewString) {
            'use strict';
                cairounread.onItemCountChanged();
        },
        OnItemPropertyFlagChanged : function(item, property, oldFlag, newFlag) {
            'use strict';
            if (property=="Status"){
                cairounread.onItemCountChanged();
            }
        },
        OnItemEvent : function(item, event) {
            'use strict';
            cairounread.onItemCountChanged();
        },

        OnFolderLoaded : function(aFolder) {},
        OnDeleteOrMoveMessagesCompleted : function(aFolder) {},
        OnItemPropertyChanged : function(parent, item, viewString) {},
        OnItemIntPropertyChanged : function(item, property, oldVal, newVal) {},
        OnItemBoolPropertyChanged : function(item, property, oldValue, newValue) {},
        OnItemUnicharPropertyChanged : function(item, property, oldValue, newValue) {}
    },

    observe: function(subject, topic, data) {
        'use strict';
        if (topic != "nsPref:changed") {
            return;
        }

        switch(data) {
            case "traverse-deep":
                this.traverseDeep = this.prefs.getBoolPref("traverse-deep");
                cairounread.onItemCountChanged();
            break;
        }
    },

    mailSession: '',
    notifyFlags: '',
    timeoutId: -1
};
window.addEventListener("load", function(e) { 'use strict';cairounread.onLoad(e); }, false);
window.addEventListener("close", function(e) { 'use strict';cairounread.onClose(e); }, false);
window.addEventListener("unload", function(e) { 'use strict';cairounread.onClose(e); }, false);
cairounread.mailSession = Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession);
cairounread.notifyFlags = Components.interfaces.nsIFolderListener.all;
cairounread.mailSession.AddFolderListener(cairounread.folderListener, cairounread.notifyFlags);

fabounet, Tuesday 12 November 2013 à 15:48


Subscription date : 30 November 2007
Messages : 17118
thanks, I didn't know that

Guest, Thursday 23 January 2014 à 21:34

Thanks to author :
Guest
,

fixed it for me - glx-dock 3.0 - Thunderbird 24 - under xubuntu 12.04

greets Krishan

Guest, Sunday 14 December 2014 à 11:21

The fixes posted in this thread didn't work for me as of today (Thunderbird 31.2.0). I solved it after some work, though.
Here's the diff:

diff -Naur OLD/chrome/content/cairounread.js NEW/chrome/content/cairounread.js
--- OLD/chrome/content/cairounread.js    2013-02-19 23:06:08.000000000 +0100
+++ NEW/chrome/content/cairounread.js    2014-12-14 11:06:36.000000000 +0100
@@ -106,10 +106,10 @@
        var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
        var accounts = acctMgr.accounts;
        var totalCount = 0;
-        dump("Found " + accounts.Count() + " accounts\n");
-        for (var i = 0; i < accounts.Count(); i++) {
-            var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
-            var rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
+        dump("Found " + accounts.length + " accounts\n");
+        Cu.import("resource:///modules/iteratorUtils.jsm");
+        for each (let account in fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
+            var rootFolder = account.incomingServer.rootFolder; // nsIMsgFolder
                if (rootFolder.hasSubFolders) {
                    totalCount += that.getTotalCount(rootFolder);
                }


And here's a finished XPI: https://www.mediafire.com/?k6fucyug62roa1a

/exscape serenity  exscape org

exscape, Wednesday 17 December 2014 à 08:41


Subscription date : 15 December 2014
Messages : 3
By the way

If you want the unread count to be displayed on the launcher icon only (not on e.g. compose/open email windows), also edit chrome/content/cairo-SetQuickInfo.py inside the .xpi, and change the SetQuickInfo call from ... "class=thunderbird" to ... "class=thunderbird & type=Launcher".

Applets | Applets

Subjects Author Language Messages Last message
[Locked] Thunderbird Unread Count Add-On broken
Page : 1 2
Guest 25 exscape [Read]
17 December 2014 à 08:41


Glx-Dock / Cairo-Dock List of forums Applets | Applets Thunderbird Unread Count Add-On broken Top

Online users :

Powered by ElementSpeak © 2007 Adrien Pilleboue, 2009-2013 Matthieu Baerts.
Dock based on CSS Dock Menu (Ndesign) with jQuery. Icons by zgegball
Cairo-Dock is a free software under GNU-GPL3 licence. First stable version created by Fabounet.
Many thanks to TuxFamily for the web Hosting and Mav for the domain name.