~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/irc/xul/tests/test1-static.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * The contents of this file are subject to the Mozilla Public
 
3
 * License Version 1.1 (the "License"); you may not use this file
 
4
 * except in compliance with the License. You may obtain a copy of
 
5
 * the License at http://www.mozilla.org/MPL/
 
6
 *
 
7
 * Software distributed under the License is distributed on an "AS
 
8
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
9
 * implied. See the License for the specific language governing
 
10
 * rights and limitations under the License.
 
11
 *
 
12
 * The Original Code is JSIRC Test Client #1
 
13
 *
 
14
 * The Initial Developer of the Original Code is New Dimensions Consulting,
 
15
 * Inc. Portions created by New Dimensions Consulting, Inc. are
 
16
 * Copyright (C) 1999 New Dimenstions Consulting, Inc. All
 
17
 * Rights Reserved.
 
18
 *
 
19
 * Contributor(s):
 
20
 *  Robert Ginda, rginda@ndcico.com, original author
 
21
 */
 
22
 
 
23
var client = new Object();
 
24
 
 
25
client.COMMAND_CHAR = "/";
 
26
client.STEP_TIMEOUT = 500;
 
27
client.UPDATE_DELAY = 500;
 
28
 
 
29
client.INITIAL_ALIASES =
 
30
[
 
31
 {name: "connect", value: "e.network.connect();"},
 
32
 {name: "quit",
 
33
  value: "client.quit(e.inputData ? e.inputData : 'no reason');"},
 
34
 {name: "nick",
 
35
  value: "if (e.server && e.inputData) " +
 
36
  "e.server.sendData ('NICK ' + e.inputData + '\\n');"},
 
37
 {name: "network", value: "setCurrentNetwork(e.inputData); onListChannels();"},
 
38
 {name: "channel", value: "setCurrentChannel(e.inputData); onListUsers();"},
 
39
 {name: "me", value: "if (e.channel) e.channel.act (e.inputData);"}
 
40
];
 
41
 
 
42
 
 
43
client.addAlias = function cli_addalias (name, value)
 
44
{
 
45
    var funcName = "onInput" + name[0].toUpperCase() +
 
46
        name.substr (1, name.length).toLowerCase();
 
47
 
 
48
    try
 
49
    {
 
50
        
 
51
        client[funcName] = eval ("f = function alias_" + name + " (e) { " +
 
52
                                 value + "}");
 
53
        
 
54
    }
 
55
    catch (ex)
 
56
    {
 
57
        display ("Error adding alias (" + name + "): "  + ex);
 
58
    }
 
59
    
 
60
}
 
61
 
 
62
client.removeAlias = function cli_remalias (name)
 
63
{
 
64
 
 
65
    delete client[funcName];
 
66
    
 
67
}
 
68
 
 
69
client.quit = function cli_quit (reason)
 
70
{
 
71
    
 
72
    for (var n in client.networks)
 
73
        if (client.networks[n].primServ)
 
74
            client.networks[n].quit (reason);
 
75
    
 
76
}
 
77
 
 
78
CIRCUser.prototype.getDecoratedNick = function usr_decoratednick()
 
79
{
 
80
    var pfx;
 
81
    
 
82
    if (typeof this.isOp != "undefined")
 
83
    {
 
84
        pfx = "[";
 
85
        if (this.__proto__ == this.parent.parent.me)
 
86
            pfx += "*";
 
87
        pfx += this.isOp ? "O" : "X";
 
88
        pfx += this.isVoice ? "V" : "X";
 
89
        pfx += "] ";
 
90
    }
 
91
    else
 
92
        if (this == this.parent.me)
 
93
            pfx = "[*??]";
 
94
        else
 
95
            pfx = "[??] ";
 
96
    
 
97
    return pfx + this.nick;
 
98
 
 
99
}
 
100
 
 
101
CIRCNetwork.prototype.getDecoratedName = function usr_decoratedname()
 
102
{
 
103
    var pfx = "[";
 
104
 
 
105
    pfx += this.isConnected() ? "online" : "offline";
 
106
    pfx += "] ";
 
107
 
 
108
    return pfx + this.name;
 
109
    
 
110
}
 
111
 
 
112
function initStatic()
 
113
{
 
114
    
 
115
    CIRCNetwork.prototype.INITIAL_NICK = "test1";
 
116
    CIRCNetwork.prototype.INITIAL_NAME = "test1";
 
117
    CIRCNetwork.prototype.INITIAL_DESC = "New Now Know How";
 
118
    CIRCNetwork.prototype.INITIAL_CHANNEL = "";
 
119
    CIRCServer.prototype.READ_TIMEOUT = 0;
 
120
 
 
121
    var list = document.getElementById("lstQuickList");
 
122
    list.onclick = onListClick;
 
123
    
 
124
}
 
125
 
 
126
/*
 
127
 * One time initilization stuff
 
128
 */     
 
129
function init(obj)
 
130
{
 
131
    
 
132
    obj.networks = new Object();
 
133
    obj.eventPump = new CEventPump (10);
 
134
    
 
135
    obj.networks["efnet"] =
 
136
        new CIRCNetwork ("efnet", [{name: "irc.primenet.com", port: 6667},
 
137
                         {name: "irc.cs.cmu.edu",   port: 6667}],
 
138
                         obj.eventPump);
 
139
    obj.networks["linuxnet"] =
 
140
        new CIRCNetwork ("linuxnet", [{name: "irc.mozilla.org", port: 6667}],
 
141
                         obj.eventPump);
 
142
    obj.networks["hybridnet"] =
 
143
        new CIRCNetwork ("hybridnet", [{name: "irc.ssc.net", port: 6667}],
 
144
                         obj.eventPump);
 
145
 
 
146
    obj.primNet = obj.networks["efnet"];
 
147
 
 
148
    if (DEBUG)
 
149
        /* hook all events EXCEPT server.poll and *.event-end types
 
150
         * (the 4th param inverts the match) */
 
151
        obj.eventPump.addHook ([{type: "poll", set: /^(server|dcc-chat)$/},
 
152
                               {type: "event-end"}], event_tracer,
 
153
                               "event-tracer", true /* negate */);
 
154
    
 
155
}
 
156
 
 
157
function listClear (list)
 
158
{
 
159
 
 
160
    while (list.options.length > 0)
 
161
        list.options[0] = null;
 
162
 
 
163
}
 
164
 
 
165
function listFill (list, source, prop, callFlag /* optional */)
 
166
{
 
167
    var ary = new Array();
 
168
    
 
169
    listClear (list);
 
170
 
 
171
    for (var o in source)
 
172
        if (!callFlag)
 
173
            ary.push (source[o][prop]);
 
174
        else
 
175
            ary.push (source[o][prop]());
 
176
 
 
177
    ary.sort();
 
178
    
 
179
    for (var i = 0; i < ary.length; i++)
 
180
        list.add (new Option(ary[i]), null);
 
181
    
 
182
}
 
183
 
 
184
function listGetSelectedIndex (list)
 
185
{
 
186
    var sels = new Array();
 
187
 
 
188
    for (o in list.options)
 
189
        if (list.options[o].selected)
 
190
            sels[sels.length] = o;
 
191
 
 
192
    if (sels.length == 1)
 
193
        return sels[0];
 
194
    else
 
195
        return sels;
 
196
    
 
197
}
 
198
 
 
199
function display (line)
 
200
{
 
201
    var output = document.getElementById ("output");
 
202
 
 
203
    output.value = line + "\n" + output.value;
 
204
    
 
205
}
 
206
 
 
207
function mainstep()
 
208
{
 
209
 
 
210
    client.eventPump.stepEvents();
 
211
    setTimeout ("mainstep()", client.STEP_TIMEOUT);
 
212
    
 
213
}
 
214
 
 
215
/*
 
216
 * Hook used to trace events.
 
217
 */
 
218
function event_tracer (e)
 
219
{
 
220
    var name="", data="";
 
221
 
 
222
    switch (e.set)
 
223
    {
 
224
        case "server":
 
225
            name = e.destObject.connection.host;
 
226
            if (e.type == "rawdata")
 
227
                data = "'" + e.data + "'";
 
228
            break;
 
229
 
 
230
        case "channel":
 
231
            name = e.destObject.name;
 
232
            break;
 
233
            
 
234
        case "user":
 
235
            name = e.destObject.nick;
 
236
            break;
 
237
 
 
238
        case "httpdoc":
 
239
            name = e.destObject.server + e.destObject.path;
 
240
            if (e.destObject.state != "complete")
 
241
                data = "state: '" + e.destObject.state + "', recieved " +
 
242
                    e.destObject.data.length;
 
243
            else
 
244
                dd ("document done:\n" + dumpObjectTree (this));
 
245
            break;
 
246
 
 
247
        case "dcc-chat":
 
248
            name = e.destObject.host + ":" + e.destObject.port;
 
249
            if (e.type == "rawdata")
 
250
                data = "'" + e.data + "'";
 
251
            break;
 
252
 
 
253
        case "client":
 
254
            if (e.type == "do-connect")
 
255
                data = "attempt: " + e.attempt + "/" +
 
256
                    e.destObject.MAX_CONNECT_ATTEMPTS;
 
257
            break;
 
258
 
 
259
        default:
 
260
            break;
 
261
    }
 
262
 
 
263
    if (name)
 
264
        name = "[" + name + "]";
 
265
 
 
266
    str = "Level " + e.level + ": '" + e.type + "', " +
 
267
        e.set + name + "." + e.destMethod;
 
268
        if (data)
 
269
          str += "\ndata   : " + data;
 
270
 
 
271
    dd (str);
 
272
 
 
273
    return true;
 
274
 
 
275
}
 
276
 
 
277
function updateList ()
 
278
{
 
279
 
 
280
    if (!client.updateTimeout)
 
281
        client.updateTimeout = setTimeout ("updateListNow()",
 
282
                                           client.UPDATE_DELAY);    
 
283
}
 
284
 
 
285
function updateListNow()
 
286
{
 
287
 
 
288
    var quickList = document.getElementById("lstQuickList");
 
289
 
 
290
    if (client.updateTimeout)
 
291
    {
 
292
        clearTimeout (client.updateTimeout);
 
293
        delete client.updateTimeout;
 
294
    }
 
295
 
 
296
    switch (client.lastListType)
 
297
    {
 
298
 
 
299
        case "networks":
 
300
            listFill (quickList, client.networks, "getDecoratedName",
 
301
                      true);
 
302
            break;
 
303
 
 
304
        case "users":
 
305
            listFill (quickList, client.network.primServ.users,
 
306
                      "getDecoratedNick", true);
 
307
            break;
 
308
 
 
309
        case "channels":
 
310
            listFill (quickList, client.network.primServ.channels, "name",
 
311
                      false);
 
312
            break;
 
313
 
 
314
        case "chan-users":
 
315
            listFill (quickList, client.channel.users, "getDecoratedNick",
 
316
                      true);
 
317
            break;
 
318
 
 
319
        default:
 
320
            break;
 
321
            
 
322
    }
 
323
    
 
324
}
 
325
 
 
326
function updateStatus()
 
327
{
 
328
    var status = document.getElementById ("status");
 
329
    
 
330
    var netName = (client.network) ? client.network.name : "[no-network]";
 
331
    var chanName = (client.channel) ? client.channel.name : "[no-channel]";
 
332
    
 
333
    status.value = netName + " " + chanName;
 
334
    
 
335
}
 
336
 
 
337
function setCurrentNetwork (o)
 
338
{
 
339
    var oldnetwork = client.network;
 
340
    
 
341
    switch (typeof o)
 
342
    {
 
343
        case "object":
 
344
            client.network = o;
 
345
            break;
 
346
 
 
347
        case "string":
 
348
            var v = client.networks[o];
 
349
            if (v)
 
350
                client.network = v;
 
351
            break;
 
352
 
 
353
        default:
 
354
            dd ("setCurrentNetwork: typeof o (" + typeof o + ") confused me.");
 
355
            return false;
 
356
    }
 
357
 
 
358
    if (client.network != oldnetwork)
 
359
    {
 
360
        client.channel = (void 0);
 
361
        client.user = (void 0);
 
362
        client.cuser = (void 0);
 
363
    }
 
364
 
 
365
    var props = document.getElementById ("txtProperties");
 
366
    props.value = "network: " + client.network.name + "\n" +
 
367
        dumpObjectTree (client.network, 1) +
 
368
        "\n============\nclient object:\n" + dumpObjectTree (client, 1);
 
369
    updateStatus();
 
370
 
 
371
}
 
372
 
 
373
function setCurrentUser (o)
 
374
{
 
375
    switch (typeof o)
 
376
    {
 
377
        case "object":
 
378
            client.user = o;
 
379
            break;
 
380
 
 
381
        case "string":
 
382
            if (!client.network.primServ)
 
383
                return false;
 
384
            
 
385
            var v = client.network.primServ.users[o];
 
386
            if (v)
 
387
                client.user = v;
 
388
            break;
 
389
 
 
390
        default:
 
391
            return false;
 
392
    }
 
393
 
 
394
    var props = document.getElementById ("txtProperties");
 
395
    props.value = "network user: " + client.user.nick + "\n" +
 
396
        dumpObjectTree (client.user, 1) +
 
397
        "\n============\nclient object:\n" + dumpObjectTree (client, 1);
 
398
    updateStatus();
 
399
    
 
400
}
 
401
 
 
402
function setCurrentChannel (o)
 
403
{
 
404
    var oldchannel = client.channel;
 
405
    
 
406
    switch (typeof o)
 
407
    {
 
408
        case "object":
 
409
            client.channel = o;
 
410
            break;
 
411
 
 
412
        case "string":
 
413
            if (!client.network.primServ)
 
414
                return false;
 
415
            
 
416
            var v = client.network.primServ.channels[o];
 
417
            if (v)
 
418
                client.channel = v;
 
419
            break;
 
420
 
 
421
        default:
 
422
            return false;
 
423
    }
 
424
 
 
425
    if (client.channel != oldchannel)
 
426
        client.cuser = (void 0);
 
427
    
 
428
    var props = document.getElementById ("txtProperties");
 
429
    props.value = "channel: " + client.channel.name + "\n" +
 
430
        dumpObjectTree (client.channel, 1) +
 
431
        "\n============\nclient object:\n" + dumpObjectTree (client, 1);
 
432
    updateStatus();
 
433
    
 
434
}
 
435
function setCurrentCUser (o)
 
436
{
 
437
    switch (typeof o)
 
438
    {
 
439
        case "object":
 
440
            client.cuser = o;
 
441
            break;
 
442
 
 
443
        case "string":
 
444
            if (!client.channel)
 
445
                return false;
 
446
            
 
447
            var v = client.channel.users[o];
 
448
            if (v)
 
449
                client.cuser = v;
 
450
            break;
 
451
 
 
452
        default:
 
453
            return false;
 
454
    }
 
455
 
 
456
    setCurrentUser (o.__proto__);
 
457
    var props = document.getElementById ("txtProperties");
 
458
    props.value = "channel user: " + client.cuser.nick + "\n" +
 
459
        dumpObjectTree (client.cuser, 1) +
 
460
        "\n============\nclient object:\n" + dumpObjectTree (client, 1);
 
461
    updateStatus();
 
462
    
 
463
}