summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Faure <[email protected]>2016-07-14 14:53:37 +0200
committerDavid Faure <[email protected]>2016-07-14 15:01:30 +0200
commitd0bdbeb640c6149d3ececd619290890e9a735beb (patch)
treee4dfe81a5c0d169e4e0c089056e780173a829261
parentfe353ac7408e3d561e1a80ecd4501858203b46ab (diff)
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
-rw-r--r--plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp12
-rw-r--r--plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h2
-rw-r--r--plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp27
-rw-r--r--plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h2
4 files changed, 28 insertions, 15 deletions
diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp
index 3de8d85..aca222f 100644
--- a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp
+++ b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.cpp
@@ -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)
diff --git a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h
index ba61200..4d131f7 100644
--- a/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h
+++ b/plugins/messageviewerplugins/autotests/viewerplugincreateeventtest.h
@@ -30,8 +30,8 @@ public:
~ViewerPluginCreateeventTest();
private Q_SLOTS:
- void shouldHaveDefaultValue();
void shouldCreateAction();
+ void shouldShowWidget();
};
#endif // VIEWERPLUGINCREATEEVENTTEST_H
diff --git a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp
index ba058e3..9f253e4 100644
--- a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp
+++ b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.cpp
@@ -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);
diff --git a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h
index 578a849..66fcf28 100644
--- a/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h
+++ b/plugins/messageviewerplugins/createeventplugin/viewerplugincreateeventinterface.h
@@ -46,6 +46,8 @@ private Q_SLOTS:
private:
void createAction(KActionCollection *ac);
+ EventEdit *widget();
+
Akonadi::Item mMessageItem;
EventEdit *mEventEdit;
QList<QAction *> mAction;