Commit 9c8b6716 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Load the resources and tags from bundles into the database

parent 6f7ad142
......@@ -5,13 +5,13 @@ b\)_Basic-5_Size_default.kpp
DESTINATION ${DATA_INSTALL_DIR}/krita/paintoppresets)
install( FILES
"* Favorites.desktop"
"Pixel Art.desktop"
Digital.desktop
Erasers.desktop
FX.desktop
Ink.desktop
Paint.desktop
Sketch.desktop
Textures.desktop
"* Favorites.tag"
"Pixel Art.tag"
Digital.tag
Erasers.tag
FX.tag
Ink.tag
Paint.tag
Sketch.tag
Textures.tag
DESTINATION ${DATA_INSTALL_DIR}/krita/paintoppresets)
......@@ -3,4 +3,4 @@ Type=Tag
Name=Digital
Comment=Brush presets with a digital look and feel.
URL=Digital
Default Resources=a)_Eraser_Circle.kpp,b)_Basic-5_Size_default.kpp
Default Resources=a)_Eraser_Circle,b)_Basic-5_Size
......@@ -3,4 +3,4 @@ Type=Tag
Name=Erasers
Comment=Eraser Brush Presets
URL=Erasers
Default Resources=a)_Eraser_Circle.kpp
Default Resources=a)_Eraser_Circle
......@@ -36,8 +36,8 @@ public:
, m_resourceType(resourceType)
{
QList<KoResourceBundleManifest::ResourceReference> resources = m_bundle->manifest().files(resourceType);
Q_FOREACH(KoResourceBundleManifest::ResourceReference resource, resources) {
Q_FOREACH(const QString &tagname, resource.tagList) {
Q_FOREACH(const KoResourceBundleManifest::ResourceReference &resourceReference, resources) {
Q_FOREACH(const QString &tagname, resourceReference.tagList) {
if (!m_tags.contains(tagname)){
KisTagSP tag = QSharedPointer<KisTag>(new KisTag());
tag->setName(tagname);
......@@ -45,7 +45,8 @@ public:
tag->setUrl(bundle->filename() + ':' + tagname);
m_tags[tagname] = tag;
}
m_tags[tagname]->setDefaultResources(m_tags[tagname]->defaultResources() << resource.resourcePath);
KoResourceSP resource = m_bundle->resource(resourceType, resourceReference.resourcePath);
m_tags[tagname]->setDefaultResources(m_tags[tagname]->defaultResources() << resource->name());
}
}
m_tagIterator.reset(new QListIterator<KisTagSP>(m_tags.values()));
......@@ -55,6 +56,7 @@ public:
{
return m_tagIterator->hasNext();
}
void next() const override
{
const_cast<BundleTagIterator*>(this)->m_tag = m_tagIterator->next();
......
......@@ -34,7 +34,7 @@ public:
, m_resourceType(resourceType)
{
m_dirIterator.reset(new QDirIterator(location + '/' + resourceType,
QStringList() << "*.desktop",
QStringList() << "*.tag",
QDir::Files | QDir::Readable,
QDirIterator::Subdirectories));
}
......
......@@ -246,7 +246,7 @@ bool KisResourceCacheDb::initialize(const QString &location)
return s_valid;
}
int KisResourceCacheDb::resourceIdForResource(const QString &resourceFileName, const QString &resourceType)
int KisResourceCacheDb::resourceIdForResource(const QString &resourceName, const QString &resourceType, const QString &storageLocation)
{
QFile f(":/select_resource_id.sql");
f.open(QFile::ReadOnly);
......@@ -256,9 +256,9 @@ int KisResourceCacheDb::resourceIdForResource(const QString &resourceFileName, c
return -1;
}
q.bindValue(":filename", resourceFileName);
q.bindValue(":name", resourceName);
q.bindValue(":resource_type", resourceType);
q.bindValue(":storage_location", storageLocation);
if (!q.exec()) {
qWarning() << "Could not query resourceIdForResource" << q.boundValues() << q.lastError();
return -1;
......@@ -348,7 +348,7 @@ bool KisResourceCacheDb::addResourceVersion(int resourceId, QDateTime timestamp,
", filename = :filename\n"
", tooltip = :tooltip\n"
", thumbnail = :thumbnail)\n"
"WHERE resourceId = :resourceId");
"WHERE resource_id = :resource_id");
if (!r) {
qWarning() << "Could not prepare updateResource statement" << q.lastError();
return r;
......@@ -390,7 +390,7 @@ bool KisResourceCacheDb::addResource(KisResourceStorageSP storage, QDateTime tim
}
// Check whether it already exists
int resourceId = resourceIdForResource(resource->filename(), resourceType);
int resourceId = resourceIdForResource(resource->name(), resourceType, storage->location());
if (resourceId > -1) {
if (resourceNeedsUpdating(resourceId, timestamp)) {
r = addResourceVersion(resourceId, timestamp, storage, resource);
......@@ -399,15 +399,16 @@ bool KisResourceCacheDb::addResource(KisResourceStorageSP storage, QDateTime tim
else {
QSqlQuery q;
r = q.prepare("INSERT INTO resources "
"(resource_type_id, name, filename, tooltip, thumbnail, status)"
"(storage_id, resource_type_id, name, filename, tooltip, thumbnail, status)"
"VALUES"
"((SELECT id FROM resource_types WHERE name = :resource_type), :name, :filename, :tooltip, :thumbnail, :status);");
"((SELECT id FROM storages WHERE location = :storage_location), (SELECT id FROM resource_types WHERE name = :resource_type), :name, :filename, :tooltip, :thumbnail, :status);");
if (!r) {
qWarning() << "Could not prepare addResource statement" << q.lastError();
return r;
}
q.bindValue(":storage_location", storage->location());
q.bindValue(":resource_type", resourceType);
q.bindValue(":name", resource->name());
q.bindValue(":filename", resource->filename());
......@@ -428,7 +429,7 @@ bool KisResourceCacheDb::addResource(KisResourceStorageSP storage, QDateTime tim
return r;
}
resourceId = resourceIdForResource(resource->filename(), resourceType);
resourceId = resourceIdForResource(resource->name(), resourceType, storage->location());
}
// Then add a new version
QSqlQuery q;
......@@ -483,10 +484,10 @@ bool KisResourceCacheDb::addResources(KisResourceStorageSP storage, QString reso
bool KisResourceCacheDb::tagResource(KisResourceStorageSP storage, const QString resourceName, KisTagSP tag, const QString &resourceType)
{
// Get resource id
int resourceId = resourceIdForResource(storage->location() + "/" + resourceType + "/" + resourceName, resourceType);
int resourceId = resourceIdForResource(resourceName, resourceType, storage->location());
if (resourceId < 0) {
qWarning() << "Could not find resource to tag" << storage->location() + "/" + resourceName << resourceType;
qWarning() << "Could not find resource to tag" << storage->location() << resourceName << resourceType;
return false;
}
......
......@@ -65,7 +65,7 @@ private:
~KisResourceCacheDb();
KisResourceCacheDb operator=(const KisResourceCacheDb&);
static int resourceIdForResource(const QString &filename, const QString &resourceType);
static int resourceIdForResource(const QString &resourceName, const QString &resourceType, const QString &storageLocation);
static bool resourceNeedsUpdating(int resourceId, QDateTime timestamp);
static bool addResourceVersion(int resourceId, QDateTime timestamp, KisResourceStorageSP storage, KoResourceSP resource);
static bool addResource(KisResourceStorageSP storage, QDateTime timestamp, KoResourceSP resource, const QString &resourceType);
......
......@@ -82,5 +82,6 @@ QStringList KisResourceLoaderRegistry::resourceTypes() const
}
r.removeDuplicates();
r.sort();
return r;
}
......@@ -131,7 +131,7 @@ QStringList KisResourceLocator::errorMessages() const
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(InitalizationStatus initalizationStatus, const QString &installationResourcesLocation)
{
qDebug() << "firstTimeInstallation" << installationResourcesLocation;
emit progressMessage(i18n("Krita is running for the first time. Intialization will take some time."));
Q_UNUSED(initalizationStatus);
Q_FOREACH(const QString &folder, KisResourceLoaderRegistry::instance()->resourceTypes()) {
......@@ -158,6 +158,19 @@ KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(Inita
}
}
// And add bundles and adobe libraries
QStringList filters = QStringList() << "*.bundle" << "*.abr" << "*.asl";
QDirIterator iter(installationResourcesLocation, filters, QDir::Files, QDirIterator::Subdirectories);
while (iter.hasNext()) {
iter.next();
emit progressMessage(i18n("Installing the resources from bundle %1.", iter.filePath()));
QFile f(iter.filePath());
Q_ASSERT(f.exists());
if (!f.copy(d->resourceLocation + '/' + iter.fileName())) {
d->errorMessages << i18n("Could not copy resource %1 to %2").arg(f.fileName()).arg(d->resourceLocation);
}
}
QFile f(d->resourceLocation + '/' + "KRITA_RESOURCE_VERSION");
f.open(QFile::WriteOnly);
f.write(KritaVersionWrapper::versionString().toUtf8());
......@@ -172,7 +185,7 @@ KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation(Inita
bool KisResourceLocator::initializeDb()
{
qDebug() << "initalizeDb";
emit progressMessage(i18n("Initalizing the resources."));
d->errorMessages.clear();
findStorages();
......@@ -183,7 +196,7 @@ bool KisResourceLocator::initializeDb()
}
Q_FOREACH(const QString &resourceType, KisResourceLoaderRegistry::instance()->resourceTypes()) {
qDebug() << "Adding storage" << storage->location() << "folder" << resourceType;
emit progressMessage(i18n("Adding %1 resources to folder %2", resourceType, storage->location()));
if (!KisResourceCacheDb::addResources(storage, resourceType)) {
d->errorMessages.append(i18n("Could not add resource type %1 to the cache database").arg(resourceType));
}
......@@ -193,9 +206,7 @@ bool KisResourceLocator::initializeDb()
}
}
qDebug() << d->errorMessages;
return true;
return (d->errorMessages.isEmpty());
}
void KisResourceLocator::findStorages()
......
......@@ -62,6 +62,10 @@ public:
QStringList errorMessages() const;
Q_SIGNALS:
void progressMessage(const QString&);
private:
friend class TestResourceLocator;
......
......@@ -43,6 +43,7 @@ public:
KisResourceStorage::KisResourceStorage(const QString &location)
: d(new Private())
{
qDebug() << "KisResourceStorage" << location;
d->location = location;
QFileInfo fi(d->location);
if (fi.isDir()) {
......
......@@ -522,6 +522,10 @@ KoResourceSP KoResourceBundle::resource(const QString &resourceType, const QStri
QString mime = KisMimeDatabase::mimeTypeForSuffix(filepath);
KisResourceLoaderBase *loader = KisResourceLoaderRegistry::instance()->loader(resourceType, mime);
if (!loader) {
qWarning() << "Could not create loader for" << resourceType << filepath << mime;
return 0;
}
KoResourceSP res = loader->load(filepath, *resourceStore->device());
resourceStore->close();
m_resourceCache[filepath] = res;
......
CREATE TABLE IF NOT EXISTS resources (
id INTEGER PRIMARY KEY
, resource_type_id INTEGER
, storage_id INTEGER
, name TEXT NOT NULL
, filename TEXT NOT NULL
, tooltip TEXT
, thumbnail BLOB
, status INTEGER
, FOREIGN KEY(resource_type_id) REFERENCES resource_types(id)
, UNIQUE(resource_type_id, name)
, UNIQUE(filename)
, UNIQUE(storage_id, resource_type_id, name)
, UNIQUE(storage_id, filename)
);
......@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS versioned_resources (
, timestamp INTEGER
, deleted INTEGER
, checksum TEXT
, uuid TEXT
, FOREIGN KEY(resource_id) REFERENCES resources(id)
, FOREIGN KEY(storage_id) REFERENCES storages(id)
);
SELECT resources.id
FROM resources
, resource_types
WHERE resource_type_id = resource_types.id
, storages
WHERE resources.resource_type_id = resource_types.id
AND storages.id = resources.storage_id
AND storages.location = :storage_location
AND resource_types.name = :resource_type
AND filename = :filename;
AND resources.name = :name
......@@ -323,6 +323,8 @@ bool KisApplication::loadResources()
Q_FOREACH(const QByteArray ba, src) {
allImageMimes << QString::fromUtf8(ba);
}
allImageMimes << KisMimeDatabase::mimeTypeForSuffix("pat");
reg->add(new KisResourceLoader<KoPattern>("patterns", "patterns", allImageMimes));
reg->add(new KisResourceLoader<KisWorkspaceResource>("workspaces", "workspaces", QStringList() << "application/x-krita-workspace"));
reg->add(new KisResourceLoader<KoSvgSymbolCollectionResource>("symbols", "symbols", QStringList() << "image/svg+xml"));
......@@ -335,6 +337,7 @@ bool KisApplication::loadResources()
}
KisResourceLocator::LocatorError r = KisResourceLocator::instance()->initialize(KoResourcePaths::getApplicationRoot() + "/share/krita");
connect(KisResourceLocator::instance(), SIGNAL(progressMessage(const QString&)), this, SLOT(setSplashScreenLoadingText(const QString&)));
if (r != KisResourceLocator::LocatorError::Ok ) {
QMessageBox::critical(0, i18nc("@title:window", "Krita: Fatal error"), KisResourceLocator::instance()->errorMessages().join('\n') + i18n("\n\nKrita will quit now."));
return false;
......@@ -648,10 +651,9 @@ void KisApplication::setSplashScreen(QWidget *splashScreen)
d->splashScreen = qobject_cast<KisSplashScreen*>(splashScreen);
}
void KisApplication::setSplashScreenLoadingText(QString textToLoad)
void KisApplication::setSplashScreenLoadingText(const QString &textToLoad)
{
if (d->splashScreen) {
//d->splashScreen->loadingLabel->setText(textToLoad);
d->splashScreen->setLoadingText(textToLoad);
d->splashScreen->repaint();
}
......
......@@ -88,9 +88,6 @@ public:
* to have the splash show correctly on Xinerama displays.
*/
void setSplashScreen(QWidget *splash);
void setSplashScreenLoadingText(QString);
void hideSplashScreen();
/// Overridden to handle exceptions from event handlers.
......@@ -107,6 +104,7 @@ public Q_SLOTS:
void remoteArguments(QByteArray message, QObject*socket);
void fileOpenRequested(const QString & url);
void setSplashScreenLoadingText(const QString&);
private:
/// @return the number of autosavefiles opened
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment