1 /*
2  * %kadu copyright begin%
3  * Copyright 2011 Bartosz Brachaczek (b.brachaczek@gmail.com)
4  * Copyright 2011, 2013 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
5  * %kadu copyright end%
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "jabber-open-chat-with-runner.h"
22 
23 #include "jabber-id-validator.h"
24 
25 #include "accounts/account.h"
26 #include "buddies/buddy-manager.h"
27 #include "buddies/buddy.h"
28 #include "contacts/contact-manager.h"
29 #include "debug.h"
30 
JabberOpenChatWithRunner(Account account,QObject * parent)31 JabberOpenChatWithRunner::JabberOpenChatWithRunner(Account account, QObject *parent) :
32 		QObject{parent},
33 		m_account{account}
34 {
35 }
36 
~JabberOpenChatWithRunner()37 JabberOpenChatWithRunner::~JabberOpenChatWithRunner()
38 {
39 }
40 
setBuddyManager(BuddyManager * buddyManager)41 void JabberOpenChatWithRunner::setBuddyManager(BuddyManager *buddyManager)
42 {
43 	m_buddyManager = buddyManager;
44 }
45 
setContactManager(ContactManager * contactManager)46 void JabberOpenChatWithRunner::setContactManager(ContactManager *contactManager)
47 {
48 	m_contactManager = contactManager;
49 }
50 
matchingContacts(const QString & query)51 BuddyList JabberOpenChatWithRunner::matchingContacts(const QString &query)
52 {
53 	kdebugf();
54 
55 	BuddyList matchedContacts;
56 	QString queryCopy(query);
57 	int pos = 0;
58 	JabberIdValidator validator;
59 	if (validator.validate(queryCopy, pos) != QValidator::Acceptable)
60 		return matchedContacts;
61 
62 	auto contact = m_contactManager->byId(m_account, query, ActionCreate);
63 	auto buddy = m_buddyManager->byContact(contact, ActionCreate);
64 	matchedContacts.append(buddy);
65 
66 	return matchedContacts;
67 }
68 
setAccount(Account account)69 void JabberOpenChatWithRunner::setAccount(Account account)
70 {
71 	m_account = account;
72 }
73 
74 #include "moc_jabber-open-chat-with-runner.cpp"
75