Commit e91b0135 authored by Rafał Malinowski's avatar Rafał Malinowski

protocols: added notification for roster synchronization

Signed-off-by: Rafał Malinowski's avatarRafał Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent a7053191
......@@ -71,6 +71,7 @@
#include "plugins/plugins-manager.h"
#include "protocols/protocol-factory.h"
#include "protocols/protocol.h"
#include "protocols/services/roster/roster-notifier.h"
#include "provider/default-provider.h"
#include "provider/simple-provider.h"
#include "services/chat-image-request-service-configurator.h"
......@@ -566,6 +567,10 @@ void Core::runServices()
CurrentChatTopBarWidgetFactoryRepository = new ChatTopBarWidgetFactoryRepository(this);
CurrentUnreadMessageRepository = new UnreadMessageRepository(this);
CurrentRosterNotifier = new RosterNotifier(this);
foreach (const auto &notifyEvent, CurrentRosterNotifier->notifyEvents())
NotificationManager::instance()->registerNotifyEvent(notifyEvent);
// this instance lives forever
// TODO: maybe make it QObject and make CurrentChatImageRequestService its parent
ChatImageRequestServiceConfigurator *configurator = new ChatImageRequestServiceConfigurator();
......@@ -678,6 +683,11 @@ UnreadMessageRepository * Core::unreadMessageRepository() const
return CurrentUnreadMessageRepository;
}
RosterNotifier * Core::rosterNotifier() const
{
return CurrentRosterNotifier;
}
void Core::showMainWindow()
{
if (ShowMainWindowOnStart)
......
......@@ -69,6 +69,7 @@ class MessageHtmlRendererService;
class MessageTransformerService;
class NotificationService;
class RawMessageTransformerService;
class RosterNotifier;
class UnreadMessageRepository;
class KADUAPI Core : public QObject, private AccountsAwareObject, public ConfigurationAwareObject
......@@ -98,6 +99,7 @@ class KADUAPI Core : public QObject, private AccountsAwareObject, public Configu
ChatConfigurationWidgetFactoryRepository *CurrentChatConfigurationWidgetFactoryRepository;
ChatTopBarWidgetFactoryRepository *CurrentChatTopBarWidgetFactoryRepository;
UnreadMessageRepository *CurrentUnreadMessageRepository;
RosterNotifier *CurrentRosterNotifier;
KaduWindow *Window;
......@@ -165,6 +167,7 @@ public:
ChatConfigurationWidgetFactoryRepository * chatConfigurationWidgetFactoryRepository() const;
ChatTopBarWidgetFactoryRepository * chatTopBarWidgetFactoryRepository() const;
UnreadMessageRepository * unreadMessageRepository() const;
RosterNotifier * rosterNotifier() const;
void setShowMainWindowOnStart(bool show);
void setMainWindow(QWidget *window);
......
......@@ -13,6 +13,7 @@ set (protocols_SRCS
services/contact-list-service.cpp
services/roster/roster-entry.cpp
services/roster/roster-notifier.cpp
services/roster/roster-service.cpp
services/roster/roster-task.cpp
......
/*
* %kadu copyright begin%
* Copyright 2013 Rafał Malinowski (rafal.przemyslaw.malinowski@gmail.com)
* %kadu copyright end%
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "notify/notification/account-notification.h"
#include "notify/notification-manager.h"
#include "notify/notify-event.h"
#include "roster-notifier.h"
QString RosterNotifier::RosterNotifyTopic("Roster");
QString RosterNotifier::ImportSucceededNotifyTopic("Roster/ImportSucceeded");
QString RosterNotifier::ImportFailedNotifyTopic("Roster/ImportFailed");
QString RosterNotifier::ExportSucceededNotifyTopic("Roster/ExportSucceeded");
QString RosterNotifier::ExportFailedNotifyTopic("Roster/ExportFailed");
RosterNotifier::RosterNotifier(QObject *parent) :
QObject(parent)
{
RosterNotifyEvent.reset(new NotifyEvent(RosterNotifyTopic, NotifyEvent::CallbackNotRequired,
QT_TRANSLATE_NOOP("@default", "Roster")));
ImportSucceededNotifyEvent.reset(new NotifyEvent(ImportSucceededNotifyTopic, NotifyEvent::CallbackNotRequired,
QT_TRANSLATE_NOOP("@default", "Import from server succeeded")));
ImportFailedNotifyEvent.reset(new NotifyEvent(ImportFailedNotifyTopic, NotifyEvent::CallbackNotRequired,
QT_TRANSLATE_NOOP("@default", "Import from server failed")));
ExportSucceededNotifyEvent.reset(new NotifyEvent(ExportSucceededNotifyTopic, NotifyEvent::CallbackNotRequired,
QT_TRANSLATE_NOOP("@default", "Export to server succeeded")));
ExportFailedNotifyEvent.reset(new NotifyEvent(ExportFailedNotifyTopic, NotifyEvent::CallbackNotRequired,
QT_TRANSLATE_NOOP("@default", "Export to server failed")));
}
RosterNotifier::~RosterNotifier()
{
}
QList<NotifyEvent *> RosterNotifier::notifyEvents()
{
return QList<NotifyEvent *>()
<< RosterNotifyEvent.data()
<< ImportSucceededNotifyEvent.data()
<< ImportFailedNotifyEvent.data()
<< ExportSucceededNotifyEvent.data()
<< ExportFailedNotifyEvent.data();
}
void RosterNotifier::notify(const QString &topic, const Account &account, const QString &message)
{
AccountNotification *notification = new AccountNotification(account, topic, KaduIcon());
notification->setTitle(tr("Roster"));
notification->setText(message);
NotificationManager::instance()->notify(notification);
}
void RosterNotifier::notifyImportSucceeded(const Account &account)
{
notify(ImportSucceededNotifyTopic, account,
tr("%1: roster import succeded").arg(account.id()));
}
void RosterNotifier::notifyImportFailed(const Account &account)
{
notify(ImportFailedNotifyTopic, account,
tr("%1: roster import failed").arg(account.id()));
}
void RosterNotifier::notifyExportSucceeded(const Account &account)
{
notify(ExportSucceededNotifyTopic, account,
tr("%1: roster export succeded").arg(account.id()));
}
void RosterNotifier::notifyExportFailed(const Account &account)
{
notify(ExportFailedNotifyTopic, account,
tr("%1: roster export failed").arg(account.id()));
}
#include "moc_roster-notifier.cpp"
/*
* %kadu copyright begin%
* Copyright 2013 Rafał Malinowski (rafal.przemyslaw.malinowski@gmail.com)
* %kadu copyright end%
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QtCore/QObject>
#include <exports.h>
class Account;
class NotifyEvent;
class KADUAPI RosterNotifier : public QObject
{
Q_OBJECT
static QString RosterNotifyTopic;
static QString ImportSucceededNotifyTopic;
static QString ImportFailedNotifyTopic;
static QString ExportSucceededNotifyTopic;
static QString ExportFailedNotifyTopic;
QScopedPointer<NotifyEvent> RosterNotifyEvent;
QScopedPointer<NotifyEvent> ImportSucceededNotifyEvent;
QScopedPointer<NotifyEvent> ImportFailedNotifyEvent;
QScopedPointer<NotifyEvent> ExportSucceededNotifyEvent;
QScopedPointer<NotifyEvent> ExportFailedNotifyEvent;
void notify(const QString &topic, const Account &account, const QString &message);
public:
explicit RosterNotifier(QObject *parent = 0);
virtual ~RosterNotifier();
QList<NotifyEvent *> notifyEvents();
public slots:
void notifyImportSucceeded(const Account &account);
void notifyImportFailed(const Account &account);
void notifyExportSucceeded(const Account &account);
void notifyExportFailed(const Account &account);
};
......@@ -385,6 +385,10 @@ void FreedesktopNotify::createDefaultConfiguration()
config_file.addVariable("Notify", "multilogon_FreedesktopNotify", true);
config_file.addVariable("Notify", "multilogon/sessionConnected_FreedesktopNotify", true);
config_file.addVariable("Notify", "multilogon/sessionDisconnected_FreedesktopNotify", true);
config_file.addVariable("Notify", "Roster/ImportFailed_UseCustomSettings", true);
config_file.addVariable("Notify", "Roster/ImportFailed_FreedesktopNotify", true);
config_file.addVariable("Notify", "Roster/ExportFailed_UseCustomSettings", true);
config_file.addVariable("Notify", "Roster/ExportFailed_FreedesktopNotify", true);
config_file.addVariable("FreedesktopNotify", "CustomTimeout", false);
config_file.addVariable("FreedesktopNotify", "Timeout", 10);
......
......@@ -98,6 +98,7 @@ GaduProtocol::GaduProtocol(Account account, ProtocolFactory *factory) :
CurrentContactListService = new GaduContactListService(account, this);
CurrentContactListService->setConnection(Connection);
CurrentContactListService->setRosterNotifier(Core::instance()->rosterNotifier());
CurrentContactPersonalInfoService = new GaduContactPersonalInfoService(account, this);
CurrentContactPersonalInfoService->setConnection(Connection);
......
......@@ -31,6 +31,7 @@
#include "core/core.h"
#include "misc/misc.h"
#include "protocols/services/roster/roster-entry.h"
#include "protocols/services/roster/roster-notifier.h"
#include "debug.h"
#include "helpers/gadu-list-helper.h"
......@@ -64,6 +65,43 @@ void GaduContactListService::setConnection(GaduConnection *connection)
Connection = connection;
}
void GaduContactListService::setRosterNotifier(RosterNotifier *rosterNotifier)
{
MyRosterNotifier = rosterNotifier;
}
void GaduContactListService::putFinished(bool ok)
{
if (ok)
{
emit stateMachinePutFinished();
if (MyRosterNotifier)
MyRosterNotifier.data()->notifyExportSucceeded(account());
}
else
{
emit stateMachinePutFailed();
if (MyRosterNotifier)
MyRosterNotifier.data()->notifyExportFailed(account());
}
}
void GaduContactListService::getFinished(bool ok)
{
if (ok)
{
emit stateMachineGetFinished();
if (MyRosterNotifier)
MyRosterNotifier.data()->notifyImportSucceeded(account());
}
else
{
emit stateMachineGetFailed();
if (MyRosterNotifier)
MyRosterNotifier.data()->notifyImportFailed(account());
}
}
void GaduContactListService::handleEventUserlist100GetReply(struct gg_event *e)
{
if (!StateMachine->isPerformingGet())
......@@ -75,14 +113,14 @@ void GaduContactListService::handleEventUserlist100GetReply(struct gg_event *e)
GaduAccountDetails *accountDetails = dynamic_cast<GaduAccountDetails *>(account().details());
if (!accountDetails)
{
emit stateMachineGetFailed();
getFinished(false);
return;
}
if (e->event.userlist100_reply.format_type != GG_USERLIST100_FORMAT_TYPE_GG70)
{
kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "got userlist 100 reply with unwanted format type (%d)\n", (int)e->event.userlist100_reply.format_type);
emit stateMachineGetFailed();
getFinished(false);
return;
}
......@@ -90,7 +128,7 @@ void GaduContactListService::handleEventUserlist100GetReply(struct gg_event *e)
if (!content)
{
kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "got userlist 100 reply without any content\n");
emit stateMachineGetFailed();
getFinished(false);
return;
}
......@@ -100,7 +138,7 @@ void GaduContactListService::handleEventUserlist100GetReply(struct gg_event *e)
{
QByteArray content2(content);
BuddyList buddies = GaduListHelper::byteArrayToBuddyList(account(), content2);
emit stateMachineGetFinished();
getFinished(true);
setBuddiesList(buddies, true);
accountDetails->setUserlistVersion(e->event.userlist100_reply.version);
......@@ -120,7 +158,7 @@ void GaduContactListService::handleEventUserlist100GetReply(struct gg_event *e)
{
kdebugmf(KDEBUG_NETWORK|KDEBUG_INFO, "ignoring userlist 100 reply as we already know that version\n");
emit stateMachineGetFinished();
getFinished(true);
}
}
......@@ -142,12 +180,12 @@ void GaduContactListService::handleEventUserlist100PutReply(struct gg_event *e)
foreach (const Contact &contact, ContactManager::instance()->dirtyContacts(account()))
contact.rosterEntry()->setState(RosterEntrySynchronized);
emit stateMachinePutFinished();
putFinished(true);
return;
}
}
emit stateMachinePutFailed();
putFinished(false);
}
void GaduContactListService::handleEventUserlist100Reply(struct gg_event *e)
......@@ -206,7 +244,7 @@ void GaduContactListService::importContactList()
auto writableSessionToken = Connection.data()->writableSessionToken();
int ret = gg_userlist100_request(writableSessionToken.get()->rawSession(), GG_USERLIST100_GET, 0, GG_USERLIST100_FORMAT_TYPE_GG70, 0);
if (-1 == ret)
emit stateMachineGetFailed();
getFinished(false);
}
void GaduContactListService::exportContactList()
......@@ -228,7 +266,7 @@ void GaduContactListService::exportContactList(const BuddyList &buddies)
GaduAccountDetails *accountDetails = dynamic_cast<GaduAccountDetails *>(account().details());
if (!accountDetails)
{
emit stateMachinePutFailed();
putFinished(false);
return;
}
......@@ -236,7 +274,7 @@ void GaduContactListService::exportContactList(const BuddyList &buddies)
int ret = gg_userlist100_request(writableSessionToken.get()->rawSession(),
GG_USERLIST100_PUT, accountDetails->userlistVersion(), GG_USERLIST100_FORMAT_TYPE_GG70, contacts.constData());
if (-1 == ret)
emit stateMachinePutFailed();
putFinished(false);
}
void GaduContactListService::copySupportedBuddyInformation(const Buddy &destination, const Buddy &source)
......
......@@ -32,12 +32,14 @@
class GaduContactListStateMachine;
class GaduConnection;
class RosterNotifier;
class GaduContactListService : public ContactListService
{
Q_OBJECT
QWeakPointer<GaduConnection> Connection;
QWeakPointer<RosterNotifier> MyRosterNotifier;
GaduContactListStateMachine *StateMachine;
friend class GaduProtocolSocketNotifiers;
......@@ -46,6 +48,9 @@ class GaduContactListService : public ContactListService
void handleEventUserlist100GetReply(struct gg_event *e);
void handleEventUserlist100Reply(struct gg_event *e);
void putFinished(bool ok);
void getFinished(bool ok);
private slots:
void dirtyContactAdded(Contact contact);
......@@ -54,6 +59,7 @@ public:
virtual ~GaduContactListService();
void setConnection(GaduConnection *connection);
void setRosterNotifier(RosterNotifier *rosterNotifier);
virtual bool haveToAskForAddingContacts() const;
......
......@@ -696,6 +696,10 @@ void HintManager::createDefaultConfiguration()
config_file.addVariable("Notify", "multilogon_Hints", true);
config_file.addVariable("Notify", "multilogon/sessionConnected_Hints", true);
config_file.addVariable("Notify", "multilogon/sessionDisconnected_Hints", true);
config_file.addVariable("Notify", "Roster/ImportFailed_UseCustomSettings", true);
config_file.addVariable("Notify", "Roster/ImportFailed_Hints", true);
config_file.addVariable("Notify", "Roster/ExportFailed_UseCustomSettings", true);
config_file.addVariable("Notify", "Roster/ExportFailed_Hints", true);
#endif
config_file.addVariable("Hints", "CiteSign", 50);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment