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

Extract content type widget

parent 6ae56210
......@@ -17,3 +17,8 @@ set( mailcommon_incidencesforwidgettest_source incidencesforwidgettest.cpp )
kde4_add_unit_test( incidencesforwidgettest ${mailcommon_incidencesforwidgettest_source})
target_link_libraries( incidencesforwidgettest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} mailcommon)
set( mailcommon_contenttypewidgettest_source contenttypewidgettest.cpp )
kde4_add_unit_test( contenttypewidgettest ${mailcommon_contenttypewidgettest_source})
target_link_libraries( contenttypewidgettest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTGUI_LIBRARY} mailcommon)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "contenttypewidgettest.h"
#include "../contenttypewidget.h"
#include <kcombobox.h>
#include <qlabel.h>
#include <qtest_kde.h>
ContentTypeWidgetTest::ContentTypeWidgetTest(QObject *parent)
: QObject(parent)
{
}
ContentTypeWidgetTest::~ContentTypeWidgetTest()
{
}
void ContentTypeWidgetTest::shouldHaveDefaultValue()
{
MailCommon::ContentTypeWidget widget;
QLabel *label = qFindChild<QLabel *>(&widget, QLatin1String("contenttypewidgetlabel"));
QVERIFY(label);
KComboBox *combo = qFindChild<KComboBox *>(&widget, QLatin1String("contentcombobox"));
QVERIFY(combo);
QVERIFY(combo->count()>0);
QCOMPARE(widget.currentIndex(), 0);
}
void ContentTypeWidgetTest::shouldChangeComboBoxIndex()
{
MailCommon::ContentTypeWidget contentType;
KComboBox *combo = qFindChild<KComboBox *>(&contentType, QLatin1String("contentcombobox"));
for (int i = 0 ; i < combo->count() ; ++i) {
contentType.setCurrentIndex(i);
QCOMPARE(contentType.currentIndex(), i);
QCOMPARE(combo->currentIndex(), i);
}
}
void ContentTypeWidgetTest::shouldEmitSignalWhenIndexChanged()
{
MailCommon::ContentTypeWidget contentType;
contentType.show();
QTest::qWaitForWindowShown(&contentType);
QSignalSpy spy(&contentType, SIGNAL(activated(int)));
contentType.setCurrentIndex(1);
//FIXME
//QCOMPARE(spy.at(0).count(), 1);
}
void ContentTypeWidgetTest::shouldChangeItem()
{
MailCommon::ContentTypeWidget contentType;
contentType.show();
QTest::qWaitForWindowShown(&contentType);
KComboBox *combo = qFindChild<KComboBox *>(&contentType, QLatin1String("contentcombobox"));
for (int i = 0 ; i < combo->count() ; ++i) {
contentType.setCurrentIndex(i);
QCOMPARE(contentType.currentText(), combo->currentText());
}
}
QTEST_KDEMAIN(ContentTypeWidgetTest, GUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef CONTENTTYPEWIDGETTEST_H
#define CONTENTTYPEWIDGETTEST_H
#include <QObject>
class ContentTypeWidgetTest : public QObject
{
Q_OBJECT
public:
explicit ContentTypeWidgetTest(QObject *parent = 0);
~ContentTypeWidgetTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeComboBoxIndex();
void shouldEmitSignalWhenIndexChanged();
void shouldChangeItem();
};
#endif // CONTENTTYPEWIDGETTEST_H
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "contenttypewidget.h"
#include "collectiontypeutil.h"
#include <KLocalizedString>
#include <KComboBox>
#include <QHBoxLayout>
#include <QLabel>
using namespace MailCommon;
ContentTypeWidget::ContentTypeWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *hbox = new QHBoxLayout(this);
hbox->setMargin(0);
QLabel *label = new QLabel( i18n( "&Folder contents:" ), this );
label->setObjectName(QLatin1String("contenttypewidgetlabel"));
hbox->addWidget(label);
mContentsComboBox = new KComboBox( this );
mContentsComboBox->setObjectName(QLatin1String("contentcombobox"));
label->setBuddy( mContentsComboBox );
hbox->addWidget(mContentsComboBox);
MailCommon::CollectionTypeUtil collectionUtil;
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeMail ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeCalendar ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeContact ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeNote ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeTask ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeJournal ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeConfiguration ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeFreebusy ) );
mContentsComboBox->addItem( collectionUtil.folderContentDescription( CollectionTypeUtil::ContentsTypeFile ) );
connect(mContentsComboBox, SIGNAL(activated(int)), SIGNAL(activated(int)));
}
ContentTypeWidget::~ContentTypeWidget()
{
}
int ContentTypeWidget::currentIndex() const
{
return mContentsComboBox->currentIndex();
}
void ContentTypeWidget::setCurrentIndex(int index)
{
mContentsComboBox->setCurrentIndex(index);
}
void ContentTypeWidget::setCurrentItem(const QString &name)
{
mContentsComboBox->setCurrentItem(name);
}
QString ContentTypeWidget::currentText() const
{
return mContentsComboBox->currentText();
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef CONTENTTYPEWIDGET_H
#define CONTENTTYPEWIDGET_H
#include <QWidget>
#include "mailcommon_export.h"
class KComboBox;
namespace MailCommon {
class MAILCOMMON_EXPORT ContentTypeWidget : public QWidget
{
Q_OBJECT
public:
explicit ContentTypeWidget(QWidget *parent=0);
~ContentTypeWidget();
int currentIndex() const;
void setCurrentIndex(int index);
void setCurrentItem(const QString &name);
QString currentText() const;
Q_SIGNALS:
void activated(int index);
private:
KComboBox *mContentsComboBox;
};
}
#endif // CONTENTTYPEWIDGET_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