Refactoring, improve validation in kcm, optimize
ClosedPublic

Authored by alex on Feb 2 2020, 7:42 AM.

Details

Summary

The config keys are now in a separate file, instead of having them at two places.
Runner
The duplicate call to reloadConfiguration has been removed and aliases/codes get validated.
Additionally the match method has been simplified and the character is now copied to the clipboard when selected.
KCM
Validation of the add/delete buttons, error message now in GUI and deprecated methods removed.

Test Plan

Compile, test runner and test editing entries.
Manually add alias(and no hex value) to ~/.config/krunnerrc and reload the kcm, error message should be shown.

Before:


After:



Diff Detail

Repository
R114 Plasma Addons
Branch
charrunner_improvements (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 22294
Build 22312: arc lint + arc unit
alex created this revision.Feb 2 2020, 7:42 AM
Restricted Application added a project: Plasma. · View Herald TranscriptFeb 2 2020, 7:42 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
alex requested review of this revision.Feb 2 2020, 7:42 AM
ngraham edited the test plan for this revision. (Show Details)Feb 2 2020, 2:29 PM
sitter added inline comments.Feb 10 2020, 12:11 PM
runners/characters/charrunner.cpp
40 ↗(On Diff #74849)

m_triggerWord is empty when this executes. I think that needs to move back to reloadConfiguration

50 ↗(On Diff #74849)

unnecessary ref

90 ↗(On Diff #74849)

newline

runners/characters/charrunner_config.cpp
64 ↗(On Diff #74849)

There is no purpose to this size variable. Compilers will optimize i < aliasList.size().

72 ↗(On Diff #74849)

this needs i18nc()

89 ↗(On Diff #74849)

count not useful

120 ↗(On Diff #74849)

newline

124 ↗(On Diff #74849)

newline

alex updated this revision to Diff 75358.Feb 10 2020, 12:48 PM
  • Implement requested changes
alex marked 8 inline comments as done.Feb 10 2020, 12:50 PM
dvratil added inline comments.
runners/characters/config_keys.h
23

You could use static constexpr QStringView CONFIG_TRIGGERWORD = u"triggerWord" to get something that's compile-time and easily used with QString API

alex added a comment.Feb 24 2020, 11:50 PM

First of all thanks for the idea, but is the QString API needed ? These strings are just used for reading the config and if you have a look at the implementation of the readEntry method:

QStringList KConfigGroup::readEntry(const QString &key, const QStringList &aDefault) const
{
     return readEntry(key.toUtf8().constData(), aDefault);
}

Basically the method is just converting the QString to a char array and calls the readEntry method (which is currently directly called).
Link: https://api.kde.org/frameworks-api/frameworks-apidocs/frameworks/kconfig/html/kconfiggroup_8cpp_source.html#l00717

Huh, guess kconfig never goes to QString after all.

@davidre had a similar suggestion of using auto instead and let the compiler do its work IIRC

dvratil's comment still applies to DEFAULT_TRIGGERWORD though.

Generally speaking the global static keyword strings aren't very popluar in our code. Although, TBH, I do not know why.

alex updated this revision to Diff 76350.Feb 25 2020, 10:23 AM
  • Implement suggestion
sitter accepted this revision.Mar 9 2020, 11:02 AM

LGTM. Does anyone have final comments?

This revision is now accepted and ready to land.Mar 9 2020, 11:02 AM
This revision was automatically updated to reflect the committed changes.