Commit 9fb83433 authored by Laurent Montel's avatar Laurent Montel 😁

Use some QStringLiteral

parent 1d55191e
......@@ -58,9 +58,12 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX LIBKLEO
########### Targets ###########
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x060000)
remove_definitions( -DQT_NO_CAST_FROM_ASCII )
add_definitions(-DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT)
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
add_definitions(-DQT_USE_QSTRINGBUILDER)
########### CMake Config Files ###########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Libkleo")
......
......@@ -157,8 +157,8 @@ int main(int argc, char **argv)
{
// Static querying of a single boolean option
static const char s_groupName[] = "Monitor";
static const char s_entryName[] = "quiet";
static const QString s_groupName = QStringLiteral("Monitor");
static const QString s_entryName = QStringLiteral("quiet");
QGpgME::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), s_groupName, s_entryName);
if (entry) {
Q_ASSERT(entry->argType() == QGpgME::CryptoConfigEntry::ArgType_None);
......@@ -201,14 +201,14 @@ int main(int argc, char **argv)
cout << "quiet option reset to initial: " << (val ? "is set" : "is not set") << endl;
} else {
cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
cout << "Entry 'dirmngr/" << qPrintable(s_groupName) << "/" << qPrintable(s_entryName) << "' not found" << endl;
}
}
{
// Static querying and setting of a single int option
static const char s_groupName[] = "LDAP";
static const char s_entryName[] = "ldaptimeout";
static const QString s_groupName = QStringLiteral("LDAP");
static const QString s_entryName = QStringLiteral("ldaptimeout");
QGpgME::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), s_groupName, s_entryName);
if (entry) {
Q_ASSERT(entry->argType() == QGpgME::CryptoConfigEntry::ArgType_UInt);
......@@ -254,14 +254,14 @@ int main(int argc, char **argv)
cout << "LDAP timeout reset to initial " << val << " seconds." << endl;
} else {
cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
cout << "Entry 'dirmngr/" << qPrintable(s_groupName) << "/" << qPrintable(s_entryName) << "' not found" << endl;
}
}
{
// Static querying and setting of a single string option
static const char s_groupName[] = "Debug";
static const char s_entryName[] = "log-file";
static const QString s_groupName = QStringLiteral("Debug");
static const QString s_entryName = QStringLiteral("log-file");
QGpgME::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), s_groupName, s_entryName);
if (entry) {
Q_ASSERT(entry->argType() == QGpgME::CryptoConfigEntry::ArgType_Path);
......@@ -302,14 +302,14 @@ int main(int argc, char **argv)
cout << "Log-file reset to initial " << val.toLocal8Bit().constData() << endl;
} else {
cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
cout << "Entry 'dirmngr/" << qPrintable(s_groupName) << "/" << qPrintable(s_entryName) << "' not found" << endl;
}
}
{
// Static querying and setting of the LDAP URL list option
static const char s_groupName[] = "LDAP";
static const char s_entryName[] = "LDAP Server";
static const QString s_groupName = QStringLiteral("LDAP");
static const QString s_entryName = QStringLiteral("LDAP Server");
QGpgME::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), s_groupName, s_entryName);
if (entry) {
Q_ASSERT(entry->argType() == QGpgME::CryptoConfigEntry::ArgType_LDAPURL);
......@@ -327,8 +327,8 @@ int main(int argc, char **argv)
lst << QUrl(QStringLiteral("ldap://foo:389?a:b c"));
lst << QUrl(QStringLiteral("ldap://server:389?a=b,c=DE")); // the query contains a literal ','
//cout << " trying to set: " << lst.toStringList().join(", ").local8Bit() << endl;
Q_ASSERT(lst[0].query() == "b");
Q_ASSERT(lst[1].query() == "a:b c"); // see, the space got _not_escaped
Q_ASSERT(lst[0].query() == QStringLiteral("b"));
Q_ASSERT(lst[1].query() == QStringLiteral("a:b c")); // see, the space got _not_escaped
entry->setURLValueList(lst);
Q_ASSERT(entry->isDirty());
config->sync(true);
......@@ -367,7 +367,7 @@ int main(int argc, char **argv)
}
cout << endl;
} else {
cout << "Entry 'dirmngr/" << s_groupName << "/" << s_entryName << "' not found" << endl;
cout << "Entry 'dirmngr/" << qPrintable(s_groupName) << "/" << qPrintable(s_entryName) << "' not found" << endl;
}
}
......
......@@ -70,7 +70,7 @@ KeyGenerator::KeyGenerator(QWidget *parent)
: QDialog(parent)
{
setModal(true);
setWindowTitle("KeyGenerationJob test");
setWindowTitle(QStringLiteral("KeyGenerationJob test"));
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
......@@ -80,7 +80,7 @@ KeyGenerator::KeyGenerator(QWidget *parent)
buttonBox->addButton(user1Button, QDialogButtonBox::ActionRole);
connect(buttonBox, &QDialogButtonBox::rejected, this, &KeyGenerator::reject);
user1Button->setDefault(true);
KGuiItem::assign(user1Button, KGuiItem("Create"));
KGuiItem::assign(user1Button, KGuiItem(QStringLiteral("Create")));
QWidget *w = new QWidget(this);
mainLayout->addWidget(w);
......@@ -91,16 +91,16 @@ KeyGenerator::KeyGenerator(QWidget *parent)
int row = -1;
++row;
glay->addWidget(new QLabel("<GnupgKeyParms format=\"internal\">", w),
glay->addWidget(new QLabel(QStringLiteral("<GnupgKeyParms format=\"internal\">"), w),
row, 0, 1, 2);
for (int i = 0; i < numKeyParams; ++i) {
++row;
glay->addWidget(new QLabel(keyParams[i], w), row, 0);
glay->addWidget(new QLabel(QString::fromLatin1(keyParams[i]), w), row, 0);
glay->addWidget(mLineEdits[i] = new QLineEdit(w), row, 1);
}
++row;
glay->addWidget(new QLabel("</GnupgKeyParms>", w), row, 0, 1, 2);
glay->addWidget(new QLabel(QStringLiteral("</GnupgKeyParms>"), w), row, 0, 1, 2);
++row;
glay->setRowStretch(row, 1);
glay->setColumnStretch(1, 1);
......@@ -112,12 +112,12 @@ KeyGenerator::~KeyGenerator() {}
void KeyGenerator::slotStartKeyGeneration()
{
QString params = "<GnupgKeyParms format=\"internal\">\n";
QString params = QStringLiteral("<GnupgKeyParms format=\"internal\">\n");
for (int i = 0; i < numKeyParams; ++i)
if (mLineEdits[i] && !mLineEdits[i]->text().trimmed().isEmpty()) {
params += keyParams[i] + (": " + mLineEdits[i]->text().trimmed()) + '\n';
params += QString::fromLatin1(keyParams[i]) + (QStringLiteral(": ") + mLineEdits[i]->text().trimmed()) + QLatin1Char('\n');
}
params += "</GnupgKeyParms>\n";
params += QStringLiteral("</GnupgKeyParms>\n");
const QGpgME::Protocol *proto = nullptr;
if (protocol) {
......@@ -141,15 +141,15 @@ void KeyGenerator::slotStartKeyGeneration()
}
#ifndef LIBKLEO_NO_PROGRESSDIALOG
else {
(void)new Kleo::ProgressDialog(job, "Generating key", this);
(void)new Kleo::ProgressDialog(job, QStringLiteral("Generating key"), this);
}
#endif
}
void KeyGenerator::showError(const GpgME::Error &err)
{
KMessageBox::error(this, "Could not start key generation: " + QString::fromLocal8Bit(err.asString()),
"Key Generation Error");
KMessageBox::error(this, QStringLiteral("Could not start key generation: %1").arg(QString::fromLocal8Bit(err.asString())),
QStringLiteral("Key Generation Error"));
}
void KeyGenerator::slotResult(const GpgME::KeyGenerationResult &res, const QByteArray &keyData)
......@@ -157,8 +157,8 @@ void KeyGenerator::slotResult(const GpgME::KeyGenerationResult &res, const QByte
if (res.error()) {
showError(res.error());
} else
KMessageBox::information(this, QString("Key generated successfully, %1 bytes long").arg(keyData.size()),
"Key Generation Finished");
KMessageBox::information(this, QStringLiteral("Key generated successfully, %1 bytes long").arg(keyData.size()),
QStringLiteral("Key Generation Finished"));
}
int main(int argc, char **argv)
......
......@@ -63,33 +63,33 @@ public:
QString TestColumnStrategy::title(int col) const
{
switch (col) {
case 0: return "Subject";
case 1: return "EMail";
case 2: return "Issuer";
case 3: return "Serial";
case 4: return "Protocol";
case 5: return "Validity";
case 0: return QStringLiteral("Subject");
case 1: return QStringLiteral("EMail");
case 2: return QStringLiteral("Issuer");
case 3: return QStringLiteral("Serial");
case 4: return QStringLiteral("Protocol");
case 5: return QStringLiteral("Validity");
default: return QString();
}
}
QString TestColumnStrategy::toolTip(const GpgME::Key &key, int) const
{
return "Fingerprint: " + QString::fromUtf8(key.primaryFingerprint());
return QStringLiteral("Fingerprint: ") + QString::fromUtf8(key.primaryFingerprint());
}
QString TestColumnStrategy::text(const GpgME::Key &key, int col) const
{
if (key.isNull()) {
return "<null>";
return QStringLiteral("<null>");
}
switch (col) {
case 0: return QString::fromUtf8(key.userID(0).id());
case 1: return QString::fromUtf8(key.userID(0).email());
case 2: return QString::fromUtf8(key.issuerName());
case 3: return key.issuerSerial();
case 4: return key.protocolAsString();
case 5: return QChar(key.userID(0).validityAsString());
case 3: return QString::fromLatin1(key.issuerSerial());
case 4: return QString::fromLatin1(key.protocolAsString());
case 5: return QString(QLatin1Char(key.userID(0).validityAsString()));
default: return QString();
}
}
......@@ -108,14 +108,14 @@ void CertListView::slotResult(const GpgME::KeyListResult &result)
{
qDebug() << "CertListView::slotResult()";
if (result.isNull()) {
QMessageBox::information(this, "Key Listing Result", "KeyListResult is null!");
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("KeyListResult is null!"));
} else if (result.error())
QMessageBox::critical(this, "Key Listing Result",
QString("KeyListResult Error: %1").arg(result.error().asString()));
QMessageBox::critical(this, QStringLiteral("Key Listing Result"),
QStringLiteral("KeyListResult Error: %1").arg(QString::fromLatin1(result.error().asString())));
else if (result.isTruncated()) {
QMessageBox::information(this, "Key Listing Result", "KeyListResult is truncated!");
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("KeyListResult is truncated!"));
} else {
QMessageBox::information(this, "Key Listing Result", "Key listing successful");
QMessageBox::information(this, QStringLiteral("Key Listing Result"), QStringLiteral("Key listing successful"));
}
}
......
......@@ -52,8 +52,8 @@ int main(int argc, char **argv)
parser.process(app);
aboutData.processCommandLine(&parser);
Kleo::KeySelectionDialog dlg("Kleo::KeySelectionDialog Test",
"Please select a key:",
Kleo::KeySelectionDialog dlg(QStringLiteral("Kleo::KeySelectionDialog Test"),
QStringLiteral("Please select a key:"),
std::vector<GpgME::Key>(),
Kleo::KeySelectionDialog::AllKeys, true, true);
......
......@@ -185,8 +185,8 @@ public:
QString name, email;
if (key.protocol() == GpgME::OpenPGP) {
name = userID.name();
email = userID.email();
name = QString::fromUtf8(userID.name());
email = QString::fromUtf8(userID.email());
} else {
const Kleo::DN dn(userID.id());
name = dn[QStringLiteral("CN")];
......@@ -330,7 +330,7 @@ void Kleo::KeySelectionCombo::setCurrentKey(const QString &fingerprint)
for (int i = 0; i < d->proxyModel->rowCount(); ++i) {
const auto idx = d->proxyModel->index(i, 0, QModelIndex());
const auto key = d->proxyModel->data(idx, Kleo::KeyListModelInterface::KeyRole).value<GpgME::Key>();
if (!key.isNull() && fingerprint == key.primaryFingerprint()) {
if (!key.isNull() && fingerprint == QString::fromLatin1(key.primaryFingerprint())) {
setCurrentIndex(i);
return;
}
......
......@@ -208,7 +208,7 @@ private:
static QString iconPath(const QString &name)
{
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, "libkleopatra/pics/" + name + ".png");
return QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("libkleopatra/pics/") + name + QStringLiteral(".png"));
}
ColumnStrategy::ColumnStrategy(unsigned int keyUsage)
......
......@@ -402,7 +402,7 @@ const char *Kleo::outputFileExtension(unsigned int classification, bool usePGPFi
bool Kleo::isFingerprint(const QString &fpr)
{
static QRegularExpression fprRegex("[0-9a-fA-F]{40}");
static QRegularExpression fprRegex(QStringLiteral("[0-9a-fA-F]{40}"));
return fprRegex.match(fpr).hasMatch();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment