[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepim/akonadi/resources/shared
From:       Bertjan Broeksema <b.broeksema () home ! nl>
Date:       2008-11-01 18:38:48
Message-ID: 1225564728.980840.7039.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 878749 by bbroeksema:

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.


 M  +10 -5     singlefileresource.h  
 M  +9 -2      singlefileresourcebase.cpp  
 M  +1 -0      singlefileresourcebase.h  
 M  +8 -1      singlefileresourceconfigdialog.ui  
 M  +65 -3     singlefileresourceconfigdialogbase.cpp  
 M  +11 -0     singlefileresourceconfigdialogbase.h  


--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresource.h #878748:878749
@@ -83,7 +83,7 @@
         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 @@
 
         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 @@
         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 @@
         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 @@
 
         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." ) );
       }
--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresourcebase.cpp \
#878748:878749 @@ -83,6 +83,11 @@
  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 @@
 
   mDownloadJob = 0;
   KGlobal::deref();
+
+  emit status( Idle, i18nc( "@info:status", "Ready" ) );
 }
 
 void SingleFileResourceBase::slotUploadJobResult( KJob *job )
@@ -127,12 +134,12 @@
   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"
--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresourcebase.h #878748:878749
@@ -86,6 +86,7 @@
     KIO::FileCopyJob *mUploadJob;
     
   private Q_SLOTS:
+    void handleProgress( KJob *, unsigned long );
     void fileChanged( const QString &fileName );
     void slotDownloadJobResult( KJob * );
     void slotUploadJobResult( KJob * );
--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresourceconfigdialog.ui \
#878748:878749 @@ -6,7 +6,7 @@
     <x>0</x>
     <y>0</y>
     <width>547</width>
-    <height>301</height>
+    <height>386</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -47,6 +47,13 @@
            </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" >
              <string>Select the file which content should be represented by this \
resource. If the file does not exist yet it will be created. You can also specify an \
URL to a remote file, however monitoring the file for changes will not work in this \
                case.</string>
--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresourceconfigdialogbase.cpp \
#878748:878749 @@ -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 @@
 
   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 @@
     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;
+}
--- trunk/KDE/kdepim/akonadi/resources/shared/singlefileresourceconfigdialogbase.h \
#878748:878749 @@ -26,7 +26,13 @@
 #include <KDE/KDialog>
 
 class KConfigDialogManager;
+class KFileItem;
+class KJob;
 
+namespace KIO {
+class StatJob;
+}
+
 namespace Akonadi {
 
 /**
@@ -51,8 +57,13 @@
     Ui::SingleFileResourceConfigDialog ui;
     KConfigDialogManager* mManager;
 
+  private:
+    KIO::StatJob* mStatJob;
+    bool mDirUrlChecked;
+
   private Q_SLOTS:
     void validate();
+    void slotStatJobResult( KJob * );
 };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic