[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:05:59 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=97ebd85
The following commit has been merged in the master branch:
commit 97ebd8512563ffe3a954619f66be2bd279bbe7d1
Author: Dario Freddi <dario.freddi at collabora.co.uk>
Date: Fri Apr 15 19:56:54 2011 +0200
Fetch the avatar through a separate class, library ready
---
CMakeLists.txt | 1 +
fetch-avatar-job.cpp | 113 ++++++++++++++++++++++++++
remove-contact-dialog.h => fetch-avatar-job.h | 44 +++++-----
main-widget.cpp | 38 ++++-----
main-widget.h | 2 +
5 files changed, 150 insertions(+), 48 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b85062..b2c5f5b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -35,6 +35,7 @@ set (contactlist_SRCS
main-widget.cpp
add-contact-dialog.cpp
remove-contact-dialog.cpp
+ fetch-avatar-job.cpp
)
diff --git a/fetch-avatar-job.cpp b/fetch-avatar-job.cpp
new file mode 100644
index 0000000..0d82313
--- /dev/null
+++ b/fetch-avatar-job.cpp
@@ -0,0 +1,113 @@
+/*
+ * This file is part of telepathy-contactslist-prototype
+ *
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * @Author Dario Freddi <dario.freddi at collabora.co.uk>
+ *
+ * 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 "fetch-avatar-job.h"
+
+#include <KUrl>
+#include <KLocalizedString>
+
+#include <KIO/Job>
+
+class FetchAvatarJob::Private
+{
+public:
+ Private(FetchAvatarJob *q) : q(q) {}
+ ~Private() {}
+
+ void _k_onMimeTypeDetected(KIO::Job *job, const QString &mimetype);
+ void _k_onDataFromJob(KIO::Job *job, const QByteArray &data);
+ void _k_onJobFinished(KJob *job);
+
+ Tp::Avatar avatar;
+ KUrl url;
+
+ FetchAvatarJob *q;
+};
+
+FetchAvatarJob::FetchAvatarJob(const KUrl& url, QObject* parent)
+ : KJob(parent)
+ , d(new Private(this))
+{
+ d->url = url;
+}
+
+FetchAvatarJob::~FetchAvatarJob()
+{
+ delete d;
+}
+
+Tp::Avatar FetchAvatarJob::avatar() const
+{
+ return d->avatar;
+}
+
+void FetchAvatarJob::start()
+{
+ if (d->url.isEmpty() || !d->url.isValid()) {
+ setError(1);
+ emitResult();
+ return;
+ }
+
+ KIO::TransferJob *job = KIO::get(d->url);
+
+ connect(job, SIGNAL(mimetype(KIO::Job*,QString)),
+ this, SLOT(_k_onMimeTypeDetected(KIO::Job*,QString)));
+ connect(job, SIGNAL(data(KIO::Job*,QByteArray)),
+ this, SLOT(_k_onDataFromJob(KIO::Job*,QByteArray)));
+ connect(job, SIGNAL(result(KJob*)),
+ this, SLOT(_k_onJobFinished(KJob*)));
+}
+
+void FetchAvatarJob::Private::_k_onMimeTypeDetected(KIO::Job *job, const QString &mimetype)
+{
+ if (!mimetype.contains("image/")) {
+ q->setErrorText(i18n("The file you have selected doesn't seem to be an image!
"
+ "Please select an image file."));
+ q->setError(1);
+ q->emitResult();
+
+ disconnect(job, SIGNAL(result(KJob*)),
+ q, SLOT(_k_onJobFinished(KJob*)));
+ disconnect(job, SIGNAL(data(KIO::Job*,QByteArray)),
+ q, SLOT(_k_onDataFromJob(KIO::Job*,QByteArray)));
+
+ job->kill();
+
+ return;
+ }
+
+ avatar.MIMEType = mimetype;
+}
+
+void FetchAvatarJob::Private::_k_onDataFromJob(KIO::Job *job, const QByteArray &data)
+{
+ Q_UNUSED(job)
+ avatar.avatarData.append(data);
+}
+
+void FetchAvatarJob::Private::_k_onJobFinished(KJob *job)
+{
+ q->setError(job->error());
+ q->emitResult();
+}
+
+#include "fetch-avatar-job.moc"
diff --git a/remove-contact-dialog.h b/fetch-avatar-job.h
similarity index 52%
copy from remove-contact-dialog.h
copy to fetch-avatar-job.h
index 2af624a..633351e 100644
--- a/remove-contact-dialog.h
+++ b/fetch-avatar-job.h
@@ -1,7 +1,8 @@
/*
- * This file is part of telepathy-contactslist
+ * This file is part of telepathy-contactslist-prototype
*
- * Copyright (C) 2011 by Francesco Nwokeka <francesco.nwokeka at gmail.com>
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * @Author Dario Freddi <dario.freddi at collabora.co.uk>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -18,38 +19,33 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef REMOVECONTACTDIALOG_H
-#define REMOVECONTACTDIALOG_H
+#ifndef FETCH_AVATAR_JOB_H
+#define FETCH_AVATAR_JOB_H
-#include <KDialog>
+#include <KJob>
-#include <TelepathyQt4/Contact>
+#include <TelepathyQt4/Types>
-namespace Ui {
- class RemoveContactDialog;
-}
-
-class AccountsModel;
-
-class RemoveContactDialog : public KDialog
+class KUrl;
+class FetchAvatarJob : public KJob
{
Q_OBJECT
public:
- /**
- * constructor
- * @param contact Tp::ContactPtr of the contact to remove
- * @param parent parent widget
- */
- RemoveContactDialog(Tp::ContactPtr contact, QWidget *parent = 0);
+ explicit FetchAvatarJob(const KUrl &url, QObject *parent = 0);
+ virtual ~FetchAvatarJob();
- /** returns value of "block contact" checkbox */
- bool blockContact() const;
+ void start();
+ Tp::Avatar avatar() const;
private:
- Ui::RemoveContactDialog *ui;
-};
+ class Private;
+ Private * const d;
+ Q_PRIVATE_SLOT(d, void _k_onMimeTypeDetected(KIO::Job*,QString))
+ Q_PRIVATE_SLOT(d, void _k_onDataFromJob(KIO::Job*,QByteArray))
+ Q_PRIVATE_SLOT(d, void _k_onJobFinished(KJob*))
+};
-#endif // REMOVECONTACTDIALOG_H
+#endif // FETCH_AVATAR_JOB_H
diff --git a/main-widget.cpp b/main-widget.cpp
index 5fa5490..af9acea 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -40,6 +40,7 @@
#include <TelepathyQt4/ContactManager>
#include <KDebug>
+#include <KIO/Job>
#include <KUser>
#include <KMenu>
#include <KMessageBox>
@@ -59,6 +60,7 @@
#include "contact-model-item.h"
#include "add-contact-dialog.h"
#include "remove-contact-dialog.h"
+#include "fetch-avatar-job.h"
#define PREFERRED_TEXTCHAT_HANDLER "org.freedesktop.Telepathy.Client.KDE.TextUi"
@@ -804,36 +806,26 @@ void MainWidget::selectAvatarFromAccount(const QString &accountUID)
void MainWidget::loadAvatarFromFile()
{
- //FIXME: Think of network files, which QFile won't open
- KUrl file = KFileDialog::getImageOpenUrl();
+ FetchAvatarJob *job = new FetchAvatarJob(KFileDialog::getImageOpenUrl(), this);
- if (file.isEmpty() || !file.isValid()) {
- return;
- }
+ connect(job, SIGNAL(result(KJob*)), this, SLOT(onAvatarFetched(KJob*)));
- KMimeType::Ptr mime = KMimeType::findByUrl(file);
+ job->start();
+}
- if (!mime->name().contains("image/")) {
- KMessageBox::error(this, i18n("The file you have selected doesn't seem to be an image! \
- Please select an image file."));
+void MainWidget::onAvatarFetched(KJob *job)
+{
+ if (job->error()) {
+ KMessageBox::error(this, job->errorText());
return;
}
- QFile imageBuffer(file.toLocalFile());
- imageBuffer.open(QIODevice::ReadOnly);
- if (!imageBuffer.isOpen() || !imageBuffer.isReadable()) {
- //FIXME: probably should also tell the user what to do, no? but what to do? :)
- KMessageBox::error(this, i18n("Sorry, the image couldn't be processed."));
- imageBuffer.close();
- return;
- }
+ FetchAvatarJob *fetchJob = qobject_cast< FetchAvatarJob* >(job);
- Tp::Avatar avatar;
- avatar.avatarData = imageBuffer.readAll();
- avatar.MIMEType = mime->name();
+ Q_ASSERT(fetchJob);
foreach (const Tp::AccountPtr account, m_accountManager->allAccounts()) {
- Tp::PendingOperation *op = account->setAvatar(avatar);
+ Tp::PendingOperation *op = account->setAvatar(fetchJob->avatar());
//connect for eventual error displaying
connect(op, SIGNAL(finished(Tp::PendingOperation*)),
@@ -842,7 +834,7 @@ void MainWidget::loadAvatarFromFile()
//add the selected avatar to the avatar button
QIcon icon;
- icon.addPixmap(QPixmap::fromImage(QImage::fromData(avatar.avatarData)).scaled(48, 48));
+ icon.addPixmap(QPixmap::fromImage(QImage::fromData(fetchJob->avatar().avatarData)).scaled(48, 48));
m_userAccountIconButton->setIcon(icon);
//since all the accounts will have the same avatar,
@@ -852,6 +844,4 @@ void MainWidget::loadAvatarFromFile()
avatarGroup.writeEntry("method", "account");
avatarGroup.writeEntry("source", m_accountManager->allAccounts().first()->uniqueIdentifier());
avatarGroup.config()->sync();
-
- imageBuffer.close();
}
diff --git a/main-widget.h b/main-widget.h
index 310dfb6..9180d64 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -38,6 +38,7 @@ class AccountsModel;
class AccountFilterModel;
class ContactDelegate;
class FilterBar;
+class KJob;
class MainWidget : public KMainWindow, Ui::MainWindow
{
@@ -94,6 +95,7 @@ private Q_SLOTS:
void slotGenericOperationFinished(Tp::PendingOperation *operation); /** called when a Tp::PendingOperation finishes. Used to check for errors */
void slotStartTextChat();
void slotUnblockContactTriggered();
+ void onAvatarFetched(KJob*);
private:
AccountsModel *m_model;
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list