Commit 8657410f authored by Fabian Vogt's avatar Fabian Vogt
Browse files

Remove dead preview code (part 2)

5b71c22b removed preview code, but for some reason omitted some files.
parent 912f7986
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "applicationplugin.h"
#include <KGlobal>
#include <KStandardDirs>
#include <QDebug>
#include <QDeclarativeComponent>
#include <KService>
ApplicationPlugin::ApplicationPlugin(QObject* parent, const QVariantList&): PreviewPlugin(parent)
{
}
void ApplicationPlugin::generatePreview()
{
QString qmlFile = KGlobal::dirs()->findResource("data", "plasma/plasmoids/org.kde.milou/contents/ui/previews/Audio.qml");
QDeclarativeComponent* component = new QDeclarativeComponent(context()->engine(), qmlFile, this);
if (component->status() == QDeclarativeComponent::Error) {
qWarning() << component->errorString();
return;
}
QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component->create());
const QString entryPath = url().toLocalFile();
KService::Ptr service = KService::serviceByDesktopPath(entryPath);
if (!service) {
return;
}
item->setProperty("title", service->name());
//item->setProperty("keys", QVariant::fromValue(keys));
//item->setProperty("values", QVariant::fromValue(values));
//item->setProperty("length", keys.length());
item->setProperty("length", 0);
item->setProperty("iconName", service->icon());
Q_EMIT previewGenerated(item);
}
MILOU_EXPORT_PREVIEW(ApplicationPlugin, "milouapplicationplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "audioplugin.h"
#include <KGlobal>
#include <KStandardDirs>
#include <QDebug>
#include <QDeclarativeComponent>
#include <kfilemetadata/properties.h>
AudioPlugin::AudioPlugin(QObject* parent, const QVariantList&): PreviewPlugin(parent)
{
}
void AudioPlugin::generatePreview()
{
Baloo::FileFetchJob* job = new Baloo::FileFetchJob(url().toLocalFile());
connect(job, SIGNAL(fileReceived(Baloo::File)),
this, SLOT(slotFileReceived(Baloo::File)));
job->start();
}
void AudioPlugin::slotFileReceived(const Baloo::File& file)
{
QString qmlFile = KGlobal::dirs()->findResource("data", "plasma/plasmoids/org.kde.milou/contents/ui/previews/Audio.qml");
QDeclarativeComponent* component = new QDeclarativeComponent(context()->engine(), qmlFile, this);
if (component->status() == QDeclarativeComponent::Error) {
qWarning() << component->errorString();
return;
}
QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component->create());
QStringList keys;
keys << i18n("Artist:") << i18n("Album:") << i18n("Duration:");
QStringList values;
values << file.property(KFileMetaData::Property::Artist).toString();
values << file.property(KFileMetaData::Property::Album).toString();
int duration = file.property(KFileMetaData::Property::Duration).toInt();
QTime time;
time = time.addSecs(duration);
if (time.hour())
values << time.toString();
else
values << time.toString("m:ss");
item->setProperty("title", file.property(KFileMetaData::Property::Title).toString());
item->setProperty("keys", QVariant::fromValue(keys));
item->setProperty("values", QVariant::fromValue(values));
item->setProperty("length", keys.length());
item->setProperty("iconName", QLatin1String("audio-x-flac"));
Q_EMIT previewGenerated(item);
}
MILOU_EXPORT_PREVIEW(AudioPlugin, "milouaudioplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "bookmarkplugin.h"
#include <QWebView>
BookmarkPlugin::BookmarkPlugin(QObject* parent, const QVariantList& ): PreviewPlugin(parent)
{
}
void BookmarkPlugin::generatePreview()
{
QWebView* webView = new QWebView();
webView->load(url());
webView->resize(512, 512);
Q_EMIT previewGenerated(webView);
}
MILOU_EXPORT_PREVIEW(BookmarkPlugin, "miloubookmarkplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "emailplugin.h"
#include <KMime/Message>
#include <KMimeType>
#include <QIcon>
#include <Akonadi/ItemFetchScope>
#include <QTextDocument>
#include <QTextCursor>
#include <QTextEdit>
#include <QTextTable>
EmailPlugin::EmailPlugin(QObject* parent, const QVariantList& )
: PreviewPlugin(parent)
{
}
void EmailPlugin::generatePreview()
{
if (url().scheme() != QLatin1String("akonadi")) {
qWarning() << "We only support akonadi urls";
return;
}
Akonadi::ItemFetchJob* job = new Akonadi::ItemFetchJob(Akonadi::Item::fromUrl(url()));
job->fetchScope().fetchFullPayload();
connect(job, SIGNAL(itemsReceived(Akonadi::Item::List)),
this, SLOT(slotItemsReceived(Akonadi::Item::List)));
}
void EmailPlugin::slotItemsReceived(const Akonadi::Item::List& itemList)
{
if (itemList.empty()) {
return;
}
Akonadi::Item item = itemList.first();
KMime::Message msg;
msg.setContent(item.payloadData());
msg.setFrozen(true);
msg.parse();
KMime::Headers::Subject *subject = msg.subject();
KMime::Headers::From *from = msg.from();
KMime::Headers::To *to = msg.to();
KMime::Headers::Date* date = msg.date();
QString dateString = KGlobal::locale()->formatDateTime(date->dateTime(),
KLocale::FancyShortDate, KLocale::Seconds);
KMime::Content* textContent = msg.textContent();
KMime::Content* htmlContent = msg.mainBodyPart("text/html");
QTextCharFormat greyCharFormat;
greyCharFormat.setForeground(QBrush(Qt::gray));
QTextCharFormat normalCharFormat;
QTextCharFormat boldCharFormat;
QFont f = boldCharFormat.font();
f.setBold(true);
boldCharFormat.setFont(f);
QTextBlockFormat rightAlignment;
rightAlignment.setAlignment(Qt::AlignRight);
QTextBlockFormat leftAlignment;
leftAlignment.setAlignment(Qt::AlignLeft);
leftAlignment.setLeftMargin(3);
QTextDocument* doc = new QTextDocument(this);
QTextCursor cursor(doc);
QTextTable* table = cursor.insertTable(4, 2);
table->cellAt(0, 0).firstCursorPosition().setBlockFormat(rightAlignment);
table->cellAt(0, 0).firstCursorPosition().insertText(i18n("From:"), greyCharFormat);
table->cellAt(0, 1).firstCursorPosition().setBlockFormat(leftAlignment);
table->cellAt(0, 1).firstCursorPosition().insertText(from->asUnicodeString(), normalCharFormat);
table->cellAt(1, 0).firstCursorPosition().setBlockFormat(rightAlignment);
table->cellAt(1, 0).firstCursorPosition().insertText(i18n("To:"), greyCharFormat);
table->cellAt(1, 1).firstCursorPosition().setBlockFormat(leftAlignment);
table->cellAt(1, 1).firstCursorPosition().insertText(to->asUnicodeString(), normalCharFormat);
table->cellAt(2, 0).firstCursorPosition().setBlockFormat(rightAlignment);
table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Date:"), greyCharFormat);
table->cellAt(2, 1).firstCursorPosition().setBlockFormat(leftAlignment);
table->cellAt(2, 1).firstCursorPosition().insertText(dateString, normalCharFormat);
table->cellAt(3, 0).firstCursorPosition().setBlockFormat(rightAlignment);
table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Subject:"), greyCharFormat);
table->cellAt(3, 1).firstCursorPosition().setBlockFormat(leftAlignment);
table->cellAt(3, 1).firstCursorPosition().insertText(subject->asUnicodeString(), boldCharFormat);
QTextTableFormat tableFormat;
tableFormat.setBorder(0);
table->setFormat(tableFormat);
cursor = table->lastCursorPosition();
cursor.setPosition(cursor.position()+1);
cursor.insertText("\n\n");
if (!htmlContent)
insertEmailBody(cursor, textContent->decodedText(true, true));
else
cursor.insertHtml(htmlContent->decodedText(true, true));
// Attachments
const KMime::Content::List list = msg.attachments();
if (list.count())
cursor.insertText(i18n("\nAttachments:\n\n"), greyCharFormat);
for (KMime::Content *c : list) {
KMime::Headers::ContentType* contentType = c->contentType(false);
KMimeType::Ptr mimetype = KMimeType::mimeType(contentType->mimeType());
if (!mimetype->isValid())
continue;
QString iconName = mimetype->iconName();
QImage icon = QIcon::fromTheme(iconName).pixmap(32, 32).toImage();
cursor.insertImage(icon);
cursor.insertText(contentType->name() + "\n");
}
QTextEdit* edit = new QTextEdit();
edit->setDocument(doc);
edit->setReadOnly(true);
// Maybe the height should be reduced based on the contents? Also maybe the width
// could be increased for html emails
edit->resize(384, 384);
highlight(doc);
Q_EMIT previewGenerated(edit);
}
// Inserts quoted text in green
void EmailPlugin::insertEmailBody(QTextCursor& cursor, const QString& body)
{
QTextCharFormat greenFormat;
greenFormat.setForeground(QBrush(Qt::darkGreen));
QString b(body);
QTextStream stream(&b, QIODevice::ReadOnly);
while (!stream.atEnd()) {
QString line = stream.readLine();
if (line.startsWith('>')) {
cursor.insertText(line, greenFormat);
cursor.insertText("\n");
}
else {
cursor.insertText(line, QTextCharFormat());
cursor.insertText("\n");
}
}
}
MILOU_EXPORT_PREVIEW(EmailPlugin, "milouemailplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "fileplugin.h"
#include <KGlobal>
#include <KStandardDirs>
#include <QDebug>
#include <QDeclarativeComponent>
#include <QFileInfo>
#include <KLocale>
#include <KMimeType>
FilePlugin::FilePlugin(QObject* parent, const QVariantList&): PreviewPlugin(parent)
{
}
void FilePlugin::generatePreview()
{
QFileInfo fileInfo(url().toLocalFile());
QString qmlFile = KGlobal::dirs()->findResource("data", "plasma/plasmoids/org.kde.milou/contents/ui/previews/Audio.qml");
QDeclarativeComponent* component = new QDeclarativeComponent(context()->engine(), qmlFile, this);
if (component->status() == QDeclarativeComponent::Error) {
qWarning() << component->errorString();
return;
}
QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(component->create());
QStringList keys;
keys << i18n("Modified:") << i18n("Size:");
QStringList values;
values << KGlobal::locale()->formatDateTime(fileInfo.lastModified(), KLocale::FancyShortDate);
values << KGlobal::locale()->formatByteSize(fileInfo.size());
item->setProperty("title", fileInfo.fileName());
item->setProperty("keys", QVariant::fromValue(keys));
item->setProperty("values", QVariant::fromValue(values));
item->setProperty("length", keys.length());
KMimeType::Ptr mime = KMimeType::findByUrl(url());
if (!mime.isNull())
item->setProperty("iconName", mime->iconName());
Q_EMIT previewGenerated(item);
}
MILOU_EXPORT_PREVIEW(FilePlugin, "miloufileplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "imageplugin.h"
#include <QPainter>
#include <QDebug>
ImagePlugin::ImagePlugin(QObject* parent, const QVariantList& ): PreviewPlugin(parent)
{
}
void ImagePlugin::generatePreview()
{
KFileItemList itemList;
itemList << KFileItem(url(), mimetype(), mode_t());
QStringList enabledPlugins;
enabledPlugins << "imagethumbnail" << "jpegthumbnail" << "directorythumbnail"
<< "videopreview" << "ffmpegthumbs";
QSize size(512, 512);
if (mimetype() == QLatin1String("inode/directory")) {
size = QSize(256, 256);
}
KIO::PreviewJob* job = new KIO::PreviewJob(itemList, size, &enabledPlugins);
job->setScaleType(KIO::PreviewJob::ScaledAndCached);
connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
this, SLOT(slotGotPreview(KFileItem,QPixmap)));
connect(job, SIGNAL(finished(KJob*)),
this, SLOT(slotJobFinished(KJob*)));
job->start();
}
namespace {
class ImageItem: public QDeclarativeItem {
public:
void paint(QPainter* painter, const QStyleOptionGraphicsItem* , QWidget* ) {
if (!m_pixmap.isNull()) {
painter->drawPixmap(x(), y(), width(), height(), m_pixmap);
}
}
QPixmap m_pixmap;
};
}
void ImagePlugin::slotGotPreview(const KFileItem&, const QPixmap& pixmap)
{
ImageItem* declarativeItem = new ImageItem();
declarativeItem->m_pixmap = pixmap;
declarativeItem->setFlag(QGraphicsItem::ItemHasNoContents, false);
declarativeItem->setWidth(pixmap.width());
declarativeItem->setHeight(pixmap.height());
Q_EMIT previewGenerated(declarativeItem);
}
void ImagePlugin::slotJobFinished(KJob* job)
{
if (job->error())
qWarning() << job->errorString();
}
MILOU_EXPORT_PREVIEW(ImagePlugin, "milouimageplugin", "milou")
/*
* This file is part of the KDE Milou Project
* Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
*
* 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) version 3, or any
* later version accepted by the membership of KDE e.V. (or its
* successor approved by the membership of KDE e.V.), which shall
* act as a proxy defined in Section 6 of version 3 of the license.
*
* 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "okularplugin.h"
#include <KParts/ReadOnlyPart>
#include <QDebug>
OkularPlugin::OkularPlugin(QObject* parent, const QVariantList& ): PreviewPlugin(parent)
{
}
void OkularPlugin::generatePreview()
{
// FIXME: You will need to create your own config file, so that the last accessed page
// is not opened
KService::Ptr service = KService::serviceByDesktopName("okular_part");
if (service) {
QVariantList args;
args << QLatin1String("ViewerWidget");
KParts::ReadOnlyPart* part = service->createInstance<KParts::ReadOnlyPart>(this, args);
part->openUrl(url());
QWidget* widget = part->widget();
widget->resize(384, 384);
Q_EMIT previewGenerated(widget);
}
else {
qWarning() << "Could not load okular service!";
}
}
MILOU_EXPORT_PREVIEW(OkularPlugin, "milouokularplugin", "milou")
/*
* <one line to give the library's name and an idea of what it does.>
* Copyright 2013 Vishesh Handa <me@vhanda.in>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/