Commit e23334dc authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent c805c7fb
Pipeline #60420 passed with stage
in 23 minutes and 17 seconds
......@@ -56,7 +56,7 @@ void FollowUpReminderFinishTaskJob::slotItemFetchJobDone(KJob *job)
deleteLater();
return;
}
KCalendarCore::Todo::Ptr todo = item.payload<KCalendarCore::Todo::Ptr>();
auto todo = item.payload<KCalendarCore::Todo::Ptr>();
todo->setCompleted(true);
Akonadi::Item updateItem = item;
updateItem.setPayload<KCalendarCore::Todo::Ptr>(todo);
......
......@@ -62,7 +62,7 @@ void FollowUpReminderJob::slotItemFetchJobDone(KJob *job)
deleteLater();
return;
}
const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
const auto msg = item.payload<KMime::Message::Ptr>();
if (msg) {
KMime::Headers::InReplyTo *replyTo = msg->inReplyTo(false);
if (replyTo) {
......
......@@ -239,7 +239,7 @@ void FilterManager::Private::beginFiltering(const Akonadi::Item &item) const
if (FilterLog::instance()->isLogging()) {
FilterLog::instance()->addSeparator();
if (item.hasPayload<KMime::Message::Ptr>()) {
KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
auto msg = item.payload<KMime::Message::Ptr>();
const QString subject = msg->subject()->asUnicodeString();
const QString from = msg->from()->asUnicodeString();
const QDateTime dateTime = msg->date()->dateTime();
......@@ -427,7 +427,7 @@ bool FilterManager::process(const Akonadi::Item &item, bool needsFullPayload, co
bool FilterManager::processContextItem(ItemContext context)
{
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
const auto msg = context.item().payload<KMime::Message::Ptr>();
msg->assemble();
auto col = Akonadi::EntityTreeModel::updatedCollection(MailCommon::Kernel::self()->kernelIf()->collectionModel(), context.item().parentCollection());
......
......@@ -40,7 +40,7 @@ public:
{
if (role == Qt::CheckStateRole) {
// Make top-level collections uncheckable
const Akonadi::Collection col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (col.parentCollection() == Akonadi::Collection::root()) {
return {};
}
......@@ -52,7 +52,7 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const override
{
// Make top-level collections uncheckable
const Akonadi::Collection col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (col.parentCollection() == Akonadi::Collection::root()) {
return QSortFilterProxyModel::flags(index) & ~Qt::ItemIsUserCheckable;
} else {
......@@ -64,7 +64,7 @@ public:
{
// Hide ourselves
const auto sourceIndex = sourceModel()->index(source_row, 0, source_parent);
const Akonadi::Collection col = sourceModel()->data(sourceIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto col = sourceModel()->data(sourceIndex, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
return !UnifiedMailboxManager::isUnifiedMailbox(col);
}
};
......
......@@ -594,7 +594,7 @@ void KTNEFMain::createOpenWithMenu(QMenu *topMenu)
void KTNEFMain::slotOpenWithAction(QAction *act)
{
KService::Ptr app = act->data().value<KService::Ptr>();
auto app = act->data().value<KService::Ptr>();
openWith(app);
}
......@@ -198,7 +198,7 @@ void CollectionMailingListPage::slotFetchDone(KJob *job)
for (int i = --num; (i > num - maxchecks) && (i >= 0); --i) {
Akonadi::Item item = items[i];
if (item.hasPayload<KMime::Message::Ptr>()) {
KMime::Message::Ptr message = item.payload<KMime::Message::Ptr>();
auto message = item.payload<KMime::Message::Ptr>();
mMailingList = MessageCore::MailingList::detect(message);
if (mMailingList.features() & MailingList::Post) {
break;
......
......@@ -101,7 +101,7 @@ void AttachmentController::selectionChanged()
AttachmentPart::List selectedParts;
selectedParts.reserve(selectedRows.count());
for (const QModelIndex &index : selectedRows) {
AttachmentPart::Ptr part = mView->model()->data(index, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
auto part = mView->model()->data(index, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
selectedParts.append(part);
}
setSelectedParts(selectedParts);
......@@ -132,7 +132,7 @@ void AttachmentController::doubleClicked(const QModelIndex &itemClicked)
// The itemClicked index will contain the column information. But we want to retrieve
// the AttachmentPart, so we must recreate the QModelIndex without the column information
const QModelIndex &properItemClickedIndex = mView->model()->index(itemClicked.row(), 0);
AttachmentPart::Ptr part = mView->model()->data(properItemClickedIndex, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
auto part = mView->model()->data(properItemClickedIndex, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
// We can't edit encapsulated messages, but we can view them.
if (part->isMessageOrMessageCollection()) {
......
......@@ -112,7 +112,7 @@ void AttachmentView::keyPressEvent(QKeyEvent *event)
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
toRemove.reserve(selectedIndexes.count());
for (const QModelIndex &index : selectedIndexes) {
AttachmentPart::Ptr part = model()->data(index, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
auto part = model()->data(index, MessageComposer::AttachmentModel::AttachmentPartRole).value<AttachmentPart::Ptr>();
toRemove.append(part);
}
for (const AttachmentPart::Ptr &part : qAsConst(toRemove)) {
......
......@@ -2209,7 +2209,7 @@ bool KMComposerWin::insertFromMimeData(const QMimeData *source, bool forceAttach
if (!forceAttachment) {
if (mComposerBase->editor()->textMode()
== MessageComposer::RichTextComposerNg::Rich /*&& mComposerBase->editor()->isEnableImageActions() Necessary ?*/) {
QImage image = qvariant_cast<QImage>(source->imageData());
auto image = qvariant_cast<QImage>(source->imageData());
QFileInfo fi(source->text());
QMenu menu(this);
......@@ -2376,14 +2376,14 @@ void KMComposerWin::slotFetchJob(KJob *job)
for (const Akonadi::Item &item : items) {
QString attachmentName = QStringLiteral("attachment");
if (item.hasPayload<KContacts::Addressee>()) {
const KContacts::Addressee contact = item.payload<KContacts::Addressee>();
const auto contact = item.payload<KContacts::Addressee>();
attachmentName = contact.realName() + QLatin1String(".vcf");
// Workaround about broken kaddressbook fields.
QByteArray data = item.payloadData();
KContacts::adaptIMAttributes(data);
addAttachment(attachmentName, KMime::Headers::CEbase64, QString(), data, "text/x-vcard");
} else if (item.hasPayload<KContacts::ContactGroup>()) {
const KContacts::ContactGroup group = item.payload<KContacts::ContactGroup>();
const auto group = item.payload<KContacts::ContactGroup>();
attachmentName = group.name() + QLatin1String(".vcf");
auto expandJob = new Akonadi::ContactGroupExpandJob(group, this);
expandJob->setProperty("groupName", attachmentName);
......
......@@ -83,7 +83,7 @@ void FolderShortcutActionManager::updateShortcutsForIndex(const QModelIndex &par
for (int i = start; i <= end; ++i) {
if (model->hasIndex(i, 0, parent)) {
const QModelIndex child = model->index(i, 0, parent);
Akonadi::Collection collection = model->data(child, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
auto collection = model->data(child, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection.isValid()) {
shortcutChanged(collection);
}
......
......@@ -27,7 +27,7 @@ AddEmailToExistingContactJob::~AddEmailToExistingContactJob() = default;
void AddEmailToExistingContactJob::start()
{
if (mItem.hasPayload<KContacts::Addressee>()) {
KContacts::Addressee address = mItem.payload<KContacts::Addressee>();
auto address = mItem.payload<KContacts::Addressee>();
QStringList emails = address.emails();
if (emails.contains(mEmail)) {
emitResult();
......
......@@ -50,7 +50,7 @@ void CreateFollowupReminderOnExistingMessageJob::itemFetchJobDone(KJob *job)
deleteLater();
return;
}
KMime::Message::Ptr msg = mMessageItem.payload<KMime::Message::Ptr>();
auto msg = mMessageItem.payload<KMime::Message::Ptr>();
if (msg) {
auto reminderJob = new MessageComposer::FollowupReminderCreateJob(this);
KMime::Headers::MessageID *messageID = msg->messageID(false);
......
......@@ -36,7 +36,7 @@ void RemoveDuplicateMailJob::start()
Akonadi::Collection::List collections;
for (const QModelIndex &index : indexes) {
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (collection.isValid()) {
collections << collection;
}
......
......@@ -1217,7 +1217,7 @@ void KMMainWidget::slotCollectionChanged(const Akonadi::Collection &collection,
const QModelIndex idx = Akonadi::EntityTreeModel::modelIndexForCollection(KMKernel::self()->collectionModel(), collection);
if (idx.isValid()) {
const QString text = idx.data().toString();
const QIcon icon = idx.data(Qt::DecorationRole).value<QIcon>();
const auto icon = idx.data(Qt::DecorationRole).value<QIcon>();
mMessagePane->updateTabIconText(collection, text, icon);
}
}
......@@ -1370,7 +1370,7 @@ void KMMainWidget::slotNewFromTemplate(QAction *action)
if (!mTemplateFolder.isValid()) {
return;
}
const Akonadi::Item item = action->data().value<Akonadi::Item>();
const auto item = action->data().value<Akonadi::Item>();
newFromTemplate(item);
}
......@@ -2019,7 +2019,7 @@ void KMMainWidget::slotNewMessageToRecipients()
return;
}
ComposeNewMessageJob *job = new ComposeNewMessageJob;
auto *job = new ComposeNewMessageJob;
job->setFolderSettings(mCurrentFolderSettings);
job->setCurrentCollection(mCurrentCollection);
job->setRecipientsFromMessage(selectedMessages.constFirst());
......@@ -2601,11 +2601,11 @@ void KMMainWidget::slotContactSearchJobForMessagePopupDone(KJob *job)
} else {
mMsgView->clearContactItem();
}
const Akonadi::Item msg = job->property("msg").value<Akonadi::Item>();
const auto msg = job->property("msg").value<Akonadi::Item>();
const QPoint aPoint = job->property("point").toPoint();
const QUrl imageUrl = job->property("imageUrl").toUrl();
const QUrl url = job->property("url").toUrl();
const WebEngineViewer::WebHitTestResult result = job->property("webhitresult").value<WebEngineViewer::WebHitTestResult>();
const auto result = job->property("webhitresult").value<WebEngineViewer::WebHitTestResult>();
showMessagePopup(msg, url, imageUrl, aPoint, contactAlreadyExists, uniqueContactFound, result);
}
......
......@@ -362,7 +362,7 @@ void KMReaderMainWin::slotForwardAttachedMessage()
void KMReaderMainWin::slotNewMessageToRecipients()
{
ComposeNewMessageJob *job = new ComposeNewMessageJob;
auto *job = new ComposeNewMessageJob;
const Akonadi::Collection parentCol = mReaderWin->messageItem().parentCollection();
if (parentCol.isValid()) {
......@@ -568,7 +568,7 @@ void KMReaderMainWin::slotMoveItem(QAction *action)
{
if (action) {
const QModelIndex index = action->data().toModelIndex();
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
copyOrMoveItem(collection, true);
}
}
......@@ -598,7 +598,7 @@ void KMReaderMainWin::slotCopyItem(QAction *action)
{
if (action) {
const QModelIndex index = action->data().toModelIndex();
const Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
copyOrMoveItem(collection, false);
}
}
......@@ -645,11 +645,11 @@ void KMReaderMainWin::slotContactSearchJobForMessagePopupDone(KJob *job)
mReaderWin->clearContactItem();
}
const Akonadi::Item msg = job->property("msg").value<Akonadi::Item>();
const auto msg = job->property("msg").value<Akonadi::Item>();
const QPoint aPoint = job->property("point").toPoint();
const QUrl imageUrl = job->property("imageUrl").toUrl();
const QUrl url = job->property("url").toUrl();
const WebEngineViewer::WebHitTestResult result = job->property("webhitresult").value<WebEngineViewer::WebHitTestResult>();
const auto result = job->property("webhitresult").value<WebEngineViewer::WebHitTestResult>();
showMessagePopup(msg, url, imageUrl, aPoint, contactAlreadyExists, uniqueContactFound, result);
}
......
......@@ -740,7 +740,7 @@ bool KMReaderWin::printSelectedText(bool preview)
auto composer = new ::MessageComposer::Composer;
composer->textPart()->setCleanPlainText(str);
composer->textPart()->setWrappedPlainText(str);
KMime::Message::Ptr messagePtr = messageItem().payload<KMime::Message::Ptr>();
auto messagePtr = messageItem().payload<KMime::Message::Ptr>();
composer->infoPart()->setFrom(messagePtr->from()->asUnicodeString());
composer->infoPart()->setTo(QStringList() << messagePtr->to()->asUnicodeString());
composer->infoPart()->setCc(QStringList() << messagePtr->cc()->asUnicodeString());
......@@ -867,7 +867,7 @@ void KMReaderWin::slotContactEditorError(const QString &error)
void KMReaderWin::contactStored(const Akonadi::Item &item)
{
if (item.hasPayload<KContacts::Addressee>()) {
const KContacts::Addressee contact = item.payload<KContacts::Addressee>();
const auto contact = item.payload<KContacts::Addressee>();
setContactItem(item, contact);
mViewer->slotChangeDisplayMail(mViewAsHtml->isChecked() ? Viewer::Html : Viewer::Text, mLoadExternalReference->isChecked());
}
......
......@@ -207,7 +207,7 @@ void KMSystemTray::fillFoldersMenu(QMenu *menu, const QAbstractItemModel *model,
const int rowCount = model->rowCount(parentIndex);
for (int row = 0; row < rowCount; ++row) {
const QModelIndex index = model->index(row, 0, parentIndex);
const Akonadi::Collection collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto collection = model->data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
qint64 count = 0;
if (mUnityServiceManager && !mUnityServiceManager->excludeFolder(collection)) {
const Akonadi::CollectionStatistics statistics = collection.statistics();
......
......@@ -112,7 +112,7 @@ void SummaryWidget::displayModel(const QModelIndex &parent, int &counter, const
const int nbCol = mModelProxy->rowCount(parent);
for (int i = 0; i < nbCol; ++i) {
const QModelIndex child = mModelProxy->index(i, 0, parent);
const Akonadi::Collection col = mModelProxy->data(child, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const auto col = mModelProxy->data(child, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
const int showCollection = mModelProxy->data(child, Qt::CheckStateRole).toInt();
if (col.isValid()) {
......@@ -162,7 +162,7 @@ void SummaryWidget::displayModel(const QModelIndex &parent, int &counter, const
mLabels.append(label);
// Folder icon.
QIcon icon = mModelProxy->data(child, Qt::DecorationRole).value<QIcon>();
auto icon = mModelProxy->data(child, Qt::DecorationRole).value<QIcon>();
label = new QLabel(this);
label->setPixmap(icon.pixmap(label->height() / 1.5));
label->setMaximumWidth(label->minimumSizeHint().width());
......
......@@ -153,7 +153,7 @@ void ManageShowCollectionProperties::slotCollectionPropertiesFinished(KJob *job)
return;
}
QPointer<KPIM::ProgressItem> progressItem = job->property("progressItem").value<QPointer<KPIM::ProgressItem>>();
auto progressItem = job->property("progressItem").value<QPointer<KPIM::ProgressItem>>();
// progressItem does not exist anymore, operation has been canceled
if (!progressItem) {
return;
......
......@@ -416,7 +416,7 @@ void MessageActions::updateMailingListActions(const Akonadi::Item &messageItem)
if (!messageItem.hasPayload<KMime::Message::Ptr>()) {
return;
}
KMime::Message::Ptr message = messageItem.payload<KMime::Message::Ptr>();
auto message = messageItem.payload<KMime::Message::Ptr>();
const MessageCore::MailingList mailList = MessageCore::MailingList::detect(message);
if (mailList.features() == MessageCore::MailingList::None) {
......
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