Commit 84449fb8 authored by Volker Krause's avatar Volker Krause
Browse files

- provide a way to notify agents that their configuration has been

  changed remotely and make use of that in the vcard resource
- add an initial kabc kresources migrator, mostly infrastructure, so far
  it can only handle vcard files

svn path=/trunk/KDE/kdepim/akonadi/; revision=845126
parent a2ef8841
......@@ -34,6 +34,7 @@ add_subdirectory(kabc)
add_subdirectory(kcal)
add_subdirectory(kcm)
add_subdirectory(tray)
add_subdirectory(migration)
if( Nepomuk_FOUND )
add_subdirectory(nepomuk)
......
add_subdirectory( kres )
set(kres-migrator_srcs
main.cpp
kabcmigrator.cpp
)
kcfg_generate_dbus_interface(${CMAKE_SOURCE_DIR}/akonadi/resources/vcard/vcardresource.kcfg org.kde.Akonadi.VCard.Settings)
qt4_add_dbus_interface(kres-migrator_srcs
${CMAKE_CURRENT_BINARY_DIR}/org.kde.Akonadi.VCard.Settings.xml vcardsettings VCardSettings
)
kde4_add_app_icon(kres-migrator_srcs "${KDE4_ICON_DIR}/oxygen/*/apps/email.png")
kde4_add_executable(kres-migrator ${kres-migrator_srcs})
target_link_libraries(kres-migrator ${KDE4_AKONADI_LIBS} ${KDE4_KRESOURCE_LIBS} ${KDE4_KABC_LIBS})
install(TARGETS kres-migrator ${INSTALL_TARGETS_DEFAULT_ARGS})
/*
Copyright (c) 2008 Volker Krause <vkrause@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 "kabcmigrator.h"
#include "vcardsettings.h"
#include <akonadi/agentinstance.h>
#include <akonadi/agentinstancecreatejob.h>
#include <akonadi/agentmanager.h>
#include <akonadi/agenttype.h>
#include <KDebug>
#include <KGlobal>
using namespace Akonadi;
KABCMigrator::KABCMigrator()
{
migrateType( "contact" );
}
KABCMigrator::~KABCMigrator()
{
}
void KABCMigrator::migrateResource( KABC::Resource* res)
{
kDebug() << res->identifier() << res->type();
if ( res->type() == "file" )
migrateFileResource( res );
else
migrateNext();
}
void KABCMigrator::migrateFileResource(KABC::Resource * res)
{
kDebug();
const KConfigGroup kresCfg = kresConfig( res );
if ( kresCfg.readEntry( "FileFormat", "" ) != "vcard" ) {
kDebug() << "Unsupported file format found!";
return;
}
const AgentType type = AgentManager::self()->type( "akonadi_vcard_resource" );
if ( !type.isValid() ) {
kDebug() << "Unable to obtain vcard resource type!";
return;
}
AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type, this );
connect( job, SIGNAL(result(KJob*)), SLOT(fileResourceCreated(KJob*)) );
mJobMap.insert( job, res );
job->start();
}
void KABCMigrator::fileResourceCreated(KJob * job)
{
kDebug();
if ( job->error() ) {
kDebug() << "Failed to create vcard resource!";
return;
}
Q_ASSERT( mJobMap.contains( job ) );
KABC::Resource *res = mJobMap.take( job );
AgentInstance instance = static_cast<AgentInstanceCreateJob*>( job )->instance();
const KConfigGroup kresCfg = kresConfig( res );
instance.setName( kresCfg.readEntry( "ResourceName", "Migrated Addressbook" ) );
kDebug() << "org.kde.Akonadi.Resource." + instance.identifier();
OrgKdeAkonadiVCardSettingsInterface *iface = new OrgKdeAkonadiVCardSettingsInterface( "org.freedesktop.Akonadi.Resource." + instance.identifier(),
"/Settings", QDBusConnection::sessionBus(), this );
if ( !iface->isValid() ) {
kDebug() << "Failed to obtain dbus interface for resource configuration!";
return;
}
iface->setPath( kresCfg.readPathEntry( "FileName", "" ) );
// iface->setReadOnly( res->readOnly() );
iface->setReadOnly( true );
instance.reconfigure();
migrateNext();
}
#include "kabcmigrator.moc"
/*
Copyright (c) 2008 Volker Krause <vkrause@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 KABCMIGRATOR_H
#define KABCMIGRATOR_H
#include "kresmigrator.h"
#include <kabc/resource.h>
#include <QHash>
class KJob;
/**
* Migrate KABC resources to Akonadi
*/
class KABCMigrator : public KResMigrator<KABC::Resource>
{
Q_OBJECT
public:
KABCMigrator();
~KABCMigrator();
void migrateResource( KABC::Resource *res );
private slots:
void fileResourceCreated( KJob* job );
private:
void migrateFileResource( KABC::Resource *res );
private:
QHash<KJob*, KABC::Resource*> mJobMap;
};
#endif
/*
Copyright (c) a2008 Volker Krause <vkrause@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.
*/
/*
Copyright (c) 2008 Volker Krause <vkrause@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 KRESMIGRATOR_H
#define KRESMIGRATOR_H
#include <kresources/manager.h>
#include <kresources/resource.h>
#include <KConfigGroup>
#include <KDebug>
#include <KGlobal>
#include <KStandardDirs>
template <typename T> class KResMigrator : public QObject
{
public:
KResMigrator() : mConfig( 0 )
{
KGlobal::ref();
}
virtual ~KResMigrator()
{
delete mConfig;
delete mManager;
KGlobal::deref();
}
void migrateType( const QString &type )
{
mManager = new KRES::Manager<T>( type );
mManager->readConfig();
const QString kresCfgFile = KStandardDirs::locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( type ) );
mConfig = new KConfig( kresCfgFile );
mIt = mManager->begin();
migrateNext();
}
void migrateNext()
{
while ( mIt != mManager->end() ) {
KConfigGroup cfg( KGlobal::config(), "Resource " + (*mIt)->identifier() );
if ( !cfg.readEntry( "Migrated", false ) ) {
migrateResource( *mIt );
++mIt;
return;
}
++mIt;
}
if ( mIt == mManager->end() )
deleteLater();
}
virtual void migrateResource( T *res ) = 0;
void resourceMigrated( T *res ) const
{
KConfigGroup cfg( KGlobal::config(), "Resource " + res->identifier() );
cfg.writeEntry( "Migrated", true );
cfg.sync();
}
KConfigGroup kresConfig( T* res ) const
{
return KConfigGroup( mConfig, "Resource_" + res->identifier() );
}
private:
KConfig *mConfig;
KRES::Manager<T> *mManager;
typedef typename KRES::Manager<T>::Iterator ResourceIterator;
ResourceIterator mIt;
};
#endif
/*
Copyright (c) 2008 Volker Krause <vkrause@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 "kabcmigrator.h"
#include <akonadi/control.h>
#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kglobal.h>
int main( int argc, char **argv )
{
KAboutData aboutData( "kres-migrator", 0,
ki18n( "KResource Migration Tool" ),
"0.1",
ki18n( "Migration of KResource settings and application to Akonadi" ),
KAboutData::License_LGPL,
ki18n( "(c) 2008 the Akonadi developers" ),
KLocalizedString(),
"http://pim.kde.org/akonadi/" );
aboutData.setProgramIconName( "akonadi" );
aboutData.addAuthor( ki18n( "Volker Krause" ), ki18n( "Author" ), "vkrause@kde.org" );
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication app;
app.setQuitOnLastWindowClosed( false );
KGlobal::setAllowQuit( true );
Akonadi::Control::start();
new KABCMigrator();
// new KCalMigrator();
return app.exec();
}
......@@ -37,6 +37,7 @@ VCardResource::VCardResource( const QString &id )
QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
Settings::self(), QDBusConnection::ExportAdaptors );
changeRecorder()->itemFetchScope().fetchFullPayload();
connect( this, SIGNAL(reloadConfiguration()), SLOT(loadAddressees()) );
loadAddressees();
}
......@@ -163,6 +164,9 @@ void VCardResource::retrieveItems( const Akonadi::Collection & col )
bool VCardResource::loadAddressees()
{
if ( !mAddressees.isEmpty() )
storeAddressees();
mAddressees.clear();
const QString fileName = Settings::self()->path();
......@@ -185,6 +189,7 @@ bool VCardResource::loadAddressees()
mAddressees.insert( list[ i ].uid(), list[ i ] );
}
emit status( Idle );
return true;
}
......
......@@ -48,8 +48,10 @@ class VCardResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::O
virtual void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> &parts );
virtual void itemRemoved( const Akonadi::Item &item );
private:
private Q_SLOTS:
bool loadAddressees();
private:
bool storeAddressees();
private:
......
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