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