folderdiaquotatab.cpp
00001 // -*- mode: C++; c-file-style: "gnu" -*- 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 <tqwidgetstack.h> 00042 #include <tqlayout.h> 00043 #include <tqlabel.h> 00044 #include <tqprogressbar.h> 00045 #include <tqwhatsthis.h> 00046 00047 #include "folderdiaquotatab_p.h" 00048 00049 #include <assert.h> 00050 00051 using namespace KMail; 00052 00053 KMail::FolderDiaQuotaTab::FolderDiaQuotaTab( KMFolderDialog* dlg, TQWidget* parent, const char* name ) 00054 : FolderDiaTab( parent, name ), 00055 mImapAccount( 0 ), 00056 mDlg( dlg ) 00057 { 00058 TQVBoxLayout* topLayout = new TQVBoxLayout( this ); 00059 // We need a widget stack to show either a label ("no qutoa support", "please wait"...) 00060 // or quota info 00061 mStack = new TQWidgetStack( this ); 00062 topLayout->addWidget( mStack ); 00063 00064 mLabel = new TQLabel( 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 // This can be simplified once KMFolderImap and KMFolderCachedImap have a common base class 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 ); // see KMFolderDialog constructor 00088 } 00089 00090 void KMail::FolderDiaQuotaTab::load() 00091 { 00092 if ( mDlg->folder() ) { 00093 // existing folder 00094 initializeWithValuesFromFolder( mDlg->folder() ); 00095 } else if ( mDlg->parentFolder() ) { 00096 // new folder 00097 initializeWithValuesFromFolder( mDlg->parentFolder() ); 00098 } 00099 00100 if ( mFolderType == KMFolderTypeCachedImap ) { 00101 showQuotaWidget(); 00102 return; 00103 } 00104 00105 assert( mFolderType == KMFolderTypeImap ); 00106 00107 // Loading, for online IMAP, consists of two steps: 00108 // 1) connect 00109 // 2) get quota info 00110 00111 // First ensure we are connected 00112 mStack->raiseWidget( mLabel ); 00113 if ( !mImapAccount ) { // hmmm? 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; // nothing to be done for the (virtual) account folder 00120 mLabel->setText( i18n( "Connecting to server %1, please wait..." ).arg( mImapAccount->host() ) ); 00121 ImapAccountBase::ConnectionState state = mImapAccount->makeConnection(); 00122 if ( state == ImapAccountBase::Error ) { // Cancelled by user, or slave can't start 00123 slotConnectionResult( -1, TQString() ); 00124 } else if ( state == ImapAccountBase::Connecting ) { 00125 connect( mImapAccount, TQT_SIGNAL( connectionResult(int, const TQString&) ), 00126 this, TQT_SLOT( slotConnectionResult(int, const TQString&) ) ); 00127 } else { // Connected 00128 slotConnectionResult( 0, TQString() ); 00129 } 00130 00131 } 00132 00133 void KMail::FolderDiaQuotaTab::slotConnectionResult( int errorCode, const TQString& errorMsg ) 00134 { 00135 disconnect( mImapAccount, TQT_SIGNAL( connectionResult(int, const TQString&) ), 00136 this, TQT_SLOT( slotConnectionResult(int, const TQString&) ) ); 00137 if ( errorCode ) { 00138 if ( errorCode == -1 ) // unspecified error 00139 mLabel->setText( i18n( "Error connecting to server %1" ).arg( mImapAccount->host() ) ); 00140 else 00141 // Connection error (error message box already shown by the account) 00142 mLabel->setText( TDEIO::buildErrorString( errorCode, errorMsg ) ); 00143 return; 00144 } 00145 connect( mImapAccount, TQT_SIGNAL( receivedStorageQuotaInfo( KMFolder*, TDEIO::Job*, const KMail::QuotaInfo& ) ), 00146 this, TQT_SLOT( slotReceivedQuotaInfo( KMFolder*, TDEIO::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 TDEIO::Job* job, 00153 const KMail::QuotaInfo& info ) 00154 { 00155 if ( folder == mDlg->folder() ? mDlg->folder() : mDlg->parentFolder() ) { 00156 //KMFolderImap* folderImap = static_cast<KMFolderImap*>( folder->storage() ); 00157 00158 disconnect( mImapAccount, TQT_SIGNAL(receivedStorageQuotaInfo( KMFolder*, TDEIO::Job*, const KMail::QuotaInfo& )), 00159 this, TQT_SLOT(slotReceivedQuotaInfo( KMFolder*, TDEIO::Job*, const KMail::QuotaInfo& )) ); 00160 00161 if ( job && job->error() ) { 00162 if ( job->error() == TDEIO::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::AccepStatus KMail::FolderDiaQuotaTab::accept() 00191 { 00192 if ( mFolderType == KMFolderTypeCachedImap || mFolderType == KMFolderTypeImap ) 00193 return Accepted; 00194 else 00195 assert(0); 00196 return Accepted; // our code sanity checker doesn't know there is no coming back from assert(0) 00197 } 00198 00199 bool KMail::FolderDiaQuotaTab::save() 00200 { 00201 // nothing to do, we are read-only 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(); // support for Quotas (or not tried connecting yet) 00213 } 00214 00215 #include "folderdiaquotatab.moc"