aboutsummaryrefslogtreecommitdiffstats
path: root/notifier/observer_nsIAlertService.js
blob: f48fd0c5715e152e79aa16077585cda79ef90579 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var PLUGIN_INFO =
<VimperatorPlugin>
  <name>{NAME}</name>
  <description>notification using nsIAlertService</description>
  <description lang="ja">nsIAlertServiceを使用したnotifier用通知プラグイン</description>
  <author mail="teramako@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/teramako/">teramako</author>
  <version>0.1</version>
  <license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
  <minVersion>2.0pre</minVersion>
  <maxVersion>2.0pre</maxVersion>
  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/notifier/observer_nsIAlertService.js</updateURL>
  <detail><![CDATA[
notifier.js 用の通知プラグイン
OSのプラットフォーム依存の通知なのでプラットフォームによってはうまく動作しない可能性があります
Mac OSのGrowlが設定されている場合があやしいです

== 設定値 ==
about:config  :set! コマンドでアラートのポップアップ時間等を変更できます

alerts.slideIncrement:
  ポップアップ時の上昇/下降量(px) (default: 1)
alerts.slideIncrementTime:
  ポップアップ時の上昇/下降インターバル(millisec.) (default: 10)
alerts.totalOpenTime:
  アラートの表示時間(millisec.) (default: 4000)

== 動作確認済プラットフォーム ==
- Debian/GNU Linux (GNOME)
- Windows XP

== 既知の問題点 ==
- アラートが連続すると重なってしまう
- 稀に左上隅にアラートがあがり消えない
  解決方法:
    以下のコマンドを実行すると消すことが出来ます
    >||
    :js Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator).getMostRecentWindow("alert:alert").close()
    ||<
  ]]></detail>
</VimperatorPlugin>;
//}}}
(function(){

var notifier = liberator.plugins.notifier;
if (!notifier){
    return;
}

var libly = notifier.libly;
var $U = libly.$U;
var logger = $U.getLogger("observer_alert");

const alertService = Cc["@mozilla.org/alerts-service;1"].getService(Ci.nsIAlertsService);
const ICON_URL = "chrome://vimperator/skin/icon.png";
var observer = {
    observe: function(aSubject, aTopic, aData){
        if (aTopic == "alertclickcallback" && aData){
            liberator.open(aData, liberator.NEW_TAB);
        }
    }
};
function getAlertWindows(){
    return Cc["@mozilla.org/appshell/window-mediator;1"]
            .getService(Ci.nsIWindowMediator)
            .getXULWindowEnumerator("alert:alert");
}
function alertNotify(count, message){
    alertService.showAlertNotification(
        ICON_URL,
        count + ": " + message.title,
        "",
        message.link ? true : false,
        message.link,
        observer
    );
    (function(){
        var fixed = false;
        var winEnum = getAlertWindows();
        var win;
        while (winEnum.hasMoreElements()){
            win = winEnum.getNext()
                    .QueryInterface(Ci.nsIXULWindow).docShell
                    .QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIDOMWindow);
            if (win.arguments[1] == count + ": " + message.title){
                let box = win.document.getElementById("alertTextBox");
                let t = box.firstChild;
                if (box.lastChild.hasAttribute("clickable")){
                    t.style.cursor = "pointer";
                    t.style.color = "#1455D6";
                    t.style.textDecoration = "underline";
                }
                t.setAttribute("onclick", "onAlertClick();");
                box.removeChild(box.lastChild);
                box.appendChild($U.xmlToDom(new XMLList(
                    '<div xmlns="http://www.w3.org/1999/xhtml" class="alertText plain">' + message.message + "</div>"),
                    document
                ));
                win.onAlertLoad();
                fixed = true;
            }
        }
        if (!fixed) setTimeout(arguments.callee, 10);
    })();
}

notifier.observer.register(notifier.Observer, {
    initialize: function (){
        this.count = 1;
    },
    update: function(message){
        alertNotify(this.count, message);
        this.count++;
    }
});

})();
// vim: set fdm=marker sw=4 ts=4 sts=0 et:

options.add(["statuslinetoolbars", "slt"], "Statusline Toolbar Sets", "stringlist", "", { toolbar: t, getter: function () { return this.toolbar.currentSet.split(",").filter(function(id) id != "status-bar").join(",") || "none"; }, setter: function (val) { if (val == "none") val = ""; let newSets = [], removeSets = this.toolbar.currentSet.split(",").filter(function(id) id != "status-bar"), index; for (let [, id] in Iterator(this.parseValues(val))) { let i = removeSets.indexOf(id); if (i != -1) { newSets.push(id); removeSets.splice(i, 1); continue; } let elm = $(id); if (elm) { if (elm.parentNode !== t) { t.appendChild(elm); if (updater[id] && typeof updater[id][0] == "function") updater[id][0](elm); } newSets.push(id); } else if (gToolbox.palette.querySelector("#" + id)) { newSets.push(id); } } t.currentSet = newSets.join(","); t.setAttribute("currentset", newSets.join(",")); updateSets(this.toolbar, newSets, removeSets); document.persist(this.toolbar.id, "currentset"); customizeDone(); return val; }, completer: function (context) { context.completions = [["none","-"]].concat(Array.map(gToolbox.palette.children, function(elm) { return [ elm.id, elm.getAttribute("label") || "-" ]; })); }, validator: function (ids) { return ids.every(function(id) { return ($(id) || gToolbox.palette.querySelector("#" + id)); }); }, }); customizeDone(); } function updateSets (toolbar, newSets, removeSets) { for (let [, id] in Iterator(newSets)) { if (updater[id] && typeof updater[id][0] == "function") { updater[id][0](id); } } for (let [, id] in Iterator(removeSets)) { let elm = $(id); if (!elm) continue; toolbar.removeChild(elm); if (updater[id] && typeof updater[id][1] == "function") { updater[id][1](elm); } } } function createToolbar () { var toolbar = createElement("toolbar", { id: id, toolbarname: "Liberator Statusline Toolbar", toolboxid: "navigator-toolbox", mode: "icons", iconsize: "small", defaulticonsize: "small", lockiconsize: "small", customizable: "true", context: "toolbar-context-menu", }); toolbar.setAttributeNS(NS.uri, "highlight", "ModeMsg"); var RDF = services.get("rdf"); var localStore = RDF.GetDataSource("rdf:local-store"); var currentSet = localStore.GetTarget( RDF.GetResource(document.baseURI + "#" + toolbar.id), RDF.GetResource("currentset"), true); if (currentSet) { currentSet = currentSet.QueryInterface(Ci.nsIRDFLiteral).Value; toolbar.setAttribute("currentset", currentSet); } return toolbar; } // vim: sw=2 ts=2 et: