Commit 3af84101 authored by Bertjan Broeksema's avatar Bertjan Broeksema
Browse files

Some polishing:

- Idle messages changed to "Ready"
- No external progress dialogs more for remote files, but progress shown in the
  config dialog.
- When a remote file is selected an asynchronous check is done if the file 
  exists and has read/write access. If it does not exist another check is 
	started to see if the parent directoy of the file exists and is writeable. If
	both check fails it is accounted as an invalid location.

svn path=/trunk/KDE/kdepim/akonadi/; revision=878749
parent 2039473c
......@@ -83,7 +83,7 @@ class SingleFileResource : public SingleFileResourceBase
if ( !QFile::exists( mCurrentUrl.path() ) ) {
QFile f( mCurrentUrl.path() );
if ( f.open( QIODevice::WriteOnly ) && f.resize( 0 ) ) {
emit status( Idle, i18n( "File '%1' created.", mCurrentUrl.prettyUrl() ) );
emit status( Idle, i18nc( "@info:status", "Ready" ) );
} else {
emit status( Broken, i18n( "Could not create file '%1'.", mCurrentUrl.prettyUrl() ) );
mCurrentUrl.clear();
......@@ -98,7 +98,8 @@ class SingleFileResource : public SingleFileResourceBase
if ( Settings::self()->monitorFile() )
KDirWatch::self()->addFile( mCurrentUrl.path() );
emit status( Idle, i18n( "Data loaded from '%1'.", mCurrentUrl.prettyUrl() ) );
emit status( Idle, i18nc( "@info:status", "Ready" ) );
}
else
{
......@@ -117,9 +118,11 @@ class SingleFileResource : public SingleFileResourceBase
KGlobal::ref();
// NOTE: Test what happens with remotefile -> save, close before save is finished.
mDownloadJob = KIO::file_copy( mCurrentUrl, KUrl( cacheFile() ), -1, KIO::Overwrite | KIO::DefaultFlags );
mDownloadJob = KIO::file_copy( mCurrentUrl, KUrl( cacheFile() ), -1, KIO::Overwrite | KIO::DefaultFlags | KIO::HideProgressInfo );
connect( mDownloadJob, SIGNAL( result( KJob * ) ),
SLOT( slotDownloadJobResult( KJob * ) ) );
connect( mDownloadJob, SIGNAL( percent( KJob *, unsigned long ) ),
SLOT( handleProgress( KJob *, unsigned long ) ) );
emit status( Running, i18n( "Downloading remote file." ) );
}
......@@ -151,7 +154,7 @@ class SingleFileResource : public SingleFileResourceBase
if ( !writeResult )
return;
emit status( Idle, i18n( "Data successfully saved to '%1'.", mCurrentUrl.prettyUrl() ) );
emit status( Idle, i18nc( "@info:status", "Ready" ) );
} else {
// Check if there is a download or an upload in progress.
if ( mDownloadJob ) {
......@@ -170,9 +173,11 @@ class SingleFileResource : public SingleFileResourceBase
KGlobal::ref();
// Start a job to upload the localy cached file to the remote location.
mUploadJob = KIO::file_copy( KUrl( cacheFile() ), mCurrentUrl, -1, KIO::Overwrite | KIO::DefaultFlags );
mUploadJob = KIO::file_copy( KUrl( cacheFile() ), mCurrentUrl, -1, KIO::Overwrite | KIO::DefaultFlags | KIO::HideProgressInfo );
connect( mUploadJob, SIGNAL( result( KJob * ) ),
SLOT( slotUploadJobResult( KJob * ) ) );
connect( mUploadJob, SIGNAL( percent( KJob *, unsigned long ) ),
SLOT( handleProgress( KJob *, unsigned long ) ) );
emit status( Running, i18n( "Uploading cached file to remote location." ) );
}
......
......@@ -83,6 +83,11 @@ void SingleFileResourceBase::reloadFile()
synchronize();
}
void SingleFileResourceBase::handleProgress( KJob *, unsigned long pct )
{
emit percent( pct );
}
void SingleFileResourceBase::fileChanged(const QString & fileName)
{
if ( fileName != mCurrentUrl.path() )
......@@ -120,6 +125,8 @@ void SingleFileResourceBase::slotDownloadJobResult( KJob *job )
mDownloadJob = 0;
KGlobal::deref();
emit status( Idle, i18nc( "@info:status", "Ready" ) );
}
void SingleFileResourceBase::slotUploadJobResult( KJob *job )
......@@ -127,12 +134,12 @@ void SingleFileResourceBase::slotUploadJobResult( KJob *job )
if ( job->error() ) {
static_cast<KIO::Job*>(job)->ui()->showErrorMessage();
emit status( Broken, i18n( "Could not save file '%1'.", mCurrentUrl.prettyUrl() ) );
} else {
emit status( Idle, i18n( "Data successfully saved to '%1'.", mCurrentUrl.prettyUrl() ) );
}
mUploadJob = 0;
KGlobal::deref();
emit status( Idle, i18nc( "@info:status", "Ready" ) );
}
#include "singlefileresourcebase.moc"
......@@ -86,6 +86,7 @@ class SingleFileResourceBase : public ResourceBase, public Akonadi::AgentBase::O
KIO::FileCopyJob *mUploadJob;
private Q_SLOTS:
void handleProgress( KJob *, unsigned long );
void fileChanged( const QString &fileName );
void slotDownloadJobResult( KJob * );
void slotUploadJobResult( KJob * );
......
......@@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>547</width>
<height>301</height>
<height>386</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -46,6 +46,13 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="statusLabel" >
<property name="text" >
<string>Status:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
......
......@@ -21,6 +21,8 @@
#include "singlefileresourceconfigdialogbase.h"
#include <KConfigDialogManager>
#include <KFileItem>
#include <KIO/Job>
#include <KWindowSystem>
#include <QTimer>
......@@ -28,10 +30,11 @@
using namespace Akonadi;
SingleFileResourceConfigDialogBase::SingleFileResourceConfigDialogBase( WId windowId ) :
KDialog()
KDialog(), mStatJob( 0 ), mDirUrlChecked( false )
{
ui.setupUi( mainWidget() );
ui.kcfg_Path->setMode( KFile::File );
ui.statusLabel->setVisible( false );
setButtons( Ok | Cancel );
if ( windowId )
......@@ -61,6 +64,8 @@ void SingleFileResourceConfigDialogBase::validate()
if ( currentUrl.isLocalFile() ) {
ui.kcfg_MonitorFile->setEnabled( true );
ui.statusLabel->setVisible( false );
const QFileInfo file( currentUrl.path() );
if ( file.exists() && !file.isWritable() ) {
ui.kcfg_ReadOnly->setEnabled( false );
......@@ -71,7 +76,64 @@ void SingleFileResourceConfigDialogBase::validate()
enableButton( Ok, true );
} else {
ui.kcfg_MonitorFile->setEnabled( false );
// TODO: Check if remote server supports writing.
enableButton( Ok, true );
ui.statusLabel->setText( i18nc( "@info:status", "Checking file information..." ) );
ui.statusLabel->setVisible( true );
if ( mStatJob )
mStatJob->kill();
mStatJob = KIO::stat( currentUrl, KIO::DefaultFlags | KIO::HideProgressInfo );
mStatJob->setDetails( 2 ); // All details.
mStatJob->setSide( KIO::StatJob::SourceSide );
connect( mStatJob, SIGNAL( result( KJob * ) ),
SLOT( slotStatJobResult( KJob * ) ) );
// Disable the button until the MetaJob is finished.
enableButton( Ok, false );
}
}
void SingleFileResourceConfigDialogBase::slotStatJobResult( KJob* job )
{
if ( job->error() == KIO::ERR_DOES_NOT_EXIST && !mDirUrlChecked ) {
// The file did not exists, so let's see if the directory the file should
// reside supports writing.
const KUrl dirUrl = ui.kcfg_Path->url().upUrl();
mStatJob = KIO::stat( dirUrl, KIO::DefaultFlags | KIO::HideProgressInfo );
mStatJob->setDetails( 2 ); // All details.
mStatJob->setSide( KIO::StatJob::SourceSide );
connect( mStatJob, SIGNAL( result( KJob * ) ),
SLOT( slotStatJobResult( KJob * ) ) );
// Make sure we don't check the whole path upwards.
mDirUrlChecked = true;
return;
} 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 );
enableButton( Ok, false );
mDirUrlChecked = false;
mStatJob = 0;
return;
}
KIO::StatJob* statJob = qobject_cast<KIO::StatJob *>( job );
const KFileItem item( statJob->statResult(), KUrl() );
if ( item.isWritable() ) {
ui.kcfg_ReadOnly->setEnabled( true );
} else {
ui.kcfg_ReadOnly->setEnabled( false );
ui.kcfg_ReadOnly->setChecked( true );
}
ui.statusLabel->setVisible( false );
enableButton( Ok, true );
mDirUrlChecked = false;
mStatJob = 0;
}
......@@ -26,6 +26,12 @@
#include <KDE/KDialog>
class KConfigDialogManager;
class KFileItem;
class KJob;
namespace KIO {
class StatJob;
}
namespace Akonadi {
......@@ -51,8 +57,13 @@ class SingleFileResourceConfigDialogBase : public KDialog
Ui::SingleFileResourceConfigDialog ui;
KConfigDialogManager* mManager;
private:
KIO::StatJob* mStatJob;
bool mDirUrlChecked;
private Q_SLOTS:
void validate();
void slotStatJobResult( KJob * );
};
}
......
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