diff --git a/KTp/Widgets/start-chat-dialog.cpp b/KTp/Widgets/start-chat-dialog.cpp index 9bb2a32..0fcb4e4 100644 --- a/KTp/Widgets/start-chat-dialog.cpp +++ b/KTp/Widgets/start-chat-dialog.cpp @@ -1,161 +1,159 @@ /* * Start chat dialog * * Copyright (C) 2013 Anant Kamath * * 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. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "start-chat-dialog.h" #include "ui_start-chat-dialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace KTp { struct KTPCOMMONINTERNALS_NO_EXPORT StartChatDialog::Private { Private() : ui(new Ui::StartChatDialog), acceptInProgress(false) {} Ui::StartChatDialog *ui; bool acceptInProgress; QPointer pendingContact; QDialogButtonBox *buttonBox; }; StartChatDialog::StartChatDialog(const Tp::AccountManagerPtr &accountManager, QWidget *parent) : QDialog(parent), d(new Private) { setWindowTitle(i18n("Start a chat")); setWindowIcon(QIcon::fromTheme(QLatin1String("telepathy-kde"))); d->buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(d->buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(d->buttonBox, SIGNAL(rejected()), this, SLOT(reject())); QWidget *widget = new QWidget(this); d->ui->setupUi(widget); QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->addWidget(widget); mainLayout->addWidget(d->buttonBox); setLayout(mainLayout); d->ui->accountCombo->setAccountSet(accountManager->onlineAccounts()); d->ui->screenNameLineEdit->setFocus(); } StartChatDialog::~StartChatDialog() { delete d->ui; delete d; } void StartChatDialog::accept() { Tp::AccountPtr account = d->ui->accountCombo->currentAccount(); const QString contactIdentifier = d->ui->screenNameLineEdit->text(); if (account.isNull()) { KMessageBox::sorry(this, i18n("No account selected.")); } else if (account->connection().isNull()) { KMessageBox::sorry(this, i18n("The requested account has been disconnected " "and so a chat could not be initiated.")); } else if (contactIdentifier.isEmpty()) { KMessageBox::sorry(this, i18n("You did not specify the name of the contact to start a chat with.")); } else { d->pendingContact = account->connection()->contactManager()->contactsForIdentifiers( QStringList() << contactIdentifier, Tp::Contact::FeatureCapabilities); connect(d->pendingContact, SIGNAL(finished(Tp::PendingOperation*)), SLOT(_k_onPendingContactFinished(Tp::PendingOperation*))); setInProgress(true); } } void StartChatDialog::_k_onPendingContactFinished(Tp::PendingOperation *op) { Tp::PendingContacts *pc = qobject_cast(op); Q_ASSERT(pc); if (pc->isError()) { KMessageBox::sorry(this, i18n("The contact Screen Name you provided is invalid or does not accept text chats.")); return; } if (pc == d->pendingContact && !pc->isError() && pc->contacts().size() > 0) { KTp::ContactPtr currentContact = KTp::ContactPtr::qObjectCast(pc->contacts().at(0)); Tp::PendingChannelRequest *op = KTp::Actions::startChat(d->ui->accountCombo->currentAccount(), currentContact, true); connect(op, SIGNAL(finished(Tp::PendingOperation*)), SLOT(_k_onStartChatFinished(Tp::PendingOperation*))); } } void StartChatDialog::closeEvent(QCloseEvent *e) { // ignore close event if we are in the middle of an operation if (!d->acceptInProgress) { QDialog::closeEvent(e); } } void StartChatDialog::_k_onStartChatFinished(Tp::PendingOperation *op) { if (op->isError()) { qWarning() << "Failed to start a text channel with the contact for the given identifier" << op->errorName() << op->errorMessage(); KMessageBox::sorry(this, i18n("Failed to start a chat with the contact.")); setInProgress(false); } else { QDialog::accept(); } } void StartChatDialog::setInProgress(bool inProgress) { d->acceptInProgress = inProgress; layout()->itemAt(0)->widget()->setEnabled(!inProgress); d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!inProgress); d->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(!inProgress); } } //namespace KTp - -#include "start-chat-dialog.moc" diff --git a/KTp/service-availability-checker.cpp b/KTp/service-availability-checker.cpp index ebf321c..45cbe1a 100644 --- a/KTp/service-availability-checker.cpp +++ b/KTp/service-availability-checker.cpp @@ -1,112 +1,110 @@ /* Copyright (C) 2011 Collabora Ltd. @author George Kiagiadakis 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 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 Lesser General Public License along with this program. If not, see . */ #include "service-availability-checker.h" #include #include #include #include #include "ktp-debug.h" namespace KTp { struct ServiceAvailabilityChecker::Private { QString serviceName; bool serviceAvailable; bool serviceActivatable; }; ServiceAvailabilityChecker::ServiceAvailabilityChecker(const QString & serviceName, QObject *parent) : QObject(parent), d(new Private) { d->serviceName = serviceName; d->serviceAvailable = false; d->serviceActivatable = false; QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(serviceName, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(serviceWatcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), this, SLOT(onServiceOwnerChanged(QString,QString,QString))); introspect(); } ServiceAvailabilityChecker::~ServiceAvailabilityChecker() { delete d; } bool ServiceAvailabilityChecker::isAvailable() const { return d->serviceAvailable || d->serviceActivatable; } void ServiceAvailabilityChecker::introspect() { QDBusConnectionInterface *dbusIface = QDBusConnection::sessionBus().interface(); QDBusPendingCall call = dbusIface->asyncCall(QLatin1String("ListActivatableNames")); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onCallFinished(QDBusPendingCallWatcher*))); watcher->setObjectName(QLatin1String("ListActivatableNamesWatcher")); call = dbusIface->asyncCall(QLatin1String("ListNames")); watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onCallFinished(QDBusPendingCallWatcher*))); } void ServiceAvailabilityChecker::onCallFinished(QDBusPendingCallWatcher *watcher) { QDBusReply reply = *watcher; if (!reply.isValid()) { qCDebug(KTP_COMMONINTERNALS) << "Got error while introspecting service availability:" << reply.error(); } else { if (watcher->objectName() == QLatin1String("ListActivatableNamesWatcher")) { d->serviceActivatable = reply.value().contains(d->serviceName); } else { if (!d->serviceAvailable) { d->serviceAvailable = reply.value().contains(d->serviceName); } //else onServiceOwnerChanged() has been emitted before the introspection finished //so the reply we got here may be incorrect, claiming that the service is not available } } watcher->deleteLater(); } void ServiceAvailabilityChecker::onServiceOwnerChanged(const QString & service, const QString & oldOwner, const QString & newOwner) { Q_UNUSED(oldOwner); if (service == d->serviceName) { d->serviceAvailable = !newOwner.isEmpty(); } } } - -#include "service-availability-checker.moc" diff --git a/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp index 4d116bf..4d2acb1 100644 --- a/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp +++ b/kpeople/uiplugins/chatplugin/chatlistviewdelegate.cpp @@ -1,60 +1,58 @@ /* Copyright 2014 Nilesh Suthar 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. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "chatlistviewdelegate.h" #include #include void ChatListviewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyledItemDelegate::paint(painter, option, index); painter->save(); QFont font = QApplication::font(); QFont timeFont = QApplication::font(); QFont messagefont = QApplication::font(); timeFont.setItalic(true); font.setBold(true); QFontMetrics fm(font); QString senderAlias = index.data(senderAliasRole).toString() + QLatin1String(":"); QString message = index.data(messageRole).toString(); QString time = index.data(messageTimeRole).toString(); QRect aliasRect = option.rect; QRect messageRect = option.rect; QRect timeRect = option.rect; messageRect.setLeft(fm.width(senderAlias)); painter->setFont(font); painter->drawText(aliasRect, senderAlias); painter->setFont(messagefont); painter->drawText(messageRect, message); painter->setFont(timeFont); painter->drawText(timeRect, Qt::AlignRight, time); painter->restore(); } - -#include "chatlistviewdelegate.moc"