00001
00033 #include "folderdiaquotatab.h"
00034 #include "kmfolder.h"
00035 #include "kmfoldertype.h"
00036 #include "kmfolderimap.h"
00037 #include "kmfoldercachedimap.h"
00038 #include "kmacctcachedimap.h"
00039 #include "imapaccountbase.h"
00040
00041 #include <qwidgetstack.h>
00042 #include <qlayout.h>
00043 #include <qlabel.h>
00044 #include <qprogressbar.h>
00045 #include <qwhatsthis.h>
00046
00047 #include "folderdiaquotatab_p.h"
00048
00049 #include <assert.h>
00050
00051 using namespace KMail;
00052
00053 KMail::FolderDiaQuotaTab::FolderDiaQuotaTab( KMFolderDialog* dlg, QWidget* parent, const char* name )
00054 : FolderDiaTab( parent, name ),
00055 mImapAccount( 0 ),
00056 mDlg( dlg )
00057 {
00058 QVBoxLayout* topLayout = new QVBoxLayout( this );
00059
00060
00061 mStack = new QWidgetStack( this );
00062 topLayout->addWidget( mStack );
00063
00064 mLabel = new QLabel( mStack );
00065 mLabel->setAlignment( AlignHCenter | AlignVCenter | WordBreak );
00066 mStack->addWidget( mLabel );
00067
00068 mQuotaWidget = new KMail::QuotaWidget( mStack );
00069 }
00070
00071
00072 void KMail::FolderDiaQuotaTab::initializeWithValuesFromFolder( KMFolder* folder )
00073 {
00074
00075 mFolderType = folder->folderType();
00076 if ( mFolderType == KMFolderTypeImap ) {
00077 KMFolderImap* folderImap = static_cast<KMFolderImap*>( folder->storage() );
00078 mImapAccount = folderImap->account();
00079 mImapPath = folderImap->imapPath();
00080 }
00081 else if ( mFolderType == KMFolderTypeCachedImap ) {
00082 KMFolderCachedImap* folderImap = static_cast<KMFolderCachedImap*>( folder->storage() );
00083 mImapAccount = folderImap->account();
00084 mQuotaInfo = folderImap->quotaInfo();
00085 }
00086 else
00087 assert( 0 );
00088 }
00089
00090 void KMail::FolderDiaQuotaTab::load()
00091 {
00092 if ( mDlg->folder() ) {
00093
00094 initializeWithValuesFromFolder( mDlg->folder() );
00095 } else if ( mDlg->parentFolder() ) {
00096
00097 initializeWithValuesFromFolder( mDlg->parentFolder() );
00098 }
00099
00100 if ( mFolderType == KMFolderTypeCachedImap ) {
00101 showQuotaWidget();
00102 return;
00103 }
00104
00105 assert( mFolderType == KMFolderTypeImap );
00106
00107
00108
00109
00110
00111
00112 mStack->raiseWidget( mLabel );
00113 if ( !mImapAccount ) {
00114 mLabel->setText( i18n( "Error: no IMAP account defined for this folder" ) );
00115 return;
00116 }
00117 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
00118 if ( folder && folder->storage() == mImapAccount->rootFolder() )
00119 return;
00120 mLabel->setText( i18n( "Connecting to server %1, please wait..." ).arg( mImapAccount->host() ) );
00121 ImapAccountBase::ConnectionState state = mImapAccount->makeConnection();
00122 if ( state == ImapAccountBase::Error ) {
00123 slotConnectionResult( -1, QString::null );
00124 } else if ( state == ImapAccountBase::Connecting ) {
00125 connect( mImapAccount, SIGNAL( connectionResult(int, const QString&) ),
00126 this, SLOT( slotConnectionResult(int, const QString&) ) );
00127 } else {
00128 slotConnectionResult( 0, QString::null );
00129 }
00130
00131 }
00132
00133 void KMail::FolderDiaQuotaTab::slotConnectionResult( int errorCode, const QString& errorMsg )
00134 {
00135 disconnect( mImapAccount, SIGNAL( connectionResult(int, const QString&) ),
00136 this, SLOT( slotConnectionResult(int, const QString&) ) );
00137 if ( errorCode ) {
00138 if ( errorCode == -1 )
00139 mLabel->setText( i18n( "Error connecting to server %1" ).arg( mImapAccount->host() ) );
00140 else
00141
00142 mLabel->setText( KIO::buildErrorString( errorCode, errorMsg ) );
00143 return;
00144 }
00145 connect( mImapAccount, SIGNAL( receivedStorageQuotaInfo( KMFolder*, KIO::Job*, const KMail::QuotaInfo& ) ),
00146 this, SLOT( slotReceivedQuotaInfo( KMFolder*, KIO::Job*, const KMail::QuotaInfo& ) ) );
00147 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
00148 mImapAccount->getStorageQuotaInfo( folder, mImapPath );
00149 }
00150
00151 void KMail::FolderDiaQuotaTab::slotReceivedQuotaInfo( KMFolder* folder,
00152 KIO::Job* job,
00153 const KMail::QuotaInfo& info )
00154 {
00155 if ( folder == mDlg->folder() ? mDlg->folder() : mDlg->parentFolder() ) {
00156
00157
00158 disconnect( mImapAccount, SIGNAL(receivedStorageQuotaInfo( KMFolder*, KIO::Job*, const KMail::QuotaInfo& )),
00159 this, SLOT(slotReceivedQuotaInfo( KMFolder*, KIO::Job*, const KMail::QuotaInfo& )) );
00160
00161 if ( job && job->error() ) {
00162 if ( job->error() == KIO::ERR_UNSUPPORTED_ACTION )
00163 mLabel->setText( i18n( "This account does not have support for quota information." ) );
00164 else
00165 mLabel->setText( i18n( "Error retrieving quota information from server\n%1" ).arg( job->errorString() ) );
00166 } else {
00167 mQuotaInfo = info;
00168 }
00169 showQuotaWidget();
00170 }
00171 }
00172
00173 void KMail::FolderDiaQuotaTab::showQuotaWidget()
00174 {
00175 if ( !mQuotaInfo.isValid() ) {
00176 if ( !mImapAccount->hasQuotaSupport() ) {
00177 mLabel->setText( i18n( "This account does not have support for quota information." ) );
00178 }
00179 } else {
00180 if ( !mQuotaInfo.isEmpty() ) {
00181 mStack->raiseWidget( mQuotaWidget );
00182 mQuotaWidget->setQuotaInfo( mQuotaInfo );
00183 } else {
00184 mLabel->setText( i18n( "No quota is set for this folder." ) );
00185 }
00186 }
00187 }
00188
00189
00190 KMail::FolderDiaTab::AcceptStatus KMail::FolderDiaQuotaTab::accept()
00191 {
00192 if ( mFolderType == KMFolderTypeCachedImap || mFolderType == KMFolderTypeImap )
00193 return Accepted;
00194 else
00195 assert(0);
00196 return Accepted;
00197 }
00198
00199 bool KMail::FolderDiaQuotaTab::save()
00200 {
00201
00202 return true;
00203 }
00204
00205 bool KMail::FolderDiaQuotaTab::supports( KMFolder* refFolder )
00206 {
00207 ImapAccountBase* imapAccount = 0;
00208 if ( refFolder->folderType() == KMFolderTypeImap )
00209 imapAccount = static_cast<KMFolderImap*>( refFolder->storage() )->account();
00210 else if ( refFolder->folderType() == KMFolderTypeCachedImap )
00211 imapAccount = static_cast<KMFolderCachedImap*>( refFolder->storage() )->account();
00212 return imapAccount && imapAccount->hasQuotaSupport();
00213 }
00214
00215 #include "folderdiaquotatab.moc"