LibResource Class Overview
Open, HighPublic

Description

LibResource

ResourceLoader

ResourceLoaderRegistry

The resource loader is an abstract api class that know hows to load a specific resource and give information to the cache database about that resource. The registry is a singleton where loaders for each supported resource are added.

Resource

VersionedResource
    Resources

ResourceStorage
    ::Bundle
    ::ABR
    ::ASL
    ::Folder
    Resources

ResourceLocator
    ResourceStorages
    VersionedResources
    ResourceCacheDb

Tag

ResourceModel::QAbstractItemModel
    Resources

TagModel::QAbstractItemModel
    Tags

ResourceCacheDb
    ResourceModel
    TagModel

The ResourceCacheDb object is created and owned by KisApplication. All public functions can be static because the underlying database object is shared application wide (this is because of the way QtSql has been designed).

rempt created this task.May 22 2018, 11:22 AM
rempt triaged this task as High priority.
rempt updated the task description. (Show Details)May 30 2018, 12:36 PM
rempt added a comment.May 30 2018, 1:12 PM

Notes about the cache database:

  • It is a cache, but the user-created links between tags and resources exist only in the database. We cannot drop the database and recreate it based on what is in the resources folder, unless we back-up the tag links in an external file.

Logic for creating/recreating the database:

  • There is no database yet: create the database
  • There is a database: open and verify the version. If the version is too low, migration is needed
  • There is a database, but not all tables are present: migration is needed
  • There is a database, but not entries in the lookup tables are present: migration is needed.

What do we do when we remove an entry from a lookup table -- remove a resource type?

rempt updated the task description. (Show Details)May 30 2018, 1:24 PM
rempt updated the task description. (Show Details)May 31 2018, 8:13 AM
rempt updated the task description. (Show Details)Jun 6 2018, 9:23 AM
rempt updated the task description. (Show Details)Jun 6 2018, 9:44 AM
rempt added a comment.Jun 7 2018, 8:56 AM

Notes about the lifecycle of the resource system

  1. Startup
  • On application startup, the KisResourceLoader instances are registered with the KisResourceLoaderRegistry singleton.
  • The cache database is opened. KisResourceCacheDb is accessible from this point
  • The KisResourceLocator singleton is created
  • KisResourceLocator will make a list of all available KisResourceStorages in the configured directory.
  • KisResourceLocator will ask the database to synchronize itself.
  1. Synchronization
  1. we discover there are no resources in any of the listed storages. -> this means that we need to reinstall the default resources that come with Krita
  1. we discover new resources -> we will add them to the database
  1. we discover a resource has changed (date has changed, md5 sum has changed) -> we will add a new version to the database
  1. we discover a resource has disappeared -> we will remove the resource from the database (but keep the version history and mark the brush as deleted? Do we need to make a difference between deleted from disk, deleted from the ui, deleted by updating krita)
  1. we discover new tags.
  1. Runtime
  • From now on resources can be retrieved.
  • KisResourceModel and KisTagModel provide a view of all resources as cached in the database.
  • If the user selects an item from the KisResourceModel, the resource will be loaded using KisResourceLoader and returned. KisResourceLocator will cache X resources of each type.
  • If the user changes the place where storages are located, KisResourceLocator will ask the database to re-synchronize.
  • Q: will we use QFileSystemWatcher to trigger a re-synch if a resource is copied or removed into or from the storage location? A: No idea yet.
  • If the user removes a resource using the gui, the database will be updated. The flag deleted will be set on the last versioned resource.
  • If the user creates a resource or adds it through the resource manager, the database will be updated. A new resource will be inserted.
  • If the user modifies a resource, a new version will be created on disk and in the database
  • If the user tags a resource, the database will be updated
  • If the user untags a resource, the database will be updated
  • If the user removes a tag using the gui, the database will be updated and the flag active will be set to false
  • If the user removes a tag from disk...
  1. Shutdown
  • ...
rempt added a comment.Jun 8 2018, 8:36 AM

Note about first installation:

I first thought that checking whether the resource location was empty would be a good idea to figure out whether a first-time install of krita's default resources would be needed, but this would break on updating an existing installation to the first version with the new resource system.