Commit d619e4a5 authored by Volker Krause's avatar Volker Krause
Browse files

- map collection name changes to resource name changes

- allow to rename collections also in readonly mode
- provide a collection icon

svn path=/trunk/KDE/kdepim/akonadi/; revision=875727
parent 7df1e7d6
......@@ -24,8 +24,6 @@
#include <kcal/calendarlocal.h>
#include <kcal/incidence.h>
#include <akonadi/changerecorder.h>
#include <akonadi/itemfetchscope.h>
#include <akonadi/kcal/kcalmimetypevisitor.h>
#include <kdebug.h>
......@@ -46,12 +44,11 @@ ICalResource::ICalResource( const QString &id )
QStringList mimeTypes;
mimeTypes << QLatin1String( "text/calendar" );
mimeTypes += mMimeVisitor->allMimeTypes();
setSupportedMimetypes( mimeTypes );
setSupportedMimetypes( mimeTypes, "office-calendar" );
new SettingsAdaptor( Settings::self() );
QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
Settings::self(), QDBusConnection::ExportAdaptors );
changeRecorder()->itemFetchScope().fetchFullPayload();
}
ICalResource::~ICalResource()
......
......@@ -32,7 +32,7 @@ namespace Akonadi {
class KCalMimeTypeVisitor;
}
class ICalResource : public Akonadi::SingleFileResource<Settings>, public Akonadi::AgentBase::Observer
class ICalResource : public Akonadi::SingleFileResource<Settings>
{
Q_OBJECT
......
......@@ -23,6 +23,8 @@
#include "singlefileresourcebase.h"
#include <akonadi/collectiondisplayattribute.h>
#include <KLocale>
#include <QFile>
......@@ -61,6 +63,8 @@ class SingleFileResource : public SingleFileResourceBase
if ( !mCurrentUrl.isEmpty() )
writeFile();
const bool nameWasChanged = mCurrentUrl.fileName() != name() && !mCurrentUrl.isEmpty();
if ( Settings::self()->path().isEmpty() ) {
emit status( Broken, i18n( "No file selected." ) );
return;
......@@ -71,6 +75,8 @@ class SingleFileResource : public SingleFileResourceBase
// NOTE: Test what happens with remotefile -> save, close before save is finished.
mCurrentUrl = KUrl( Settings::self()->path() );
if ( !nameWasChanged )
setName( mCurrentUrl.fileName() );
// check if the file does not exist yet, if so, create it
if ( !QFile::exists( mCurrentUrl.path() ) ) {
......@@ -125,18 +131,22 @@ class SingleFileResource : public SingleFileResourceBase
Collection c;
c.setParent( Collection::root() );
c.setRemoteId( Settings::self()->path() );
c.setName( name() );
c.setName( identifier() );
QStringList mimeTypes;
c.setContentMimeTypes( mSupportedMimetypes );
if ( Settings::self()->readOnly() ) {
c.setRights( Collection::ReadOnly );
c.setRights( Collection::CanChangeCollection );
} else {
Collection::Rights rights;
rights |= Collection::CanChangeItem;
rights |= Collection::CanCreateItem;
rights |= Collection::CanDeleteItem;
rights |= Collection::CanChangeCollection;
c.setRights( rights );
}
CollectionDisplayAttribute* attr = c.attribute<CollectionDisplayAttribute>( Collection::AddIfMissing );
attr->setDisplayName( name() );
attr->setIconName( mCollectionIcon );
Collection::List list;
list << c;
collectionsRetrieved( list );
......
......@@ -20,6 +20,10 @@
#include "singlefileresourcebase.h"
#include <akonadi/changerecorder.h>
#include <akonadi/collectiondisplayattribute.h>
#include <akonadi/itemfetchscope.h>
using namespace Akonadi;
SingleFileResourceBase::SingleFileResourceBase( const QString & id ) :
......@@ -30,11 +34,28 @@ SingleFileResourceBase::SingleFileResourceBase( const QString & id ) :
connect( this, SIGNAL(reloadConfiguration()), SLOT(readFile()) );
QTimer::singleShot( 0, this, SLOT(readFile()) );
changeRecorder()->itemFetchScope().fetchFullPayload();
changeRecorder()->fetchCollection( true );
}
void SingleFileResourceBase::setSupportedMimetypes(const QStringList & mimeTypes)
void SingleFileResourceBase::setSupportedMimetypes(const QStringList & mimeTypes, const QString &icon)
{
mSupportedMimetypes = mimeTypes;
mCollectionIcon = icon;
}
void SingleFileResourceBase::collectionChanged(const Akonadi::Collection & collection)
{
QString newName = collection.name();
if ( collection.hasAttribute<CollectionDisplayAttribute>() ) {
CollectionDisplayAttribute *attr = collection.attribute<CollectionDisplayAttribute>();
if ( !attr->displayName().isEmpty() )
newName = attr->displayName();
}
if ( newName != name() )
setName( newName );
}
#include "singlefileresourcebase.moc"
......@@ -33,16 +33,18 @@ namespace Akonadi
* Base class for single file based resources.
* @see SingleFileResource
*/
class SingleFileResourceBase : public ResourceBase
class SingleFileResourceBase : public ResourceBase, public Akonadi::AgentBase::Observer
{
Q_OBJECT
public:
SingleFileResourceBase( const QString &id );
/**
* Set the mimetypes supported by this resource.
* Set the mimetypes supported by this resource and an optional icon for the collection.
*/
void setSupportedMimetypes( const QStringList &mimeTypes );
void setSupportedMimetypes( const QStringList &mimeTypes, const QString &icon = QString() );
void collectionChanged( const Akonadi::Collection &collection );
public Q_SLOTS:
virtual void readFile() = 0;
......@@ -67,6 +69,7 @@ class SingleFileResourceBase : public ResourceBase
QTimer mDirtyTimer;
KUrl mCurrentUrl;
QStringList mSupportedMimetypes;
QString mCollectionIcon;
};
}
......
......@@ -22,9 +22,6 @@
#include "settingsadaptor.h"
#include "singlefileresourceconfigdialog.h"
#include <akonadi/changerecorder.h>
#include <akonadi/itemfetchscope.h>
#include <kfiledialog.h>
#include <klocale.h>
#include <KWindowSystem>
......@@ -35,12 +32,11 @@ using namespace Akonadi;
VCardResource::VCardResource( const QString &id )
: SingleFileResource<Settings>( id )
{
setSupportedMimetypes( QStringList() << "text/directory" );
setSupportedMimetypes( QStringList() << "text/directory", "office-address-book" );
new SettingsAdaptor( Settings::self() );
QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
Settings::self(), QDBusConnection::ExportAdaptors );
changeRecorder()->itemFetchScope().fetchFullPayload();
}
VCardResource::~VCardResource()
......
......@@ -26,7 +26,7 @@
#include <kabc/addressee.h>
#include <kabc/vcardconverter.h>
class VCardResource : public Akonadi::SingleFileResource<Settings>, public Akonadi::AgentBase::Observer
class VCardResource : public Akonadi::SingleFileResource<Settings>
{
Q_OBJECT
......
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