]> git.ktnx.net Git - icedeb.git/blob - chrome/icedeb.js
df6363f3cfab8cfa1124fd07411783f32eb2349e
[icedeb.git] / chrome / icedeb.js
1 function getClipboardText() {
2     var clip = Components.classes['@mozilla.org/widget/clipboard;1']
3         .getService(Components.interfaces.nsIClipboard);
4     if (!clip) return null;
5
6     var trans = Components.classes['@mozilla.org/widget/transferable;1']
7         .createInstance(Components.interfaces.nsITransferable);
8     if (!trans) return null;
9
10     trans.addDataFlavor("text/unicode");
11     clip.getData(trans,
12             clip.supportsSelectionClipboard()
13             ? clip.kSelectionClipboard
14             : clip.kGlobalClipboard
15     );
16
17     var str = new Object;
18     var strLength = new Object;
19     trans.getTransferData("text/unicode", str, strLength);
20
21     var text = null;
22
23     if (str) str  = str.value.QueryInterface(Components.interfaces.nsISupportsString);
24     if (str) text = str.data.substring(0, strLength.value / 2);
25
26     return text;
27 }
28
29 function lookup_bts(in_new) {
30     var bug = getClipboardText();
31     if (!bug) return null;
32     bug = bug.replace(/^#/, '');
33     var uri="http://bugs.debian.org/" + bug;
34
35     if (in_new) {
36         var b = getBrowser();
37         var new_tab = b.addTab(uri);
38         b.selectedTab = new_tab;
39     }
40     else {
41         loadURI(uri);
42     }
43 }
44
45 function lookup_pts(in_new) {
46     var pkg = getClipboardText();
47     if (!pkg) return null;
48     var uri="http://packages.qa.debian.org/" + pkg;
49
50     if (in_new) {
51         var b = getBrowser();
52         var new_tab = b.addTab(uri);
53         b.selectedTab = new_tab;
54     }
55     else {
56         loadURI(uri);
57     }
58 }
59
60 function lookup_deb(in_new) {
61     var pkg = getClipboardText();
62     if (!pkg) return null;
63     var uri="http://packages.debian.org/" + pkg;
64
65     if (in_new) {
66         var b = getBrowser();
67         var new_tab = b.addTab(uri);
68         b.selectedTab = new_tab;
69     }
70     else {
71         loadURI(uri);
72     }
73 }
74
75 Debian = {
76     btsButton: function (e) {
77         if ( e.button == 0 )
78             lookup_bts(false)
79         else if ( e.button == 1 )
80             lookup_bts(true);
81     },
82     ptsButton: function (e) {
83         if ( e.button == 0 )
84             lookup_pts(false)
85         else if ( e.button == 1 )
86             lookup_pts(true);
87     },
88     debButton: function (e) {
89         if ( e.button == 0 )
90             lookup_deb(false)
91         else if ( e.button == 1 )
92             lookup_deb(true);
93     }
94 }
95