22 #include "imapresourcesettings.h"
23 #include "pimcommon/util/pimutil.h"
26 #include <Akonadi/ItemFetchJob>
27 #include <Akonadi/ItemFetchScope>
28 #include <Akonadi/CollectionModifyJob>
30 using namespace Akonadi;
32 #include <KPIMIdentities/IdentityManager>
33 #include <KPIMIdentities/Identity>
38 #include <QMutexLocker>
39 #include <QSharedPointer>
41 namespace MailCommon {
44 static QMap<Collection::Id,QSharedPointer<FolderCollection> >
fcMap;
47 const Akonadi::Collection &coll,
bool writeConfig )
55 fcMap.insert( coll.id(), sptr );
57 sptr->setCollection( coll );
58 if ( !sptr->isWriteConfig() && writeConfig ) {
59 sptr->setWriteConfig(
true );
66 FolderCollection::FolderCollection(
const Akonadi::Collection & col,
bool writeconfig )
68 mPutRepliesInSameFolder( false ),
69 mHideInSelectionDialog( false ),
70 mWriteConfig( writeconfig )
72 Q_ASSERT( col.isValid() );
73 mIdentity =
KernelIf->identityManager()->defaultIdentity().uoid();
76 connect(
KernelIf->identityManager(), SIGNAL(changed()),
106 return mCollection.name();
116 return mCollection.contentMimeTypes().isEmpty();
121 return mCollection.rights() & Akonadi::Collection::ReadOnly;
126 return mCollection.rights() & Akonadi::Collection::CanDeleteItem;
131 return mCollection.rights() & Akonadi::Collection::CanCreateItem;
136 return mCollection.statistics().count();
141 return mCollection.rights();
146 return mCollection.statistics();
161 uint defaultIdentity =
KernelIf->identityManager()->defaultIdentity().uoid();
163 if ( mUseDefaultIdentity ) {
164 mIdentity = defaultIdentity;
168 if (
KernelIf->identityManager()->identityForUoid( mIdentity ).isNull() ) {
169 mIdentity = defaultIdentity;
170 mUseDefaultIdentity =
true;
176 return QString::fromLatin1(
"Folder-%1" ).arg( QString::number( col.id() ) );
182 mMailingListEnabled = configGroup.readEntry(
"MailingListEnabled",
false );
183 mMailingList.readConfig( configGroup );
185 mUseDefaultIdentity = configGroup.readEntry(
"UseDefaultIdentity",
true );
186 uint defaultIdentity =
KernelIf->identityManager()->defaultIdentity().uoid();
187 mIdentity = configGroup.readEntry(
"Identity", defaultIdentity );
190 mPutRepliesInSameFolder = configGroup.readEntry(
"PutRepliesInSameFolder",
false );
191 mHideInSelectionDialog = configGroup.readEntry(
"HideInSelectionDialog",
false );
193 if (configGroup.hasKey(QLatin1String(
"IgnoreNewMail"))) {
194 if ( configGroup.readEntry( QLatin1String(
"IgnoreNewMail"),
false ) ) {
198 new Akonadi::CollectionModifyJob( mCollection,
this );
201 configGroup.deleteEntry(
"IgnoreNewMail");
204 const QString
shortcut( configGroup.readEntry(
"Shortcut" ) );
213 return mCollection.isValid();
220 configGroup.writeEntry(
"MailingListEnabled", mMailingListEnabled );
221 mMailingList.writeConfig( configGroup );
223 configGroup.writeEntry(
"UseDefaultIdentity", mUseDefaultIdentity );
225 if ( !mUseDefaultIdentity ) {
226 uint defaultIdentityId = -1;
228 if ( mCollection.resource().contains( IMAP_RESOURCE_IDENTIFIER ) ) {
229 OrgKdeAkonadiImapSettingsInterface *imapSettingsInterface =
230 PimCommon::Util::createImapSettingsInterface( mCollection.resource() );
232 if ( imapSettingsInterface->isValid() ) {
233 QDBusReply<int> reply = imapSettingsInterface->accountIdentity();
234 if ( reply.isValid() ) {
235 defaultIdentityId =
static_cast<uint
>( reply );
238 delete imapSettingsInterface;
240 defaultIdentityId =
KernelIf->identityManager()->defaultIdentity().uoid();
243 if ( mIdentity != defaultIdentityId ) {
244 configGroup.writeEntry(
"Identity", mIdentity );
246 configGroup.deleteEntry(
"Identity" );
249 configGroup.deleteEntry(
"Identity" );
252 configGroup.writeEntry(
"PutRepliesInSameFolder", mPutRepliesInSameFolder );
253 if (mHideInSelectionDialog)
254 configGroup.writeEntry(
"HideInSelectionDialog", mHideInSelectionDialog );
256 configGroup.deleteEntry(
"HideInSelectionDialog");
258 if ( !mShortcut.isEmpty() ) {
259 configGroup.writeEntry(
"Shortcut", mShortcut.toString() );
261 configGroup.deleteEntry(
"Shortcut" );
267 if ( mShortcut != sc ) {
274 if ( mUseDefaultIdentity != useDefaultIdentity ) {
276 if ( mUseDefaultIdentity ) {
277 mIdentity =
KernelIf->identityManager()->defaultIdentity().uoid();
285 if ( mIdentity != identity ) {
293 if ( mUseDefaultIdentity ) {
295 OrgKdeAkonadiImapSettingsInterface *imapSettingsInterface =
296 PimCommon::Util::createImapSettingsInterface( mCollection.resource() );
298 if ( imapSettingsInterface->isValid() ) {
299 QDBusReply<bool> useDefault = imapSettingsInterface->useDefaultIdentity();
300 if ( useDefault.isValid() && useDefault.value() ) {
301 delete imapSettingsInterface;
305 QDBusReply<int> remoteAccountIdent = imapSettingsInterface->accountIdentity();
306 if ( remoteAccountIdent.isValid() && remoteAccountIdent.value() > 0 ) {
307 identityId = remoteAccountIdent;
310 delete imapSettingsInterface;
311 if ( identityId != -1 &&
312 !
KernelIf->identityManager()->identityForUoid( identityId ).isNull() ) {
321 if ( mMailingList.features() & MailingList::Post ) {
322 KUrl::List post = mMailingList.postUrls();
323 KUrl::List::const_iterator end( post.constEnd() );
324 for ( KUrl::List::const_iterator it = post.constBegin(); it != end; ++it ) {
327 const QString protocol = (*it).protocol();
328 if ( protocol == QLatin1String(
"mailto" ) || protocol.isEmpty() ) {
338 if ( mMailingListEnabled != enabled ) {
339 mMailingListEnabled = enabled;
346 if ( mMailingList == mlist ) {
350 mMailingList = mlist;
356 #include "foldercollection.moc"
bool canCreateMessages() const
bool useDefaultIdentity() const
void setMailingListEnabled(bool enabled)
Returns true if this folder is associated with a mailing-list.
void setWriteConfig(bool writeConfig)
bool isStructural() const
static QMap< Collection::Id, QSharedPointer< FolderCollection > > fcMap
bool isSystemFolder() const
Akonadi::Collection collection() const
void slotIdentitiesChanged()
static QString configGroupName(const Akonadi::Collection &col)
void setCollection(const Akonadi::Collection &collection)
bool isWriteConfig() const
void setIdentity(uint identity)
const KShortcut & shortcut() const
void setUseDefaultIdentity(bool useDefaultIdentity)
Get / set whether the default identity should be used instead of the identity specified by setIdentit...
void setMailingList(const MailingList &mlist)
void setShortcut(const KShortcut &)
bool isSystemFolderCollection(const Akonadi::Collection &col)
Akonadi::CollectionStatistics statistics() const
bool canDeleteMessages() const
void setIgnoreNewMail(bool b)
Akonadi::Collection::Rights rights() const
QString mailingListPostAddress() const