From fc1b469d3ef6f218ac270cb3abf7133442ff1a2f Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Fri, 14 Sep 2012 14:39:54 +0200 Subject: fix example --- .../example_7_archiveHandling.cpp | 155 +++++++++++++++++++++ .../example_7_archiveHandling.h | 66 +++++++++ .../example_7_archiveHandling.pro | 5 +- examples/example_7_archiveHandling/main.cpp | 40 ------ examples/example_7_archiveHandling/xmppClient.cpp | 144 ------------------- examples/example_7_archiveHandling/xmppClient.h | 66 --------- 6 files changed, 223 insertions(+), 253 deletions(-) create mode 100644 examples/example_7_archiveHandling/example_7_archiveHandling.cpp create mode 100644 examples/example_7_archiveHandling/example_7_archiveHandling.h delete mode 100644 examples/example_7_archiveHandling/main.cpp delete mode 100644 examples/example_7_archiveHandling/xmppClient.cpp delete mode 100644 examples/example_7_archiveHandling/xmppClient.h (limited to 'examples/example_7_archiveHandling') diff --git a/examples/example_7_archiveHandling/example_7_archiveHandling.cpp b/examples/example_7_archiveHandling/example_7_archiveHandling.cpp new file mode 100644 index 00000000..9cbb0943 --- /dev/null +++ b/examples/example_7_archiveHandling/example_7_archiveHandling.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/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 +#include + +#include "QXmppArchiveIq.h" +#include "QXmppArchiveManager.h" + +#include "example_7_archiveHandling.h" + +static void logStart(const QString &msg) +{ + qDebug("example_7_archiveHandling : %s", qPrintable(msg)); +} + +static void logEnd(const QString &msg) +{ + qDebug(" => %s", qPrintable(msg)); +} + +xmppClient::xmppClient(QObject *parent) + : QXmppClient(parent) + , m_collectionCount(-1) + , m_pageDirection(PageForwards) + , m_pageSize(10) +{ + bool check; + Q_UNUSED(check); + + // add archive manager + archiveManager = new QXmppArchiveManager; + addExtension(archiveManager); + + // connect signals + check = connect(this, SIGNAL(connected()), + this, SLOT(clientConnected())); + Q_ASSERT(check); + + check = connect(archiveManager, SIGNAL(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply)), + SLOT(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply))); + Q_ASSERT(check); + + check = connect(archiveManager, SIGNAL(archiveListReceived(QList, QXmppResultSetReply)), + SLOT(archiveListReceived(QList, QXmppResultSetReply))); + Q_ASSERT(check); + + // set limits + m_startDate = QDateTime::currentDateTime().addDays(-21); + m_endDate = QDateTime::currentDateTime(); +} + +xmppClient::~xmppClient() +{ + +} + +void xmppClient::setPageDirection(PageDirection direction) +{ + m_pageDirection = direction; +} + +void xmppClient::setPageSize(int size) +{ + m_pageSize = size; +} + +void xmppClient::clientConnected() +{ + logEnd("connected"); + + // we want 0 results, i.e. only result-set management information (count) + logStart("fetching collection count"); + QXmppResultSetQuery rsmQuery; + rsmQuery.setMax(0); + archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); +} + +void xmppClient::archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply) +{ + if (m_collectionCount < 0) { + logEnd(QString::number(rsmReply.count()) + " items"); + m_collectionCount = rsmReply.count(); + + // fetch first page + logStart("fetching collection first page"); + QXmppResultSetQuery rsmQuery; + rsmQuery.setMax(m_pageSize); + if (m_pageDirection == PageBackwards) + rsmQuery.setBefore(""); + archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); + } else if (!chats.size()) { + logEnd("no items"); + } else { + logEnd(QString("items %1 to %2 of %3").arg(QString::number(rsmReply.index()), QString::number(rsmReply.index() + chats.size() - 1), QString::number(rsmReply.count()))); + foreach (const QXmppArchiveChat &chat, chats) { + qDebug("chat start %s", qPrintable(chat.start().toString())); + // NOTE: to actually retrieve conversations, uncomment this + //archiveManager->retrieveCollection(chat.with(), chat.start()); + } + if (!rsmReply.isNull()) { + // fetch next page + QXmppResultSetQuery rsmQuery; + rsmQuery.setMax(m_pageSize); + if (m_pageDirection == PageBackwards) { + logStart("fetching collection previous page"); + rsmQuery.setBefore(rsmReply.first()); + } else { + logStart("fetching collection next page"); + rsmQuery.setAfter(rsmReply.last()); + } + archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); + } + } +} + +void xmppClient::archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply) +{ + logEnd(QString("chat received, RSM count %1").arg(QString::number(rsmReply.count()))); + foreach (const QXmppArchiveMessage &msg, chat.messages()) { + qDebug("example_7_archiveHandling : %s", qPrintable(msg.body())); + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + xmppClient client; + client.setPageSize(15); + client.setPageDirection(xmppClient::PageBackwards); + client.connectToServer("qxmpp.test1@qxmpp.org", "qxmpp123"); + + return a.exec(); +} diff --git a/examples/example_7_archiveHandling/example_7_archiveHandling.h b/examples/example_7_archiveHandling/example_7_archiveHandling.h new file mode 100644 index 00000000..9299c4f8 --- /dev/null +++ b/examples/example_7_archiveHandling/example_7_archiveHandling.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2008-2012 The QXmpp developers + * + * Author: + * Jeremy Lainé + * + * Source: + * http://code.google.com/p/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 + +#include "QXmppClient.h" + +class QXmppArchiveChat; +class QXmppArchiveManager; +class QXmppResultSetReply; + +class xmppClient : public QXmppClient +{ + Q_OBJECT + +public: + enum PageDirection { + PageForwards = 0, + PageBackwards + }; + + xmppClient(QObject *parent = 0); + ~xmppClient(); + + void setPageDirection(PageDirection direction); + void setPageSize(int size); + +public slots: + void clientConnected(); + void archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply); + void archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply); + +private: + QXmppArchiveManager *archiveManager; + int m_collectionCount; + QDateTime m_startDate; + QDateTime m_endDate; + PageDirection m_pageDirection; + int m_pageSize; +}; + +#endif // XMPPCLIENT_H diff --git a/examples/example_7_archiveHandling/example_7_archiveHandling.pro b/examples/example_7_archiveHandling/example_7_archiveHandling.pro index 0d7d75df..fc80314a 100644 --- a/examples/example_7_archiveHandling/example_7_archiveHandling.pro +++ b/examples/example_7_archiveHandling/example_7_archiveHandling.pro @@ -2,7 +2,6 @@ include(../examples.pri) TARGET = example_7_archiveHandling -SOURCES += main.cpp \ - xmppClient.cpp +SOURCES += example_7_archiveHandling.cpp -HEADERS += xmppClient.h +HEADERS += example_7_archiveHandling.h diff --git a/examples/example_7_archiveHandling/main.cpp b/examples/example_7_archiveHandling/main.cpp deleted file mode 100644 index 98338b20..00000000 --- a/examples/example_7_archiveHandling/main.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2008-2012 The QXmpp developers - * - * Author: - * Manjeet Dahiya - * - * Source: - * http://code.google.com/p/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 -#include "xmppClient.h" -#include "QXmppLogger.h" - -int main(int argc, char *argv[]) -{ - QCoreApplication a(argc, argv); - - QXmppLogger::getLogger()->setLoggingType(QXmppLogger::FileLogging); - - xmppClient client; - client.setPageSize(15); - client.setPageDirection(xmppClient::PageBackwards); - client.connectToServer("qxmpp.test1@gmail.com", "qxmpp123"); - return a.exec(); -} diff --git a/examples/example_7_archiveHandling/xmppClient.cpp b/examples/example_7_archiveHandling/xmppClient.cpp deleted file mode 100644 index bc54b990..00000000 --- a/examples/example_7_archiveHandling/xmppClient.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2008-2012 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/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 - -#include "QXmppArchiveIq.h" -#include "QXmppArchiveManager.h" - -#include "xmppClient.h" - -static void logStart(const QString &msg) -{ - qDebug("example_7_archiveHandling : %s", qPrintable(msg)); -} - -static void logEnd(const QString &msg) -{ - qDebug(" => %s", qPrintable(msg)); -} - -xmppClient::xmppClient(QObject *parent) - : QXmppClient(parent) - , m_collectionCount(-1) - , m_pageDirection(PageForwards) - , m_pageSize(10) -{ - bool check; - Q_UNUSED(check); - - // add archive manager - archiveManager = new QXmppArchiveManager; - addExtension(archiveManager); - - // connect signals - check = connect(this, SIGNAL(connected()), - this, SLOT(clientConnected())); - Q_ASSERT(check); - - check = connect(archiveManager, SIGNAL(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply)), - SLOT(archiveChatReceived(QXmppArchiveChat, QXmppResultSetReply))); - Q_ASSERT(check); - - check = connect(archiveManager, SIGNAL(archiveListReceived(QList, QXmppResultSetReply)), - SLOT(archiveListReceived(QList, QXmppResultSetReply))); - Q_ASSERT(check); - - // set limits - m_startDate = QDateTime::currentDateTime().addDays(-21); - m_endDate = QDateTime::currentDateTime(); -} - -xmppClient::~xmppClient() -{ - -} - -void xmppClient::setPageDirection(PageDirection direction) -{ - m_pageDirection = direction; -} - -void xmppClient::setPageSize(int size) -{ - m_pageSize = size; -} - -void xmppClient::clientConnected() -{ - logEnd("connected"); - - // we want 0 results, i.e. only result-set management information (count) - logStart("fetching collection count"); - QXmppResultSetQuery rsmQuery; - rsmQuery.setMax(0); - archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); -} - -void xmppClient::archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply) -{ - if (m_collectionCount < 0) { - logEnd(QString::number(rsmReply.count()) + " items"); - m_collectionCount = rsmReply.count(); - - // fetch first page - logStart("fetching collection first page"); - QXmppResultSetQuery rsmQuery; - rsmQuery.setMax(m_pageSize); - if (m_pageDirection == PageBackwards) - rsmQuery.setBefore(""); - archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); - } else if (!chats.size()) { - logEnd("no items"); - } else { - logEnd(QString("items %1 to %2 of %3").arg(QString::number(rsmReply.index()), QString::number(rsmReply.index() + chats.size() - 1), QString::number(rsmReply.count()))); - foreach (const QXmppArchiveChat &chat, chats) { - qDebug("chat start %s", qPrintable(chat.start().toString())); - // NOTE: to actually retrieve conversations, uncomment this - //archiveManager->retrieveCollection(chat.with(), chat.start()); - } - if (!rsmReply.isNull()) { - // fetch next page - QXmppResultSetQuery rsmQuery; - rsmQuery.setMax(m_pageSize); - if (m_pageDirection == PageBackwards) { - logStart("fetching collection previous page"); - rsmQuery.setBefore(rsmReply.first()); - } else { - logStart("fetching collection next page"); - rsmQuery.setAfter(rsmReply.last()); - } - archiveManager->listCollections("", m_startDate, m_endDate, rsmQuery); - } - } -} - -void xmppClient::archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply) -{ - logEnd(QString("chat received, RSM count %1").arg(QString::number(rsmReply.count()))); - foreach (const QXmppArchiveMessage &msg, chat.messages()) { - qDebug("example_7_archiveHandling : %s", qPrintable(msg.body())); - } -} - diff --git a/examples/example_7_archiveHandling/xmppClient.h b/examples/example_7_archiveHandling/xmppClient.h deleted file mode 100644 index 9299c4f8..00000000 --- a/examples/example_7_archiveHandling/xmppClient.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2008-2012 The QXmpp developers - * - * Author: - * Jeremy Lainé - * - * Source: - * http://code.google.com/p/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 - -#include "QXmppClient.h" - -class QXmppArchiveChat; -class QXmppArchiveManager; -class QXmppResultSetReply; - -class xmppClient : public QXmppClient -{ - Q_OBJECT - -public: - enum PageDirection { - PageForwards = 0, - PageBackwards - }; - - xmppClient(QObject *parent = 0); - ~xmppClient(); - - void setPageDirection(PageDirection direction); - void setPageSize(int size); - -public slots: - void clientConnected(); - void archiveListReceived(const QList &chats, const QXmppResultSetReply &rsmReply); - void archiveChatReceived(const QXmppArchiveChat &chat, const QXmppResultSetReply &rsmReply); - -private: - QXmppArchiveManager *archiveManager; - int m_collectionCount; - QDateTime m_startDate; - QDateTime m_endDate; - PageDirection m_pageDirection; - int m_pageSize; -}; - -#endif // XMPPCLIENT_H -- cgit v1.2.3