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

Use contenttypewidget. Move code to collectiontypeutil

parent d4cd99bb
......@@ -94,6 +94,7 @@ set(libmailcommon_collection_SRCS
collectionpage/expirecollectionattribute.cpp
collectionpage/newmailnotifierattribute.cpp
collectionpage/incidencesforwidget.cpp
collectionpage/contenttypewidget.cpp
)
set(libmailcommon_folder_SRCS
......
......@@ -19,6 +19,7 @@
#include "collectiontypeutil.h"
#include "incidencesforwidget.h"
#include "contenttypewidget.h"
#include "collectionannotationsattribute.h"
#include "newmailnotifierattribute.h"
#include "foldercollection.h"
......@@ -46,11 +47,6 @@
#include <QLabel>
#include <QVBoxLayout>
// TODO Where should these be?
#define KOLAB_FOLDERTYPE "/shared/vendor/kolab/folder-type"
#define KOLAB_INCIDENCESFOR "/shared/vendor/kolab/incidences-for"
#define KOLAB_SHAREDSEEN "/shared/vendor/cmu/cyrus-imapd/sharedseen"
using namespace Akonadi;
using namespace MailCommon;
......@@ -58,6 +54,7 @@ CollectionGeneralPage::CollectionGeneralPage( QWidget *parent )
: CollectionPropertiesPage( parent ),
mContentsComboBox(0),
mIncidencesForComboBox(0),
mSharedSeenFlagsCheckBox(0),
mNameEdit( 0 ),
mFolderCollection( 0 )
{
......@@ -69,7 +66,7 @@ CollectionGeneralPage::~CollectionGeneralPage()
{
}
static void addLine( QWidget *parent, QVBoxLayout *layout )
void CollectionGeneralPage::addLine( QWidget *parent, QVBoxLayout *layout )
{
QFrame *line = new QFrame( parent );
line->setGeometry( QRect( 80, 150, 250, 20 ) );
......@@ -183,43 +180,31 @@ void CollectionGeneralPage::init( const Akonadi::Collection &collection )
"automatically. Identities can be set up in the main configuration "
"dialog. (Settings -> Configure KMail)" ) );
CollectionTypeUtil::FolderContentsType contentsType = CollectionTypeUtil::ContentsTypeMail;
const CollectionAnnotationsAttribute *annotationAttribute =
collection.attribute<CollectionAnnotationsAttribute>();
// Only do make this settable, if the IMAP resource is enabled
// and it's not the personal folders (those must not be changed)
if ( PimCommon::Util::isImapResource(collection.resource()) ) {
CollectionTypeUtil::FolderContentsType contentsType = CollectionTypeUtil::ContentsTypeMail;
const QMap<QByteArray, QByteArray> annotations =
( annotationAttribute ?
annotationAttribute->annotations() :
QMap<QByteArray, QByteArray>() );
const CollectionAnnotationsAttribute *annotationAttribute =
collection.attribute<CollectionAnnotationsAttribute>();
const bool sharedSeen = ( annotations.value( KOLAB_SHAREDSEEN ) == "true" );
const QMap<QByteArray, QByteArray> annotations =
( annotationAttribute ?
annotationAttribute->annotations() :
QMap<QByteArray, QByteArray>() );
CollectionTypeUtil collectionUtil;
const CollectionTypeUtil::IncidencesFor incidencesFor =
collectionUtil.incidencesForFromString( QLatin1String(annotations.value( KOLAB_INCIDENCESFOR )) );
const bool sharedSeen = ( annotations.value( CollectionTypeUtil::kolabSharedSeen() ) == "true" );
const CollectionTypeUtil::FolderContentsType folderType = collectionUtil.typeFromKolabName( annotations.value( KOLAB_FOLDERTYPE ) );
CollectionTypeUtil collectionUtil;
const CollectionTypeUtil::IncidencesFor incidencesFor =
collectionUtil.incidencesForFromString( QLatin1String(annotations.value( CollectionTypeUtil::kolabIncidencesFor() )) );
// Only do make this settable, if the IMAP resource is enabled
// and it's not the personal folders (those must not be changed)
if ( PimCommon::Util::isImapResource(collection.resource()) ) {
++row;
label = new QLabel( i18n( "&Folder contents:" ), this );
gl->addWidget( label, row, 0 );
mContentsComboBox = new KComboBox( this );
label->setBuddy( mContentsComboBox );
gl->addWidget( mContentsComboBox, row, 1 );
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 ) );
const CollectionTypeUtil::FolderContentsType folderType = collectionUtil.typeFromKolabName( annotations.value( CollectionTypeUtil::kolabFolderType() ) );
++row;
mContentsComboBox = new ContentTypeWidget(this);
gl->addWidget(mContentsComboBox, row, 0, 1, 2);
mContentsComboBox->setCurrentIndex( contentsType );
connect( mContentsComboBox, SIGNAL(activated(int)),
......@@ -235,7 +220,7 @@ void CollectionGeneralPage::init( const Akonadi::Collection &collection )
const bool folderTypeComboboxEnabled = ( folderType == CollectionTypeUtil::ContentsTypeCalendar || folderType == CollectionTypeUtil::ContentsTypeTask );
++row;
mIncidencesForComboBox = new IncidencesForWidget(this);
gl->addWidget(mIncidencesForComboBox, row, 0, 1, 1);
gl->addWidget(mIncidencesForComboBox, row, 0, 1, 2);
mIncidencesForComboBox->setCurrentIndex( incidencesFor );
mIncidencesForComboBox->setEnabled(folderTypeComboboxEnabled);
......@@ -250,8 +235,6 @@ void CollectionGeneralPage::init( const Akonadi::Collection &collection )
"the same for all users having access to this folder. If disabled "
"(the default), every user with access to this folder has their "
"own unread state." ) );
} else {
mSharedSeenFlagsCheckBox = 0;
}
topLayout->addStretch( 100 ); // eat all superfluous space
......@@ -290,10 +273,10 @@ void CollectionGeneralPage::load( const Akonadi::Collection &collection )
if ( annotationsAttribute ) {
const QMap<QByteArray, QByteArray> annotations = annotationsAttribute->annotations();
if ( annotations.contains( KOLAB_FOLDERTYPE ) ) {
if ( annotations.contains( CollectionTypeUtil::kolabFolderType() ) ) {
CollectionTypeUtil collectionUtil;
mContentsComboBox->setCurrentItem(
collectionUtil.typeNameFromKolabType( annotations[ KOLAB_FOLDERTYPE ] ) );
collectionUtil.typeNameFromKolabType( annotations[ CollectionTypeUtil::kolabFolderType() ] ) );
}
}
}
......@@ -338,12 +321,12 @@ void CollectionGeneralPage::save( Collection &collection )
QMap<QByteArray, QByteArray> annotations = annotationsAttribute->annotations();
if ( mSharedSeenFlagsCheckBox && mSharedSeenFlagsCheckBox->isEnabled() ) {
annotations[ KOLAB_SHAREDSEEN ] = mSharedSeenFlagsCheckBox->isChecked() ? "true" : "false";
annotations[ CollectionTypeUtil::kolabSharedSeen() ] = mSharedSeenFlagsCheckBox->isChecked() ? "true" : "false";
}
CollectionTypeUtil collectionUtil;
if ( mIncidencesForComboBox && mIncidencesForComboBox->isEnabled() ) {
annotations[ KOLAB_INCIDENCESFOR ] =
annotations[ CollectionTypeUtil::kolabIncidencesFor() ] =
collectionUtil.incidencesForToString(
static_cast<CollectionTypeUtil::IncidencesFor>( mIncidencesForComboBox->currentIndex() ) ).toLatin1();
}
......@@ -354,42 +337,12 @@ void CollectionGeneralPage::save( Collection &collection )
const QByteArray kolabName = collectionUtil.kolabNameFromType( type ) ;
if ( !kolabName.isEmpty() ) {
QString iconName;
switch( type ) {
case CollectionTypeUtil::ContentsTypeCalendar:
iconName= QString::fromLatin1( "view-calendar" );
break;
case CollectionTypeUtil::ContentsTypeContact:
iconName= QString::fromLatin1( "view-pim-contacts" );
break;
case CollectionTypeUtil::ContentsTypeNote:
iconName = QString::fromLatin1( "view-pim-notes" );
break;
case CollectionTypeUtil::ContentsTypeTask:
iconName = QString::fromLatin1( "view-pim-tasks" );
break;
case CollectionTypeUtil::ContentsTypeJournal:
iconName = QString::fromLatin1( "view-pim-journal" );
break;
case CollectionTypeUtil::ContentsTypeConfiguration:
iconName = QString::fromLatin1( "configure" );
break;
case CollectionTypeUtil::ContentsTypeFreebusy:
iconName = QString::fromLatin1( "view-calendar-agenda" );
break;
case CollectionTypeUtil::ContentsTypeFile:
iconName = QString::fromLatin1( "document-open" );
break;
case CollectionTypeUtil::ContentsTypeMail:
default:
break;
}
const QString iconName = collectionUtil.iconNameFromContentsType(type);
Akonadi::EntityDisplayAttribute *attribute =
collection.attribute<Akonadi::EntityDisplayAttribute>( Akonadi::Entity::AddIfMissing );
attribute->setIconName( iconName );
new Akonadi::CollectionModifyJob( collection );
annotations[ KOLAB_FOLDERTYPE ] = kolabName;
annotations[ CollectionTypeUtil::kolabFolderType() ] = kolabName;
}
}
if ( annotations.isEmpty() ) {
......
......@@ -32,11 +32,12 @@ template <typename T> class QSharedPointer;
namespace KPIMIdentities {
class IdentityCombo;
}
class QVBoxLayout;
namespace MailCommon {
class FolderCollection;
class IncidencesForWidget;
class ContentTypeWidget;
class MAILCOMMON_EXPORT CollectionGeneralPage : public Akonadi::CollectionPropertiesPage
{
Q_OBJECT
......@@ -57,8 +58,9 @@ private Q_SLOTS:
void slotNameChanged( const QString &name );
private:
void addLine(QWidget *parent, QVBoxLayout *layout);
QString mColorName;
KComboBox *mContentsComboBox;
ContentTypeWidget *mContentsComboBox;
IncidencesForWidget *mIncidencesForComboBox;
QCheckBox *mSharedSeenFlagsCheckBox;
QCheckBox *mNotifyOnNewMailCheckBox;
......
......@@ -32,6 +32,22 @@ CollectionTypeUtil::~CollectionTypeUtil()
}
QByteArray CollectionTypeUtil::kolabFolderType()
{
return "/shared/vendor/kolab/folder-type";
}
QByteArray CollectionTypeUtil::kolabIncidencesFor()
{
return "/shared/vendor/kolab/incidences-for";
}
QByteArray CollectionTypeUtil::kolabSharedSeen()
{
return "/shared/vendor/cmu/cyrus-imapd/sharedseen";
}
QString CollectionTypeUtil::folderContentDescription( CollectionTypeUtil::FolderContentsType type )
{
switch ( type ) {
......@@ -204,3 +220,40 @@ QString CollectionTypeUtil::typeNameFromKolabType( const QByteArray &type )
return i18nc( "type of folder content", "Mail" );
}
QString CollectionTypeUtil::iconNameFromContentsType(CollectionTypeUtil::FolderContentsType type)
{
QString iconName;
switch (type) {
case CollectionTypeUtil::ContentsTypeCalendar:
iconName = QString::fromLatin1( "view-calendar" );
break;
case CollectionTypeUtil::ContentsTypeContact:
iconName= QString::fromLatin1( "view-pim-contacts" );
break;
case CollectionTypeUtil::ContentsTypeNote:
iconName = QString::fromLatin1( "view-pim-notes" );
break;
case CollectionTypeUtil::ContentsTypeTask:
iconName = QString::fromLatin1( "view-pim-tasks" );
break;
case CollectionTypeUtil::ContentsTypeJournal:
iconName = QString::fromLatin1( "view-pim-journal" );
break;
case CollectionTypeUtil::ContentsTypeConfiguration:
iconName = QString::fromLatin1( "configure" );
break;
case CollectionTypeUtil::ContentsTypeFreebusy:
iconName = QString::fromLatin1( "view-calendar-agenda" );
break;
case CollectionTypeUtil::ContentsTypeFile:
iconName = QString::fromLatin1( "document-open" );
break;
case CollectionTypeUtil::ContentsTypeMail:
default:
break;
}
return iconName;
}
......@@ -32,6 +32,11 @@ public:
CollectionTypeUtil();
~CollectionTypeUtil();
static QByteArray kolabFolderType();
static QByteArray kolabIncidencesFor();
static QByteArray kolabSharedSeen();
enum FolderContentsType {
ContentsTypeMail = 0,
ContentsTypeCalendar,
......@@ -58,6 +63,7 @@ public:
QString incidencesForToString(CollectionTypeUtil::IncidencesFor type);
CollectionTypeUtil::FolderContentsType contentsTypeFromString(const QString &type);
QString typeNameFromKolabType(const QByteArray &type);
QString iconNameFromContentsType(CollectionTypeUtil::FolderContentsType type);
};
}
#endif // COLLECTIONTYPEUTIL_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