[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [telepathy-send-file] /: Create preview for all file types,
From: Martin Klapetek <martin.klapetek () gmail ! com>
Date: 2011-10-31 19:07:41
Message-ID: 20111031190741.78626A60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 494d8014169e0a2429f0ad480e78a6a63297964d by Martin Klapetek.
Committed on 31/10/2011 at 19:59.
Pushed by mklapetek into branch 'master'.
Create preview for all file types, not only images. Also some small UI changes.
Reviewed-by: Daniele E. Domenichelli
REVIEW: 103002
M +21 -1 mainwindow.cpp
M +2 -2 mainwindow.h
M +23 -10 mainwindow.ui
http://commits.kde.org/telepathy-send-file/494d8014169e0a2429f0ad480e78a6a63297964d
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 64b41e1..31d28e9 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -29,6 +29,7 @@
#include <KMimeType>
#include <KDebug>
#include <KMessageBox>
+#include <KDE/KIO/PreviewJob>
#include <QAbstractItemDelegate>
#include <QPainter>
@@ -96,6 +97,7 @@ void ContactGridDelegate::paint(QPainter *painter, const \
QStyleOptionViewItem &o
QSize ContactGridDelegate::sizeHint(const QStyleOptionViewItem &option, const \
QModelIndex &index) const {
+ Q_UNUSED(index);
int textHeight = option.fontMetrics.height()*2;
return QSize(84, 80 + textHeight + 3);
}
@@ -112,9 +114,18 @@ MainWindow::MainWindow(const KUrl &url, QWidget *parent) :
kDebug() << KApplication::arguments();
- ui->filePreview->showPreview(url);
ui->fileNameLabel->setText(url.fileName());
+ KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url);
+ KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << file, QSize(280, \
280), &KIO::PreviewJob::availablePlugins()); + job->setOverlayIconAlpha(0);
+ job->setScaleType(KIO::PreviewJob::Unscaled);
+ connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
+ this, SLOT(onPreviewLoaded(KFileItem,QPixmap)));
+ connect(job, SIGNAL(failed(KFileItem)),
+ this, SLOT(onPreviewFailed(KFileItem)));
+
+
Tp::AccountFactoryPtr accountFactory = \
Tp::AccountFactory::create(QDBusConnection::sessionBus(),
\
Tp::Features() << Tp::Account::FeatureCore
<< \
Tp::Account::FeatureAvatar @@ -217,4 +228,13 @@ void \
MainWindow::slotFileTransferFinished(Tp::PendingOperation* op) }
}
+void MainWindow::onPreviewLoaded(const KFileItem& item, const QPixmap& preview)
+{
+ Q_UNUSED(item);
+ ui->filePreview->setPixmap(preview);
+}
+void MainWindow::onPreviewFailed(const KFileItem& item)
+{
+ kWarning() << "Loading thumb failed" << item.name();
+}
diff --git a/mainwindow.h b/mainwindow.h
index 4c40102..35250dc 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -27,7 +27,6 @@
#include <TelepathyQt4/AccountManager>
-
namespace Ui {
class MainWindow;
}
@@ -46,7 +45,8 @@ public:
private slots:
void onAccountManagerReady();
void onDialogAccepted();
-
+ void onPreviewLoaded(const KFileItem &item, const QPixmap &preview);
+ void onPreviewFailed(const KFileItem &item);
void slotFileTransferFinished(Tp::PendingOperation *op);
private:
diff --git a/mainwindow.ui b/mainwindow.ui
index d99ce3b..0dc57de 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -54,7 +54,20 @@
</spacer>
</item>
<item>
- <widget class="KImageFilePreview" name="filePreview"/>
+ <widget class="QLabel" name="filePreview">
+ <property name="minimumSize">
+ <size>
+ <width>280</width>
+ <height>280</height>
+ </size>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
</item>
<item>
<widget class="QLabel" name="fileNameLabel">
@@ -82,6 +95,8 @@
</layout>
</item>
<item>
+ <layout class="QVBoxLayout" name="verticalLayout2">
+ <item>
<widget class="QListView" name="listView">
<property name="minimumSize">
<size>
@@ -89,6 +104,12 @@
<height>0</height>
</size>
</property>
+ <property name="sizeIncrement">
+ <size>
+ <width>80</width>
+ <height>0</height>
+ </size>
+ </property>
<property name="baseSize">
<size>
<width>260</width>
@@ -115,8 +136,7 @@
</property>
</widget>
</item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout_2"/>
+ </layout>
</item>
</layout>
</item>
@@ -129,13 +149,6 @@
</item>
</layout>
</widget>
- <customwidgets>
- <customwidget>
- <class>KImageFilePreview</class>
- <extends>QWidget</extends>
- <header>kimagefilepreview.h</header>
- </customwidget>
- </customwidgets>
<resources/>
<connections/>
</ui>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic