14#include <QGlobalStatic>
15#include <QRegularExpression>
19#include <kconfiggroup.h>
59 return inputProfileManager;
64 return d->profiles.values();
69 return d->profiles.keys();
74 if (
d->profiles.contains(name)) {
75 return d->profiles.value(name);
83 return d->currentProfile;
96 if (
d->profiles.contains(name)) {
97 return d->profiles.value(name);
111 if (
d->profiles.contains(name)) {
112 QString currentProfileName =
d->currentProfile->name();
114 delete d->profiles.value(name);
115 d->profiles.remove(name);
120 if (userDir.exists(
d->profileFileName(name))) {
121 userDir.remove(
d->profileFileName(name));
124 if (currentProfileName == name) {
125 d->currentProfile =
d->profiles.begin().value();
135 if (!
d->profiles.contains(oldName)) {
141 d->profiles.remove(oldName);
143 d->profiles.insert(newName,
profile);
156 if (!
d->profiles.contains(name) ||
d->profiles.contains(newName)) {
162 d->profiles.insert(newName, newProfile);
181 d->currentProfile =
nullptr;
182 qDeleteAll(
d->profiles);
192 QMap<QString, ProfileEntry> profileEntriesToMigrate;
193 QMap<QString, QList<ProfileEntry>> profileEntries;
203 KConfig config(
p, KConfig::SimpleConfig);
204 if (!config.hasGroup(
"General") || !config.group(
"General").hasKey(
"name") || !config.group(
"General").hasKey(
"version")) {
210 entry.
version = config.group(
"General").readEntry(
"version", 0);
211 entry.
name = config.group(
"General").readEntry(
"name");
218 profileEntriesToMigrate[entry.
name] = entry;
221 if (!profileEntries.contains(entry.
name)) {
227 profileEntries[entry.
name].append(entry);
233 auto entriesIt = profileEntriesToMigrate.begin();
234 while (entriesIt != profileEntriesToMigrate.end()) {
239 if (profileEntries.contains(entry.
name)) {
245 if (existingEntry.
fullpath.startsWith(userLocalSaveLocation)) {
246 entriesIt = profileEntriesToMigrate.erase(entriesIt);
255 profileEntries.remove(existingEntry.
name);
263 for (
const auto &profileEntry : profileEntriesToMigrate) {
267 Q_FOREACH(
const QString & profileName, profileEntries.keys()) {
269 if (profileEntries[profileName].isEmpty()) {
275 ProfileEntry entry = profileEntries[profileName].first();
281 if (
d->profiles.size() > 0) {
283 QString kritaDefault = QStringLiteral(
"Krita Default");
284 if (
d->profiles.contains(kritaDefault)) {
285 d->currentProfile =
d->profiles.value(kritaDefault);
287 d->currentProfile =
d->profiles.begin().value();
294 if (
d->currentProfile) {
301 KConfig config(fullPath, KConfig::SimpleConfig);
306 const int version = config.group(
"General").readEntry(
"version", 0);
307 const QString name = config.group(
"General").readEntry(
"name");
313 if (!config.hasGroup(action->
id())) {
317 KConfigGroup grp = config.group(action->
id());
319 Q_FOREACH (
const QString &entry, grp.entryMap()) {
324 loadedShortcuts.append(shortcut);
342 if (profileEntry.
version == 5) {
344 parsedShortcuts = migratorFromV5.
migrate(profileEntry);
345 }
else if (profileEntry.
version == 6) {
347 parsedShortcuts = migratorFromV6.
migrate(profileEntry);
349 warnKrita <<
"Unable to migrate input profile: unknown version:" << profileEntry.
version <<
"("
354 dbgKrita <<
"Migrating a profile " << profileEntry.
name <<
"(" << profileEntry.
fullpath <<
")" <<
"from version" << profileEntry.
version;
361 const QString profilePath = profileEntry.
fullpath;
362 QString oldProfileName = QFileInfo(profilePath).fileName();
363 oldProfileName.replace(
".profile", QString::number(
PROFILE_VERSION - 1) +
".profile");
365 QString oldProfilePath = storagePath + oldProfileName;
367 QFile::copy(profilePath, oldProfilePath);
369 KConfig config(oldProfilePath, KConfig::SimpleConfig);
374 for (
const auto &shortcut : parsedShortcuts) {
401 const QString profilePath = storagePath +
d->profileFileName(
profile->
name());
402 KConfig config(profilePath, KConfig::SimpleConfig);
404 config.group(
"General").writeEntry(
"name",
profile->
name());
408 KConfigGroup grp = config.group(action->
id());
414 grp.writeEntry(QString(
"%1").arg(index++), shortcut->
serialize());
423 QSet<KisShortcutConfiguration *> conflictedShortcuts;
425 for (
auto startIt = shortcuts.constBegin(); startIt != shortcuts.constEnd(); ++startIt) {
427 for (
auto index = startIt + 1; index != shortcuts.constEnd(); ++index) {
431 if (*first == *second && !first->
isNoOp()) {
432 conflictedShortcuts.insert(first);
433 conflictedShortcuts.insert(second);
437 return conflictedShortcuts.values();
446 if(
profile.contains(kdeHome)) {
459 : QObject(parent), d(new
Private())
466 qDeleteAll(
d->profiles);
467 qDeleteAll(
d->actions);
471void KisInputProfileManager::Private::createActions()
490QString KisInputProfileManager::Private::profileFileName(
const QString &profileName)
492 QRegularExpression reg(
"[^a-z0-9]");
493 return profileName.toLower().remove(reg).append(
".profile");
Q_GLOBAL_STATIC(KisStoragePluginRegistry, s_instance)
PythonPluginManager * instance
Alternate Invocation implementation of KisAbstractInputAction.
Change Primary Setting implementation of KisAbstractInputAction.
void setCurrentInputProfile(const QString &name)
QString currentInputProfile(bool defaultValue=false) const
Pan Canvas implementation of KisAbstractInputAction.
Rotate Canvas implementation of KisAbstractInputAction.
Select Layer implementation of KisAbstractInputAction.
A class encapsulating all settings for a single shortcut.
bool unserialize(const QString &serialized)
void setAction(KisAbstractInputAction *newAction)
Zoom Canvas implementation of KisAbstractInputAction.
This class handles both rotation and zooming operation. This is separate from Zoom and Rotate operati...
static QString getAppDataLocation()
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)