[prev in list] [next in list] [prev in thread] [next in thread]
List: kopete-devel
Subject: [kopete-devel] jabber MUC improvements
From: cedric <cedric.borgese () gmail ! com>
Date: 2006-01-16 20:53:19
Message-ID: 200601172201.35344.cedric.borgese () gmail ! com
[Download RAW message or body]
Hello kopete devs,I'm a user of KDE and since I really like kopete but I didn't find \
some feature that I want in it, I decided to contribute.So, I enable the ability to \
parse jabber chatrooms and to join room protected with password.I paste my patch \
after, please say me if it's ok to include it in kopete 0.12 (I saw that the feature \
freeze is soon.) Thank you for the great instant messaging tool that kopete is :)
Index: protocols/jabber/libiris/iris/include/im.h===================================================================--- \
protocols/jabber/libiris/iris/include/im.h (rà ©vision 498969)+++ \
protocols/jabber/libiris/iris/include/im.h (copie de travail)@@ -607,6 +607,7 @@ \
FileTransferManager *fileTransferManager() const; bool groupChatJoin(const QString \
&host, const QString &room, const QString &nick);+ bool groupChatJoin(const QString \
&host, const QString &room, const QString &nick, const QString &password); void \
groupChatSetStatus(const QString &host, const QString &room, const Status &); void \
groupChatChangeNick(const QString &host, const QString &room, const QString &nick, \
const Status &); void groupChatLeave(const QString &host, const QString \
&room);Index: protocols/jabber/libiris/iris/xmpp-im/client.cpp===================================================================--- \
protocols/jabber/libiris/iris/xmpp-im/client.cpp (rà ©vision 498969)+++ \
protocols/jabber/libiris/iris/xmpp-im/client.cpp (copie de travail)@@ -315,6 +315,35 \
@@ return true; } +bool Client::groupChatJoin(const QString &host, const QString \
&room, const QString &nick, const QString &password)+{+ Jid jid(room + "@" + host + \
"/" + nick);+ for(QValueList<GroupChat>::Iterator it = d->groupChatList.begin(); it \
!= d->groupChatList.end();) {+ GroupChat &i = *it;+ if(i.j.compare(jid, false)) \
{+ // if this room is shutting down, then free it up+ if(i.status == \
GroupChat::Closing)+ it = d->groupChatList.remove(it);+ else+ return \
false;+ }+ else+ ++it;+ }++ debug(QString("Client: Joined: \
[%1]\n").arg(jid.full()));+ GroupChat i;+ i.j = jid;+ i.status = \
GroupChat::Connecting;+ d->groupChatList += i;++ JT_MucPresence *j = new \
JT_MucPresence(rootTask());+ j->pres(jid, Status(), password);+ j->go(true);++ return \
true;+}+ void Client::groupChatSetStatus(const QString &host, const QString &room, \
const Status &_s) { Jid jid(room + "@" + host);Index: \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.h===================================================================--- \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.h (rà ©vision 498969)+++ \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.h (copie de travail)@@ -439,6 \
+439,27 @@ class Private; Private *d; };++ class JT_MucPresence : public \
Task+ {+ Q_OBJECT+ public:+ JT_MucPresence(Task \
*parent);+ ~JT_MucPresence();++ void pres(const Status &);+ void pres(const Jid &, \
const Status &, const QString &password);+ void sub(const Jid &, const QString \
&subType);++ void onGo();++ private:+ QDomElement tag;+ int type;++ class \
Private;+ Private *d;+ }; } #endifIndex: \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.cpp===================================================================--- \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.cpp (rà ©vision 498969)+++ \
protocols/jabber/libiris/iris/xmpp-im/xmpp_tasks.cpp (copie de travail)@@ -1956,3 \
+1956,84 @@ return true; } \
+//----------------------------------------------------------------------------+// \
JT_MucPresence+//----------------------------------------------------------------------------+JT_MucPresence::JT_MucPresence(Task \
*parent)+:Task(parent)+{+ type = -1;+}++JT_MucPresence::~JT_MucPresence()+{+}++void \
JT_MucPresence::pres(const Status &s)+{+ type = 0;++ tag = \
doc()->createElement("presence");+ if(!s.isAvailable()) {+ tag.setAttribute("type", \
"unavailable");+ if(!s.status().isEmpty())+ tag.appendChild(textTag(doc(), \
"status", s.status()));+ }+ else {+ if(s.isInvisible())+ tag.setAttribute("type", \
"invisible");++ if(!s.show().isEmpty())+ tag.appendChild(textTag(doc(), "show", \
s.show()));+ if(!s.status().isEmpty())+ tag.appendChild(textTag(doc(), "status", \
s.status()));++ tag.appendChild( textTag(doc(), "priority", \
QString("%1").arg(s.priority()) ) );++ if(!s.keyID().isEmpty()) {+ QDomElement x = \
textTag(doc(), "x", s.keyID());+ x.setAttribute("xmlns", \
"http://jabber.org/protocol/e2e");+ tag.appendChild(x);+ }+ if(!s.xsigned().isEmpty()) \
{+ QDomElement x = textTag(doc(), "x", s.xsigned());+ x.setAttribute("xmlns", \
"jabber:x:signed");+ tag.appendChild(x);+ }++ if(!s.capsNode().isEmpty() && \
!s.capsVersion().isEmpty()) {+ QDomElement c = \
doc()->createElement("c");+ c.setAttribute("xmlns","http://jabber.org/protocol/caps" \
);+ c.setAttribute("node",s.capsNode());+ c.setAttribute("ver",s.capsVersion());+ if \
(!s.capsExt().isEmpty()) \
+ c.setAttribute("ext",s.capsExt());+ tag.appendChild(c);+ }+ }+}++void \
JT_MucPresence::pres(const Jid &to, const Status &s, const QString \
&password)+{+ pres(s);+ tag.setAttribute("to", to.full());+ QDomElement x = \
textTag(doc(), "x", s.xsigned());+ x.setAttribute("xmlns", \
"http://jabber.org/protocol/muc");+ x.appendChild( textTag(doc(), "password", \
password.latin1()) );+ tag.appendChild(x);+}++void JT_MucPresence::sub(const Jid &to, \
const QString &subType)+{+ type = 1;++ tag = \
doc()->createElement("presence");+ tag.setAttribute("to", \
to.full());+ tag.setAttribute("type", subType);+}++void \
JT_MucPresence::onGo()+{+ send(tag);+ setSuccess();+}Index: \
protocols/jabber/jabberclient.h===================================================================--- \
protocols/jabber/jabberclient.h (rà ©vision 498969)+++ \
protocols/jabber/jabberclient.h (copie de travail)@@ -68,7 +68,11 @@ Ok, /** No \
error. */ InvalidPassword, /** Password used to connect to the server was \
incorrect. */ AlreadyConnected, /** A new connection was attempted while the \
previous one hasn't been closed. */- NoTLS /** Use of TLS has been forced (see \
@ref forceTLS) but TLS is not available, either server- or client-side. \
*/+ NoTLS, /** Use of TLS has been forced (see @ref forceTLS) but TLS is not \
available, either server- or client-side. */+ InvalidPasswordForMUC = 401, /** A \
password is require to enter on this Multi-User Chat */+ NicknameConflict = \
409, /** There is already someone with that nick connected to the Multi-User Chat \
*/+ BannedFromThisMUC = 403, /** You can't join this Multi-User Chat because you \
were bannished */+ MaxUsersReachedForThisMuc = 503 /** You can't join this \
Multi-User Chat because it is full */ }; JabberClient();@@ -356,6 +360,15 @@ void \
joinGroupChat ( const QString &host, const QString &room, const QString &nick ); \
/**+ * Join a group chat that require a password.+ * @param host Node to join the \
room at.+ * @param room Name of room to join.+ * @param nick Nick name you want to \
join with.+ * @param password The password to join the room.+ */+ void \
joinGroupChat ( const QString &host, const QString &room, const QString &nick, const \
QString &password );++ /** * Leave a group chat. * @param host Node to leave room \
at. * @param room Name of room to leave.Index: \
protocols/jabber/jabberaccount.cpp===================================================================--- \
protocols/jabber/jabberaccount.cpp (rà ©vision 498969)+++ \
protocols/jabber/jabberaccount.cpp (copie de travail)@@ -43,6 +43,8 @@ #include \
<kapplication.h> #include <kaboutdata.h> #include <ksocketbase.h>+#include \
<kpassdlg.h>+#include <kinputdialog.h> #include "kopetepassword.h" #include \
"kopeteawayaction.h"@@ -1472,12 +1474,55 @@ { kdDebug (JABBER_DEBUG_GLOBAL) << \
k_funcinfo << "Group chat error - room " << jid.full () << " had error " << error << \
" (" << reason << ")" << endl; - QString detailedReason = reason.isEmpty () ? i18n ( \
"No reason given by the server" ) : reason;+ switch (error)+ {+ case \
JabberClient::InvalidPasswordForMUC:+ {+ QCString password;+ int result = \
KPasswordDialog::getPassword(password, i18n("A password is required to join the room \
%1.").arg(jid.node()));+ if (result == \
KPasswordDialog::Accepted)+ m_jabberClient->joinGroupChat(jid.domain(), \
jid.node(), jid.resource(), password);+ }+ break; - KMessageBox::queuedMessageBox ( \
Kopete::UI::Global::mainWidget (),+ case JabberClient::NicknameConflict:+ {+ bool \
ok;+ QString nickname = KInputDialog::getText(i18n("Error trying to join %1 : \
nickname %2 is already in use").arg(jid.node(), jid.resource()),+ i18n("Give \
your nickname"),+ QString(),+ &ok);+ if \
(ok)+ {+ m_jabberClient->joinGroupChat(jid.domain(), jid.node(), \
nickname);+ }+ }+ break;++ case \
JabberClient::BannedFromThisMUC:+ KMessageBox::queuedMessageBox ( \
Kopete::UI::Global::mainWidget (), KMessageBox::Error,+ i18n ("You \
can't join the room %1 because you were banned").arg(jid.node()),+ i18n \
("Jabber Group Chat") );+ break;++ case \
JabberClient::MaxUsersReachedForThisMuc:+ KMessageBox::queuedMessageBox ( \
Kopete::UI::Global::mainWidget (),+ KMessageBox::Error,+ i18n ("You \
can't join the room %1 because the maximum users has been \
reached").arg(jid.node()),+ i18n ("Jabber Group Chat") \
);+ break;++ default:+ {+ QString detailedReason = reason.isEmpty () ? i18n ( "No \
reason given by the server" ) : reason;++ KMessageBox::queuedMessageBox ( \
Kopete::UI::Global::mainWidget (),+ KMessageBox::Error, i18n ("There \
was an error processing your request for group chat %1. (Reason: %2, Code %3)").arg ( \
jid.full (), detailedReason, QString::number ( error ) ), i18n ("Jabber \
Group Chat") );+ }+ } } void JabberAccount::slotResourceAvailable (const XMPP::Jid \
& jid, const XMPP::Resource & resource)Index: \
protocols/jabber/jabberclient.cpp===================================================================--- \
protocols/jabber/jabberclient.cpp (rà ©vision 498969)+++ \
protocols/jabber/jabberclient.cpp (copie de travail)@@ -809,6 +809,13 @@ } +void \
JabberClient::joinGroupChat ( const QString &host, const QString &room, const QString \
&nick, const QString &password )+{++ client()->groupChatJoin ( host, room, nick, \
password );++}+ void JabberClient::leaveGroupChat ( const QString &host, const \
QString &room ) { Index: \
protocols/jabber/ui/dlgjabberchatjoin.h===================================================================--- \
protocols/jabber/ui/dlgjabberchatjoin.h (rà ©vision 498969)+++ \
protocols/jabber/ui/dlgjabberchatjoin.h (copie de travail)@@ -19,28 +19,48 @@ #ifndef \
DLGJABBERCHATJOIN_H #define DLGJABBERCHATJOIN_H -#include <kdialogbase.h>+#include \
"dlgchatjoin.h" #include "jabberaccount.h" -/**- *@author Till Gerken \
<till@tantalo.net>- */--class dlgJabberChatJoin : public KDialogBase+class \
dlgJabberChatJoin : public dlgChatJoin {+ Q_OBJECT - Q_OBJECT- public:- \
dlgJabberChatJoin (JabberAccount *account, QWidget * parent = 0, const char *name = \
0);+ dlgJabberChatJoin(JabberAccount *account, QWidget* parent = 0, const char* name \
= 0);+ ~dlgJabberChatJoin();+ /*$PUBLIC_FUNCTIONS$*/ -private slots:- void slotOk \
();- void slotCancel ();+public slots:+ /*$PUBLIC_SLOTS$*/+ virtual void \
slotJoin();+ virtual void slotBowse(); +protected:+ \
/*$PROTECTED_FUNCTIONS$*/++protected slots:+ /*$PROTECTED_SLOTS$*/+ private:+ + \
JabberAccount *m_account;+ QString m_chatroomsServer; + /*+ TODO : Used to look for \
the default chat server,+ this is duplicate with dlgjabberservices.h+ should be \
merged elsewhere !+ */+ void checkDefaultChatroomServer();+private slots:+ void \
slotQueryFinished();+ void slotDiscoFinished();++ // end todo.+ }; #endif+Index: \
protocols/jabber/ui/dlgjabberchatjoin.cpp===================================================================--- \
protocols/jabber/ui/dlgjabberchatjoin.cpp (rà ©vision 498969)+++ \
protocols/jabber/ui/dlgjabberchatjoin.cpp (copie de travail)@@ -16,53 +16,104 @@ * \
* ***************************************************************************/ \
-#include "dlgjabberchatjoin.h"- #include <kdebug.h> #include <klocale.h>-#include \
<kdialogbase.h> #include <qlineedit.h>+#include <qpushbutton.h> #include \
"jabberaccount.h" #include "jabberclient.h"+#include "dlgjabberchatroomslist.h" \
-#include "dlgchatjoin.h"+#include "dlgjabberchatjoin.h" \
-dlgJabberChatJoin::dlgJabberChatJoin (JabberAccount *account, QWidget * parent, \
const char *name)- : KDialogBase (parent, name, false,- \
i18n("Join Jabber Groupchat"),- KDialogBase::Ok | \
KDialogBase::Cancel)+dlgJabberChatJoin::dlgJabberChatJoin(JabberAccount *account, \
QWidget* parent, const char* name) :+dlgChatJoin(parent, name),+m_account(account) \
{+ setCaption(i18n("Join Jabber \
Groupchat"));+ leNick->setText(m_account->client()->client()->user());+ checkDefaultChatroomServer();+} \
- m_account = account;+dlgJabberChatJoin::~dlgJabberChatJoin()+{+} - setMainWidget ( \
new dlgChatJoin ( this ) );+/*$SPECIALIZATION$*/+void \
dlgJabberChatJoin::slotJoin()+{+ if(!m_account->isConnected())+ {+ m_account->errorConnectFirst();+ return;+ } \
+ m_account->client()->joinGroupChat(leServer->text(), leRoom->text(), \
leNick->text());+ accept(); } -void dlgJabberChatJoin::slotOk ()+void \
dlgJabberChatJoin::slotBowse() {- if(!m_account->isConnected()) { \
m_account->errorConnectFirst(); return; } - dlgChatJoin *widget = \
dynamic_cast<dlgChatJoin *>(mainWidget ());+ dlgJabberChatRoomsList *crl = new \
dlgJabberChatRoomsList(*m_account, m_chatroomsServer);+ crl->show();+ accept();+} \
- // send the join request- m_account->client()->joinGroupChat ( \
widget->leServer->text (), widget->leRoom->text (), widget->leNick->text () \
);+/*+ TODO : Used to look for the default chat server,+ this is duplicate with \
dlgjabberservices.cpp+ should be merged elsewhere !+*/+// JabberAccount \
*m_account;+// XMPP::JT_GetServices * serviceTask; - delete this;+void \
dlgJabberChatJoin::checkDefaultChatroomServer()+{+ XMPP::JT_GetServices *serviceTask \
= new XMPP::JT_GetServices(m_account->client()->rootTask());+ connect(serviceTask, \
SIGNAL (finished()), this, SLOT (slotQueryFinished())); \
+ serviceTask->get(m_account->server());+ serviceTask->go(true); } -void \
dlgJabberChatJoin::slotCancel ()+void dlgJabberChatJoin::slotQueryFinished() \
{+ XMPP::JT_GetServices *task = (XMPP::JT_GetServices*)sender();+ if (!task->success \
())+ return; - delete this;+ for (XMPP::AgentList::const_iterator it = \
task->agents().begin(); it != task->agents().end(); ++it)+ {+ XMPP::JT_DiscoInfo \
*discoTask = new XMPP::JT_DiscoInfo(m_account->client()->rootTask());+ connect(discoTask, \
SIGNAL (finished()), this, SLOT (slotDiscoFinished())); \
+ discoTask->get((*it).jid().full());+ discoTask->go(true);+ } } +void \
dlgJabberChatJoin::slotDiscoFinished()+{+ XMPP::JT_DiscoInfo *task = \
(XMPP::JT_DiscoInfo*)sender();++ if (!task->success())+ return;++ if \
(task->item().features().canGroupchat() && \
!task->item().features().isGateway())+ {+ m_chatroomsServer = \
task->item().jid().full();+ leServer->setText(m_chatroomsServer);+ }+}++// end todo+ \
#include "dlgjabberchatjoin.moc"+Index: \
protocols/jabber/ui/dlgchatjoin.ui===================================================================--- \
protocols/jabber/ui/dlgchatjoin.ui (rà ©vision 498969)+++ \
protocols/jabber/ui/dlgchatjoin.ui (copie de travail)@@ -1,6 +1,6 @@-<!DOCTYPE UI><UI \
version="3.2" stdsetdef="1">+<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> \
<class>dlgChatJoin</class>-<widget class="QWidget">+<widget class="KDialog"> \
<property name="name"> <cstring>dlgChatJoin</cstring> </property>@@ -8,69 \
+8,132 @@ <rect> <x>0</x> <y>0</y>- \
<width>290</width>- <height>122</height>+ <width>291</width>+ \
<height>160</height> </rect> </property>+ <property name="caption">+ \
<string>dlgChatJoin</string>+ </property> <grid> <property \
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic