[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qsos-commits] qsos/apps/xuleditor/chrome/content editor.js ed...
From: |
Raphaël Semeteys |
Subject: |
[Qsos-commits] qsos/apps/xuleditor/chrome/content editor.js ed... |
Date: |
Sat, 24 Feb 2007 23:02:37 +0000 |
CVSROOT: /sources/qsos
Module name: qsos
Changes by: Raphaël Semeteys <rsemeteys> 07/02/24 23:02:37
Modified files:
apps/xuleditor/chrome/content: editor.js editor.xul
Log message:
Chat management
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/editor.js?cvsroot=qsos&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/qsos/apps/xuleditor/chrome/content/editor.xul?cvsroot=qsos&r1=1.18&r2=1.19
Patches:
Index: editor.js
===================================================================
RCS file: /sources/qsos/qsos/apps/xuleditor/chrome/content/editor.js,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- editor.js 15 Feb 2007 17:24:32 -0000 1.19
+++ editor.js 24 Feb 2007 23:02:37 -0000 1.20
@@ -21,6 +21,8 @@
** QSOS XUL Editor
** editor.js: functions associated with the editor.xul file
**
+** TODO:
+** - Chat: find a way to colorize text in "conversation" textbox
*/
//Object "Document" representing data in the QSOS XML file
@@ -32,9 +34,10 @@
//Localized strings bundle
var strbundle;
-//XMPP account init
-var account = { jid: undefined };
+//Chat variables
+var nick;
var chatroom;
+var con;
//Window initialization after loading
function init() {
@@ -53,47 +56,178 @@
if (url) {
openRemoteFile(url)
}
+}
- //Chat stuff (using xmpp4moz extension)
+////////////////////////////////////////////////////////////////////
+// Chat event functions
+////////////////////////////////////////////////////////////////////
- channel = XMPP.createChannel(
- <query xmlns="http://jabber.org/protocol/disco#info">
- <feature var="http://jabber.org/protocol/muc"/>
- <feature var="http://jabber.org/protocol/muc#user"/>
- <feature var='http://jabber.org/protocol/xhtml-im'/>
- </query>);
-
- channel.on(
- {event: 'message'},
- function(message) {
+//Initializes chat session
+function startChat() {
+ var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
+ .getService(Components.interfaces.nsIPrefBranch);
+ chatroom = prefManager.getCharPref("extensions.qsos-xuled.chatroom");
+ nick = prefManager.getCharPref("extensions.qsos-xuled.nick", "_");
+ if (nick == "_") {
+ //If nickname is not stored in preferences, ask for it and store it
+ nick = window.prompt(strbundle.getString("nick"));
+ prefManager.setCharPref("extensions.qsos-xuled.nick", nick);
+ }
+ document.getElementById("chat-start").setAttribute("disabled", "true");
+ doLogin();
+}
+
+function htmlEnc(str) {
+ str = str.replace(/&/g,"&");
+ str = str.replace(/</g,"<");
+ str = str.replace(/>/g,">");
+ str = str.replace(/\"/g,""");
+ str = str.replace(/\n/g,"<br />");
+ return str;
+}
+
+//Returns nickname from user's JID
+function getUserNick(jid) {
+ var splitted_jid = jid.split("/");
+ if (splitted_jid.length > 1) {
+ return splitted_jid[1];
+ } else {
+ return "Chatroom";
+ }
+}
+
+//Put the selected nick in input field
+function talkToUser() {
+ var listbox = document.getElementById('roster');
+ var inputText = document.getElementById('input');
+ if (listbox.selectedItem) {
+ inputText.value += listbox.selectedItem.getAttribute('id').substring(1) +
" ";
+ }
+}
+
+//JSJaC IQ event handler (debug)
+//Remoce the hidden attribute in "err" textbox in editor.xul file to visualize
messages
+function handleEvent(aJSJaCPacket) {
+ document.getElementById('err').value +=
+ "IN (raw): " + aJSJaCPacket.xml() + '\n';
+}
+
+//JSJaC message handler
+function handleMessage(aJSJaCPacket) {
var conversation = document.getElementById('conversation');
- conversation.value +=
- (message.direction == 'out' ? 'Me' : address@hidden) + ' : ' +
- message.stanza.body + '\n';
+ conversation.value += getUserNick(aJSJaCPacket.getFrom())+': ' +
aJSJaCPacket.getBody() + '\n';
conversation.inputField.scrollTop =
conversation.inputField.scrollHeight - conversation.inputField.clientHeight;
- });
+}
+
+//JSJaC presence handler
+function handlePresence(aJSJaCPacket) {
+ var item = ''; //Text to be inserted in roster
+ if (!aJSJaCPacket.getType() && !aJSJaCPacket.getShow()) {
+ item += getUserNick(aJSJaCPacket.getFrom())+' (available';
+ } else {
+ item += getUserNick(aJSJaCPacket.getFrom())+' (';
+ if (aJSJaCPacket.getType()) {
+ item += aJSJaCPacket.getType();
+ } else {
+ item += aJSJaCPacket.getShow();
+ }
+ if (aJSJaCPacket.getStatus()) {
+ item += ' '+htmlEnc(aJSJaCPacket.getStatus());
+ }
+ }
+ item += ')';
- XMPP.cache.presenceIn.forEach(receivedPresence);
+ var lid = '_'+getUserNick(aJSJaCPacket.getFrom());
+ var listbox = document.getElementById('roster');
+ var entry = document.getElementById(lid);
- var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- chatroom = prefManager.getCharPref("extensions.qsos-xuled.chatroom");
+ if (entry) {
+ //if nick already in roster, update it
+ entry.setAttribute('label', item);
+ } else {
+ //or create a new entry
+ var listitem = document.createElement('listitem');
+ listitem.setAttribute('label', item);
+ listitem.setAttribute('id', lid);
+ listbox.appendChild(listitem);
+ }
+}
+
+//JSJaC connection handler
+function handleConnected() {
+ //Must send special Presence message before entering the chatroom
+ var aPresence = new JSJaCPresence();
+ aPresence.setTo(chatroom + '/' + nick);
+ aPresence.setFrom('address@hidden');
- XMPP.send(account,
- <presence to={chatroom + '/address@hidden'}>
- <x xmlns='http://jabber.org/protocol/muc'/>
- </presence>);
+ var x = aPresence.getDoc().createElement('x');
+ x.setAttribute('xmlns','http://jabber.org/protocol/muc');
+ aPresence.getNode().appendChild(x);
+ con.send(aPresence);
}
-//Callback function for presence notification
-function receivedPresence(presence) {
- document.getElementById("roster").value += address@hidden + '\n';
+//JSJaC error handler (debug)
+//Remoce the hidden attribute in "err" textbox in editor.xul file to visualize
messages
+function handleError(e) {
+ document.getElementById('err').value = "An error occured: Code: " +
e.getAttribute('code') + "\nType:" + e.getAttribute('type') + "\nCondition: " +
e.firstChild.nodeName;
+}
+
+//JSJaC status change handler (TODO)
+function handleStatusChange(status) {
+}
+
+//Connects user to groupchat
+function doLogin() {
+ try {
+ //Setup args for contructor
+ oArgs = new Object();
+ oArgs.httpbase = 'http://88.191.44.3/chat/http-poll/';
+ oArgs.timerval = 2000;
+
+ //Events handlers
+ con = new JSJaCHttpPollingConnection(oArgs);
+ con.registerHandler('message',handleMessage);
+ con.registerHandler('presence',handlePresence);
+ con.registerHandler('iq',handleEvent);
+ con.registerHandler('onconnect',handleConnected);
+ con.registerHandler('onerror',handleError);
+ con.registerHandler('status_changed',handleStatusChange);
+
+ //Setup args for connect method
+ oArgs = new Object();
+ oArgs.domain = 'garous.org';
+ oArgs.username = 'muckl';
+ oArgs.resource = 'xuleditor';
+ oArgs.pass = 'muckl';
+ //oArgs.register = false;
+ con.connect(oArgs);
+
+ } catch (e) {
+ document.getElementById('err').value = e.toString();
+ } finally {
+ return false;
+ }
+}
+
+//Sends content of "input" textbox to the groupchat
+function sendMsg() {
+ var msg = document.getElementById('input').value;
+ if (msg == '') return false;
+
+ var aMsg = new JSJaCMessage();
+ aMsg.setType('groupchat');
+ aMsg.setTo(chatroom);
+ aMsg.setBody(msg);
+ con.send(aMsg);
+
+ document.getElementById('input').value = '';
+
+ return false;
}
-//Callback function for message sending
-function send() {
- var input = document.getElementById('input').value;
- XMPP.send(account, <message to={chatroom}
type='groupchat'><body>{input}</body></message>);
+function quit() {
+ if (con && con.connected())
+ con.disconnect();
}
////////////////////////////////////////////////////////////////////
Index: editor.xul
===================================================================
RCS file: /sources/qsos/qsos/apps/xuleditor/chrome/content/editor.xul,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- editor.xul 15 Feb 2007 17:24:32 -0000 1.18
+++ editor.xul 24 Feb 2007 23:02:37 -0000 1.19
@@ -4,10 +4,17 @@
<!DOCTYPE window SYSTEM "chrome://qsos-xuled/locale/editor.dtd">
<window id="QSOS" title="&QSOS.label;" width="800px" height="600px"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+
onload="init();">
+ <script type="application/x-javascript" src="jsjac/xmlextras.js"></script>
+ <script type="application/x-javascript" src="jsjac/JSJaCPacket.js"></script>
+ <script type="application/x-javascript" src="jsjac/crypt.js"></script>
+ <script type="application/x-javascript" src="jsjac/json.js"></script>
+ <script type="application/x-javascript" src="jsjac/qm_cookie.js"></script>
+ <script type="application/x-javascript"
src="jsjac/JSJaCConnection.js"></script>
+ <script type="application/x-javascript"
src="jsjac/JSJaCHttpPollingConnection.js"></script>
<script type="application/x-javascript" src="Document.js"></script>
<script type="application/x-javascript" src="editor.js"></script>
- <script type="application/x-javascript"
src="chrome://xmpp4moz/content/xmpp.js"/>
<stringbundle id="properties"
src="chrome://qsos-xuled/locale/editor.properties"/>
<vbox>
<toolbox>
@@ -31,6 +38,11 @@
<menuitem id="tree-collapse" label="&tree-collapse.label;"
onclick="expandTree('false');"/>
</menupopup>
</menu>
+ <menu id="chat-menu" label="&chat-menu.label;"
onclick="document.getElementById('chat-menu').focus();">
+ <menupopup id="chat-popup">
+ <menuitem id="chat-start" label="&chat-start.label;"
onclick="startChat();"/>
+ </menupopup>
+ </menu>
<menu id="help-menu" label="&help-menu.label;"
onclick="document.getElementById('help-menu').focus();">
<menupopup id="help-popup">
<menuitem id="help-about" label="&help-about.label;"
onclick="aboutDialog();"/>
@@ -44,7 +56,7 @@
<tab id = "t-software" class = "header" label = "&t-header.label;"/>
<tab id = "t-c-title" class = "criteria" label = "&t-c-title.label;"/>
<tab id = "t-chart" class = "graph" label = "&t-chart.label;"/>
- <tab id = "t-chat" label = "Chat"/>
+ <tab id = "t-chat" class = "chat" label = "&t-chat.label;"/>
</tabs>
<tabpanels flex = "1">
<tabpanel flex = "1">
@@ -128,24 +140,25 @@
</svg>
</vbox>
</tabpanel>
- <tabpanel flex = "1">
+ <tabpanel id = "chatbox" flex = "1">
<hbox flex = "1">
<vbox flex = "5">
- <label value="Conversation"/>
+ <label value="&chat-conversation;"/>
<textbox id="conversation" multiline="true" rows="20"
readonly="true"/>
- <label value="Say something" control="input" accesskey="a"/>
+ <label value="&chat-input;" control="input"/>
<textbox id="input" multiline="true" rows="2"/>
+ <textbox id="err" multiline="true" rows="2" hidden="true"/>
<hbox>
<spacer flex="1"/>
- <button label="Send!" oncommand="send();" accesskey="S"/>
+ <button label="&chat-send;" oncommand="sendMsg();"/>
<spacer flex="1"/>
</hbox>
</vbox>
</hbox>
<splitter/>
<vbox>
- <label value="Participants"/>
- <textbox id="roster" multiline="true" flex="1" readonly="true"/>
+ <label value="&chat-roster;"/>
+ <listbox id="roster" flex="1" readonly="true"
onselect="talkToUser();"/>
</vbox>
</tabpanel>
</tabpanels>