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
wilder-work
Kevin Ottens 17 years ago
parent 001ca9585f
commit 984ecc44a2
  1. 1
      CMakeLists.txt
  2. 57
      collectionaclpage.cpp
  3. 5
      folderselectiontreeview.cpp
  4. 83
      imapaclattribute.cpp
  5. 49
      imapaclattribute.h

@ -78,6 +78,7 @@ set(kmailprivate_LIB_SRCS
collectionquotapage.cpp
collectionquotapage_p.cpp
collectionaclpage.cpp
imapaclattribute.cpp
messagehelper.cpp
messageinfo.cpp
foldercollection.cpp

@ -33,6 +33,10 @@
#include <khbox.h>
#include <QStackedWidget>
#include "messageviewer/autoqpointer.h"
#include "imapaclattribute.h"
#include <akonadi/collection.h>
#include <akonadi/collectionmodifyjob.h>
#include <addressesdialog.h>
#include <kabc/addresseelist.h>
@ -59,19 +63,18 @@
#include <kmessagebox.h>
#include <kvbox.h>
#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<unsigned int>(-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<Akonadi::ImapAclAttribute>() ) {
return;
}
Akonadi::ImapAclAttribute *acls = col.attribute<Akonadi::ImapAclAttribute>();
QMap<QByteArray, KIMAP::Acl::Rights> 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)

@ -21,6 +21,7 @@
#include <QSortFilterProxyModel>
#include <QHBoxLayout>
#include <akonadi/attributefactory.h>
#include <akonadi/entitytreeview.h>
#include <akonadi/changerecorder.h>
#include <akonadi/session.h>
@ -32,6 +33,8 @@
#include <akonadi/statisticsproxymodel.h>
#include <akonadi_next/quotacolorproxymodel.h>
#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<Akonadi::ImapAclAttribute>();
QHBoxLayout *lay = new QHBoxLayout( this );
lay->setMargin( 0 );
Akonadi::Session *session = new Akonadi::Session( "KMail Session", this );

@ -0,0 +1,83 @@
/*
Copyright (C) 2009 Kevin Ottens <ervin@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 "imapaclattribute.h"
#include <QtCore/QByteArray>
using namespace Akonadi;
ImapAclAttribute::ImapAclAttribute()
{
}
ImapAclAttribute::ImapAclAttribute( const QMap<QByteArray, KIMAP::Acl::Rights> &rights )
: mRights( rights )
{
}
void ImapAclAttribute::setRights( const QMap<QByteArray, KIMAP::Acl::Rights> &rights )
{
mRights = rights;
}
QMap<QByteArray, KIMAP::Acl::Rights> 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<QByteArray> 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 );
}
}

@ -0,0 +1,49 @@
/*
Copyright (C) 2009 Kevin Ottens <ervin@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 AKONADI_IMAPACLATTRIBUTE_H
#define AKONADI_IMAPACLATTRIBUTE_H
#include <akonadi/attribute.h>
#include <QtCore/QMap>
#include <kimap/acl.h>
namespace Akonadi {
class ImapAclAttribute : public Akonadi::Attribute
{
public:
ImapAclAttribute();
ImapAclAttribute( const QMap<QByteArray, KIMAP::Acl::Rights> &rights );
void setRights( const QMap<QByteArray, KIMAP::Acl::Rights> &rights );
QMap<QByteArray, KIMAP::Acl::Rights> rights() const;
virtual QByteArray type() const;
virtual Attribute *clone() const;
virtual QByteArray serialized() const;
virtual void deserialize( const QByteArray &data );
private:
QMap<QByteArray, KIMAP::Acl::Rights> mRights;
};
}
#endif
Loading…
Cancel
Save