Commit 481f8246 authored by David Jarvie's avatar David Jarvie
Browse files

Move resource configure() method into singlefileresource.h, to enable the

common functionality to be provided by the base class.
Execute synchronizeCollections() after config dialog OK, to load new settings
from the config file.

svn path=/trunk/KDE/kdepim/runtime/; revision=1148119
parent 21da802b
......@@ -10,6 +10,10 @@
<label>Path to iCal file.</label>
<default></default>
</entry>
<entry name="DisplayName" type="String">
<label>Display name.</label>
<default></default>
</entry>
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>false</default>
......
......@@ -71,17 +71,10 @@ void ICalResourceBase::aboutToQuit()
Settings::self()->writeConfig();
}
void ICalResourceBase::configure( WId windowId )
void ICalResourceBase::customizeConfigDialog( SingleFileResourceConfigDialog<Settings>* dlg )
{
SingleFileResourceConfigDialog<Settings> dlg( windowId );
dlg.setFilter( "text/calendar" );
dlg.setCaption( i18n("Select Calendar") );
if ( dlg.exec() == QDialog::Accepted ) {
reloadFile();
emit configurationDialogAccepted();
} else {
emit configurationDialogRejected();
}
dlg->setFilter( "text/calendar" );
dlg->setCaption( i18n("Select Calendar") );
}
bool ICalResourceBase::readFromFile( const QString &fileName )
......
......@@ -36,9 +36,6 @@ class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
ICalResourceBase( const QString &id );
~ICalResourceBase();
public Q_SLOTS:
virtual void configure( WId windowId );
protected Q_SLOTS:
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void retrieveItems( const Akonadi::Collection &col );
......@@ -49,6 +46,12 @@ class ICalResourceBase : public Akonadi::SingleFileResource<Settings>
void initialise( const QStringList &mimeTypes, const QString &icon );
bool readFromFile( const QString &fileName );
bool writeToFile( const QString &fileName );
/**
* Customize the configuration dialog before it is displayed.
*/
virtual void customizeConfigDialog( Akonadi::SingleFileResourceConfigDialog<Settings>* dlg );
virtual void aboutToQuit();
/**
......
......@@ -9,6 +9,10 @@
<label>Path to iCal file.</label>
<default></default>
</entry>
<entry name="DisplayName" type="String">
<label>Display name.</label>
<default></default>
</entry>
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>false</default>
......
......@@ -62,25 +62,17 @@ bool KDEAccountsResource::retrieveItem( const Akonadi::Item &item, const QSet<QB
return true;
}
void KDEAccountsResource::configure( WId windowId )
void KDEAccountsResource::customizeConfigDialog( SingleFileResourceConfigDialog<Settings>* dlg )
{
QPointer<SingleFileResourceConfigDialog<Settings> > dlg = new SingleFileResourceConfigDialog<Settings>( windowId );
dlg->setCaption( i18n( "Select KDE Accounts File" ) );
}
if ( dlg->exec() == QDialog::Accepted ) {
void KDEAccountsResource::configDialogAcceptedActions( SingleFileResourceConfigDialog<Settings>* )
{
// We can't hide the GUI element but we can enforce that the
// resource is read-only
Settings::self()->setReadOnly( true );
Settings::self()->writeConfig();
reloadFile();
emit configurationDialogAccepted();
} else {
emit configurationDialogRejected();
}
delete dlg;
}
void KDEAccountsResource::itemAdded( const Akonadi::Item&, const Akonadi::Collection& )
......
......@@ -33,14 +33,22 @@ class KDEAccountsResource : public Akonadi::SingleFileResource<Settings>
KDEAccountsResource( const QString &id );
~KDEAccountsResource();
public Q_SLOTS:
virtual void configure( WId windowId );
protected Q_SLOTS:
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void retrieveItems( const Akonadi::Collection &collection );
protected:
/**
* Customize the configuration dialog before it is displayed.
*/
virtual void customizeConfigDialog( Akonadi::SingleFileResourceConfigDialog<Settings>* dlg );
/*
* Do stuff when the configuration dialog has been accepted, before
* reloadFile() is called.
*/
virtual void configDialogAcceptedActions( Akonadi::SingleFileResourceConfigDialog<Settings>* dlg );
bool readFromFile( const QString &fileName );
bool writeToFile( const QString &fileName );
......
......@@ -10,6 +10,10 @@
<label>Path to KDE accounts file.</label>
<default></default>
</entry>
<entry name="DisplayName" type="String">
<label>Display name.</label>
<default></default>
</entry>
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>true</default>
......
......@@ -78,23 +78,11 @@ MboxResource::~MboxResource()
{
}
void MboxResource::configure( WId windowId )
void MboxResource::customizeConfigDialog( SingleFileResourceConfigDialog<Settings>* dlg )
{
QPointer<SingleFileResourceConfigDialog<Settings> > dlg
= new SingleFileResourceConfigDialog<Settings>( windowId );
dlg->addPage( i18n("Compact frequency"), new CompactPage( Settings::self()->path() ) );
dlg->addPage( i18n("Lock method"), new LockMethodPage() );
dlg->setCaption( i18n( "Select MBox file" ) );
if ( dlg->exec() == QDialog::Accepted ) {
reloadFile();
emit configurationDialogAccepted();
} else {
emit configurationDialogRejected();
}
delete dlg;
}
void MboxResource::retrieveItems( const Akonadi::Collection &col )
......
......@@ -33,9 +33,6 @@ class MboxResource : public Akonadi::SingleFileResource<Settings>
MboxResource( const QString &id );
~MboxResource();
public Q_SLOTS:
virtual void configure( WId windowId );
protected Q_SLOTS:
virtual bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
virtual void retrieveItems( const Akonadi::Collection &col );
......@@ -51,6 +48,11 @@ class MboxResource : public Akonadi::SingleFileResource<Settings>
virtual void handleHashChange();
virtual bool readFromFile( const QString &fileName );
virtual bool writeToFile( const QString &fileName );
/**
* Customize the configuration dialog before it is displayed.
*/
virtual void customizeConfigDialog( Akonadi::SingleFileResourceConfigDialog<Settings>* dlg );
private Q_SLOTS:
void onCollectionFetch( KJob *job );
......
......@@ -10,6 +10,10 @@
<label>Path to mbox file.</label>
<default></default>
</entry>
<entry name="DisplayName" type="String">
<label>Display name.</label>
<default></default>
</entry>
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>false</default>
......
......@@ -22,6 +22,7 @@
#define AKONADI_SINGLEFILERESOURCE_H
#include "singlefileresourcebase.h"
#include "singlefileresourceconfigdialog.h"
#include <akonadi/entitydisplayattribute.h>
......@@ -32,6 +33,7 @@
#include <QFile>
#include <QDir>
#include <QPointer>
namespace Akonadi
{
......@@ -73,7 +75,8 @@ class SingleFileResource : public SingleFileResourceBase
if ( mCurrentUrl.isLocalFile() )
{
if ( ( name().isEmpty() || name() == identifier() ) && !mCurrentUrl.isEmpty() )
if ( Settings::self()->displayName().isEmpty()
&& ( name().isEmpty() || name() == identifier() ) && !mCurrentUrl.isEmpty() )
setName( mCurrentUrl.fileName() );
// check if the file does not exist yet, if so, create it
......@@ -136,6 +139,11 @@ class SingleFileResource : public SingleFileResourceBase
emit status( Running, i18n( "Downloading remote file." ) );
}
const QString display = Settings::self()->displayName();
if ( !display.isEmpty() ) {
setName( display );
}
}
/**
......@@ -211,13 +219,53 @@ class SingleFileResource : public SingleFileResourceBase
taskDone();
}
public Q_SLOTS:
/**
* Display the configuration dialog for the resource.
*/
void configure( WId windowId )
{
QPointer<SingleFileResourceConfigDialog<Settings> > dlg
= new SingleFileResourceConfigDialog<Settings>( windowId );
customizeConfigDialog( dlg );
if ( dlg->exec() == QDialog::Accepted ) {
if ( dlg ) { // in case is got destroyed
configDialogAcceptedActions( dlg );
}
reloadFile();
synchronizeCollectionTree();
emit configurationDialogAccepted();
} else {
emit configurationDialogRejected();
}
}
protected:
/**
* Implement in derived classes to customize the configuration dialog
* before it is displayed.
*/
virtual void customizeConfigDialog( SingleFileResourceConfigDialog<Settings>* dlg )
{
Q_UNUSED(dlg);
}
/**
* Implement in derived classes to do things when the configuration dialog
* has been accepted, before reloadFile() is called.
*/
virtual void configDialogAcceptedActions( SingleFileResourceConfigDialog<Settings>* dlg )
{
Q_UNUSED(dlg);
}
void retrieveCollections()
{
Collection c;
c.setParentCollection( Collection::root() );
c.setRemoteId( Settings::self()->path() );
c.setName( identifier() );
const QString display = Settings::self()->displayName();
c.setName( display.isEmpty() ? identifier() : display );
QStringList mimeTypes;
c.setContentMimeTypes( mSupportedMimetypes );
if ( Settings::self()->readOnly() ) {
......
......@@ -36,7 +36,7 @@ SingleFileResourceConfigWidget::SingleFileResourceConfigWidget( QWidget *parent
{
ui.setupUi( this );
ui.kcfg_Path->setMode( KFile::File );
ui.statusLabel->setVisible( false );
ui.statusLabel->setText( QString() );
connect( ui.kcfg_Path, SIGNAL(textChanged(QString)), SLOT(validate()) );
connect( ui.kcfg_ReadOnly, SIGNAL(toggled(bool)), SLOT(validate()) );
......@@ -82,7 +82,7 @@ void SingleFileResourceConfigWidget::validate()
if ( mMonitorEnabled ) {
ui.kcfg_MonitorFile->setEnabled( true );
}
ui.statusLabel->setVisible( false );
ui.statusLabel->setText( QString() );
const QFileInfo file( currentUrl.toLocalFile() );
if ( file.exists() && !file.isWritable() ) {
......@@ -97,7 +97,6 @@ void SingleFileResourceConfigWidget::validate()
ui.kcfg_MonitorFile->setEnabled( false );
}
ui.statusLabel->setText( i18nc( "@info:status", "Checking file information..." ) );
ui.statusLabel->setVisible( true );
if ( mStatJob )
mStatJob->kill();
......@@ -134,7 +133,7 @@ void SingleFileResourceConfigWidget::slotStatJobResult( KJob* job )
} else if ( job->error() ) {
// It doesn't seem possible to read nor write from the location so leave the
// ok button disabled
ui.statusLabel->setVisible( false );
ui.statusLabel->setText( QString() );
emit validated( false );
mDirUrlChecked = false;
mStatJob = 0;
......@@ -151,7 +150,7 @@ void SingleFileResourceConfigWidget::slotStatJobResult( KJob* job )
ui.kcfg_ReadOnly->setChecked( true );
}
ui.statusLabel->setVisible( false );
ui.statusLabel->setText( QString() );
emit validated( true );
mDirUrlChecked = false;
......
......@@ -2,19 +2,17 @@
<ui version="4.0">
<class>SingleFileResourceConfigWidget</class>
<widget class="QWidget" name="SingleFileResourceConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>429</height>
</rect>
<property name="minimumSize">
<size>
<width>400</width>
<height>10</height>
</size>
</property>
<attribute name="title">
<string>File</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Access Rights</string>
......@@ -40,7 +38,7 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QGroupBox" name="groupBox_MonitorFile">
<property name="title">
<string>Monitoring</string>
......@@ -109,9 +107,50 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Display Name</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_1">
<property name="text">
<string>&amp;Name:</string>
</property>
<property name="buddy">
<cstring>kcfg_DisplayName</cstring>
</property>
</widget>
</item>
<item>
<widget class="KLineEdit" name="kcfg_DisplayName"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Enter the name used to identify this resource in displays. If not specified, the filename will be used.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
......
......@@ -38,6 +38,21 @@
<string>Status:</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Display name:</string>
</property>
<property name="buddy">
<cstring>kcfg_DisplayName</cstring>
</property>
</widget>
</item>
<item>
<widget class="KLineEdit" name="kcfg_DisplayName"/>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="kcfg_ReadOnly">
......@@ -57,6 +72,11 @@
</widget>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
......
......@@ -65,18 +65,10 @@ void VCardResource::aboutToQuit()
Settings::self()->writeConfig();
}
void VCardResource::configure( WId windowId )
void VCardResource::customizeConfigDialog( SingleFileResourceConfigDialog<Settings>* dlg )
{
SingleFileResourceConfigDialog<Settings> dlg( windowId );
dlg.setFilter( "*.vcf|" + i18nc("Filedialog filter for *.vcf", "vCard Address Book File" ) );
dlg.setCaption( i18n("Select Address Book") );
if ( dlg.exec() == QDialog::Accepted ) {
reloadFile();
emit configurationDialogAccepted();
} else {
emit configurationDialogRejected();
}
dlg->setFilter( "*.vcf|" + i18nc("Filedialog filter for *.vcf", "vCard Address Book File" ) );
dlg->setCaption( i18n("Select Address Book") );
}
void VCardResource::itemAdded( const Akonadi::Item &item, const Akonadi::Collection& )
......
......@@ -34,14 +34,16 @@ class VCardResource : public Akonadi::SingleFileResource<Settings>
VCardResource( const QString &id );
~VCardResource();
public Q_SLOTS:
virtual void configure( WId windowId );
protected Q_SLOTS:
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void retrieveItems( const Akonadi::Collection &col );
protected:
/**
* Customize the configuration dialog before it is displayed.
*/
virtual void customizeConfigDialog( Akonadi::SingleFileResourceConfigDialog<Settings>* dlg );
bool readFromFile( const QString &fileName );
bool writeToFile( const QString &fileName );
virtual void aboutToQuit();
......
......@@ -10,6 +10,10 @@
<label>Path to vCard file.</label>
<default></default>
</entry>
<entry name="DisplayName" type="String">
<label>Display name.</label>
<default></default>
</entry>
<entry name="ReadOnly" type="Bool">
<label>Do not change the actual backend data.</label>
<default>false</default>
......
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