Commit d4d9fe53 authored by David Faure's avatar David Faure

MessageViewer plugin: create NoteEdit widget on demand.

parent d0bdbeb6
...@@ -42,26 +42,27 @@ ViewerPluginCreateNoteTest::~ViewerPluginCreateNoteTest() ...@@ -42,26 +42,27 @@ ViewerPluginCreateNoteTest::~ViewerPluginCreateNoteTest()
} }
void ViewerPluginCreateNoteTest::shouldHaveDefaultValue() void ViewerPluginCreateNoteTest::shouldCreateAction()
{ {
MessageViewer::ViewerPluginCreatenote *note = new MessageViewer::ViewerPluginCreatenote(this); MessageViewer::ViewerPluginCreatenote *note = new MessageViewer::ViewerPluginCreatenote(this);
QVERIFY(!note->viewerPluginName().isEmpty()); QVERIFY(!note->viewerPluginName().isEmpty());
QWidget *parent = new QWidget(0); QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout); parent->setLayout(new QHBoxLayout);
MessageViewer::ViewerPluginInterface *interface = note->createView(parent, new KActionCollection(this));
QVERIFY(note->createView(parent, new KActionCollection(this))); QVERIFY(interface);
QVERIFY(!interface->actions().isEmpty());
} }
void ViewerPluginCreateNoteTest::shouldCreateAction() void ViewerPluginCreateNoteTest::shouldShowWidget()
{ {
MessageViewer::ViewerPluginCreatenote *event = new MessageViewer::ViewerPluginCreatenote(this); MessageViewer::ViewerPluginCreatenote *note = new MessageViewer::ViewerPluginCreatenote(this);
QWidget *parent = new QWidget(0); QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout); parent->setLayout(new QHBoxLayout);
MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this)); MessageViewer::ViewerPluginInterface *interface = note->createView(parent, new KActionCollection(this));
QVERIFY(!interface->actions().isEmpty()); interface->execute();
QWidget *createnotewidget = parent->findChild<QWidget *>(QStringLiteral("noteedit")); QWidget *createnotewidget = parent->findChild<QWidget *>(QStringLiteral("noteedit"));
QVERIFY(createnotewidget); QVERIFY(createnotewidget);
QCOMPARE(createnotewidget->isVisible(), false); QCOMPARE(createnotewidget->isHidden(), false);
} }
QTEST_MAIN(ViewerPluginCreateNoteTest) QTEST_MAIN(ViewerPluginCreateNoteTest)
...@@ -30,8 +30,8 @@ public: ...@@ -30,8 +30,8 @@ public:
~ViewerPluginCreateNoteTest(); ~ViewerPluginCreateNoteTest();
private Q_SLOTS: private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldCreateAction(); void shouldCreateAction();
void shouldShowWidget();
}; };
#endif // VIEWERPLUGINCREATENOTETEST_H #endif // VIEWERPLUGINCREATENOTETEST_H
...@@ -33,14 +33,10 @@ ...@@ -33,14 +33,10 @@
using namespace MessageViewer; using namespace MessageViewer;
ViewerPluginCreatenoteInterface::ViewerPluginCreatenoteInterface(KActionCollection *ac, QWidget *parent) ViewerPluginCreatenoteInterface::ViewerPluginCreatenoteInterface(KActionCollection *ac, QWidget *parent)
: ViewerPluginInterface(parent) : ViewerPluginInterface(parent),
mNoteEdit(Q_NULLPTR)
{ {
createAction(ac); createAction(ac);
mNoteEdit = new NoteEdit(parent);
mNoteEdit->setObjectName(QStringLiteral("noteedit"));
mNoteEdit->hide();
connect(mNoteEdit, &NoteEdit::createNote, this, &ViewerPluginCreatenoteInterface::slotCreateNote);
parent->layout()->addWidget(mNoteEdit);
} }
ViewerPluginCreatenoteInterface::~ViewerPluginCreatenoteInterface() ViewerPluginCreatenoteInterface::~ViewerPluginCreatenoteInterface()
...@@ -61,12 +57,12 @@ QList<QAction *> ViewerPluginCreatenoteInterface::actions() const ...@@ -61,12 +57,12 @@ QList<QAction *> ViewerPluginCreatenoteInterface::actions() const
void ViewerPluginCreatenoteInterface::setMessage(const KMime::Message::Ptr &value) void ViewerPluginCreatenoteInterface::setMessage(const KMime::Message::Ptr &value)
{ {
mNoteEdit->setMessage(value); widget()->setMessage(value);
} }
void ViewerPluginCreatenoteInterface::closePlugin() void ViewerPluginCreatenoteInterface::closePlugin()
{ {
mNoteEdit->slotCloseWidget(); widget()->slotCloseWidget();
} }
Akonadi::Relation ViewerPluginCreatenoteInterface::relatedNoteRelation() const Akonadi::Relation ViewerPluginCreatenoteInterface::relatedNoteRelation() const
...@@ -98,7 +94,7 @@ void ViewerPluginCreatenoteInterface::showWidget() ...@@ -98,7 +94,7 @@ void ViewerPluginCreatenoteInterface::showWidget()
void ViewerPluginCreatenoteInterface::showCreateNewNoteWidget() void ViewerPluginCreatenoteInterface::showCreateNewNoteWidget()
{ {
mNoteEdit->showNoteEdit(); widget()->showNoteEdit();
} }
void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job) void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job)
...@@ -113,7 +109,7 @@ void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job) ...@@ -113,7 +109,7 @@ void ViewerPluginCreatenoteInterface::slotNoteItemFetched(KJob *job)
showCreateNewNoteWidget(); showCreateNewNoteWidget();
} else { } else {
Akonadi::NoteUtils::NoteMessageWrapper note(fetch->items().first().payload<KMime::Message::Ptr>()); Akonadi::NoteUtils::NoteMessageWrapper note(fetch->items().first().payload<KMime::Message::Ptr>());
mNoteEdit->setMessage(note.message()); widget()->setMessage(note.message());
showCreateNewNoteWidget(); showCreateNewNoteWidget();
} }
} }
...@@ -163,3 +159,16 @@ void ViewerPluginCreatenoteInterface::slotCreateNote(const KMime::Message::Ptr & ...@@ -163,3 +159,16 @@ void ViewerPluginCreatenoteInterface::slotCreateNote(const KMime::Message::Ptr &
CreateNoteJob *createJob = new CreateNoteJob(notePtr, collection, mMessageItem, this); CreateNoteJob *createJob = new CreateNoteJob(notePtr, collection, mMessageItem, this);
createJob->start(); createJob->start();
} }
NoteEdit *ViewerPluginCreatenoteInterface::widget()
{
if (!mNoteEdit) {
QWidget *parentWidget = static_cast<QWidget *>(parent());
mNoteEdit = new NoteEdit(parentWidget);
connect(mNoteEdit, &NoteEdit::createNote, this, &ViewerPluginCreatenoteInterface::slotCreateNote);
mNoteEdit->setObjectName(QStringLiteral("noteedit"));
parentWidget->layout()->addWidget(mNoteEdit);
mNoteEdit->hide();
}
return mNoteEdit;
}
...@@ -49,6 +49,8 @@ private: ...@@ -49,6 +49,8 @@ private:
Akonadi::Relation relatedNoteRelation() const; Akonadi::Relation relatedNoteRelation() const;
void showCreateNewNoteWidget(); void showCreateNewNoteWidget();
void createAction(KActionCollection *ac); void createAction(KActionCollection *ac);
NoteEdit *widget();
Akonadi::Item mMessageItem; Akonadi::Item mMessageItem;
NoteEdit *mNoteEdit; NoteEdit *mNoteEdit;
QList<QAction *> mAction; QList<QAction *> mAction;
......
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