diff --git a/src/approverdaemon.h b/src/approverdaemon.h index d6caf28..272c0aa 100644 --- a/src/approverdaemon.h +++ b/src/approverdaemon.h @@ -1,34 +1,34 @@ /* Copyright (C) 2010 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 . */ #ifndef APPROVERDAEMON_H #define APPROVERDAEMON_H #include class ApproverDaemon : public QObject, public Tp::AbstractClientApprover { Q_OBJECT public: - ApproverDaemon(QObject *parent = 0); + ApproverDaemon(QObject *parent = nullptr); protected: void addDispatchOperation(const Tp::MethodInvocationContextPtr<> & context, const Tp::ChannelDispatchOperationPtr & dispatchOperation) override; }; #endif // APPROVERDAEMON_H diff --git a/src/channelapprover.cpp b/src/channelapprover.cpp index ab4e25e..0e9dc26 100644 --- a/src/channelapprover.cpp +++ b/src/channelapprover.cpp @@ -1,45 +1,45 @@ /* Copyright (C) 2010 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 "channelapprover.h" #include "textchannelapprover.h" #include "filetransferchannelapprover.h" #include "tubechannelapprover.h" ChannelApprover *ChannelApprover::create(const Tp::ChannelPtr & channel, QObject *parent) { if (channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_TEXT) { return new TextChannelApprover(Tp::TextChannelPtr::dynamicCast(channel), parent); } if (channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_FILE_TRANSFER) { return new FileTransferChannelApprover( Tp::FileTransferChannelPtr::dynamicCast(channel), parent); } if ((channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_STREAM_TUBE) || (channel->channelType() == TP_QT_IFACE_CHANNEL_TYPE_DBUS_TUBE)) { return new TubeChannelApprover(Tp::TubeChannelPtr::dynamicCast(channel), parent); } Q_ASSERT(false); - return NULL; + return nullptr; } #include "channelapprover.moc" diff --git a/src/filetransferchannelapprover.cpp b/src/filetransferchannelapprover.cpp index dd76919..053e3cc 100644 --- a/src/filetransferchannelapprover.cpp +++ b/src/filetransferchannelapprover.cpp @@ -1,89 +1,89 @@ /* Copyright (C) 2010-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 "filetransferchannelapprover.h" #include "ktp_approver_debug.h" #include #include #include #include #include #include FileTransferChannelApprover::FileTransferChannelApprover( const Tp::FileTransferChannelPtr & channel, QObject *parent) : ChannelApprover(parent) { qCDebug(APPROVER); //notification - m_notification = new KNotification("incoming_file_transfer", 0, KNotification::Persistent); + m_notification = new KNotification("incoming_file_transfer", nullptr, KNotification::Persistent); m_notification.data()->setComponentName(QStringLiteral("ktelepathy")); m_notification.data()->setTitle(i18n("Incoming file transfer")); Tp::ContactPtr sender = channel->initiatorContact(); m_notification.data()->setText(i18n("

%1 is sending you a file. " "Do you accept the file transfer?

" "

Filename: %2

", sender->alias(), channel->fileName())); QPixmap pixmap; if (pixmap.load(sender->avatarData().fileName)) { m_notification.data()->setPixmap(pixmap); } m_notification.data()->setActions(QStringList() << i18n("Accept") << i18n("Reject")); connect(m_notification.data(), SIGNAL(action1Activated()), SIGNAL(channelAccepted())); connect(m_notification.data(), SIGNAL(action2Activated()), SIGNAL(channelRejected())); m_notification.data()->sendEvent(); //tray icon m_notifierItem = new KStatusNotifierItem; m_notifierItem->setCategory(KStatusNotifierItem::Communications); m_notifierItem->setStatus(KStatusNotifierItem::NeedsAttention); m_notifierItem->setIconByName(QLatin1String("document-save")); m_notifierItem->setAttentionIconByName(QLatin1String("mail-unread-new")); m_notifierItem->setStandardActionsEnabled(false); m_notifierItem->setTitle(i18n("Incoming file transfer")); m_notifierItem->setToolTip(QLatin1String("document-save"), i18n("Incoming file transfer from %1", sender->alias()), QString()); m_notifierItem->contextMenu()->clear(); //calling clear removes the pointless title m_notifierItem->contextMenu()->addAction(i18n("Accept"), this, SIGNAL(channelAccepted())); m_notifierItem->contextMenu()->addAction(i18n("Reject"), this, SIGNAL(channelRejected())); connect(m_notifierItem, SIGNAL(activateRequested(bool,QPoint)), SIGNAL(channelAccepted())); } FileTransferChannelApprover::~FileTransferChannelApprover() { qCDebug(APPROVER); //destroy the notification if (m_notification) { m_notification.data()->close(); m_notification.data()->deleteLater(); } //destroy the tray icon delete m_notifierItem; } #include "filetransferchannelapprover.moc" diff --git a/src/ktpapprovermodule.cpp b/src/ktpapprovermodule.cpp index 956599c..2dab6a8 100644 --- a/src/ktpapprovermodule.cpp +++ b/src/ktpapprovermodule.cpp @@ -1,96 +1,96 @@ /* Copyright (C) 2010 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 "approverdaemon.h" #include "version.h" #include #include #include #include #include #include #include #include #include #include #include #include class KTpApproverModule : public KDEDModule { public: KTpApproverModule(QObject *parent, const QVariantList & args) : KDEDModule(parent) { Q_UNUSED(args); Tp::registerTypes(); Tp::enableDebug(false); Tp::enableWarnings(true); Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus()); Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus()); Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus()); channelFactory->addCommonFeatures(Tp::Channel::FeatureCore); channelFactory->addFeaturesForTextChats(Tp::Features() << Tp::TextChannel::FeatureCore << Tp::TextChannel::FeatureMessageQueue); channelFactory->addFeaturesForIncomingFileTransfers( Tp::IncomingFileTransferChannel::FeatureCore); channelFactory->addFeaturesForIncomingStreamTubes( Tp::IncomingStreamTubeChannel::FeatureCore); channelFactory->addFeaturesForIncomingDBusTubes( Tp::IncomingDBusTubeChannel::FeatureCore); Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias << Tp::Contact::FeatureAvatarData); m_registrar = Tp::ClientRegistrar::create(accountFactory, connectionFactory, channelFactory, contactFactory); m_registrar->registerClient(Tp::SharedPtr(new ApproverDaemon()), "KTp.Approver"); } static inline KAboutData aboutData() { - KAboutData aboutData(QStringLiteral("ktp-approver"), 0, + KAboutData aboutData(QStringLiteral("ktp-approver"), nullptr, KTP_APPROVER_VERSION, - 0, KAboutLicense::LGPL, + nullptr, KAboutLicense::LGPL, i18n("(C) 2010, Collabora Ltd.")); aboutData.addAuthor(i18n("George Kiagiadakis"), QString(), QStringLiteral("george.kiagiadakis@collabora.co.uk")); return aboutData; } private: Tp::ClientRegistrarPtr m_registrar; }; K_PLUGIN_FACTORY(KTpApproverModuleFactory, registerPlugin();) #include "ktpapprovermodule.moc" \ No newline at end of file diff --git a/src/textchannelapprover.cpp b/src/textchannelapprover.cpp index a1978c9..daf4c02 100644 --- a/src/textchannelapprover.cpp +++ b/src/textchannelapprover.cpp @@ -1,128 +1,128 @@ /* Copyright (C) 2010 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 "textchannelapprover.h" #include #include #include #include #include #include #include #include TextChannelApprover::TextChannelApprover(const Tp::TextChannelPtr & channel, QObject *parent) : ChannelApprover(parent), m_notifierItem(getNotifierItem()) { Q_FOREACH(const Tp::ReceivedMessage & msg, channel->messageQueue()) { onMessageReceived(msg); } connect(channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)), SLOT(onMessageReceived(Tp::ReceivedMessage))); connect(m_notifierItem.data(), SIGNAL(activateRequested(bool,QPoint)), SIGNAL(channelAccepted())); updateNotifierItemTooltip(); } TextChannelApprover::~TextChannelApprover() { //destroy the notification if (m_notification) { m_notification.data()->close(); m_notification.data()->deleteLater(); } } void TextChannelApprover::onMessageReceived(const Tp::ReceivedMessage & msg) { if (msg.isDeliveryReport()) { return; } if (msg.deliveryDetails().status() == Tp::DeliveryStatusRead) { // The message is already read; nothing to notify about. return; } if (msg.isSilent()) { return; } if (!m_notification) { - m_notification = new KNotification("new_text_message", 0, KNotification::Persistent); + m_notification = new KNotification("new_text_message", nullptr, KNotification::Persistent); m_notification.data()->setComponentName(QStringLiteral("ktelepathy")); Tp::ContactPtr sender = msg.sender(); if (sender) { m_notification.data()->setTitle(sender->alias()); QPixmap pixmap; if (pixmap.load(sender->avatarData().fileName)) { m_notification.data()->setPixmap(pixmap); } } else { m_notification.data()->setTitle(i18n("Incoming message")); } m_notification.data()->setActions(QStringList() << i18n("Respond")); connect(m_notification.data(), SIGNAL(action1Activated()), SIGNAL(channelAccepted())); } m_notifierItem.data()->contextMenu()->clear(); //calling clear removes the pointless title m_notifierItem.data()->contextMenu()->addAction(i18n("Accept"), this, SIGNAL(channelAccepted())); m_notifierItem.data()->contextMenu()->addAction(i18n("Close"), this, SIGNAL(channelRejected())); m_notification.data()->setText(msg.text().simplified()); m_notification.data()->sendEvent(); } Q_GLOBAL_STATIC(QWeakPointer, s_notifierItem) //static QSharedPointer TextChannelApprover::getNotifierItem() { QSharedPointer notifierItem = s_notifierItem->toStrongRef(); if (!notifierItem) { notifierItem = QSharedPointer(new KStatusNotifierItem); notifierItem->setCategory(KStatusNotifierItem::Communications); notifierItem->setStatus(KStatusNotifierItem::NeedsAttention); notifierItem->setIconByName(QLatin1String("mail-unread")); notifierItem->setAttentionIconByName(QLatin1String("mail-unread-new")); notifierItem->setStandardActionsEnabled(false); notifierItem->setProperty("approver_new_channels_count", 0U); *s_notifierItem = notifierItem; } return notifierItem; } void TextChannelApprover::updateNotifierItemTooltip() { QVariant channelsCount = m_notifierItem->property("approver_new_channels_count"); channelsCount = QVariant(channelsCount.toUInt() + 1); m_notifierItem->setProperty("approver_new_channels_count", channelsCount); m_notifierItem->setToolTip(QLatin1String("mail-unread-new"), i18np("You have 1 incoming conversation", "You have %1 incoming conversations", channelsCount.toUInt()), QString()); } #include "textchannelapprover.moc" diff --git a/src/tubechannelapprover.cpp b/src/tubechannelapprover.cpp index 10c2965..4d60360 100644 --- a/src/tubechannelapprover.cpp +++ b/src/tubechannelapprover.cpp @@ -1,163 +1,163 @@ /* Copyright (C) 2012 David Edmundson Copyright (C) 2013 Dan Vrátil 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 "tubechannelapprover.h" #include "ktp_approver_debug.h" #include #include #include #include #include #include #include #include #include #include #include "approverdaemon.h" TubeChannelApprover::TubeChannelApprover(const Tp::TubeChannelPtr& channel, QObject* parent): - ChannelApprover(0), + ChannelApprover(nullptr), m_channel(channel) { Q_UNUSED(parent); qCDebug(APPROVER) << "Incoming tube channel"; qCDebug(APPROVER) << "\tTube Type:" << channel->channelType(); connect(m_channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), SLOT(onChannelInvalidated())); QString serviceName; if (Tp::StreamTubeChannelPtr streamTube = Tp::StreamTubeChannelPtr::dynamicCast(channel)) { qCDebug(APPROVER) << "\tService:" << streamTube->service(); serviceName = streamTube->service(); } else if (Tp::DBusTubeChannelPtr dbusTube = Tp::DBusTubeChannelPtr::dynamicCast(channel)) { qCDebug(APPROVER) << "\tService name:" << dbusTube->serviceName(); serviceName = dbusTube->serviceName(); } KService::List services = KServiceTypeTrader::self()->query(QLatin1String("KTpApprover")); qCDebug(APPROVER) << "Found" << services.count() << "KTpApprover services"; if (!services.isEmpty()) { Q_FOREACH(const KService::Ptr &service, services) { if ((service->property(QLatin1String("X-KTp-ChannelType")) != channel->channelType()) || (service->property(QLatin1String("X-KTp-Service")) != serviceName)) { continue; } m_service = service; } } if (!m_service) { qCDebug(APPROVER) << "No service to match" << channel->channelType() << "," << serviceName; showNotification(i18n("Unknown Incoming Connection"), i18n("%1 wants to start an unknown service with you", channel->initiatorContact()->alias()), QLatin1String("dialog-warning"), channel->initiatorContact()); return; } showNotification(m_service->name(), m_service->comment(), m_service->icon(), channel->initiatorContact()); } TubeChannelApprover::~TubeChannelApprover() { qCDebug(APPROVER); //destroy the notification if (m_notification) { m_notification.data()->close(); m_notification.data()->deleteLater(); } if (m_notifierItem) { m_notifierItem->deleteLater(); } } void TubeChannelApprover::showNotification(const QString& title, const QString& comment, const QString& icon, const Tp::ContactPtr& sender) { // incoming_file_transfer = defines notification sound & user preferences - m_notification = new KNotification(QLatin1String("incoming_file_transfer"), 0, KNotification::Persistent); + m_notification = new KNotification(QLatin1String("incoming_file_transfer"), nullptr, KNotification::Persistent); m_notification.data()->setComponentName(QStringLiteral("ktelepathy")); m_notification.data()->setTitle(title); if (comment.contains(QLatin1String("%1"))) { Q_ASSERT(sender); m_notification.data()->setText(comment.arg(sender->alias())); } else { m_notification.data()->setText(comment); } m_notification.data()->setPixmap(QIcon::fromTheme(icon).pixmap(32, 32)); m_notification.data()->setActions(QStringList() << i18n("Accept") << i18n("Reject")); connect(m_notification.data(), SIGNAL(action1Activated()), SIGNAL(channelAccepted())); connect(m_notification.data(), SIGNAL(action2Activated()), SIGNAL(channelRejected())); m_notification.data()->sendEvent(); //tray icon m_notifierItem = new KStatusNotifierItem; m_notifierItem->setCategory(KStatusNotifierItem::Communications); m_notifierItem->setStatus(KStatusNotifierItem::NeedsAttention); m_notifierItem->setIconByName(icon); m_notifierItem->setStandardActionsEnabled(false); m_notifierItem->setTitle(title); m_notifierItem->setToolTip(QLatin1String("document-save"), i18n("Incoming %1 request from %2", title, sender->alias()), QString()); m_notifierItem->contextMenu()->clear(); //calling clear removes the pointless title m_notifierItem->contextMenu()->addAction(i18n("Accept"), this, SIGNAL(channelAccepted())); m_notifierItem->contextMenu()->addAction(i18n("Reject"), this, SIGNAL(channelRejected())); connect(this, SIGNAL(channelAccepted()), SLOT(onChannelAccepted())); } void TubeChannelApprover::onChannelAccepted() { //destroy the notification if (m_notification) { m_notification.data()->close(); m_notification.data()->deleteLater(); } m_notifierItem->setStatus(KStatusNotifierItem::Active); if (m_service && m_service->property(QLatin1String("X-KTp-Cancellable")).toBool()) { m_notifierItem->setTitle(i18n("%1 share with %2", m_service->name(), m_channel->initiatorContact()->alias())); //set new menu to an entry to close the channel m_notifierItem->contextMenu()->clear(); m_notifierItem->contextMenu()->addAction(QIcon::fromTheme("dialog-close"), i18n("Stop %1 Sharing", m_service->name()), this, SLOT(onChannelCloseRequested())); } else { m_notifierItem->deleteLater(); } } void TubeChannelApprover::onChannelCloseRequested() { m_channel->requestClose(); } void TubeChannelApprover::onChannelInvalidated() { deleteLater(); }