14#include <QGlobalStatic>
19#include <kconfiggroup.h>
58 return inputProfileManager;
63 return d->profiles.values();
68 return d->profiles.keys();
73 if (
d->profiles.contains(name)) {
74 return d->profiles.value(name);
82 return d->currentProfile;
95 if (
d->profiles.contains(name)) {
96 return d->profiles.value(name);
110 if (
d->profiles.contains(name)) {
111 QString currentProfileName =
d->currentProfile->name();
113 delete d->profiles.value(name);
114 d->profiles.remove(name);
119 if (userDir.exists(
d->profileFileName(name))) {
120 userDir.remove(
d->profileFileName(name));
123 if (currentProfileName == name) {
124 d->currentProfile =
d->profiles.begin().value();
134 if (!
d->profiles.contains(oldName)) {
140 d->profiles.remove(oldName);
142 d->profiles.insert(newName,
profile);
155 if (!
d->profiles.contains(name) ||
d->profiles.contains(newName)) {
161 d->profiles.insert(newName, newProfile);
180 d->currentProfile =
nullptr;
181 qDeleteAll(
d->profiles);
191 QMap<QString, ProfileEntry> profileEntriesToMigrate;
192 QMap<QString, QList<ProfileEntry>> profileEntries;
202 KConfig config(
p, KConfig::SimpleConfig);
203 if (!config.hasGroup(
"General") || !config.group(
"General").hasKey(
"name") || !config.group(
"General").hasKey(
"version")) {
209 entry.
version = config.group(
"General").readEntry(
"version", 0);
210 entry.
name = config.group(
"General").readEntry(
"name");
217 profileEntriesToMigrate[entry.
name] = entry;
220 if (!profileEntries.contains(entry.
name)) {
226 profileEntries[entry.
name].append(entry);
232 auto entriesIt = profileEntriesToMigrate.begin();
233 while (entriesIt != profileEntriesToMigrate.end()) {
238 if (profileEntries.contains(entry.
name)) {
244 if (existingEntry.
fullpath.startsWith(userLocalSaveLocation)) {
245 entriesIt = profileEntriesToMigrate.erase(entriesIt);
254 profileEntries.remove(existingEntry.
name);
264 QMap<ProfileEntry, QList<KisShortcutConfiguration>> parsedProfilesToMigrate =
265 migrator.
migrate(profileEntriesToMigrate);
267 for (
ProfileEntry profileEntry : parsedProfilesToMigrate.keys()) {
273 const QString profilePath = profileEntry.fullpath;
274 QString oldProfileName = QFileInfo(profilePath).fileName();
275 oldProfileName.replace(
".profile", QString::number(
PROFILE_VERSION - 1) +
".profile");
277 QString oldProfilePath = storagePath + oldProfileName;
279 QFile::copy(profilePath, oldProfilePath);
281 KConfig config(oldProfilePath, KConfig::SimpleConfig);
287 for (
const auto &shortcut : shortcuts) {
297 Q_FOREACH(
const QString & profileName, profileEntries.keys()) {
299 if (profileEntries[profileName].isEmpty()) {
305 ProfileEntry entry = profileEntries[profileName].first();
307 KConfig config(entry.
fullpath, KConfig::SimpleConfig);
311 if (!config.hasGroup(action->
id())) {
315 KConfigGroup grp = config.group(action->
id());
317 Q_FOREACH(
const QString & entry, grp.entryMap()) {
332 if (
d->profiles.size() > 0) {
334 QString kritaDefault = QStringLiteral(
"Krita Default");
335 if (
d->profiles.contains(kritaDefault)) {
336 d->currentProfile =
d->profiles.value(kritaDefault);
338 d->currentProfile =
d->profiles.begin().value();
345 if (
d->currentProfile) {
366 const QString profilePath = storagePath +
d->profileFileName(
profile->
name());
367 KConfig config(profilePath, KConfig::SimpleConfig);
369 config.group(
"General").writeEntry(
"name",
profile->
name());
373 KConfigGroup grp = config.group(action->
id());
379 grp.writeEntry(QString(
"%1").arg(index++), shortcut->
serialize());
388 QSet<KisShortcutConfiguration *> conflictedShortcuts;
390 for (
auto startIt = shortcuts.constBegin(); startIt != shortcuts.constEnd(); ++startIt) {
392 for (
auto index = startIt + 1; index != shortcuts.constEnd(); ++index) {
396 if (*first == *second && !first->
isNoOp()) {
397 conflictedShortcuts.insert(first);
398 conflictedShortcuts.insert(second);
402 return conflictedShortcuts.values();
411 if(
profile.contains(kdeHome)) {
424 : QObject(parent), d(new
Private())
431 qDeleteAll(
d->profiles);
432 qDeleteAll(
d->actions);
436void KisInputProfileManager::Private::createActions()
454QString KisInputProfileManager::Private::profileFileName(
const QString &profileName)
456 QRegExp reg(
"[^a-z0-9]");
457#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
458 return profileName.toLower().remove(QRegExp(
"[^a-z0-9]")).append(
".profile");
460 QString pf = profileName.toLower();
462 return pf.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)