From 984ecc44a22c3b9849939b3738d16e48cd93f1ea Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Thu, 12 Nov 2009 13:52:56 +0000 Subject: [PATCH] Start porting the ACL page of the collection properties. For now you can list IMAP ACLs. svn path=/branches/work/akonadi-ports/kdepim/; revision=1047976 --- CMakeLists.txt | 1 + collectionaclpage.cpp | 57 +++++++++++++++++-------- folderselectiontreeview.cpp | 5 +++ imapaclattribute.cpp | 83 +++++++++++++++++++++++++++++++++++++ imapaclattribute.h | 49 ++++++++++++++++++++++ 5 files changed, 178 insertions(+), 17 deletions(-) create mode 100644 imapaclattribute.cpp create mode 100644 imapaclattribute.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dd6cd7787..fccc42356 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ set(kmailprivate_LIB_SRCS collectionquotapage.cpp collectionquotapage_p.cpp collectionaclpage.cpp + imapaclattribute.cpp messagehelper.cpp messageinfo.cpp foldercollection.cpp diff --git a/collectionaclpage.cpp b/collectionaclpage.cpp index dd5278722..09dfc6ef5 100644 --- a/collectionaclpage.cpp +++ b/collectionaclpage.cpp @@ -33,6 +33,10 @@ #include #include #include "messageviewer/autoqpointer.h" +#include "imapaclattribute.h" + +#include +#include #include #include @@ -59,19 +63,18 @@ #include #include -#if 0 // The set of standard permission sets static const struct { unsigned int permissions; const char* userString; } standardPermissions[] = { - { 0, I18N_NOOP2( "Permissions", "None" ) }, - { ACLJobs::List | ACLJobs::Read | ACLJobs::WriteSeenFlag, I18N_NOOP2( "Permissions", "Read" ) }, - { ACLJobs::List | ACLJobs::Read | ACLJobs::WriteSeenFlag | ACLJobs::Insert | ACLJobs::Post, I18N_NOOP2( "Permissions", "Append" ) }, - { ACLJobs::AllWrite, I18N_NOOP2( "Permissions", "Write" ) }, - { ACLJobs::All, I18N_NOOP2( "Permissions", "All" ) } + { KIMAP::Acl::None, I18N_NOOP2( "Permissions", "None" ) }, + { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen, I18N_NOOP2( "Permissions", "Read" ) }, + { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen | KIMAP::Acl::Insert | KIMAP::Acl::Post, I18N_NOOP2( "Permissions", "Append" ) }, + { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen | KIMAP::Acl::Write, I18N_NOOP2( "Permissions", "Write" ) }, + { KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen | KIMAP::Acl::Insert | KIMAP::Acl::Post | KIMAP::Acl::Write, I18N_NOOP2( "Permissions", "All" ) } }; -#endif + #if 0 ACLEntryDialog::ACLEntryDialog( IMAPUserIdFormat userIdFormat, const QString& caption, QWidget* parent ) : KDialog( parent ) @@ -203,6 +206,7 @@ unsigned int ACLEntryDialog::permissions() const return static_cast(-1); // hm ? return mButtonGroup->id( button ); } +#endif class CollectionAclPage::ListViewItem : public QTreeWidgetItem { @@ -211,7 +215,7 @@ public: : QTreeWidgetItem( listview ), mModified( false ), mNew( false ) {} - void load( const ACLListEntry& entry ); + void load( const QByteArray &id, KIMAP::Acl::Rights rights ); void save( ACLList& list, KABC::AddressBook* abook, IMAPUserIdFormat userIdFormat ); @@ -258,27 +262,28 @@ void CollectionAclPage::ListViewItem::setPermissions( unsigned int permissions ) setText( 1, permissionsToUserString( permissions, QString() ) ); } -void CollectionAclPage::ListViewItem::load( const ACLListEntry& entry ) +void CollectionAclPage::ListViewItem::load( const QByteArray &id, KIMAP::Acl::Rights rights ) { // Don't allow spaces in userids. If you need this, fix the slave->app communication, // since it uses space as a separator (imap4.cc, look for GETACL) // It's ok in distribution list names though, that's why this check is only done here // and also why there's no validator on the lineedit. - if ( entry.userId.contains( ' ' ) ) { - kWarning() << "Userid contains a space:" << entry.userId; + if ( id.contains( ' ' ) ) { + kWarning() << "Userid contains a space:" << id; } - setUserId( entry.userId ); - mPermissions = entry.permissions; - mInternalRightsList = entry.internalRightsList; - setText( 1, permissionsToUserString( entry.permissions, entry.internalRightsList ) ); - mModified = entry.changed; // for dimap, so that earlier changes are still marked as changes + setUserId( id ); + mPermissions = rights; + mInternalRightsList = KIMAP::Acl::rightsToString( rights ); + setText( 1, permissionsToUserString( mPermissions, mInternalRightsList ) ); + mModified = true; // for dimap, so that earlier changes are still marked as changes } void CollectionAclPage::ListViewItem::save( ACLList& aclList, KABC::AddressBook* addressBook, IMAPUserIdFormat userIdFormat ) { + #if 0 // expand distribution lists KABC::DistributionList* list = addressBook->findDistributionListByName( userId(), Qt::CaseInsensitive ); if ( list ) { @@ -301,8 +306,9 @@ void CollectionAclPage::ListViewItem::save( ACLList& aclList, } aclList.append( entry ); } + #endif } -#endif + //// CollectionAclPage::CollectionAclPage( QWidget* parent ) @@ -369,6 +375,23 @@ void CollectionAclPage::init() void CollectionAclPage::load(const Akonadi::Collection & col) { + if ( !col.hasAttribute() ) { + return; + } + + Akonadi::ImapAclAttribute *acls = col.attribute(); + QMap rights = acls->rights(); + + mListView->clear(); + foreach ( const QByteArray &id, rights.keys() ) { + ListViewItem* item = new ListViewItem( mListView ); + item->load( id, rights[id] ); + if ( !col.isValid() ) // new collection? everything is new then + item->setModified( true ); + } + + mStack->setCurrentWidget( mACLWidget ); + //slotSelectionChanged(); } void CollectionAclPage::save(Akonadi::Collection & col) diff --git a/folderselectiontreeview.cpp b/folderselectiontreeview.cpp index b9b48eb89..c9bc70818 100644 --- a/folderselectiontreeview.cpp +++ b/folderselectiontreeview.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,8 @@ #include #include +#include "imapaclattribute.h" + #include "readablecollectionproxymodel.h" #include "globalsettings.h" @@ -60,6 +63,8 @@ public: FolderSelectionTreeView::FolderSelectionTreeView( QWidget *parent, KXMLGUIClient *xmlGuiClient ) : QWidget( parent ), d( new FolderSelectionTreeViewPrivate() ) { + Akonadi::AttributeFactory::registerAttribute(); + QHBoxLayout *lay = new QHBoxLayout( this ); lay->setMargin( 0 ); Akonadi::Session *session = new Akonadi::Session( "KMail Session", this ); diff --git a/imapaclattribute.cpp b/imapaclattribute.cpp new file mode 100644 index 000000000..b6ab031f4 --- /dev/null +++ b/imapaclattribute.cpp @@ -0,0 +1,83 @@ +/* + Copyright (C) 2009 Kevin Ottens + + 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 "imapaclattribute.h" + +#include + +using namespace Akonadi; + +ImapAclAttribute::ImapAclAttribute() +{ +} + +ImapAclAttribute::ImapAclAttribute( const QMap &rights ) + : mRights( rights ) +{ +} + +void ImapAclAttribute::setRights( const QMap &rights ) +{ + mRights = rights; +} + +QMap ImapAclAttribute::rights() const +{ + return mRights; +} + +QByteArray ImapAclAttribute::type() const +{ + return "imapacl"; +} + +Akonadi::Attribute* ImapAclAttribute::clone() const +{ + return new ImapAclAttribute( mRights ); +} + +QByteArray ImapAclAttribute::serialized() const +{ + QByteArray result = ""; + + foreach ( const QByteArray &id, mRights.keys() ) { + result+= id; + result+= ' '; + result+= KIMAP::Acl::rightsToString( mRights[id] ); + result+= " % "; // We use this separator as '%' is not allowed in keys or values + } + result.chop( 3 ); + + return result; + +} + +void ImapAclAttribute::deserialize( const QByteArray &data ) +{ + mRights.clear(); + QList lines = data.split( '%' ); + + foreach ( const QByteArray &line, lines ) { + QByteArray trimmed = line.trimmed(); + int wsIndex = trimmed.indexOf( ' ' ); + const QByteArray id = trimmed.mid( 0, wsIndex ).trimmed(); + const QByteArray value = trimmed.mid( wsIndex+1, line.length()-wsIndex ).trimmed(); + mRights[id] = KIMAP::Acl::rightsFromString( value ); + } +} diff --git a/imapaclattribute.h b/imapaclattribute.h new file mode 100644 index 000000000..392441859 --- /dev/null +++ b/imapaclattribute.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2009 Kevin Ottens + + 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 AKONADI_IMAPACLATTRIBUTE_H +#define AKONADI_IMAPACLATTRIBUTE_H + +#include + +#include + +#include + +namespace Akonadi { + +class ImapAclAttribute : public Akonadi::Attribute +{ + public: + ImapAclAttribute(); + ImapAclAttribute( const QMap &rights ); + void setRights( const QMap &rights ); + QMap rights() const; + virtual QByteArray type() const; + virtual Attribute *clone() const; + virtual QByteArray serialized() const; + virtual void deserialize( const QByteArray &data ); + + private: + QMap mRights; +}; + +} + +#endif