Page MenuHomePhorge

No OneTemporary

diff --git a/experimental/libkdeclarative/CMakeLists.txt b/experimental/libkdeclarative/CMakeLists.txt
index 5fe5ff6f1a..0db647ce49 100644
--- a/experimental/libkdeclarative/CMakeLists.txt
+++ b/experimental/libkdeclarative/CMakeLists.txt
@@ -1,63 +1,54 @@
project(kdeclarative)
if(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION)
set(KDECLARATIVE_NO_KIO TRUE)
endif(KDE_PLATFORM_FEATURE_BINARY_COMPATIBLE_FEATURE_REDUCTION)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kdeclarative.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kdeclarative.h)
include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${KDE4_KIO_INCLUDES}
${CMAKE_SOURCE_DIR}/kio
)
if(BUILDING_EXPERIMENTAL_SEPARATELY)
include_directories(${KDE4_INCLUDES})
endif()
set(kdeclarative_LIB_SRCS
kdeclarative.cpp
private/engineaccess.cpp
private/kiconprovider.cpp
bindings/qscriptnonguibookkeeping.cpp
bindings/i18n.cpp
bindings/icon.cpp
- bindings/url.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/icons/kicon.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/icons/kiconengine.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/icons/kiconloader.cpp
- #${CMAKE_SOURCE_DIR}/kdeui/icons/kiconeffect.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/icons/kicontheme.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/kernel/kglobalsettings.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/colors/kcolorscheme.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/colors/kcolorspaces.cpp
- ${CMAKE_SOURCE_DIR}/kdeui/colors/kcolorutils.cpp)
+ bindings/url.cpp)
kde4_add_library(kdeclarative SHARED ${kdeclarative_LIB_SRCS})
set_target_properties(kdeclarative PROPERTIES VERSION ${KDE_NON_GENERIC_LIB_VERSION} SOVERSION ${KDE_NON_GENERIC_LIB_SOVERSION})
-target_link_libraries(kdeclarative ${KDE4_KDECORE_LIBS} ${QT_QTSVG_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSCRIPT_LIBRARY} ${X11_LIBRARIES} ${X11_Xcursor_LIB} ${QT_QTDECLARATIVE_LIBRARY})
+target_link_libraries(kdeclarative ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${QT_QTSCRIPT_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
## test
set(kdeclarative_TEST_SRCS
test/test.cpp)
kde4_add_executable(kdeclarativetest ${kdeclarative_TEST_SRCS})
target_link_libraries(kdeclarativetest kdeclarative ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTSCRIPT_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY})
## install
set(kdeclarative_LIB_HEADERS
kdeclarative.h
kdeclarative_export.h)
install(FILES ${kdeclarative_LIB_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/ COMPONENT Devel)
install(TARGETS kdeclarative EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
diff --git a/experimental/libkdeclarative/bindings/icon.cpp b/experimental/libkdeclarative/bindings/icon.cpp
index 892bd2145e..7188d635dd 100644
--- a/experimental/libkdeclarative/bindings/icon.cpp
+++ b/experimental/libkdeclarative/bindings/icon.cpp
@@ -1,113 +1,112 @@
/*
* Copyright (c) 2009 Aaron J. Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License version 2 as
* published by the Free Software Foundation
*
* 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QtScript/QScriptValue>
#include <QtScript/QScriptEngine>
#include <QtScript/QScriptContext>
-#define KICONLOADER_WITHOUTEFFECTS
#include <kicon.h>
#include "backportglobal.h"
Q_DECLARE_METATYPE(QIcon)
Q_DECLARE_METATYPE(QIcon*)
Q_DECLARE_METATYPE(KIcon)
Q_DECLARE_METATYPE(KIcon*)
static QScriptValue iconCtor(QScriptContext *ctx, QScriptEngine *eng)
{
if (ctx->argumentCount() > 0) {
QScriptValue v = ctx->argument(0);
if (v.isString()) {
QIcon icon = KIcon(v.toString());
return qScriptValueFromValue(eng, icon);
} else if (v.isVariant()) {
QVariant variant = v.toVariant();
QPixmap p = variant.value<QPixmap>();
if (!p.isNull()) {
return qScriptValueFromValue(eng, QIcon(p));
}
}
}
return qScriptValueFromValue(eng, QIcon());
}
static QScriptValue addPixmap(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QIcon, addPixmap);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
if (arg.isVariant()) {
QVariant variant = arg.toVariant();
QPixmap p = variant.value<QPixmap>();
if (!p.isNull()) {
self->addPixmap(p);
}
}
}
return eng->undefinedValue();
}
static QScriptValue addFile(QScriptContext *ctx, QScriptEngine *eng)
{
DECLARE_SELF(QIcon, addFile);
if (ctx->argumentCount() > 0) {
QScriptValue arg = ctx->argument(0);
if (arg.isString()) {
self->addFile(arg.toString());
}
}
return eng->undefinedValue();
}
static QScriptValue isNull(QScriptContext *ctx, QScriptEngine *eng)
{
Q_UNUSED(eng)
DECLARE_SELF(QIcon, isNull);
return self->isNull();
}
QScriptValue constructIconClass(QScriptEngine *eng)
{
QScriptValue proto = qScriptValueFromValue(eng, QIcon());
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
proto.setProperty("addPixmap", eng->newFunction(addPixmap));
proto.setProperty("addFile", eng->newFunction(addFile));
proto.setProperty("null", eng->newFunction(isNull), getter);
QScriptValue ctorFun = eng->newFunction(iconCtor, proto);
ADD_ENUM_VALUE(ctorFun, QIcon, Normal);
ADD_ENUM_VALUE(ctorFun, QIcon, Disabled);
ADD_ENUM_VALUE(ctorFun, QIcon, Active);
ADD_ENUM_VALUE(ctorFun, QIcon, Selected);
ADD_ENUM_VALUE(ctorFun, QIcon, Off);
ADD_ENUM_VALUE(ctorFun, QIcon, On);
eng->setDefaultPrototype(qMetaTypeId<QIcon>(), proto);
return ctorFun;
}
diff --git a/kdeui/icons/kiconloader.cpp b/kdeui/icons/kiconloader.cpp
index 5310765616..d89360ca1a 100644
--- a/kdeui/icons/kiconloader.cpp
+++ b/kdeui/icons/kiconloader.cpp
@@ -1,1732 +1,1722 @@
/* vi: ts=8 sts=4 sw=4
*
* kiconloader.cpp: An icon loader for KDE with theming functionality.
*
* This file is part of the KDE project, module kdeui.
* Copyright (C) 2000 Geert Jansen <jansen@kde.org>
* Antonio Larrosa <larrosa@kde.org>
* 2010 Michael Pyne <mpyne@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kiconloader.h"
#include <sys/types.h>
#include <stdlib.h> //for abs
#include <unistd.h> //for readlink
#include <dirent.h>
#include <assert.h>
#include <QtCore/QCache>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/QBuffer>
#include <QtCore/QDataStream>
#include <QtCore/QByteArray>
#include <QtCore/QStringBuilder> // % operator for QString
#include <QtGui/QIcon>
#include <QtGui/QImage>
#include <QtGui/QMovie>
#include <QtGui/QPainter>
#include <QtGui/QPixmap>
#include <QtGui/QPixmapCache>
#ifndef _WIN32_WCE
#include <QtSvg/QSvgRenderer>
#endif
// kdecore
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kdebug.h>
#include <kstandarddirs.h>
#include <kglobal.h>
#include <kglobalsettings.h>
#include <kcomponentdata.h>
#include <kde_file.h>
#include <kshareddatacache.h>
// kdeui
#include "kicontheme.h"
#include "kiconeffect.h"
#include "k3icon_p.h"
// Used to make cache keys for icons with no group. Result type is QString*
K_GLOBAL_STATIC_WITH_ARGS(QString, NULL_EFFECT_FINGERPRINT, (QString::fromLatin1("noeffect")))
// Qt implements Tiny SVG specification. This specification does not cover important elements
// that are pretty globally used on our icons, like blurring (and other filters). TT seems to have
// no interest in supporting the full SVG specification (it would be slower, even with JS, CSS
// support...). So, we have no chance for now. Let's disable svg rendering unconditionally.
// (ereslibre)
#undef KDE_QT_SVG_RENDERER_FIXED
/**
* Checks for relative paths quickly on UNIX-alikes, slowly on everything else.
*/
static bool pathIsRelative(const QString &path)
{
#ifdef Q_OS_UNIX
return (!path.isEmpty() && path[0] != QChar('/'));
#else
return QDir::isRelativePath(path);
#endif
}
/**
* Holds a QPixmap for this process, along with its associated path on disk.
*/
struct PixmapWithPath
{
QPixmap pixmap;
QString path;
};
/*** KIconThemeNode: A node in the icon theme dependancy tree. ***/
class KIconThemeNode
{
public:
KIconThemeNode(KIconTheme *_theme);
~KIconThemeNode();
void queryIcons(QStringList *lst, int size, KIconLoader::Context context) const;
void queryIconsByContext(QStringList *lst, int size, KIconLoader::Context context) const;
K3Icon findIcon(const QString& name, int size, KIconLoader::MatchType match) const;
void printTree(QString& dbgString) const;
KIconTheme *theme;
};
KIconThemeNode::KIconThemeNode(KIconTheme *_theme)
{
theme = _theme;
}
KIconThemeNode::~KIconThemeNode()
{
delete theme;
}
void KIconThemeNode::printTree(QString& dbgString) const
{
/* This method doesn't have much sense anymore, so maybe it should
be removed in the (near?) future */
dbgString += '(';
dbgString += theme->name();
dbgString += ')';
}
void KIconThemeNode::queryIcons(QStringList *result,
int size, KIconLoader::Context context) const
{
// add the icons of this theme to it
*result += theme->queryIcons(size, context);
}
void KIconThemeNode::queryIconsByContext(QStringList *result,
int size, KIconLoader::Context context) const
{
// add the icons of this theme to it
*result += theme->queryIconsByContext(size, context);
}
K3Icon KIconThemeNode::findIcon(const QString& name, int size,
KIconLoader::MatchType match) const
{
return theme->iconPath(name, size, match);
}
/*** KIconGroup: Icon type description. ***/
struct KIconGroup
{
int size;
bool alphaBlending;
};
/*** d pointer for KIconLoader. ***/
class KIconLoaderPrivate
{
public:
KIconLoaderPrivate(KIconLoader *q)
: q(q)
, mpGroups(0)
, mIconCache(0)
{
}
~KIconLoaderPrivate()
{
/* antlarr: There's no need to delete d->mpThemeRoot as it's already
deleted when the elements of d->links are deleted */
qDeleteAll(links);
delete[] mpGroups;
delete mIconCache;
}
/**
* @internal
*/
void init( const QString& _appname, KStandardDirs *_dirs );
/**
* @internal
*/
bool initIconThemes();
/**
* @internal
* tries to find an icon with the name. It tries some extension and
* match strategies
*/
K3Icon findMatchingIcon(const QString& name, int size) const;
/**
* @internal
* tries to find an icon with the name.
* This is one layer above findMatchingIcon -- it also implements generic fallbacks
* such as generic icons for mimetypes.
*/
K3Icon findMatchingIconWithGenericFallbacks(const QString& name, int size) const;
/**
* @internal
* Adds themes installed in the application's directory.
**/
void addAppThemes(const QString& appname);
/**
* @internal
* Adds all themes that are part of this node and the themes
* below (the fallbacks of the theme) into the tree.
*/
void addBaseThemes(KIconThemeNode *node, const QString &appname);
/**
* @internal
* Recursively adds all themes that are specified in the "Inherits"
* property of the given theme into the tree.
*/
void addInheritedThemes(KIconThemeNode *node, const QString &appname);
/**
* @internal
* Creates a KIconThemeNode out of a theme name, and adds this theme
* as well as all its inherited themes into the tree. Themes that already
* exist in the tree will be ignored and not added twice.
*/
void addThemeByName(const QString &themename, const QString &appname);
/**
* @internal
* return the path for the unknown icon in that size
*/
QString unknownIconPath( int size ) const;
/**
* Checks if name ends in one of the supported icon formats (i.e. .png)
* and returns the name without the extension if it does.
*/
QString removeIconExtension(const QString &name) const;
/**
* @internal
* Used with KIconLoader::loadIcon to convert the given name, size, group,
* and icon state information to valid states. All parameters except the
* name can be modified as well to be valid.
*/
void normalizeIconMetadata(KIconLoader::Group &group, int &size, int &state) const;
/**
* @internal
* Used with KIconLoader::loadIcon to get a base key name from the given
* icon metadata. Ensure the metadata is normalized first.
*/
QString makeCacheKey(const QString &name, KIconLoader::Group group, const QStringList &overlays,
int size, int state) const;
/**
* @internal
* Creates the QImage for @p path, using SVG rendering as appropriate.
* @p size is only used for scalable images, but if non-zero non-scalable
* images will be resized anyways.
*/
QImage createIconImage(const QString &path, int size = 0);
/**
* @internal
* Adds an QPixmap with its associated path to the shared icon cache.
*/
void insertCachedPixmapWithPath(const QString &key, const QPixmap &data, const QString &path);
/**
* @internal
* Retrieves the path and pixmap of the given key from the shared
* icon cache.
*/
bool findCachedPixmapWithPath(const QString &key, QPixmap &data, QString &path);
KIconLoader *const q;
QStringList mThemesInTree;
KIconGroup *mpGroups;
KIconThemeNode *mpThemeRoot;
KStandardDirs *mpDirs;
-#ifndef KICONLOADER_WITHOUTEFFECTS
KIconEffect mpEffect;
-#endif
QList<KIconThemeNode *> links;
// This shares the icons across all processes
KSharedDataCache* mIconCache;
// This caches rendered QPixmaps in just this process.
QCache<QString, PixmapWithPath> mPixmapCache;
bool extraDesktopIconsLoaded :1;
// lazy loading: initIconThemes() is only needed when the "links" list is needed
// mIconThemeInited is used inside initIconThemes() to init only once
bool mIconThemeInited :1;
QString appname;
void drawOverlays(const KIconLoader *loader, KIconLoader::Group group, int state, QPixmap& pix, const QStringList& overlays);
};
class KIconLoaderGlobalData
{
public:
KIconLoaderGlobalData() {
const QStringList genericIconsFiles = KGlobal::dirs()->findAllResources("xdgdata-mime", "generic-icons");
//kDebug() << genericIconsFiles;
Q_FOREACH(const QString& file, genericIconsFiles) {
parseGenericIconsFiles(file);
}
}
QString genericIconFor(const QString& icon) const {
return m_genericIcons.value(icon);
}
private:
void parseGenericIconsFiles(const QString& fileName);
QHash<QString, QString> m_genericIcons;
};
void KIconLoaderGlobalData::parseGenericIconsFiles(const QString& fileName)
{
QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QTextStream stream(&file);
stream.setCodec("ISO 8859-1");
while (!stream.atEnd()) {
const QString line = stream.readLine();
if (line.isEmpty() || line[0] == '#')
continue;
const int pos = line.indexOf(':');
if (pos == -1) // syntax error
continue;
QString mimeIcon = line.left(pos);
const int slashindex = mimeIcon.indexOf(QLatin1Char('/'));
if (slashindex != -1) {
mimeIcon[slashindex] = QLatin1Char('-');
}
const QString genericIcon = line.mid(pos+1);
m_genericIcons.insert(mimeIcon, genericIcon);
//kDebug(264) << mimeIcon << "->" << genericIcon;
}
}
}
K_GLOBAL_STATIC(KIconLoaderGlobalData, s_globalData)
void KIconLoaderPrivate::drawOverlays(const KIconLoader *iconLoader, KIconLoader::Group group, int state, QPixmap& pix, const QStringList& overlays)
{
if (overlays.isEmpty()) {
return;
}
const int width = pix.size().width();
const int height = pix.size().height();
const int iconSize = qMin(width, height);
int overlaySize;
if (iconSize < 32) {
overlaySize = 8;
} else if (iconSize <= 48) {
overlaySize = 16;
} else if (iconSize <= 96) {
overlaySize = 22;
} else if (iconSize < 256) {
overlaySize = 32;
} else {
overlaySize = 64;
}
QPainter painter(&pix);
int count = 0;
foreach (const QString& overlay, overlays) {
// Ensure empty strings fill up a emblem spot
// Needed when you have several emblems to ensure they're always painted
// at the same place, even if one is not here
if (overlay.isEmpty()) {
++count;
continue;
}
//TODO: should we pass in the kstate? it results in a slower
// path, and perhaps emblems should remain in the default state
// anyways?
const QPixmap pixmap = iconLoader->loadIcon(overlay, group, overlaySize, state, QStringList(), 0, true);
if (pixmap.isNull()) {
continue;
}
QPoint startPoint;
switch (count) {
case 0:
// bottom left corner
startPoint = QPoint(2, height - overlaySize - 2);
break;
case 1:
// bottom right corner
startPoint = QPoint(width - overlaySize - 2,
height - overlaySize - 2);
break;
case 2:
// top right corner
startPoint = QPoint(width - overlaySize - 2, 2);
break;
case 3:
// top left corner
startPoint = QPoint(2, 2);
break;
}
painter.drawPixmap(startPoint, pixmap);
++count;
if (count > 3) {
break;
}
}
}
KIconLoader::KIconLoader(const QString& _appname, KStandardDirs *_dirs, QObject* parent)
: QObject(parent)
{
setObjectName(_appname);
d = new KIconLoaderPrivate(this);
connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
this, SLOT(newIconLoader()));
d->init( _appname, _dirs );
}
KIconLoader::KIconLoader(const KComponentData &componentData, QObject* parent)
: QObject(parent)
{
setObjectName(componentData.componentName());
d = new KIconLoaderPrivate(this);
connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)),
this, SLOT(newIconLoader()));
d->init(componentData.componentName(), componentData.dirs());
}
void KIconLoader::reconfigure( const QString& _appname, KStandardDirs *_dirs )
{
delete d;
d = new KIconLoaderPrivate(this);
d->init( _appname, _dirs );
}
void KIconLoaderPrivate::init( const QString& _appname, KStandardDirs *_dirs )
{
extraDesktopIconsLoaded=false;
mIconThemeInited = false;
mpThemeRoot = 0;
if (_dirs)
mpDirs = _dirs;
else
mpDirs = KGlobal::dirs();
appname = _appname;
if (appname.isEmpty())
appname = KGlobal::mainComponent().componentName();
// Initialize icon cache
mIconCache = new KSharedDataCache("icon-cache", 10 * 1024 * 1024);
// Cost here is number of pixels, not size. So this is actually a bit
// smaller.
mPixmapCache.setMaxCost(10 * 1024 * 1024);
// These have to match the order in kicontheme.h
static const char * const groups[] = { "Desktop", "Toolbar", "MainToolbar", "Small", "Panel", "Dialog", 0L };
KSharedConfig::Ptr config = KGlobal::config();
// loading config and default sizes
initIconThemes();
KIconTheme *defaultSizesTheme = links.empty() ? 0 : links.first()->theme;
mpGroups = new KIconGroup[(int) KIconLoader::LastGroup];
for (KIconLoader::Group i = KIconLoader::FirstGroup; i < KIconLoader::LastGroup; ++i) {
if (groups[i] == 0L) {
break;
}
KConfigGroup cg(config, QLatin1String(groups[i]) + "Icons");
mpGroups[i].size = cg.readEntry("Size", 0);
if (QPixmap::defaultDepth() > 8) {
mpGroups[i].alphaBlending = cg.readEntry("AlphaBlending", true);
} else {
mpGroups[i].alphaBlending = false;
}
if (!mpGroups[i].size && defaultSizesTheme) {
mpGroups[i].size = defaultSizesTheme->defaultSize(i);
}
}
}
bool KIconLoaderPrivate::initIconThemes()
{
if (mIconThemeInited) {
// If mpThemeRoot isn't 0 then initing has succeeded
return (mpThemeRoot != 0);
}
//kDebug(264);
mIconThemeInited = true;
// Add the default theme and its base themes to the theme tree
KIconTheme *def = new KIconTheme(KIconTheme::current(), appname);
if (!def->isValid())
{
delete def;
// warn, as this is actually a small penalty hit
kDebug(264) << "Couldn't find current icon theme, falling back to default.";
def = new KIconTheme(KIconTheme::defaultThemeName(), appname);
if (!def->isValid())
{
kError(264) << "Error: standard icon theme" << KIconTheme::defaultThemeName() << "not found!" << endl;
delete def;
return false;
}
}
mpThemeRoot = new KIconThemeNode(def);
mThemesInTree.append(def->internalName());
links.append(mpThemeRoot);
addBaseThemes(mpThemeRoot, appname);
// Insert application specific themes at the top.
mpDirs->addResourceType("appicon", "data", appname + "/pics/");
// ################## KDE5: consider removing the toolbar directory
mpDirs->addResourceType("appicon", "data", appname + "/toolbar/");
// Add legacy icon dirs.
QStringList dirs;
dirs += mpDirs->resourceDirs("icon");
dirs += mpDirs->resourceDirs("pixmap");
dirs += mpDirs->resourceDirs("xdgdata-icon");
dirs += "/usr/share/pixmaps";
// These are not in the icon spec, but e.g. GNOME puts some icons there anyway.
dirs += mpDirs->resourceDirs("xdgdata-pixmap");
for (QStringList::ConstIterator it = dirs.constBegin(); it != dirs.constEnd(); ++it)
mpDirs->addResourceDir("appicon", *it);
#ifndef NDEBUG
QString dbgString = "Theme tree: ";
mpThemeRoot->printTree(dbgString);
kDebug(264) << dbgString;
#endif
return true;
}
KIconLoader::~KIconLoader()
{
delete d;
}
void KIconLoader::addAppDir(const QString& appname)
{
d->initIconThemes();
d->mpDirs->addResourceType("appicon", "data", appname + "/pics/");
// ################## KDE5: consider removing the toolbar directory
d->mpDirs->addResourceType("appicon", "data", appname + "/toolbar/");
d->addAppThemes(appname);
}
void KIconLoaderPrivate::addAppThemes(const QString& appname)
{
initIconThemes();
KIconTheme *def = new KIconTheme(KIconTheme::current(), appname);
if (!def->isValid()) {
delete def;
def = new KIconTheme(KIconTheme::defaultThemeName(), appname);
}
KIconThemeNode* node = new KIconThemeNode(def);
bool addedToLinks = false;
if (!mThemesInTree.contains(node->theme->internalName())) {
mThemesInTree.append(node->theme->internalName());
links.append(node);
addedToLinks = true;
}
addBaseThemes(node, appname);
if (!addedToLinks) {
// Nodes in links are being deleted later - this one needs manual care.
delete node;
}
}
void KIconLoaderPrivate::addBaseThemes(KIconThemeNode *node, const QString &appname)
{
// Quote from the icon theme specification:
// The lookup is done first in the current theme, and then recursively
// in each of the current theme's parents, and finally in the
// default theme called "hicolor" (implementations may add more
// default themes before "hicolor", but "hicolor" must be last).
//
// So we first make sure that all inherited themes are added, then we
// add the KDE default theme as fallback for all icons that might not be
// present in an inherited theme, and hicolor goes last.
addInheritedThemes(node, appname);
addThemeByName(KIconTheme::defaultThemeName(), appname);
addThemeByName("hicolor", appname);
}
void KIconLoaderPrivate::addInheritedThemes(KIconThemeNode *node, const QString &appname)
{
const QStringList lst = node->theme->inherits();
for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
if ((*it) == "hicolor") {
// The icon theme spec says that "hicolor" must be the very last
// of all inherited themes, so don't add it here but at the very end
// of addBaseThemes().
continue;
}
addThemeByName(*it, appname);
}
}
void KIconLoaderPrivate::addThemeByName(const QString &themename, const QString &appname)
{
if (mThemesInTree.contains(themename + appname)) {
return;
}
KIconTheme *theme = new KIconTheme(themename, appname);
if (!theme->isValid()) {
delete theme;
return;
}
KIconThemeNode *n = new KIconThemeNode(theme);
mThemesInTree.append(themename + appname);
links.append(n);
addInheritedThemes(n, appname);
}
void KIconLoader::addExtraDesktopThemes()
{
if ( d->extraDesktopIconsLoaded ) return;
d->initIconThemes();
QStringList list;
const QStringList icnlibs = KGlobal::dirs()->resourceDirs("icon");
QStringList::ConstIterator it;
char buf[1000];
int r;
for (it=icnlibs.begin(); it!=icnlibs.end(); ++it)
{
QDir dir(*it);
if (!dir.exists())
continue;
const QStringList lst = dir.entryList(QStringList( "default.*" ), QDir::Dirs);
QStringList::ConstIterator it2;
for (it2=lst.begin(); it2!=lst.end(); ++it2)
{
if (!KStandardDirs::exists(*it + *it2 + "/index.desktop")
&& !KStandardDirs::exists(*it + *it2 + "/index.theme"))
continue;
r=readlink( QFile::encodeName(*it + *it2) , buf, sizeof(buf)-1);
if ( r>0 )
{
buf[r]=0;
const QDir dir2( buf );
QString themeName=dir2.dirName();
if (!list.contains(themeName))
list.append(themeName);
}
}
}
for (it = list.constBegin(); it != list.constEnd(); ++it)
{
// Don't add the KDE defaults once more, we have them anyways.
if (*it == QLatin1String("default.kde")
|| *it == QLatin1String("default.kde4")) {
continue;
}
d->addThemeByName(*it, "");
}
d->extraDesktopIconsLoaded=true;
}
bool KIconLoader::extraDesktopThemesAdded() const
{
return d->extraDesktopIconsLoaded;
}
void KIconLoader::drawOverlays(const QStringList &overlays, QPixmap &pixmap, KIconLoader::Group group, int state) const
{
d->drawOverlays(this, group, state, pixmap, overlays);
}
QString KIconLoaderPrivate::removeIconExtension(const QString &name) const
{
if (name.endsWith(QLatin1String(".png"))
|| name.endsWith(QLatin1String(".xpm"))
|| name.endsWith(QLatin1String(".svg"))) {
return name.left(name.length() - 4);
} else if (name.endsWith(QLatin1String(".svgz"))) {
return name.left(name.length() - 5);
}
return name;
}
void KIconLoaderPrivate::normalizeIconMetadata(KIconLoader::Group &group, int &size, int &state) const
{
if ((state < 0) || (state >= KIconLoader::LastState))
{
kWarning(264) << "Illegal icon state: " << state;
state = KIconLoader::DefaultState;
}
if (size < 0) {
size = 0;
}
// For "User" icons, bail early since the size should be based on the size on disk,
// which we've already checked.
if (group == KIconLoader::User) {
return;
}
if ((group < -1) || (group >= KIconLoader::LastGroup))
{
kWarning(264) << "Illegal icon group: " << group;
group = KIconLoader::Desktop;
}
// If size == 0, use default size for the specified group.
if (size == 0)
{
if (group < 0)
{
kWarning(264) << "Neither size nor group specified!";
group = KIconLoader::Desktop;
}
size = mpGroups[group].size;
}
}
QString KIconLoaderPrivate::makeCacheKey(const QString &name, KIconLoader::Group group,
const QStringList &overlays, int size, int state) const
{
// The KSharedDataCache is shared so add some namespacing. The following code
// uses QStringBuilder (new in Qt 4.6)
return (group == KIconLoader::User
? QLatin1Literal("$kicou_")
: QLatin1Literal("$kico_"))
% name
% QLatin1Char('_')
% QString::number(size)
% QLatin1Char('_')
% overlays.join("_")
-#ifndef KICONLOADER_WITHOUTEFFECTS
% ( group >= 0 ? mpEffect.fingerprint(group, state)
: *NULL_EFFECT_FINGERPRINT);
-#else
- % NULL_EFFECT_FINGERPRINT);
-#endif
}
QImage KIconLoaderPrivate::createIconImage(const QString &path, int size)
{
// Use the extension as the format. Works for XPM and PNG, but not for SVG. The
// "VGZ" is the last 3 characters of "SVGZ"
QString ext = path.right(3).toUpper();
QImage img;
if (ext != "SVG" && ext != "VGZ")
{
// Not a SVG or SVGZ
img = QImage(path, ext.toLatin1());
if (size != 0 && !img.isNull()) {
img = img.scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
}
else
{
#ifndef _WIN32_WCE
QSvgRenderer renderer(path, q);
if (renderer.isValid()) {
img = QImage(size, size, QImage::Format_ARGB32_Premultiplied);
img.fill(0);
QPainter p(&img);
renderer.render(&p);
}
#endif
}
return img;
}
void KIconLoaderPrivate::insertCachedPixmapWithPath(
const QString &key,
const QPixmap &data,
const QString &path = QString())
{
// Even if the pixmap is null, we add it to the caches so that we record
// the fact that whatever icon led to us getting a null pixmap doesn't
// exist.
QBuffer output;
output.open(QIODevice::WriteOnly);
QDataStream outputStream(&output);
outputStream.setVersion(QDataStream::Qt_4_6);
outputStream << path;
// Convert the QPixmap to PNG. This is actually done by Qt's own operator.
outputStream << data;
output.close();
// The byte array contained in the QBuffer is what we want in the cache.
mIconCache->insert(key, output.buffer());
// Also insert the object into our process-local cache for even more
// speed.
PixmapWithPath *pixmapPath = new PixmapWithPath;
pixmapPath->pixmap = data;
pixmapPath->path = path;
mPixmapCache.insert(key, pixmapPath, data.width() * data.height() + 1);
}
bool KIconLoaderPrivate::findCachedPixmapWithPath(const QString &key, QPixmap &data, QString &path)
{
// If the pixmap is present in our local process cache, use that since we
// don't need to decompress and upload it to the X server/graphics card.
const PixmapWithPath *pixmapPath = mPixmapCache.object(key);
if (pixmapPath) {
path = pixmapPath->path;
data = pixmapPath->pixmap;
return true;
}
// Otherwise try to find it in our shared memory cache since that will
// be quicker than the disk, especially for SVGs.
QByteArray result;
if (!mIconCache->find(key, &result) || result.isEmpty()) {
return false;
}
QBuffer buffer;
buffer.setBuffer(&result);
buffer.open(QIODevice::ReadOnly);
QDataStream inputStream(&buffer);
inputStream.setVersion(QDataStream::Qt_4_6);
QString tempPath;
inputStream >> tempPath;
if (inputStream.status() == QDataStream::Ok) {
QPixmap tempPixmap;
inputStream >> tempPixmap;
if (inputStream.status() == QDataStream::Ok) {
data = tempPixmap;
path = tempPath;
// Since we're here we didn't have a QPixmap cache entry, add one now.
PixmapWithPath *newPixmapWithPath = new PixmapWithPath;
newPixmapWithPath->pixmap = data;
newPixmapWithPath->path = path;
mPixmapCache.insert(key, newPixmapWithPath, data.width() * data.height() + 1);
return true;
}
}
return false;
}
K3Icon KIconLoaderPrivate::findMatchingIconWithGenericFallbacks(const QString& name, int size) const
{
K3Icon icon = findMatchingIcon(name, size);
if (icon.isValid())
return icon;
const QString genericIcon = s_globalData->genericIconFor(name);
if (!genericIcon.isEmpty()) {
icon = findMatchingIcon(genericIcon, size);
}
return icon;
}
K3Icon KIconLoaderPrivate::findMatchingIcon(const QString& name, int size) const
{
const_cast<KIconLoaderPrivate*>(this)->initIconThemes();
K3Icon icon;
// The following code has been commented out because the Qt SVG renderer needs
// to be improved. If you are going to change/remove some code from this part,
// please contact me before (ereslibre@kde.org), or kde-core-devel@kde.org. (ereslibre)
#ifdef KDE_QT_SVG_RENDERER_FIXED
const char * ext1[4] = { ".png", ".svgz", ".svg", ".xpm" };
const char * ext2[4] = { ".svgz", ".svg", ".png", ".xpm" };
const char ** ext;
if (size == KIconLoader::SizeSmall ||
size == KIconLoader::SizeSmallMedium ||
size == KIconLoader::SizeMedium ||
size == KIconLoader::SizeLarge ||
size == KIconLoader::SizeHuge ||
size == KIconLoader::SizeEnormous)
{
ext = ext1; // size is standard, give preference to PNG over SVG when searching
}
else
{
ext = ext2; // size is non-standard, give preference to SVG over PNG when searching
}
/* If size parameter is a standard one, that means:
- KIconLoader::SizeSmall
- KIconLoader::SizeSmallMedium
- KIconLoader::SizeMedium
- KIconLoader::SizeLarge
- KIconLoader::SizeHuge
- KIconLoader::SizeEnormous
To follow the XDG icon theme and icon naming specifications,
the order in which we look for an icon is:
png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
less specific fallback in this theme: png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
even less specific fallback in this theme: [same order]
(...)
next theme in inheritance tree: png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
less specific fallbacks in this next theme
(...)
next theme in inheritance tree: png, svgz, svg, xpm exact match
png, svgz, svg, xpm best match
less specific fallbacks in this next theme
(...)
and so on.
If size parameter is a non-standard one, then we give more preference to
SVG format since drawing SVG's gives better quality and despite being
slower than resizing a PNG image, the cases where non-standard sizes are
asked are very rare. For non-standard sizes what we have is:
svgz, svg, png, xpm exact match
svgz, svg, png, xpm best match
less specific fallback in this theme: svgz, svg, png, xpm exact match
svgz, svg, png, xpm best match
even less specific fallback in this theme: [same order]
(...)
next theme in inheritance tree: svgz, svg, png, xpm exact match
svgz, svg, png, xpm best match
less specific fallbacks in this next theme
(...)
next theme in inheritance tree: svgz, svg, png, xpm exact match
svgz, svg, png, xpm best match
less specific fallbacks in this next theme
(...)
and so on.
*/
#else
const char * const ext[4] = { ".png", ".svgz", ".svg", ".xpm" };
#endif
bool genericFallback = name.endsWith(QLatin1String("-x-generic"));
foreach(KIconThemeNode *themeNode, links)
{
QString currentName = name;
while (!currentName.isEmpty())
{
//kDebug(264) << "Looking up" << currentName;
// The following code has been commented out because the Qt SVG renderer needs
// to be improved. If you are going to change/remove some code from this part,
// please contact me before (ereslibre@kde.org), or kde-core-devel@kde.org. (ereslibre)
#ifdef KDE_QT_SVG_RENDERER_FIXED
for (int i = 0 ; i < 4 ; i++)
{
icon = themeNode->theme->iconPath(currentName + ext[i], size, KIconLoader::MatchExact);
if (icon.isValid())
return icon;
}
for (int i = 0 ; i < 4 ; i++)
{
icon = themeNode->theme->iconPath(currentName + ext[i], size, KIconLoader::MatchBest);
if (icon.isValid())
return icon;
}
#else
for (int i = 0 ; i < 4 ; i++)
{
icon = themeNode->theme->iconPath(currentName + ext[i], size, KIconLoader::MatchExact);
if (icon.isValid())
return icon;
icon = themeNode->theme->iconPath(currentName + ext[i], size, KIconLoader::MatchBest);
if (icon.isValid())
return icon;
}
#endif
if (genericFallback)
// we already tested the base name
break;
int rindex = currentName.lastIndexOf('-');
if (rindex > 1) { // > 1 so that we don't split x-content or x-epoc
currentName.truncate(rindex);
if (currentName.endsWith(QLatin1String("-x")))
currentName.chop(2);
} else {
// From update-mime-database.c
static const QSet<QString> mediaTypes = QSet<QString>()
<< "text" << "application" << "image" << "audio"
<< "inode" << "video" << "message" << "model" << "multipart"
<< "x-content" << "x-epoc";
// Shared-mime-info spec says:
// "If [generic-icon] is not specified then the mimetype is used to generate the
// generic icon by using the top-level media type (e.g. "video" in "video/ogg")
// and appending "-x-generic" (i.e. "video-x-generic" in the previous example)."
if (mediaTypes.contains(currentName)) {
currentName += QLatin1String("-x-generic");
genericFallback = true;
} else {
break;
}
}
}
}
return icon;
}
inline QString KIconLoaderPrivate::unknownIconPath( int size ) const
{
static const QString &str_unknown = KGlobal::staticQString("unknown");
K3Icon icon = findMatchingIcon(str_unknown, size);
if (!icon.isValid())
{
kDebug(264) << "Warning: could not find \"Unknown\" icon for size = "
<< size << endl;
return QString();
}
return icon.path;
}
// Finds the absolute path to an icon.
QString KIconLoader::iconPath(const QString& _name, int group_or_size,
bool canReturnNull) const
{
if (!d->initIconThemes()) {
return QString();
}
if (_name.isEmpty() || !pathIsRelative(_name))
{
// we have either an absolute path or nothing to work with
return _name;
}
QString name = d->removeIconExtension( _name );
QString path;
if (group_or_size == KIconLoader::User)
{
static const QString &png_ext = KGlobal::staticQString(".png");
static const QString &xpm_ext = KGlobal::staticQString(".xpm");
path = d->mpDirs->findResource("appicon", name + png_ext);
static const QString &svgz_ext = KGlobal::staticQString(".svgz");
static const QString &svg_ext = KGlobal::staticQString(".svg");
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + svgz_ext);
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + svg_ext);
if (path.isEmpty())
path = d->mpDirs->findResource("appicon", name + xpm_ext);
return path;
}
if (group_or_size >= KIconLoader::LastGroup)
{
kDebug(264) << "Illegal icon group: " << group_or_size;
return path;
}
int size;
if (group_or_size >= 0)
size = d->mpGroups[group_or_size].size;
else
size = -group_or_size;
if (_name.isEmpty()) {
if (canReturnNull)
return QString();
else
return d->unknownIconPath(size);
}
K3Icon icon = d->findMatchingIconWithGenericFallbacks(name, size);
if (!icon.isValid())
{
// Try "User" group too.
path = iconPath(name, KIconLoader::User, true);
if (!path.isEmpty() || canReturnNull)
return path;
return d->unknownIconPath(size);
}
return icon.path;
}
QPixmap KIconLoader::loadMimeTypeIcon( const QString& _iconName, KIconLoader::Group group, int size,
int state, const QStringList& overlays, QString *path_store ) const
{
QString iconName = _iconName;
const int slashindex = iconName.indexOf(QLatin1Char('/'));
if (slashindex != -1) {
iconName[slashindex] = QLatin1Char('-');
}
if ( !d->extraDesktopIconsLoaded )
{
const QPixmap pixmap = loadIcon( iconName, group, size, state, overlays, path_store, true );
if (!pixmap.isNull() ) {
return pixmap;
}
const_cast<KIconLoader *>(this)->addExtraDesktopThemes();
}
const QPixmap pixmap = loadIcon(iconName, group, size, state, overlays, path_store, true);
if (pixmap.isNull()) {
// Icon not found, fallback to application/octet-stream
return loadIcon("application-octet-stream", group, size, state, overlays, path_store, false);
}
return pixmap;
}
QPixmap KIconLoader::loadIcon(const QString& _name, KIconLoader::Group group, int size,
int state, const QStringList& overlays,
QString *path_store, bool canReturnNull) const
{
QString name = _name;
bool favIconOverlay = false;
if (size < 0 || _name.isEmpty())
return QPixmap();
/*
* This method works in a kind of pipeline, with the following steps:
* 1. Sanity checks.
* 2. Convert _name, group, size, etc. to a key name.
* 3. Check if the key is already cached.
* 4. If not, initialize the theme and find/load the icon.
* 4a Apply overlays
* 4b Re-add to cache.
*/
// Special case for absolute path icons.
if (name.startsWith(QLatin1String("favicons/")))
{
favIconOverlay = true;
name = KStandardDirs::locateLocal("cache", name+".png");
}
bool absolutePath = !pathIsRelative(name);
if (!absolutePath) {
name = d->removeIconExtension(name);
}
// Don't bother looking for an icon with no name.
if (name.isEmpty()) {
return QPixmap();
}
// May modify group, size, or state. This function puts them into sane
// states.
d->normalizeIconMetadata(group, size, state);
// See if the image is already cached.
QString key = d->makeCacheKey(name, group, overlays, size, state);
QPixmap pix;
bool iconWasUnknown = false;
K3Icon icon;
if (d->findCachedPixmapWithPath(key, pix, icon.path)) {
if (path_store) {
*path_store = icon.path;
}
// We cache the pixmap for the event of trying to find an unknown icon
// with canReturnNull set to false, but if we *can* return null then
// we should do so when necessary.
if (canReturnNull && icon.path.isEmpty()) {
return QPixmap();
}
return pix;
}
// Image is not cached... go find it and apply effects.
if (!d->initIconThemes()) {
return QPixmap();
}
favIconOverlay = favIconOverlay && size > 22;
// First we look for non-User icons. If we don't find one we'd search in
// the User space anyways...
if (group != KIconLoader::User) {
// K3Icon seems to hold some needed information.
if (absolutePath && !favIconOverlay)
{
icon.context = KIconLoader::Any;
icon.type = KIconLoader::Scalable;
icon.path = name;
}
else
{
icon = d->findMatchingIconWithGenericFallbacks(favIconOverlay ? QString("text-html") : name, size);
}
}
if (icon.path.isEmpty()) {
// We do have a "User" icon, or we couldn't find the non-User one.
icon.path = (absolutePath) ? name :
iconPath(name, KIconLoader::User, canReturnNull);
}
// Still can't find it? Use "unknown" if we can't return null.
// We keep going in the function so we can ensure this result gets cached.
if (icon.path.isEmpty() && !canReturnNull) {
icon.path = d->unknownIconPath(size);
iconWasUnknown = true;
}
QImage img = d->createIconImage(icon.path, size);
-#ifndef KICONLOADER_WITHOUTEFFECTS
if (group >= 0)
{
img = d->mpEffect.apply(img, group, state);
}
-#endif
if (favIconOverlay)
{
QImage favIcon(name, "PNG");
if (!favIcon.isNull()) // if favIcon not there yet, don't try to blend it
{
QPainter p(&img);
// Align the favicon overlay
QRect r(favIcon.rect());
r.moveBottomRight(img.rect().bottomRight());
r.adjust(-1, -1, -1, -1); // Move off edge
// Blend favIcon over img.
p.drawImage(r, favIcon);
}
}
pix = QPixmap::fromImage(img);
// TODO: If we make a loadIcon that returns the image we can convert
// drawOverlays to use the image instead of pixmaps as well so we don't
// have to transfer so much to the graphics card.
d->drawOverlays(this, group, state, pix, overlays);
// Don't add the path to our unknown icon to the cache, only cache the
// actual image.
if (iconWasUnknown) {
icon.path.clear();
}
d->insertCachedPixmapWithPath(key, pix, icon.path);
if (path_store) {
*path_store = icon.path;
}
return pix;
}
QMovie *KIconLoader::loadMovie(const QString& name, KIconLoader::Group group, int size, QObject *parent) const
{
QString file = moviePath( name, group, size );
if (file.isEmpty())
return 0;
int dirLen = file.lastIndexOf('/');
QString icon = iconPath(name, size ? -size : group, true);
if (!icon.isEmpty() && file.left(dirLen) != icon.left(dirLen))
return 0;
QMovie *movie = new QMovie(file, QByteArray(), parent);
if (!movie->isValid())
{
delete movie;
return 0;
}
return movie;
}
QString KIconLoader::moviePath(const QString& name, KIconLoader::Group group, int size) const
{
if (!d->mpGroups) return QString();
d->initIconThemes();
if ( (group < -1 || group >= KIconLoader::LastGroup) && group != KIconLoader::User )
{
kDebug(264) << "Illegal icon group: " << group;
group = KIconLoader::Desktop;
}
if (size == 0 && group < 0)
{
kDebug(264) << "Neither size nor group specified!";
group = KIconLoader::Desktop;
}
QString file = name + ".mng";
if (group == KIconLoader::User)
{
file = d->mpDirs->findResource("appicon", file);
}
else
{
if (size == 0)
size = d->mpGroups[group].size;
K3Icon icon;
foreach(KIconThemeNode *themeNode, d->links)
{
icon = themeNode->theme->iconPath(file, size, KIconLoader::MatchExact);
if (icon.isValid())
break;
}
if ( !icon.isValid() )
{
foreach(KIconThemeNode *themeNode, d->links)
{
icon = themeNode->theme->iconPath(file, size, KIconLoader::MatchBest);
if (icon.isValid())
break;
}
}
file = icon.isValid() ? icon.path : QString();
}
return file;
}
QStringList KIconLoader::loadAnimated(const QString& name, KIconLoader::Group group, int size) const
{
QStringList lst;
if (!d->mpGroups) return lst;
d->initIconThemes();
if ((group < -1) || (group >= KIconLoader::LastGroup))
{
kDebug(264) << "Illegal icon group: " << group;
group = KIconLoader::Desktop;
}
if ((size == 0) && (group < 0))
{
kDebug(264) << "Neither size nor group specified!";
group = KIconLoader::Desktop;
}
QString file = name + "/0001";
if (group == KIconLoader::User)
{
file = d->mpDirs->findResource("appicon", file + ".png");
} else
{
if (size == 0)
size = d->mpGroups[group].size;
K3Icon icon = d->findMatchingIcon(file, size);
file = icon.isValid() ? icon.path : QString();
}
if (file.isEmpty())
return lst;
QString path = file.left(file.length()-8);
DIR* dp = opendir( QFile::encodeName(path) );
if(!dp)
return lst;
KDE_struct_dirent* ep;
while( ( ep = KDE_readdir( dp ) ) != 0L )
{
QString fn(QFile::decodeName(ep->d_name));
if(!(fn.left(4)).toUInt())
continue;
lst += path + fn;
}
closedir ( dp );
lst.sort();
return lst;
}
KIconTheme *KIconLoader::theme() const
{
d->initIconThemes();
if (d->mpThemeRoot) return d->mpThemeRoot->theme;
return 0L;
}
int KIconLoader::currentSize(KIconLoader::Group group) const
{
if (!d->mpGroups) return -1;
if (group < 0 || group >= KIconLoader::LastGroup)
{
kDebug(264) << "Illegal icon group: " << group;
return -1;
}
return d->mpGroups[group].size;
}
QStringList KIconLoader::queryIconsByDir( const QString& iconsDir ) const
{
const QDir dir(iconsDir);
const QStringList formats = QStringList() << "*.png" << "*.xpm" << "*.svg" << "*.svgz";
const QStringList lst = dir.entryList(formats, QDir::Files);
QStringList result;
QStringList::ConstIterator it;
for (it=lst.begin(); it!=lst.end(); ++it)
result += iconsDir + '/' + *it;
return result;
}
QStringList KIconLoader::queryIconsByContext(int group_or_size,
KIconLoader::Context context) const
{
d->initIconThemes();
QStringList result;
if (group_or_size >= KIconLoader::LastGroup)
{
kDebug(264) << "Illegal icon group: " << group_or_size;
return result;
}
int size;
if (group_or_size >= 0)
size = d->mpGroups[group_or_size].size;
else
size = -group_or_size;
foreach(KIconThemeNode *themeNode, d->links)
themeNode->queryIconsByContext(&result, size, context);
// Eliminate duplicate entries (same icon in different directories)
QString name;
QStringList res2, entries;
QStringList::ConstIterator it;
for (it=result.constBegin(); it!=result.constEnd(); ++it)
{
int n = (*it).lastIndexOf('/');
if (n == -1)
name = *it;
else
name = (*it).mid(n+1);
name = d->removeIconExtension(name);
if (!entries.contains(name))
{
entries += name;
res2 += *it;
}
}
return res2;
}
QStringList KIconLoader::queryIcons(int group_or_size, KIconLoader::Context context) const
{
d->initIconThemes();
QStringList result;
if (group_or_size >= KIconLoader::LastGroup)
{
kDebug(264) << "Illegal icon group: " << group_or_size;
return result;
}
int size;
if (group_or_size >= 0)
size = d->mpGroups[group_or_size].size;
else
size = -group_or_size;
foreach(KIconThemeNode *themeNode, d->links)
themeNode->queryIcons(&result, size, context);
// Eliminate duplicate entries (same icon in different directories)
QString name;
QStringList res2, entries;
QStringList::ConstIterator it;
for (it=result.constBegin(); it!=result.constEnd(); ++it)
{
int n = (*it).lastIndexOf('/');
if (n == -1)
name = *it;
else
name = (*it).mid(n+1);
name = d->removeIconExtension(name);
if (!entries.contains(name))
{
entries += name;
res2 += *it;
}
}
return res2;
}
// used by KIconDialog to find out which contexts to offer in a combobox
bool KIconLoader::hasContext(KIconLoader::Context context) const
{
d->initIconThemes();
foreach(KIconThemeNode *themeNode, d->links)
if( themeNode->theme->hasContext( context ))
return true;
return false;
}
-#ifndef KICONLOADER_WITHOUTEFFECTS
KIconEffect * KIconLoader::iconEffect() const
{
return &d->mpEffect;
}
-#endif
bool KIconLoader::alphaBlending(KIconLoader::Group group) const
{
if (!d->mpGroups) return false;
if (group < 0 || group >= KIconLoader::LastGroup)
{
kDebug(264) << "Illegal icon group: " << group;
return false;
}
return d->mpGroups[group].alphaBlending;
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon KIconLoader::loadIconSet( const QString& name, KIconLoader::Group g, int s,
bool canReturnNull )
{
QIcon iconset;
QPixmap tmp = loadIcon(name, g, s, KIconLoader::ActiveState, QStringList(), NULL, canReturnNull);
iconset.addPixmap( tmp, QIcon::Active, QIcon::On );
// we don't use QIconSet's resizing anyway
tmp = loadIcon(name, g, s, KIconLoader::DisabledState, QStringList(), NULL, canReturnNull);
iconset.addPixmap( tmp, QIcon::Disabled, QIcon::On );
tmp = loadIcon(name, g, s, KIconLoader::DefaultState, QStringList(), NULL, canReturnNull);
iconset.addPixmap( tmp, QIcon::Normal, QIcon::On );
return iconset;
}
#endif
// Easy access functions
QPixmap DesktopIcon(const QString& name, int force_size, int state, const QStringList &overlays)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIcon(name, KIconLoader::Desktop, force_size, state, overlays);
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon DesktopIconSet(const QString& name, int force_size)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIconSet(name, KIconLoader::Desktop, force_size);
}
#endif
QPixmap BarIcon(const QString& name, int force_size, int state, const QStringList &overlays)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIcon(name, KIconLoader::Toolbar, force_size, state, overlays);
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon BarIconSet(const QString& name, int force_size)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIconSet( name, KIconLoader::Toolbar, force_size );
}
#endif
QPixmap SmallIcon(const QString& name, int force_size, int state, const QStringList &overlays)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIcon(name, KIconLoader::Small, force_size, state, overlays);
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon SmallIconSet(const QString& name, int force_size)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIconSet( name, KIconLoader::Small, force_size );
}
#endif
QPixmap MainBarIcon(const QString& name, int force_size, int state, const QStringList &overlays)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIcon(name, KIconLoader::MainToolbar, force_size, state, overlays);
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon MainBarIconSet(const QString& name, int force_size)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIconSet( name, KIconLoader::MainToolbar, force_size );
}
#endif
QPixmap UserIcon(const QString& name, int state, const QStringList &overlays)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIcon(name, KIconLoader::User, 0, state, overlays);
}
// deprecated
#ifndef KDE_NO_DEPRECATED
QIcon UserIconSet(const QString& name)
{
KIconLoader *loader = KIconLoader::global();
return loader->loadIconSet( name, KIconLoader::User );
}
#endif
int IconSize(KIconLoader::Group group)
{
KIconLoader *loader = KIconLoader::global();
return loader->currentSize(group);
}
QPixmap KIconLoader::unknown()
{
QPixmap pix;
if ( QPixmapCache::find("unknown", pix) ) //krazy:exclude=iconnames
return pix;
QString path = global()->iconPath("unknown", KIconLoader::Small, true); //krazy:exclude=iconnames
if (path.isEmpty())
{
kDebug(264) << "Warning: Cannot find \"unknown\" icon.";
pix = QPixmap(32,32);
} else
{
pix.load(path);
QPixmapCache::insert("unknown", pix); //krazy:exclude=iconnames
}
return pix;
}
/*** the global icon loader ***/
K_GLOBAL_STATIC_WITH_ARGS(KIconLoader, globalIconLoader, (KGlobal::mainComponent(), 0))
KIconLoader *KIconLoader::global()
{
return globalIconLoader;
}
void KIconLoader::newIconLoader()
{
if ( global() == this) {
KIconTheme::reconfigure();
}
reconfigure( objectName(), d->mpDirs );
emit iconLoaderSettingsChanged();
}
#include "kiconloader.moc"
diff --git a/kdeui/icons/kiconloader.h b/kdeui/icons/kiconloader.h
index 547c9beddb..6a9d1af239 100644
--- a/kdeui/icons/kiconloader.h
+++ b/kdeui/icons/kiconloader.h
@@ -1,568 +1,566 @@
/* vi: ts=8 sts=4 sw=4
*
* This file is part of the KDE project, module kdecore.
* Copyright (C) 2000 Geert Jansen <jansen@kde.org>
* Antonio Larrosa <larrosa@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License version 2 as published by the Free Software Foundation.
*
* 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KICONLOADER_H
#define KICONLOADER_H
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QObject>
#include <kglobal.h>
#include <kdeui_export.h>
class QIcon;
class QMovie;
class QPixmap;
class KComponentData;
class KIconLoaderPrivate;
class KStandardDirs;
class KIconEffect;
class KIconTheme;
/**
* Iconloader for KDE.
*
* KIconLoader will load the current icon theme and all its base themes.
* Icons will be searched in any of these themes. Additionally, it caches
* icons and applies effects according to the user's preferences.
*
* In KDE, it is encouraged to load icons by "Group". An icon group is a
* location on the screen where icons are being used. Standard groups are:
* Desktop, Toolbar, MainToolbar, Small and Panel. Each group has some
* centrally configured properties bound to it, including the icon size
* and effects. This makes it possible to offer a consistent icon look in
* all KDE applications.
*
* The standard groups are defined below.
*
* @li KIconLoader::Desktop: Icons in the iconview of konqueror, kdesktop and similar apps.
* @li KIconLoader::Toolbar: Icons in toolbars.
* @li KIconLoader::MainToolbar: Icons in the main toolbars.
* @li KIconLoader::Small: Various small (typical 16x16) places: titlebars, listviews
* and menu entries.
* @li KIconLoader::Panel: Icons in kicker's panel
*
* The icons are stored on disk in an icon theme or in a standalone
* directory. The icon theme directories contain multiple sizes and/or
* depths for the same icon. The iconloader will load the correct one based
* on the icon group and the current theme. Icon themes are stored globally
* in share/icons, or, application specific in share/apps/$appdir/icons.
*
* The standalone directories contain just one version of an icon. The
* directories that are searched are: $appdir/pics and $appdir/toolbar.
* Icons in these directories can be loaded by using the special group
* "User".
*
*/
class KDEUI_EXPORT KIconLoader : public QObject
{
Q_OBJECT
Q_ENUMS(Context)
Q_ENUMS(Type)
Q_ENUMS(MatchType)
Q_ENUMS(Group)
Q_ENUMS(StdSizes)
Q_ENUMS(States)
public:
/**
* Defines the context of the icon.
*/
enum Context {
Any, ///< Some icon with unknown purpose.
Action, ///< An action icon (e.g. 'save', 'print').
Application, ///< An icon that represents an application.
Device, ///< An icon that represents a device.
FileSystem, ///< An icon that represents a file system. @deprecated Use Place instead.
MimeType, ///< An icon that represents a mime type (or file type).
Animation, ///< An icon that is animated.
Category, ///< An icon that represents a category.
Emblem, ///< An icon that adds information to an existing icon.
Emote, ///< An icon that expresses an emotion.
International, ///< An icon that represents a country's flag.
Place, ///< An icon that represents a location (e.g. 'home', 'trash').
StatusIcon ///< An icon that represents an event.
};
/**
* The type of the icon.
*/
enum Type {
Fixed, ///< Fixed-size icon.
Scalable, ///< Scalable-size icon.
Threshold ///< A threshold icon.
};
/**
* The type of a match.
*/
enum MatchType {
MatchExact, ///< Only try to find an exact match.
MatchBest ///< Take the best match if there is no exact match.
};
/**
* The group of the icon.
*/
enum Group {
/// No group
NoGroup=-1,
/// Desktop icons
Desktop=0,
/// First group
FirstGroup=0,
/// Toolbar icons
Toolbar,
/// Main toolbar icons
MainToolbar,
/// Small icons, e.g. for buttons
Small,
/// Panel (Plasma Taskbar) icons
Panel,
/// Icons for use in dialog titles, page lists, etc
Dialog,
/// Last group
LastGroup,
/// User icons
User
};
/**
* These are the standard sizes for icons.
*/
enum StdSizes {
/// small icons for menu entries
SizeSmall=16,
/// slightly larger small icons for toolbars, panels, etc
SizeSmallMedium=22,
/// medium sized icons for the desktop
SizeMedium=32,
/// large sized icons for the panel
SizeLarge=48,
/// huge sized icons for iconviews
SizeHuge=64,
/// enormous sized icons for iconviews
SizeEnormous=128
};
/**
* Defines the possible states of an icon.
*/
enum States {
DefaultState, ///< The default state.
ActiveState, ///< Icon is active.
DisabledState, ///< Icon is disabled.
LastState ///< Last state (last constant)
};
/**
* Constructs an iconloader.
* @param appname Add the data directories of this application to the
* icon search path for the "User" group. The default argument adds the
* directories of the current application.
* @param dirs the KStandardDirs object to use. If null the global one is used
*
* Usually, you use the default iconloader, which can be accessed via
* KIconLoader::global(), so you hardly ever have to create an
* iconloader object yourself. That one is the current KComponentData's
* (typically KApplication's) iconloader.
*/
explicit KIconLoader(const QString& appname=QString(), KStandardDirs *dirs = 0, QObject* parent = 0);
/**
* Constructs an iconloader.
* @param componentData the KComponentData to use to create this icon loader.
*
* Usually, you use the default iconloader, which can be accessed via
* KIconLoader::global(), so you hardly ever have to create an
* iconloader object yourself. That one is the current KComponentData's
* (typically KApplication's) iconloader.
*/
explicit KIconLoader(const KComponentData &componentData, QObject* parent = 0);
/**
* Cleanup
*/
~KIconLoader();
/**
* Returns the global icon loader initialized with the global KComponentData.
* @return global icon loader
*/
static KIconLoader* global();
/**
* Adds @p appname to the list of application specific directories.
* @param appname The application name.
*/
void addAppDir(const QString& appname);
/**
* Loads an icon. It will try very hard to find an icon which is
* suitable. If no exact match is found, a close match is searched.
* If neither an exact nor a close match is found, a null pixmap or
* the "unknown" pixmap is returned, depending on the value of the
* @p canReturnNull parameter.
*
* @param name The name of the icon, without extension.
* @param group The icon group. This will specify the size of and effects to
* be applied to the icon.
* @param size If nonzero, this overrides the size specified by @p group.
* See KIconLoader::StdSizes.
* @param state The icon state: @p DefaultState, @p ActiveState or
* @p DisabledState. Depending on the user's preferences, the iconloader
* may apply a visual effect to hint about its state.
* @param overlays a list of emblem icons to overlay, by name. the emblem
* prefix is applied automatically to each name, e.g.
* "zip" becomes "emblem-zip"
* @param path_store If not null, the path of the icon is stored here,
* if the icon was found. If the icon was not found @p path_store
* is unaltered even if the "unknown" pixmap was returned.
* @param canReturnNull Can return a null pixmap? If false, the
* "unknown" pixmap is returned when no appropriate icon has been
* found. <em>Note:</em> a null pixmap can still be returned in the
* event of invalid parameters, such as empty names, negative sizes,
* and etc.
* @return the QPixmap. Can be null when not found, depending on
* @p canReturnNull.
*/
QPixmap loadIcon(const QString& name, KIconLoader::Group group, int size=0,
int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList(),
QString *path_store=0L,
bool canReturnNull=false) const;
/**
* Loads an icon for a mimetype.
* This is basically like loadIcon except that extra desktop themes are loaded if necessary.
*
* @param iconName The name of the icon, without extension, usually from KMimeType.
* @param group The icon group. This will specify the size of and effects to
* be applied to the icon.
* @param size If nonzero, this overrides the size specified by @p group.
* See KIconLoader::StdSizes.
* @param state The icon state: @p DefaultState, @p ActiveState or
* @p DisabledState. Depending on the user's preferences, the iconloader
* may apply a visual effect to hint about its state.
* @param path_store If not null, the path of the icon is stored here.
* @param overlays a list of emblem icons to overlay, by name. the emblem
* prefix is applied automatically to each name, e.g.
* "zip" becomes "emblem-zip"
* @return the QPixmap. Can not be null, the
* "unknown" pixmap is returned when no appropriate icon has been found.
*/
QPixmap loadMimeTypeIcon( const QString& iconName, KIconLoader::Group group, int size=0,
int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList(),
QString *path_store=0 ) const;
/**
* Creates an icon set, that will do on-demand loading of the icon.
* Loading itself is done by calling loadIcon .
*
* @param name The name of the icon, without extension.
* @param group The icon group. This will specify the size of and effects to
* be applied to the icon.
* @param size If nonzero, this overrides the size specified by @p group.
* See KIconLoader::StdSizes.
* @param canReturnNull Can return a null iconset? If false, iconset
* containing the "unknown" pixmap is returned when no appropriate icon has
* been found.
* @return the icon set. Can be null when not found, depending on
* @p canReturnNull.
*
* @deprecated use KIcon instead, which uses the iconloader internally
*/
#ifndef KDE_NO_DEPRECATED
KDE_DEPRECATED QIcon loadIconSet(const QString& name, KIconLoader::Group group, int size = 0,
bool canReturnNull = false);
#endif
/**
* Returns the path of an icon.
* @param name The name of the icon, without extension. If an absolute
* path is supplied for this parameter, iconPath will return it
* directly.
* @param group_or_size If positive, search icons whose size is
* specified by the icon group @p group_or_size. If negative, search
* icons whose size is - @p group_or_size.
* See KIconLoader::Group and KIconLoader::StdSizes
* @param canReturnNull Can return a null string? If not, a path to the
* "unknown" icon will be returned.
* @return the path of an icon, can be null or the "unknown" icon when
* not found, depending on @p canReturnNull.
*/
QString iconPath(const QString& name, int group_or_size,
bool canReturnNull=false) const;
/**
* Loads an animated icon.
* @param name The name of the icon.
* @param group The icon group. See loadIcon().
* @param size Override the default size for @p group.
* See KIconLoader::StdSizes.
* @param parent The parent object of the returned QMovie.
* @return A QMovie object. Can be null if not found or not valid.
* Ownership is passed to the caller.
*/
QMovie *loadMovie(const QString& name, KIconLoader::Group group, int size=0, QObject *parent=0) const;
/**
* Returns the path to an animated icon.
* @param name The name of the icon.
* @param group The icon group. See loadIcon().
* @param size Override the default size for @p group.
* See KIconLoader::StdSizes.
* @return the full path to the movie, ready to be passed to QMovie's constructor.
* Empty string if not found.
*/
QString moviePath(const QString& name, KIconLoader::Group group, int size=0) const;
/**
* Loads an animated icon as a series of still frames. If you want to load
* a .mng animation as QMovie instead, please use loadMovie() instead.
* @param name The name of the icon.
* @param group The icon group. See loadIcon().
* @param size Override the default size for @p group.
* See KIconLoader::StdSizes.
* @return A QStringList containing the absolute path of all the frames
* making up the animation.
*/
QStringList loadAnimated(const QString& name, KIconLoader::Group group, int size=0) const;
/**
* Queries all available icons for a specific group, having a specific
* context.
* @param group_or_size If positive, search icons whose size is
* specified by the icon group @p group_or_size. If negative, search
* icons whose size is - @p group_or_size.
* See KIconLoader::Group and KIconLoader::StdSizes
* @param context The icon context.
* @return a list of all icons
*/
QStringList queryIcons(int group_or_size, KIconLoader::Context context=KIconLoader::Any) const;
/**
* Queries all available icons for a specific context.
* @param group_or_size The icon preferred group or size. If available
* at this group or size, those icons will be returned, in other case,
* icons of undefined size will be returned. Positive numbers are groups,
* negative numbers are negated sizes. See KIconLoader::Group and
* KIconLoader::StdSizes
* @param context The icon context.
* @return A QStringList containing the icon names
* available for that context
*/
QStringList queryIconsByContext(int group_or_size,
KIconLoader::Context context=KIconLoader::Any) const;
/**
* @internal
*/
bool hasContext( KIconLoader::Context context ) const;
/**
* Returns a list of all icons (*.png or *.xpm extension) in the
* given directory.
* @param iconsDir the directory to search in
* @return A QStringList containing the icon paths
*/
QStringList queryIconsByDir( const QString& iconsDir ) const;
/**
* Returns the current size of the icon group.
* Using e.g. KIconLoader::SmallIcon will retrieve the icon size
* that is currently set from System Settings->Appearance->Icon
* sizes. SmallIcon for instance, would typically be 16x16, but
* the user could increase it and this setting would change as well.
* @param group the group to check.
* @return the current size for an icon group.
*/
int currentSize(KIconLoader::Group group) const;
/**
* Returns a pointer to the current theme. Can be used to query
* available and default sizes for groups.
* @note The KIconTheme will change if reconfigure() is called and
* therefore it's not recommended to store the pointer anywhere.
* @return a pointer to the current theme. 0 if no theme set.
*/
KIconTheme *theme() const;
-#ifndef KICONLOADER_WITHOUTEFFECTS
/**
* Returns a pointer to the KIconEffect object used by the icon loader.
* @return the KIconEffect.
*/
KIconEffect *iconEffect() const;
-#endif;
/**
* Called by KComponentData::newIconLoader to reconfigure the icon loader.
* @param _appname the new application name
* @param _dirs the new standard directories. If 0, the directories
* from KGlobal will be taken.
*/
void reconfigure( const QString& _appname, KStandardDirs *_dirs );
/**
* Returns the unknown icon. An icon that is used when no other icon
* can be found.
* @return the unknown pixmap
*/
static QPixmap unknown();
/**
* Checks whether the user wants to blend the icons with the background
* using the alpha channel information for a given group.
* @param group the group to check
* @return true if alpha blending is desired
* @obsolete
*/
bool alphaBlending( KIconLoader::Group group ) const;
/**
* Adds all the default themes from other desktops at the end of
* the list of icon themes.
*/
void addExtraDesktopThemes();
/**
* Returns if the default icon themes of other desktops have been added
* to the list of icon themes where icons are searched.
*/
bool extraDesktopThemesAdded() const;
/**
* Draws overlays on the specified pixmap, it takes the width and height
* of the pixmap into consideration
* @param overlays to draw
* @param pixmap to draw on
* @since 4.7
*/
void drawOverlays(const QStringList &overlays, QPixmap &pixmap, KIconLoader::Group group, int state = KIconLoader::DefaultState) const;
public Q_SLOTS:
/**
* Re-initialize the global icon loader
*/
void newIconLoader();
Q_SIGNALS:
/**
* Emitted by newIconLoader once the new settings have been loaded
*/
void iconLoaderSettingsChanged();
private:
// @internal the data object
KIconLoaderPrivate *d;
};
/**
* \relates KIconLoader
* Load a desktop icon.
*/
KDEUI_EXPORT QPixmap DesktopIcon(const QString& name, int size=0,
int state=KIconLoader::DefaultState, const QStringList& overlays = QStringList());
/**
* \relates KIconLoader
* Load a desktop icon, and apply the necessary effects to get an IconSet.
* @deprecated use KIcon(name) or KIcon(name,componentData.iconLoader()) instead
*/
#ifndef KDE_NO_DEPRECATED
KDEUI_EXPORT_DEPRECATED QIcon DesktopIconSet(const QString& name, int size=0);
#endif
/**
* \relates KIconLoader
* Load a toolbar icon.
*/
KDEUI_EXPORT QPixmap BarIcon(const QString& name, int size=0, int state=KIconLoader::DefaultState,
const QStringList& overlays = QStringList());
/**
* \relates KIconLoader
* Load a toolbar icon, and apply the necessary effects to get an IconSet.
* @deprecated use KIcon(name) or KIcon(name,componentData.iconLoader()) instead
*/
#ifndef KDE_NO_DEPRECATED
KDEUI_EXPORT_DEPRECATED QIcon BarIconSet(const QString& name, int size=0);
#endif
/**
* \relates KIconLoader
* Load a small icon.
*/
KDEUI_EXPORT QPixmap SmallIcon(const QString& name, int size=0,
int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList());
/**
* \relates KIconLoader
* Load a small icon, and apply the necessary effects to get an IconSet.
* @deprecated use KIcon(name) or KIcon(name,componentData.iconLoader()) instead
*/
#ifndef KDE_NO_DEPRECATED
KDEUI_EXPORT_DEPRECATED QIcon SmallIconSet(const QString& name, int size=0);
#endif
/**
* \relates KIconLoader
* Load a main toolbar icon.
*/
KDEUI_EXPORT QPixmap MainBarIcon(const QString& name, int size=0,
int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList());
/**
* \relates KIconLoader
* Load a main toolbar icon, and apply the effects to get an IconSet.
* @deprecated use KIcon(name) or KIcon(name,componentData.iconLoader()) instead
*/
#ifndef KDE_NO_DEPRECATED
KDEUI_EXPORT_DEPRECATED QIcon MainBarIconSet(const QString& name, int size=0);
#endif
/**
* \relates KIconLoader
* Load a user icon. User icons are searched in $appdir/pics.
*/
KDEUI_EXPORT QPixmap UserIcon(const QString& name, int state=KIconLoader::DefaultState, const QStringList &overlays = QStringList());
/**
* \relates KIconLoader
* Load a user icon, and apply the effects to get an IconSet.
* @deprecated use KIcon(name) or KIcon(name,componentData.iconLoader()) instead
*/
#ifndef KDE_NO_DEPRECATED
KDEUI_EXPORT_DEPRECATED QIcon UserIconSet(const QString& name);
#endif
/**
* \relates KIconLoader
* Returns the current icon size for a specific group.
*/
KDEUI_EXPORT int IconSize(KIconLoader::Group group);
inline KIconLoader::Group& operator++(KIconLoader::Group& group) { group = static_cast<KIconLoader::Group>(group+1); return group; }
inline KIconLoader::Group operator++(KIconLoader::Group& group,int) { KIconLoader::Group ret = group; ++group; return ret; }
#endif // KICONLOADER_H
diff --git a/plasma/servicejob.h b/plasma/servicejob.h
index 6a975c0c76..b55b70e2fe 100644
--- a/plasma/servicejob.h
+++ b/plasma/servicejob.h
@@ -1,139 +1,139 @@
/*
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* 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 Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_SERVICEJOB_H
#define PLASMA_SERVICEJOB_H
#include <QtCore/QVariant>
#include <kjob.h>
#include <kservice.h>
#include <plasma/plasma_export.h>
#include "credentials.h"
namespace Plasma
{
class ServiceJobPrivate;
/**
* @class ServiceJob plasma/servicejob.h <Plasma/ServiceJob>
*
* @short This class provides jobs for use with Plasma::Service
*
* Unlike KJob, you can do the work in start(), since Plasma::Service already
* delays the call to start() until the event loop is reached.
*
* If the job is quick enough that it is not worth reporting the progress,
* you just need to implement start() to do the task, then call emitResult()
* at the end of it. If the task does not complete successfully, you should
* set a non-zero error code with setError(int) and an error message with
* setErrorText(QString).
*
* If the job is longer (involving network access, for instance), you should
* report the progress at regular intervals. See the KJob documentation for
* information on how to do this.
*/
class PLASMA_EXPORT ServiceJob : public KJob
{
Q_OBJECT
Q_PROPERTY(QString destination READ destination)
Q_PROPERTY(QString operationName READ operationName)
Q_PROPERTY(QVariant result READ result)
public:
/**
* Default constructor
*
* @param destination the subject that the job is acting on
* @param operation the action that the job is performing on the @p destination
* @param parameters the parameters of the @p action
* @param parent the parent object for this service
*/
ServiceJob(const QString &destination, const QString &operation,
const QMap<QString, QVariant> &parameters, QObject *parent = 0);
/**
* Destructor
*/
~ServiceJob();
/**
* @return the subject that the job is acting on
*/
QString destination() const;
/**
* @return the operation the job is performing on the destination
*/
QString operationName() const;
/**
* @return the parameters for the operation
*/
QMap<QString, QVariant> parameters() const;
/**
* @return the identity of the caller of this operation
*/
Credentials identity() const;
/**
* Returns the result of the operation
*
* The result will be invalid if the job has not completed yet, or
* if the job does not have a meaningful result.
*
* Note that this should not be used to find out whether the operation
* was successful. Instead, you should check the value of error().
*
* @return the result of the operation
*/
QVariant result() const;
/**
* Default implementation of start, which simply sets the results to false.
* This makes it easy to create a "failure" job.
*/
Q_INVOKABLE virtual void start();
protected:
/**
* Sets the result for an operation.
*/
void setResult(const QVariant &result);
private:
Q_PRIVATE_SLOT(d, void autoStart())
Q_PRIVATE_SLOT(d, void preventAutoStart())
ServiceJobPrivate * const d;
friend class ServiceProvider;
friend class RemoteServiceJob;
};
} // namespace Plasma
-using namespace Plasma;
-Q_DECLARE_METATYPE(ServiceJob *)
+
+Q_DECLARE_METATYPE(Plasma::ServiceJob *)
#endif // multiple inclusion guard

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 1, 9:58 AM (1 d, 21 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10076253
Default Alt Text
(85 KB)

Event Timeline