Krita Source Code Documentation
Loading...
Searching...
No Matches
KisInputProfileMigrator.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Sharaf Zaman <shzam@sdf.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
8
9#include <KConfig>
10#include <KConfigGroup>
11#include <KoResourcePaths.h>
12
13#include <QDebug>
14
18
22
24 : m_manager(manager)
25{
26 // FIXME(sh_zam): Should we declare this as "the default profile" somewhere?
27 const QStringList profiles =
29 .filter("kritadefault.profile");
30
31 if (!profiles.empty()) {
32 // This will be from the install location, so *has* to be the default, see KoResourcePaths for the
33 // order in which it returns locations.
34 m_defaultProfile = profiles.last();
35 } else {
36 qWarning() << "Default profile does not exist anywhere!";
37 }
38}
39
43
53
54template <typename Func>
56{
57 auto it = shortcuts.begin();
58 while (it != shortcuts.end()) {
59 KisShortcutConfiguration shortcut = *it;
60 if (pred(shortcut)) {
61 ++it;
62 } else {
63 it = shortcuts.erase(it);
64 }
65 }
66}
67
69{
71
72 KConfig config(profile, KConfig::SimpleConfig);
73
75 for (const auto action : actions) {
76 if (!config.hasGroup(action->id())) {
77 continue;
78 }
79
80 KConfigGroup group = config.group(action->id());
81 for (const auto &groupEntry : group.entryMap()) {
83
84 shortcut.setAction(action);
85 if (shortcut.unserialize(groupEntry)) {
86 shortcuts.append(shortcut);
87 }
88 }
89 }
90 return shortcuts;
91}
92
93QMap<ProfileEntry, QList<KisShortcutConfiguration>>
94KisInputProfileMigrator5To6::migrate(const QMap<QString, ProfileEntry> profiles)
95{
96 QMap<ProfileEntry, QList<KisShortcutConfiguration>> parsedProfiles;
97 for (const auto &profile : profiles) {
98 QList<KisShortcutConfiguration> shortcuts = getShortcutsFromProfile(profile.fullpath);
99
100 // we ignore the touch shortcuts, because they're from an older version
101 filterShortcuts(shortcuts, [](KisShortcutConfiguration shortcut) {
102 return shortcut.type() != KisShortcutConfiguration::GestureType;
103 });
104
105 // now we add the default new shortcuts -- this should complete the migration.
106 shortcuts.append(defaultTouchShortcuts());
107
108 parsedProfiles[profile] = shortcuts;
109 }
110
111 return parsedProfiles;
112}
A class to manage a list of profiles and actions.
QList< KisAbstractInputAction * > actions
QMap< ProfileEntry, QList< KisShortcutConfiguration > > migrate(const QMap< QString, ProfileEntry > profiles) override
QList< KisShortcutConfiguration > defaultTouchShortcuts()
void filterShortcuts(QList< KisShortcutConfiguration > &shortcuts, Func func)
KisInputProfileMigrator5To6(KisInputProfileManager *manager)
KisInputProfileManager * m_manager
QList< KisShortcutConfiguration > getShortcutsFromProfile(QString profile) const
A class encapsulating all settings for a single shortcut.
bool unserialize(const QString &serialized)
void setAction(KisAbstractInputAction *newAction)
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)