mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
generic: adjust to ThumbCreator changes
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
0eb0d1bcde
commit
a9b6e2dd29
6 changed files with 25 additions and 103 deletions
|
@ -51,8 +51,7 @@
|
||||||
// kde-workspace/kioslave/thumbnail/thumbnail.h
|
// kde-workspace/kioslave/thumbnail/thumbnail.h
|
||||||
enum PreviewDefaults {
|
enum PreviewDefaults {
|
||||||
MaxLocalSize = 20, // 20 MB
|
MaxLocalSize = 20, // 20 MB
|
||||||
MaxRemoteSize = 5, // 5 MB
|
MaxRemoteSize = 5 // 5 MB
|
||||||
IconAlpha = 125
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
||||||
|
@ -61,8 +60,7 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
||||||
m_listView(0),
|
m_listView(0),
|
||||||
m_enabledPreviewPlugins(),
|
m_enabledPreviewPlugins(),
|
||||||
m_localFileSizeBox(0),
|
m_localFileSizeBox(0),
|
||||||
m_remoteFileSizeBox(0),
|
m_remoteFileSizeBox(0)
|
||||||
m_iconAlphaBox(0)
|
|
||||||
{
|
{
|
||||||
QVBoxLayout* topLayout = new QVBoxLayout(this);
|
QVBoxLayout* topLayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
@ -102,28 +100,16 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
||||||
fileSizeLayout->addWidget(remoteFileSizeLabel, 1, 0);
|
fileSizeLayout->addWidget(remoteFileSizeLabel, 1, 0);
|
||||||
fileSizeLayout->addWidget(m_remoteFileSizeBox, 1, 1, Qt::AlignRight);
|
fileSizeLayout->addWidget(m_remoteFileSizeBox, 1, 1, Qt::AlignRight);
|
||||||
|
|
||||||
QLabel* iconAlphaLabel = new QLabel(i18nc("@label", "Icon alpha:"), this);
|
|
||||||
|
|
||||||
m_iconAlphaBox = new KIntNumInput(this);
|
|
||||||
m_iconAlphaBox->setSingleStep(1);
|
|
||||||
m_iconAlphaBox->setRange(0, 255);
|
|
||||||
|
|
||||||
QGridLayout* iconAlphaLayout = new QGridLayout(this);
|
|
||||||
iconAlphaLayout->addWidget(iconAlphaLabel, 0, 0);
|
|
||||||
iconAlphaLayout->addWidget(m_iconAlphaBox, 0, 1, Qt::AlignRight);
|
|
||||||
|
|
||||||
topLayout->addSpacing(KDialog::spacingHint());
|
topLayout->addSpacing(KDialog::spacingHint());
|
||||||
topLayout->addWidget(showPreviewsLabel);
|
topLayout->addWidget(showPreviewsLabel);
|
||||||
topLayout->addWidget(m_listView);
|
topLayout->addWidget(m_listView);
|
||||||
topLayout->addLayout(fileSizeLayout);
|
topLayout->addLayout(fileSizeLayout);
|
||||||
topLayout->addLayout(iconAlphaLayout);
|
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
|
|
||||||
connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed()));
|
connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed()));
|
||||||
connect(m_localFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
|
connect(m_localFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
|
||||||
connect(m_remoteFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
|
connect(m_remoteFileSizeBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
|
||||||
connect(m_iconAlphaBox, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewsSettingsPage::~PreviewsSettingsPage()
|
PreviewsSettingsPage::~PreviewsSettingsPage()
|
||||||
|
@ -159,10 +145,6 @@ void PreviewsSettingsPage::applySettings()
|
||||||
globalConfig.writeEntry("MaximumRemoteSize",
|
globalConfig.writeEntry("MaximumRemoteSize",
|
||||||
maximumRemoteSize,
|
maximumRemoteSize,
|
||||||
KConfigBase::Normal | KConfigBase::Global);
|
KConfigBase::Normal | KConfigBase::Global);
|
||||||
const int iconAlpha = m_iconAlphaBox->value();
|
|
||||||
globalConfig.writeEntry("IconAlpha",
|
|
||||||
iconAlpha,
|
|
||||||
KConfigBase::Normal | KConfigBase::Global);
|
|
||||||
globalConfig.sync();
|
globalConfig.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +152,6 @@ void PreviewsSettingsPage::restoreDefaults()
|
||||||
{
|
{
|
||||||
m_localFileSizeBox->setValue(PreviewDefaults::MaxLocalSize);
|
m_localFileSizeBox->setValue(PreviewDefaults::MaxLocalSize);
|
||||||
m_remoteFileSizeBox->setValue(PreviewDefaults::MaxRemoteSize);
|
m_remoteFileSizeBox->setValue(PreviewDefaults::MaxRemoteSize);
|
||||||
m_remoteFileSizeBox->setValue(PreviewDefaults::IconAlpha);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewsSettingsPage::showEvent(QShowEvent* event)
|
void PreviewsSettingsPage::showEvent(QShowEvent* event)
|
||||||
|
@ -236,9 +217,6 @@ void PreviewsSettingsPage::loadSettings()
|
||||||
const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024);
|
const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024);
|
||||||
m_localFileSizeBox->setValue(maxLocalMByteSize);
|
m_localFileSizeBox->setValue(maxLocalMByteSize);
|
||||||
m_remoteFileSizeBox->setValue(maxRemoteMByteSize);
|
m_remoteFileSizeBox->setValue(maxRemoteMByteSize);
|
||||||
const int defaultIconAlpha = static_cast<int>(PreviewDefaults::IconAlpha);
|
|
||||||
const int iconAlpha = globalConfig.readEntry("IconAlpha", defaultIconAlpha);
|
|
||||||
m_iconAlphaBox->setValue(iconAlpha);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "moc_previewssettingspage.cpp"
|
#include "moc_previewssettingspage.cpp"
|
||||||
|
|
|
@ -64,7 +64,6 @@ private:
|
||||||
QStringList m_enabledPreviewPlugins;
|
QStringList m_enabledPreviewPlugins;
|
||||||
KIntNumInput* m_localFileSizeBox;
|
KIntNumInput* m_localFileSizeBox;
|
||||||
KIntNumInput* m_remoteFileSizeBox;
|
KIntNumInput* m_remoteFileSizeBox;
|
||||||
KIntNumInput* m_iconAlphaBox;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -125,5 +125,5 @@ bool DjVuCreator::create(const QString &path, int width, int height, QImage &img
|
||||||
|
|
||||||
ThumbCreator::Flags DjVuCreator::flags() const
|
ThumbCreator::Flags DjVuCreator::flags() const
|
||||||
{
|
{
|
||||||
return ThumbCreator::Flags(ThumbCreator::DrawFrame | ThumbCreator::BlendIcon);
|
return ThumbCreator::Flags(ThumbCreator::DrawFrame);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,6 @@ bool TextCreator::create(const QString &path, int width, int height, QImage &img
|
||||||
|
|
||||||
ThumbCreator::Flags TextCreator::flags() const
|
ThumbCreator::Flags TextCreator::flags() const
|
||||||
{
|
{
|
||||||
return ThumbCreator::Flags(ThumbCreator::DrawFrame | ThumbCreator::BlendIcon);
|
return ThumbCreator::Flags(ThumbCreator::DrawFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,11 +59,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// Recognized metadata entries:
|
// Recognized metadata entries:
|
||||||
// mimeType - the mime type of the file, used for the overlay icon if any
|
|
||||||
// width - maximum width for the thumbnail
|
// width - maximum width for the thumbnail
|
||||||
// height - maximum height for the thumbnail
|
// height - maximum height for the thumbnail
|
||||||
// iconSize - the size of the overlay icon to use if any
|
|
||||||
// iconAlpha - the transparency value used for icon overlays
|
|
||||||
// plugin - the name of the plugin library to be used for thumbnail creation.
|
// plugin - the name of the plugin library to be used for thumbnail creation.
|
||||||
// Provided by the application to save an addition KTrader
|
// Provided by the application to save an addition KTrader
|
||||||
// query here.
|
// query here.
|
||||||
|
@ -105,63 +102,55 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
ThumbnailProtocol::ThumbnailProtocol(const QByteArray &app)
|
ThumbnailProtocol::ThumbnailProtocol(const QByteArray &app)
|
||||||
: SlaveBase("thumbnail", app),
|
: SlaveBase("thumbnail", app),
|
||||||
m_iconSize(0),
|
m_maxFileSize(0)
|
||||||
m_maxFileSize(0)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ThumbnailProtocol::~ThumbnailProtocol()
|
ThumbnailProtocol::~ThumbnailProtocol()
|
||||||
{
|
{
|
||||||
qDeleteAll( m_creators );
|
qDeleteAll(m_creators);
|
||||||
m_creators.clear();
|
m_creators.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThumbnailProtocol::get(const KUrl &url)
|
void ThumbnailProtocol::get(const KUrl &url)
|
||||||
{
|
{
|
||||||
m_mimeType = metaData("mimeType");
|
const QString mimeType = metaData("mimeType");
|
||||||
kDebug(7115) << "Wanting MIME Type:" << m_mimeType;
|
kDebug(7115) << "Wanting MIME Type:" << mimeType;
|
||||||
|
|
||||||
if (m_mimeType.isEmpty()) {
|
if (mimeType.isEmpty()) {
|
||||||
error(KIO::ERR_INTERNAL, i18n("No MIME Type specified."));
|
error(KIO::ERR_INTERNAL, i18n("No MIME Type specified."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_width = metaData("width").toInt();
|
m_width = metaData("width").toInt();
|
||||||
m_height = metaData("height").toInt();
|
m_height = metaData("height").toInt();
|
||||||
int iconSize = metaData("iconSize").toInt();
|
|
||||||
|
|
||||||
if (m_width < 0 || m_height < 0) {
|
if (m_width < 0 || m_height < 0) {
|
||||||
error(KIO::ERR_INTERNAL, i18n("No or invalid size specified."));
|
error(KIO::ERR_INTERNAL, i18n("No or invalid size specified."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!iconSize) {
|
QString plugin = metaData("plugin");
|
||||||
iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
|
if (plugin.isEmpty() && mimeType == QLatin1String("inode/directory")) {
|
||||||
|
// the directorythumbnail plugin is builtin
|
||||||
|
plugin = QLatin1String("directorythumbnail");
|
||||||
}
|
}
|
||||||
if (iconSize != m_iconSize) {
|
|
||||||
m_iconDict.clear();
|
|
||||||
}
|
|
||||||
m_iconSize = iconSize;
|
|
||||||
|
|
||||||
m_iconAlpha = metaData("iconAlpha").toInt();
|
if (plugin.isEmpty()) {
|
||||||
|
error(KIO::ERR_INTERNAL, i18n("No plugin specified."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QImage img;
|
QImage img;
|
||||||
ThumbCreator::Flags flags = ThumbCreator::None;
|
ThumbCreator::Flags flags = ThumbCreator::None;
|
||||||
|
|
||||||
QString plugin = metaData("plugin");
|
if (plugin == QLatin1String("directorythumbnail")) {
|
||||||
if ((plugin.isEmpty() || plugin == "directorythumbnail") && m_mimeType == "inode/directory") {
|
|
||||||
img = thumbForDirectory(url);
|
img = thumbForDirectory(url);
|
||||||
if(img.isNull()) {
|
if (img.isNull()) {
|
||||||
error(KIO::ERR_INTERNAL, i18n("Cannot create thumbnail for directory"));
|
error(KIO::ERR_INTERNAL, i18n("Cannot create thumbnail for directory"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (plugin.isEmpty()) {
|
|
||||||
error(KIO::ERR_INTERNAL, i18n("No plugin specified."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ThumbCreator* creator = getThumbCreator(plugin);
|
ThumbCreator* creator = getThumbCreator(plugin);
|
||||||
if(!creator) {
|
if(!creator) {
|
||||||
error(KIO::ERR_INTERNAL, i18n("Cannot load ThumbCreator %1", plugin));
|
error(KIO::ERR_INTERNAL, i18n("Cannot load ThumbCreator %1", plugin));
|
||||||
|
@ -192,24 +181,6 @@ void ThumbnailProtocol::get(const KUrl &url)
|
||||||
p.end();
|
p.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & ThumbCreator::BlendIcon) && KIconLoader::global()->alphaBlending(KIconLoader::Desktop)) {
|
|
||||||
// blending the mimetype icon in
|
|
||||||
QImage icon = getIcon();
|
|
||||||
const qreal widthratio = (qreal(img.width()) / icon.width());
|
|
||||||
const qreal heightratio = (qreal(img.height()) / icon.height());
|
|
||||||
// but only if it will not cover too much of the thumbnail
|
|
||||||
if (widthratio >= s_iconratio && heightratio >= s_iconratio) {
|
|
||||||
|
|
||||||
int x = img.width() - icon.width() - 4;
|
|
||||||
x = qMax( x, 0 );
|
|
||||||
int y = img.height() - icon.height() - 6;
|
|
||||||
y = qMax( y, 0 );
|
|
||||||
QPainter p(&img);
|
|
||||||
p.setOpacity(m_iconAlpha/255.0);
|
|
||||||
p.drawImage(x, y, icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (img.isNull()) {
|
if (img.isNull()) {
|
||||||
error(KIO::ERR_INTERNAL, i18n("Failed to create a thumbnail."));
|
error(KIO::ERR_INTERNAL, i18n("Failed to create a thumbnail."));
|
||||||
return;
|
return;
|
||||||
|
@ -221,14 +192,14 @@ void ThumbnailProtocol::get(const KUrl &url)
|
||||||
finished();
|
finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ThumbnailProtocol::pluginForMimeType(const QString& mimeType) {
|
QString ThumbnailProtocol::pluginForMimeType(const QString &mimeType) {
|
||||||
KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("ThumbCreator"));
|
KService::List offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String("ThumbCreator"));
|
||||||
if (!offers.isEmpty()) {
|
if (!offers.isEmpty()) {
|
||||||
const KService::Ptr serv = offers.first();
|
const KService::Ptr serv = offers.first();
|
||||||
return serv->library();
|
return serv->library();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Match group mimetypes
|
// Match group mimetypes
|
||||||
///@todo Move this into some central location together with the related matching code in previewjob.cpp. This doesn't handle inheritance and such
|
///@todo Move this into some central location together with the related matching code in previewjob.cpp. This doesn't handle inheritance and such
|
||||||
const KService::List plugins = KServiceTypeTrader::self()->query("ThumbCreator");
|
const KService::List plugins = KServiceTypeTrader::self()->query("ThumbCreator");
|
||||||
foreach(KService::Ptr plugin, plugins) {
|
foreach(KService::Ptr plugin, plugins) {
|
||||||
|
@ -334,12 +305,8 @@ QImage ThumbnailProtocol::thumbForDirectory(const KUrl& directory)
|
||||||
|
|
||||||
//Use the current (custom) folder icon
|
//Use the current (custom) folder icon
|
||||||
KUrl tempDirectory = directory;
|
KUrl tempDirectory = directory;
|
||||||
tempDirectory.setScheme("file"); //iconNameForUrl will not work with the "thumbnail:/" scheme
|
tempDirectory.setScheme("file"); // KMimeType will not work with the "thumbnail:/" scheme
|
||||||
QString iconName = KMimeType::iconNameForUrl(tempDirectory, S_IFDIR);
|
const QPixmap folder = KIO::pixmapForUrl(tempDirectory, KIconLoader::Desktop, qMin(m_width, m_height));
|
||||||
|
|
||||||
const QPixmap folder = KIconLoader::global()->loadMimeTypeIcon(iconName,
|
|
||||||
KIconLoader::Desktop,
|
|
||||||
qMin(m_width, m_height));
|
|
||||||
const int folderWidth = folder.width();
|
const int folderWidth = folder.width();
|
||||||
const int folderHeight = folder.height();
|
const int folderHeight = folder.height();
|
||||||
|
|
||||||
|
@ -518,21 +485,6 @@ ThumbCreator* ThumbnailProtocol::getThumbCreator(const QString& plugin)
|
||||||
return creator;
|
return creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const QImage ThumbnailProtocol::getIcon()
|
|
||||||
{
|
|
||||||
///@todo Can we really do this? It doesn't seem to respect the size
|
|
||||||
if (!m_iconDict.contains(m_mimeType)) { // generate it
|
|
||||||
QImage icon( KIconLoader::global()->loadMimeTypeIcon( KMimeType::mimeType(m_mimeType)->iconName(), KIconLoader::Desktop, m_iconSize ).toImage() );
|
|
||||||
icon = icon.convertToFormat(QImage::Format_ARGB32);
|
|
||||||
m_iconDict.insert(m_mimeType, icon);
|
|
||||||
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_iconDict.value(m_mimeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ThumbnailProtocol::createSubThumbnail(QImage& thumbnail, const QString& filePath,
|
bool ThumbnailProtocol::createSubThumbnail(QImage& thumbnail, const QString& filePath,
|
||||||
int segmentWidth, int segmentHeight)
|
int segmentWidth, int segmentHeight)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,8 +31,7 @@
|
||||||
// kdelibs/kio/kio/previewjob.cpp
|
// kdelibs/kio/kio/previewjob.cpp
|
||||||
enum PreviewDefaults {
|
enum PreviewDefaults {
|
||||||
MaxLocalSize = 20, // 20 MB
|
MaxLocalSize = 20, // 20 MB
|
||||||
MaxRemoteSize = 5, // 5 MB
|
MaxRemoteSize = 5 // 5 MB
|
||||||
IconAlpha = 125
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThumbCreator;
|
class ThumbCreator;
|
||||||
|
@ -47,7 +46,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ThumbCreator* getThumbCreator(const QString& plugin);
|
ThumbCreator* getThumbCreator(const QString& plugin);
|
||||||
const QImage getIcon();
|
|
||||||
bool isOpaque(const QImage &image) const;
|
bool isOpaque(const QImage &image) const;
|
||||||
void drawPictureFrame(QPainter *painter, const QPoint &pos, const QImage &image,
|
void drawPictureFrame(QPainter *painter, const QPoint &pos, const QImage &image,
|
||||||
int frameWidth, QSize imageTargetSize) const;
|
int frameWidth, QSize imageTargetSize) const;
|
||||||
|
@ -76,15 +74,10 @@ private:
|
||||||
bool drawSubThumbnail(QPainter& p, const QString& filePath, int width, int height,
|
bool drawSubThumbnail(QPainter& p, const QString& filePath, int width, int height,
|
||||||
int xPos, int yPos, int frameWidth);
|
int xPos, int yPos, int frameWidth);
|
||||||
private:
|
private:
|
||||||
QString m_mimeType;
|
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
int m_iconSize;
|
|
||||||
int m_iconAlpha;
|
|
||||||
// Thumbnail creators
|
// Thumbnail creators
|
||||||
QHash<QString, ThumbCreator*> m_creators;
|
QHash<QString, ThumbCreator*> m_creators;
|
||||||
// transparent icon cache
|
|
||||||
QHash<QString, QImage> m_iconDict;
|
|
||||||
QStringList m_enabledPlugins;
|
QStringList m_enabledPlugins;
|
||||||
QSet<QString> m_propagationDirectories;
|
QSet<QString> m_propagationDirectories;
|
||||||
QString m_thumbBasePath;
|
QString m_thumbBasePath;
|
||||||
|
|
Loading…
Add table
Reference in a new issue