Commit 9b5fdb4a authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Reduce duplicate code

parent 53a7ad8b
...@@ -248,8 +248,7 @@ void TodoEdit::slotReturnPressed() ...@@ -248,8 +248,7 @@ void TodoEdit::slotReturnPressed()
if (!mNoteEdit->text().trimmed().isEmpty()) { if (!mNoteEdit->text().trimmed().isEmpty()) {
mMsgWidget->setText(i18nc("%1 is summary of the todo, %2 is name of the folder in which it is stored", mMsgWidget->setText(i18nc("%1 is summary of the todo, %2 is name of the folder in which it is stored",
"New todo '%1' was added to task list '%2'", mNoteEdit->text(), collection.displayName())); "New todo '%1' was added to task list '%2'", mNoteEdit->text(), collection.displayName()));
KCalCore::Todo::Ptr todo(new KCalCore::Todo); KCalCore::Todo::Ptr todo = createTodoItem();
todo->setSummary(mNoteEdit->text());
mNoteEdit->clear(); mNoteEdit->clear();
// We don't hide the widget here, so that multiple todo's can be added // We don't hide the widget here, so that multiple todo's can be added
...@@ -259,6 +258,20 @@ void TodoEdit::slotReturnPressed() ...@@ -259,6 +258,20 @@ void TodoEdit::slotReturnPressed()
} }
} }
KCalCore::Todo::Ptr TodoEdit::createTodoItem()
{
KCalCore::Todo::Ptr todo(new KCalCore::Todo);
todo->setSummary(mNoteEdit->text());
KCalCore::Attachment::Ptr attachment(new KCalCore::Attachment(mMessage->encodedContent().toBase64(), KMime::Message::mimeType()));
const KMime::Headers::Subject *const subject = mMessage->subject(false);
if (subject) {
attachment->setLabel(subject->asUnicodeString());
}
todo->addAttachment(attachment);
return todo;
}
bool TodoEdit::eventFilter(QObject *object, QEvent *e) bool TodoEdit::eventFilter(QObject *object, QEvent *e)
{ {
// Close the bar when pressing Escape. // Close the bar when pressing Escape.
...@@ -290,21 +303,15 @@ bool TodoEdit::eventFilter(QObject *object, QEvent *e) ...@@ -290,21 +303,15 @@ bool TodoEdit::eventFilter(QObject *object, QEvent *e)
void TodoEdit::slotOpenEditor() void TodoEdit::slotOpenEditor()
{ {
QTemporaryFile tf; KCalCore::Todo::Ptr event = createTodoItem();
tf.setAutoRemove(false);
tf.open();
tf.write(mMessage->encodedContent());
tf.close();
const KMime::Headers::Subject *const subject = mMessage->subject(false); Akonadi::Item item;
IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::createTodoEditor( item.setPayload<KCalCore::Todo::Ptr>(event);
mNoteEdit->text(), QString(), item.setMimeType(KCalCore::Todo::todoMimeType());
QStringList() << tf.fileName(),
QStringList(), // attendees IncidenceEditorNG::IncidenceDialog *dlg = IncidenceEditorNG::IncidenceDialogFactory::create(true, KCalCore::IncidenceBase::TypeTodo, nullptr, this);
QStringList() << KMime::Message::mimeType(),
QStringList() << (subject ? subject->asUnicodeString() : QString()),
true, mCollection, true, this);
connect(dlg, &IncidenceEditorNG::IncidenceDialog::finished, this, &TodoEdit::slotCloseWidget); connect(dlg, &IncidenceEditorNG::IncidenceDialog::finished, this, &TodoEdit::slotCloseWidget);
dlg->load(item);
dlg->open(); dlg->open();
} }
......
...@@ -61,6 +61,7 @@ Q_SIGNALS: ...@@ -61,6 +61,7 @@ Q_SIGNALS:
protected: protected:
bool eventFilter(QObject *object, QEvent *e) override; bool eventFilter(QObject *object, QEvent *e) override;
private: private:
KCalCore::Todo::Ptr createTodoItem();
void comboboxRowInserted(); void comboboxRowInserted();
void slotReturnPressed(); void slotReturnPressed();
void slotCollectionChanged(int); void slotCollectionChanged(int);
......
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