2
Copyright (c) 2006 by Olivier Goffart <ogoffart at kde.org>
4
Kopete (c) 2006 by the Kopete developers <kopete-devel@kde.org>
6
*************************************************************************
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
*************************************************************************
16
#include "jabberbookmarks.h"
17
#include "jabberaccount.h"
19
#include <kopetecontact.h>
24
#include <kselectaction.h>
28
#include "tasks/jt_privatestorage.h"
31
JabberBookmarks::JabberBookmarks(JabberAccount *parent) : QObject(parent) , m_account(parent)
33
connect( m_account , SIGNAL( isConnectedChanged() ) , this , SLOT( accountConnected() ) );
36
void JabberBookmarks::accountConnected()
38
if(!m_account->isConnected())
41
JT_PrivateStorage * task = new JT_PrivateStorage ( m_account->client()->rootTask ());
42
task->get( "storage" , "storage:bookmarks" );
43
QObject::connect ( task, SIGNAL ( finished () ), this, SLOT ( slotReceivedBookmarks() ) );
47
void JabberBookmarks::slotReceivedBookmarks( )
49
JT_PrivateStorage * task = (JT_PrivateStorage*)(sender());
50
m_storage=QDomDocument("storage");
51
m_conferencesJID.clear();
54
QDomElement storage_e=task->element();
55
if(!storage_e.isNull() && storage_e.tagName() == "storage")
57
storage_e=m_storage.importNode(storage_e,true).toElement();
58
m_storage.appendChild(storage_e);
60
for(QDomNode n = storage_e.firstChild(); !n.isNull(); n = n.nextSibling())
62
QDomElement i = n.toElement();
65
if(i.tagName() == "conference")
67
QString jid=i.attribute("jid");
69
for(QDomNode n = i.firstChild(); !n.isNull(); n = n.nextSibling()) {
70
QDomElement e = n.toElement();
73
else if(e.tagName() == "nick")
75
else if(e.tagName() == "password")
79
m_conferencesJID += jid;
80
if(i.attribute("autojoin") == "true")
83
QString nick=x_jid.resource();
85
nick=m_account->myself()->nickName();
87
if(password.isEmpty())
88
m_account->client()->joinGroupChat(x_jid.host() , x_jid.user() , nick );
90
m_account->client()->joinGroupChat(x_jid.host() , x_jid.user() , nick , password);
99
void JabberBookmarks::insertGroupChat(const XMPP::Jid &jid)
101
if(m_conferencesJID.contains(jid.full()) || !m_account->isConnected())
106
QDomElement storage_e=m_storage.documentElement();
107
if(storage_e.isNull())
109
storage_e=m_storage.createElement("storage");
110
m_storage.appendChild(storage_e);
111
storage_e.setAttribute("xmlns","storage:bookmarks");
114
QDomElement conference=m_storage.createElement("conference");
115
storage_e.appendChild(conference);
116
conference.setAttribute("jid",jid.userHost());
117
QDomElement nick=m_storage.createElement("nick");
118
conference.appendChild(nick);
119
nick.appendChild(m_storage.createTextNode(jid.resource()));
120
QDomElement name=m_storage.createElement("name");
121
conference.appendChild(name);
122
name.appendChild(m_storage.createTextNode(jid.full()));
124
JT_PrivateStorage * task = new JT_PrivateStorage ( m_account->client()->rootTask ());
125
task->set( storage_e );
128
m_conferencesJID += jid.full();
131
KAction * JabberBookmarks::bookmarksAction(QObject * /*parent*/)
133
KSelectAction *groupchatBM = new KSelectAction( this );
134
groupchatBM->setIcon( KIcon("jabber_group") );
135
groupchatBM->setText( i18n("Groupchat bookmark") );
136
groupchatBM->setItems(m_conferencesJID);
137
QObject::connect(groupchatBM, SIGNAL(triggered(const QString&)) , this , SLOT(slotJoinChatBookmark(const QString&)));
141
void JabberBookmarks::slotJoinChatBookmark( const QString & _jid )
143
if(!m_account->isConnected())
146
m_account->client()->joinGroupChat( jid.host() , jid.user() , jid.resource() );
149
#include "jabberbookmarks.moc"