diff --git a/agents/newmailnotifier/specialnotifierjob.cpp b/agents/newmailnotifier/specialnotifierjob.cpp index fd593006a..027f6603e 100644 --- a/agents/newmailnotifier/specialnotifierjob.cpp +++ b/agents/newmailnotifier/specialnotifierjob.cpp @@ -1,176 +1,176 @@ /* Copyright (C) 2013-2018 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "newmailnotifiershowmessagejob.h" #include "specialnotifierjob.h" #include "newmailnotifieragentsettings.h" #include #include #include #include #include #include #include #include #include "newmailnotifier_debug.h" SpecialNotifierJob::SpecialNotifierJob(const QStringList &listEmails, const QString &path, Akonadi::Item::Id id, QObject *parent) : QObject(parent) , mListEmails(listEmails) , mPath(path) , mItemId(id) { Akonadi::Item item(mItemId); Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(item, this); job->fetchScope().fetchPayloadPart(Akonadi::MessagePart::Envelope, true); connect(job, &Akonadi::ItemFetchJob::result, this, &SpecialNotifierJob::slotItemFetchJobDone); } SpecialNotifierJob::~SpecialNotifierJob() { } void SpecialNotifierJob::setDefaultPixmap(const QPixmap &pixmap) { mDefaultPixmap = pixmap; } void SpecialNotifierJob::slotItemFetchJobDone(KJob *job) { if (job->error()) { qCWarning(NEWMAILNOTIFIER_LOG) << job->errorString(); deleteLater(); return; } const Akonadi::Item::List lst = qobject_cast(job)->items(); if (lst.count() == 1) { const Akonadi::Item item = lst.first(); if (!item.hasPayload()) { qCDebug(NEWMAILNOTIFIER_LOG) << " message has not payload."; deleteLater(); return; } const KMime::Message::Ptr mb = item.payload(); mFrom = mb->from()->asUnicodeString(); mSubject = mb->subject()->asUnicodeString(); if (NewMailNotifierAgentSettings::showPhoto()) { Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob(this); job->setLimit(1); job->setQuery(Akonadi::ContactSearchJob::Email, KEmailAddress::firstEmailAddress(mFrom).toLower(), Akonadi::ContactSearchJob::ExactMatch); connect(job, &Akonadi::ItemFetchJob::result, this, &SpecialNotifierJob::slotSearchJobFinished); } else { emitNotification(mDefaultPixmap); deleteLater(); } } else { qCWarning(NEWMAILNOTIFIER_LOG) << " Found item different from 1: " << lst.count(); deleteLater(); return; } } void SpecialNotifierJob::slotSearchJobFinished(KJob *job) { const Akonadi::ContactSearchJob *searchJob = qobject_cast(job); if (searchJob->error()) { qCWarning(NEWMAILNOTIFIER_LOG) << "Unable to fetch contact:" << searchJob->errorText(); emitNotification(mDefaultPixmap); return; } if (!searchJob->contacts().isEmpty()) { const KContacts::Addressee addressee = searchJob->contacts().at(0); const KContacts::Picture photo = addressee.photo(); const QImage image = photo.data(); if (image.isNull()) { emitNotification(mDefaultPixmap); } else { emitNotification(QPixmap::fromImage(image)); } } else { emitNotification(mDefaultPixmap); } } void SpecialNotifierJob::emitNotification(const QPixmap &pixmap) { if (NewMailNotifierAgentSettings::excludeEmailsFromMe()) { for (const QString &email : qAsConst(mListEmails)) { if (mFrom.contains(email)) { //Exclude this notification deleteLater(); return; } } } QStringList result; if (NewMailNotifierAgentSettings::showFrom()) { result << i18n("From: %1", mFrom.toHtmlEscaped()); } if (NewMailNotifierAgentSettings::showSubject()) { QString subject = mSubject.simplified(); if (subject.length() > 80) { subject.truncate(80); subject += QStringLiteral("..."); } result << i18n("Subject: %1", subject.toHtmlEscaped()); } if (NewMailNotifierAgentSettings::showFolder()) { result << i18n("In: %1", mPath); } if (NewMailNotifierAgentSettings::textToSpeakEnabled()) { if (!NewMailNotifierAgentSettings::textToSpeak().isEmpty()) { QString message = NewMailNotifierAgentSettings::textToSpeak(); - message.replace(QStringLiteral("%s"), mSubject.toHtmlEscaped()); - message.replace(QStringLiteral("%f"), mFrom.toHtmlEscaped()); + message.replace(QLatin1String("%s"), mSubject.toHtmlEscaped()); + message.replace(QLatin1String("%f"), mFrom.toHtmlEscaped()); Q_EMIT say(message); } } if (NewMailNotifierAgentSettings::showButtonToDisplayMail()) { KNotification *notification = new KNotification(QStringLiteral("new-email"), nullptr, NewMailNotifierAgentSettings::keepPersistentNotification() ? KNotification::Persistent | KNotification::SkipGrouping : KNotification::CloseOnTimeout); notification->setText(result.join(QLatin1Char('\n'))); notification->setPixmap(pixmap); notification->setActions(QStringList() << i18n("Show mail...")); connect(notification, QOverload::of(&KNotification::activated), this, &SpecialNotifierJob::slotOpenMail); connect(notification, &KNotification::closed, this, &SpecialNotifierJob::deleteLater); notification->sendEvent(); } else { Q_EMIT displayNotification(pixmap, result.join(QLatin1Char('\n'))); deleteLater(); } } void SpecialNotifierJob::slotOpenMail() { NewMailNotifierShowMessageJob *job = new NewMailNotifierShowMessageJob(mItemId); job->start(); } diff --git a/resources/dav/resource/setupwizard.cpp b/resources/dav/resource/setupwizard.cpp index f46bec5df..6e2be9e25 100644 --- a/resources/dav/resource/setupwizard.cpp +++ b/resources/dav/resource/setupwizard.cpp @@ -1,559 +1,559 @@ /* Copyright (c) 2010 Tobias Koenig This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "setupwizard.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include enum GroupwareServers { Citadel, DAVical, eGroupware, OpenGroupware, ScalableOGo, Scalix, Zarafa, Zimbra }; static QString settingsToUrl(const QWizard *wizard, const QString &protocol) { QString desktopFilePath = wizard->property("providerDesktopFilePath").toString(); if (desktopFilePath.isEmpty()) { return QString(); } KService::Ptr service = KService::serviceByStorageId(desktopFilePath); if (!service) { return QString(); } QStringList supportedProtocols = service->property(QStringLiteral("X-DavGroupware-SupportedProtocols")).toStringList(); if (!supportedProtocols.contains(protocol)) { return QString(); } QString pathPattern; QString pathPropertyName(QStringLiteral("X-DavGroupware-") + protocol + QStringLiteral("Path")); if (service->property(pathPropertyName).isNull()) { return QString(); } pathPattern.append(service->property(pathPropertyName).toString() + QLatin1Char('/')); QString username = wizard->field(QStringLiteral("credentialsUserName")).toString(); QString localPart(username); localPart.remove(QRegExp(QLatin1String("@.*$"))); - pathPattern.replace(QStringLiteral("$user$"), username); - pathPattern.replace(QStringLiteral("$localpart$"), localPart); + pathPattern.replace(QLatin1String("$user$"), username); + pathPattern.replace(QLatin1String("$localpart$"), localPart); QString providerName; if (!service->property(QStringLiteral("X-DavGroupware-Provider")).isNull()) { providerName = service->property(QStringLiteral("X-DavGroupware-Provider")).toString(); } QString localPath = wizard->field(QStringLiteral("installationPath")).toString(); if (!localPath.isEmpty()) { if (providerName == QLatin1String("davical")) { if (!localPath.endsWith(QLatin1Char('/'))) { pathPattern.append(localPath + QLatin1Char('/')); } else { pathPattern.append(localPath); } } else { if (!localPath.startsWith(QLatin1Char('/'))) { pathPattern.prepend(QLatin1Char('/') + localPath); } else { pathPattern.prepend(localPath); } } } QUrl url; if (!wizard->property("usePredefinedProvider").isNull()) { if (service->property(QStringLiteral("X-DavGroupware-ProviderUsesSSL")).toBool()) { url.setScheme(QStringLiteral("https")); } else { url.setScheme(QStringLiteral("http")); } QString hostPropertyName(QStringLiteral("X-DavGroupware-") + protocol + QStringLiteral("Host")); if (service->property(hostPropertyName).isNull()) { return QString(); } url.setHost(service->property(hostPropertyName).toString()); url.setPath(pathPattern); } else { if (wizard->field(QStringLiteral("connectionUseSecureConnection")).toBool()) { url.setScheme(QStringLiteral("https")); } else { url.setScheme(QStringLiteral("http")); } QString host = wizard->field(QStringLiteral("connectionHost")).toString(); if (host.isEmpty()) { return QString(); } QStringList hostParts = host.split(QLatin1Char(':')); url.setHost(hostParts.at(0)); url.setPath(pathPattern); if (hostParts.size() == 2) { int port = hostParts.at(1).toInt(); if (port) { url.setPort(port); } } } return url.toString(); } /* * SetupWizard */ SetupWizard::SetupWizard(QWidget *parent) : QWizard(parent) { setWindowTitle(i18n("DAV groupware configuration wizard")); setWindowIcon(QIcon::fromTheme(QStringLiteral("folder-remote"))); setPage(W_CredentialsPage, new CredentialsPage); setPage(W_PredefinedProviderPage, new PredefinedProviderPage); setPage(W_ServerTypePage, new ServerTypePage); setPage(W_ConnectionPage, new ConnectionPage); setPage(W_CheckPage, new CheckPage); } QString SetupWizard::displayName() const { QString desktopFilePath = property("providerDesktopFilePath").toString(); if (desktopFilePath.isEmpty()) { return QString(); } KService::Ptr service = KService::serviceByStorageId(desktopFilePath); if (!service) { return QString(); } return service->name(); } SetupWizard::Url::List SetupWizard::urls() const { Url::List urls; QString desktopFilePath = property("providerDesktopFilePath").toString(); if (desktopFilePath.isEmpty()) { return urls; } KService::Ptr service = KService::serviceByStorageId(desktopFilePath); if (!service) { return urls; } const QStringList supportedProtocols = service->property(QStringLiteral("X-DavGroupware-SupportedProtocols")).toStringList(); for (const QString &protocol : supportedProtocols) { Url url; if (protocol == QLatin1String("CalDav")) { url.protocol = KDAV::CalDav; } else if (protocol == QLatin1String("CardDav")) { url.protocol = KDAV::CardDav; } else if (protocol == QLatin1String("GroupDav")) { url.protocol = KDAV::GroupDav; } else { return urls; } QString urlStr = settingsToUrl(this, protocol); if (!urlStr.isEmpty()) { url.url = urlStr; url.userName = QStringLiteral("$default$"); urls << url; } } return urls; } /* * CredentialsPage */ CredentialsPage::CredentialsPage(QWidget *parent) : QWizardPage(parent) { setTitle(i18n("Login Credentials")); setSubTitle(i18n("Enter your credentials to login to the groupware server")); QFormLayout *layout = new QFormLayout(this); mUserName = new KLineEdit; layout->addRow(i18n("User"), mUserName); registerField(QStringLiteral("credentialsUserName*"), mUserName); mPassword = new KPasswordLineEdit; layout->addRow(i18n("Password"), mPassword); registerField(QStringLiteral("credentialsPassword*"), mPassword, "password", SIGNAL(passwordChanged(QString))); } int CredentialsPage::nextId() const { QString userName = field(QStringLiteral("credentialsUserName")).toString(); if (userName.endsWith(QLatin1String("@yahoo.com"))) { KService::List offers; offers = KServiceTypeTrader::self()->query(QStringLiteral("DavGroupwareProvider"), QStringLiteral("Name == 'Yahoo!'")); if (offers.isEmpty()) { return SetupWizard::W_ServerTypePage; } wizard()->setProperty("usePredefinedProvider", true); wizard()->setProperty("predefinedProviderName", offers.at(0)->name()); wizard()->setProperty("providerDesktopFilePath", offers.at(0)->entryPath()); return SetupWizard::W_PredefinedProviderPage; } else { return SetupWizard::W_ServerTypePage; } } /* * PredefinedProviderPage */ PredefinedProviderPage::PredefinedProviderPage(QWidget *parent) : QWizardPage(parent) { setTitle(i18n("Predefined provider found")); setSubTitle(i18n("Select if you want to use the auto-detected provider")); QVBoxLayout *layout = new QVBoxLayout(this); mLabel = new QLabel; layout->addWidget(mLabel); mProviderGroup = new QButtonGroup(this); mProviderGroup->setExclusive(true); mUseProvider = new QRadioButton; mProviderGroup->addButton(mUseProvider); mUseProvider->setChecked(true); layout->addWidget(mUseProvider); mDontUseProvider = new QRadioButton(i18n("No, choose another server")); mProviderGroup->addButton(mDontUseProvider); layout->addWidget(mDontUseProvider); } void PredefinedProviderPage::initializePage() { mLabel->setText(i18n("Based on the email address you used as a login, this wizard\n" "can configure automatically an account for %1 services.\n" "Do you wish to do so?", wizard()->property("predefinedProviderName").toString())); mUseProvider->setText(i18n("Yes, use %1 as provider", wizard()->property("predefinedProviderName").toString())); } int PredefinedProviderPage::nextId() const { if (mUseProvider->isChecked()) { return SetupWizard::W_CheckPage; } else { wizard()->setProperty("usePredefinedProvider", QVariant()); wizard()->setProperty("providerDesktopFilePath", QVariant()); return SetupWizard::W_ServerTypePage; } } /* * ServerTypePage */ bool compareServiceOffers(const QPair &off1, const QPair &off2) { return off1.first.toLower() < off2.first.toLower(); } ServerTypePage::ServerTypePage(QWidget *parent) : QWizardPage(parent) { setTitle(i18n("Groupware Server")); setSubTitle(i18n("Select the groupware server the resource shall be configured for")); mProvidersCombo = new QComboBox(this); mProvidersCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); KServiceTypeTrader *trader = KServiceTypeTrader::self(); const KService::List providers = trader->query(QStringLiteral("DavGroupwareProvider")); QList< QPair > offers; offers.reserve(providers.count()); for (const KService::Ptr &provider : providers) { offers.append(QPair(provider->name(), provider->entryPath())); } std::sort(offers.begin(), offers.end(), compareServiceOffers); QListIterator< QPair > it(offers); while (it.hasNext()) { QPair p = it.next(); mProvidersCombo->addItem(p.first, p.second); } registerField(QStringLiteral("provider"), mProvidersCombo, "currentText"); QVBoxLayout *layout = new QVBoxLayout(this); mServerGroup = new QButtonGroup(this); mServerGroup->setExclusive(true); QHBoxLayout *hLayout = new QHBoxLayout; QRadioButton *button = new QRadioButton(i18n("Use one of those servers:")); registerField(QStringLiteral("templateConfiguration"), button); mServerGroup->addButton(button); mServerGroup->setId(button, 0); button->setChecked(true); hLayout->addWidget(button); hLayout->addWidget(mProvidersCombo); layout->addLayout(hLayout); button = new QRadioButton(i18n("Configure the resource manually")); connect(button, &QRadioButton::toggled, this, &ServerTypePage::manualConfigToggled); registerField(QStringLiteral("manualConfiguration"), button); mServerGroup->addButton(button); mServerGroup->setId(button, 1); layout->addWidget(button); layout->addStretch(1); } void ServerTypePage::manualConfigToggled(bool state) { setFinalPage(state); wizard()->button(QWizard::NextButton)->setEnabled(!state); } bool ServerTypePage::validatePage() { QVariant desktopFilePath = mProvidersCombo->itemData(mProvidersCombo->currentIndex()); if (desktopFilePath.isNull()) { return false; } else { wizard()->setProperty("providerDesktopFilePath", desktopFilePath); return true; } } /* * ConnectionPage */ ConnectionPage::ConnectionPage(QWidget *parent) : QWizardPage(parent) , mPreviewLayout(nullptr) , mCalDavUrlPreview(nullptr) , mCardDavUrlPreview(nullptr) , mGroupDavUrlPreview(nullptr) { setTitle(i18n("Connection")); setSubTitle(i18n("Enter the connection information for the groupware server")); mLayout = new QFormLayout(this); QRegExp hostnameRegexp(QStringLiteral("^[a-z0-9][.a-z0-9-]*[a-z0-9](?::[0-9]+)?$")); mHost = new KLineEdit; registerField(QStringLiteral("connectionHost*"), mHost); mHost->setValidator(new QRegExpValidator(hostnameRegexp, this)); mLayout->addRow(i18n("Host"), mHost); mPath = new KLineEdit; mLayout->addRow(i18n("Installation path"), mPath); registerField(QStringLiteral("installationPath"), mPath); mUseSecureConnection = new QCheckBox(i18n("Use secure connection")); mUseSecureConnection->setChecked(true); registerField(QStringLiteral("connectionUseSecureConnection"), mUseSecureConnection); mLayout->addRow(QString(), mUseSecureConnection); connect(mHost, &KLineEdit::textChanged, this, &ConnectionPage::urlElementChanged); connect(mPath, &KLineEdit::textChanged, this, &ConnectionPage::urlElementChanged); connect(mUseSecureConnection, &QCheckBox::toggled, this, &ConnectionPage::urlElementChanged); } void ConnectionPage::initializePage() { KService::Ptr service = KService::serviceByStorageId(wizard()->property("providerDesktopFilePath").toString()); if (!service) { return; } QString providerInstallationPath = service->property(QStringLiteral("X-DavGroupware-InstallationPath")).toString(); if (!providerInstallationPath.isEmpty()) { mPath->setText(providerInstallationPath); } QStringList supportedProtocols = service->property(QStringLiteral("X-DavGroupware-SupportedProtocols")).toStringList(); mPreviewLayout = new QFormLayout; mLayout->addRow(mPreviewLayout); if (supportedProtocols.contains(QLatin1String("CalDav"))) { mCalDavUrlLabel = new QLabel(i18n("Final URL (CalDav)")); mCalDavUrlPreview = new QLabel; mPreviewLayout->addRow(mCalDavUrlLabel, mCalDavUrlPreview); } if (supportedProtocols.contains(QLatin1String("CardDav"))) { mCardDavUrlLabel = new QLabel(i18n("Final URL (CardDav)")); mCardDavUrlPreview = new QLabel; mPreviewLayout->addRow(mCardDavUrlLabel, mCardDavUrlPreview); } if (supportedProtocols.contains(QLatin1String("GroupDav"))) { mGroupDavUrlLabel = new QLabel(i18n("Final URL (GroupDav)")); mGroupDavUrlPreview = new QLabel; mPreviewLayout->addRow(mGroupDavUrlLabel, mGroupDavUrlPreview); } } void ConnectionPage::cleanupPage() { delete mPreviewLayout; if (mCalDavUrlPreview) { delete mCalDavUrlLabel; delete mCalDavUrlPreview; mCalDavUrlPreview = nullptr; } if (mCardDavUrlPreview) { delete mCardDavUrlLabel; delete mCardDavUrlPreview; mCardDavUrlPreview = nullptr; } if (mGroupDavUrlPreview) { delete mGroupDavUrlLabel; delete mGroupDavUrlPreview; mGroupDavUrlPreview = nullptr; } QWizardPage::cleanupPage(); } void ConnectionPage::urlElementChanged() { if (mHost->text().isEmpty()) { if (mCalDavUrlPreview) { mCalDavUrlPreview->setText(QStringLiteral("-")); } if (mCardDavUrlPreview) { mCardDavUrlPreview->setText(QStringLiteral("-")); } if (mGroupDavUrlPreview) { mGroupDavUrlPreview->setText(QStringLiteral("-")); } } else { if (mCalDavUrlPreview) { mCalDavUrlPreview->setText(settingsToUrl(this->wizard(), QStringLiteral("CalDav"))); } if (mCardDavUrlPreview) { mCardDavUrlPreview->setText(settingsToUrl(this->wizard(), QStringLiteral("CardDav"))); } if (mGroupDavUrlPreview) { mGroupDavUrlPreview->setText(settingsToUrl(this->wizard(), QStringLiteral("GroupDav"))); } } } /* * CheckPage */ CheckPage::CheckPage(QWidget *parent) : QWizardPage(parent) { setTitle(i18n("Test Connection")); setSubTitle(i18n("You can test now whether the groupware server can be accessed with the current configuration")); setFinalPage(true); QVBoxLayout *layout = new QVBoxLayout(this); QPushButton *button = new QPushButton(i18n("Test Connection")); layout->addWidget(button); mStatusLabel = new QTextBrowser; layout->addWidget(mStatusLabel); connect(button, &QRadioButton::clicked, this, &CheckPage::checkConnection); } void CheckPage::checkConnection() { mStatusLabel->clear(); KDAV::DavUrl::List davUrls; // convert list of SetupWizard::Url to list of KDAV::DavUrl const SetupWizard::Url::List urls = static_cast(wizard())->urls(); for (const SetupWizard::Url &url : urls) { KDAV::DavUrl davUrl; davUrl.setProtocol(url.protocol); QUrl serverUrl(url.url); serverUrl.setUserName(wizard()->field(QStringLiteral("credentialsUserName")).toString()); serverUrl.setPassword(wizard()->field(QStringLiteral("credentialsPassword")).toString()); davUrl.setUrl(serverUrl); davUrls << davUrl; } // start the dav collections fetch job to test connectivity KDAV::DavCollectionsMultiFetchJob *job = new KDAV::DavCollectionsMultiFetchJob(davUrls, this); connect(job, &KDAV::DavCollectionsMultiFetchJob::result, this, &CheckPage::onFetchDone); job->start(); } void CheckPage::onFetchDone(KJob *job) { QString msg; QPixmap icon; if (job->error()) { msg = i18n("An error occurred: %1", job->errorText()); icon = QIcon::fromTheme(QStringLiteral("dialog-close")).pixmap(16, 16); } else { msg = i18n("Connected successfully"); icon = QIcon::fromTheme(QStringLiteral("dialog-ok-apply")).pixmap(16, 16); } mStatusLabel->setHtml(QStringLiteral(" %1").arg(msg)); mStatusLabel->document()->addResource(QTextDocument::ImageResource, QUrl(QStringLiteral("icon")), QVariant(icon)); } diff --git a/resources/openxchange/oxa/oxutils.cpp b/resources/openxchange/oxa/oxutils.cpp index c9fd17742..ff549ff4c 100644 --- a/resources/openxchange/oxa/oxutils.cpp +++ b/resources/openxchange/oxa/oxutils.cpp @@ -1,128 +1,128 @@ /* This file is part of oxaccess. Copyright (c) 2009 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "oxutils.h" #include using namespace OXA; QString OXUtils::writeBoolean(bool value) { return value ? QStringLiteral("true") : QStringLiteral("false"); } QString OXUtils::writeNumber(qlonglong value) { return QString::number(value); } QString OXUtils::writeString(const QString &value) { QStringList lines = value.split(QLatin1Char('\n')); for (int i = 0; i < lines.count(); ++i) { lines[i].replace(QLatin1Char('\\'), QStringLiteral("\\\\")); lines[i].replace(QLatin1Char('"'), QStringLiteral("\\\"")); } return lines.join(QLatin1Char('\n')); } QString OXUtils::writeName(const QString &value) { //TODO: assert on invalid names return value; } QString OXUtils::writeDateTime(const QDateTime &value) { QString result; //workaround, as QDateTime does not support negative time_t values QDateTime Time_t_S(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::UTC); if (value < Time_t_S) { result = QString::number(Time_t_S.secsTo(value)); } else { result = QString::number(value.toUTC().toTime_t()); } return QString(result + QLatin1String("000")); } QString OXUtils::writeDate(const QDate &value) { return writeDateTime(QDateTime(value, QTime(0, 0, 0), Qt::UTC)); } bool OXUtils::readBoolean(const QString &text) { if (text == QLatin1String("true")) { return true; } else if (text == QLatin1String("false")) { return false; } else { Q_ASSERT(false); return false; } } qlonglong OXUtils::readNumber(const QString &text) { return text.toLongLong(); } QString OXUtils::readString(const QString &text) { QString value(text); - value.replace(QStringLiteral("\\\""), QStringLiteral("\"")); - value.replace(QStringLiteral("\\\\"), QStringLiteral("\\")); + value.replace(QLatin1String("\\\""), QLatin1String("\"")); + value.replace(QLatin1String("\\\\"), QLatin1String("\\")); return value; } QString OXUtils::readName(const QString &text) { return text; } QDateTime OXUtils::readDateTime(const QString &text) { // remove the trailing '000', they exceed the integer dimension const int ticks = text.mid(0, text.length() - 3).toLongLong(); //workaround, as QDateTime does not support negative time_t values QDateTime value; if (ticks < 0) { value.setTime_t(0); value = value.addSecs(ticks); } else { value.setTime_t(ticks); } return value; } QDate OXUtils::readDate(const QString &text) { return readDateTime(text).date(); }