Commit 335c3bdb authored by Laurent Montel's avatar Laurent Montel 😁

Split contentstypecombobox. Add unittest. Create collectiontypeutil too

parent e1dc8906
......@@ -86,12 +86,14 @@ set(libmailcommon_filter_SRCS
)
set(libmailcommon_collection_SRCS
collectionpage/collectiontypeutil.cpp
collectionpage/attributeregistrar.cpp
collectionpage/collectionannotationsattribute.cpp
collectionpage/collectiongeneralpage.cpp
collectionpage/collectionexpirypage.cpp
collectionpage/expirecollectionattribute.cpp
collectionpage/newmailnotifierattribute.cpp
collectionpage/contentstypecombobox.cpp
)
set(libmailcommon_folder_SRCS
......
......@@ -12,3 +12,8 @@ target_link_libraries( collectionannotationsattributetest ${QT_QTTEST_LIBRARY} $
set( mailcommon_expirecollectionattributetest_source expirecollectionattributetest.cpp ../expirecollectionattribute.cpp )
kde4_add_unit_test( expirecollectionattributetest ${mailcommon_expirecollectionattributetest_source})
target_link_libraries( expirecollectionattributetest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS})
set( mailcommon_contentstypecomboboxtest_source contentstypecomboboxtest.cpp )
kde4_add_unit_test( contentstypecomboboxtest ${mailcommon_contentstypecomboboxtest_source})
target_link_libraries( contentstypecomboboxtest ${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 "contentstypecomboboxtest.h"
#include "../contentstypecombobox.h"
#include <kcombobox.h>
#include <qlabel.h>
#include <qtest_kde.h>
#include <QSignalSpy>
ContentsTypeComboBoxTest::ContentsTypeComboBoxTest(QObject *parent)
: QObject(parent)
{
}
ContentsTypeComboBoxTest::~ContentsTypeComboBoxTest()
{
}
void ContentsTypeComboBoxTest::shouldHaveDefaultValue()
{
MailCommon::ContentsTypeComboBox contentType;
QLabel *label = qFindChild<QLabel *>(&contentType, QLatin1String("contentstypelabel"));
QVERIFY(label);
KComboBox *combo = qFindChild<KComboBox *>(&contentType, QLatin1String("contentstypecombobox"));
QVERIFY(combo);
QVERIFY(combo->count()>0);
QCOMPARE(contentType.currentIndex(), 0);
}
void ContentsTypeComboBoxTest::shouldChangeComboBoxIndex()
{
MailCommon::ContentsTypeComboBox contentType;
KComboBox *combo = qFindChild<KComboBox *>(&contentType, QLatin1String("contentstypecombobox"));
for (int i = 0 ; i < combo->count() ; ++i) {
contentType.setCurrentIndex(i);
QVERIFY(contentType.currentIndex() == i);
QVERIFY(combo->currentIndex() == i);
}
}
void ContentsTypeComboBoxTest::shouldEmitSignalWhenIndexChanged()
{
MailCommon::ContentsTypeComboBox contentType;
contentType.show();
QTest::qWaitForWindowShown(&contentType);
QSignalSpy spy(&contentType, SIGNAL(indexChanged(int)));
contentType.setCurrentIndex(1);
QVERIFY(spy.at(0).count() == 1);
}
QTEST_KDEMAIN(ContentsTypeComboBoxTest, 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 CONTENTSTYPECOMBOBOXTEST_H
#define CONTENTSTYPECOMBOBOXTEST_H
#include <QObject>
class ContentsTypeComboBoxTest : public QObject
{
Q_OBJECT
public:
explicit ContentsTypeComboBoxTest(QObject *parent = 0);
~ContentsTypeComboBoxTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldChangeComboBoxIndex();
void shouldEmitSignalWhenIndexChanged();
};
#endif // CONTENTSTYPECOMBOBOXTEST_H
......@@ -17,6 +17,7 @@
#include "collectiongeneralpage.h"
#include "contentstypecombobox.h"
#include "collectionannotationsattribute.h"
#include "newmailnotifierattribute.h"
#include "foldercollection.h"
......@@ -403,31 +404,9 @@ void CollectionGeneralPage::init( const Akonadi::Collection &collection )
// or if it's set to calendar or task (existing folder)
if ( folderType == ContentsTypeCalendar || folderType == ContentsTypeTask ) {
++row;
QLabel *label = new QLabel( i18n( "Generate free/&busy and activate alarms for:" ), this );
gl->addWidget( label, row, 0 );
mIncidencesForComboBox = new KComboBox( this );
label->setBuddy( mIncidencesForComboBox );
gl->addWidget( mIncidencesForComboBox, row, 1 );
mIncidencesForComboBox->addItem( i18n( "Nobody" ) );
mIncidencesForComboBox->addItem( i18n( "Admins of This Folder" ) );
mIncidencesForComboBox->addItem( i18n( "All Readers of This Folder" ) );
const QString whatsThisForMyOwnFolders =
i18n( "This setting defines which users sharing "
"this folder should get \"busy\" periods in their freebusy lists "
"and should see the alarms for the events or tasks in this folder. "
"The setting applies to Calendar and Task folders only "
"(for tasks, this setting is only used for alarms).\n\n"
"Example use cases: if the boss shares a folder with his secretary, "
"only the boss should be marked as busy for his meetings, so he should "
"select \"Admins\", since the secretary has no admin rights on the folder.\n"
"On the other hand if a working group shares a Calendar for "
"group meetings, all readers of the folders should be marked "
"as busy for meetings.\n"
"A company-wide folder with optional events in it would use \"Nobody\" "
"since it is not known who will go to those events." );
mIncidencesForComboBox->setWhatsThis( whatsThisForMyOwnFolders );
mIncidencesForComboBox = new ContentsTypeComboBox(this);
gl->addWidget(mIncidencesForComboBox, row, 0, 1, 1);
mIncidencesForComboBox->setCurrentIndex( incidencesFor );
} else {
mIncidencesForComboBox = 0;
......
......@@ -36,7 +36,7 @@ class IdentityCombo;
namespace MailCommon {
class FolderCollection;
class ContentsTypeComboBox;
class MAILCOMMON_EXPORT CollectionGeneralPage : public Akonadi::CollectionPropertiesPage
{
Q_OBJECT
......@@ -78,7 +78,7 @@ private Q_SLOTS:
private:
QString mColorName;
KComboBox *mContentsComboBox;
KComboBox *mIncidencesForComboBox;
ContentsTypeComboBox *mIncidencesForComboBox;
QCheckBox *mSharedSeenFlagsCheckBox;
QCheckBox *mNotifyOnNewMailCheckBox;
QCheckBox *mKeepRepliesInSameFolderCheckBox;
......
/*
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 "collectiontypeutil.h"
#include <KLocalizedString>
using namespace MailCommon;
CollectionTypeUtil::CollectionTypeUtil()
{
}
CollectionTypeUtil::~CollectionTypeUtil()
{
}
QString CollectionTypeUtil::folderContentDescription( CollectionTypeUtil::FolderContentsType type )
{
switch ( type ) {
case CollectionTypeUtil::ContentsTypeMail:
return ( i18nc( "type of folder content", "Mail" ) );
case CollectionTypeUtil::ContentsTypeCalendar:
return ( i18nc( "type of folder content", "Calendar" ) );
case CollectionTypeUtil::ContentsTypeContact:
return ( i18nc( "type of folder content", "Contacts" ) );
case CollectionTypeUtil::ContentsTypeNote:
return ( i18nc( "type of folder content", "Notes" ) );
case CollectionTypeUtil::ContentsTypeTask:
return ( i18nc( "type of folder content", "Tasks" ) );
case CollectionTypeUtil::ContentsTypeJournal:
return ( i18nc( "type of folder content", "Journal" ) );
case CollectionTypeUtil::ContentsTypeConfiguration:
return ( i18nc( "type of folder content", "Configuration" ) );
case CollectionTypeUtil::ContentsTypeFreebusy:
return ( i18nc( "type of folder content", "Freebusy" ) );
case CollectionTypeUtil::ContentsTypeFile:
return ( i18nc( "type of folder content", "Files" ) );
default:
return ( i18nc( "type of folder content", "Unknown" ) );
}
}
CollectionTypeUtil::IncidencesFor CollectionTypeUtil::incidencesForFromString( const QString &string )
{
if ( string == QLatin1String("nobody") ) {
return CollectionTypeUtil::IncForNobody;
}
else if ( string == QLatin1String("admins") ) {
return CollectionTypeUtil::IncForAdmins;
}
else if ( string == QLatin1String("readers") ) {
return CollectionTypeUtil::IncForReaders;
}
return CollectionTypeUtil::IncForAdmins; // by default
}
CollectionTypeUtil::FolderContentsType CollectionTypeUtil::typeFromKolabName(const QByteArray &name)
{
if ( name == "task" || name == "task.default" ) {
return CollectionTypeUtil::ContentsTypeTask;
}
if ( name == "event" || name == "event.default" ) {
return CollectionTypeUtil::ContentsTypeCalendar;
}
if ( name == "contact" || name == "contact.default" ) {
return CollectionTypeUtil::ContentsTypeContact;
}
if ( name == "note" || name == "note.default" ) {
return CollectionTypeUtil::ContentsTypeNote;
}
if ( name == "journal" || name == "journal.default" ) {
return CollectionTypeUtil::ContentsTypeJournal;
}
if ( name == "configuration" || name == "configuration.default" ) {
return CollectionTypeUtil::ContentsTypeConfiguration;
}
if ( name == "freebusy" || name == "freebusy.default" ) {
return CollectionTypeUtil::ContentsTypeFreebusy;
}
if ( name == "file" || name == "file.default" ) {
return CollectionTypeUtil::ContentsTypeFile;
}
return CollectionTypeUtil::ContentsTypeMail;
}
QByteArray CollectionTypeUtil::kolabNameFromType( CollectionTypeUtil::FolderContentsType type )
{
switch ( type ) {
case CollectionTypeUtil::ContentsTypeCalendar:
return "event";
case CollectionTypeUtil::ContentsTypeContact:
return "contact";
case CollectionTypeUtil::ContentsTypeNote:
return "note";
case CollectionTypeUtil::ContentsTypeTask:
return "task";
case CollectionTypeUtil::ContentsTypeJournal:
return "journal";
case CollectionTypeUtil::ContentsTypeConfiguration:
return "configuration";
case CollectionTypeUtil::ContentsTypeFreebusy:
return "freebusy";
case CollectionTypeUtil::ContentsTypeFile:
return "file";
default:
return QByteArray();
}
}
/*
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 COLLECTIONTYPEUTIL_H
#define COLLECTIONTYPEUTIL_H
#include "mailcommon_export.h"
#include <QByteArray>
#include <QString>
namespace MailCommon {
class MAILCOMMON_EXPORT CollectionTypeUtil
{
public:
CollectionTypeUtil();
~CollectionTypeUtil();
enum FolderContentsType {
ContentsTypeMail = 0,
ContentsTypeCalendar,
ContentsTypeContact,
ContentsTypeNote,
ContentsTypeTask,
ContentsTypeJournal,
ContentsTypeConfiguration,
ContentsTypeFreebusy,
ContentsTypeFile,
ContentsTypeLast = ContentsTypeFile
};
enum IncidencesFor {
IncForNobody,
IncForAdmins,
IncForReaders
};
CollectionTypeUtil::IncidencesFor incidencesForFromString(const QString &string);
CollectionTypeUtil::FolderContentsType typeFromKolabName(const QByteArray &name);
QString folderContentDescription(CollectionTypeUtil::FolderContentsType type);
QByteArray kolabNameFromType(CollectionTypeUtil::FolderContentsType type);
};
}
#endif // COLLECTIONTYPEUTIL_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 "contentstypecombobox.h"
#include <QLabel>
#include <QHBoxLayout>
#include <KLocalizedString>
#include <KComboBox>
using namespace MailCommon;
ContentsTypeComboBox::ContentsTypeComboBox(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *hbox = new QHBoxLayout(this);
QLabel *label = new QLabel( i18n( "Generate free/&busy and activate alarms for:" ), this );
label->setObjectName(QLatin1String("contentstypelabel"));
hbox->addWidget(label);
mIncidencesForComboBox = new KComboBox( this );
label->setBuddy( mIncidencesForComboBox );
hbox->addWidget(mIncidencesForComboBox);
mIncidencesForComboBox->addItem( i18n( "Nobody" ) );
mIncidencesForComboBox->addItem( i18n( "Admins of This Folder" ) );
mIncidencesForComboBox->addItem( i18n( "All Readers of This Folder" ) );
const QString whatsThisForMyOwnFolders =
i18n( "This setting defines which users sharing "
"this folder should get \"busy\" periods in their freebusy lists "
"and should see the alarms for the events or tasks in this folder. "
"The setting applies to Calendar and Task folders only "
"(for tasks, this setting is only used for alarms).\n\n"
"Example use cases: if the boss shares a folder with his secretary, "
"only the boss should be marked as busy for his meetings, so he should "
"select \"Admins\", since the secretary has no admin rights on the folder.\n"
"On the other hand if a working group shares a Calendar for "
"group meetings, all readers of the folders should be marked "
"as busy for meetings.\n"
"A company-wide folder with optional events in it would use \"Nobody\" "
"since it is not known who will go to those events." );
mIncidencesForComboBox->setObjectName(QLatin1String("contentstypecombobox"));
mIncidencesForComboBox->setWhatsThis( whatsThisForMyOwnFolders );
connect(mIncidencesForComboBox, SIGNAL(currentIndexChanged(int)), SIGNAL(indexChanged(int)));
}
ContentsTypeComboBox::~ContentsTypeComboBox()
{
}
int ContentsTypeComboBox::currentIndex() const
{
return mIncidencesForComboBox->currentIndex();
}
void ContentsTypeComboBox::setCurrentIndex(int index)
{
mIncidencesForComboBox->setCurrentIndex(index);
}
/*
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 CONTENTSTYPECOMBOBOX_H
#define CONTENTSTYPECOMBOBOX_H
#include "mailcommon_export.h"
#include <QWidget>
class KComboBox;
namespace MailCommon {
class MAILCOMMON_EXPORT ContentsTypeComboBox : public QWidget
{
Q_OBJECT
public:
explicit ContentsTypeComboBox(QWidget *parent=0);
~ContentsTypeComboBox();
int currentIndex() const;
void setCurrentIndex(int index);
Q_SIGNALS:
void indexChanged(int value);
private:
KComboBox *mIncidencesForComboBox;
};
}
#endif // CONTENTSTYPECOMBOBOX_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