Hi all.
This mail is for those who know how to develop under
C++/Qt/TelepathyQt.
I have a problem that's been bugging me for some time now. I'm just one step
from completing the
"invite to chat" feature but I can't quite figure out what I'm doing wrong.
Sometimes i get a group chat, sometimes I don't.
It appears that in the function TelepathyChatUi::handleChannels I don't recieve
any contacts to add
to the new chatRoom when instead in ChatWindow::onInviteToChatTriggered I have
the contacts and I
pass them to the function Tp::Account::createConferenceTextChat.
So attached is the diff of my work. If any of you have some time to figure this
out I would appreciate
it.
Cheers,
Francesco
diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 0e6094a..97bd98b 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -20,6 +20,7 @@
#include "chat-window.h"
+#include "chat-invite-dialog.h"
#include "chat-search-bar.h"
#include "chat-tab.h"
@@ -213,7 +214,7 @@ void ChatWindow::onCurrentIndexChanged(int index)
setFileTransferEnabled(selfCapabilities.fileTransfers() && contactCapabilites.fileTransfers());
setVideoCallEnabled(selfCapabilities.streamedMediaVideoCalls() && contactCapabilites.streamedMediaVideoCalls());
/// TODO re-activate check when invitation to chat has been sorted out
- setInviteToChatEnabled(false);
+ setInviteToChatEnabled(/*false*/true);
} else {
// group chats don't have these functions
setAudioCallEnabled(false);
@@ -276,7 +277,38 @@ void ChatWindow::onGenericOperationFinished(Tp::PendingOperation* op)
void ChatWindow::onInviteToChatTriggered()
{
- /// TODO
+ // get current ChatWidget to retrieve Tp::AccountPtr from. This pointer is used to determine which
+ // contacts the user can invite to the chat
+ ChatTab *currChat = qobject_cast<ChatTab*>(m_tabWidget->currentWidget());
+
+ // consistency check for ChatTab
+ if (!currChat) {
+ return;
+ }
+
+ QWeakPointer<ChatInviteDialog> dialog = new ChatInviteDialog(currChat->account(), currChat->textChannel(), this);
+
+ if (dialog.data()->exec() == QDialog::Accepted) {
+ QStringList inviteeIds = dialog.data()->contactInvitees();
+
+ // add current contact to invitee list as well
+ inviteeIds.append(currChat->textChannel()->targetId());
+
+ qDebug() << "CONTACTS TO INVITE ARE: " << inviteeIds;
+
+ QList<Tp::ChannelPtr>channels;
+ channels.append(currChat->textChannel()); // or leave empty to create new channel
+
+ // request chat room creation
+ Tp::PendingChannelRequest *groupChatRequest = currChat->account()->createConferenceTextChat(channels,
+ inviteeIds,
+ QDateTime::currentDateTime(),
+ PREFERRED_TEXTCHAT_HANDLER);
+
+ connect(groupChatRequest, SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onGenericOperationFinished(Tp::PendingOperation*)));
+ }
+
+ delete dialog.data();
}
void ChatWindow::onNextTabActionTriggered()
diff --git a/app/main.cpp b/app/main.cpp
index 4f47e18..73d1bd5 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
"0.1");
aboutData.addAuthor(ki18n("David Edmundson"), ki18n("Developer"), "[email protected]");
aboutData.addAuthor(ki18n("Dominik Schmidt"), ki18n("Developer"), "[email protected]");
+ aboutData.addAuthor(ki18n("Francesco Nwokeka"), ki18n("Developer"), "[email protected]");
aboutData.setProductName("telepathy/text-chat-ui"); //set the correct name for bug reporting
KCmdLineArgs::init(argc, argv, &aboutData);
@@ -50,6 +51,7 @@ int main(int argc, char *argv[])
QDBusConnection::sessionBus(),
Tp::Features() << Tp::Connection::FeatureSelfContact
<< Tp::Connection::FeatureCore
+ << Tp::Connection::FeatureRoster
);
Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
diff --git a/app/telepathy-chat-ui.cpp b/app/telepathy-chat-ui.cpp
index 1654a9d..abb42d0 100644
--- a/app/telepathy-chat-ui.cpp
+++ b/app/telepathy-chat-ui.cpp
@@ -44,7 +44,8 @@ TelepathyChatUi::~TelepathyChatUi()
{
kDebug();
}
-
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/ContactManager>
void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & context,
const Tp::AccountPtr & account,
const Tp::ConnectionPtr & connection,
@@ -54,21 +55,29 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
const Tp::AbstractClientHandler::HandlerInfo & handlerInfo)
{
kDebug();
- Q_UNUSED(connection);
+// Q_UNUSED(connection);
Q_UNUSED(requestsSatisfied);
Q_UNUSED(userActionTime);
Q_UNUSED(handlerInfo);
Tp::TextChannelPtr textChannel;
foreach(const Tp::ChannelPtr & channel, channels) {
+ qDebug() << "GOT CONFERENCE" << channel->isConference();
textChannel = Tp::TextChannelPtr::dynamicCast(channel);
- if (textChannel) {
- break;
- }
+// if (textChannel) {
+// break;
+// }
}
Q_ASSERT(textChannel);
+ qDebug() << "CONTACTAAAAAAAAAA: " << textChannel->targetId();
+ qDebug() << "GROUP NUM: " << textChannel->conferenceInitialInviteeContacts().toList().count();
+ QList<Tp::ContactPtr> asd = textChannel->conferenceInitialInviteeContacts().toList();
+ for (int i = 0; i < asd.count(); ++i) {
+ qDebug() << "ALIAS IN CHAT: " << asd.at(i)->id();
+ }
+
// create new chat
m_chatWindow->startChat(textChannel, account);
m_chatWindow->show();
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 89b61c1..bfb95d8 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -1,13 +1,14 @@
set(telepathy_chat_handler_lib_SRCS
- chat-widget.cpp
- chat-window-style.cpp
- chat-window-style-manager.cpp
adium-theme-view.cpp
adium-theme-header-info.cpp
adium-theme-message-info.cpp
adium-theme-content-info.cpp
adium-theme-status-info.cpp
channel-contact-model.cpp
+ chat-invite-dialog.cpp
+ chat-widget.cpp
+ chat-window-style.cpp
+ chat-window-style-manager.cpp
chat-style-plist-file-reader.cpp
chat-text-edit.cpp
chat-search-bar.cpp
@@ -19,6 +20,7 @@ set(telepathy_chat_handler_lib_HDRS
adium-theme-message-info.h
adium-theme-status-info.h
adium-theme-view.h
+ chat-invite-dialog.h
chat-style-plist-file-reader.h
chat-widget.h
chat-window-style.h
@@ -38,7 +40,9 @@ set(telepathy_chat_handler_lib_PRETTY_HDRS
)
set(telepathy_chat_handler_lib_UI
- chat-widget.ui)
+ chat-widget.ui
+ chat-invite-dialog.ui
+)
kde4_add_ui_files(telepathy_chat_handler_lib_SRCS ${telepathy_chat_handler_lib_UI})
diff --git a/lib/chat-invite-dialog.cpp b/lib/chat-invite-dialog.cpp
new file mode 100644
index 0000000..76d32da
--- /dev/null
+++ b/lib/chat-invite-dialog.cpp
@@ -0,0 +1,68 @@
+#include "chat-invite-dialog.h"
+#include "ui_chat-invite-dialog.h"
+
+#include <QListWidget>
+#include <QListWidgetItem>
+
+#include <TelepathyQt4/ContactManager>
+#include <TelepathyQt4/Presence>
+
+ChatInviteDialog::ChatInviteDialog(Tp::AccountPtr account, Tp::TextChannelPtr textChannel, QWidget* parent)
+ : QDialog(parent)
+ , ui(new Ui::ChatInviteDialogUi)
+{
+ ui->setupUi(this);
+
+ // medium sized icons so you don't become blind
+ ui->kactionselector->availableListWidget()->setIconSize(QSize(30, 30));
+ ui->kactionselector->selectedListWidget()->setIconSize(QSize(30, 30));
+
+ // populate list
+ Tp::Contacts contacts = account->connection()->contactManager()->allKnownContacts();
+ m_contacts = contacts.toList();
+
+ // create "add to chat" list
+ for( int i = 0; i < m_contacts.size(); i++) {
+ Tp::ContactPtr auxContact = m_contacts.at(i);
+
+ // filter offline users
+ if (auxContact->presence().type() != Tp::ConnectionPresenceTypeOffline
+ && auxContact->id() != textChannel->targetId()) {
+ QListWidgetItem *item;
+
+ // set default avatar if none is retrieved
+ if (auxContact->avatarData().fileName.isEmpty()) {
+ item = new QListWidgetItem(KIcon("im-user"), auxContact->alias());
+ } else {
+ item = new QListWidgetItem(KIcon(auxContact->avatarData().fileName), auxContact->alias());
+ }
+
+ // set aux data
+ item->setData(Qt::UserRole, auxContact->id());
+
+ // add to list
+ ui->kactionselector->availableListWidget()->addItem(item);
+ }
+ }
+}
+
+ChatInviteDialog::~ChatInviteDialog()
+{
+ delete ui;
+}
+
+QStringList ChatInviteDialog::contactInvitees()
+{
+ QStringList contactsToAdd;
+
+ QListWidget *inviteeList = ui->kactionselector->selectedListWidget();
+
+ for (int i = 0; i < inviteeList->count(); ++i) {
+ contactsToAdd.append(inviteeList->item(i)->data(Qt::UserRole).toString());
+ qDebug() << "APPENDING data: " << inviteeList->item(i)->data(Qt::UserRole).toString();
+ }
+
+ return contactsToAdd;
+}
+
+
diff --git a/lib/chat-invite-dialog.h b/lib/chat-invite-dialog.h
new file mode 100644
index 0000000..18e77ca
--- /dev/null
+++ b/lib/chat-invite-dialog.h
@@ -0,0 +1,56 @@
+/***************************************************************************
+ * Copyright (C) 2011 by Francesco Nwokeka <[email protected]> *
+ * *
+ * 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, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef CHATINVITEDIALOG_H
+#define CHATINVITEDIALOG_H
+
+#include "kdetelepathychat_export.h"
+
+#include <QDialog>
+
+#include <TelepathyQt4/Account>
+#include <TelepathyQt4/Contact>
+#include <TelepathyQt4/TextChannel>
+
+namespace Ui {
+ class ChatInviteDialogUi;
+}
+
+class KDE_TELEPATHY_CHAT_EXPORT ChatInviteDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit ChatInviteDialog(Tp::AccountPtr account, Tp::TextChannelPtr textChannel, QWidget *parent=0);
+ ~ChatInviteDialog();
+
+ /**
+ * returns a list of Contacts chosen by the user, to invite to current chat
+ * @param account the user account to retrieve contacts from
+ */
+ QStringList contactInvitees();
+
+signals:
+ void sendInviteToContacts(const QList<Tp::ContactPtr> &invitees);
+
+private:
+ QList<Tp::ContactPtr> m_contacts;
+ Ui::ChatInviteDialogUi *ui;
+};
+#endif // CHATINVITEDIALOG_H
\ No newline at end of file
diff --git a/lib/chat-invite-dialog.ui b/lib/chat-invite-dialog.ui
new file mode 100644
index 0000000..0a70110
--- /dev/null
+++ b/lib/chat-invite-dialog.ui
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ChatInviteDialogUi</class>
+ <widget class="QDialog" name="ChatInviteDialogUi">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>639</width>
+ <height>380</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Invite Contacts</string>
+ </property>
+ <property name="sizeGripEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="KActionSelector" name="kactionselector"/>
+ </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>
+ <property name="centerButtons">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>KActionSelector</class>
+ <extends>QWidget</extends>
+ <header>kactionselector.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>ChatInviteDialogUi</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>ChatInviteDialogUi</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/lib/chat-widget.cpp b/lib/chat-widget.cpp
index 89e8c97..b932405 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -131,7 +131,7 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
d->chatviewlInitialised = false;
d->showFormatToolbarAction = new QAction(i18n("Show format options"), this);
- d->isGroupChat = false;
+ d->isGroupChat = channel->isConference();
d->ui.setupUi(this);
d->ui.formatToolbar->show();
@@ -177,7 +177,12 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
} else {
//some sort of group chat scenario.. Not sure how to create this yet.
info.setChatName("Group Chat");
- d->isGroupChat = true;
+ qDebug() << "GROUPCHAT CONTACTS ARE: ";
+
+ QList<Tp::ContactPtr> asd = d->channel->conferenceInitialInviteeContacts().toList();
+ for (int i = 0; i < asd.count(); ++i) {
+ qDebug() << "ALIAS IN CHAT: " << asd.at(i)->id();
+ }
}
if (!d->isGroupChat) {
@@ -488,9 +493,19 @@ void ChatWidget::handleIncomingMessage(const Tp::ReceivedMessage &message)
messageInfo.setMessage(message.text());
messageInfo.setTime(message.received());
- messageInfo.setUserIconPath(message.sender()->avatarData().fileName);
- messageInfo.setSenderDisplayName(message.sender()->alias());
- messageInfo.setSenderScreenName(message.sender()->id());
+
+ if (isGroupChat()) {
+// qDebug() << "MESSAGE WAS SENT BY: " << messageInfo.sender() << messageInfo.senderDisplayName() << " or " << messageInfo.senderScreenName();
+// messageInfo.setUserIconPath(QString());
+// messageInfo.setSenderDisplayName(messageInfo.senderDisplayName());
+// messageInfo.setSenderScreenName(messageInfo.senderScreenName());
+
+ } else {
+ // use "sender" object
+ messageInfo.setUserIconPath(message.sender()->avatarData().fileName);
+ messageInfo.setSenderDisplayName(message.sender()->alias());
+ messageInfo.setSenderScreenName(message.sender()->id());
+ }
d->ui.chatArea->addContentMessage(messageInfo);
d->channel->acknowledge(QList<Tp::ReceivedMessage>() << message);
_______________________________________________
KDE-Telepathy mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-telepathy