# Resource Rewrite Discussion Krita Mini-Sprint 2019-10-22 ##### Attendees: * Boudewijn Rempt * Wolthera van Hövell tot Westerflier * Dmitry Kazakov * Agata Cacko ## State of the rewrite * Technical details this morning. * All pieces have been started; no new classes are needed, but many parts don't yet work. ### DONE * copy over resources to the user's resources folder * initial creation of the database schema * initial filling of the database * folder storage class * tag loading from desktop files * updating the cache db with changes done directly on the resources folder * bundle storage class * Database explorer UI * models for integrating with the UI * implement dirty resources mechanism * Remove all hints that bundles are resources. * implement metadata mechanism for resources --> the KisResourceModel class has many unimplemented methods atm * Implement in-memory resources, that are deleted from the db when Krita starts (add to locator cache, set id on resource, add to database, update model) ### DOING * Implement KoResourceServer as a shim for KoResourceModel * fix loading the actual preset in the preset delegate ### TODO * **PLUGIN \[Agata\]** ASL storage class (Adobe Layer Style). Needs KisLayerStyleResource class. Needs good unittest. And ASL contains gradients, patterns and layerstyles. * Complexity: Simple * Time needed: 2-3 days, refactoring might take longer because the rest of krita isn't prepared to see layers styles as a resource. Lots of UI work. * **PLUGIN \[Agata\]** ABR storage class (Adobe Brush Library) * Complexity: Simple * Time needed: 2-3 days, probably no gui rework needed. * **UI \[wolthera\]** adding/updating/removing resources from the UI (resource views) * Complexity: Testing and bugfixing (check all resource types, where they are removed and added etc.). Simple but takes a lot of time * Time needed: a lot, min. 2 weeks * **UI/DB \[Agata\]** showing/selecting/adding/removing tags from the UI (resource views, tags) - current code is difficult, too complex, it might be better to not reuse it. * Complexity: **EXTREME!!!** * Time needed: Month * tags system: we can drop the wildcards and things, autocomplete is interesting, but multi-select is important. The connection between the tag library and the tag gui needs rewritten. The current gui is sort of okay. * Make KisFavoriteManager a model-view class for presets and tags * **DB \[later\]** database migration and versioning (loop over version, find update *from* version, execute and so on until version is up to date) * Needs testing, Write regression tests for that, Manual for regression testing on every release, discuss grouping tests with Anna-m. Create a db of version X, fill it with test data, convert it to the current version (say, X+4), check that the database integrity is not impaired. Repeat for every version. * Complexity: Doesn't require coding skills, just system design skills. But is fiddly. And tedious * Time Needed: recurs every time the database schema changes * **DB \[boud\]** MD5sums need to be added to the versioned resource table. * Complexity: simple * Time Needed: 1 hour * **DB->PLUGIN->CORE->UI \[boud\]** Resources in the kra file vs resources in the database: Every kra file will become an extra storage item, added and removed when the file is opened and closed. **KisDocumentStorage .** Only resources that are not the latest version as determined by md5 are added to the document storage, if they are the latest version, the ones from the original storage is used. * Integrate with loading layer styles: the layer style needs to refer to the resources in KisResourceLocator. * integrate with loaded .kra files * integrate with loaded .svg files * Complexity: Medium * Time Needed: 3 weeks * **CORE \[later, dmitry\]** Make resources reloadable * fix reloading the preset if dirty presets is switched off (KisPaintopBox::resourceSelected). The problem is that the preset itself no longer knows where it comes from or how it should be loaded. * Integrate with dirty-preset functionality * Complexity: Medium * Time Needed: 2 weeks * NOTE: Might be simpler, depends on memory management for resources, all resources are in shared pointer, unless cloned explictely, so modify preset in one window, presets are modified everywhere. Presets are always dirty, because we're not making clones *anymore* , we need to add, ensure there's a reload method in koresource, right now there's only a load method, and this might not work appropriately, due the new concept of bundles. * **UI \[later\]** Would be nice: icons for workspaces, generated or screenshots. * Complexity: * Time Needed: * **UI/CORE** \[Wolthera\] bundle creator * Main complexity is fixing the bundle generator. Then the UI design. Then compatibility with old bundle format. Rewrite bundles, rewrite GUI. * Complexity: Advanced. * Time Needed: Month * Resource manager should go! * **UI \[wolthera\]** bundle selector * Complexity: Simple * Time Needed: Week? * popup button in every resource view to select active bundles * changing bundles list should update all the views * **UI \[wolthera\]** Adding resources: allow D&D of the resources on resource views (or Krita main Window) * **CORE \[agata\]** versioned resources: for read-only storages: need design, works for folder storage (Saving modified/versioned resources that come from read-only storages.) Needs solid tests. * Complexity: Extreme * Time Needed: depends... * **DB/CORE/... \[dmitry, later\]** resources dependent on other resources (e.g. preset -> brush and pattern) This needs to be stored in the database as links between resource id's and saved to bundles when creating or updating bundles. * Database work: add relations between resources: `create_resources_resources.sql` * Refactor creating presets that use gradients, brush tips or patterns. * Preset with dependent resources should create a KisDocumentStorage for this preset (if the dependent resources are new). It is memory storage and removed on every Krita restart. * Should be implemented on a level of: KisResourceCacheDB * Complexity: Extreme * Time Needed: * **UI/DB \[later\]** Implement undelete of resources dialog (or put in resource browser) ### KNOWN BUGS * The resource viewer as used in dockers are broken, while the view widgets work in the database browser. * KGM cannot be loaded * Gradient previews are square. * Bugs in systems boudewijn hasn't touched. Eg. drawing and using resources in other methods may or may not leak due to the changes to the system. * Presets/Brush tips/Masked brushes * Patterns * Gradients * Palettes * Workspaces??? * Need hidden flag for storages (or do I have that already) ## How to proceed * Database things need to be done first. * Agata: * ABR/ASL needs to be done by the same person, and they can be done at any moment. * Versioned resources. * Tags * Boud: * will handle md5sums * resource storage for kra file. * Dmitry: 1. dmitry should fix difficult bugs, ivan should fix easy bugs. 2. linked/dependant resources 3. maybe reloadable resources * Wolthera will come to Deventer for mini sprint for the bundles * Adding/removing/updating resources from the UI. * dnd of presets on main krita window. * bundle selector * Later: * workspaces icons * resources reloadable is completely seperate * migrations last * undelete of resources ### Sorting Resources There are 2 todo's: sorting resources in the popup palette and sorting resources in the resource viewer. #### Resource Viewer * We need to have D&D of resources in the resource viewer to change the order (as in the palette viewer) * There needs to be a unique resource priority order number in the resources table, unique *per* resource type, not globally * On moving the resource to a new location, it needs to be renumbered, and all resources with an index > the new number need to be renumbered. In practice, this is fiddly and bug-prone, but it is doable. * There cannot be different sort orders for different tags; within a tag, the order is always the global one. This is actually what already happens when using deevad's hack with alphabetically grouping resources. #### Popup palette This is a *different* problem from the order problem in the resource viewer. There needs to be a per-tag definition of the resources shown in the palette, with position linked to individual slots. This would be a new table linking tags and resources.