[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:22:05 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=c8bd0c4

The following commit has been merged in the master branch:
commit c8bd0c41bfdd38f09d10a16b0b37f14d48e9df99
Author: Dan Vrátil <dan at progdan.cz>
Date:   Sun Jul 15 17:02:08 2012 +0200

    Support drag and drop file transfer
    
    REVIEW: 105511
    BUG: 288561
---
 app/main.cpp        |   2 +
 lib/chat-widget.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/chat-widget.h   |   5 +++
 3 files changed, 121 insertions(+)

diff --git a/app/main.cpp b/app/main.cpp
index b8b2523..b15745c 100644
--- a/app/main.cpp
+++ b/app/main.cpp
@@ -27,6 +27,7 @@
 #include <TelepathyQt/ChannelFactory>
 #include <TelepathyQt/ContactFactory>
 #include <TelepathyQt/TextChannel>
+#include <TelepathyQt/OutgoingFileTransferChannel>
 
 #include <KAboutData>
 #include <KCmdLineArgs>
@@ -65,6 +66,7 @@ int main(int argc, char *argv[])
                                                << Tp::TextChannel::FeatureMessageCapabilities;
     channelFactory->addFeaturesForTextChats(textFeatures);
     channelFactory->addFeaturesForTextChatrooms(textFeatures);
+    channelFactory->addFeaturesForOutgoingFileTransfers(Tp::OutgoingFileTransferChannel::FeatureCore);
 
     Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
         Tp::Features() << Tp::Contact::FeatureAlias
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index ea5196f..297ee1f 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -37,6 +37,8 @@
 #include <KDebug>
 #include <KColorScheme>
 #include <KLineEdit>
+#include <KMimeType>
+#include <KTemporaryFile>
 
 #include <TelepathyQt/Account>
 #include <TelepathyQt/Message>
@@ -44,6 +46,8 @@
 #include <TelepathyQt/AvatarData>
 #include <TelepathyQt/Connection>
 #include <TelepathyQt/Presence>
+#include <TelepathyQt/PendingChannelRequest>
+#include <TelepathyQt/OutgoingFileTransferChannel>
 
 #include <KTp/presence.h>
 #include "message-processor.h"
@@ -71,6 +75,8 @@ public:
     LogManager *logManager;
     QTimer *pausedStateTimer;
 
+    QList< Tp::OutgoingFileTransferChannelPtr > tmpFileTransfers;
+
     KComponentData telepathyComponentData();
 };
 
@@ -128,6 +134,10 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
 
     d->ui.chatArea->load((d->isGroupChat?AdiumThemeView::GroupChat:AdiumThemeView::SingleUserChat));
 
+    d->ui.sendMessageBox->setAcceptDrops(false);
+    d->ui.chatArea->setAcceptDrops(false);
+    setAcceptDrops(true);
+
     AdiumThemeHeaderInfo info;
 
     info.setGroupChat(d->isGroupChat);
@@ -329,6 +339,110 @@ void ChatWidget::keyPressEvent(QKeyEvent *e)
     QWidget::keyPressEvent(e);
 }
 
+void ChatWidget::temporaryFileTransferStateChanged(Tp::FileTransferState state, Tp::FileTransferStateChangeReason reason)
+{
+    Q_UNUSED(reason);
+
+    if ((state == Tp::FileTransferStateCompleted) || (state == Tp::FileTransferStateCancelled)) {
+        Tp::OutgoingFileTransferChannel *channel = qobject_cast<Tp::OutgoingFileTransferChannel*>(sender());
+        Q_ASSERT(channel);
+
+        QString localFile = QUrl(channel->uri()).toLocalFile();
+        if (QFile::exists(localFile)) {
+            QFile::remove(localFile);
+            kDebug() << "File" << localFile << "removed";
+        }
+
+        d->tmpFileTransfers.removeAll(Tp::OutgoingFileTransferChannelPtr(channel));
+    }
+}
+
+
+void ChatWidget::temporaryFileTransferChannelCreated(Tp::PendingOperation *operation)
+{
+    Tp::PendingChannelRequest *request = qobject_cast<Tp::PendingChannelRequest*>(operation);
+    Q_ASSERT(request);
+
+    Tp::OutgoingFileTransferChannelPtr transferChannel;
+    transferChannel = Tp::OutgoingFileTransferChannelPtr::qObjectCast<Tp::Channel>(request->channelRequest()->channel());
+    Q_ASSERT(!transferChannel.isNull());
+
+    /* Make sure the pointer lives until the transfer is over
+     * so that the signal connection below lasts until the end */
+    d->tmpFileTransfers << transferChannel;
+
+    connect(transferChannel.data(), SIGNAL(stateChanged(Tp::FileTransferState,Tp::FileTransferStateChangeReason)),
+            this, SLOT(temporaryFileTransferStateChanged(Tp::FileTransferState,Tp::FileTransferStateChangeReason)));
+}
+
+
+void ChatWidget::dropEvent(QDropEvent *e)
+{
+    const QMimeData *data = e->mimeData();
+
+    if (data->hasUrls()) {
+        Q_FOREACH(const QUrl &url, data->urls()) {
+            if (url.isLocalFile()) {
+                Tp::FileTransferChannelCreationProperties properties(
+                        url.toLocalFile(),
+                        KMimeType::findByFileContent(url.toLocalFile())->name());
+                d->account->createFileTransfer(d->channel->targetContact(),
+                        properties, QDateTime::currentDateTime(),
+                        QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer"));
+            } else {
+                d->ui.sendMessageBox->append(url.toString());
+            }
+        }
+        e->acceptProposedAction();
+    } else if (data->hasText()) {
+        d->ui.sendMessageBox->append(data->text());
+        e->acceptProposedAction();
+    } else if (data->hasHtml()) {
+        d->ui.sendMessageBox->insertHtml(data->html());
+        e->acceptProposedAction();
+    } else if (data->hasImage()) {
+        QImage image = qvariant_cast<QImage>(data->imageData());
+
+        KTemporaryFile tmpFile;
+        tmpFile.setPrefix(d->account->displayName() + QLatin1String("-"));
+        tmpFile.setSuffix(QLatin1String(".png"));
+        tmpFile.setAutoRemove(false);
+        if (!tmpFile.open()) {
+            return;
+        }
+        tmpFile.close();
+
+        if (!image.save(tmpFile.fileName(), "PNG")) {
+            return;
+        }
+
+        Tp::FileTransferChannelCreationProperties properties(
+                    tmpFile.fileName(),
+                    KMimeType::findByFileContent(tmpFile.fileName())->name());
+        Tp::PendingChannelRequest *request;
+        request = d->account->createFileTransfer(d->channel->targetContact(),
+                        properties, QDateTime::currentDateTime(),
+                        QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer"));
+        connect(request, SIGNAL(finished(Tp::PendingOperation*)),
+                this, SLOT(temporaryFileTransferChannelCreated(Tp::PendingOperation*)));
+
+        kDebug() << "Starting transfer of" << tmpFile.fileName();
+        e->acceptProposedAction();
+    }
+
+    QWidget::dropEvent(e);
+}
+
+void ChatWidget::dragEnterEvent(QDragEnterEvent *e)
+{
+    if (e->mimeData()->hasHtml() || e->mimeData()->hasImage() ||
+        e->mimeData()->hasText() || e->mimeData()->hasUrls()) {
+            e->accept();
+    }
+
+    QWidget::dragEnterEvent(e);
+}
+
 QString ChatWidget::title() const
 {
     return d->title;
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index 686b632..9b6f08e 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -103,6 +103,8 @@ protected:
     void changeEvent(QEvent *e);
     void resizeEvent(QResizeEvent *);
     void keyPressEvent(QKeyEvent *e);
+    virtual void dropEvent(QDropEvent *e);
+    virtual void dragEnterEvent(QDragEnterEvent *e);
 
 protected Q_SLOTS:
     /** Show the received message in the chat window*/
@@ -168,6 +170,9 @@ private Q_SLOTS:
     void onHistoryFetched(const QList<AdiumThemeContentInfo> &messages);
     void onChatPausedTimerExpired();
 
+    void temporaryFileTransferChannelCreated(Tp::PendingOperation *operation);
+    void temporaryFileTransferStateChanged(Tp::FileTransferState, Tp::FileTransferStateChangeReason);
+
 private:
     /** connects necessary signals for the channel */
     void setupChannelSignals();

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list