Commit 42a7a211 authored by Halla Rempt's avatar Halla Rempt

BUG:352149 Sanitize the order of resource and tag loading

This now loads the bundles at the end of loading all resources.
parent 6c02b9dd
add_subdirectory( tests )
set(kritaresourcemanager_SOURCES set(kritaresourcemanager_SOURCES
resourcemanager.cpp resourcemanager.cpp
resourcebundle_manifest.cpp
resourcebundle.cpp
dlg_create_bundle.cpp dlg_create_bundle.cpp
dlg_bundle_manager.cpp dlg_bundle_manager.cpp
) )
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <kis_icon.h> #include <kis_icon.h>
#include "kis_action.h" #include "kis_action.h"
#include <kis_resource_server_provider.h>
#define ICON_SIZE 48 #define ICON_SIZE 48
...@@ -82,14 +83,14 @@ DlgBundleManager::DlgBundleManager(KisActionManager* actionMgr, QWidget *parent) ...@@ -82,14 +83,14 @@ DlgBundleManager::DlgBundleManager(KisActionManager* actionMgr, QWidget *parent)
void DlgBundleManager::refreshListData() void DlgBundleManager::refreshListData()
{ {
KoResourceServer<ResourceBundle> *bundleServer = ResourceBundleServerProvider::instance()->resourceBundleServer(); KoResourceServer<KisResourceBundle> *bundleServer = KisResourceServerProvider::instance()->resourceBundleServer();
m_ui->listInactive->clear(); m_ui->listInactive->clear();
m_ui->listActive->clear(); m_ui->listActive->clear();
Q_FOREACH (const QString &f, bundleServer->blackListedFiles()) { Q_FOREACH (const QString &f, bundleServer->blackListedFiles()) {
ResourceBundle *bundle = new ResourceBundle(f); KisResourceBundle *bundle = new KisResourceBundle(f);
bundle->load(); bundle->load();
if (bundle->valid()) { if (bundle->valid()) {
bundle->setInstalled(false); bundle->setInstalled(false);
...@@ -98,7 +99,7 @@ void DlgBundleManager::refreshListData() ...@@ -98,7 +99,7 @@ void DlgBundleManager::refreshListData()
} }
fillListWidget(m_blacklistedBundles.values(), m_ui->listInactive); fillListWidget(m_blacklistedBundles.values(), m_ui->listInactive);
Q_FOREACH (ResourceBundle *bundle, bundleServer->resources()) { Q_FOREACH (KisResourceBundle *bundle, bundleServer->resources()) {
if (bundle->valid()) { if (bundle->valid()) {
m_activeBundles[bundle->filename()] = bundle; m_activeBundles[bundle->filename()] = bundle;
} }
...@@ -108,19 +109,19 @@ void DlgBundleManager::refreshListData() ...@@ -108,19 +109,19 @@ void DlgBundleManager::refreshListData()
void DlgBundleManager::accept() void DlgBundleManager::accept()
{ {
KoResourceServer<ResourceBundle> *bundleServer = ResourceBundleServerProvider::instance()->resourceBundleServer(); KoResourceServer<KisResourceBundle> *bundleServer = KisResourceServerProvider::instance()->resourceBundleServer();
for (int i = 0; i < m_ui->listActive->count(); ++i) { for (int i = 0; i < m_ui->listActive->count(); ++i) {
QListWidgetItem *item = m_ui->listActive->item(i); QListWidgetItem *item = m_ui->listActive->item(i);
QByteArray ba = item->data(Qt::UserRole).toByteArray(); QByteArray ba = item->data(Qt::UserRole).toByteArray();
ResourceBundle *bundle = bundleServer->resourceByMD5(ba); KisResourceBundle *bundle = bundleServer->resourceByMD5(ba);
QMessageBox bundleFeedback; QMessageBox bundleFeedback;
bundleFeedback.setIcon(QMessageBox::Warning); bundleFeedback.setIcon(QMessageBox::Warning);
QString feedback = "bundlefeedback"; QString feedback = "bundlefeedback";
if (!bundle) { if (!bundle) {
// Get it from the blacklisted bundles // Get it from the blacklisted bundles
Q_FOREACH (ResourceBundle *b2, m_blacklistedBundles.values()) { Q_FOREACH (KisResourceBundle *b2, m_blacklistedBundles.values()) {
if (b2->md5() == ba) { if (b2->md5() == ba) {
bundle = b2; bundle = b2;
break; break;
...@@ -160,7 +161,7 @@ void DlgBundleManager::accept() ...@@ -160,7 +161,7 @@ void DlgBundleManager::accept()
for (int i = 0; i < m_ui->listInactive->count(); ++i) { for (int i = 0; i < m_ui->listInactive->count(); ++i) {
QListWidgetItem *item = m_ui->listInactive->item(i); QListWidgetItem *item = m_ui->listInactive->item(i);
QByteArray ba = item->data(Qt::UserRole).toByteArray(); QByteArray ba = item->data(Qt::UserRole).toByteArray();
ResourceBundle *bundle = bundleServer->resourceByMD5(ba); KisResourceBundle *bundle = bundleServer->resourceByMD5(ba);
if (bundle && bundle->isInstalled()) { if (bundle && bundle->isInstalled()) {
bundle->uninstall(); bundle->uninstall();
...@@ -207,12 +208,12 @@ void DlgBundleManager::itemSelected(QListWidgetItem *current, QListWidgetItem *) ...@@ -207,12 +208,12 @@ void DlgBundleManager::itemSelected(QListWidgetItem *current, QListWidgetItem *)
else { else {
QByteArray ba = current->data(Qt::UserRole).toByteArray(); QByteArray ba = current->data(Qt::UserRole).toByteArray();
KoResourceServer<ResourceBundle> *bundleServer = ResourceBundleServerProvider::instance()->resourceBundleServer(); KoResourceServer<KisResourceBundle> *bundleServer = KisResourceServerProvider::instance()->resourceBundleServer();
ResourceBundle *bundle = bundleServer->resourceByMD5(ba); KisResourceBundle *bundle = bundleServer->resourceByMD5(ba);
if (!bundle) { if (!bundle) {
// Get it from the blacklisted bundles // Get it from the blacklisted bundles
Q_FOREACH (ResourceBundle *b2, m_blacklistedBundles.values()) { Q_FOREACH (KisResourceBundle *b2, m_blacklistedBundles.values()) {
if (b2->md5() == ba) { if (b2->md5() == ba) {
bundle = b2; bundle = b2;
break; break;
...@@ -291,12 +292,12 @@ void DlgBundleManager::editBundle() ...@@ -291,12 +292,12 @@ void DlgBundleManager::editBundle()
} }
} }
void DlgBundleManager::fillListWidget(QList<ResourceBundle *> bundles, QListWidget *w) void DlgBundleManager::fillListWidget(QList<KisResourceBundle *> bundles, QListWidget *w)
{ {
w->setIconSize(QSize(ICON_SIZE, ICON_SIZE)); w->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
w->setSelectionMode(QAbstractItemView::MultiSelection); w->setSelectionMode(QAbstractItemView::MultiSelection);
Q_FOREACH (ResourceBundle *bundle, bundles) { Q_FOREACH (KisResourceBundle *bundle, bundles) {
QPixmap pixmap(ICON_SIZE, ICON_SIZE); QPixmap pixmap(ICON_SIZE, ICON_SIZE);
if (!bundle->image().isNull()) { if (!bundle->image().isNull()) {
QImage scaled = bundle->image().scaled(ICON_SIZE, ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation); QImage scaled = bundle->image().scaled(ICON_SIZE, ICON_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <KoDialog.h> #include <KoDialog.h>
#include "kis_action_manager.h" #include "kis_action_manager.h"
class ResourceBundle; class KisResourceBundle;
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
...@@ -57,13 +57,13 @@ private: ...@@ -57,13 +57,13 @@ private:
QWidget *m_page; QWidget *m_page;
Ui::WdgDlgBundleManager *m_ui; Ui::WdgDlgBundleManager *m_ui;
void fillListWidget(QList<ResourceBundle*> bundles, QListWidget *w); void fillListWidget(QList<KisResourceBundle*> bundles, QListWidget *w);
void refreshListData(); void refreshListData();
QMap<QString, ResourceBundle*> m_blacklistedBundles; QMap<QString, KisResourceBundle*> m_blacklistedBundles;
QMap<QString, ResourceBundle*> m_activeBundles; QMap<QString, KisResourceBundle*> m_activeBundles;
ResourceBundle *m_currentBundle; KisResourceBundle *m_currentBundle;
KisActionManager* m_actionManager; KisActionManager* m_actionManager;
}; };
......
...@@ -43,11 +43,11 @@ ...@@ -43,11 +43,11 @@
#include <kis_config.h> #include <kis_config.h>
#include "resourcebundle.h" #include "KisResourceBundle.h"
#define ICON_SIZE 48 #define ICON_SIZE 48
DlgCreateBundle::DlgCreateBundle(ResourceBundle *bundle, QWidget *parent) DlgCreateBundle::DlgCreateBundle(KisResourceBundle *bundle, QWidget *parent)
: KoDialog(parent) : KoDialog(parent)
, m_ui(new Ui::WdgDlgCreateBundle) , m_ui(new Ui::WdgDlgCreateBundle)
, m_bundle(bundle) , m_bundle(bundle)
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <KoDialog.h> #include <KoDialog.h>
class ResourceBundle; class KisResourceBundle;
namespace Ui namespace Ui
{ {
...@@ -33,7 +33,7 @@ class DlgCreateBundle : public KoDialog ...@@ -33,7 +33,7 @@ class DlgCreateBundle : public KoDialog
Q_OBJECT Q_OBJECT
public: public:
explicit DlgCreateBundle(ResourceBundle *bundle = 0, QWidget *parent = 0); explicit DlgCreateBundle(KisResourceBundle *bundle = 0, QWidget *parent = 0);
~DlgCreateBundle(); ~DlgCreateBundle();
QString bundleName() const; QString bundleName() const;
...@@ -74,7 +74,7 @@ private: ...@@ -74,7 +74,7 @@ private:
QString m_previewImage; QString m_previewImage;
ResourceBundle *m_bundle; KisResourceBundle *m_bundle;
}; };
#endif // KOBUNDLECREATIONWIDGET_H #endif // KOBUNDLECREATIONWIDGET_H
...@@ -48,40 +48,11 @@ ...@@ -48,40 +48,11 @@
#include "dlg_bundle_manager.h" #include "dlg_bundle_manager.h"
#include "dlg_create_bundle.h" #include "dlg_create_bundle.h"
Q_GLOBAL_STATIC(ResourceBundleServerProvider, s_instance)
ResourceBundleServerProvider::ResourceBundleServerProvider()
{
// user-local
m_resourceBundleServer = new KoResourceServerSimpleConstruction<ResourceBundle>("kis_resourcebundles", "*.bundle");
if (!QFileInfo(m_resourceBundleServer->saveLocation()).exists()) {
QDir().mkpath(m_resourceBundleServer->saveLocation());
}
}
ResourceBundleServerProvider *ResourceBundleServerProvider::instance()
{
return s_instance;
}
ResourceBundleServerProvider::~ResourceBundleServerProvider()
{
delete m_resourceBundleServer;
}
KoResourceServer<ResourceBundle> *ResourceBundleServerProvider::resourceBundleServer()
{
return m_resourceBundleServer;
}
class ResourceManager::Private { class ResourceManager::Private {
public: public:
Private() Private()
: loader(0)
{ {
brushServer = KisBrushServer::instance()->brushServer(false); brushServer = KisBrushServer::instance()->brushServer(false);
paintopServer = KisResourceServerProvider::instance()->paintOpPresetServer(false); paintopServer = KisResourceServerProvider::instance()->paintOpPresetServer(false);
...@@ -98,8 +69,6 @@ public: ...@@ -98,8 +69,6 @@ public:
KoResourceServer<KoColorSet>* paletteServer; KoResourceServer<KoColorSet>* paletteServer;
KoResourceServer<KisWorkspaceResource>* workspaceServer; KoResourceServer<KisWorkspaceResource>* workspaceServer;
QThread *loader;
}; };
K_PLUGIN_FACTORY_WITH_JSON(ResourceManagerFactory, "kritaresourcemanager.json", registerPlugin<ResourceManager>();) K_PLUGIN_FACTORY_WITH_JSON(ResourceManagerFactory, "kritaresourcemanager.json", registerPlugin<ResourceManager>();)
...@@ -184,7 +153,7 @@ void ResourceManager::slotImport() ...@@ -184,7 +153,7 @@ void ResourceManager::slotImport()
} }
else if (resourceType == "bundles") { else if (resourceType == "bundles") {
Q_FOREACH (const QString &res, resources) { Q_FOREACH (const QString &res, resources) {
ResourceBundle *bundle = ResourceBundleServerProvider::instance()->resourceBundleServer()->createResource(res); KisResourceBundle *bundle = KisResourceServerProvider::instance()->resourceBundleServer()->createResource(res);
bundle->load(); bundle->load();
if (bundle->valid()) { if (bundle->valid()) {
if (!bundle->install()) { if (!bundle->install()) {
...@@ -196,17 +165,17 @@ void ResourceManager::slotImport() ...@@ -196,17 +165,17 @@ void ResourceManager::slotImport()
} }
QFileInfo fi(res); QFileInfo fi(res);
QString newFilename = ResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + bundle->defaultFileExtension(); QString newFilename = KisResourceServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + bundle->defaultFileExtension();
QFileInfo fileInfo(newFilename); QFileInfo fileInfo(newFilename);
int i = 1; int i = 1;
while (fileInfo.exists()) { while (fileInfo.exists()) {
fileInfo.setFile(ResourceBundleServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + QString("%1").arg(i) + bundle->defaultFileExtension()); fileInfo.setFile(KisResourceServerProvider::instance()->resourceBundleServer()->saveLocation() + fi.baseName() + QString("%1").arg(i) + bundle->defaultFileExtension());
i++; i++;
} }
bundle->setFilename(fileInfo.filePath()); bundle->setFilename(fileInfo.filePath());
QFile::copy(res, newFilename); QFile::copy(res, newFilename);
ResourceBundleServerProvider::instance()->resourceBundleServer()->addResource(bundle, false); KisResourceServerProvider::instance()->resourceBundleServer()->addResource(bundle, false);
} }
} }
else if (resourceType == "patterns") { else if (resourceType == "patterns") {
...@@ -238,7 +207,7 @@ void ResourceManager::slotCreateBundle() ...@@ -238,7 +207,7 @@ void ResourceManager::slotCreateBundle()
} }
QString bundlePath = dlgCreateBundle.saveLocation() + "/" + dlgCreateBundle.bundleName() + ".bundle"; QString bundlePath = dlgCreateBundle.saveLocation() + "/" + dlgCreateBundle.bundleName() + ".bundle";
ResourceBundle* newBundle = new ResourceBundle(bundlePath); KisResourceBundle* newBundle = new KisResourceBundle(bundlePath);
newBundle->addMeta("name", dlgCreateBundle.bundleName()); newBundle->addMeta("name", dlgCreateBundle.bundleName());
newBundle->addMeta("author", dlgCreateBundle.authorName()); newBundle->addMeta("author", dlgCreateBundle.authorName());
...@@ -307,26 +276,5 @@ void ResourceManager::slotManageBundles() ...@@ -307,26 +276,5 @@ void ResourceManager::slotManageBundles()
} }
void ResourceManager::loadBundles()
{
d->loader = new KoResourceLoaderThread(ResourceBundleServerProvider::instance()->resourceBundleServer());
connect(d->loader, SIGNAL(finished()), this, SLOT(bundlesLoaded()));
d->loader->start();
}
void ResourceManager::bundlesLoaded()
{
delete d->loader;
d->loader = 0;
Q_FOREACH (ResourceBundle *bundle, ResourceBundleServerProvider::instance()->resourceBundleServer()->resources()) {
if (!bundle->install()) {
warnKrita << "Could not install resources for bundle" << bundle->name();
}
}
}
#include "resourcemanager.moc" #include "resourcemanager.moc"
...@@ -22,26 +22,10 @@ ...@@ -22,26 +22,10 @@
#include <QVariant> #include <QVariant>
#include <KoResourceServer.h> #include <KoResourceServer.h>
#
#include <kis_view_plugin.h> #include <kis_view_plugin.h>
#include "resourcebundle.h" #include "KisResourceBundle.h"
class ResourceBundleServerProvider {
public:
static ResourceBundleServerProvider *instance();
ResourceBundleServerProvider();
~ResourceBundleServerProvider();
KoResourceServer<ResourceBundle> *resourceBundleServer();
private:
KoResourceServer<ResourceBundle> *m_resourceBundleServer;
Q_DISABLE_COPY(ResourceBundleServerProvider)
};
class ResourceManager : public KisViewPlugin class ResourceManager : public KisViewPlugin
{ {
...@@ -54,8 +38,7 @@ private Q_SLOTS: ...@@ -54,8 +38,7 @@ private Q_SLOTS:
void slotImport(); void slotImport();
void slotCreateBundle(); void slotCreateBundle();
void slotManageBundles(); void slotManageBundles();
void loadBundles();
void bundlesLoaded();
private: private:
class Private; class Private;
Private *const d; Private *const d;
......
...@@ -331,6 +331,8 @@ set(kritaui_LIB_SRCS ...@@ -331,6 +331,8 @@ set(kritaui_LIB_SRCS
qtsingleapplication/qtlocalpeer.cpp qtsingleapplication/qtlocalpeer.cpp
qtsingleapplication/qtsingleapplication.cpp qtsingleapplication/qtsingleapplication.cpp
KisResourceBundle.cpp
KisResourceBundleManifest.cpp
kis_md5_generator.cpp kis_md5_generator.cpp
KisApplicationArguments.cpp KisApplicationArguments.cpp
......
...@@ -290,6 +290,7 @@ void loadResources() ...@@ -290,6 +290,7 @@ void loadResources()
KisBrushServer::instance()->brushServer(true); KisBrushServer::instance()->brushServer(true);
// load paintop presets // load paintop presets
KisResourceServerProvider::instance()->paintOpPresetServer(true); KisResourceServerProvider::instance()->paintOpPresetServer(true);
KisResourceServerProvider::instance()->resourceBundleServer();
} }
void loadPlugins() void loadPlugins()
......
This diff is collapsed.
/*
* Copyright (c) 2014 Victor Lafon metabolic.ewilan@hotmail.fr
*
* 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 KORESOURCEBUNDLE_H
#define KORESOURCEBUNDLE_H
#include <QSet>
#include <QList>
#include <KoXmlWriter.h>
#include "KoResource.h"
#include "KisResourceBundleManifest.h"
#include "kritaui_export.h"
class KoStore;
/**
* @brief The ResourceBundle class
* @details Describe the resource bundles as KoResources
*/
class KRITAUI_EXPORT KisResourceBundle : public KoResource
{
public:
/**
* @brief ResourceBundle : Ctor * @param bundlePath the path of the bundle
*/
KisResourceBundle(QString const& fileName);
/**
* @brief ~ResourceBundle : Dtor
*/
virtual ~KisResourceBundle();
/**
* @brief defaultFileExtension
* @return the default file extension which should be when saving the resource
*/
QString defaultFileExtension() const;
/**
* @brief load : Load this resource.
* @return true if succeed, false otherwise.
*/
bool load();
virtual bool loadFromDevice(QIODevice *dev);
/**
* @brief save : Save this resource.
* @return true if succeed, false otherwise.
*/
bool save();
virtual bool saveToDevice(QIODevice* dev) const;
/**
* @brief install : Install the contents of the resource bundle.
*/
bool install();
/**
* @brief uninstall : Uninstall the resource bundle.
*/
bool uninstall();
/**
* @brief addMeta : Add a Metadata to the resource
* @param type type of the metadata
* @param value value of the metadata
*/
void addMeta(const QString &type, const QString &value);
const QString getMeta(const QString &type, const QString &defaultValue = QString()) const;
/**
* @brief addFile : Add a file to the bundle
* @param fileType type of the resource file
* @param filePath path of the resource file
*/
void addResource(QString fileType, QString filePath, QStringList fileTagList, const QByteArray md5sum);
QList<QString> getTagsList();
/**
* @brief isInstalled
* @return true if the bundle is installed, false otherwise.
*/
bool isInstalled();
/**
* @brief setInstalled
* This allows you to set installed or uninstalled upon loading. This is used with blacklists.
*/
void setInstalled(bool install);
void setThumbnail(QString);
/**
* @brief saveMetadata: saves bundle metadata