diff --git a/src/lib/caching/kshareddatacache.h b/src/lib/caching/kshareddatacache.h index 42f4b6f..d4e29de 100644 --- a/src/lib/caching/kshareddatacache.h +++ b/src/lib/caching/kshareddatacache.h @@ -1,223 +1,226 @@ /* * This file is part of the KDE project. * Copyright © 2010 Michael Pyne * * 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 KSHAREDDATACACHE_H #define KSHAREDDATACACHE_H #include class QString; class QByteArray; /** * @class KSharedDataCache kshareddatacache.h KSharedDataCache * * @brief A simple data cache which uses shared memory to quickly access data * stored on disk. * * This class is meant to be used with KImageCache and similar classes but can * be used directly if used with care. * * Example usage: * * @code * QString loadTranslatedDocument(KSharedDataCache *cache) { * * // Find the data * QByteArray document; * * if (!cache->find("translated-doc-template", &document)) { * // Entry is not cached, manually generate and then add to cache. * document = translateDocument(globalTemplate()); * cache->insert(document); * } * * // Don't forget to encode/decode properly * return QString::fromUtf8(document); * } * @endcode * * @author Michael Pyne * @see KImageCache * @since 4.5 */ class KCOREADDONS_EXPORT KSharedDataCache { public: /** * Attaches to a shared cache, creating it if necessary. If supported, this * data cache will be shared across all processes using this cache (with * subsequent memory savings). If shared memory is unsupported or a * failure occurs, caching will still be supported, but only in the same * process, and only using the same KSharedDataCache object. * * @param cacheName Name of the cache to use/share. * @param defaultCacheSize Amount of data to be able to store, in bytes. The * actual size will be slightly larger on disk due to accounting * overhead. If the cache already existed then it will not be * resized. For this reason you should specify some reasonable size. * @param expectedItemSize The average size of an item that would be stored * in the cache, in bytes. Choosing an average size of zero bytes causes * KSharedDataCache to use whatever it feels is the best default for the * system. */ KSharedDataCache(const QString &cacheName, unsigned defaultCacheSize, unsigned expectedItemSize = 0); ~KSharedDataCache(); + KSharedDataCache(const KSharedDataCache &) = delete; + KSharedDataCache &operator=(const KSharedDataCache &) = delete; + enum EvictionPolicy { // The default value for data in our shared memory will be 0, so it is // important that whatever we want for the default value is also 0. NoEvictionPreference = 0, EvictLeastRecentlyUsed, EvictLeastOftenUsed, EvictOldest }; /** * @return The removal policy in use by the shared cache. * @see EvictionPolicy */ EvictionPolicy evictionPolicy() const; /** * Sets the entry removal policy for the shared cache to * @p newPolicy. The default is EvictionPolicy::NoEvictionPreference. * * @see EvictionPolicy */ void setEvictionPolicy(EvictionPolicy newPolicy); /** * Attempts to insert the entry @p data into the shared cache, named by * @p key, and returns true only if successful. * * Note that even if the insert was successful, that the newly added entry * may be evicted by other processes contending for the cache. */ bool insert(const QString &key, const QByteArray &data); /** * Returns the data in the cache named by @p key (even if it's some other * process's data named with the same key!), stored in @p destination. If there is * no entry named by @p key then @p destination is left unchanged. The return value * is used to tell what happened. * * If you simply want to verify whether an entry is present in the cache then * see contains(). * * @param key The key to find in the cache. * @param destination Is set to the value of @p key in the cache if @p key is * present, left unchanged otherwise. * @return true if @p key was present in the cache (@p destination will also be * updated), false if @p key was not present (@p destination will be * unchanged). */ bool find(const QString &key, QByteArray *destination) const; /** * Removes all entries from the cache. */ void clear(); /** * Removes the underlying file from the cache. Note that this is *all* that this * function does. The shared memory segment is still attached and will still contain * all the data until all processes currently attached remove the mapping. * * In order to remove the data see clear(). */ static void deleteCache(const QString &cacheName); /** * Returns true if the cache currently contains the image for the given * filename. * * NOTE: Calling this function is threadsafe, but it is in general not * possible to guarantee the image stays cached immediately afterwards, * so if you need the result use find(). */ bool contains(const QString &key) const; /** * Returns the usable cache size in bytes. The actual amount of memory * used will be slightly larger than this to account for required * accounting overhead. */ unsigned totalSize() const; /** * Returns the amount of free space in the cache, in bytes. Due to * implementation details it is possible to still not be able to fit an * entry in the cache at any given time even if it is smaller than the * amount of space remaining. */ unsigned freeSize() const; /** * @return The shared timestamp of the cache. The interpretation of the * timestamp returned is up to the application. KSharedDataCache * will initialize the timestamp to the time returned by @c time(2) * on cache creation, but KSharedDataCache will not touch the * timestamp again. * @see setTimestamp() * @since 4.6 */ unsigned timestamp() const; /** * Sets the shared timestamp of the cache. Timestamping is supported to * allow applications to more effectively "version" the data stored in the * cache. However, the timestamp is shared with all applications * using the cache so you should always be prepared for invalid * timestamps. * * When the cache is first created (note that this is different from * attaching to an existing shared cache on disk), the cache timestamp is * initialized to the time returned by @c time(2). KSharedDataCache will * not update the timestamp again, it is only updated through this method. * * Example: * @code * QImage loadCachedImage(const QString &key) * { * // Check timestamp * if (m_sharedCache->timestamp() < m_currentThemeTimestamp) { * // Cache is stale, clean it out. * m_sharedCache->clear(); * m_sharedCache->setTimestamp(m_currentThemeTimestamp); * } * * // Check cache and load image as usual... * } * @endcode * * @param newTimestamp The new timestamp to mark the shared cache with. * @see timestamp() * @since 4.6 */ void setTimestamp(unsigned newTimestamp); private: class Private; Private *d; }; #endif diff --git a/src/lib/util/kdelibs4configmigrator.h b/src/lib/util/kdelibs4configmigrator.h index 72fcb0d..aa58f8f 100644 --- a/src/lib/util/kdelibs4configmigrator.h +++ b/src/lib/util/kdelibs4configmigrator.h @@ -1,86 +1,89 @@ /* This file is part of the KDE Frameworks Copyright 2014 Montel Laurent This library 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 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 KDELIBS4CONFIGMIGRATOR_H #define KDELIBS4CONFIGMIGRATOR_H #include #include /** * @class Kdelibs4ConfigMigrator kdelibs4configmigrator.h Kdelibs4ConfigMigrator * * Kdelibs4ConfigMigrator migrates selected config files and ui files * from the kdelibs 4.x location ($KDEHOME, as used by KStandardDirs) * to the Qt 5.x location ($XDG_*_HOME, as used by QStandardPaths). * * @short Class for migration of config files and ui file from kdelibs4. * @since 5.2 */ class KCOREADDONS_EXPORT Kdelibs4ConfigMigrator { public: /** * Constructs a Kdelibs4ConfigMigrator * * @param appName The application name, which is used for the directory * containing the .ui files. */ explicit Kdelibs4ConfigMigrator(const QString &appName); /** * Destructor */ ~Kdelibs4ConfigMigrator(); + Kdelibs4ConfigMigrator(const Kdelibs4ConfigMigrator &) = delete; + Kdelibs4ConfigMigrator &operator=(const Kdelibs4ConfigMigrator &) = delete; + /** * Migrate the files, if any. * * Returns true if the migration happened. * It will return false if there was nothing to migrate (no KDEHOME). * This return value is unrelated to error handling. It is just a way to skip anything else * related to migration on a clean system, by writing * @code * if (migrate()) { * look for old data to migrate as well * } * @endcode */ bool migrate(); /** * Set the list of config files that need to be migrated. * @param configFileNameList list of config files */ void setConfigFiles(const QStringList &configFileNameList); /** * Set the list of ui files to migrate. * @param uiFileNameList list of ui files */ void setUiFiles(const QStringList &uiFileNameList); private: class Private; friend class Private; Private *const d; }; #endif // KDELIBS4CONFIGMIGRATOR_H diff --git a/src/lib/util/kdelibs4migration.h b/src/lib/util/kdelibs4migration.h index bc53ef3..2279383 100644 --- a/src/lib/util/kdelibs4migration.h +++ b/src/lib/util/kdelibs4migration.h @@ -1,117 +1,120 @@ /* This file is part of the KDE Frameworks Copyright 2014 David Faure Copyright 2014 Ivan Cukic This library 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 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 KDELIBS4MIGRATION_H #define KDELIBS4MIGRATION_H #include #include class Kdelibs4MigrationPrivate; /** * \file kdelibs4migration.h */ /** * @class Kdelibs4Migration kdelibs4migration.h Kdelibs4Migration * * Kdelibs4Migration provides support for locating config files * and application data files saved by kdelibs 4 in the user's home directory * ($KDEHOME, i.e. typically ~/.kde). * * Distributions that built kdelibs4 with a custom KDE home with * the CMake option _KDE_DEFAULT_HOME_POSTFIX should use the same option * here with _KDE4_DEFAULT_HOME_POSTFIX * * The purpose is to be able to let the application migrate these files * to the KF5/Qt5 location for these files (QStandardPaths). * * Files from the "config" resource (as saved by KConfig) should be migrated to * QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) * * Files from the "data" resource should be migrated to a subdirectory of * QStandardPaths::writableLocation(QStandardPaths::DataLocation) * * The following resources are supported:
  • config
  • data
  • services
  • servicetypes
  • wallpaper
  • emoticons
  • templates
* Use kdeHome() for anything else. * * @short Class for migration of config files from kdelibs4 * @since 5.0 */ class KCOREADDONS_EXPORT Kdelibs4Migration Q_DECL_FINAL { public: /** * Constructs a Kdelibs4Migration instance. * The constructor attempts to locate the user's "kdehome" from kdelibs4. */ explicit Kdelibs4Migration(); /** * Destructor */ ~Kdelibs4Migration(); + Kdelibs4Migration(const Kdelibs4Migration &) = delete; + Kdelibs4Migration &operator=(const Kdelibs4Migration &) = delete; + /** * Returns true if a "kdehome" was found. * Otherwise, there is nothing to migrate. */ bool kdeHomeFound() const; /** * Returns the kdehome that was found. * Don't use this method if you can use locateLocal or saveLocation * @since 5.13 */ QString kdeHome() const; /** * Finds a local file in a resource. * This API is inspired by KStandardDirs::locateLocal for ease of porting. * @param type The type of wanted resource. * @param filename A relative filename of the resource. */ QString locateLocal(const char *type, const QString &filename) const; /** * Finds a location to save files into for the given type * in the user's home directory. * @param type The type of location to return. * @param suffix A subdirectory name. */ QString saveLocation(const char *type, const QString &suffix = QString()) const; private: Kdelibs4MigrationPrivate *d; }; #endif // KFORMAT_H