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
|
||||
enum PreviewDefaults {
|
||||
MaxLocalSize = 20, // 20 MB
|
||||
MaxRemoteSize = 5, // 5 MB
|
||||
IconAlpha = 125
|
||||
MaxRemoteSize = 5 // 5 MB
|
||||
};
|
||||
|
||||
PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
||||
|
@ -61,8 +60,7 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
|||
m_listView(0),
|
||||
m_enabledPreviewPlugins(),
|
||||
m_localFileSizeBox(0),
|
||||
m_remoteFileSizeBox(0),
|
||||
m_iconAlphaBox(0)
|
||||
m_remoteFileSizeBox(0)
|
||||
{
|
||||
QVBoxLayout* topLayout = new QVBoxLayout(this);
|
||||
|
||||
|
@ -102,28 +100,16 @@ PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
|
|||
fileSizeLayout->addWidget(remoteFileSizeLabel, 1, 0);
|
||||
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->addWidget(showPreviewsLabel);
|
||||
topLayout->addWidget(m_listView);
|
||||
topLayout->addLayout(fileSizeLayout);
|
||||
topLayout->addLayout(iconAlphaLayout);
|
||||
|
||||
loadSettings();
|
||||
|
||||
connect(m_listView, SIGNAL(clicked(QModelIndex)), this, SIGNAL(changed()));
|
||||
connect(m_localFileSizeBox, 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()
|
||||
|
@ -159,10 +145,6 @@ void PreviewsSettingsPage::applySettings()
|
|||
globalConfig.writeEntry("MaximumRemoteSize",
|
||||
maximumRemoteSize,
|
||||
KConfigBase::Normal | KConfigBase::Global);
|
||||
const int iconAlpha = m_iconAlphaBox->value();
|
||||
globalConfig.writeEntry("IconAlpha",
|
||||
iconAlpha,
|
||||
KConfigBase::Normal | KConfigBase::Global);
|
||||
globalConfig.sync();
|
||||
}
|
||||
|
||||
|
@ -170,7 +152,6 @@ void PreviewsSettingsPage::restoreDefaults()
|
|||
{
|
||||
m_localFileSizeBox->setValue(PreviewDefaults::MaxLocalSize);
|
||||
m_remoteFileSizeBox->setValue(PreviewDefaults::MaxRemoteSize);
|
||||
m_remoteFileSizeBox->setValue(PreviewDefaults::IconAlpha);
|
||||
}
|
||||
|
||||
void PreviewsSettingsPage::showEvent(QShowEvent* event)
|
||||
|
@ -236,9 +217,6 @@ void PreviewsSettingsPage::loadSettings()
|
|||
const int maxRemoteMByteSize = maxRemoteByteSize / (1024 * 1024);
|
||||
m_localFileSizeBox->setValue(maxLocalMByteSize);
|
||||
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"
|
||||
|
|
|
@ -64,7 +64,6 @@ private:
|
|||
QStringList m_enabledPreviewPlugins;
|
||||
KIntNumInput* m_localFileSizeBox;
|
||||
KIntNumInput* m_remoteFileSizeBox;
|
||||
KIntNumInput* m_iconAlphaBox;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -125,5 +125,5 @@ bool DjVuCreator::create(const QString &path, int width, int height, QImage &img
|
|||
|
||||
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
|
||||
{
|
||||
return ThumbCreator::Flags(ThumbCreator::DrawFrame | ThumbCreator::BlendIcon);
|
||||
return ThumbCreator::Flags(ThumbCreator::DrawFrame);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,11 +59,8 @@
|
|||
#include <iostream>
|
||||
|
||||
// Recognized metadata entries:
|
||||
// mimeType - the mime type of the file, used for the overlay icon if any
|
||||
// width - maximum width 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.
|
||||
// Provided by the application to save an addition KTrader
|
||||
// query here.
|
||||
|
@ -105,63 +102,55 @@ int main(int argc, char **argv)
|
|||
|
||||
ThumbnailProtocol::ThumbnailProtocol(const QByteArray &app)
|
||||
: SlaveBase("thumbnail", app),
|
||||
m_iconSize(0),
|
||||
m_maxFileSize(0)
|
||||
m_maxFileSize(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ThumbnailProtocol::~ThumbnailProtocol()
|
||||
{
|
||||
qDeleteAll( m_creators );
|
||||
qDeleteAll(m_creators);
|
||||
m_creators.clear();
|
||||
}
|
||||
|
||||
void ThumbnailProtocol::get(const KUrl &url)
|
||||
{
|
||||
m_mimeType = metaData("mimeType");
|
||||
kDebug(7115) << "Wanting MIME Type:" << m_mimeType;
|
||||
const QString mimeType = metaData("mimeType");
|
||||
kDebug(7115) << "Wanting MIME Type:" << mimeType;
|
||||
|
||||
if (m_mimeType.isEmpty()) {
|
||||
if (mimeType.isEmpty()) {
|
||||
error(KIO::ERR_INTERNAL, i18n("No MIME Type specified."));
|
||||
return;
|
||||
}
|
||||
|
||||
m_width = metaData("width").toInt();
|
||||
m_height = metaData("height").toInt();
|
||||
int iconSize = metaData("iconSize").toInt();
|
||||
|
||||
if (m_width < 0 || m_height < 0) {
|
||||
error(KIO::ERR_INTERNAL, i18n("No or invalid size specified."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!iconSize) {
|
||||
iconSize = KIconLoader::global()->currentSize(KIconLoader::Desktop);
|
||||
QString plugin = metaData("plugin");
|
||||
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;
|
||||
ThumbCreator::Flags flags = ThumbCreator::None;
|
||||
|
||||
QString plugin = metaData("plugin");
|
||||
if ((plugin.isEmpty() || plugin == "directorythumbnail") && m_mimeType == "inode/directory") {
|
||||
if (plugin == QLatin1String("directorythumbnail")) {
|
||||
img = thumbForDirectory(url);
|
||||
if(img.isNull()) {
|
||||
if (img.isNull()) {
|
||||
error(KIO::ERR_INTERNAL, i18n("Cannot create thumbnail for directory"));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (plugin.isEmpty()) {
|
||||
error(KIO::ERR_INTERNAL, i18n("No plugin specified."));
|
||||
return;
|
||||
}
|
||||
|
||||
ThumbCreator* creator = getThumbCreator(plugin);
|
||||
if(!creator) {
|
||||
error(KIO::ERR_INTERNAL, i18n("Cannot load ThumbCreator %1", plugin));
|
||||
|
@ -192,24 +181,6 @@ void ThumbnailProtocol::get(const KUrl &url)
|
|||
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()) {
|
||||
error(KIO::ERR_INTERNAL, i18n("Failed to create a thumbnail."));
|
||||
return;
|
||||
|
@ -221,14 +192,14 @@ void ThumbnailProtocol::get(const KUrl &url)
|
|||
finished();
|
||||
}
|
||||
|
||||
QString ThumbnailProtocol::pluginForMimeType(const QString& mimeType) {
|
||||
KService::List offers = KMimeTypeTrader::self()->query( mimeType, QLatin1String("ThumbCreator"));
|
||||
QString ThumbnailProtocol::pluginForMimeType(const QString &mimeType) {
|
||||
KService::List offers = KMimeTypeTrader::self()->query(mimeType, QLatin1String("ThumbCreator"));
|
||||
if (!offers.isEmpty()) {
|
||||
const KService::Ptr serv = offers.first();
|
||||
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
|
||||
const KService::List plugins = KServiceTypeTrader::self()->query("ThumbCreator");
|
||||
foreach(KService::Ptr plugin, plugins) {
|
||||
|
@ -334,12 +305,8 @@ QImage ThumbnailProtocol::thumbForDirectory(const KUrl& directory)
|
|||
|
||||
//Use the current (custom) folder icon
|
||||
KUrl tempDirectory = directory;
|
||||
tempDirectory.setScheme("file"); //iconNameForUrl will not work with the "thumbnail:/" scheme
|
||||
QString iconName = KMimeType::iconNameForUrl(tempDirectory, S_IFDIR);
|
||||
|
||||
const QPixmap folder = KIconLoader::global()->loadMimeTypeIcon(iconName,
|
||||
KIconLoader::Desktop,
|
||||
qMin(m_width, m_height));
|
||||
tempDirectory.setScheme("file"); // KMimeType will not work with the "thumbnail:/" scheme
|
||||
const QPixmap folder = KIO::pixmapForUrl(tempDirectory, KIconLoader::Desktop, qMin(m_width, m_height));
|
||||
const int folderWidth = folder.width();
|
||||
const int folderHeight = folder.height();
|
||||
|
||||
|
@ -518,21 +485,6 @@ ThumbCreator* ThumbnailProtocol::getThumbCreator(const QString& plugin)
|
|||
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,
|
||||
int segmentWidth, int segmentHeight)
|
||||
{
|
||||
|
|
|
@ -31,8 +31,7 @@
|
|||
// kdelibs/kio/kio/previewjob.cpp
|
||||
enum PreviewDefaults {
|
||||
MaxLocalSize = 20, // 20 MB
|
||||
MaxRemoteSize = 5, // 5 MB
|
||||
IconAlpha = 125
|
||||
MaxRemoteSize = 5 // 5 MB
|
||||
};
|
||||
|
||||
class ThumbCreator;
|
||||
|
@ -47,7 +46,6 @@ public:
|
|||
|
||||
protected:
|
||||
ThumbCreator* getThumbCreator(const QString& plugin);
|
||||
const QImage getIcon();
|
||||
bool isOpaque(const QImage &image) const;
|
||||
void drawPictureFrame(QPainter *painter, const QPoint &pos, const QImage &image,
|
||||
int frameWidth, QSize imageTargetSize) const;
|
||||
|
@ -76,15 +74,10 @@ private:
|
|||
bool drawSubThumbnail(QPainter& p, const QString& filePath, int width, int height,
|
||||
int xPos, int yPos, int frameWidth);
|
||||
private:
|
||||
QString m_mimeType;
|
||||
int m_width;
|
||||
int m_height;
|
||||
int m_iconSize;
|
||||
int m_iconAlpha;
|
||||
// Thumbnail creators
|
||||
QHash<QString, ThumbCreator*> m_creators;
|
||||
// transparent icon cache
|
||||
QHash<QString, QImage> m_iconDict;
|
||||
QStringList m_enabledPlugins;
|
||||
QSet<QString> m_propagationDirectories;
|
||||
QString m_thumbBasePath;
|
||||
|
|
Loading…
Add table
Reference in a new issue