Commit 6c4a6245 authored by Volker Krause's avatar Volker Krause
Browse files

Keep settings as a member instead of a singleton, in preparation for

running in the agent server.

svn path=/trunk/KDE/kdepim/runtime/; revision=1200544
parent 9edbdabb
......@@ -34,12 +34,13 @@
using namespace Akonadi;
ContactsResource::ContactsResource( const QString &id )
: ResourceBase( id )
: ResourceBase( id ),
mSettings( new Settings( componentData().config() ) )
{
// setup the resource
new SettingsAdaptor( Settings::self() );
new SettingsAdaptor( mSettings );
QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
Settings::self(), QDBusConnection::ExportAdaptors );
mSettings, QDBusConnection::ExportAdaptors );
changeRecorder()->fetchCollection( true );
changeRecorder()->itemFetchScope().fetchFullPayload( true );
......@@ -53,12 +54,13 @@ ContactsResource::ContactsResource( const QString &id )
if ( name().startsWith( QLatin1String( "akonadi_contacts_resource" ) ) )
setName( i18n( "Personal Contacts" ) );
if ( Settings::self()->isConfigured() )
if ( mSettings->isConfigured() )
synchronize();
}
ContactsResource::~ContactsResource()
{
delete mSettings;
}
void ContactsResource::aboutToQuit()
......@@ -67,10 +69,10 @@ void ContactsResource::aboutToQuit()
void ContactsResource::configure( WId windowId )
{
SettingsDialog dlg( windowId );
SettingsDialog dlg( mSettings, windowId );
if ( dlg.exec() ) {
Settings::self()->setIsConfigured( true );
Settings::self()->writeConfig();
mSettings->setIsConfigured( true );
mSettings->writeConfig();
clearCache();
initializeDirectory( baseDirectoryPath() );
......@@ -209,7 +211,7 @@ bool ContactsResource::retrieveItem( const Akonadi::Item &item, const QSet<QByte
void ContactsResource::itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only directory: '%1'", collection.remoteId() ) );
return;
}
......@@ -263,7 +265,7 @@ void ContactsResource::itemAdded( const Akonadi::Item &item, const Akonadi::Coll
void ContactsResource::itemChanged( const Akonadi::Item &item, const QSet<QByteArray>& )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only file: '%1'", item.remoteId() ) );
return;
}
......@@ -313,7 +315,7 @@ void ContactsResource::itemChanged( const Akonadi::Item &item, const QSet<QByteA
void ContactsResource::itemRemoved( const Akonadi::Item &item )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only file: '%1'", item.remoteId() ) );
return;
}
......@@ -338,7 +340,7 @@ void ContactsResource::itemRemoved( const Akonadi::Item &item )
void ContactsResource::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only directory: '%1'", parent.remoteId() ) );
return;
}
......@@ -359,7 +361,7 @@ void ContactsResource::collectionAdded( const Akonadi::Collection &collection, c
void ContactsResource::collectionChanged( const Akonadi::Collection &collection )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only directory: '%1'", collection.remoteId() ) );
return;
}
......@@ -413,7 +415,7 @@ static bool removeDirectory( const QDir &directory )
void ContactsResource::collectionRemoved( const Akonadi::Collection &collection )
{
if ( Settings::self()->readOnly() ) {
if ( mSettings->readOnly() ) {
cancelTask( i18n( "Trying to write to a read-only directory: '%1'", collection.remoteId() ) );
return;
}
......@@ -452,7 +454,7 @@ void ContactsResource::collectionMoved( const Akonadi::Collection &collection, c
QString ContactsResource::baseDirectoryPath() const
{
return Settings::self()->path();
return mSettings->path();
}
void ContactsResource::initializeDirectory( const QString &path ) const
......@@ -478,7 +480,7 @@ Collection::Rights ContactsResource::supportedRights( bool isResourceCollection
{
Collection::Rights rights = Collection::ReadOnly;
if ( !Settings::self()->readOnly() ) {
if ( !mSettings->readOnly() ) {
rights |= Collection::CanChangeItem;
rights |= Collection::CanCreateItem;
rights |= Collection::CanDeleteItem;
......
......@@ -27,6 +27,7 @@
#include <kabc/contactgrouptool.h>
#include <kabc/vcardconverter.h>
class Settings;
class QDir;
class ContactsResource : public Akonadi::ResourceBase, public Akonadi::AgentBase::ObserverV2
......@@ -70,6 +71,7 @@ class ContactsResource : public Akonadi::ResourceBase, public Akonadi::AgentBase
private:
QStringList mSupportedMimeTypes;
Settings *mSettings;
};
#endif
......@@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile/>
<kcfgfile arg="true"/>
<group name="General">
<entry name="Path" type="Path">
<label>Path to contacts directory</label>
......
......@@ -3,5 +3,5 @@ ClassName=Settings
Mutators=true
ItemAccessors=true
SetUserTexts=true
Singleton=true
Singleton=false
GlobalEnums=true
......@@ -28,8 +28,9 @@
using namespace Akonadi;
SettingsDialog::SettingsDialog( WId windowId )
: KDialog()
SettingsDialog::SettingsDialog( Settings *settings, WId windowId )
: KDialog(),
mSettings( settings )
{
ui.setupUi( mainWidget() );
ui.kcfg_Path->setMode( KFile::LocalOnly | KFile::Directory );
......@@ -45,16 +46,16 @@ SettingsDialog::SettingsDialog( WId windowId )
QTimer::singleShot( 0, this, SLOT( validate() ) );
ui.kcfg_Path->setUrl( KUrl( Settings::self()->path() ) );
mManager = new KConfigDialogManager( this, Settings::self() );
ui.kcfg_Path->setUrl( KUrl( mSettings->path() ) );
mManager = new KConfigDialogManager( this, mSettings );
mManager->updateWidgets();
}
void SettingsDialog::save()
{
mManager->updateSettings();
Settings::self()->setPath( ui.kcfg_Path->url().toLocalFile() );
Settings::self()->writeConfig();
mSettings->setPath( ui.kcfg_Path->url().toLocalFile() );
mSettings->writeConfig();
}
void SettingsDialog::validate()
......
......@@ -24,6 +24,7 @@
#include <KDE/KDialog>
class Settings;
class KConfigDialogManager;
namespace Akonadi {
......@@ -32,7 +33,7 @@ class SettingsDialog : public KDialog
{
Q_OBJECT
public:
explicit SettingsDialog( WId windowId );
explicit SettingsDialog( Settings* settings, WId windowId );
private Q_SLOTS:
void save();
......@@ -41,6 +42,7 @@ class SettingsDialog : public KDialog
private:
Ui::SettingsDialog ui;
KConfigDialogManager* mManager;
Settings *mSettings;
};
}
......
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