diff options
| author | Niels Ole Salscheider <niels_ole@salscheider-online.de> | 2017-09-04 13:53:43 +0200 |
|---|---|---|
| committer | Niels Ole Salscheider <niels_ole@salscheider-online.de> | 2017-09-04 20:16:31 +0200 |
| commit | 638deefa227d89d4d4d803c2f0f66e2ca7bc3777 (patch) | |
| tree | 8166eae1385e641ace1905b1e68f5b60a79fb297 /examples | |
| parent | 2a42d04764c8539822b077d8261088bfcaec7fb7 (diff) | |
| download | qxmpp-638deefa227d89d4d4d803c2f0f66e2ca7bc3777.tar.gz | |
Remove example_4 and GuiClient
The build was disabled for some time.
There is still git if we want to bring them back.
Diffstat (limited to 'examples')
69 files changed, 0 insertions, 6639 deletions
diff --git a/examples/GuiClient/GuiClient.pro b/examples/GuiClient/GuiClient.pro deleted file mode 100644 index 60306171..00000000 --- a/examples/GuiClient/GuiClient.pro +++ /dev/null @@ -1,64 +0,0 @@ -include(../examples.pri) - -TARGET = GuiClient -TEMPLATE = app - -SOURCES += main.cpp \ - chatMsgGraphicsItem.cpp \ - chatGraphicsScene.cpp \ - chatGraphicsView.cpp \ - chatDialog.cpp \ - mainDialog.cpp \ - rosterItemModel.cpp \ - rosterItem.cpp \ - rosterItemSortFilterProxyModel.cpp \ - utils.cpp \ - rosterListView.cpp \ - searchLineEdit.cpp \ - statusWidget.cpp \ - signInStatusLabel.cpp \ - statusAvatarWidget.cpp \ - statusTextWidget.cpp \ - statusToolButton.cpp \ - vCardCache.cpp \ - profileDialog.cpp \ - capabilitiesCache.cpp \ - accountsCache.cpp \ - xmlConsoleDialog.cpp \ - aboutDialog.cpp - -HEADERS += chatMsgGraphicsItem.h \ - chatGraphicsScene.h \ - chatGraphicsView.h \ - chatDialog.h \ - mainDialog.h \ - rosterItemModel.h \ - rosterItem.h \ - rosterItemSortFilterProxyModel.h \ - utils.h \ - rosterListView.h \ - searchLineEdit.h \ - statusWidget.h \ - signInStatusLabel.h \ - statusAvatarWidget.h \ - statusTextWidget.h \ - statusToolButton.h \ - vCardCache.h \ - profileDialog.h \ - capabilitiesCache.h \ - accountsCache.h \ - xmlConsoleDialog.h \ - aboutDialog.h - -FORMS += mainDialog.ui \ - chatDialog.ui \ - statusWidget.ui \ - profileDialog.ui \ - xmlConsoleDialog.ui \ - aboutDialog.ui - -QT += network \ - xml \ - widgets - -RESOURCES += resources.qrc diff --git a/examples/GuiClient/aboutDialog.cpp b/examples/GuiClient/aboutDialog.cpp deleted file mode 100644 index 65805a53..00000000 --- a/examples/GuiClient/aboutDialog.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "aboutDialog.h" -#include "ui_aboutDialog.h" - -#include "QXmppGlobal.h" - -#include <QtGlobal> - -aboutDialog::aboutDialog(QWidget *parent) : - QDialog(parent), - ui(new Ui::aboutDialog) -{ - ui->setupUi(this); - - setWindowTitle(QString("About %1").arg(qApp->applicationName())); - - ui->textEdit->append(QString("Copyright (C) 2008-2014 The QXmpp developers\n")); - ui->textEdit->append(qApp->applicationName() + " " + qApp->applicationVersion()); - ui->textEdit->append(QString("\nBased on:")); - ui->textEdit->append(QString("QXmpp %1").arg(QXmppVersion())); - ui->textEdit->append(QString("Qt %1 [built-with]").arg(qVersion())); - ui->textEdit->append(QString("Qt %1 [running-with]").arg(QT_VERSION_STR)); -} - -aboutDialog::~aboutDialog() -{ - delete ui; -} diff --git a/examples/GuiClient/aboutDialog.h b/examples/GuiClient/aboutDialog.h deleted file mode 100644 index 22c765c7..00000000 --- a/examples/GuiClient/aboutDialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ABOUTDIALOG_H -#define ABOUTDIALOG_H - -#include <QDialog> - -namespace Ui { - class aboutDialog; -} - -class aboutDialog : public QDialog -{ - Q_OBJECT - -public: - explicit aboutDialog(QWidget *parent = 0); - ~aboutDialog(); - -private: - Ui::aboutDialog *ui; -}; - -#endif // ABOUTDIALOG_H diff --git a/examples/GuiClient/aboutDialog.ui b/examples/GuiClient/aboutDialog.ui deleted file mode 100644 index 01240819..00000000 --- a/examples/GuiClient/aboutDialog.ui +++ /dev/null @@ -1,71 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>aboutDialog</class> - <widget class="QDialog" name="aboutDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>309</width> - <height>218</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QTextEdit" name="textEdit"> - <property name="readOnly"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>aboutDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>aboutDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/examples/GuiClient/accountsCache.cpp b/examples/GuiClient/accountsCache.cpp deleted file mode 100644 index d13bded5..00000000 --- a/examples/GuiClient/accountsCache.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "accountsCache.h" -#include "utils.h" - -#include <QDir> -#include <QTextStream> -#include <QStringList> - -accountsCache::accountsCache(QObject *parent) : - QObject(parent) -{ -} - -QStringList accountsCache::getBareJids() -{ - QStringList list; - QDomElement element = m_accountsDocument.documentElement().firstChildElement("account"); - while(!element.isNull()) - { - list << element.firstChildElement("bareJid").text(); - element = element.nextSiblingElement("account"); - } - - return list; -} - -QString accountsCache::getPassword(const QString& bareJid) -{ - QDomElement element = m_accountsDocument.documentElement().firstChildElement("account"); - while(!element.isNull()) - { - if(element.firstChildElement("bareJid").text() == bareJid) - { - QByteArray passwdEncryptedBa = QByteArray::fromBase64( - element.firstChildElement("password").text().toUtf8()); - QString passwd = calculateXor(passwdEncryptedBa, bareJid.toUtf8()); - return passwd; - } - element = element.nextSiblingElement("account"); - } - - return ""; -} - -void accountsCache::addAccount(const QString& bareJid, const QString& passwd) -{ - if(m_accountsDocument.documentElement().isNull()) - { - m_accountsDocument.appendChild(m_accountsDocument.createElement("accounts")); - } - - QDomElement element = m_accountsDocument.documentElement().firstChildElement("account"); - while(!element.isNull()) - { - if(element.firstChildElement("bareJid").text() == bareJid) - { - m_accountsDocument.documentElement().removeChild(element); - break; - } - element = element.nextSiblingElement("account"); - } - - QDomElement newElement = m_accountsDocument.createElement("account"); - - QDomElement newElementBareJid = m_accountsDocument.createElement("bareJid"); - newElementBareJid.appendChild(m_accountsDocument.createTextNode(bareJid)); - newElement.appendChild(newElementBareJid); - - QDomElement newElementPasswd = m_accountsDocument.createElement("password"); - newElementPasswd.appendChild(m_accountsDocument.createTextNode( - calculateXor(passwd.toUtf8(), bareJid.toUtf8()).toBase64())); - newElement.appendChild(newElementPasswd); - - m_accountsDocument.documentElement().appendChild(newElement); - - saveToFile(); -} - -void accountsCache::loadFromFile() -{ - QDir dirSettings(getSettingsDir()); - if(dirSettings.exists()) - { - QFile file(getSettingsDir()+ "accounts.xml"); - if(file.open(QIODevice::ReadOnly)) - { - m_accountsDocument.setContent(&file, true); - } - } -} - -void accountsCache::saveToFile() -{ - QDir dir; - if(!dir.exists(getSettingsDir())) - dir.mkpath(getSettingsDir()); - - QString fileAccounts = getSettingsDir() + "accounts.xml"; - QFile file(fileAccounts); - if(file.open(QIODevice::ReadWrite)) - { - QTextStream tstream(&file); - m_accountsDocument.save(tstream, 2); - file.close(); - } -} diff --git a/examples/GuiClient/accountsCache.h b/examples/GuiClient/accountsCache.h deleted file mode 100644 index f3cb1a52..00000000 --- a/examples/GuiClient/accountsCache.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ACCOUNTSCACHE_H -#define ACCOUNTSCACHE_H - -#include <QObject> -#include <QDomElement> - -class QStringList; - -class accountsCache : public QObject -{ - Q_OBJECT - -public: - explicit accountsCache(QObject *parent); - QStringList getBareJids(); - QString getPassword(const QString& bareJid); - - void addAccount(const QString& bareJid, const QString& passwd); - -public: - void loadFromFile(); - -private: - void saveToFile(); - - QDomDocument m_accountsDocument; -}; - -#endif // ACCOUNTSCACHE_H diff --git a/examples/GuiClient/capabilitiesCache.cpp b/examples/GuiClient/capabilitiesCache.cpp deleted file mode 100644 index dd86fca5..00000000 --- a/examples/GuiClient/capabilitiesCache.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "capabilitiesCache.h" -#include "utils.h" - -#include "QXmppClient.h" -#include "QXmppDiscoveryManager.h" - -#include <QCoreApplication> -#include <QXmlStreamWriter> -#include <QDir> - -capabilitiesCache::capabilitiesCache(QXmppClient* client) : - QObject(client), m_client(client) -{ - QXmppDiscoveryManager* ext = m_client->findExtension<QXmppDiscoveryManager>(); - if(ext) - { - bool check = connect(ext, SIGNAL(infoReceived(QXmppDiscoveryIq)), - SLOT(infoReceived(QXmppDiscoveryIq))); - Q_ASSERT(check); - Q_UNUSED(check); - } -} - -bool capabilitiesCache::isCapabilityAvailable(const QString& nodeVer) -{ - return m_mapCapabilities.contains(nodeVer); -} - -void capabilitiesCache::requestInfo(const QString& jid, const QString& node) -{ - QXmppDiscoveryManager* ext = m_client->findExtension<QXmppDiscoveryManager>(); - if(ext) - { - bool alreadyRequested = false; - foreach(QString key, m_mapIdNodeVer.keys()) - { - if(m_mapIdNodeVer[key] == node) - { - alreadyRequested = true; - break; - } - } - - if(!alreadyRequested) - { - QString id = ext->requestInfo(jid, node); - m_mapIdNodeVer[id] = node; - } - } -} - -void capabilitiesCache::infoReceived(const QXmppDiscoveryIq& discoIqRcv) -{ - QXmppDiscoveryIq discoIq = discoIqRcv; - if(discoIq.queryType() == QXmppDiscoveryIq::InfoQuery && - discoIq.type() == QXmppIq::Result) - { - if(discoIq.queryNode().isEmpty()) - { - discoIq.setQueryNode(m_mapIdNodeVer[discoIq.id()]); - m_mapIdNodeVer.remove(discoIq.id()); - } - - discoIq.setTo(""); - discoIq.setFrom(""); - discoIq.setId(""); - m_mapCapabilities[discoIq.queryNode()] = discoIq; - saveToFile(discoIq.queryNode()); - } -} - -void capabilitiesCache::loadFromFile() -{ - m_mapCapabilities.clear(); - - QDir dirCaps(getSettingsDir(m_client->configuration().jidBare())+ "capabilities/"); - if(dirCaps.exists()) - { - QStringList list = dirCaps.entryList(QStringList("*.xml")); - foreach(QString fileName, list) - { - QFile file(getSettingsDir(m_client->configuration().jidBare())+ "capabilities/" + fileName); - if(file.open(QIODevice::ReadOnly)) - { - QDomDocument doc; - if(doc.setContent(&file, true)) - { - QXmppDiscoveryIq discoIq; - discoIq.parse(doc.documentElement()); - m_mapCapabilities[discoIq.queryNode()] = discoIq; - QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - } - } - } - } -} - -void capabilitiesCache::saveToFile(const QString& nodeVer) -{ - if(!m_mapCapabilities.contains(nodeVer)) - return; - - QString fileName = getSha1HashAsHex(nodeVer.toUtf8()); - QDir dir; - if(!dir.exists(getSettingsDir(m_client->configuration().jidBare()))) - dir.mkpath(getSettingsDir(m_client->configuration().jidBare())); - - QDir dir2; - if(!dir2.exists(getSettingsDir(m_client->configuration().jidBare())+ "capabilities/")) - dir2.mkpath(getSettingsDir(m_client->configuration().jidBare())+ "capabilities/"); - - QString fileCapability = getSettingsDir(m_client->configuration().jidBare()) + "capabilities/" + fileName + ".xml"; - QFile file(fileCapability); - - if(file.open(QIODevice::ReadWrite)) - { - QXmlStreamWriter stream(&file); - stream.setAutoFormatting(true); - stream.setAutoFormattingIndent(2); - m_mapCapabilities[nodeVer].toXml(&stream); - file.close(); - } -} - -QStringList capabilitiesCache::getFeatures(const QString& nodeVer) -{ - if(!m_mapCapabilities.contains(nodeVer)) - return QStringList(); - - return m_mapCapabilities[nodeVer].features(); -} - -QStringList capabilitiesCache::getIdentities(const QString& nodeVer) -{ - if(!m_mapCapabilities.contains(nodeVer)) - return QStringList(); - - QStringList idList; - QList<QXmppDiscoveryIq::Identity> list = m_mapCapabilities[nodeVer].identities(); - foreach(QXmppDiscoveryIq::Identity identity, list) - { - QStringList tmpList; - if(!identity.name().isEmpty()) - tmpList << identity.name(); - if(!identity.category().isEmpty()) - tmpList << identity.category(); - if(!identity.type().isEmpty()) - tmpList << identity.type(); - if(!identity.language().isEmpty()) - tmpList << identity.language(); - idList << tmpList.join(" | "); - } - return idList; -} - diff --git a/examples/GuiClient/capabilitiesCache.h b/examples/GuiClient/capabilitiesCache.h deleted file mode 100644 index 2e6eccac..00000000 --- a/examples/GuiClient/capabilitiesCache.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CAPABILITIESCACHE_H -#define CAPABILITIESCACHE_H - -#include <QObject> -#include <QDomElement> -#include <QMap> - -class QXmppClient; - -#include "QXmppDiscoveryIq.h" - -class capabilitiesCache : public QObject -{ - Q_OBJECT - -public: - capabilitiesCache(QXmppClient* client); - bool isCapabilityAvailable(const QString& nodeVer); - void requestInfo(const QString& jid, const QString& nodeVer); - - void loadFromFile(); - - QStringList getFeatures(const QString& nodeVer); - QStringList getIdentities(const QString& nodeVer); - -signals: - -private slots: - void infoReceived(const QXmppDiscoveryIq&); - -private: - void saveToFile(const QString& nodeVer); - - QXmppClient* m_client; - - QMap<QString, QXmppDiscoveryIq> m_mapCapabilities; - QMap<QString, QString> m_mapIdNodeVer; -}; - -#endif // CAPABILITIESCACHE_H diff --git a/examples/GuiClient/chatDialog.cpp b/examples/GuiClient/chatDialog.cpp deleted file mode 100644 index 60282802..00000000 --- a/examples/GuiClient/chatDialog.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "chatDialog.h" -#include "ui_chatDialog.h" - -#include "chatGraphicsView.h" -#include "chatGraphicsScene.h" -#include "QXmppClient.h" -#include <QPainter> -#include <QPushButton> - -chatDialog::chatDialog(QWidget *parent): QDialog(parent, Qt::Window), - ui(new Ui::chatDialogClass), m_view(0), m_scene(0), m_pushButtonSend(0), m_client(0) -{ - ui->setupUi(this); - m_view = new chatGraphicsView(this); - m_scene = new chatGraphicsScene(this); - m_view->setChatGraphicsScene(m_scene); - m_pushButtonSend = new QPushButton("Send", this); -// m_pushButtonSend->setFixedHeight(); -// m_pushButtonSend->setFixedWidth(); - QRect rect = ui->lineEdit->geometry(); - rect.setLeft(rect.right()); - rect.setWidth(60); - m_pushButtonSend->setGeometry(rect); - ui->lineEdit->setFocus(); - ui->verticalLayout->insertWidget(0, m_view); - bool check = connect(m_pushButtonSend, SIGNAL(clicked(bool)), SLOT(sendMessage())); - Q_ASSERT(check); - Q_UNUSED(check); - updateSendButtonGeomerty(); -} - -void chatDialog::show() -{ - QDialog::show(); -} - -QString chatDialog::getBareJid() const -{ - return m_bareJid; -} - -QString chatDialog::getDisplayName() const -{ - return m_displayName; -} - -void chatDialog::setBareJid(const QString& str) -{ - m_bareJid = str; -} - -void chatDialog::setDisplayName(const QString& str) -{ - m_displayName = str; - setWindowTitle(QString("Chat with %1").arg(m_bareJid)); - - QFont font; - font.setBold(true); - QFontMetrics fontMetrics(font); - QRect rect = fontMetrics.boundingRect(m_displayName); - int width = rect.width(); - - if(m_scene) - m_scene->setBoxStartLength(width); -// ui->horizontalSpacer_2->changeSize(width+20, 10); - ui->lineEdit->setFixedWidth(350 - width - 25); - updateSendButtonGeomerty(); -} - -void chatDialog::setQXmppClient(QXmppClient* client) -{ - m_client = client; -} - -void chatDialog::sendMessage() -{ - if(m_client) - m_client->sendMessage(getBareJid(), ui->lineEdit->text()); - - m_view->addMessage("Me", ui->lineEdit->text()); - ui->lineEdit->clear(); -} - -void chatDialog::messageReceived(const QString& msg) -{ - m_view->addMessage(getDisplayName(), msg); -} - -void chatDialog::keyPressEvent(QKeyEvent* event1) -{ - ui->lineEdit->setFocus(); - ui->lineEdit->event(event1); - - if(event1->key() == Qt::Key_Return) - { - m_pushButtonSend->click(); - } - else if(event1->key() == Qt::Key_Escape) - { - hide(); - } -} - -void chatDialog::paintEvent(QPaintEvent* event) -{ - QDialog::paintEvent(event); - QPainter p(this); - p.setPen(Qt::gray); - p.drawRect(rect().adjusted(5, 5, -6, -6)); -} - -void chatDialog::resizeEvent(QResizeEvent *) -{ - updateSendButtonGeomerty(); -} - -void chatDialog::moveEvent(QMoveEvent *) -{ - updateSendButtonGeomerty(); -} - -void chatDialog::updateSendButtonGeomerty() -{ - QRect rect = ui->lineEdit->geometry(); - rect.setLeft(rect.right() + 6); - rect.setWidth(60); - QRect rect2 = rect; - rect2.setHeight(25); - rect2.moveCenter(rect.center()); - m_pushButtonSend->setGeometry(rect2); -} diff --git a/examples/GuiClient/chatDialog.h b/examples/GuiClient/chatDialog.h deleted file mode 100644 index ec008ebf..00000000 --- a/examples/GuiClient/chatDialog.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATDIALOG_H -#define CHATDIALOG_H - -#include <QDialog> -#include <QKeyEvent> - -namespace Ui -{ - class chatDialogClass; -} - -class chatGraphicsView; -class chatGraphicsScene; -class QXmppClient; -class QPushButton; - -class chatDialog : public QDialog -{ - Q_OBJECT - -public: - chatDialog(QWidget *parent = 0); - void show(); - - QString getBareJid() const; - QString getDisplayName() const; - void setBareJid(const QString&); - void setDisplayName(const QString&); - void setQXmppClient(QXmppClient* client); - void messageReceived(const QString& msg); - -private slots: - void sendMessage(); - -protected: - void keyPressEvent(QKeyEvent*); - void paintEvent(QPaintEvent* event); - virtual void resizeEvent(QResizeEvent*); - virtual void moveEvent(QMoveEvent*); - -private: - void updateSendButtonGeomerty(); - - Ui::chatDialogClass *ui; - chatGraphicsView* m_view; - chatGraphicsScene* m_scene; - QPushButton* m_pushButtonSend; - - // holds a reference to the the connected client - QXmppClient* m_client; - - QString m_bareJid; - QString m_displayName; -}; - -#endif // CHATDIALOG_H diff --git a/examples/GuiClient/chatDialog.ui b/examples/GuiClient/chatDialog.ui deleted file mode 100644 index 2cdb8fcc..00000000 --- a/examples/GuiClient/chatDialog.ui +++ /dev/null @@ -1,82 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>chatDialogClass</class> - <widget class="QDialog" name="chatDialogClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>445</width> - <height>291</height> - </rect> - </property> - <property name="minimumSize"> - <size> - <width>445</width> - <height>0</height> - </size> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <property name="styleSheet"> - <string>alternate-background-color: rgb(255, 255, 255);</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <property name="margin"> - <number>6</number> - </property> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <item> - <widget class="QWidget" name="widget" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="styleSheet"> - <string>background-color: rgb(255, 255, 255);</string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEdit"> - <property name="minimumSize"> - <size> - <width>0</width> - <height>50</height> - </size> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> - </property> - </widget> - </item> - <item> - <widget class="QWidget" name="widget_2" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="styleSheet"> - <string>background-color: rgb(255, 255, 255);</string> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/examples/GuiClient/chatGraphicsScene.cpp b/examples/GuiClient/chatGraphicsScene.cpp deleted file mode 100644 index d032a87b..00000000 --- a/examples/GuiClient/chatGraphicsScene.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "chatGraphicsScene.h" -#include "chatMsgGraphicsItem.h" -#include "chatGraphicsView.h" - -chatGraphicsScene::chatGraphicsScene(QObject* parent) : QGraphicsScene(parent), - m_verticalPosForNewMessage(0), m_verticalSpacing(5) -{ -} - -void chatGraphicsScene::addMessage(const QString& user, const QString& message) -{ - chatMsgGraphicsItem* item = new chatMsgGraphicsItem(); - m_items.append(item); - item->setName(user); - item->setBoxStartLength(m_boxStartLength); - item->setText(message); - item->setViewWidth(350); -// item->setViewWidth(views().at(0)->size().width()); - item->setPos(0, m_verticalPosForNewMessage); - int height = item->boundingRect().height(); - m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; - addItem(item); - - QRectF rect = sceneRect(); - rect.setHeight(m_verticalPosForNewMessage); - setSceneRect(rect); -} - -void chatGraphicsScene::setWidthResize(int newWidth, int oldWidth) -{ - Q_UNUSED(newWidth); - Q_UNUSED(oldWidth); -// verticalReposition(); -} - -void chatGraphicsScene::verticalReposition() -{ - m_verticalPosForNewMessage = 0; - - chatMsgGraphicsItem* item = 0; - for(int i = 0; i < m_items.size(); ++i) - { - item = m_items.at(i); - item->setViewWidth(views().at(0)->size().width()); - item->setPos(0, m_verticalPosForNewMessage); - int height = item->boundingRect().height(); - m_verticalPosForNewMessage = m_verticalPosForNewMessage + height + m_verticalSpacing; - } - - QRectF rect = sceneRect(); - if(item) - { - rect.setHeight(m_verticalPosForNewMessage); - rect.setWidth(item->getMaxWidth() + item->getBoxStartLength() - 4); - setSceneRect(rect); - } -} - -void chatGraphicsScene::setBoxStartLength(int length) -{ - m_boxStartLength = length; -} - diff --git a/examples/GuiClient/chatGraphicsScene.h b/examples/GuiClient/chatGraphicsScene.h deleted file mode 100644 index f9a8fc30..00000000 --- a/examples/GuiClient/chatGraphicsScene.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATGRAPHICSSCENE_H -#define CHATGRAPHICSSCENE_H - -#include <QGraphicsScene> -#include <QList> - -class chatMsgGraphicsItem; - -class chatGraphicsScene : public QGraphicsScene -{ -public: - chatGraphicsScene(QObject* parent = 0); - void addMessage(const QString& user, const QString& message); - void setWidthResize(int newWidth, int oldWidth); - void verticalReposition(); - void setBoxStartLength(int length); - -private: - int m_verticalPosForNewMessage; - int m_verticalSpacing; - int m_boxStartLength; - QList <chatMsgGraphicsItem*> m_items; -}; - -#endif // CHATGRAPHICSSCENE_H diff --git a/examples/GuiClient/chatGraphicsView.cpp b/examples/GuiClient/chatGraphicsView.cpp deleted file mode 100644 index b39a876d..00000000 --- a/examples/GuiClient/chatGraphicsView.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "chatGraphicsView.h" -#include "chatGraphicsScene.h" -#include <QResizeEvent> - -chatGraphicsView::chatGraphicsView(QWidget* parent) : QGraphicsView(parent) -{ - setAlignment(Qt::AlignHCenter|Qt::AlignTop); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setFrameStyle(QFrame::NoFrame); -} - -void chatGraphicsView::setChatGraphicsScene(chatGraphicsScene* scene) -{ - m_scene = scene; - setScene(m_scene); -} - -void chatGraphicsView::addMessage(const QString& user, const QString& message) -{ - if(m_scene) - m_scene->addMessage(user, message); - - QRectF rect = scene()->sceneRect(); - rect.adjust(-4, -4, 4, 4); - setSceneRect(rect); - - rect = sceneRect(); - rect.setTop(sceneRect().height() - 20); - rect.setWidth(20); - ensureVisible(rect, 50, 50); -} - -void chatGraphicsView::resizeEvent(QResizeEvent *event) -{ -// pass this to scene - m_scene->setWidthResize(event->size().width(), event->oldSize().width()); - QGraphicsView::resizeEvent(event); - - QRectF rect = scene()->sceneRect(); - rect.adjust(-4, -4, 4, 4); - setSceneRect(rect); -} diff --git a/examples/GuiClient/chatGraphicsView.h b/examples/GuiClient/chatGraphicsView.h deleted file mode 100644 index 5bb857a6..00000000 --- a/examples/GuiClient/chatGraphicsView.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATGRAPHICSVIEW_H -#define CHATGRAPHICSVIEW_H - -#include <QGraphicsView> -class chatGraphicsScene; - -class chatGraphicsView : public QGraphicsView -{ -public: - chatGraphicsView(QWidget* parent = 0); - void setChatGraphicsScene(chatGraphicsScene* scene); - void addMessage(const QString& user, const QString& message); - -private: - void resizeEvent(QResizeEvent *event); - - chatGraphicsScene* m_scene; -}; - -#endif // CHATGRAPHICSVIEW_H diff --git a/examples/GuiClient/chatMsgGraphicsItem.cpp b/examples/GuiClient/chatMsgGraphicsItem.cpp deleted file mode 100644 index 428c0387..00000000 --- a/examples/GuiClient/chatMsgGraphicsItem.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "chatMsgGraphicsItem.h" - -#include <QPainter> -#include <QTextDocument> -#include <QTime> - -QLinearGradient getGradient(const QColor &col, const QRectF &rect) -{ - QLinearGradient g(rect.topLeft(), rect.bottomLeft()); - - qreal hue = col.hueF(); - qreal value = col.valueF(); - qreal saturation = col.saturationF(); - - QColor c = col; - c.setHsvF(hue, 0.42 * saturation, 0.98 * value); - g.setColorAt(0, c); - c.setHsvF(hue, 0.58 * saturation, 0.95 * value); - g.setColorAt(0.25, c); - c.setHsvF(hue, 0.70 * saturation, 0.93 * value); - g.setColorAt(0.5, c); - - c.setHsvF(hue, 0.95 * saturation, 0.9 * value); - g.setColorAt(0.501, c); - c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value); - g.setColorAt(0.75, c); - c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value); - g.setColorAt(1.0, c); - - return g; -} - -QLinearGradient darken(const QLinearGradient &gradient) -{ - QGradientStops stops = gradient.stops(); - for (int i = 0; i < stops.size(); ++i) { - QColor color = stops.at(i).second; - stops[i].second = color.darker(160); - } - - QLinearGradient g = gradient; - g.setStops(stops); - return g; -} - -static void drawPath(QPainter *p, const QPainterPath &path, const QColor &col, bool dark = false) -{ - const QRectF pathRect = path.boundingRect(); - - const QLinearGradient baseGradient = getGradient(col, pathRect); - const QLinearGradient darkGradient = darken(baseGradient); - - p->save(); - - // p->setOpacity(0.25); - - //glow -// if (dark) -// p->strokePath(path, QPen(darkGradient, 6)); -// else -// p->strokePath(path, QPen(baseGradient, 6)); - - p->setOpacity(1.0); - - //fill - if (dark) - p->fillPath(path, darkGradient); - else - p->fillPath(path, baseGradient); - - QLinearGradient g(pathRect.topLeft(), pathRect.topRight()); - g.setCoordinateMode(QGradient::ObjectBoundingMode); - - p->setOpacity(0.2); - p->fillPath(path, g); - - p->setOpacity(0.5); - - // highlight -// if (dark) -// p->strokePath(path, QPen(col.lighter(160).darker(160), 2)); -// else -// p->strokePath(path, QPen(col.lighter(160), 2)); - - p->setOpacity(1.0); - - p->restore(); -} - -chatMsgGraphicsItem::chatMsgGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent), - m_spikeWidth(9), - m_spikeHeight(6), - m_cornerRadius(10), - m_textSpacing(4), m_color(Qt::yellow) -{ - setPath(createPath()); -// setFlags(QGraphicsItem::ItemIsMovable); - - QFont font; - QFontMetrics fm(font); - m_timeStampWidth = fm.width(getTime()) + 4; -} - -void chatMsgGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option); - Q_UNUSED(widget); - - painter->setRenderHint(QPainter::Antialiasing); - drawPath(painter, path(), m_color); - -// int spike_x = m_spikeWidth; -// int spike_y = m_spikeHeight; -// int corner = m_cornerRadius; -// int length = m_width - spike_x; -// int offset = spike_x; - QFont font; - font.setBold(true); - QTextDocument textDoc(getText()); - QTextOption textOp; - textOp.setWrapMode(QTextOption::WrapAnywhere); - textOp.setAlignment(Qt::AlignLeft); - textDoc.setDefaultTextOption(textOp); - textDoc.setTextWidth(getTextWidth()); - textDoc.setDefaultFont(font); - - painter->setPen(Qt::white); - painter->setFont(font); - int height = (int) textDoc.size().height(); - painter->drawText(m_spikeWidth + m_cornerRadius, 4, getTextWidth(), height, - Qt::AlignLeft|Qt::TextWrapAnywhere, getText()); - -// painter->setPen(Qt::gray); - painter->setPen(Qt::black); - -// font.setBold(false); - painter->setFont(font); - painter->drawText(-m_boxStartLength, 0, m_boxStartLength, m_height, - Qt::AlignRight|Qt::AlignBottom, getName()); - - font.setBold(false); - painter->setPen(Qt::gray); - painter->setFont(font); - - int timeWidth; - if(m_timeStampWidth > m_boxStartLength) - timeWidth = m_timeStampWidth; - else - timeWidth = m_boxStartLength; - - painter->drawText(getMaxWidth() + 6, 0, timeWidth - 6, m_height, - Qt::AlignBottom|Qt::AlignLeft, getTime()); -} - -void chatMsgGraphicsItem::setText(const QString& text) -{ - m_text = text; - calculateWidth(); - setPath(createPath()); -} - -void chatMsgGraphicsItem::setMaxWidth(int width) -{ - m_maxWidth = width; - setPath(createPath()); -} - -void chatMsgGraphicsItem::setViewWidth(int width) -{ - //25 for scrollbar - setMaxWidth(width - getBoxStartLength() - 25); -} - -int chatMsgGraphicsItem::getMaxWidth() const -{ - return m_maxWidth; -} - -void chatMsgGraphicsItem::setAlignment(Alignment align) -{ - m_alignment = align; - setPath(createPath()); -} - -QPainterPath chatMsgGraphicsItem::createPath() -{ - calculateWidth(); - int spike_x = m_spikeWidth; - int spike_y = m_spikeHeight; - int corner = m_cornerRadius; - int length = m_width - spike_x; - int offset = spike_x; - - QPainterPath messageBoxPath; - messageBoxPath.moveTo(0 + offset, m_height - corner); - QRectF rect(offset - 2*spike_x, m_height - corner - spike_y, 2*spike_x, 2*spike_y); - messageBoxPath.arcMoveTo(rect, -90.0); - messageBoxPath.arcTo(rect, 270, 90.0); - messageBoxPath.lineTo(0 + offset, corner); - messageBoxPath.arcTo(0 + offset, 0, 2*corner, 2*corner, 180, -90.0); - messageBoxPath.lineTo(length - corner, 0); - messageBoxPath.arcTo(length + offset - corner*2, 0, 2*corner, 2*corner, 90, -90.0); - messageBoxPath.lineTo(length + offset, m_height - corner); - messageBoxPath.arcTo(length + offset - corner*2, m_height - 2*corner, 2*corner, 2*corner, 0, -90.0); - messageBoxPath.lineTo(offset + corner, m_height); - messageBoxPath.arcTo(offset, m_height - 2*corner, 2*corner, 2*corner, 270, -45.0); - messageBoxPath.closeSubpath(); - - return messageBoxPath; -} - -QString chatMsgGraphicsItem::getText() const -{ - return m_text; -} - -int chatMsgGraphicsItem::getTextWidth() const -{ - return getMaxWidth() - m_spikeWidth - m_cornerRadius*2; -} - -void chatMsgGraphicsItem::calculateWidth() -{ - QFont font; - font.setBold(true); - QTextDocument textDoc(m_text); - textDoc.setDefaultFont(font); - int idealWidth = (int)textDoc.size().width(); - textDoc.setTextWidth(getTextWidth()); - m_height = (int)textDoc.size().height(); - - if(idealWidth < getTextWidth()) - { - m_width = idealWidth + m_spikeWidth + m_cornerRadius; - } - else - m_width = getMaxWidth(); -} - -void chatMsgGraphicsItem::setName(const QString& name) -{ - m_name = name; - if(name != "Me") - m_color = QColor(0, 210, 250); - else - m_color = QColor(250, 188, 239); -} - -QString chatMsgGraphicsItem::getName() const -{ - return m_name; -} - -QString chatMsgGraphicsItem::getTime() const -{ - return QTime::currentTime().toString("hh:mm"); -} - -void chatMsgGraphicsItem::setBoxStartLength(int length) -{ - m_boxStartLength = length; -} - -int chatMsgGraphicsItem::getBoxStartLength() const -{ - return m_boxStartLength; -} - -void chatMsgGraphicsItem::setColor(const QColor& color) -{ - m_color = color; -} - -QRectF chatMsgGraphicsItem::boundingRect() const -{ - QRectF rect = QGraphicsPathItem::boundingRect(); - rect.setLeft(-getBoxStartLength()); - - int timeWidth; - if(m_timeStampWidth > m_boxStartLength) - timeWidth = m_timeStampWidth; - else - timeWidth = m_boxStartLength; - rect.setRight(getMaxWidth() + timeWidth); - return rect; -} diff --git a/examples/GuiClient/chatMsgGraphicsItem.h b/examples/GuiClient/chatMsgGraphicsItem.h deleted file mode 100644 index 653675fd..00000000 --- a/examples/GuiClient/chatMsgGraphicsItem.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CHATMSGGRAPHICSITEM_H -#define CHATMSGGRAPHICSITEM_H - -#include <QGraphicsPathItem> - -class chatMsgGraphicsItem : public QGraphicsPathItem -{ -public: - enum Alignment - { - LEFT = 0, - RIGHT - }; - - chatMsgGraphicsItem(QGraphicsItem * parent = 0); - void setText(const QString& text); - void setName(const QString& name); - QString getName() const; - QString getText() const; - - void setMaxWidth(int width); - int getMaxWidth() const; - void setViewWidth(int viewWidth); - - void setAlignment(Alignment align); - - void setBoxStartLength(int length); - int getBoxStartLength() const; - - void setColor(const QColor&); - - virtual QRectF boundingRect() const; - -private: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - QPainterPath createPath(); - int getTextWidth() const; - void calculateWidth(); - QString getTime() const; - - // max width of bubble including the spike - int m_maxWidth; - - // actual width - int m_width; - - // height of bubble - int m_height; - int m_spikeWidth; - int m_spikeHeight; - int m_cornerRadius; - int m_textSpacing; - int m_boxStartLength; - int m_timeStampWidth; - QColor m_color; - - QString m_text; - QString m_name; - int m_length; - Alignment m_alignment; -}; - -#endif // CHATMSGGRAPHICSITEM_H diff --git a/examples/GuiClient/main.cpp b/examples/GuiClient/main.cpp deleted file mode 100644 index a87eb6bb..00000000 --- a/examples/GuiClient/main.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include <QApplication> -#include <QDir> - -#include "mainDialog.h" -#include "utils.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - - QApplication::setOrganizationName("QXmpp"); - QApplication::setApplicationName("GuiClient"); - - QDir dir; - if(!dir.exists(getSettingsDir())) - dir.mkpath(getSettingsDir()); - - mainDialog cw; - cw.show(); - cw.raise(); - return a.exec(); -} diff --git a/examples/GuiClient/mainDialog.cpp b/examples/GuiClient/mainDialog.cpp deleted file mode 100644 index fa655cd0..00000000 --- a/examples/GuiClient/mainDialog.cpp +++ /dev/null @@ -1,884 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "mainDialog.h" -#include "ui_mainDialog.h" - -#include "utils.h" -#include "profileDialog.h" -#include "aboutDialog.h" -#include "chatDialog.h" - -#include "QXmppPresence.h" -#include "QXmppMessage.h" -#include "QXmppUtils.h" -#include "QXmppVCardManager.h" - -#include <QMovie> -#include <QCompleter> -#include <QInputDialog> -#include <QMessageBox> -#include <QKeyEvent> - - -mainDialog::mainDialog(QWidget *parent): QDialog(parent, Qt::Window), - ui(new Ui::mainDialogClass), m_rosterItemModel(this), - m_rosterItemSortFilterModel(this), m_vCardCache(&m_xmppClient), - m_capabilitiesCache(&m_xmppClient), m_accountsCache(this), - -#ifndef QT_NO_SYSTEMTRAYICON - m_trayIcon(this), m_trayIconMenu(this), -#endif - - m_quitAction("Quit", this), - m_signOutAction("Sign out", this), - m_settingsMenu(0) -{ - bool check; - Q_UNUSED(check); - - ui->setupUi(this); - createTrayIconAndMenu(); - createSettingsMenu(); - - ui->pushButton_cancel->setDisabled(true); - ui->label_throbber->setMovie(new QMovie(":/icons/resource/ajax-loader.gif")); - ui->label_throbber->movie()->start(); - showSignInPage(); - loadAccounts(); - - check = connect(ui->lineEdit_userName->completer(), - SIGNAL(activated(QString)), - this, SLOT(userNameCompleter_activated(QString))); - Q_ASSERT(check); - - check = connect(&m_xmppClient.rosterManager(), - SIGNAL(rosterReceived()), - this, SLOT(rosterReceived())); - Q_ASSERT(check); - - check = connect(&m_xmppClient.rosterManager(), - SIGNAL(itemChanged(QString)), - this, SLOT(rosterChanged(QString))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, - SIGNAL(error(QXmppClient::Error)), - this, SLOT(errorClient(QXmppClient::Error))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, - SIGNAL(presenceReceived(QXmppPresence)), - this, SLOT(presenceReceived(QXmppPresence))); - Q_ASSERT(check); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::SignalLogging); - - - check = connect(&m_xmppClient.rosterManager(), - SIGNAL(presenceChanged(QString,QString)), - this, SLOT(presenceChanged(QString,QString))); - Q_ASSERT(check); - - check = connect(ui->lineEdit_filter, SIGNAL(textChanged(QString)), - this, SLOT(filterChanged(QString))); - Q_ASSERT(check); - - check = connect(ui->listView, SIGNAL(showChatDialog(QString)), - this, SLOT(showChatDialog(QString))); - Q_ASSERT(check); - - check = connect(ui->listView, SIGNAL(showProfile(QString)), - this, SLOT(showProfile(QString))); - Q_ASSERT(check); - - check = connect(ui->listView, SIGNAL(removeContact(QString)), - this, SLOT(action_removeContact(QString))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(messageReceived(QXmppMessage)), - SLOT(messageReceived(QXmppMessage))); - Q_ASSERT(check); - - check = connect(ui->pushButton_signIn, SIGNAL(clicked(bool)), SLOT(signIn())); - Q_ASSERT(check); - - check = connect(ui->pushButton_cancel, SIGNAL(clicked(bool)), - SLOT(cancelSignIn())); - Q_ASSERT(check); - - m_rosterItemSortFilterModel.setSourceModel(&m_rosterItemModel); - ui->listView->setModel(&m_rosterItemSortFilterModel); - m_rosterItemSortFilterModel.sort(0); - - rosterItemDelegate *delegate = new rosterItemDelegate(); - ui->listView->setItemDelegate(delegate); - ui->listView->setFocus(); - ui->verticalLayout_3->insertWidget(0, &m_statusWidget); - - check = connect(&m_statusWidget, SIGNAL(statusTextChanged(QString)), - SLOT(statusTextChanged(QString))); - Q_ASSERT(check); - check = connect(&m_statusWidget, SIGNAL(presenceTypeChanged(QXmppPresence::Type)), - SLOT(presenceTypeChanged(QXmppPresence::Type))); - Q_ASSERT(check); - check = connect(&m_statusWidget, - SIGNAL(presenceStatusTypeChanged(QXmppPresence::AvailableStatusType)), - SLOT(presenceStatusTypeChanged(QXmppPresence::AvailableStatusType))); - Q_ASSERT(check); - check = connect(&m_statusWidget, - SIGNAL(avatarChanged(QImage)), - SLOT(avatarChanged(QImage))); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(updateStatusWidget())); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(showRosterPage())); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(connected()), SLOT(addAccountToCache())); - Q_ASSERT(check); - - check = connect(&m_xmppClient, SIGNAL(disconnected()), SLOT(showSignInPageAfterUserDisconnection())); - Q_ASSERT(check); - - check = connect(&m_xmppClient.vCardManager(), - SIGNAL(vCardReceived(QXmppVCardIq)), &m_vCardCache, - SLOT(vCardReceived(QXmppVCardIq))); - Q_ASSERT(check); - - check = connect(&m_vCardCache, - SIGNAL(vCardReadyToUse(QString)), - SLOT(updateVCard(QString))); - Q_ASSERT(check); - - check = connect(ui->pushButton_addContact, SIGNAL(clicked()), SLOT(action_addContact())); - Q_ASSERT(check); - - check = connect(QXmppLogger::getLogger(), - SIGNAL(message(QXmppLogger::MessageType,QString)), - &m_consoleDlg, - SLOT(message(QXmppLogger::MessageType,QString))); - Q_ASSERT(check); - - check = connect(ui->pushButton_settings, - SIGNAL(pressed()), - SLOT(action_settingsPressed())); - Q_ASSERT(check); -} - -void mainDialog::rosterChanged(const QString& bareJid) -{ - m_rosterItemModel.updateRosterEntry(bareJid, m_xmppClient.rosterManager(). - getRosterEntry(bareJid)); - - // if available in cache, update it else based on presence it will request if not available - if(m_vCardCache.isVCardAvailable(bareJid)) - updateVCard(bareJid); -} - -void mainDialog::rosterReceived() -{ - QStringList list = m_xmppClient.rosterManager().getRosterBareJids(); - QString bareJid; - foreach(bareJid, list) - rosterChanged(bareJid); -} - -void mainDialog::presenceChanged(const QString& bareJid, const QString& resource) -{ - if(bareJid == m_xmppClient.configuration().jidBare()) - return; - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) - return; - - QString jid = bareJid + "/" + resource; - QMap<QString, QXmppPresence> presences = m_xmppClient.rosterManager(). - getAllPresencesForBareJid(bareJid); - m_rosterItemModel.updatePresence(bareJid, presences); - - QXmppPresence& pre = presences[resource]; - - if(pre.type() == QXmppPresence::Available) - { - QString node = pre.capabilityNode(); - QString ver = pre.capabilityVer().toBase64(); - QStringList exts = pre.capabilityExt(); - - QString nodeVer = node + "#" + ver; - if(!m_capabilitiesCache.isCapabilityAvailable(nodeVer)) - m_capabilitiesCache.requestInfo(jid, nodeVer); - - foreach(QString ext, exts) - { - nodeVer = node + "#" + ext; - if(!m_capabilitiesCache.isCapabilityAvailable(nodeVer)) - m_capabilitiesCache.requestInfo(jid, nodeVer); - } - - switch(pre.vCardUpdateType()) - { - case QXmppPresence::VCardUpdateNone: - if(!m_vCardCache.isVCardAvailable(bareJid)) - m_vCardCache.requestVCard(bareJid); - case QXmppPresence::VCardUpdateNotReady: - break; - case QXmppPresence::VCardUpdateNoPhoto: - case QXmppPresence::VCardUpdateValidPhoto: - if(m_vCardCache.getPhotoHash(bareJid) != pre.photoHash()) - m_vCardCache.requestVCard(bareJid); - break; - } - } - -// QXmppPresence::Type presenceType = presences.begin().value().getType(); - -// if(!m_vCardCache.isVCardAvailable(bareJid) && -// presenceType == QXmppPresence::Available) -// { -// m_rosterItemModel.updateAvatar(bareJid, -// m_vCardCache.getVCard(bareJid).image); -// } -} - -void mainDialog::filterChanged(const QString& filter) -{ - m_rosterItemSortFilterModel.setFilterRegExp(filter); - - // follow statement selects the first row - ui->listView->selectionModel()->select(ui->listView->model()->index(0, 0), - QItemSelectionModel::ClearAndSelect); -} - -void mainDialog::keyPressEvent(QKeyEvent* event1) -{ - if(ui->stackedWidget->currentIndex() == 0) // roster page - { - if(event1->matches(QKeySequence::Find) ||( - event1->key() <= Qt::Key_9 && event1->key() >= Qt::Key_1) || - (event1->key() <= Qt::Key_Z && event1->key() >= Qt::Key_At) || - event1->key() == Qt::Key_Backspace) - { - ui->lineEdit_filter->setFocus(); - ui->lineEdit_filter->event(event1); - } - else if(event1->key() == Qt::Key_Escape) - { - ui->lineEdit_filter->clear(); - ui->listView->setFocus(); - } - else if(event1->key() == Qt::Key_Up || - event1->key() == Qt::Key_Down || - event1->key() == Qt::Key_PageUp || - event1->key() == Qt::Key_PageDown) - { - ui->listView->setFocus(); - ui->listView->event(event1); - } - else if(event1->key() == Qt::Key_Return && ui->listView->hasFocus()) - { - ui->listView->event(event1); - } - } - -// don't close on escape - if(event1->key() == Qt::Key_Escape) - { - event1->ignore(); - return; - } -// FIXME: I'm not sure what this is supposed to do, but it does not compile. -#if 0 - else if(minimize && e->modifiers() == Qt::ControlModifier && e->key() == Qt::Key_Period) - { - event1->ignore(); - return; - } -#endif -// don't close on escape - - if(ui->stackedWidget->currentIndex() == 1) // sign in page - { - QDialog::keyPressEvent(event1); - return; - } -} - -chatDialog* mainDialog::getChatDialog(const QString& bareJid) -{ - if(!m_chatDlgsList.contains(bareJid)) - { - m_chatDlgsList[bareJid] = new chatDialog(); - m_chatDlgsList[bareJid]->setBareJid(bareJid); - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)) - return 0; - - if(!m_rosterItemModel.getRosterItemFromBareJid(bareJid)-> - getName().isEmpty()) - m_chatDlgsList[bareJid]->setDisplayName(m_rosterItemModel. - getRosterItemFromBareJid(bareJid)->getName()); - else - m_chatDlgsList[bareJid]->setDisplayName(QXmppUtils::jidToUser(bareJid)); - - m_chatDlgsList[bareJid]->setQXmppClient(&m_xmppClient); - } - - return m_chatDlgsList[bareJid]; -} - -void mainDialog::showChatDialog(const QString& bareJid) -{ - if(!bareJid.isEmpty()) - getChatDialog(bareJid)->show(); -} - -void mainDialog::messageReceived(const QXmppMessage& msg) -{ - if (msg.body().isEmpty()) - return; - - chatDialog *dialog = getChatDialog(QXmppUtils::jidToBareJid(msg.from())); - if (dialog) { - dialog->show(); - dialog->messageReceived(msg.body()); - } -} - -void mainDialog::statusTextChanged(const QString& status) -{ - QXmppPresence presence = m_xmppClient.clientPresence(); - presence.setStatusText(status); - addPhotoHash(presence); - m_xmppClient.setClientPresence(presence); -} - -void mainDialog::presenceTypeChanged(QXmppPresence::Type presenceType) -{ - if(presenceType == QXmppPresence::Unavailable) - { - m_xmppClient.disconnectFromServer(); - } - else if(presenceType == QXmppPresence::Available) - { - QXmppPresence newPresence = m_xmppClient.clientPresence(); - newPresence.setType(presenceType); - newPresence.setAvailableStatusType(QXmppPresence::Online); - addPhotoHash(newPresence); - m_xmppClient.setClientPresence(newPresence); - } - m_statusWidget.setStatusText( - presenceToStatusText(m_xmppClient.clientPresence())); -} - -void mainDialog::presenceStatusTypeChanged(QXmppPresence::AvailableStatusType statusType) -{ - QXmppPresence presence = m_xmppClient.clientPresence(); - presence.setType(QXmppPresence::Available); - presence.setAvailableStatusType(statusType); - addPhotoHash(presence); - m_xmppClient.setClientPresence(presence); - m_statusWidget.setStatusText( - presenceToStatusText(m_xmppClient.clientPresence())); -} - -void mainDialog::avatarChanged(const QImage& image) -{ - QXmppVCardIq vcard; - vcard.setType(QXmppIq::Set); - - QByteArray ba; - QBuffer buffer(&ba); - if(buffer.open(QIODevice::WriteOnly)) - { - if(image.save(&buffer, "PNG")) - { - vcard.setPhoto(ba); - m_xmppClient.sendPacket(vcard); - m_statusWidget.setAvatar(image); - - m_vCardCache.getVCard(m_xmppClient.configuration().jidBare()) = vcard; - // update photo hash - QXmppPresence presence = m_xmppClient.clientPresence(); - addPhotoHash(presence); - m_xmppClient.setClientPresence(presence); - } - } -} - -void mainDialog::updateStatusWidget() -{ - const QString bareJid = m_xmppClient.configuration().jidBare(); - - // initialise status widget - updateVCard(bareJid); - m_statusWidget.setStatusText(presenceToStatusText(m_xmppClient.clientPresence())); - m_statusWidget.setPresenceAndStatusType(m_xmppClient.clientPresence().type(), - m_xmppClient.clientPresence().availableStatusType()); - - // fetch own vCard - m_vCardCache.requestVCard(bareJid); -} - -void mainDialog::signIn() -{ - ui->label_throbber->show(); - ui->pushButton_signIn->setDisabled(true); - ui->pushButton_cancel->setDisabled(false); - ui->lineEdit_userName->setDisabled(true); - ui->lineEdit_password->setDisabled(true); - ui->checkBox_rememberPasswd->setDisabled(true); - showLoginStatusWithProgress("Connecting"); - - QString bareJid = ui->lineEdit_userName->text(); - QString passwd = ui->lineEdit_password->text(); - - m_xmppClient.configuration().setJid(bareJid); - m_xmppClient.configuration().setPassword(passwd); - - m_rosterItemModel.clear(); - - m_vCardCache.loadFromFile(); - m_capabilitiesCache.loadFromFile(); - - startConnection(); -} - -void mainDialog::cancelSignIn() -{ - if(!ui->checkBox_rememberPasswd->isChecked()) - ui->lineEdit_password->setText(""); - - ui->label_throbber->hide(); - m_xmppClient.disconnectFromServer(); - showSignInPage(); - showLoginStatus("Sign in cancelled"); - addAccountToCache(); -} - -void mainDialog::showSignInPage() -{ - ui->label_throbber->hide(); - ui->pushButton_signIn->setDisabled(false); - ui->pushButton_cancel->setDisabled(true); - ui->lineEdit_userName->setDisabled(false); - ui->lineEdit_password->setDisabled(false); - ui->checkBox_rememberPasswd->setDisabled(false); - ui->stackedWidget->setCurrentIndex(1); -} - -void mainDialog::showSignInPageAfterUserDisconnection() -{ - if(!ui->checkBox_rememberPasswd->isChecked()) - ui->lineEdit_password->setText(""); - - ui->label_throbber->hide(); - - showLoginStatus("Disconnected"); - showSignInPage(); -} - -void mainDialog::showRosterPage() -{ - ui->stackedWidget->setCurrentIndex(0); -} - -void mainDialog::startConnection() -{ -// m_xmppClient.setClientPresence(QXmppPresence()); - m_xmppClient.connectToServer(m_xmppClient.configuration()); -} - -void mainDialog::showLoginStatus(const QString& msg) -{ - ui->label_status->setCustomText(msg, signInStatusLabel::None); -} - -void mainDialog::showLoginStatusWithProgress(const QString& msg) -{ - ui->label_status->setCustomText(msg, signInStatusLabel::WithProgressEllipsis); -} - -void mainDialog::showLoginStatusWithCounter(const QString& msg, int time) -{ - ui->label_status->setCustomText(msg, signInStatusLabel::CountDown, time); -} - -void mainDialog::updateVCard(const QString& bareJid) -{ - // determine full name - const QXmppVCardIq vCard = m_vCardCache.getVCard(bareJid); - QString fullName = vCard.fullName(); - if (fullName.isEmpty()) - fullName = bareJid; - - // determine avatar - QImage avatar = m_vCardCache.getAvatar(bareJid); - if (avatar.isNull()) - avatar = QImage(":/icons/resource/avatar.png"); - - if (bareJid == m_xmppClient.configuration().jidBare()) { - // update our own information - m_statusWidget.setAvatar(avatar); - m_statusWidget.setDisplayName(fullName); - } else { - // update roster information - m_rosterItemModel.updateAvatar(bareJid, avatar); - m_rosterItemModel.updateName(bareJid, fullName); - } -} - -void mainDialog::showProfile(const QString& bareJid) -{ - if(bareJid.isEmpty()) - return; - - profileDialog dlg(this, bareJid, m_xmppClient, m_capabilitiesCache); - dlg.setBareJid(bareJid); - // TODO use original image - if(!m_vCardCache.getAvatar(bareJid).isNull()) - dlg.setAvatar(m_vCardCache.getAvatar(bareJid)); - QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); - - dlg.setFullName(m_vCardCache.getVCard(bareJid).fullName()); - - if(m_vCardCache.getVCard(bareJid).fullName().isEmpty()) - dlg.setFullName(m_xmppClient.rosterManager().getRosterEntry(bareJid).name()); - - dlg.exec(); -} - -void mainDialog::loadAccounts() -{ - m_accountsCache.loadFromFile(); - QStringList list = m_accountsCache.getBareJids(); - QCompleter *completer = new QCompleter(list, this); - completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); - completer->setCaseSensitivity(Qt::CaseInsensitive); - ui->lineEdit_userName->setCompleter(completer); - - if(!list.isEmpty()) - { - ui->lineEdit_userName->setText(list.last()); - QString passwd = m_accountsCache.getPassword(list.last()); - ui->lineEdit_password->setText(passwd); - if(!passwd.isEmpty()) - ui->checkBox_rememberPasswd->setChecked(true); - } -} - -void mainDialog::userNameCompleter_activated(const QString& user) -{ - QString passwd = m_accountsCache.getPassword(user); - ui->lineEdit_password->setText(passwd); - if(!passwd.isEmpty()) - ui->checkBox_rememberPasswd->setChecked(true); -} - -void mainDialog::addAccountToCache() -{ - QString bareJid = ui->lineEdit_userName->text(); - QString passwd = ui->lineEdit_password->text(); - if(!ui->checkBox_rememberPasswd->isChecked()) - passwd = ""; - m_accountsCache.addAccount(bareJid, passwd); -} - -void mainDialog::action_signOut() -{ - m_xmppClient.disconnectFromServer(); - - // update widget - m_statusWidget.setStatusText( - presenceToStatusText(m_xmppClient.clientPresence())); -} - -void mainDialog::action_quit() -{ - m_xmppClient.disconnectFromServer(); - QApplication::quit(); -} - -void mainDialog::createTrayIconAndMenu() -{ - bool check; - Q_UNUSED(check); - - check = connect(&m_quitAction, SIGNAL(triggered()), SLOT(action_quit())); - Q_ASSERT(check); - - check = connect(&m_signOutAction, SIGNAL(triggered()), SLOT(action_signOut())); - Q_ASSERT(check); - -#ifndef QT_NO_SYSTEMTRAYICON - m_trayIcon.setIcon(QIcon(":/icons/resource/icon.png")); - - check = connect(&m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), - SLOT(action_trayIconActivated(QSystemTrayIcon::ActivationReason))); - Q_ASSERT(check); - - m_trayIconMenu.addAction(&m_signOutAction); - m_trayIconMenu.addSeparator(); - m_trayIconMenu.addAction(&m_quitAction); - - m_trayIcon.setContextMenu(&m_trayIconMenu); - m_trayIcon.show(); -#endif -} - -void mainDialog::createSettingsMenu() -{ - m_settingsMenu = new QMenu(ui->pushButton_settings); -// ui->pushButton_settings->setMenu(m_settingsMenu); - - QAction* aboutDlg = new QAction("About", ui->pushButton_settings); - connect(aboutDlg, SIGNAL(triggered()), SLOT(action_aboutDlg())); - m_settingsMenu->addAction(aboutDlg); - - m_settingsMenu->addSeparator(); - - QAction* showXml = new QAction("Show XML Console...", ui->pushButton_settings); - connect(showXml, SIGNAL(triggered()), SLOT(action_showXml())); - m_settingsMenu->addAction(showXml); - - QMenu* viewMenu = new QMenu("View", ui->pushButton_settings); - m_settingsMenu->addMenu(viewMenu); - - QAction* showOfflineContacts = new QAction("Show offline contacts", ui->pushButton_settings); - showOfflineContacts->setCheckable(true); - showOfflineContacts->setChecked(true); - connect(showOfflineContacts, SIGNAL(triggered(bool)), - &m_rosterItemSortFilterModel, SLOT(setShowOfflineContacts(bool))); - viewMenu->addAction(showOfflineContacts); - - QAction* sortByName = new QAction("Sort by name", ui->pushButton_settings); - sortByName->setCheckable(true); - sortByName->setChecked(false); - connect(sortByName, SIGNAL(triggered(bool)), - &m_rosterItemSortFilterModel, SLOT(sortByName(bool))); - viewMenu->addAction(sortByName); - - m_settingsMenu->addSeparator(); - m_settingsMenu->addAction(&m_quitAction); -} - -void mainDialog::closeEvent(QCloseEvent *event) -{ - hide(); - event->ignore(); -} - -void mainDialog::action_trayIconActivated(QSystemTrayIcon::ActivationReason reason) -{ - switch(reason) - { - case QSystemTrayIcon::Trigger: - case QSystemTrayIcon::DoubleClick: - show(); - break; - default: - ; - } -} - -void mainDialog::action_addContact() -{ - bool ok; - QString bareJid = QInputDialog::getText(this, "Add a jabber contact", - "Contact ID:", QLineEdit::Normal, "", &ok); - - if(!ok) - return; - - if(!isValidBareJid(bareJid)) - { - QMessageBox::information(this, "Invalid ID", "Specified ID <I>"+bareJid + " </I> is invalid."); - return; - } - - if(ok && !bareJid.isEmpty()) - { - QXmppPresence subscribe; - subscribe.setTo(bareJid); - subscribe.setType(QXmppPresence::Subscribe); - m_xmppClient.sendPacket(subscribe); - } -} - -void mainDialog::presenceReceived(const QXmppPresence& presence) -{ - QString from = presence.from(); - - QString message; - switch(presence.type()) - { - case QXmppPresence::Subscribe: - { - message = "<B>%1</B> wants to subscribe"; - - int retButton = QMessageBox::question( - this, "Contact Subscription", message.arg(from), - QMessageBox::Yes, QMessageBox::No); - - switch(retButton) - { - case QMessageBox::Yes: - { - QXmppPresence subscribed; - subscribed.setTo(from); - subscribed.setType(QXmppPresence::Subscribed); - m_xmppClient.sendPacket(subscribed); - - // reciprocal subscription - QXmppPresence subscribe; - subscribe.setTo(from); - subscribe.setType(QXmppPresence::Subscribe); - m_xmppClient.sendPacket(subscribe); - } - break; - case QMessageBox::No: - { - QXmppPresence unsubscribed; - unsubscribed.setTo(from); - unsubscribed.setType(QXmppPresence::Unsubscribed); - m_xmppClient.sendPacket(unsubscribed); - } - break; - default: - break; - } - - return; - } - break; - case QXmppPresence::Subscribed: - message = "<B>%1</B> accepted your request"; - break; - case QXmppPresence::Unsubscribe: - message = "<B>%1</B> unsubscribe"; - break; - case QXmppPresence::Unsubscribed: - message = "<B>%1</B> unsubscribed"; - break; - default: - return; - break; - } - - if(message.isEmpty()) - return; - - QMessageBox::information(this, "Contact Subscription", message.arg(from), - QMessageBox::Ok); -} - -void mainDialog::action_removeContact(const QString& bareJid) -{ - if(!isValidBareJid(bareJid)) - return; - - int answer = QMessageBox::question(this, "Remove contact", - QString("Do you want to remove the contact <I>%1</I>").arg(bareJid), - QMessageBox::Yes, QMessageBox::No); - if(answer == QMessageBox::Yes) - { - QXmppRosterIq remove; - remove.setType(QXmppIq::Set); - QXmppRosterIq::Item itemRemove; - itemRemove.setSubscriptionType(QXmppRosterIq::Item::Remove); - itemRemove.setBareJid(bareJid); - remove.addItem(itemRemove); - m_xmppClient.sendPacket(remove); - - m_rosterItemModel.removeRosterEntry(bareJid); - } -} - -void mainDialog::errorClient(QXmppClient::Error error) -{ - ui->label_throbber->hide(); - - showSignInPage(); - - switch(error) - { - case QXmppClient::SocketError: - showLoginStatus("Socket error"); - break; - case QXmppClient::KeepAliveError: - showLoginStatus("Keep alive error"); - break; - case QXmppClient::XmppStreamError: - switch(m_xmppClient.xmppStreamError()) - { - case QXmppStanza::Error::NotAuthorized: - showLoginStatus("Invalid password"); - break; - default: - showLoginStatus("Stream error"); - break; - } - break; - default: - break; - } -} - -void mainDialog::action_showXml() -{ - m_consoleDlg.show(); -} - -void mainDialog::addPhotoHash(QXmppPresence& pre) -{ - QString clientBareJid = m_xmppClient.configuration().jidBare(); - - if(m_vCardCache.isVCardAvailable(clientBareJid)) - { - QByteArray hash = m_vCardCache.getPhotoHash(clientBareJid); - if(hash.isEmpty()) - pre.setVCardUpdateType(QXmppPresence::VCardUpdateNoPhoto); - else - pre.setVCardUpdateType(QXmppPresence::VCardUpdateValidPhoto); - pre.setPhotoHash(hash); - } - else - { - pre.setVCardUpdateType(QXmppPresence::VCardUpdateNone); - pre.setPhotoHash(QByteArray()); - } -} - -void mainDialog::action_aboutDlg() -{ - aboutDialog abtDlg(this); - abtDlg.exec(); -} - -void mainDialog::action_settingsPressed() -{ - m_settingsMenu->exec(ui->pushButton_settings->mapToGlobal(QPoint(0, ui->pushButton_settings->height()))); -} diff --git a/examples/GuiClient/mainDialog.h b/examples/GuiClient/mainDialog.h deleted file mode 100644 index 1834074b..00000000 --- a/examples/GuiClient/mainDialog.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef MAINDIALOG_H -#define MAINDIALOG_H - -#include <QDialog> -#include <QMap> -#include <QSystemTrayIcon> -#include <QMenu> - -#include "rosterItemModel.h" -#include "rosterItemSortFilterProxyModel.h" -#include "statusWidget.h" -#include "vCardCache.h" -#include "capabilitiesCache.h" -#include "accountsCache.h" -#include "xmlConsoleDialog.h" - -#include "QXmppClient.h" - -class chatDialog; - -class QKeyEvent; - -namespace Ui -{ - class mainDialogClass; -} - -class mainDialog : public QDialog -{ - Q_OBJECT - -public: - mainDialog(QWidget *parent = 0); - -protected: - void keyPressEvent(QKeyEvent*); - void closeEvent(QCloseEvent* event); - -private slots: - void rosterChanged(const QString& bareJid); - void rosterReceived(); - void presenceChanged(const QString&, const QString&); - void filterChanged(const QString& filter); - void showChatDialog(const QString& bareJid); - void messageReceived(const QXmppMessage& msg); - void statusTextChanged(const QString&); - void presenceTypeChanged(QXmppPresence::Type); - void presenceStatusTypeChanged(QXmppPresence::AvailableStatusType); - void signIn(); - void cancelSignIn(); - void showSignInPage(); - void showSignInPageAfterUserDisconnection(); - void showRosterPage(); - void startConnection(); - void updateStatusWidget(); - void showLoginStatusWithProgress(const QString& msg); - void showLoginStatus(const QString& msg); - void showLoginStatusWithCounter(const QString& msg, int time); - void updateVCard(const QString& bareJid); - void avatarChanged(const QImage&); - void showProfile(const QString& bareJid); - void userNameCompleter_activated(const QString&); - void addAccountToCache(); - void presenceReceived(const QXmppPresence&); - void errorClient(QXmppClient::Error); - - void action_addContact(); - void action_removeContact(const QString& bareJid); - void action_signOut(); - void action_quit(); - void action_trayIconActivated(QSystemTrayIcon::ActivationReason reason); - - void action_showXml(); - void action_aboutDlg(); - void action_settingsPressed(); - -private: - void loadAccounts(); - void createTrayIconAndMenu(); - void createSettingsMenu(); - - void addPhotoHash(QXmppPresence&); - - chatDialog* getChatDialog(const QString& bareJid); - - Ui::mainDialogClass* ui; - QXmppClient m_xmppClient; - rosterItemModel m_rosterItemModel; - rosterItemSortFilterProxyModel m_rosterItemSortFilterModel; - statusWidget m_statusWidget; - vCardCache m_vCardCache; - capabilitiesCache m_capabilitiesCache; - accountsCache m_accountsCache; - - // map of bare jids and respective chatdlg - QMap<QString, chatDialog*> m_chatDlgsList; - -#ifndef QT_NO_SYSTEMTRAYICON - QSystemTrayIcon m_trayIcon; - QMenu m_trayIconMenu; -#endif - - QAction m_quitAction; - QAction m_signOutAction; - - xmlConsoleDialog m_consoleDlg; - - QMenu* m_settingsMenu; -}; - -#endif // MAINDIALOG_H diff --git a/examples/GuiClient/mainDialog.ui b/examples/GuiClient/mainDialog.ui deleted file mode 100644 index 635ca47b..00000000 --- a/examples/GuiClient/mainDialog.ui +++ /dev/null @@ -1,385 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>mainDialogClass</class> - <widget class="QDialog" name="mainDialogClass"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>236</width> - <height>484</height> - </rect> - </property> - <property name="windowTitle"> - <string>QXmpp</string> - </property> - <property name="windowIcon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/icon.png</normaloff>:/icons/resource/icon.png</iconset> - </property> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <property name="margin"> - <number>6</number> - </property> - <item> - <widget class="QStackedWidget" name="stackedWidget"> - <property name="currentIndex"> - <number>0</number> - </property> - <widget class="QWidget" name="page"> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <property name="spacing"> - <number>6</number> - </property> - <property name="leftMargin"> - <number>0</number> - </property> - <property name="topMargin"> - <number>4</number> - </property> - <property name="rightMargin"> - <number>0</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <widget class="searchLineEdit" name="lineEdit_filter"> - <property name="enabled"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <widget class="rosterListView" name="listView"> - <property name="editTriggers"> - <set>QAbstractItemView::NoEditTriggers</set> - </property> - <property name="verticalScrollMode"> - <enum>QAbstractItemView::ScrollPerPixel</enum> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QPushButton" name="pushButton_addContact"> - <property name="minimumSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/addButton.png</normaloff>:/icons/resource/addButton.png</iconset> - </property> - <property name="iconSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_3"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pushButton_settings"> - <property name="minimumSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/settingsButton.png</normaloff>:/icons/resource/settingsButton.png</iconset> - </property> - <property name="iconSize"> - <size> - <width>29</width> - <height>29</height> - </size> - </property> - <property name="default"> - <bool>true</bool> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <widget class="QWidget" name="page_2"> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="leftMargin"> - <number>20</number> - </property> - <property name="rightMargin"> - <number>20</number> - </property> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Login:</string> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEdit_userName"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <widget class="QLineEdit" name="lineEdit_password"> - <property name="text"> - <string/> - </property> - <property name="echoMode"> - <enum>QLineEdit::Password</enum> - </property> - </widget> - </item> - <item> - <widget class="QCheckBox" name="checkBox_rememberPasswd"> - <property name="text"> - <string>Remember password</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pushButton_signIn"> - <property name="text"> - <string>Sign in</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="pushButton_cancel"> - <property name="text"> - <string>Cancel</string> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_4"> - <item> - <spacer name="horizontalSpacer_4"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="signInStatusLabel" name="label_status"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_5"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <item> - <spacer name="horizontalSpacer_6"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_throbber"> - <property name="text"> - <string>movie</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>0</width> - <height>35</height> - </size> - </property> - <property name="text"> - <string/> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_7"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>70</height> - </size> - </property> - </spacer> - </item> - </layout> - </widget> - </widget> - </item> - </layout> - </widget> - <customwidgets> - <customwidget> - <class>rosterListView</class> - <extends>QListView</extends> - <header>rosterListView.h</header> - </customwidget> - <customwidget> - <class>searchLineEdit</class> - <extends>QLineEdit</extends> - <header>searchLineEdit.h</header> - </customwidget> - <customwidget> - <class>signInStatusLabel</class> - <extends>QLabel</extends> - <header>signInStatusLabel.h</header> - </customwidget> - </customwidgets> - <resources> - <include location="resources.qrc"/> - </resources> - <connections/> -</ui> diff --git a/examples/GuiClient/profileDialog.cpp b/examples/GuiClient/profileDialog.cpp deleted file mode 100644 index 384d2fa7..00000000 --- a/examples/GuiClient/profileDialog.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "profileDialog.h" -#include "ui_profileDialog.h" -#include "utils.h" - -#include "QXmppClient.h" -#include "QXmppVersionIq.h" -#include "QXmppVersionManager.h" -#include "QXmppRosterManager.h" -#include "QXmppUtils.h" -#include "QXmppEntityTimeManager.h" -#include "QXmppEntityTimeIq.h" -#include "QXmppConstants.h" - -profileDialog::profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client, capabilitiesCache& caps) : - QDialog(parent, Qt::WindowTitleHint|Qt::WindowSystemMenuHint), - ui(new Ui::profileDialog), m_bareJid(bareJid), m_xmppClient(client), m_caps(caps) -{ - bool check; - Q_UNUSED(check); - - ui->setupUi(this); - - check = connect(&m_xmppClient.versionManager(), SIGNAL(versionReceived(QXmppVersionIq)), - SLOT(versionReceived(QXmppVersionIq))); - Q_ASSERT(check); - - QXmppEntityTimeManager* timeManager = m_xmppClient.findExtension<QXmppEntityTimeManager>(); - - if(timeManager) - { - check = connect(timeManager, SIGNAL(timeReceived(QXmppEntityTimeIq)), - SLOT(timeReceived(QXmppEntityTimeIq))); - Q_ASSERT(check); - } - - QStringList resources = m_xmppClient.rosterManager().getResources(bareJid); - foreach(QString resource, resources) - { - QString jid = bareJid + "/" + resource; - m_xmppClient.versionManager().requestVersion(jid); - if(timeManager) - timeManager->requestTime(jid); - } - updateText(); -} - -profileDialog::~profileDialog() -{ - delete ui; -} - -void profileDialog::setAvatar(const QImage& image) -{ - ui->label_avatar->setPixmap(QPixmap::fromImage(image)); -} - -void profileDialog::setBareJid(const QString& bareJid) -{ - ui->label_jid->setText(bareJid); - setWindowTitle(bareJid); -} - -void profileDialog::setFullName(const QString& fullName) -{ - if(fullName.isEmpty()) - ui->label_fullName->hide(); - else - ui->label_fullName->show(); - - ui->label_fullName->setText(fullName); -} - -void profileDialog::setStatusText(const QString& status) -{ - ui->label_status->setText(status); -} - -void profileDialog::versionReceived(const QXmppVersionIq& ver) -{ - m_versions[QXmppUtils::jidToResource(ver.from())] = ver; - if(ver.type() == QXmppIq::Result) - updateText(); -} - -void profileDialog::timeReceived(const QXmppEntityTimeIq& time) -{ - m_time[QXmppUtils::jidToResource(time.from())] = time; - if(time.type() == QXmppIq::Result) - updateText(); -} - -void profileDialog::updateText() -{ - QStringList resources = m_xmppClient.rosterManager().getResources(m_bareJid); - QString statusText; - for(int i = 0; i < resources.count(); ++i) - { - QString resource = resources.at(i); - statusText += "<B>Resource: </B>" + resource; - statusText += "<BR>"; - QXmppPresence presence = m_xmppClient.rosterManager().getPresence(m_bareJid, resource); - statusText += "<B>Status: </B>" + presenceToStatusText(presence); - statusText += "<BR>"; - if(m_versions.contains(resource)) - { - statusText += "<B>Software: </B>" + QString("%1 %2 %3"). - arg(m_versions[resource].name()). - arg(m_versions[resource].version()). - arg(m_versions[resource].os()); - statusText += "<BR>"; - } - - if(m_time.contains(resource)) - { - statusText += "<B>Time: </B>" + QString("utc=%1 [tzo=%2]"). - arg(m_time[resource].utc().toString()). - arg(QXmppUtils::timezoneOffsetToString(m_time[resource].tzo())); - statusText += "<BR>"; - } - - statusText += getCapability(resource); - - if(i < resources.count() - 1) // skip for the last item - statusText += "<BR>"; - } - setStatusText(statusText); -} - -QString profileDialog::getCapability(const QString& resource) -{ - QMap<QString, QXmppPresence> presences = m_xmppClient.rosterManager(). - getAllPresencesForBareJid(m_bareJid); - QXmppPresence& pre = presences[resource]; - QString nodeVer; - QStringList resultFeatures; - QStringList resultIdentities; - - QString node = pre.capabilityNode(); - QString ver = pre.capabilityVer().toBase64(); - QStringList exts = pre.capabilityExt(); - nodeVer = node + "#" + ver; - if(m_caps.isCapabilityAvailable(nodeVer)) - { - resultFeatures << m_caps.getFeatures(nodeVer); - resultIdentities << m_caps.getIdentities(nodeVer); - } - foreach(QString ext, exts) - { - nodeVer = node + "#" + ext; - if(m_caps.isCapabilityAvailable(nodeVer)) - { - resultFeatures << m_caps.getFeatures(nodeVer); - resultIdentities << m_caps.getIdentities(nodeVer); - } - } - - resultIdentities.removeDuplicates(); - resultFeatures.removeDuplicates(); - - QString result; - result += "<B>Disco Identities:</B><BR>"; - result += resultIdentities.join("<BR>"); - result += "<BR>"; - result += "<B>Disco Features:</B><BR>"; - result += resultFeatures.join("<BR>"); - result += "<BR>"; - return result; -} diff --git a/examples/GuiClient/profileDialog.h b/examples/GuiClient/profileDialog.h deleted file mode 100644 index c1f912bf..00000000 --- a/examples/GuiClient/profileDialog.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef PROFILEDIALOG_H -#define PROFILEDIALOG_H - -#include <QDialog> -#include <QMap> -#include "capabilitiesCache.h" - -namespace Ui { - class profileDialog; -} - -class QXmppClient; -class QXmppVersionIq; -class QXmppEntityTimeIq; - -class profileDialog : public QDialog -{ - Q_OBJECT - -public: - explicit profileDialog(QWidget *parent, const QString& bareJid, QXmppClient& client, capabilitiesCache& caps); - ~profileDialog(); - - void setClientRef(QXmppClient& m_xmppClient); - void setAvatar(const QImage&); - void setBareJid(const QString&); - void setFullName(const QString&); - void setStatusText(const QString&); - -private slots: - void versionReceived(const QXmppVersionIq&); - void timeReceived(const QXmppEntityTimeIq&); - -private: - void updateText(); - QString getCapability(const QString& resource); - -private: - Ui::profileDialog *ui; - QString m_bareJid; - QXmppClient& m_xmppClient; // reference to the active QXmppClient (No ownership) - capabilitiesCache& m_caps; // reference to the active QXmppClient (No ownership) - QMap<QString, QXmppVersionIq> m_versions; - QMap<QString, QXmppEntityTimeIq> m_time; -}; - -#endif // PROFILEDIALOG_H diff --git a/examples/GuiClient/profileDialog.ui b/examples/GuiClient/profileDialog.ui deleted file mode 100644 index 84407c10..00000000 --- a/examples/GuiClient/profileDialog.ui +++ /dev/null @@ -1,205 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>profileDialog</class> - <widget class="QDialog" name="profileDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>309</width> - <height>209</height> - </rect> - </property> - <property name="windowTitle"> - <string>Profile</string> - </property> - <property name="sizeGripEnabled"> - <bool>true</bool> - </property> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <property name="margin"> - <number>6</number> - </property> - <item> - <widget class="QScrollArea" name="scrollArea"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> - </property> - <property name="widgetResizable"> - <bool>true</bool> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> - </property> - <widget class="QWidget" name="scrollAreaWidgetContents"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>297</width> - <height>168</height> - </rect> - </property> - <layout class="QVBoxLayout" name="verticalLayout_4"> - <property name="spacing"> - <number>6</number> - </property> - <property name="margin"> - <number>0</number> - </property> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <property name="sizeConstraint"> - <enum>QLayout::SetFixedSize</enum> - </property> - <item> - <widget class="QLabel" name="label_avatar"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="minimumSize"> - <size> - <width>96</width> - <height>96</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>96</width> - <height>96</height> - </size> - </property> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap resource="resources.qrc">:/icons/resource/avatar.png</pixmap> - </property> - <property name="scaledContents"> - <bool>true</bool> - </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <widget class="QLabel" name="label_fullName"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_jid"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item> - <widget class="QLabel" name="label_status"> - <property name="text"> - <string>TextLabel</string> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - <property name="textInteractionFlags"> - <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer_2"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>0</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Close</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="resources.qrc"/> - </resources> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>profileDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>343</x> - <y>215</y> - </hint> - <hint type="destinationlabel"> - <x>301</x> - <y>191</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>profileDialog</receiver> - <slot>close()</slot> - <hints> - <hint type="sourcelabel"> - <x>237</x> - <y>216</y> - </hint> - <hint type="destinationlabel"> - <x>230</x> - <y>172</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/examples/GuiClient/resource/addButton.png b/examples/GuiClient/resource/addButton.png Binary files differdeleted file mode 100644 index a1e620e8..00000000 --- a/examples/GuiClient/resource/addButton.png +++ /dev/null diff --git a/examples/GuiClient/resource/ajax-loader.gif b/examples/GuiClient/resource/ajax-loader.gif Binary files differdeleted file mode 100644 index 3288d103..00000000 --- a/examples/GuiClient/resource/ajax-loader.gif +++ /dev/null diff --git a/examples/GuiClient/resource/avatar.png b/examples/GuiClient/resource/avatar.png Binary files differdeleted file mode 100644 index 1a8111c7..00000000 --- a/examples/GuiClient/resource/avatar.png +++ /dev/null diff --git a/examples/GuiClient/resource/downArrow.png b/examples/GuiClient/resource/downArrow.png Binary files differdeleted file mode 100644 index 365684bd..00000000 --- a/examples/GuiClient/resource/downArrow.png +++ /dev/null diff --git a/examples/GuiClient/resource/gray.png b/examples/GuiClient/resource/gray.png Binary files differdeleted file mode 100644 index 152d8e18..00000000 --- a/examples/GuiClient/resource/gray.png +++ /dev/null diff --git a/examples/GuiClient/resource/green.png b/examples/GuiClient/resource/green.png Binary files differdeleted file mode 100644 index aed27a33..00000000 --- a/examples/GuiClient/resource/green.png +++ /dev/null diff --git a/examples/GuiClient/resource/icon.png b/examples/GuiClient/resource/icon.png Binary files differdeleted file mode 100644 index e6b17b18..00000000 --- a/examples/GuiClient/resource/icon.png +++ /dev/null diff --git a/examples/GuiClient/resource/icon.xcf b/examples/GuiClient/resource/icon.xcf Binary files differdeleted file mode 100644 index 8a56c227..00000000 --- a/examples/GuiClient/resource/icon.xcf +++ /dev/null diff --git a/examples/GuiClient/resource/orange.png b/examples/GuiClient/resource/orange.png Binary files differdeleted file mode 100644 index 9f6611c7..00000000 --- a/examples/GuiClient/resource/orange.png +++ /dev/null diff --git a/examples/GuiClient/resource/red.png b/examples/GuiClient/resource/red.png Binary files differdeleted file mode 100644 index 9f356080..00000000 --- a/examples/GuiClient/resource/red.png +++ /dev/null diff --git a/examples/GuiClient/resource/redred.png b/examples/GuiClient/resource/redred.png Binary files differdeleted file mode 100644 index 3cf1bc72..00000000 --- a/examples/GuiClient/resource/redred.png +++ /dev/null diff --git a/examples/GuiClient/resource/searchIcon.png b/examples/GuiClient/resource/searchIcon.png Binary files differdeleted file mode 100644 index d8c1e9bd..00000000 --- a/examples/GuiClient/resource/searchIcon.png +++ /dev/null diff --git a/examples/GuiClient/resource/settingsButton.png b/examples/GuiClient/resource/settingsButton.png Binary files differdeleted file mode 100644 index f569b63e..00000000 --- a/examples/GuiClient/resource/settingsButton.png +++ /dev/null diff --git a/examples/GuiClient/resources.qrc b/examples/GuiClient/resources.qrc deleted file mode 100644 index 67ec1dd8..00000000 --- a/examples/GuiClient/resources.qrc +++ /dev/null @@ -1,15 +0,0 @@ -<RCC> - <qresource prefix="/icons"> - <file>resource/green.png</file> - <file>resource/orange.png</file> - <file>resource/red.png</file> - <file>resource/gray.png</file> - <file>resource/avatar.png</file> - <file>resource/searchIcon.png</file> - <file>resource/downArrow.png</file> - <file>resource/ajax-loader.gif</file> - <file>resource/icon.png</file> - <file>resource/settingsButton.png</file> - <file>resource/addButton.png</file> - </qresource> -</RCC> diff --git a/examples/GuiClient/rosterItem.cpp b/examples/GuiClient/rosterItem.cpp deleted file mode 100644 index 19d2233d..00000000 --- a/examples/GuiClient/rosterItem.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "rosterItem.h" -#include <QImage> - -rosterItem::rosterItem(const QString& bareJid) -{ - setData(bareJid, rosterItem::BareJid); - setData("Offline", rosterItem::StatusText); - setAvatar(QImage(":/icons/resource/avatar.png")); - setIcon(QIcon(":/icons/resource/gray.png")); -} - -void rosterItem::setName(const QString& name) -{ - setText(name); -} - -QString rosterItem::getName() -{ - return text(); -} - -void rosterItem::setPresence(const QXmppPresence &presence) -{ - // determine status text - QString statusText = presence.statusText(); - if (statusText.isEmpty()) { - if(presence.type() == QXmppPresence::Available) - statusText = "Available"; - else if(presence.type() == QXmppPresence::Unavailable) - statusText = "Offline"; - } - - // store data - setData(statusText, rosterItem::StatusText); - setData(static_cast<int>(presence.type()), PresenceType); - setData(static_cast<int>(presence.availableStatusType()), StatusType); - - // update icon - QString icon; - if (presence.type() == QXmppPresence::Available) { - switch (presence.availableStatusType()) - { - case QXmppPresence::Online: - case QXmppPresence::Chat: - icon = "green"; - break; - case QXmppPresence::Away: - case QXmppPresence::XA: - icon = "orange"; - break; - case QXmppPresence::DND: - icon = "red"; - break; - case QXmppPresence::Invisible: - icon = "gray"; - break; - } - } else { - icon = "gray"; - } - if (!icon.isEmpty()) - setIcon(QIcon(":/icons/resource/"+icon+".png")); -} - -void rosterItem::setAvatar(const QImage& image) -{ - setData(QVariant(image), rosterItem::Avatar); -} - -QImage rosterItem::getAvatar() -{ - return qvariant_cast<QImage>(data(rosterItem::Avatar)); -} - -rosterItemDelegate::rosterItemDelegate() -{ -} - -QSize rosterItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex & index) const -{ - Q_UNUSED(option); - Q_UNUSED(index); - return QSize(44, 36); -} - -void rosterItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const -{ - painter->save(); - painter->setRenderHint(QPainter::TextAntialiasing); - QVariant value = index.data(Qt::DecorationRole); - - QColor selectedBg(60, 140, 222); - QColor alternateBg(239, 245, 254); - QColor selectedText(Qt::white); - - QColor nameTextColor(Qt::black); - QColor statusTextColor(Qt::darkGray); - - QPixmap pixmap; - if(value.type() == QVariant::Icon) - { - QIcon icon = qvariant_cast<QIcon>(value); - pixmap = icon.pixmap(QSize(16, 16), QIcon::Normal, QIcon::On); - } - - QPen penDivision; -// if(index.row() % 2) -// painter->fillRect(option.rect, alternateBg); - - if (option.state & QStyle::State_Selected) - { - painter->fillRect(option.rect, selectedBg); -// painter->fillRect(option.rect, option.palette.highlight()); -// penDivision.setColor(option.palette.highlight().color()); - penDivision.setColor(selectedBg); - nameTextColor = selectedText; - statusTextColor = selectedText; - } - else - { - penDivision.setColor(QColor(244, 244, 244)); - } - - QRect rect = option.rect; - rect.setWidth(pixmap.width()); - rect.setHeight(pixmap.height()); - rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); - rect.moveLeft(rect.left() + 2); - painter->drawPixmap(rect, pixmap); - - rect = option.rect; - rect.setLeft(rect.x() + pixmap.width() + 8); - rect.moveTop(rect.y() + 3); - QFont font; - painter->setFont(font); - painter->setPen(nameTextColor); - if(!index.data(Qt::DisplayRole).toString().isEmpty()) - painter->drawText(rect, index.data(Qt::DisplayRole).toString()); - else - painter->drawText(rect, index.data(rosterItem::BareJid).toString()); - - painter->setPen(statusTextColor); - rect.setTop(rect.y() + rect.height()/2); - rect.moveTop(rect.y() - 3); - QString statusText = index.data(rosterItem::StatusText).toString(); - QFontMetrics fontMetrics(font); - statusText = fontMetrics.elidedText(statusText, Qt::ElideRight, rect.width() - 34); - painter->drawText(rect, statusText); - - penDivision.setWidth(0); - painter->setPen(penDivision); - - rect = option.rect; - QPoint left = rect.bottomLeft(); - left.setX(left.x() + 4); - QPoint right = rect.bottomRight(); - right.setX(right.x() - 4); - painter->drawLine(left, right); - - QImage image; - value = index.data(rosterItem::Avatar); - if(value.type() == QVariant::Image) - { - image = qvariant_cast<QImage>(value); - } - - pixmap = QPixmap(":/icons/resource/avatar.png"); - rect = option.rect; - rect.setWidth(pixmap.width()); - rect.setHeight(pixmap.height()); - rect.moveTop(rect.y() + (option.rect.height() - pixmap.height())/2); - rect.moveLeft(option.rect.x() + option.rect.width() - pixmap.width() - 2); - -// if(image.isNull()) -// painter->drawPixmap(rect, pixmap); -// else - painter->drawImage(rect, image); - - painter->restore(); -} diff --git a/examples/GuiClient/rosterItem.h b/examples/GuiClient/rosterItem.h deleted file mode 100644 index 81ec93dd..00000000 --- a/examples/GuiClient/rosterItem.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEM_H -#define ROSTERITEM_H - -#include <QStandardItem> -#include <QItemDelegate> -#include <QPainter> -#include "QXmppPresence.h" - -class rosterItem : public QStandardItem -{ -public: - enum userRoles - { - StatusText = Qt::UserRole + 2, - StatusType, - PresenceType, - BareJid, - Avatar - }; - - rosterItem(const QString& bareJid); - - void setAvatar(const QImage& image); - void setPresence(const QXmppPresence &presence); - void setName(const QString& name); - QImage getAvatar(); - QString getName(); -}; - -class rosterItemDelegate : public QItemDelegate -{ -public: - rosterItemDelegate(); - QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; - void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; -}; - -#endif // ROSTERITEM_H diff --git a/examples/GuiClient/rosterItemModel.cpp b/examples/GuiClient/rosterItemModel.cpp deleted file mode 100644 index ef3a4545..00000000 --- a/examples/GuiClient/rosterItemModel.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "rosterItemModel.h" - -rosterItemModel::rosterItemModel(QObject* parent) : QStandardItemModel(parent) -{ -// addRosterItemIfDontExist("jkhjkhkhkhk"); -// addRosterItemIfDontExist("uuuu"); -// addRosterItemIfDontExist("kkkkkkk"); -// addRosterItemIfDontExist("jjjjjjjj"); -} - -rosterItem* rosterItemModel::getRosterItemFromBareJid(const QString& bareJid) -{ - if(m_jidRosterItemMap.contains(bareJid)) - return m_jidRosterItemMap[bareJid]; - else - return 0; -} - -rosterItem* rosterItemModel::getOrCreateItem(const QString& bareJid) -{ - if(m_jidRosterItemMap.contains(bareJid)) { - return m_jidRosterItemMap[bareJid]; - } else { - rosterItem* item = new rosterItem(bareJid); - m_jidRosterItemMap[bareJid] = item; - appendRow(item); - return item; - } -} - -void rosterItemModel::updatePresence(const QString& bareJid, const QMap<QString, QXmppPresence>& presences) -{ - rosterItem *item = getOrCreateItem(bareJid); - if (!presences.isEmpty()) - item->setPresence(*presences.begin()); - else - item->setPresence(QXmppPresence(QXmppPresence::Unavailable)); -} - -void rosterItemModel::updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry) -{ - getOrCreateItem(bareJid)->setName(rosterEntry.name()); -} - -void rosterItemModel::updateAvatar(const QString& bareJid, const QImage& image) -{ - getOrCreateItem(bareJid)->setAvatar(image); -} - -void rosterItemModel::updateName(const QString& bareJid, const QString& name) -{ - if (!name.isEmpty()) - getOrCreateItem(bareJid)->setName(name); -} - -void rosterItemModel::clear() -{ - QStandardItemModel::clear(); - m_jidRosterItemMap.clear(); -} - -void rosterItemModel::removeRosterEntry(const QString& bareJid) -{ - rosterItem* item = getRosterItemFromBareJid(bareJid); - if(item) - { - removeRow(item->row()); - } -} diff --git a/examples/GuiClient/rosterItemModel.h b/examples/GuiClient/rosterItemModel.h deleted file mode 100644 index 7efb91b4..00000000 --- a/examples/GuiClient/rosterItemModel.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEMMODEL_H -#define ROSTERITEMMODEL_H - -#include <QStandardItemModel> -#include "rosterItem.h" -#include "QXmppRosterManager.h" -#include "QXmppPresence.h" - -class rosterItemModel : public QStandardItemModel -{ -public: - rosterItemModel(QObject* parent); - rosterItem* getRosterItemFromBareJid(const QString& bareJid); - - void updatePresence(const QString& bareJid, const QMap<QString, QXmppPresence>& presences); - void updateRosterEntry(const QString& bareJid, const QXmppRosterIq::Item& rosterEntry); - void updateAvatar(const QString& bareJid, const QImage& image); - void updateName(const QString& bareJid, const QString& name); - - void removeRosterEntry(const QString& bareJid); - - void clear(); - -private: - rosterItem* getOrCreateItem(const QString& bareJid); - QMap<QString, rosterItem*> m_jidRosterItemMap; -}; - -#endif // ROSTERITEMMODEL_H diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp b/examples/GuiClient/rosterItemSortFilterProxyModel.cpp deleted file mode 100644 index cf47550a..00000000 --- a/examples/GuiClient/rosterItemSortFilterProxyModel.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "rosterItemSortFilterProxyModel.h" -#include "rosterItem.h" -#include "utils.h" - -rosterItemSortFilterProxyModel::rosterItemSortFilterProxyModel(QObject* parent): - QSortFilterProxyModel(parent), - m_showOfflineContacts(true), - m_sortByName(false) -{ - setDynamicSortFilter(true); - setFilterRole(Qt::DisplayRole); - setFilterCaseSensitivity(Qt::CaseInsensitive); -} - -bool rosterItemSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const -{ - if(m_sortByName) - { - int compare = left.data().toString().compare(right.data().toString(), Qt::CaseInsensitive); - if(compare < 0) - return true; - else - return false; - } - else - { - int leftPresenceType = sourceModel()->data(left, rosterItem::PresenceType).toInt(); - int leftStatusType = sourceModel()->data(left, rosterItem::StatusType).toInt(); - int rightPresenceType = sourceModel()->data(right, rosterItem::PresenceType).toInt(); - int rightStatusType = sourceModel()->data(right, rosterItem::StatusType).toInt(); - - if(leftPresenceType == rightPresenceType) - { - if(leftStatusType == rightStatusType) - { - // based on display text - int compare = left.data().toString().compare(right.data().toString(), Qt::CaseInsensitive); - if(compare < 0) - return true; - else - return false; - } - else - { - return comparisonWeightsPresenceStatusType(static_cast<QXmppPresence::AvailableStatusType>(leftStatusType)) < - comparisonWeightsPresenceStatusType(static_cast<QXmppPresence::AvailableStatusType>(rightStatusType)); - } - } - else - return comparisonWeightsPresenceType(static_cast<QXmppPresence::Type>(leftPresenceType)) < - comparisonWeightsPresenceType(static_cast<QXmppPresence::Type>(rightPresenceType)); - } -} - -bool rosterItemSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const -{ - if(!filterRegExp().isEmpty()) - return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent); - - if(m_showOfflineContacts) - return true; - - QModelIndex index = sourceModel()->index(source_row, 0, source_parent); - - int presenceType = sourceModel()->data(index, rosterItem::PresenceType).toInt(); - - if(presenceType == QXmppPresence::Available) - return true; - else - return false; -} - -void rosterItemSortFilterProxyModel::setShowOfflineContacts(bool showOfflineContacts) -{ - m_showOfflineContacts = showOfflineContacts; - invalidateFilter(); -} - -void rosterItemSortFilterProxyModel::sortByName(bool sortByName) -{ - m_sortByName = sortByName; - invalidate(); -} - diff --git a/examples/GuiClient/rosterItemSortFilterProxyModel.h b/examples/GuiClient/rosterItemSortFilterProxyModel.h deleted file mode 100644 index e4a413d3..00000000 --- a/examples/GuiClient/rosterItemSortFilterProxyModel.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERITEMSORTFILTERPROXYMODEL_H -#define ROSTERITEMSORTFILTERPROXYMODEL_H - -#include <QSortFilterProxyModel> - -class rosterItemSortFilterProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - -public: - rosterItemSortFilterProxyModel(QObject* parent = 0); - -public slots: - void setShowOfflineContacts(bool); - void sortByName(bool); - -private: - bool lessThan(const QModelIndex &left, const QModelIndex &right) const; - bool filterAcceptsRow(int, const QModelIndex&) const; - - bool m_showOfflineContacts; - bool m_sortByName; -}; - -#endif // ROSTERITEMSORTFILTERPROXYMODEL_H diff --git a/examples/GuiClient/rosterListView.cpp b/examples/GuiClient/rosterListView.cpp deleted file mode 100644 index a832f3e1..00000000 --- a/examples/GuiClient/rosterListView.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "rosterListView.h" -#include "rosterItem.h" -#include <QApplication> -#include <QMenu> -#include <QKeyEvent> - -rosterListView::rosterListView(QWidget* parent) - : QListView(parent) - , m_chat("Chat", this) - , m_profile("View Profile", this) - , m_removeContact("Remove", this) -{ - bool check; - Q_UNUSED(check); - - check = connect(this, SIGNAL(pressed(QModelIndex)), this, - SLOT(mousePressed(QModelIndex))); - Q_ASSERT(check); - check = connect(this, SIGNAL(doubleClicked(QModelIndex)), this, - SLOT(doubleClicked(QModelIndex))); - Q_ASSERT(check); - check = connect(this, SIGNAL(clicked(QModelIndex)), this, - SLOT(clicked(QModelIndex))); - Q_ASSERT(check); - check = connect(&m_chat, SIGNAL(triggered()), this, - SLOT(showChatDialog_helper())); - Q_ASSERT(check); - - check = connect(&m_profile, SIGNAL(triggered()), this, - SLOT(showProfile_helper())); - Q_ASSERT(check); - - check = connect(&m_removeContact, SIGNAL(triggered()), this, - SLOT(removeContact_helper())); - Q_ASSERT(check); -} - -bool rosterListView::event(QEvent* e) -{ - return QListView::event(e); -} - -void rosterListView::mousePressed(const QModelIndex& index) -{ - if(QApplication::mouseButtons() == Qt::RightButton) - { - QString bareJid = index.data().toString(); - QMenu menu(this); - menu.addAction(&m_chat); - menu.setDefaultAction(&m_chat); - menu.addAction(&m_profile); - menu.addAction(&m_removeContact); - menu.exec(QCursor::pos()); - } -} - -void rosterListView::doubleClicked(const QModelIndex& index) -{ - Q_UNUSED(index); - m_chat.trigger(); -} - -void rosterListView::clicked(const QModelIndex& index) -{ - Q_UNUSED(index); -} - -QString rosterListView::selectedBareJid() -{ - if(selectedIndexes().size() > 0) - return selectedIndexes().at(0).data(rosterItem::BareJid).toString(); - else - return ""; -} - -void rosterListView::showChatDialog_helper() -{ - QString bareJid = selectedBareJid(); - if(!bareJid.isEmpty()) - emit showChatDialog(bareJid); -} - -void rosterListView::showProfile_helper() -{ - QString bareJid = selectedBareJid(); - if(!bareJid.isEmpty()) - emit showProfile(bareJid); -} - -void rosterListView::keyPressEvent(QKeyEvent* event1) -{ - if(event1->key() == Qt::Key_Return) - { - showChatDialog_helper(); - } - QListView::keyPressEvent(event1); -} - -void rosterListView::removeContact_helper() -{ - QString bareJid = selectedBareJid(); - if(!bareJid.isEmpty()) - emit removeContact(bareJid); -} diff --git a/examples/GuiClient/rosterListView.h b/examples/GuiClient/rosterListView.h deleted file mode 100644 index 49d1ba04..00000000 --- a/examples/GuiClient/rosterListView.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef ROSTERLISTVIEW_H -#define ROSTERLISTVIEW_H - -#include <QListView> -#include <QAction> - -class rosterListView : public QListView -{ - Q_OBJECT - -public: - rosterListView(QWidget* parent = 0); - bool event(QEvent* e); - -public slots: - void mousePressed(const QModelIndex& index); - void doubleClicked(const QModelIndex& index); - void clicked(const QModelIndex& index); - -private slots: - void showChatDialog_helper(); - void showProfile_helper(); - void removeContact_helper(); - -protected: - void keyPressEvent(QKeyEvent*); - -signals: - void showChatDialog(const QString& bareJid); - void showProfile(const QString& bareJid); - void removeContact(const QString& bareJid); - -private: - QString selectedBareJid(); - -private: - QAction m_chat; - QAction m_profile; - QAction m_removeContact; -}; - -#endif // ROSTERLISTVIEW_H diff --git a/examples/GuiClient/searchLineEdit.cpp b/examples/GuiClient/searchLineEdit.cpp deleted file mode 100644 index b1b97d3d..00000000 --- a/examples/GuiClient/searchLineEdit.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "searchLineEdit.h" - -searchLineEdit::searchLineEdit(QWidget* parent):QLineEdit(parent) -{ - setMinimumSize(QSize(20, 24)); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - - setStyleSheet(":enabled { padding-right: 20px; padding-left: 20px }"); - clearButton = new searchClearButton(this); - clearButton->setVisible(true); - - clearButton->setCursor(Qt::ArrowCursor); - clearButton->setToolTip("Clear"); - connect(clearButton, SIGNAL(clicked()), this, SLOT(clear())); -} - -void searchLineEdit::paintEvent(QPaintEvent *e) { - QLineEdit::paintEvent(e); - QPainter painter(this); - - QImage image(":/icons/resource/searchIcon.png"); - - QRectF target(image.rect()); - target.moveCenter(QPointF(target.center().x()+2, target.center().y()+3)); - painter.drawImage(target, image, image.rect()); - - if (text().length() == 0 && (!hasFocus()) ) - { - painter.setPen(Qt::gray); - QRect r = rect(); - painter.drawText(24, r.height()/2+4, "Search Contacts"); - } - - if(text().isEmpty()) - clearButton->setVisible(false); - else - clearButton->setVisible(true); -} - -void searchLineEdit::resizeEvent(QResizeEvent*) -{ - clearButton->setParent(this); - clearButton->setGeometry(QRect(width()-23, - 0, - 24, 24)); -} - -void searchLineEdit::moveEvent(QMoveEvent*) -{ - clearButton->setParent(this); - clearButton->setGeometry(QRect(width()-23, 1, - 24, 24)); -} diff --git a/examples/GuiClient/searchLineEdit.h b/examples/GuiClient/searchLineEdit.h deleted file mode 100644 index b70e8b66..00000000 --- a/examples/GuiClient/searchLineEdit.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef SEARCHLINEEDIT_H -#define SEARCHLINEEDIT_H - -#include <QPushButton> -#include <QLineEdit> -#include <QPainter> - -class searchClearButton : public QPushButton -{ - Q_OBJECT - -public: - searchClearButton(QWidget *w) - : QPushButton(w) - { - setMinimumSize(24, 24); - setFixedSize(24, 24); - setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - } - void paintEvent(QPaintEvent *event) - { - Q_UNUSED(event); - QPainter painter(this); - int height = parentWidget()->geometry().height(); - int width = height; //parentWidget()->geometry().width(); - - painter.setRenderHint(QPainter::Antialiasing, true); - painter.setPen(Qt::white); - - float penwidth = isDown() ? 1.2 : - underMouse() ? 1.6 : 1.2; - painter.setBrush(Qt::red); - //painter.drawEllipse(4, 4, width - 8, height - 8); - QPen pen; - pen.setWidthF(penwidth); - pen.setColor(Qt::black); - painter.setPen(pen); - int border = 7; - painter.drawLine(border, border, width - border, height - border); - painter.drawLine(border, height - border, width - border, border); - } -}; - -class searchLineEdit : public QLineEdit -{ -public: - searchLineEdit(QWidget* parent = 0); - -protected: - virtual void paintEvent(QPaintEvent* e); - virtual void resizeEvent(QResizeEvent*); - virtual void moveEvent(QMoveEvent*); - -private: - QPushButton *clearButton; -}; - -#endif // SEARCHLINEEDIT_H diff --git a/examples/GuiClient/signInStatusLabel.cpp b/examples/GuiClient/signInStatusLabel.cpp deleted file mode 100644 index 91ea023b..00000000 --- a/examples/GuiClient/signInStatusLabel.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "signInStatusLabel.h" -#include <QFontMetrics> - -signInStatusLabel::signInStatusLabel(QWidget* parent):QLabel(parent), m_timer(this), - m_option(None) -{ - m_timer.setSingleShot(false); - - bool check = connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); - Q_ASSERT(check); - Q_UNUSED(check); -} - -void signInStatusLabel::setCustomText(const QString& text, signInStatusLabel::Option op, - int countDown) -{ - m_text = text; - m_option = op; - m_countDown = countDown; - switch(op) - { - case None: - m_timer.stop(); - m_postfix = ""; - break; - case WithProgressEllipsis: -// m_timer.start(400); - m_postfix = ""; - break; - case CountDown: - m_timer.start(1000); - m_postfix = ""; - break; - default: - m_timer.stop(); - m_postfix = ""; - break; - } - - if(m_option == CountDown) - setText(m_text.arg(m_countDown) + m_postfix); - else - setText(m_text + m_postfix); - - updateGeometry(); -} - -void signInStatusLabel::timeout() -{ - switch(m_option) - { - case None: - break; - case WithProgressEllipsis: - if(m_postfix == "") - m_postfix = "."; - else if(m_postfix == ".") - m_postfix = ".."; - else if(m_postfix == "..") - m_postfix = "..."; - else if(m_postfix == "...") - m_postfix = ""; - break; - case CountDown: - if(m_countDown == 0) - m_timer.stop(); - --m_countDown; - break; - default: - break; - } - - if(m_option == CountDown) - setText(m_text.arg(m_countDown) + m_postfix); - else - setText(m_text + m_postfix); - updateGeometry(); -} - -//QSize signInStatusLabel::sizeHint() const -//{ -// QFont font; -// QFontMetrics fm(font); -// return QSize(fm.width(m_text) + 15, 20); -//} diff --git a/examples/GuiClient/signInStatusLabel.h b/examples/GuiClient/signInStatusLabel.h deleted file mode 100644 index e11d1287..00000000 --- a/examples/GuiClient/signInStatusLabel.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef SIGNINSTATUSLABEL_H -#define SIGNINSTATUSLABEL_H - -#include <QLabel> -#include <QTimer> - -class signInStatusLabel : public QLabel -{ - Q_OBJECT - -public: - enum Option - { - None = 0, - WithProgressEllipsis, - CountDown - }; - signInStatusLabel(QWidget* parent = 0); - - void setCustomText(const QString& text, signInStatusLabel::Option op = None, - int countDown = 0); - -// QSize sizeHint() const; - -private slots: - void timeout(); - -private: - QTimer m_timer; - signInStatusLabel::Option m_option; - QString m_text; - QString m_postfix; - int m_countDown; -}; - -#endif // SIGNINSTATUSLABEL_H diff --git a/examples/GuiClient/statusAvatarWidget.cpp b/examples/GuiClient/statusAvatarWidget.cpp deleted file mode 100644 index d0d9968c..00000000 --- a/examples/GuiClient/statusAvatarWidget.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "statusAvatarWidget.h" -#include <QtGui/QPainter> - -statusAvatarWidget::statusAvatarWidget(QWidget* parent) - : QPushButton(parent) -{ -} - -void statusAvatarWidget::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - - QRect r = rect(); - - QPixmap pixmap = icon().pixmap(sizeHint(), QIcon::Normal, QIcon::On); - if(pixmap.isNull()) - pixmap = QPixmap(":/icons/resource/avatar.png"); - QRect pixRect(0, 0, 32, 32); - pixRect.moveCenter(r.center()); - painter.drawPixmap(pixRect, pixmap); - - if(underMouse() && !isDown()) - { - painter.drawRect(pixRect.adjusted(0, 0, -1, -1)); - QColor col(Qt::white); - col.setAlpha(80); - painter.fillRect(pixRect.adjusted(0, 0, -1, -1), col); - } - if(isDown()) - { - QColor col(Qt::white); - col.setAlpha(50); - painter.drawRect(pixRect.adjusted(1, 1, -2, -2)); - } -} - -QSize statusAvatarWidget::sizeHint() const -{ - return QSize(32, 32); -} diff --git a/examples/GuiClient/statusAvatarWidget.h b/examples/GuiClient/statusAvatarWidget.h deleted file mode 100644 index 5dcecdbe..00000000 --- a/examples/GuiClient/statusAvatarWidget.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSAVATARWIDGET_H -#define STATUSAVATARWIDGET_H - -#include <QPushButton> - -class statusAvatarWidget : public QPushButton -{ -public: - statusAvatarWidget(QWidget* parent = 0); - void paintEvent(QPaintEvent* event); - QSize sizeHint() const; -}; - -#endif // STATUSAVATARWIDGET_H diff --git a/examples/GuiClient/statusTextWidget.cpp b/examples/GuiClient/statusTextWidget.cpp deleted file mode 100644 index fa0a9126..00000000 --- a/examples/GuiClient/statusTextWidget.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "statusTextWidget.h" -#include <QHBoxLayout> -#include <QMenu> - -#include <QStyle> -#include <QStyleOptionFrameV2> - -QSize statusLineEdit::sizeHint() const -{ - QFont font; - QFontMetrics fm(font); - int width = fm.width(text()); - if(width <= (160 - 8)) - return QSize(width+8, 18); - else - return QSize(160, 18); -} - -void statusLineEditButton::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - - QStyleOptionButton panel; - initStyleOption(&panel); - QRect r = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &panel, this); - - QImage image(":/icons/resource/downArrow.png"); - QRect rectDelta(0, 0, 7, 4); - rectDelta.moveCenter(r.center()); - painter.drawImage(rectDelta, image); -} - -void statusLineEdit::focusInEvent(QFocusEvent* event) -{ - QLineEdit::focusInEvent(event); - QLineEdit::selectAll(); -} - -void statusLineEdit::mousePressEvent(QMouseEvent* event) -{ - QLineEdit::mousePressEvent(event); - QLineEdit::selectAll(); -} - -statusTextWidget::statusTextWidget(QWidget* parent) - : QWidget(parent) - , m_statusLineEdit(0) - , m_statusButton(0) - , m_clearStatusTextHistory("Clear Status Message", this) -{ - bool check; - Q_UNUSED(check); - - m_statusLineEdit = new statusLineEdit(this); - QHBoxLayout* layout = new QHBoxLayout; - layout->addWidget(m_statusLineEdit); - layout->setSpacing(0); - layout->setContentsMargins(0, 0, 0, 0); - m_statusButton = new statusLineEditButton(this); - layout->addWidget(m_statusButton); - setLayout(layout); - - check = connect(m_statusButton, SIGNAL(clicked(bool)), SLOT(showMenu())); - Q_ASSERT(check); - - check = connect(m_statusLineEdit, SIGNAL(textChanged(QString)), SLOT(textChanged())); - Q_ASSERT(check); - - check = connect(m_statusLineEdit, SIGNAL(editingFinished()), SLOT(statusTextChanged_helper())); - Q_ASSERT(check); - - check = connect(&m_clearStatusTextHistory, SIGNAL(triggered()), SLOT(clearStatusTextHistory())); - Q_ASSERT(check); -} - -void statusTextWidget::showMenu() -{ - QMenu menu(this); - - int size = m_statusTextActionList.size(); - for(int i = 0; i < size; ++i) - { - menu.addAction(m_statusTextActionList.at(size - 1 - i)); - } - - menu.addSeparator(); - menu.addAction(&m_clearStatusTextHistory); - m_clearStatusTextHistory.setDisabled(size == 0); - menu.exec(m_statusLineEdit->mapToGlobal(QPoint(0, m_statusLineEdit->height()))); -} - -void statusTextWidget::textChanged() -{ - m_statusLineEdit->updateGeometry(); -} - -void statusTextWidget::statusTextChanged_helper() -{ - addStatusTextToList(m_statusLineEdit->text()); - emit statusTextChanged(m_statusLineEdit->text()); - parentWidget()->setFocus(); -} - -void statusTextWidget::setStatusText(const QString& statusText) -{ - m_statusLineEdit->setText(statusText); -} - -void statusTextWidget::addStatusTextToList(const QString& status) -{ - for(int i = 0; i < m_statusTextActionList.size(); ++i) - { - if(m_statusTextActionList.at(i)->data().toString() == status) - { - QAction* action = m_statusTextActionList.takeAt(i); - m_statusTextActionList.append(action); - return; - } - } - - QAction* action = new QAction(status, this); - action->setData(status); - bool check = connect(action, SIGNAL(triggered()), SLOT(statusTextChanged_menuClick())); - Q_ASSERT(check); - Q_UNUSED(check); - m_statusTextActionList.append(action); -} - -void statusTextWidget::statusTextChanged_menuClick() -{ - QAction* action = qobject_cast<QAction*>(sender()); - if(action) - { - int i = 0; - while(i < m_statusTextActionList.size() && action != m_statusTextActionList.at(i)) - { - ++i; - } - - if(action == m_statusTextActionList.at(i)) - { - m_statusTextActionList.removeAt(i); - m_statusTextActionList.append(action); - } - m_statusLineEdit->setText(action->data().toString()); - emit statusTextChanged(action->data().toString()); - } -} - -void statusTextWidget::clearStatusTextHistory() -{ - emit statusTextChanged(""); -} diff --git a/examples/GuiClient/statusTextWidget.h b/examples/GuiClient/statusTextWidget.h deleted file mode 100644 index ca280672..00000000 --- a/examples/GuiClient/statusTextWidget.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSTEXTWIDGET_H -#define STATUSTEXTWIDGET_H - -#include <QWidget> -#include <QAction> -#include <QLineEdit> -#include <QPainter> -#include <QPushButton> -#include <QStyleOptionFrameV2> -#include <QFontMetrics> - - -class statusLineEditButton : public QPushButton -{ - Q_OBJECT - -public: - statusLineEditButton(QWidget* parent = 0): QPushButton(parent) - { - setCursor(Qt::PointingHandCursor); - } - void paintEvent(QPaintEvent* event); - QSize sizeHint() const - { - return QSize(14, 14); - } -}; - -class statusLineEdit : public QLineEdit -{ -public: - statusLineEdit(QWidget* parent = 0) : QLineEdit(parent) - { - setAttribute(Qt::WA_Hover, true); - setText("Available"); - setMinimumSize(QSize(20, 18)); - } - void focusInEvent(QFocusEvent* event); - void mousePressEvent(QMouseEvent* event); - - void paintEvent(QPaintEvent* event) - { - if(hasFocus()) - { - QLineEdit::paintEvent(event); - } - else - { - QPainter p(this); - QRect r = rect(); - QPalette pal = palette(); - - QStyleOptionFrameV2 panel; - initStyleOption(&panel); - r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.adjust(-1, -1, 0, 0); - r.setLeft(r.left() + 4); - p.setPen(Qt::darkGray); - p.drawText(r, Qt::AlignVCenter, text()); - } - - if(underMouse() && !hasFocus()) - { - QPainter p(this); - QRect r = rect(); - QPalette pal = palette(); - - QStyleOptionFrameV2 panel; - initStyleOption(&panel); - r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); - r.adjust(-1, -1, 0, 0); - p.setPen(Qt::gray); - p.drawRect(r); - r.setLeft(r.left() + 4); - p.setPen(Qt::darkGray); - p.drawText(r, Qt::AlignVCenter, text()); - } - } - QSize sizeHint() const; -}; - -class statusTextWidget : public QWidget -{ - Q_OBJECT - -public: - statusTextWidget(QWidget* parent = 0); - void setStatusText(const QString& statusText); - -public slots: - void showMenu(); - void textChanged(); - -private slots: - void statusTextChanged_helper(); - void statusTextChanged_menuClick(); - void clearStatusTextHistory(); - -signals: - void statusTextChanged(const QString&); - -private: - void addStatusTextToList(const QString& status); - statusLineEdit* m_statusLineEdit; - statusLineEditButton* m_statusButton; - - QList<QAction*> m_statusTextActionList; - QAction m_clearStatusTextHistory; -}; - -#endif // STATUSTEXTWIDGET_H diff --git a/examples/GuiClient/statusToolButton.cpp b/examples/GuiClient/statusToolButton.cpp deleted file mode 100644 index c14bc324..00000000 --- a/examples/GuiClient/statusToolButton.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "statusToolButton.h" -#include <QPainter> -#include <QStyle> -#include <QStyleOptionToolButton> - -statusToolButton::statusToolButton(QWidget* parent) : QToolButton(parent) -{ - setMinimumSize(QSize(20, 18)); -} - -void statusToolButton::paintEvent(QPaintEvent* event) -{ - Q_UNUSED(event); - QPainter painter(this); - if(underMouse()) - { - QStyleOptionToolButton panel; - initStyleOption(&panel); - style()->drawPrimitive(QStyle::PE_PanelButtonTool, &panel, &painter, this); - } - QRect r = rect(); - QFont font; - painter.setFont(font); - painter.setPen(Qt::gray); - - QRect rectSize(0, 0, sizeHint().width(), sizeHint().height()); - rectSize.moveCenter(r.center()); - r = rectSize; - r.adjust(0, 0, -1, -1); - painter.setPen(Qt::black); - painter.setBrush(Qt::black); - r.moveLeft(r.left() + 3); - font.setBold(true); - painter.setFont(font); - painter.drawText(r, Qt::AlignVCenter|Qt::TextSingleLine, text()); - - QImage image(":/icons/resource/downArrow.png"); - QRect rectDelta(0, 0, 7, 4); - rectDelta.moveRight(r.right() - 4); - rectDelta.moveCenter(QPoint(rectDelta.center().x(), r.center().y())); - painter.drawImage(rectDelta, image); -} - -QSize statusToolButton::sizeHint() const -{ - QFont font; - font.setBold(true); - QFontMetrics fm(font); - int width = fm.width(text()); - if(width <= (160 - 8 - 9)) - return QSize(width+8+9, 18); - else - return QSize(160, 18); -} diff --git a/examples/GuiClient/statusToolButton.h b/examples/GuiClient/statusToolButton.h deleted file mode 100644 index 9bc1a03f..00000000 --- a/examples/GuiClient/statusToolButton.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSTOOLBUTTON_H -#define STATUSTOOLBUTTON_H - -#include <QToolButton> - -class statusToolButton : public QToolButton -{ -public: - statusToolButton(QWidget* parent = 0); - void paintEvent(QPaintEvent* event); - QSize sizeHint() const; -}; - -#endif // STATUSTOOLBUTTON_H diff --git a/examples/GuiClient/statusWidget.cpp b/examples/GuiClient/statusWidget.cpp deleted file mode 100644 index c18e78e4..00000000 --- a/examples/GuiClient/statusWidget.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "statusWidget.h" - -#include <QMenu> -#include <QFileDialog> -#include <QMessageBox> - -statusWidget::statusWidget(QWidget* parent) - : QWidget(parent) -{ - bool check; - Q_UNUSED(check); - - setupUi(this); - - QMenu* menu = new QMenu(this); - menu->addAction(actionAvailable); - menu->addAction(actionBusy); - menu->addAction(actionAway); -// menu->addAction(actionInvisible); - menu->addSeparator(); - menu->addAction(actionSign_out); - toolButton_userName->setMenu(menu); - - check = connect(statusTextWidgetObject, SIGNAL(statusTextChanged(QString)), SIGNAL(statusTextChanged(QString))); - Q_ASSERT(check); - - check = connect(actionAvailable, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - - check = connect(actionBusy, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - - check = connect(actionAway, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - -// check = connect(actionInvisible, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); -// Q_ASSERT(check); - - check = connect(actionSign_out, SIGNAL(triggered()), SLOT(presenceMenuTriggered())); - Q_ASSERT(check); - - check = connect(pushButton_avatar, SIGNAL(clicked()), SLOT(avatarSelection())); - Q_ASSERT(check); -} - -void statusWidget::setStatusText(const QString& statusText) -{ - statusTextWidgetObject->setStatusText(statusText); -} - -void statusWidget::presenceMenuTriggered() -{ - QString icon = "green"; - QAction* action = qobject_cast<QAction*>(sender()); - if(action == actionAvailable) - { - emit presenceTypeChanged(QXmppPresence::Available); - icon = "green"; - } - else if(action == actionBusy) - { - emit presenceStatusTypeChanged(QXmppPresence::DND); - icon = "red"; - } - else if(action == actionAway) - { - emit presenceStatusTypeChanged(QXmppPresence::Away); - icon = "orange"; - } -#if 0 - else if(action == actionInvisible) - { - emit presenceStatusTypeChanged(QXmppPresence::Invisible); - icon = "gray"; - } -#endif - else if(action == actionSign_out) - { - emit presenceTypeChanged(QXmppPresence::Unavailable); - icon = "gray"; - } - label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); -} - -void statusWidget::setPresenceAndStatusType(QXmppPresence::Type presenceType, - QXmppPresence::AvailableStatusType statusType) -{ - if(presenceType == QXmppPresence::Available) - { - QString icon = "green"; - switch(statusType) - { - case QXmppPresence::Online: - case QXmppPresence::Chat: - icon = "green"; - break; - case QXmppPresence::Away: - case QXmppPresence::XA: - icon = "orange"; - break; - case QXmppPresence::DND: - icon = "red"; - break; - case QXmppPresence::Invisible: - icon = "gray"; - break; - } - label->setPixmap(QPixmap(":/icons/resource/"+icon+".png")); - } - else if(presenceType == QXmppPresence::Unavailable) - { - label->setPixmap(QPixmap(":/icons/resource/gray.png")); - } -} - -void statusWidget::avatarSelection() -{ - QString fileFilters = QString("Images (*.png *.jpeg *.jpg *.gif *.bmp);;All Files (*.*)"); - QString file = QFileDialog::getOpenFileName(this, "Select your avatar", - QString(), fileFilters); - if(file.isEmpty()) - return; - - QImage image; - if(image.load(file)) - { - QImage scaled = image.scaled(QSize(96, 96), Qt::KeepAspectRatio, - Qt::SmoothTransformation); - emit avatarChanged(scaled); - } - else - QMessageBox::information(this, "Avatar selection", "Invalid image file"); -} - -void statusWidget::setDisplayName(const QString& name) -{ - toolButton_userName->setText(name); -} - -void statusWidget::setAvatar(const QImage& image) -{ - pushButton_avatar->setIcon(QIcon(QPixmap::fromImage(image))); -} diff --git a/examples/GuiClient/statusWidget.h b/examples/GuiClient/statusWidget.h deleted file mode 100644 index f8e1f5f7..00000000 --- a/examples/GuiClient/statusWidget.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef STATUSWIDGET_H -#define STATUSWIDGET_H - -#include "ui_statusWidget.h" - -#include "QXmppPresence.h" - -/// Main Widget for the client's status/status text/avatar management - -class statusWidget : public QWidget, public Ui::statusWidgetClass -{ - Q_OBJECT - -public: - statusWidget(QWidget* parent = 0); - - void setDisplayName(const QString& name); - void setStatusText(const QString& statusText); - void setPresenceAndStatusType(QXmppPresence::Type presenceType, - QXmppPresence::AvailableStatusType statusType); - void setAvatar(const QImage&); - -private slots: - void presenceMenuTriggered(); - void avatarSelection(); - -signals: - void statusTextChanged(const QString&); - void presenceTypeChanged(QXmppPresence::Type); - void presenceStatusTypeChanged(QXmppPresence::AvailableStatusType); - void avatarChanged(const QImage&); -}; - -#endif // STATUSWIDGET_H diff --git a/examples/GuiClient/statusWidget.ui b/examples/GuiClient/statusWidget.ui deleted file mode 100644 index abd9ce35..00000000 --- a/examples/GuiClient/statusWidget.ui +++ /dev/null @@ -1,213 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>statusWidgetClass</class> - <widget class="QWidget" name="statusWidgetClass"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>251</width> - <height>40</height> - </rect> - </property> - <property name="windowTitle"> - <string>Form</string> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <property name="spacing"> - <number>0</number> - </property> - <property name="leftMargin"> - <number>4</number> - </property> - <property name="topMargin"> - <number>0</number> - </property> - <property name="rightMargin"> - <number>4</number> - </property> - <property name="bottomMargin"> - <number>0</number> - </property> - <item> - <widget class="QLabel" name="label"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string/> - </property> - <property name="pixmap"> - <pixmap resource="resources.qrc">:/icons/resource/green.png</pixmap> - </property> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <property name="leftMargin"> - <number>3</number> - </property> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <property name="spacing"> - <number>0</number> - </property> - <item> - <widget class="statusToolButton" name="toolButton_userName"> - <property name="text"> - <string>toolbutton</string> - </property> - <property name="popupMode"> - <enum>QToolButton::InstantPopup</enum> - </property> - <property name="toolButtonStyle"> - <enum>Qt::ToolButtonTextBesideIcon</enum> - </property> - <property name="autoRaise"> - <bool>true</bool> - </property> - <property name="arrowType"> - <enum>Qt::DownArrow</enum> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>10</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="spacing"> - <number>0</number> - </property> - <item> - <widget class="statusTextWidget" name="statusTextWidgetObject" native="true"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer_2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>10</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - </layout> - </item> - <item> - <widget class="statusAvatarWidget" name="pushButton_avatar"> - <property name="text"> - <string/> - </property> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/avatar.png</normaloff>:/icons/resource/avatar.png</iconset> - </property> - <property name="iconSize"> - <size> - <width>32</width> - <height>32</height> - </size> - </property> - </widget> - </item> - </layout> - <action name="actionBusy"> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/red.png</normaloff>:/icons/resource/red.png</iconset> - </property> - <property name="text"> - <string>Busy</string> - </property> - </action> - <action name="actionAvailable"> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/green.png</normaloff>:/icons/resource/green.png</iconset> - </property> - <property name="text"> - <string>Available</string> - </property> - </action> - <action name="actionInvisible"> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/gray.png</normaloff>:/icons/resource/gray.png</iconset> - </property> - <property name="text"> - <string>Invisible</string> - </property> - </action> - <action name="actionSign_out"> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/gray.png</normaloff>:/icons/resource/gray.png</iconset> - </property> - <property name="text"> - <string>Sign out</string> - </property> - </action> - <action name="actionAway"> - <property name="icon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/orange.png</normaloff>:/icons/resource/orange.png</iconset> - </property> - <property name="text"> - <string>Away</string> - </property> - </action> - </widget> - <customwidgets> - <customwidget> - <class>statusAvatarWidget</class> - <extends>QPushButton</extends> - <header>statusAvatarWidget.h</header> - </customwidget> - <customwidget> - <class>statusTextWidget</class> - <extends>QWidget</extends> - <header>statusTextWidget.h</header> - <container>1</container> - </customwidget> - <customwidget> - <class>statusToolButton</class> - <extends>QToolButton</extends> - <header>statusToolButton.h</header> - </customwidget> - </customwidgets> - <resources> - <include location="resources.qrc"/> - </resources> - <connections/> -</ui> diff --git a/examples/GuiClient/utils.cpp b/examples/GuiClient/utils.cpp deleted file mode 100644 index 9006fbbf..00000000 --- a/examples/GuiClient/utils.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "utils.h" -#include <QDir> -#if QT_VERSION >= 0x050000 -#include <QStandardPaths> -#else -#include <QDesktopServices> -#endif - -int comparisonWeightsPresenceStatusType(QXmppPresence::AvailableStatusType statusType) -{ - switch(statusType) - { - case QXmppPresence::Online: - case QXmppPresence::Chat: - return 0; - case QXmppPresence::DND: - return 1; - case QXmppPresence::Away: - case QXmppPresence::XA: - return 2; - case QXmppPresence::Invisible: - return 3; - default: - return 5; - } -} - -int comparisonWeightsPresenceType(QXmppPresence::Type type) -{ - switch(type) - { - case QXmppPresence::Available: - return 0; - case QXmppPresence::Unavailable: - return 1; - case QXmppPresence::Error: - case QXmppPresence::Subscribe: - case QXmppPresence::Subscribed: - case QXmppPresence::Unsubscribe: - case QXmppPresence::Unsubscribed: - case QXmppPresence::Probe: - return 3; - default: - return 5; - } -} - -QString presenceToStatusText(const QXmppPresence& presence) -{ - QString statusText = presence.statusText(); - if(statusText.isEmpty()) - { - if(presence.type() == QXmppPresence::Available) - { - switch(presence.availableStatusType()) - { - case QXmppPresence::Invisible: - statusText = "Offline"; - break; - case QXmppPresence::Online: - case QXmppPresence::Chat: - statusText = "Available"; - break; - case QXmppPresence::Away: - case QXmppPresence::XA: - statusText = "Idle"; - break; - case QXmppPresence::DND: - statusText = "Busy"; - break; - } - } - else - statusText = "Offline"; - } - - return statusText; -} - -QString getSettingsDir(const QString& bareJid) -{ -#if QT_VERSION >= 0x050000 - QStringList dirList = QStandardPaths::standardLocations(QStandardPaths::DataLocation); - QString dir = dirList.size() > 0 ? dirList.at(0) : ""; -#else - QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); -#endif - if(bareJid.isEmpty()) - return dir + "/"; - else - return QString(dir + "/%1/").arg(bareJid); -} - -QString getSha1HashAsHex(const QByteArray& image) -{ - if(image.isEmpty()) - return ""; - else - return QString(QCryptographicHash::hash(image, - QCryptographicHash::Sha1).toHex()); -} - -QImage getImageFromByteArray(const QByteArray& image) -{ - QBuffer buffer; - buffer.setData(image); - buffer.open(QIODevice::ReadOnly); - QImageReader imageReader(&buffer); - return imageReader.read(); -} - -QString getImageType1(const QByteArray& image) -{ - QBuffer buffer; - buffer.setData(image); - buffer.open(QIODevice::ReadOnly); - QString format = QImageReader::imageFormat(&buffer); - - if(format.toUpper() == "PNG") - return "image/png"; - else if(format.toUpper() == "MNG") - return "video/x-mng"; - else if(format.toUpper() == "GIF") - return "image/gif"; - else if(format.toUpper() == "BMP") - return "image/bmp"; - else if(format.toUpper() == "XPM") - return "image/x-xpm"; - else if(format.toUpper() == "SVG") - return "image/svg+xml"; - else if(format.toUpper() == "JPEG") - return "image/jpeg"; - - return "image/unknown"; -} - -bool isValidBareJid(const QString& bareJid) -{ - QRegExp re("^[^@]+@[^@]+$"); - return re.exactMatch(bareJid); -} - -QByteArray calculateXor(const QByteArray& data, const QByteArray& key) -{ - if(key.isEmpty()) - return data; - - QByteArray result; - for(int i = 0 , j = 0; i < data.length(); ++i , ++j) - { - if(j == key.length()) - j = 0; - result.append(data.at(i) ^ key.at(j)); - } - return result; -} diff --git a/examples/GuiClient/utils.h b/examples/GuiClient/utils.h deleted file mode 100644 index a7f0df90..00000000 --- a/examples/GuiClient/utils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef CLIENTUTILS_H -#define CLIENTUTILS_H - -#include "QXmppPresence.h" - -#include <QCryptographicHash> -#include <QBuffer> -#include <QImageReader> - -int comparisonWeightsPresenceStatusType(QXmppPresence::AvailableStatusType); -int comparisonWeightsPresenceType(QXmppPresence::Type); - -QString presenceToStatusText(const QXmppPresence& presence); - -QString getSettingsDir(const QString& bareJid = ""); - -QString getSha1HashAsHex(const QByteArray& image); -QImage getImageFromByteArray(const QByteArray& image); -QString getImageType1(const QByteArray& image); - -bool isValidBareJid(const QString& bareJid); - -QByteArray calculateXor(const QByteArray& data, const QByteArray& key); - -#endif // CLIENTUTILS_H diff --git a/examples/GuiClient/vCardCache.cpp b/examples/GuiClient/vCardCache.cpp deleted file mode 100644 index ede247c0..00000000 --- a/examples/GuiClient/vCardCache.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "vCardCache.h" -#include "utils.h" - -#include "QXmppClient.h" -#include "QXmppUtils.h" -#include "QXmppVCardManager.h" - -#include <QDir> -#include <QDomDocument> -#include <QCoreApplication> - -vCardCache::vCardCache(QXmppClient* client) : QObject(client), - m_client(client) -{ -} - -void vCardCache::vCardReceived(const QXmppVCardIq& vcard) -{ - QString from = vcard.from(); - - if(from.isEmpty() && m_client) - from = m_client->configuration().jidBare(); - - m_mapBareJidVcard[from] = vcard; - - saveToFile(from); - - emit vCardReadyToUse(from); -} - -bool vCardCache::isVCardAvailable(const QString& bareJid) const -{ - return m_mapBareJidVcard.contains(bareJid); -} - -// TODO don't request again, if it is already requested -void vCardCache::requestVCard(const QString& bareJid) -{ - if(m_client) - m_client->vCardManager().requestVCard(bareJid); -} - -//TODO not a good way to handle -QXmppVCardIq& vCardCache::getVCard(const QString& bareJid) -{ - return m_mapBareJidVcard[bareJid]; -} - -void vCardCache::saveToFile(const QString& bareJid) -{ - QDir dir; - if(!dir.exists(getSettingsDir(m_client->configuration().jidBare()))) - dir.mkpath(getSettingsDir(m_client->configuration().jidBare())); - - QDir dir2; - if(!dir2.exists(getSettingsDir(m_client->configuration().jidBare())+ "vCards/")) - dir2.mkpath(getSettingsDir(m_client->configuration().jidBare())+ "vCards/"); - - if(m_mapBareJidVcard.contains(bareJid)) - { - QString fileVCard = getSettingsDir(m_client->configuration().jidBare()) + "vCards/" + bareJid + ".xml"; - QFile file(fileVCard); - - if(file.open(QIODevice::ReadWrite)) - { - QXmlStreamWriter stream(&file); - stream.setAutoFormatting(true); - stream.setAutoFormattingIndent(2); - m_mapBareJidVcard[bareJid].toXml(&stream); - file.close(); - } - } -} - -void vCardCache::loadFromFile() -{ - m_mapBareJidVcard.clear(); - - QDir dirVCards(getSettingsDir(m_client->configuration().jidBare())+ "vCards/"); - if(dirVCards.exists()) - { - QStringList list = dirVCards.entryList(QStringList("*.xml")); - foreach(QString fileName, list) - { - QFile file(getSettingsDir(m_client->configuration().jidBare())+ "vCards/" + fileName); - QString bareJid = fileName; - bareJid.chop(4); - if(file.open(QIODevice::ReadOnly)) - { - QDomDocument doc; - if(doc.setContent(&file, true)) - { - QXmppVCardIq vCardIq; - vCardIq.parse(doc.documentElement()); - m_mapBareJidVcard[bareJid] = vCardIq; - QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - } - } - } - } -} - -//TODO: this should return scaled image -QImage vCardCache::getAvatar(const QString& bareJid) const -{ - if(m_mapBareJidVcard.contains(bareJid)) - return getImageFromByteArray(m_mapBareJidVcard[bareJid].photo()); - else - return QImage(); -} - -QByteArray vCardCache::getPhotoHash(const QString& bareJid) const -{ - if(!m_mapBareJidVcard.contains(bareJid)) - return QByteArray(); - - if(m_mapBareJidVcard[bareJid].photo().isEmpty()) - return QByteArray(); - else - return QCryptographicHash::hash(m_mapBareJidVcard[bareJid].photo(), - QCryptographicHash::Sha1); -} diff --git a/examples/GuiClient/vCardCache.h b/examples/GuiClient/vCardCache.h deleted file mode 100644 index 0f5c6dd2..00000000 --- a/examples/GuiClient/vCardCache.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef VCARDCACHE_H -#define VCARDCACHE_H - -#include <QObject> -#include <QMap> -#include "QXmppVCardIq.h" - -class QImage; -class QXmppClient; - -class vCardCache : public QObject -{ - Q_OBJECT - -public: - vCardCache(QXmppClient* client); - - bool isVCardAvailable(const QString& bareJid) const; - void requestVCard(const QString& bareJid); - QXmppVCardIq& getVCard(const QString& bareJid); - QImage getAvatar(const QString& bareJid) const; - - void loadFromFile(); - - QByteArray getPhotoHash(const QString& bareJid) const; - -signals: - void vCardReadyToUse(const QString& bareJid); - -public slots: - void vCardReceived(const QXmppVCardIq&); - -private: - void saveToFile(const QString& bareJid); - - QXmppClient* m_client; - QMap<QString, QXmppVCardIq> m_mapBareJidVcard; -}; - -#endif // VCARDCACHE_H diff --git a/examples/GuiClient/xmlConsoleDialog.cpp b/examples/GuiClient/xmlConsoleDialog.cpp deleted file mode 100644 index da52a1db..00000000 --- a/examples/GuiClient/xmlConsoleDialog.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#include "xmlConsoleDialog.h" -#include "ui_xmlConsoleDialog.h" - -#include <QDomDocument> -#include <QTextStream> - -static QString s_colorHexSent("#02aa3f"); -static QString s_colorHexReceived("#aa0000"); - -xmlConsoleDialog::xmlConsoleDialog(QWidget *parent) : - QDialog(parent, Qt::Window), - ui(new Ui::xmlConsoleDialog) -{ - ui->setupUi(this); - setWindowTitle("Debugging Console"); - - ui->label_legend->setText( - QString("<html><body><p><span style=\"color:%1\">Sent</span><span> | </span><span style=\"color:%2\">Received</span></p></body></html>").arg(s_colorHexSent).arg(s_colorHexReceived)); -} - -xmlConsoleDialog::~xmlConsoleDialog() -{ - delete ui; -} - -void xmlConsoleDialog::message(QXmppLogger::MessageType type, const QString& text) -{ - if(!ui->checkBox_enable->isChecked()) - return; - - QColor color; - switch(type) - { - case QXmppLogger::ReceivedMessage: - color = QColor(s_colorHexReceived); - break; - case QXmppLogger::SentMessage: - color = QColor(s_colorHexSent); - break; - default: - return; - } - - QDomDocument doc; - -// Indent XML string - bool isXml = doc.setContent(text); - QString formattedText; - QTextStream stream(&formattedText); - doc.save(stream, 2); - - ui->textBrowser->setTextColor(color); - if(isXml) - ui->textBrowser->append(formattedText); - else - ui->textBrowser->append(text); -} diff --git a/examples/GuiClient/xmlConsoleDialog.h b/examples/GuiClient/xmlConsoleDialog.h deleted file mode 100644 index 5bc974ed..00000000 --- a/examples/GuiClient/xmlConsoleDialog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef XMLCONSOLEDIALOG_H -#define XMLCONSOLEDIALOG_H - -#include <QDialog> -#include "QXmppLogger.h" - -namespace Ui { - class xmlConsoleDialog; -} - -class xmlConsoleDialog : public QDialog -{ - Q_OBJECT - -public: - explicit xmlConsoleDialog(QWidget *parent = 0); - ~xmlConsoleDialog(); - -public slots: - void message(QXmppLogger::MessageType, const QString &); - -private: - Ui::xmlConsoleDialog *ui; -}; - -#endif // XMLCONSOLEDIALOG_H diff --git a/examples/GuiClient/xmlConsoleDialog.ui b/examples/GuiClient/xmlConsoleDialog.ui deleted file mode 100644 index 61a3a1e2..00000000 --- a/examples/GuiClient/xmlConsoleDialog.ui +++ /dev/null @@ -1,139 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>xmlConsoleDialog</class> - <widget class="QDialog" name="xmlConsoleDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>569</width> - <height>349</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <property name="windowIcon"> - <iconset resource="resources.qrc"> - <normaloff>:/icons/resource/icon.png</normaloff>:/icons/resource/icon.png</iconset> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="margin"> - <number>6</number> - </property> - <item> - <widget class="QTextBrowser" name="textBrowser"/> - </item> - <item> - <widget class="QLabel" name="label_legend"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QCheckBox" name="checkBox_enable"> - <property name="text"> - <string>Enable</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item> - <spacer name="horizontalSpacer"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item> - <widget class="QPushButton" name="pushButton_clear"> - <property name="text"> - <string>Clear</string> - </property> - </widget> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel</set> - </property> - </widget> - </item> - </layout> - </item> - </layout> - </widget> - <resources> - <include location="resources.qrc"/> - </resources> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>xmlConsoleDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>389</x> - <y>289</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>xmlConsoleDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>389</x> - <y>289</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>pushButton_clear</sender> - <signal>clicked()</signal> - <receiver>textBrowser</receiver> - <slot>clear()</slot> - <hints> - <hint type="sourcelabel"> - <x>257</x> - <y>283</y> - </hint> - <hint type="destinationlabel"> - <x>178</x> - <y>202</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/examples/example_4_callHandling/example_4_callHandling.cpp b/examples/example_4_callHandling/example_4_callHandling.cpp deleted file mode 100644 index c2989f3b..00000000 --- a/examples/example_4_callHandling/example_4_callHandling.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Authors: - * Ian Reinhart Geiser - * Jeremy Lainé - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - -#include <cstdlib> -#include <cstdio> - -#include <QAudioInput> -#include <QAudioOutput> -#include <QCoreApplication> -#include <QDebug> -#include <QHostInfo> - -#include "QXmppCallManager.h" -#include "QXmppJingleIq.h" -#include "QXmppRtpChannel.h" -#include "QXmppUtils.h" - -#include "example_4_callHandling.h" - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) - , m_turnPort(0) - , m_turnFinished(false) -{ - bool check; - Q_UNUSED(check); - - // add QXmppCallManager extension - callManager = new QXmppCallManager; - addExtension(callManager); - - check = connect(this, SIGNAL(connected()), - this, SLOT(slotConnected())); - Q_ASSERT(check); - - check = connect(this, SIGNAL(presenceReceived(QXmppPresence)), - this, SLOT(slotPresenceReceived(QXmppPresence))); - Q_ASSERT(check); - - check = connect(callManager, SIGNAL(callReceived(QXmppCall*)), - this, SLOT(slotCallReceived(QXmppCall*))); - Q_ASSERT(check); - - check = connect(&m_dns, SIGNAL(finished()), - this, SLOT(slotDnsLookupFinished())); - Q_ASSERT(check); -} - -void xmppClient::setRecipient(const QString &recipient) -{ - m_recipient = recipient; -} - -/// The audio mode of a call changed. - -void xmppClient::slotAudioModeChanged(QIODevice::OpenMode mode) -{ - QXmppCall *call = qobject_cast<QXmppCall*>(sender()); - Q_ASSERT(call); - QXmppRtpAudioChannel *channel = call->audioChannel(); - - // prepare audio format - QAudioFormat format; - format.setFrequency(channel->payloadType().clockrate()); - format.setChannels(channel->payloadType().channels()); - format.setSampleSize(16); - format.setCodec("audio/pcm"); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setSampleType(QAudioFormat::SignedInt); - - // the size in bytes of the audio buffers to/from sound devices - // 160 ms seems to be the minimum to work consistently on Linux/Mac/Windows - const int bufferSize = (format.frequency() * format.channels() * (format.sampleSize() / 8) * 160) / 1000; - - if (mode & QIODevice::ReadOnly) { - // initialise audio output - QAudioOutput *audioOutput = new QAudioOutput(format, this); - audioOutput->setBufferSize(bufferSize); - audioOutput->start(channel); - } - - if (mode & QIODevice::WriteOnly) { - // initialise audio input - QAudioInput *audioInput = new QAudioInput(format, this); - audioInput->setBufferSize(bufferSize); - audioInput->start(channel); - } -} - - -/// A call was received. - -void xmppClient::slotCallReceived(QXmppCall *call) -{ - bool check; - Q_UNUSED(check); - - qDebug() << "Got call from:" << call->jid(); - - check = connect(call, SIGNAL(stateChanged(QXmppCall::State)), - this, SLOT(slotCallStateChanged(QXmppCall::State))); - Q_ASSERT(check); - - check = connect(call, SIGNAL(audioModeChanged(QIODevice::OpenMode)), - this, SLOT(slotAudioModeChanged(QIODevice::OpenMode))); - Q_ASSERT(check); - - // accept call - call->accept(); -} - -/// A call changed state. - -void xmppClient::slotCallStateChanged(QXmppCall::State state) -{ - if (state == QXmppCall::ActiveState) - qDebug("Call active"); - else if (state == QXmppCall::DisconnectingState) - qDebug("Call disconnecting"); - else if (state == QXmppCall::FinishedState) - qDebug("Call finished"); -} - -void xmppClient::slotConnected() -{ - // lookup TURN server - const QString domain = configuration().domain(); - debug(QString("Looking up TURN server for domain %1").arg(domain)); - m_dns.setType(QDnsLookup::SRV); - m_dns.setName("_turn._udp." + domain); - m_dns.lookup(); -} - -/// The DNS SRV lookup for TURN completed. - -void xmppClient::slotDnsLookupFinished() -{ - QString serverName; - - if (m_dns.error() == QDnsLookup::NoError && !m_dns.serviceRecords().isEmpty()) { - m_turnPort = m_dns.serviceRecords().first().port(); - QHostInfo::lookupHost(m_dns.serviceRecords().first().target(), - this, SLOT(slotHostInfoFinished(QHostInfo))); - } else { - warning("Could not find STUN server for domain " + configuration().domain()); - m_turnFinished = true; - startCall(); - } -} - -void xmppClient::slotHostInfoFinished(const QHostInfo &hostInfo) -{ - if (!hostInfo.addresses().isEmpty()) { - info(QString("Found TURN server %1 port %2 for domain %3").arg(hostInfo.addresses().first().toString(), QString::number(m_turnPort), configuration().domain())); - callManager->setTurnServer(hostInfo.addresses().first(), m_turnPort); - callManager->setTurnUser(configuration().user()); - callManager->setTurnPassword(configuration().password()); - } - m_turnFinished = true; - startCall(); -} - -/// A presence was received. - -void xmppClient::slotPresenceReceived(const QXmppPresence &presence) -{ - // if we don't have a recipient, or if the presence is not from the recipient, - // do nothing - if (m_recipient.isEmpty() || - QXmppUtils::jidToBareJid(presence.from()) != m_recipient || - presence.type() != QXmppPresence::Available) - return; - - // start the call and connect to the its signals - m_recipientFullJid = presence.from(); - startCall(); -} - -void xmppClient::startCall() -{ - bool check; - Q_UNUSED(check); - - if (!m_turnFinished || m_recipientFullJid.isEmpty()) - return; - - // start the call and connect to the its signals - QXmppCall *call = callManager->call(m_recipientFullJid); - - check = connect(call, SIGNAL(stateChanged(QXmppCall::State)), - this, SLOT(slotCallStateChanged(QXmppCall::State))); - Q_ASSERT(check); - - check = connect(call, SIGNAL(audioModeChanged(QIODevice::OpenMode)), - this, SLOT(slotAudioModeChanged(QIODevice::OpenMode))); - Q_ASSERT(check); -} - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - // we want one argument : "send" or "receive" - if (argc != 2 || (strcmp(argv[1], "send") && strcmp(argv[1], "receive"))) - { - fprintf(stderr, "Usage: %s send|receive\n", argv[0]); - return EXIT_FAILURE; - } - - xmppClient client; - client.logger()->setLoggingType(QXmppLogger::StdoutLogging); - if (!strcmp(argv[1], "send")) { - client.setRecipient("qxmpp.test2@qxmpp.org"); - client.connectToServer("qxmpp.test1@qxmpp.org", "qxmpp123"); - } else { - client.connectToServer("qxmpp.test2@qxmpp.org", "qxmpp456"); - } - - return a.exec(); -} diff --git a/examples/example_4_callHandling/example_4_callHandling.h b/examples/example_4_callHandling/example_4_callHandling.h deleted file mode 100644 index 09af27c8..00000000 --- a/examples/example_4_callHandling/example_4_callHandling.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2008-2014 The QXmpp developers - * - * Author: - * Ian Reinhart Geiser - * - * Source: - * https://github.com/qxmpp-project/qxmpp - * - * This file is a part of QXmpp library. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - */ - - -#ifndef XMPPCLIENT_H -#define XMPPCLIENT_H - -#include "QXmppCallManager.h" -#include "QXmppClient.h" -#include "qdnslookup.h" - -class QHostInfo; - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - xmppClient(QObject *parent = 0); - void setRecipient(const QString &recipient); - -private slots: - void slotAudioModeChanged(QIODevice::OpenMode mode); - void slotCallReceived(QXmppCall *call); - void slotCallStateChanged(QXmppCall::State state); - void slotConnected(); - void slotDnsLookupFinished(); - void slotHostInfoFinished(const QHostInfo &hostInfo); - void slotPresenceReceived(const QXmppPresence &presence); - -private: - void startCall(); - - QXmppCallManager *callManager; - QDnsLookup m_dns; - QString m_recipient; - QString m_recipientFullJid; - quint16 m_turnPort; - bool m_turnFinished; -}; - -#endif // IBBCLIENT_H diff --git a/examples/example_4_callHandling/example_4_callHandling.pro b/examples/example_4_callHandling/example_4_callHandling.pro deleted file mode 100644 index 039455ef..00000000 --- a/examples/example_4_callHandling/example_4_callHandling.pro +++ /dev/null @@ -1,15 +0,0 @@ -include(../examples.pri) - -CONFIG += mobility -MOBILITY += multimedia - -TARGET = example_4_callHandling - -SOURCES += example_4_callHandling.cpp - -HEADERS += example_4_callHandling.h - -# Symbian packaging rules -symbian { - TARGET.CAPABILITY = "UserEnvironment" -} |
