Commit d25b5b8d authored by Laurent Montel's avatar Laurent Montel 😁

Allow to use kactioncollection here. Clean up code. Add unittest

parent 04f37a2d
......@@ -1914,6 +1914,7 @@ void KMMainWidget::slotSelectMoreMessageTagList()
return;
TagSelectDialog dlg( this, selectedMessages.count(), selectedMessages.first() );
dlg.setActionCollection(QList<KActionCollection*>() << actionCollection());
if ( dlg.exec() ) {
const Akonadi::Tag::List lst = dlg.selectedTag();
if (!lst.isEmpty()) {
......
......@@ -61,32 +61,45 @@ TagSelectDialog::TagSelectDialog( QWidget * parent, int numberOfSelectedMessages
setMainWidget( mainWidget );
mListTag = new QListWidget( this );
mListTag->setObjectName(QLatin1String("listtag"));
KListWidgetSearchLine *listWidgetSearchLine = new KListWidgetSearchLine(this,mListTag);
listWidgetSearchLine->setClickMessage(i18n("Search tag"));
listWidgetSearchLine->setClearButtonShown(true);
listWidgetSearchLine->setTrapReturnKey(true);
listWidgetSearchLine->setObjectName(QLatin1String("searchline"));
mainLayout->addWidget(listWidgetSearchLine);
mainLayout->addWidget( mListTag );
createTagList();
connect(this, SIGNAL(user1Clicked()), SLOT(slotAddNewTag()));
readConfig();
}
TagSelectDialog::~TagSelectDialog()
{
writeConfig();
}
KConfigGroup group( KMKernel::self()->config(), "TagSelectDialog" );
void TagSelectDialog::readConfig()
{
KConfigGroup group( KGlobal::config(), "TagSelectDialog" );
const QSize size = group.readEntry( "Size", QSize(500, 300) );
if ( size.isValid() ) {
resize( size );
}
}
TagSelectDialog::~TagSelectDialog()
void TagSelectDialog::writeConfig()
{
KConfigGroup group( KMKernel::self()->config(), "TagSelectDialog" );
KConfigGroup group( KGlobal::config(), "TagSelectDialog" );
group.writeEntry( "Size", size() );
}
void TagSelectDialog::slotAddNewTag()
{
QPointer<MailCommon::AddTagDialog> dialog = new MailCommon::AddTagDialog(QList<KActionCollection*>(), this);
QPointer<MailCommon::AddTagDialog> dialog = new MailCommon::AddTagDialog(mActionCollectionList, this);
dialog->setTags(mTagList);
if ( dialog->exec() ) {
mListTag->clear();
......@@ -103,6 +116,11 @@ void TagSelectDialog::createTagList()
connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(slotTagsFetched(KJob*)));
}
void TagSelectDialog::setActionCollection(const QList<KActionCollection *> &actionCollectionList)
{
mActionCollectionList = actionCollectionList;
}
void TagSelectDialog::slotTagsFetched(KJob *job)
{
if (job->error()) {
......@@ -143,6 +161,5 @@ Akonadi::Tag::List TagSelectDialog::selectedTag() const
lst.append( Akonadi::Tag::fromUrl( item->data(UrlTag).toString() ) );
}
}
qDebug()<<" lst"<<lst;
return lst;
}
......@@ -35,6 +35,7 @@
#include "tag.h"
class QListWidget;
class KActionCollection;
class TagSelectDialog : public KDialog
{
Q_OBJECT
......@@ -43,11 +44,15 @@ public:
~TagSelectDialog();
Akonadi::Tag::List selectedTag() const;
void setActionCollection(const QList<KActionCollection *> &actionCollectionList);
private Q_SLOTS:
void slotAddNewTag();
void slotTagsFetched(KJob*);
private:
void writeConfig();
void readConfig();
void createTagList();
enum ItemType {
UrlTag = Qt::UserRole + 1
......@@ -56,6 +61,7 @@ private:
Akonadi::Item mSelectedItem;
QList<MailCommon::Tag::Ptr> mTagList;
QList<KActionCollection*> mActionCollectionList;
QListWidget *mListTag;
};
......
......@@ -63,3 +63,6 @@ set( kmail_configureagentitemtest_source configureagentitemtest.cpp ../configure
kde4_add_unit_test( configureagentitemtest ${kmail_configureagentitemtest_source})
target_link_libraries( configureagentitemtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} )
add_akonadi_isolated_test_advanced( tagselectdialogtest.cpp "../tag/tagselectdialog.cpp" "${KDEPIMLIBS_AKONADI_LIBS};kmailprivate;mailcommon")
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "tagselectdialogtest.h"
#include "tag/tagselectdialog.h"
#include <KListWidgetSearchLine>
#include <QListWidget>
#include <qtest_kde.h>
TagSelectDialogTest::TagSelectDialogTest(QObject *parent)
: QObject(parent)
{
}
TagSelectDialogTest::~TagSelectDialogTest()
{
}
void TagSelectDialogTest::shouldHaveDefaultValue()
{
TagSelectDialog dlg(0, 1, Akonadi::Item());
QListWidget *listWidget = dlg.findChild<QListWidget *>(QLatin1String("listtag"));
QVERIFY(listWidget);
KListWidgetSearchLine *listWidgetSearchLine = dlg.findChild<KListWidgetSearchLine *>(QLatin1String("searchline"));
QVERIFY(listWidgetSearchLine);
QVERIFY(listWidgetSearchLine->isClearButtonShown());
QVERIFY(listWidgetSearchLine->trapReturnKey());
}
QTEST_KDEMAIN(TagSelectDialogTest, GUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef TAGSELECTDIALOGTEST_H
#define TAGSELECTDIALOGTEST_H
#include <QObject>
class TagSelectDialogTest : public QObject
{
Q_OBJECT
public:
explicit TagSelectDialogTest(QObject *parent = 0);
~TagSelectDialogTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
};
#endif // TAGSELECTDIALOGTEST_H
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