Commit d0bdbeb6 authored by David Faure's avatar David Faure

MessageViewer plugin: create EventEdit widget on demand.

Summary:
This avoids creating a CollectionComboBox on startup (which includes a Monitor,
an ETM and 3 proxies on top), which might never be used if the user doesn't
use the "create event" feature.

The same change should of course be done to noteedit and todoedit.

The unittest had to be adjusted because it was checking that the widget
was created upfront and hidden, which is exactly what this patch changes.

Test Plan:
Ctrl+E in kmail still brings up the event edit widget,
without any noticeable delay the first time.

Reviewers: knauss, mlaurent

Reviewed By: knauss, mlaurent

Subscribers: knauss, kde-pim, #kde_pim

Tags: #kde_pim

Differential Revision: https://phabricator.kde.org/D2161
parent fe353ac7
......@@ -42,25 +42,27 @@ ViewerPluginCreateeventTest::~ViewerPluginCreateeventTest()
}
void ViewerPluginCreateeventTest::shouldHaveDefaultValue()
void ViewerPluginCreateeventTest::shouldCreateAction()
{
MessageViewer::ViewerPluginCreateevent *event = new MessageViewer::ViewerPluginCreateevent(this);
QVERIFY(!event->viewerPluginName().isEmpty());
QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout);
QVERIFY(event->createView(parent, new KActionCollection(this)));
MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this));
QVERIFY(interface);
QVERIFY(!interface->actions().isEmpty());
}
void ViewerPluginCreateeventTest::shouldCreateAction()
void ViewerPluginCreateeventTest::shouldShowWidget()
{
MessageViewer::ViewerPluginCreateevent *event = new MessageViewer::ViewerPluginCreateevent(this);
QWidget *parent = new QWidget(0);
parent->setLayout(new QHBoxLayout);
MessageViewer::ViewerPluginInterface *interface = event->createView(parent, new KActionCollection(this));
QVERIFY(!interface->actions().isEmpty());
interface->execute();
QWidget *createeventwidget = parent->findChild<QWidget *>(QStringLiteral("eventedit"));
QVERIFY(createeventwidget);
QCOMPARE(createeventwidget->isVisible(), false);
QCOMPARE(createeventwidget->isHidden(), false);
}
QTEST_MAIN(ViewerPluginCreateeventTest)
......@@ -30,8 +30,8 @@ public:
~ViewerPluginCreateeventTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldCreateAction();
void shouldShowWidget();
};
#endif // VIEWERPLUGINCREATEEVENTTEST_H
......@@ -30,13 +30,9 @@
using namespace MessageViewer;
ViewerPluginCreateEventInterface::ViewerPluginCreateEventInterface(KActionCollection *ac, QWidget *parent)
: ViewerPluginInterface(parent)
: ViewerPluginInterface(parent),
mEventEdit(Q_NULLPTR)
{
mEventEdit = new EventEdit(parent);
connect(mEventEdit, &EventEdit::createEvent, this, &ViewerPluginCreateEventInterface::slotCreateEvent);
mEventEdit->setObjectName(QStringLiteral("eventedit"));
parent->layout()->addWidget(mEventEdit);
mEventEdit->hide();
createAction(ac);
}
......@@ -63,17 +59,17 @@ QList<QAction *> ViewerPluginCreateEventInterface::actions() const
void ViewerPluginCreateEventInterface::setMessage(const KMime::Message::Ptr &value)
{
mEventEdit->setMessage(value);
widget()->setMessage(value);
}
void ViewerPluginCreateEventInterface::closePlugin()
{
mEventEdit->slotCloseWidget();
widget()->slotCloseWidget();
}
void ViewerPluginCreateEventInterface::showWidget()
{
mEventEdit->showEventEdit();
widget()->showEventEdit();
}
void ViewerPluginCreateEventInterface::setMessageItem(const Akonadi::Item &item)
......@@ -94,6 +90,19 @@ void ViewerPluginCreateEventInterface::createAction(KActionCollection *ac)
}
}
EventEdit *ViewerPluginCreateEventInterface::widget()
{
if (!mEventEdit) {
QWidget *parentWidget = static_cast<QWidget *>(parent());
mEventEdit = new EventEdit(parentWidget);
connect(mEventEdit, &EventEdit::createEvent, this, &ViewerPluginCreateEventInterface::slotCreateEvent);
mEventEdit->setObjectName(QStringLiteral("eventedit"));
parentWidget->layout()->addWidget(mEventEdit);
mEventEdit->hide();
}
return mEventEdit;
}
void ViewerPluginCreateEventInterface::slotCreateEvent(const KCalCore::Event::Ptr &eventPtr, const Akonadi::Collection &collection)
{
CreateEventJob *createJob = new CreateEventJob(eventPtr, collection, mMessageItem, this);
......
......@@ -46,6 +46,8 @@ private Q_SLOTS:
private:
void createAction(KActionCollection *ac);
EventEdit *widget();
Akonadi::Item mMessageItem;
EventEdit *mEventEdit;
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