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