Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit cbdb08b9 authored by Laurent Montel's avatar Laurent Montel 😁

Minor optimization

parent 492b9441
......@@ -46,7 +46,7 @@ void EwsAutodiscoveryJob::start()
void EwsAutodiscoveryJob::parseEmail()
{
int atIndex = mEmail.indexOf(QChar::fromLatin1('@'));
int atIndex = mEmail.indexOf(QLatin1Char('@'));
if (atIndex < 0) {
setErrorMsg(i18n("Incorrect email address"));
emitResult();
......
......@@ -93,14 +93,15 @@ EwsAttachment::EwsAttachment(QXmlStreamReader &reader)
return;
}
if (reader.name() == QStringLiteral("ItemAttachment")) {
const QStringRef readerName = reader.name();
if (readerName == QStringLiteral("ItemAttachment")) {
d->mType = ItemAttachment;
} else if (reader.name() == QStringLiteral("FileAttachment")) {
} else if (readerName == QStringLiteral("FileAttachment")) {
d->mType = FileAttachment;
} else if (reader.name() == QStringLiteral("ReferenceAttachment")) {
} else if (readerName == QStringLiteral("ReferenceAttachment")) {
d->mType = ReferenceAttachment;
} else {
qCWarningNC(EWSCLI_LOG) << QStringLiteral("Unknown attachment type %1").arg(reader.name().toString());
qCWarningNC(EWSCLI_LOG) << QStringLiteral("Unknown attachment type %1").arg(readerName.toString());
ok = false;
}
......@@ -121,7 +122,7 @@ EwsAttachment::EwsAttachment(QXmlStreamReader &reader)
break;
}
QString elmName = reader.name().toString();
const QString elmName = reader.name().toString();
if (elmName == QStringLiteral("AttachmentId")) {
QXmlStreamAttributes attrs = reader.attributes();
if (!attrs.hasAttribute(QStringLiteral("Id"))) {
......
......@@ -69,23 +69,24 @@ EwsAttendee::EwsAttendee(QXmlStreamReader &reader)
return;
}
if (reader.name() == QStringLiteral("Mailbox")) {
const QStringRef readerName = reader.name();
if (readerName == QStringLiteral("Mailbox")) {
d->mMailbox = EwsMailbox(reader);
if (!d->mMailbox.isValid()) {
qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read EWS request - invalid attendee %1 element.")
.arg(reader.name().toString());
.arg(readerName.toString());
return;
}
} else if (reader.name() == QStringLiteral("ResponseType")) {
} else if (readerName == QStringLiteral("ResponseType")) {
bool ok;
d->mResponse = decodeEnumString<EwsEventResponseType>(reader.readElementText(),
responseTypeNames, responseTypeNameCount, &ok);
if (reader.error() != QXmlStreamReader::NoError || !ok) {
qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read EWS request - invalid attendee %1 element.")
.arg(reader.name().toString());
.arg(readerName.toString());
return;
}
} else if (reader.name() == QStringLiteral("LastResponseTime")) {
} else if (readerName == QStringLiteral("LastResponseTime")) {
// Unsupported - ignore
//qCWarningNC(EWSCLIENT_LOG) << QStringLiteral("Unsupported mailbox element %1").arg(reader.name().toString());
reader.skipCurrentElement();
......
......@@ -44,7 +44,7 @@ void EwsCreateFolderRequest::start()
writer.writeEndElement();
writer.writeStartElement(ewsMsgNsUri, QStringLiteral("Folders"));
Q_FOREACH (const EwsFolder &folder, mFolders) {
for (const EwsFolder &folder : qAsConst(mFolders)) {
folder.write(writer);
}
writer.writeEndElement();
......
......@@ -47,7 +47,7 @@ void EwsDeleteFolderRequest::start()
writer.writeAttribute(QStringLiteral("DeleteType"), deleteTypes[mType]);
writer.writeStartElement(ewsMsgNsUri, QStringLiteral("FolderIds"));
Q_FOREACH (const EwsId &id, mIds) {
for (const EwsId &id : qAsConst(mIds)) {
id.writeFolderIds(writer);
}
writer.writeEndElement();
......
......@@ -47,7 +47,7 @@ void EwsDeleteItemRequest::start()
writer.writeAttribute(QStringLiteral("DeleteType"), deleteTypes[mType]);
writer.writeStartElement(ewsMsgNsUri, QStringLiteral("ItemIds"));
Q_FOREACH (const EwsId &id, mIds) {
for (const EwsId &id : qAsConst(mIds)) {
id.writeItemIds(writer);
}
writer.writeEndElement();
......
......@@ -95,38 +95,38 @@ EwsEffectiveRights::EwsEffectiveRights(QXmlStreamReader &reader)
<< reader.namespaceUri();
return;
}
if (reader.name() == QStringLiteral("CreateAssociated")) {
const QStringRef readerName = reader.name();
if (readerName == QStringLiteral("CreateAssociated")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateAssociated)) {
return;
}
} else if (reader.name() == QStringLiteral("CreateContents")) {
} else if (readerName == QStringLiteral("CreateContents")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateContents)) {
return;
}
} else if (reader.name() == QStringLiteral("CreateHierarchy")) {
} else if (readerName == QStringLiteral("CreateHierarchy")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::CreateHierarchy)) {
return;
}
} else if (reader.name() == QStringLiteral("Delete")) {
} else if (readerName == QStringLiteral("Delete")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::Delete)) {
return;
}
} else if (reader.name() == QStringLiteral("Modify")) {
} else if (readerName == QStringLiteral("Modify")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::Modify)) {
return;
}
} else if (reader.name() == QStringLiteral("Read")) {
} else if (readerName == QStringLiteral("Read")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::Read)) {
return;
}
} else if (reader.name() == QStringLiteral("ViewPrivateItems")) {
} else if (readerName == QStringLiteral("ViewPrivateItems")) {
if (!d->readRight(reader, EwsEffectiveRightsPrivate::ViewPrivateItems)) {
return;
}
} else {
qCWarning(EWSCLI_LOG) << QStringLiteral("Failed to read %1 element - unknown element: %2.")
.arg(QStringLiteral("EffectiveRights"), reader.name().toString());
.arg(QStringLiteral("EffectiveRights"), readerName.toString());
return;
}
}
......
......@@ -163,7 +163,7 @@ EwsEventRequestBase::Notification::Notification(QXmlStreamReader &reader)
bool EwsEventRequestBase::Notification::eventsReader(QXmlStreamReader &reader, QVariant &val)
{
Event::List events = val.value<Event::List>();
QString elmName(reader.name().toString());
const QString elmName(reader.name().toString());
Event event(reader);
if (!event.isValid()) {
......
......@@ -195,11 +195,12 @@ bool EwsFindFolderResponse::parseRootFolder(QXmlStreamReader &reader)
EwsFolder* EwsFindFolderResponse::readFolder(QXmlStreamReader &reader)
{
EwsFolder *folder = nullptr;
if (reader.name() == QStringLiteral("Folder") ||
reader.name() == QStringLiteral("CalendarFolder") ||
reader.name() == QStringLiteral("ContactsFolder") ||
reader.name() == QStringLiteral("TasksFolder") ||
reader.name() == QStringLiteral("SearchFolder")) {
const QStringRef readerName = reader.name();
if (readerName == QStringLiteral("Folder") ||
readerName == QStringLiteral("CalendarFolder") ||
readerName == QStringLiteral("ContactsFolder") ||
readerName == QStringLiteral("TasksFolder") ||
readerName == QStringLiteral("SearchFolder")) {
folder = new EwsFolder(reader);
if (!folder->isValid()) {
setErrorMsg(QStringLiteral("Failed to read EWS request - invalid %1 element.")
......@@ -212,7 +213,7 @@ EwsFolder* EwsFindFolderResponse::readFolder(QXmlStreamReader &reader)
EwsClient::folderHash[(*folder)[EwsFolderFieldFolderId].value<EwsId>().id()] = dn.toString();
}
} else {
qCWarning(EWSCLI_LOG).noquote() << QStringLiteral("Unsupported folder type %1").arg(reader.name().toString());
qCWarning(EWSCLI_LOG).noquote() << QStringLiteral("Unsupported folder type %1").arg(readerName.toString());
reader.skipCurrentElement();
}
......
......@@ -252,26 +252,27 @@ bool EwsFindItemResponse::parseRootFolder(QXmlStreamReader &reader)
EwsItem* EwsFindItemResponse::readItem(QXmlStreamReader &reader)
{
EwsItem *item = nullptr;
if (reader.name() == QStringLiteral("Item") ||
reader.name() == QStringLiteral("Message") ||
reader.name() == QStringLiteral("CalendarItem") ||
reader.name() == QStringLiteral("Contact") ||
reader.name() == QStringLiteral("DistributionList") ||
reader.name() == QStringLiteral("MeetingMessage") ||
reader.name() == QStringLiteral("MeetingRequest") ||
reader.name() == QStringLiteral("MeetingResponse") ||
reader.name() == QStringLiteral("MeetingCancellation") ||
reader.name() == QStringLiteral("Task")) {
qCDebug(EWSCLI_LOG).noquote() << QStringLiteral("Processing %1").arg(reader.name().toString());
const QStringRef readerName = reader.name();
if (readerName == QStringLiteral("Item") ||
readerName == QStringLiteral("Message") ||
readerName == QStringLiteral("CalendarItem") ||
readerName == QStringLiteral("Contact") ||
readerName == QStringLiteral("DistributionList") ||
readerName == QStringLiteral("MeetingMessage") ||
readerName == QStringLiteral("MeetingRequest") ||
readerName == QStringLiteral("MeetingResponse") ||
readerName == QStringLiteral("MeetingCancellation") ||
readerName == QStringLiteral("Task")) {
qCDebug(EWSCLI_LOG).noquote() << QStringLiteral("Processing %1").arg(readerName.toString());
item = new EwsItem(reader);
if (!item->isValid()) {
setErrorMsg(QStringLiteral("Failed to read EWS request - invalid %1 element.")
.arg(reader.name().toString()));
.arg(readerName.toString()));
delete item;
return nullptr;
}
} else {
qCWarning(EWSCLI_LOG).noquote() << QStringLiteral("Unsupported folder type %1").arg(reader.name().toString());
qCWarning(EWSCLI_LOG).noquote() << QStringLiteral("Unsupported folder type %1").arg(readerName.toString());
reader.skipCurrentElement();
}
......
......@@ -419,13 +419,13 @@ EwsItem::EwsItem(QXmlStreamReader &reader)
EwsItemPrivate *d = reinterpret_cast<EwsItemPrivate*>(this->d.data());
// Check what item type are we
QStringRef elmName = reader.name();
const QStringRef elmName = reader.name();
if (elmName == QStringLiteral("Item")) {
d->mType = EwsItemTypeItem;
QStringRef subtype = reader.attributes().value(QStringLiteral("xsi:type"));
const QStringRef subtype = reader.attributes().value(QStringLiteral("xsi:type"));
if (!subtype.isEmpty()) {
auto tokens = subtype.split(QChar::fromLatin1(':'));
QStringRef type = tokens.size() == 1 ? tokens[0] : tokens[1];
auto tokens = subtype.split(QLatin1Char(':'));
const QStringRef type = tokens.size() == 1 ? tokens[0] : tokens[1];
if (type == QStringLiteral("AbchPersonItemType")) {
d->mType = EwsItemTypeAbchPerson;
}
......
......@@ -319,7 +319,7 @@ void EwsPropertyField::write(QXmlStreamWriter &writer) const
case IndexedField: {
writer.writeStartElement(ewsTypeNsUri, QStringLiteral("IndexedFieldURI"));
writer.writeAttribute(QStringLiteral("FieldURI"), d->mUri);
QStringList tokens = d->mUri.split(QChar::fromLatin1(':'));
QStringList tokens = d->mUri.split(QLatin1Char(':'));
writer.writeAttribute(QStringLiteral("FieldIndex"), tokens[1] + QString::number(d->mIndex));
writer.writeEndElement();
break;
......@@ -382,7 +382,7 @@ bool EwsPropertyField::read(QXmlStreamReader &reader)
return false;
}
QString uri = attrs.value(QStringLiteral("FieldURI")).toString();
QStringList tokens = uri.split(QChar::fromLatin1(':'));
QStringList tokens = uri.split(QLatin1Char(':'));
QString indexStr = attrs.value(QStringLiteral("FieldIndex")).toString();
if (!indexStr.startsWith(tokens[1])) {
qCWarningNC(EWSCLI_LOG) << QStringLiteral("Error reading property field - malformed %1 attribute.")
......@@ -542,7 +542,7 @@ bool EwsPropertyField::writeWithValue(QXmlStreamWriter &writer, const QVariant &
{
switch (d->mPropType) {
case Field: {
QStringList tokens = d->mUri.split(QChar::fromLatin1(':'));
QStringList tokens = d->mUri.split(QLatin1Char(':'));
if (tokens.size() != 2) {
qCWarningNC(EWSCLI_LOG) << QStringLiteral("Invalid field URI: %1").arg(d->mUri);
return false;
......@@ -553,7 +553,7 @@ bool EwsPropertyField::writeWithValue(QXmlStreamWriter &writer, const QVariant &
break;
}
case IndexedField: {
QStringList tokens = d->mUri.split(QChar::fromLatin1(':'));
QStringList tokens = d->mUri.split(QLatin1Char(':'));
if (tokens.size() != 2) {
qCWarningNC(EWSCLI_LOG) << QStringLiteral("Invalid field URI: %1").arg(d->mUri);
return false;
......
......@@ -551,7 +551,7 @@ bool EwsRecurrence::readDow(QXmlStreamReader &reader, QBitArray &dow)
{
bool ok;
QString text = reader.readElementText();
QStringList days = text.split(QChar::fromLatin1(' '));
QStringList days = text.split(QLatin1Char(' '));
Q_FOREACH (const QString &day, days) {
short dowIndex = decodeEnumString<short>(day, dayOfWeekNames, dayOfWeekNameCount, &ok);
if (reader.error() != QXmlStreamReader::NoError || !ok) {
......
......@@ -461,7 +461,7 @@ void EwsResource::passwordRequestFinished(const QString &password)
if (mSettings->domain().isEmpty()) {
mEwsClient.setCredentials(mSettings->username(), mPassword);
} else {
mEwsClient.setCredentials(mSettings->domain() + QChar::fromLatin1('\\') + mSettings->username(), mPassword);
mEwsClient.setCredentials(mSettings->domain() + QLatin1Char('\\') + mSettings->username(), mPassword);
}
mSettings->save();
if (mSettings->baseUrl().isEmpty()) {
......
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