generic: remove redundant classes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-01-23 04:31:52 +02:00
parent 9c7e1896db
commit 82dbf8202b
16 changed files with 8 additions and 2564 deletions

View file

@ -1 +0,0 @@
#include "../kpixmapcache.h"

View file

@ -1 +0,0 @@
#include "../kpixmapprovider.h"

View file

@ -1 +0,0 @@
#include "../kurlpixmapprovider.h"

View file

@ -125,7 +125,6 @@ set(kdeui_LIB_SRCS
icons/kicon.cpp
icons/kiconloader.cpp
icons/kicontheme.cpp
icons/kiconcache.cpp
itemviews/kbreadcrumbselectionmodel.cpp
itemviews/kcheckableproxymodel.cpp
itemviews/klinkitemselectionmodel.cpp
@ -200,8 +199,6 @@ set(kdeui_LIB_SRCS
util/knumvalidator.cpp
util/kpassivepopup.cpp
util/kpassivepopupmessagehandler.cpp
util/kpixmapcache.cpp
util/kpixmapprovider.cpp
util/kstandardguiitem.cpp
util/kwallet.cpp
util/kwordwrap.cpp
@ -517,7 +514,6 @@ install(
icons/k3icon_p.h
icons/kiconloader.h
icons/kicontheme.h
icons/kiconcache.h
itemviews/kbreadcrumbselectionmodel.h
itemviews/kcheckableproxymodel.h
itemviews/klinkitemselectionmodel.h
@ -579,8 +575,6 @@ install(
util/knumvalidator.h
util/kpassivepopup.h
util/kpassivepopupmessagehandler.h
util/kpixmapcache.h
util/kpixmapprovider.h
util/kimagecache.h
util/kstandardguiitem.h
util/kwallet.h

View file

@ -1,317 +0,0 @@
/*
*
* This file is part of the KDE project.
* Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
*
* 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 "kiconcache.h"
#include <QtCore/QString>
#include <QtGui/QPixmap>
#include <QtCore/QFile>
#include <QtCore/QDataStream>
#include <QtCore/QFileInfo>
#include <QtCore/QDateTime>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <sys/file.h>
#include <time.h>
#define KDE_ICONCACHE_NAME "kde-icon-cache"
#define KDE_ICONCACHE_VERSION 0x000100
class KIconCache::Private
{
public:
Private(KIconCache* _q)
{
q = _q;
mUpdatesCheckedTime = 0;
}
bool themeDirsChanged()
{
if (q->existingIconThemeDirs(mThemeNames) != mThemeDirs ||
q->mostRecentMTime(mThemeDirs) != mThemesMTime) {
kDebug(264) << "Theme directory has been modified";
return true;
} else {
return false;
}
}
void checkForThemeUpdates()
{
if (!q->isEnabled()) {
return;
}
// Don't check more often than every 5 secs
const quint32 now = ::time(0);
if (now < mUpdatesCheckedTime + 5) {
return;
}
mUpdatesCheckedTime = now;
// Perhaps another process has already checked for updates in last 5 secs
const QFileInfo fi(mUpdatesFile);
if (fi.exists() && fi.lastModified().toTime_t() + 5 > now) {
return;
}
// Check for theme updates
if (themeDirsChanged()) {
// Update themes info and discard the cache
mThemeDirs = q->existingIconThemeDirs(mThemeNames);
mThemesMTime = q->mostRecentMTime(mThemeDirs);
q->discard();
}
// Update timestamp file
QFile f(mUpdatesFile);
f.open(QIODevice::WriteOnly);
}
KIconCache* q;
qint32 mDefaultIconSize[6];
QStringList mThemeNames;
QSet<QString> mThemeDirs;
quint32 mThemesMTime;
QString mUpdatesFile;
quint32 mUpdatesCheckedTime;
QString* mLoadPath;
QString mSavePath;
};
KIconCache::KIconCache()
: KPixmapCache(KDE_ICONCACHE_NAME), d(new Private(this))
{
d->mUpdatesFile = KGlobal::dirs()->locateLocal("cache", "kpc/"KDE_ICONCACHE_NAME".updated");
// Set limit to 10 MB
setCacheLimit(10 * 1024);
}
KIconCache::~KIconCache()
{
delete d;
}
void KIconCache::deleteCache()
{
KPixmapCache::deleteCache(KDE_ICONCACHE_NAME);
}
bool KIconCache::loadCustomIndexHeader(QDataStream& stream)
{
if (stream.atEnd()) {
return false;
}
// Load version
quint32 version;
stream >> version;
if (version != KDE_ICONCACHE_VERSION) {
kDebug(264) << "Obsolete iconcache version" << version << "will recreate";
return false;
}
// Load default sizes of icons
for (int i = 0; i < 6; i++) {
stream >> d->mDefaultIconSize[i];
}
stream >> d->mThemeNames;
stream >> d->mThemeDirs;
// TODO: use KPixmapCache's timestamp instead
stream >> d->mThemesMTime;
if (stream.status() != QDataStream::Ok) {
kWarning() << "Failed to read index file's header";
recreateCacheFiles();
return false;
}
// Make sure at least one theme was read
if (!d->mThemeNames.count()) {
kDebug(264) << "Empty themes list";
return false;
}
// Make sure the theme dirs haven't changed
if (d->themeDirsChanged()) {
return false;
}
d->mUpdatesCheckedTime= ::time(0);
return true;
}
void KIconCache::writeCustomIndexHeader(QDataStream& stream)
{
setValid(false);
stream << (quint32)KDE_ICONCACHE_VERSION;
for (int i = 0; i < 6; i++) {
stream << d->mDefaultIconSize[i];
}
// Save iconthemes info
stream << d->mThemeNames;
stream << d->mThemeDirs;
stream << d->mThemesMTime;
// Cache is valid if header was successfully written and we actually have
// the icontheme name(s)
if (stream.status() == QDataStream::Ok && d->mThemeNames.count()) {
setValid(true);
}
}
QSet<QString> KIconCache::existingIconThemeDirs(const QStringList& themeNames) const
{
// Find all possible icontheme dirs
// This has been taken from kicontheme.cpp
QStringList icondirs = KGlobal::dirs()->resourceDirs("icon")
<< KGlobal::dirs()->resourceDirs("xdgdata-icon")
<< "/usr/share/pixmaps/"
// These are not in the icon spec, but e.g. GNOME puts some icons there anyway.
<< KGlobal::dirs()->resourceDirs("xdgdata-pixmap");
icondirs.removeDuplicates();
// Check which of theme actually contain existing dir of one of the
// given themes
QSet<QString> dirs;
foreach (const QString it, icondirs) {
foreach (const QString themeIt, themeNames) {
QString dirName = it + themeIt + '/';
if (KGlobal::dirs()->exists(dirName)) {
dirs.insert(dirName);
}
}
}
return dirs;
}
unsigned int KIconCache::mostRecentMTime(const QSet<QString>& dirNames) const
{
unsigned int timestamp = 0;
foreach (const QString &dir, dirNames) {
unsigned int mtime = QFileInfo(dir).lastModified().toTime_t();
if (timestamp < mtime) {
timestamp = mtime;
}
}
return timestamp;
}
int KIconCache::defaultIconSize(KIconLoader::Group group) const
{
if ((group < 0) || (group >= KIconLoader::LastGroup))
{
kDebug(264) << "Illegal icon group:" << group;
return -1;
}
return d->mDefaultIconSize[group];
}
void KIconCache::setThemeInfo(const QList<KIconTheme*>& themes)
{
if (themes.isEmpty()) {
for (KIconLoader::Group i = KIconLoader::FirstGroup; i < KIconLoader::LastGroup; ++i) {
d->mDefaultIconSize[i] = 0;
}
return;
}
// This as to be done always, even if the cache itself is disabled
for (KIconLoader::Group i = KIconLoader::FirstGroup; i < KIconLoader::LastGroup; ++i) {
d->mDefaultIconSize[i] = themes.first()->defaultSize(i);
}
if (!isEnabled()) {
return;
}
setValid(false);
// Save internal names and dirs of all themes
d->mThemeNames.clear();
foreach (KIconTheme* theme, themes) {
d->mThemeNames.append(theme->internalName());
}
d->mThemeDirs = existingIconThemeDirs(d->mThemeNames);
d->mThemesMTime = mostRecentMTime(d->mThemeDirs);
d->mUpdatesCheckedTime= ::time(0);
// Recreate the cache
recreateCacheFiles();
}
bool KIconCache::find(const QString& key, QPixmap& pix, QString* path)
{
d->checkForThemeUpdates();
d->mLoadPath = path;
// We can use QPixmapCache only if we don't need the path
setUseQPixmapCache(!path);
//kDebug(264) << "use QPC = " << useQPixmapCache();
bool ret = find(key, pix);
d->mLoadPath = 0;
return ret;
}
void KIconCache::insert(const QString& key, const QPixmap& pix, const QString& path)
{
d->mSavePath = path;
insert(key, pix);
d->mSavePath.clear();
}
bool KIconCache::find(const QString& key, QPixmap& pix)
{
// TODO: make sure that cache is still valid
return KPixmapCache::find(key, pix);
}
void KIconCache::insert(const QString& key, const QPixmap& pix)
{
// TODO: make sure that cache is still valid
KPixmapCache::insert(key, pix);
}
bool KIconCache::loadCustomData(QDataStream& stream)
{
QString path;
stream >> path;
if (d->mLoadPath) {
*d->mLoadPath = path;
}
return true;
}
bool KIconCache::writeCustomData(QDataStream& stream)
{
stream << d->mSavePath;
return true;
}

View file

@ -1,93 +0,0 @@
/*
*
* This file is part of the KDE project.
* Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
*
* 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 KICONCACHE_H
#define KICONCACHE_H
#include <kdeui_export.h>
#include <kicontheme.h>
#include <kpixmapcache.h>
class QString;
class QStringList;
class QPixmap;
class QDataStream;
/**
* Icon cache for KDE.
*
* Note that this is the KDE-wide cache for storing icons and should only be
* used by KIconLoader. If you want to cache your own pixmaps you should look
* at KImageCache or KSharedDataCache instead.
*
* @internal
*/
// KDE5: Un-export the symbols for this. Better yet, remove it entirely
// since KPixmapCache is deprecated.
class KDEUI_EXPORT KIconCache : public KPixmapCache
{
public:
/**
* Constucts the icon cache object.
**/
explicit KIconCache();
virtual ~KIconCache();
bool find(const QString& key, QPixmap& pix, QString* path);
void insert(const QString& key, const QPixmap& pix, const QString& path);
virtual bool find(const QString& key, QPixmap& pix);
virtual void insert(const QString& key, const QPixmap& pix);
/**
* Deletes the icon cache.
**/
static void deleteCache();
/**
* The default size of current theme for a certain icon group.
* @param group The icon group. See KIconLoader::Group.
* @return The default size in pixels for the given icon group.
*/
int defaultIconSize(KIconLoader::Group group) const;
void setThemeInfo(const QList<KIconTheme*>& themes);
protected:
virtual bool loadCustomIndexHeader(QDataStream& stream);
virtual void writeCustomIndexHeader(QDataStream& stream);
virtual bool loadCustomData(QDataStream& stream);
virtual bool writeCustomData(QDataStream& stream);
QSet<QString> existingIconThemeDirs(const QStringList& themeNames) const;
unsigned int mostRecentMTime(const QSet<QString>& dirNames) const;
private:
class Private;
friend class Private;
Private * const d;
};
#endif // KICONCACHE_H

File diff suppressed because it is too large Load diff

View file

@ -1,384 +0,0 @@
/*
*
* This file is part of the KDE project.
* Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
*
* 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 KPIXMAPCACHE_H
#define KPIXMAPCACHE_H
#include <kdeui_export.h>
#include <QtCore/QList>
#include <QtCore/QSet>
#include <QtCore/QSize>
class QString;
class QPixmap;
/**
* @brief General-purpose pixmap cache for KDE.
*
* The pixmap cache can be used to store pixmaps which can later be loaded
* from the cache very quickly.
*
* Its most common use is storing SVG images which might be expensive to
* render every time they are used. With the cache you can render each SVG
* only once and later use the stored version unless the SVG file or requested
* pixmap size changes.
*
* KPixmapCache's API is similar to that of the QPixmapCache so if you're
* already using the latter then all you need to do is creating a KPixmapCache
* object (unlike QPixmapCache, KPixmapCache doesn't have many static methods)
* and calling @ref insert() and @ref find() method on that object:
* @code
* // Create KPixmapCache object
* KPixmapCache* cache = new KPixmapCache("myapp-pixmaps");
* // Load a pixmap
* QPixmap pix;
* if (!cache->find("pixmap-1", pix)) {
* // Pixmap isn't in the cache, create it and insert to cache
* pix = createPixmapFromData();
* cache->insert("pixmap-1", pix);
* }
* // Use pix
* @endcode
*
* The above example illustrates that you can also cache pixmaps created from
* some data. In case such data is updated, you might need to discard cache
* contents using @ref discard() method:
* @code
* // Discard the cache if it's too old
* if (cache->timestamp() < mydataTimestamp()) {
* cache->discard();
* }
* // Now the cache contains up-to-date data
* @endcode
* As demonstrated, you can use cache's @ref timestamp() method to see when
* the cache was created. If necessary, you can also change the timestamp
* using @ref setTimestamp() method.
*
* @deprecated KPixmapCache is susceptible to various non-trivial locking bugs and
* inefficiencies, and is supported for backward compatibility only (since it exposes
* a QDataStream API for subclasses). Users should port to KImageCache for a very close
* work-alike, or KSharedDataCache if they need more control.
*
* @see KImageCache, KSharedDataCache
*
* @author Rivo Laks
*/
class KDEUI_EXPORT KPixmapCache
{
public:
/**
* Constucts the pixmap cache object.
* @param name unique name of the cache
*/
explicit KPixmapCache(const QString& name);
virtual ~KPixmapCache();
/**
* Tries to load pixmap with the specified @a key from cache. If the pixmap
* is found it is stored in @a pix, otherwise @a pix is unchanged.
*
* @return true when pixmap was found and loaded from cache, false otherwise
*/
virtual bool find(const QString& key, QPixmap& pix);
/**
* Inserts the pixmap @a pix into the cache, associated with the key @a key.
*
* Any existing pixmaps associated with @a key are overwritten.
*/
virtual void insert(const QString& key, const QPixmap& pix);
/**
* Loads a pixmap from given file, using the cache. If the file does not
* exist on disk, an empty pixmap is returned, even if that file had
* previously been cached. In addition, if the file's modified-time is
* more recent than cache's @ref timestamp(), the @em entire cache is
* discarded (to be regenerated). This behavior may change in a future
* KDE Platform release. If the cached data is current the pixmap
* is returned directly from the cache without any file loading.
*
* @note The mapping between @a filename and the actual key used internally
* is implementation-dependent and can change without warning. Use insert()
* manually if you need control of the key, otherwise consistently use this
* function.
*
* @param filename The name of the pixmap to load, cache, and return.
* @return The given pixmap, or an empty pixmap if the file was invalid or did
* not exist.
*/
QPixmap loadFromFile(const QString& filename);
/**
* Same as loadFromFile(), but using an SVG file instead. You may optionally
* pass in a @a size to control the size of the output pixmap.
*
* @note The returned pixmap is only cached for identical filenames and sizes.
* If you change the size in between calls to this function then the
* pixmap will have to be regenerated again.
*
* @param filename The filename of the SVG file to load.
* @param size size of the pixmap where the SVG is render to. If not given
* then the SVG file's default size is used.
* @return an empty pixmap if the file does not exist or was invalid, otherwise
* a pixmap of the desired @a size.
*/
QPixmap loadFromSvg(const QString& filename, const QSize& size = QSize());
/**
* @note KPixmapCache does not ever change the timestamp, so the application
* must set the timestamp if it to be used.
* @return Timestamp of the cache, set using the setTimestamp() method.
*/
unsigned int timestamp() const;
/**
* Sets the timestamp of app-specific cache. It's saved in the cache file
* and can later be retrieved using the timestamp() method.
* By default the timestamp is set to the cache creation time.
*/
void setTimestamp(unsigned int time);
/**
* Sets whether QPixmapCache (memory caching) should be used in addition
* to disk cache. QPixmapCache is used by default.
*
* @note On most systems KPixmapCache can use shared-memory to share cached
* pixmaps with other applications attached to the same shared pixmap,
* which means additional memory caching is unnecessary and actually
* wasteful of memory.
*
* @warning QPixmapCache is shared among the entire process and therefore
* can cause strange interactions with other instances of KPixmapCache.
* This may be fixed in the future and should be not relied upon.
*/
// KDE5 Get rid of QPixmapCache and use a sane cache instead.
void setUseQPixmapCache(bool use);
/**
* Whether QPixmapCache should be used to cache pixmaps in memory in
* addition to caching them on the disk.
*
* @b NOTE: The design of QPixmapCache means that the entries stored in
* the cache are shared throughout the entire process, and not just in
* this particular KPixmapCache. KPixmapCache makes an effort to ensure
* that entries from other KPixmapCaches do not inadvertently spill over
* into this one, but is not entirely successful (see discard())
*/
bool useQPixmapCache() const;
/**
* @return approximate size of the cache, in kilobytes (1 kilobyte == 1024 bytes)
*/
int size() const;
/**
* @return maximum size of the cache (in kilobytes).
* Default setting is 3 megabytes (1 megabyte = 2^20 bytes).
*/
int cacheLimit() const;
/**
* Sets the maximum size of the cache (in kilobytes). If cache gets bigger
* than the limit then some entries are removed (according to
* removeEntryStrategy()).
*
* Setting the cache limit to 0 disables caching (as all entries will get
* immediately removed).
*
* Note that the cleanup might not be done immediately, so the cache might
* temporarily (for a few seconds) grow bigger than the limit.
*/
void setCacheLimit(int kbytes);
/**
* Describes which entries will be removed first during cache cleanup.
* @see removeEntryStrategy(), @see setRemoveEntryStrategy()
*/
enum RemoveStrategy { /// oldest entries are removed first.
RemoveOldest,
/// least used entries are removed first.
RemoveSeldomUsed,
/// least recently used entries are removed first.
RemoveLeastRecentlyUsed
};
/**
* @return current entry removal strategy.
* Default is RemoveLeastRecentlyUsed.
*/
RemoveStrategy removeEntryStrategy() const;
/**
* Sets the removeEntryStrategy used when removing entries.
*/
void setRemoveEntryStrategy(RemoveStrategy strategy);
/**
* Cache will be disabled when e.g. its data file cannot be created or
* read.
*
* @return true when the cache is enabled.
*/
bool isEnabled() const;
/**
* @return true when the cache is ready to be used. Not being valid usually
* means that some additional initialization has to be done before the
* cache can be used.
*/
bool isValid() const;
/**
* Deletes a pixmap cache.
* @param name unique name of the cache to be deleted
*/
// KDE5: Static function oh how I hate you, this makes it very difficult to perform
// appropriate locking and synchronization to actually remove the cache.
static void deleteCache(const QString& name);
/**
* Deletes all entries and reinitializes this cache.
*
* @b NOTE: If useQPixmapCache is set to true then that cache must also
* be cleared. There is only one QPixmapCache for the entire process
* however so other KPixmapCaches and other QPixmapCache users may also
* be affected, leading to a temporary slowdown until the QPixmapCache is
* repopulated.
*/
void discard();
/**
* Removes some of the entries in the cache according to current
* removeEntryStrategy().
*
* @param newsize wanted size of the cache, in bytes. If 0 is given then
* current cacheLimit() is used.
*
* @warning This currently works by copying some entries to a new cache and
* then replacing the old cache with the new one. Thus it might be slow and
* will temporarily use extra disk space.
*/
void removeEntries(int newsize = 0);
protected:
/**
* Makes sure that the cache is initialized correctly, including the loading of the
* cache index and data, and any shared memory attachments (for systems where that
* is enabled).
*
* @note Although this method is protected you should not use it from any subclasses.
*
* @internal
*/
// KDE5: rename to ensureInitialized()
// KDE5: Make private or move to Private
void ensureInited() const;
/**
* Can be used by subclasses to load custom data from the stream.
* This function will be called by KPixmapCache immediately following the
* image data for a single image being read from @a stream.
* (This function is called once for every single image).
*
* @see writeCustomData
* @see loadCustomIndexHeader
* @param stream the QDataStream to read data from
* @return true if custom data was successfully loaded, false otherwise. If
* false is returned then the cached item is assumed to be invalid and
* will not be available to find() or contains().
*/
virtual bool loadCustomData(QDataStream& stream);
/**
* Can be used by subclasses to write custom data into the stream.
* This function will be called by KPixmapCache immediately after the
* image data for a single image has been written to @a stream.
* (This function is called once for every single image).
*
* @see loadCustomData
* @see writeCustomIndexHeader
* @param stream the QDataStream to write data to
*/
virtual bool writeCustomData(QDataStream& stream);
/**
* Can be used by subclasses to load custom data from cache's header.
* This function will be called by KPixmapCache immediately after the
* index header has been written out. (This function is called one time
* only for the entire cache).
*
* @see loadCustomData
* @see writeCustomIndexHeader
* @param stream the QDataStream to read data from
* @return true if custom index header data was successfully read, false
* otherwise. If false is returned then the cache is assumed to
* be invalid and further processing does not occur.
*/
virtual bool loadCustomIndexHeader(QDataStream& stream);
/**
* Can be used by subclasses to write custom data into cache's header.
* This function will be called by KPixmapCache immediately following the
* index header has being loaded. (This function is called one time
* only for the entire cache).
*
* @see writeCustomData
* @see loadCustomIndexHeader
* @param stream the QDataStream to write data to
*/
virtual void writeCustomIndexHeader(QDataStream& stream);
/**
* Sets whether this cache is valid or not. (The cache must be enabled in addition
* for isValid() to return true. @see isEnabled(), @see setEnabled()).
*
* Most cache functions do not work if the cache is not valid. KPixmapCache assumes
* the cache is valid as long as its cache files were able to be created (see
* recreateCacheFiles()) even if the cache is not enabled.
*
* Can be used by subclasses to indicate that cache needs some additional
* initialization before it can be used (note that KPixmapCache will @em not handle
* actually performing this extra initialization).
*/
void setValid(bool valid);
/**
* This function causes the cache files to be recreate by invalidating the cache.
* Any shared memory mappings (if enabled) are dropped temporarily as well.
*
* @note The recreated cache will be initially empty, but with the same size limits
* and entry removal strategy (see removeEntryStrategy()).
*
* If you use this in a subclass be prepared to handle writeCustomData() and
* writeCustomIndexHeader().
*
* @return true if the cache was successfully recreated.
*/
bool recreateCacheFiles();
private:
/// @internal
class Private;
friend class Private;
Private * const d; ///< @internal
};
#endif // KPIXMAPCACHE_H

View file

@ -1,25 +0,0 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@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 (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 "kpixmapprovider.h"
KPixmapProvider::~KPixmapProvider() {}

View file

@ -1,53 +0,0 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@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 (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 KPIXMAPPROVIDER_H
#define KPIXMAPPROVIDER_H
#include <kdeui_export.h>
#include <QtGui/QPixmap>
/**
* A tiny abstract class with just one method:
* pixmapFor()
*
* It will be called whenever an icon is searched for @p text.
*
* Used e.g. by KHistoryCombo
*
* @author Carsten Pfeiffer <pfeiffer@kde.org>
* @short an abstract interface for looking up icons
*/
class KDEUI_EXPORT KPixmapProvider
{
public:
virtual ~KPixmapProvider();
/**
* You may subclass this and return a pixmap of size @p size for @p text.
* @param text the text that is associated with the pixmap
* @param size the size of the icon in pixels, 0 for defaylt size.
* See KIconLoader::StdSize.
* @return the pixmap for the arguments, or null if there is none
*/
virtual QPixmap pixmapFor( const QString& text, int size = 0 ) = 0;
};
#endif // KPIXMAPPROVIDER_H

View file

@ -30,17 +30,16 @@
#include <klocale.h>
#include <knotification.h>
#include <kpixmapprovider.h>
#include <kstandardshortcut.h>
#include <kicontheme.h>
#include <kicon.h>
#include <kiconloader.h>
#include <kdebug.h>
class KHistoryComboBox::Private
{
public:
Private(KHistoryComboBox *q): q(q), myPixProvider(0) {}
Private(KHistoryComboBox *q): q(q) {}
KHistoryComboBox *q;
@ -59,7 +58,6 @@ public:
* Needed to allow going back after rotation.
*/
bool myRotated;
KPixmapProvider *myPixProvider;
};
// we are always read-write
@ -88,7 +86,6 @@ void KHistoryComboBox::init( bool useCompletion )
setInsertPolicy( NoInsert );
d->myIterateIndex = -1;
d->myRotated = false;
d->myPixProvider = 0L;
// obey HISTCONTROL setting
QByteArray histControl = qgetenv("HISTCONTROL");
@ -106,7 +103,6 @@ void KHistoryComboBox::init( bool useCompletion )
KHistoryComboBox::~KHistoryComboBox()
{
delete d->myPixProvider;
delete d;
}
@ -204,10 +200,8 @@ void KHistoryComboBox::addToHistory( const QString& item )
}
// now add the item
if ( d->myPixProvider )
insertItem( 0, d->myPixProvider->pixmapFor(item, iconSize().height()), item);
else
insertItem( 0, item );
const QPixmap pixmap = KIconLoader::global()->loadMimeTypeIcon( item, KIconLoader::Desktop, iconSize().height() );
insertItem( 0, pixmap, item );
if ( wasCurrent )
setCurrentIndex( 0 );
@ -373,25 +367,6 @@ void KHistoryComboBox::slotReset()
d->myRotated = false;
}
void KHistoryComboBox::setPixmapProvider( KPixmapProvider *prov )
{
if ( d->myPixProvider == prov )
return;
delete d->myPixProvider;
d->myPixProvider = prov;
// re-insert all the items with/without pixmap
// I would prefer to use changeItem(), but that doesn't honor the pixmap
// when using an editable combobox (what we do)
if ( count() > 0 ) {
QStringList items( historyItems() );
clear();
insertItems( items );
}
}
void KHistoryComboBox::insertItems( const QStringList& items )
{
QStringList::ConstIterator it = items.constBegin();
@ -400,11 +375,8 @@ void KHistoryComboBox::insertItems( const QStringList& items )
while ( it != itEnd ) {
const QString item = *it;
if ( !item.isEmpty() ) { // only insert non-empty items
if ( d->myPixProvider )
addItem( d->myPixProvider->pixmapFor(item, iconSize().height()),
item );
else
addItem( item );
const QPixmap pixmap = KIconLoader::global()->loadMimeTypeIcon( item, KIconLoader::Desktop, iconSize().height() );
addItem( item );
}
++it;
}
@ -435,11 +407,6 @@ void KHistoryComboBox::slotSimulateActivated( const QString& text )
}
}
KPixmapProvider *KHistoryComboBox::pixmapProvider() const
{
return d->myPixProvider;
}
void KHistoryComboBox::reset()
{
slotReset();

View file

@ -24,8 +24,6 @@
#include <kcombobox.h>
class KPixmapProvider;
/**
* @short A combobox for offering a history and completion
*
@ -154,27 +152,6 @@ public:
*/
bool removeFromHistory( const QString& item );
/**
* Sets a pixmap provider, so that items in the combobox can have a pixmap.
* KPixmapProvider is just an abstract class with the one pure virtual
* method KPixmapProvider::pixmapFor(). This method is called whenever
* an item is added to the KHistoryComboBoxBox. Implement it to return your
* own custom pixmaps, or use the KUrlPixmapProvider from libkio,
* which uses KMimeType::pixmapForUrl to resolve icons.
*
* Set @p prov to 0L if you want to disable pixmaps. Default no pixmaps.
*
* @see pixmapProvider
*/
void setPixmapProvider( KPixmapProvider *prov );
/**
* @returns the current pixmap provider.
* @see setPixmapProvider
* @see KPixmapProvider
*/
KPixmapProvider * pixmapProvider() const;
/**
* Resets the current position of the up/down history. Call this
* when you manually call setCurrentItem() or clearEdit().
@ -228,12 +205,12 @@ protected:
virtual void wheelEvent( QWheelEvent *ev );
/**
* Inserts @p items into the combo, honoring pixmapProvider()
* Inserts @p items into the combo,
* Does not update the completionObject.
*
* Note: duplicatesEnabled() is not honored here.
*
* Called from setHistoryItems() and setPixmapProvider()
* Called from setHistoryItems()
*/
void insertItems( const QStringList& items );

View file

@ -47,7 +47,6 @@
#include <krecentdirs.h>
#include <ktoggleaction.h>
#include <kurlcompletion.h>
#include <kurlpixmapprovider.h>
#include <kdebug.h>
#include <kpropertiesdialog.h>
#include <kpushbutton.h>
@ -297,7 +296,6 @@ KDirSelectDialog::KDirSelectDialog(const KUrl &startDir, bool localOnly,
d->m_urlCombo->setLayoutDirection( Qt::LeftToRight );
d->m_urlCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength);
d->m_urlCombo->setTrapReturnKey( true );
d->m_urlCombo->setPixmapProvider( new KUrlPixmapProvider() );
KUrlCompletion *comp = new KUrlCompletion();
comp->setMode( KUrlCompletion::DirCompletion );
d->m_urlCombo->setCompletionObject( comp, true );

View file

@ -114,7 +114,6 @@ set(kiocore_STAT_SRCS
kio/kshellcompletion.cpp
kio/kurifilter.cpp
kio/kurlcompletion.cpp
kio/kurlpixmapprovider.cpp
kio/metainfojob.cpp
kio/netaccess.cpp
kio/paste.cpp
@ -413,7 +412,6 @@ install(
kio/kshellcompletion.h
kio/kurifilter.h
kio/kurlcompletion.h
kio/kurlpixmapprovider.h
kio/predicateproperties.h
kfile/kabstractfilemodule.h
kfile/kabstractfilewidget.h

View file

@ -1,43 +0,0 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@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 (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 "kurlpixmapprovider.h"
#include <kurl.h>
#include <kio/global.h>
KUrlPixmapProvider::KUrlPixmapProvider()
: d(0)
{
}
KUrlPixmapProvider::~KUrlPixmapProvider()
{
}
QPixmap KUrlPixmapProvider::pixmapFor( const QString& url, int size )
{
KUrl u;
if ( url.at(0) == '/' )
u.setPath( url );
else
u = url;
return KIO::pixmapForUrl( u, 0, KIconLoader::Desktop, size );
}

View file

@ -1,70 +0,0 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@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 (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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 KURLPIXMAPPROVIDER_H
#define KURLPIXMAPPROVIDER_H
#include <kio/kio_export.h>
#include <kpixmapprovider.h>
/**
* Implementation of KPixmapProvider.
*
* Uses KMimeType::pixmapForURL() to resolve icons.
*
* Instatiate this class and supply it to the desired class, e.g.
* \code
* KHistoryCombo *combo = new KHistoryCombo( this );
* combo->setPixmapProvider( new KUrlPixmapProvider );
* [...]
* \endcode
*
* @short Resolves pixmaps for URLs
* @author Carsten Pfeiffer <pfeiffer@kde.org>
*/
class KIO_EXPORT KUrlPixmapProvider : public KPixmapProvider
{
public:
/**
* Creates a new url pixmap provider.
*/
KUrlPixmapProvider();
/**
* Destroys the url pixmap provider.
*/
~KUrlPixmapProvider();
/**
* Returns a pixmap for @p url with size @p size.
* Uses KMimeType::pixmapForURL().
* @param url the URL to fetch a pixmap for
* @param size the size of the pixmap in pixels, or 0 for default.
* @return the resulting pixmap
* @see KIconLoader::StdSizes
*/
virtual QPixmap pixmapFor( const QString& url, int size = 0 );
private:
class Private;
Private* const d;
};
#endif // KURLPIXMAPPROVIDER_H