Permalink
Browse files

Merge branch 'metacontacts' of git://github.com/magist3r/qutim into m…

…etacontacts
  • Loading branch information...
euroelessar committed Mar 30, 2012
2 parents 159049b + aa5ab9f commit 6ebddef8df141d7987b9f47df07a370b002884c0
@@ -4,5 +4,5 @@ qutim_add_plugin( metacontacts
EXTENSION_CLASS Core::MetaContacts::Manager
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
DISPLAY_NAME "Simple MetaContacts"
- DESCRIPTION "Default qutIM MetaContacts implementation, very stupid one"
+ DESCRIPTION "Default qutIM MetaContacts implementation"
)
@@ -48,6 +48,10 @@ Manager::Manager() :
connect(this, SIGNAL(contactCreated(qutim_sdk_0_3::Contact*)), SLOT(onContactCreated(qutim_sdk_0_3::Contact*)));
QTimer::singleShot(0, this, SLOT(initActions()));
setContactsFactory(m_factory.data());
+ m_handler.reset(new MetaContactMessageHandler);
+ qutim_sdk_0_3::MessageHandler::registerHandler(m_handler.data(),
+ qutim_sdk_0_3::MessageHandler::HighPriority,
+ qutim_sdk_0_3::MessageHandler::HighPriority);
}
Manager::~Manager()
@@ -28,6 +28,7 @@
#include <qutim/metacontactmanager.h>
#include "metacontactimpl.h"
+#include "messagehandler.h"
namespace qutim_sdk_0_3 {
class RosterStorage;
@@ -62,6 +63,7 @@ private slots:
QScopedPointer<Factory> m_factory;
friend class Factory;
bool m_blockUpdate;
+ QScopedPointer <MetaContactMessageHandler> m_handler;
};
}
}
@@ -3,6 +3,7 @@
** qutIM - instant messenger
**
** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
+** Copyright © 2012 Sergei Lopatin <magist3r@gmail.com>
**
*****************************************************************************
**
@@ -36,9 +37,9 @@ using namespace qutim_sdk_0_3;
MergeDialog::MergeDialog(QWidget *parent) :
QDialog(parent),
- ui(new Ui::MergeDialog)
+ ui(new Ui::MergeDialog)
{
- ui->setupUi(this);
+ ui->setupUi(this);
ui->treeView->setModel(m_model = new Model(this));
ui->treeView->setItemDelegate(new ItemDelegate(this));
ui->treeView->expandAll();
@@ -47,15 +48,29 @@ MergeDialog::MergeDialog(QWidget *parent) :
m_model, SLOT(searchContacts(QString)));
connect(ui->treeView, SIGNAL(clicked(QModelIndex)),
m_model, SLOT(activated(QModelIndex)));
- connect(m_model, SIGNAL(addContactTriggered(qutim_sdk_0_3::Contact*)),
- this, SLOT(addContact(qutim_sdk_0_3::Contact*)));
- connect(m_model, SIGNAL(removeContactTriggered(qutim_sdk_0_3::Contact*)),
- this, SLOT(removeContact(qutim_sdk_0_3::Contact*)));
+ connect(ui->treeView, SIGNAL(clicked(QModelIndex)),
+ this, SLOT(onClicked()));
}
MergeDialog::~MergeDialog()
{
- delete ui;
+ delete ui;
+}
+
+void MergeDialog::accept()
+{
+ QList<Contact*> contacts = m_model->getContacts();
+ if(!(contacts.count() < 2)) {
+ MetaContactImpl *metaContact = m_model->metaContact();
+ if (!metaContact)
+ metaContact = static_cast<MetaContactImpl*>(MetaContactManager::instance()->createContact());
+
+ if (ui->nameEdit->text().size() != 0)
+ metaContact->setName(ui->nameEdit->text());
+ metaContact->addContacts(contacts, true);
+
+ }
+ QDialog::accept();
}
void MergeDialog::setMetaContact(MetaContactImpl* contact)
@@ -69,25 +84,6 @@ void MergeDialog::setMetaContact(MetaContactImpl* contact)
nameChanged(contact->name());
}
-void MergeDialog::addContact(qutim_sdk_0_3::Contact *contact)
-{
- MetaContactImpl *metaContact = m_model->metaContact();
- if (!metaContact) {
- metaContact = static_cast<MetaContactImpl*>(MetaContactManager::instance()->createContact());
- metaContact->addContact(contact);
- setMetaContact(metaContact);
- } else
- metaContact->addContact(contact);
-
-}
-
-void MergeDialog::removeContact(qutim_sdk_0_3::Contact *contact)
-{
- MetaContactImpl *metaContact = m_model->metaContact();
- Q_ASSERT(metaContact);
- metaContact->removeContact(contact);
-}
-
void MergeDialog::setName(const QString& name)
{
if(m_model->metaContact())
@@ -97,7 +93,7 @@ void MergeDialog::setName(const QString& name)
void MergeDialog::closeEvent(QCloseEvent *ev)
{
setName(ui->nameEdit->text());
- QWidget::closeEvent(ev);
+ QWidget::closeEvent(ev);
}
void MergeDialog::nameChanged(const QString& name)
@@ -106,6 +102,13 @@ void MergeDialog::nameChanged(const QString& name)
setWindowTitle(tr("%1 - qutIM").arg(name));
}
+void MergeDialog::onClicked()
+{
+ if(!(ui->searchField->text().size() == 0))
+ m_model->searchContacts(ui->searchField->text());
+ else if(!(ui->nameEdit->text().size() == 0))
+ m_model->searchContacts(ui->nameEdit->text());
+}
} // namespace MetaContacts
} // namespace Core
@@ -3,6 +3,7 @@
** qutIM - instant messenger
**
** Copyright © 2011 Aleksey Sidorov <gorthauer87@yandex.ru>
+** Copyright © 2012 Sergei Lopatin <magist3r@gmail.com>
**
*****************************************************************************
**
@@ -41,26 +42,26 @@ class Model;
namespace Ui {
- class MergeDialog;
+ class MergeDialog;
}
class MetaContactImpl;
class MergeDialog : public QDialog
{
- Q_OBJECT
+ Q_OBJECT
public:
explicit MergeDialog(QWidget *parent = 0);
- ~MergeDialog();
+ ~MergeDialog();
void setMetaContact(MetaContactImpl *contact);
protected:
- virtual void closeEvent(QCloseEvent* );
+ virtual void closeEvent(QCloseEvent* );
private slots:
- void addContact(qutim_sdk_0_3::Contact *);
- void removeContact(qutim_sdk_0_3::Contact *);
void setName(const QString &name);
void nameChanged(const QString &name);
+ void onClicked();
+ void accept();
private:
- Ui::MergeDialog *ui;
+ Ui::MergeDialog *ui;
Model *m_model;
};
@@ -77,12 +77,12 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
- <x>186</x>
- <y>438</y>
+ <x>206</x>
+ <y>437</y>
</hint>
<hint type="destinationlabel">
- <x>186</x>
- <y>227</y>
+ <x>2</x>
+ <y>235</y>
</hint>
</hints>
</connection>
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** qutIM - instant messenger
+**
+** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru>
+** Copyright © 2012 Sergei Lopatin <magist3r@gmail.com>
+**
+*****************************************************************************
+**
+** $QUTIM_BEGIN_LICENSE$
+** 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 3 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/.
+** $QUTIM_END_LICENSE$
+**
+****************************************************************************/
+
+#include "messagehandler.h"
+#include <qutim/debug.h>
+#include <qutim/metacontact.h>
+#include <qutim/account.h>
+#include <qutim/protocol.h>
+#include "metacontactimpl.h"
+
+using namespace qutim_sdk_0_3;
+
+namespace Core
+{
+namespace MetaContacts
+{
+MetaContactMessageHandler::MetaContactMessageHandler()
+{
+}
+
+MessageHandler::Result MetaContactMessageHandler::doHandle(qutim_sdk_0_3::Message &message, QString *reason)
+{
+ if (message.isIncoming()) {
+ if (MetaContactImpl *contact = qobject_cast<MetaContactImpl*>(message.chatUnit()->metaContact())) {
+ Contact *rawContact = 0;
+ ChatUnit *u = message.chatUnit();
+ while (u) {
+ if ((rawContact = qobject_cast<Contact*>(u)))
+ break;
+ u = u->upperUnit();
+ }
+ if (rawContact && contact->getActiveContact()->buddy() != rawContact)
+ contact->setActiveContact(rawContact);
+ }
+ }
+ return MetaContactMessageHandler::Accept;
+
+}
+
+}
+}
@@ -0,0 +1,47 @@
+/****************************************************************************
+**
+** qutIM - instant messenger
+**
+** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru>
+** Copyright © 2012 Sergei Lopatin <magist3r@gmail.com>
+**
+*****************************************************************************
+**
+** $QUTIM_BEGIN_LICENSE$
+** 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 3 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/.
+** $QUTIM_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef METACONTACTMESSAGEHANDLER_H
+#define METACONTACTMESSAGEHANDLER_H
+
+#include <qutim/messagehandler.h>
+
+namespace Core
+{
+namespace MetaContacts
+{
+class MetaContactMessageHandler : public qutim_sdk_0_3::MessageHandler
+{
+public:
+ MetaContactMessageHandler();
+protected:
+ virtual qutim_sdk_0_3::MessageHandler::Result doHandle(qutim_sdk_0_3::Message &message, QString *reason);
+};
+
+}
+}
+
+#endif // METACONTACTMESSAGEHANDLER_H
Oops, something went wrong.

0 comments on commit 6ebddef

Please sign in to comment.