Skip to content

Commit

Permalink
Migrate to stricter Qt interface
Browse files Browse the repository at this point in the history
  • Loading branch information
R1tschY committed Apr 15, 2024
1 parent 1a1c84d commit 37fb2f5
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 161 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
endif()
add_definitions(-DSAILFISHOS)

# KDE Connect
add_subdirectory(kdeconnect-kde)

# Sailfish Connect
find_package(ECM 5.99 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
include(ECMQtDeclareLoggingCategory)

# KDE Connect
add_subdirectory(kdeconnect-kde)

find_package(Qt5 REQUIRED COMPONENTS Core DBus Network Gui Sql Quick Feedback)
find_package(KF5 REQUIRED COMPONENTS I18n CoreAddons Config)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(KDECMakeSettings)
remove_definitions(
-DQT_NO_KEYWORDS
-DQT_NO_FOREACH
)

# Options
set(PACKAGE_NAME harbour-sailfishconnect)
Expand Down
2 changes: 1 addition & 1 deletion app/src/appdaemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void AppDaemon::sendSimpleNotification(const QString &eventId, const QString &ti
notification->setPreviewSummary(title);
notification->setPreviewBody(text);
if (eventId == QStringLiteral("pingReceived")) {
notification->setIcon("image://theme/icon-lock-information");
notification->setIcon(QStringLiteral("image://theme/icon-lock-information"));
}
notification->publish();
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/dbus/kdeconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ void DeviceApi::pluginCall(const QString& plugin, const QString& method)
{
QDBusMessage msg = QDBusMessage::createMethodCall(
QStringLiteral("org.kde.kdeconnect"),
QStringLiteral("/modules/kdeconnect/devices/") % id() % QChar('/') % plugin,
QStringLiteral("/modules/kdeconnect/devices/") % id() % QChar::fromLatin1('/') % plugin,
QStringLiteral("org.kde.kdeconnect.device.") + plugin,
method);
checkForDbusError(QDBusConnection::sessionBus().asyncCall(msg));
}

} // namespace SailfishConnect
} // namespace SailfishConnect
4 changes: 2 additions & 2 deletions app/src/helper/jobsnotificator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void JobsNotificator::jobChanged(JobInfo *job)
Q_ASSERT(notification != nullptr);

if (job->state() == QStringLiteral("running")) {
notification->setHintValue("x-nemo-progress", job->progress());
notification->setHintValue(QStringLiteral("x-nemo-progress"), job->progress());

if (job->totalFiles() > 1) {
notification->setBody(job->title());
Expand Down Expand Up @@ -141,7 +141,7 @@ void JobsNotificator::addJob(JobInfo *job)
notification->setPreviewBody(body);
notification->setSummary(i18n("Downloading ..."));
}
notification->setHintValue("x-nemo-progress", job->progress());
notification->setHintValue(QStringLiteral("x-nemo-progress"), job->progress());
if (device) {
notification->setRemoteActions(
{ UI::openDevicePageDbusAction(device->id()) });
Expand Down
89 changes: 44 additions & 45 deletions app/src/helper/keyboardlayoutprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ KeyboardLayoutProvider::KeyboardLayoutProvider(QObject *parent)
m_settings.endGroup();

QJsonArray row1;
for (const QString& key : {"esc", "F1", "F2", "F3", "F4", "F5", "F6"}) {
for (const QString& key : {QStringLiteral("esc"), QStringLiteral("F1"), QStringLiteral("F2"), QStringLiteral("F3"), QStringLiteral("F4"), QStringLiteral("F5"), QStringLiteral("F6")}) {
QJsonObject keyObject;
keyObject.insert(QStringLiteral("caption"), key);
if (key.startsWith('F')) {
if (key.startsWith(QChar::fromLatin1('F'))) {
int num = key.at(1).toLatin1() - '0';
QString name = 'F' % QString::number(num + 6);
QString name = QChar::fromLatin1('F') % QString::number(num + 6);
keyObject.insert(QStringLiteral("captionShifted"), name);
}
row1.append(keyObject);
Expand All @@ -67,50 +67,50 @@ QString KeyboardLayoutProvider::layout() const
void KeyboardLayoutProvider::setLayout(const QString &layout)
{
// seems to be the only way to get the files stored
QFile layoutFile(MALIIT_LAYOUT_DIR % layout % ".qml");
QFile layoutFile(MALIIT_LAYOUT_DIR % layout % QStringLiteral(".qml"));
if (!layoutFile.open(QIODevice::ReadOnly)) {
qCDebug(logger) << "Unknown layout: " << layout;
return;
}

QRegularExpression caption("caption: \"([\\S])\"");
QRegularExpression captionShifted("captionShifted: \"([\\S])\"");
QRegularExpression symView("symView: \"([\\S]+)\"");
QRegularExpression symView2("symView2: \"([\\S]+)\"");
QByteArray line = layoutFile.readLine();
QRegularExpression caption(QStringLiteral("caption: \"([\\S])\""));
QRegularExpression captionShifted(QStringLiteral("captionShifted: \"([\\S])\""));
QRegularExpression symView(QStringLiteral("symView: \"([\\S]+)\""));
QRegularExpression symView2(QStringLiteral("symView2: \"([\\S]+)\""));
QString line = QString::fromUtf8(layoutFile.readLine());
QJsonArray keys;
QJsonArray row;

while (line.length() > 0) {
if (line.contains(" }")) {
if (line.contains(QStringLiteral(" }"))) {
keys.append(row);
} else if (line.contains("KeyboardRow {")) {
} else if (line.contains(QStringLiteral("KeyboardRow {"))) {
row = QJsonArray();
} else if (line.contains("Key")) {
QByteArray keySequence = line;
while (!line.contains('}')) {
line = layoutFile.readLine();
} else if (line.contains(QStringLiteral("Key"))) {
QString keySequence = line;
while (!line.contains(QChar::fromLatin1('}'))) {
line = QString::fromUtf8(layoutFile.readLine());
keySequence.append(line);
}
while (keySequence.contains('\n')) {
keySequence.replace('\n', ' ');
while (keySequence.contains(QChar::fromLatin1('\n'))) {
keySequence.replace(QChar::fromLatin1('\n'), QChar::fromLatin1(' '));
}

// remove backslash
keySequence.replace("\\\"", "\"");
keySequence.replace("\\\\", "\\");
keySequence.replace(QStringLiteral("\\\""), QStringLiteral("\""));
keySequence.replace(QStringLiteral("\\\\"), QStringLiteral("\\"));

if (keySequence.contains("ShiftKey")) {
if (keySequence.contains(QStringLiteral("ShiftKey"))) {
QJsonObject key;
key["caption"] = "shift";
key[QStringLiteral("caption")] = QStringLiteral("shift");
row.append(key);
} else if (keySequence.contains("BackspaceKey")) {
} else if (keySequence.contains(QStringLiteral("BackspaceKey"))) {
QJsonObject upKey;
upKey["caption"] = "";
upKey["symView"] = "up";
upKey[QStringLiteral("caption")] = QStringLiteral("");
upKey[QStringLiteral("symView")] = QStringLiteral("up");
row.append(upKey);
QJsonObject key;
key["caption"] = "backspace";
key[QStringLiteral("caption")] = QStringLiteral("backspace");
row.append(key);
} else {
QRegularExpressionMatch captionMatch =
Expand All @@ -122,21 +122,21 @@ void KeyboardLayoutProvider::setLayout(const QString &layout)
QRegularExpressionMatch symView2Match =
symView2.match(keySequence);
QJsonObject key;
key["caption"] = captionMatch.captured(1);
key[QStringLiteral("caption")] = captionMatch.captured(1);
if (captionShiftedMatch.hasMatch()) {
key["captionShifted"] = captionShiftedMatch.captured(1);
key[QStringLiteral("captionShifted")] = captionShiftedMatch.captured(1);
}
if (symViewMatch.hasMatch()) {
key["symView"] = symViewMatch.captured(1);
key[QStringLiteral("symView")] = symViewMatch.captured(1);
}
if (symView2Match.hasMatch()) {
key["symView2"] = symView2Match.captured(1);
key[QStringLiteral("symView2")] = symView2Match.captured(1);
}
row.append(key);
}
}

line = layoutFile.readLine();
line = QString::fromUtf8(layoutFile.readLine());
}

layoutFile.close();
Expand All @@ -150,17 +150,17 @@ void KeyboardLayoutProvider::setLayout(const QString &layout)
m_row4 = keys[2].toArray().toVariantList();

QJsonArray row5;
for (const QString& key : {"?123", "ctrl", ",", " ", ".", "alt", "enter"}) {
for (const QString& key : {QStringLiteral("?123"), QStringLiteral("ctrl"), QStringLiteral(","), QStringLiteral(" "), QStringLiteral("."), QStringLiteral("alt"), QStringLiteral("enter")}) {
QJsonObject keyObject;
keyObject["caption"] = key;
if (key == ".") {
keyObject["symView"] = "left";
} else if (key == "alt") {
keyObject["symView"] = "down";
} else if (key == "enter") {
keyObject["symView"] = "right";
} else if (key == "?123") {
keyObject["symView"] = "ABC";
keyObject[QStringLiteral("caption")] = key;
if (key == QStringLiteral(".")) {
keyObject[QStringLiteral("symView")] = QStringLiteral("left");
} else if (key == QStringLiteral("alt")) {
keyObject[QStringLiteral("symView")] = QStringLiteral("down");
} else if (key == QStringLiteral("enter")) {
keyObject[QStringLiteral("symView")] = QStringLiteral("right");
} else if (key == QStringLiteral("?123")) {
keyObject[QStringLiteral("symView")] = QStringLiteral("ABC");
}
row5.append(keyObject);
}
Expand Down Expand Up @@ -261,16 +261,15 @@ void KeyboardLayoutProvider::loadNames()

for (const QString &group : settings.childGroups()) {
settings.beginGroup(group);
longNames[group] = settings.value(
QStringLiteral("name")).toByteArray();
longNames[group] = settings.value(QStringLiteral("name")).toString();
settings.endGroup();
}
}
}

// then load layouts
for (const QString &layout : confDir.entryList()) {
if (layout.endsWith(QStringLiteral(".qml")) && !layout.contains('_')) {
if (layout.endsWith(QStringLiteral(".qml")) && !layout.contains(QChar::fromLatin1('_'))) {
// hi, kn, mr and te are currentently not working
if (layout.contains(QStringLiteral("hi")) || layout.contains(QStringLiteral("kn")) ||
layout.contains(QStringLiteral("mr")) || layout.contains(QStringLiteral("te")) ||
Expand All @@ -279,8 +278,8 @@ void KeyboardLayoutProvider::loadNames()
}

QJsonObject language;
language.insert("short", layout.left(layout.indexOf('.')));
language.insert("long", longNames[layout]);
language.insert(QStringLiteral("short"), layout.left(layout.indexOf(QChar::fromLatin1('.'))));
language.insert(QStringLiteral("long"), longNames[layout]);
m_layouts.append(language);
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/models/devicelistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ static QUrl deviceTypeToIcon(const QString& deviceType)
// TODO: move to qml part
if (deviceType == QLatin1String("smartphone")
|| deviceType == QLatin1String("phone"))
return QStringLiteral("image://theme/icon-m-phone");
return QUrl(QStringLiteral("image://theme/icon-m-phone"));

if (deviceType == QLatin1String("tablet"))
return QStringLiteral("image://theme/icon-m-tablet");
return QUrl(QStringLiteral("image://theme/icon-m-tablet"));

// FUTURE-TODO: use a television icon for "tv" when it exists

return QStringLiteral("image://theme/icon-m-computer");
return QUrl(QStringLiteral("image://theme/icon-m-computer"));
}

DeviceListModel::DeviceListModel(QObject *parent)
Expand Down
24 changes: 12 additions & 12 deletions app/src/sailfishconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,21 @@ bool copyDirectory(const QString& src, const QString& dst)

for (const QString dir : srcDir.entryList(
QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks)) {
QString dst_path = dst % '/' % dir;
QString dst_path = dst % QChar::fromLatin1('/') % dir;
if (!srcDir.mkpath(dst_path)) {
qCCritical(logger) << "Failed to create directory" << dst_path;
return false;
}
if (!copyDirectory(src % '/' % dir, dst_path)) {
if (!copyDirectory(src % QChar::fromLatin1('/') % dir, dst_path)) {
return false;
}
}

for (const QString file : srcDir.entryList(QDir::Files)) {
if (!QFile::copy(src % '/' % file, dst % '/' % file)) {
if (!QFile::copy(src % QChar::fromLatin1('/') % file, dst % QChar::fromLatin1('/') % file)) {
qCCritical(logger)
<< "Failed to copy file" << (src % '/' % file)
<< "to" << (dst % '/' % file);
<< "Failed to copy file" << (src % QChar::fromLatin1('/') % file)
<< "to" << (dst % QChar::fromLatin1('/') % file);
return false;
}
}
Expand All @@ -211,13 +211,13 @@ bool copyDirectory(const QString& src, const QString& dst)
void migrateOldInstallation() {
QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
QString oldConfigPath = configPath
% '/' % QStringLiteral("harbour-sailfishconnect")
% '/' % QStringLiteral("harbour-sailfishconnect");
% QChar::fromLatin1('/') % QStringLiteral("harbour-sailfishconnect")
% QChar::fromLatin1('/') % QStringLiteral("harbour-sailfishconnect");
QString newConfigPath = configPath
% '/' % QStringLiteral("harbour-sailfishconnect");
% QChar::fromLatin1('/') % QStringLiteral("harbour-sailfishconnect");

QString oldCertificatePath = oldConfigPath % '/' % QStringLiteral("certificate.pem");
QString newCertificatePath = newConfigPath % '/' % QStringLiteral("certificate.pem");
QString oldCertificatePath = oldConfigPath % QChar::fromLatin1('/') % QStringLiteral("certificate.pem");
QString newCertificatePath = newConfigPath % QChar::fromLatin1('/') % QStringLiteral("certificate.pem");

if (QFileInfo::exists(oldCertificatePath) && !QFileInfo::exists(newCertificatePath)) {
qCInfo(logger) << "Migrate config from" << oldConfigPath << "to" << newConfigPath;
Expand Down Expand Up @@ -247,7 +247,7 @@ Options parseCommandLine(const QCoreApplication &app) {
parser.addHelpOption();
parser.addVersionOption();

QCommandLineOption daemonOption(QStringList() << "d" << "daemon",
QCommandLineOption daemonOption(QStringList() << QStringLiteral("d") << QStringLiteral("daemon"),
QStringLiteral("Start application in daemon mode. "
"Window is not shown until a call without is flag."));
parser.addOption(daemonOption);
Expand Down Expand Up @@ -276,7 +276,7 @@ int main(int argc, char *argv[])

// Logging
qInstallMessageHandler(myMessageOutput);
QLoggingCategory::setFilterRules("kdeconnect.*=true");
QLoggingCategory::setFilterRules(QStringLiteral("kdeconnect.*=true"));

// I18n
initI18n();
Expand Down
16 changes: 8 additions & 8 deletions app/src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ void UI::showMainWindow()
m_view->installEventFilter(this);

setRunInBackground(
m_settings.value("runInBackground", m_runInBackground).toBool());
m_settings.value(QStringLiteral("runInBackground"), m_runInBackground).toBool());

// view
m_view->rootContext()->setContextProperty("daemon", m_daemonApi);
m_view->rootContext()->setContextProperty("ui", this);
m_view->rootContext()->setContextProperty("keyboardLayout", m_keyboardLayoutProvider);
m_view->rootContext()->setContextProperty(QStringLiteral("daemon"), m_daemonApi);
m_view->rootContext()->setContextProperty(QStringLiteral("ui"), this);
m_view->rootContext()->setContextProperty(QStringLiteral("keyboardLayout"), m_keyboardLayoutProvider);
m_view->setSource(SailfishApp::pathToMainQml());
m_view->showFullScreen();
}
Expand Down Expand Up @@ -189,7 +189,7 @@ void UI::setRunInBackground(bool value)
return;

m_runInBackground = value;
m_settings.setValue("runInBackground", value);
m_settings.setValue(QStringLiteral("runInBackground"), value);
m_settings.sync();

qGuiApp->setQuitOnLastWindowClosed(!value);
Expand All @@ -199,10 +199,10 @@ void UI::setRunInBackground(bool value)
systemctl->setProcessChannelMode(QProcess::MergedChannels);
if (value) {
connect(systemctl, SIGNAL(finished(int)), this, SLOT(onRegisteredService()));
systemctl->start("systemctl", { "--user", "enable", SERVICE_FILE_LOCATION });
systemctl->start(QStringLiteral("systemctl"), { QStringLiteral("--user"), QStringLiteral("enable"), SERVICE_FILE_LOCATION });
} else {
connect(systemctl, SIGNAL(finished(int)), this, SLOT(onUnregisteredService()));
systemctl->start("systemctl", { "--user", "disable", SERVICE_FILE_LOCATION });
systemctl->start(QStringLiteral("systemctl"), { QStringLiteral("--user"), QStringLiteral("disable"), SERVICE_FILE_LOCATION });
}
#endif

Expand All @@ -212,7 +212,7 @@ void UI::setRunInBackground(bool value)
QVariant UI::openDevicePageDbusAction(const QString &deviceId)
{
return Notification::remoteAction(
QStringLiteral("default"), QString("default"),
QStringLiteral("default"), QStringLiteral("default"),
DBUS_SERVICE_NAME, UI::DBUS_PATH, UI::DBUS_INTERFACE_NAME,
QStringLiteral("openDevicePage"), { deviceId });
}
Expand Down
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
KF5CoreAddons/5.36.0@r1tschy/stable
KF5I18n/5.36.0@r1tschy/stable
KF5Config/5.36.0@r1tschy/stable
extra-cmake-modules/5.99.0@r1tschy/stable
libssh/0.9.5@r1tschy/stable

[options]
Expand Down
Loading

0 comments on commit 37fb2f5

Please sign in to comment.