33 #include "folderdiaquotatab.h" 35 #include "kmfoldertype.h" 36 #include "kmfolderimap.h" 37 #include "kmfoldercachedimap.h" 38 #include "kmacctcachedimap.h" 39 #include "imapaccountbase.h" 41 #include <tqwidgetstack.h> 44 #include <tqprogressbar.h> 45 #include <tqwhatsthis.h> 47 #include "folderdiaquotatab_p.h" 51 using namespace KMail;
53 KMail::FolderDiaQuotaTab::FolderDiaQuotaTab(
KMFolderDialog* dlg, TQWidget* parent,
const char* name )
58 TQVBoxLayout* topLayout =
new TQVBoxLayout(
this );
61 mStack =
new TQWidgetStack(
this );
62 topLayout->addWidget( mStack );
64 mLabel =
new TQLabel( mStack );
65 mLabel->setAlignment( AlignHCenter | AlignVCenter | WordBreak );
66 mStack->addWidget( mLabel );
68 mQuotaWidget =
new KMail::QuotaWidget( mStack );
72 void KMail::FolderDiaQuotaTab::initializeWithValuesFromFolder(
KMFolder* folder )
76 if ( mFolderType == KMFolderTypeImap ) {
77 KMFolderImap* folderImap =
static_cast<KMFolderImap*
>( folder->storage() );
78 mImapAccount = folderImap->account();
79 mImapPath = folderImap->imapPath();
81 else if ( mFolderType == KMFolderTypeCachedImap ) {
82 KMFolderCachedImap* folderImap =
static_cast<KMFolderCachedImap*
>( folder->storage() );
83 mImapAccount = folderImap->account();
84 mQuotaInfo = folderImap->quotaInfo();
90 void KMail::FolderDiaQuotaTab::load()
92 if ( mDlg->folder() ) {
94 initializeWithValuesFromFolder( mDlg->folder() );
95 }
else if ( mDlg->parentFolder() ) {
97 initializeWithValuesFromFolder( mDlg->parentFolder() );
100 if ( mFolderType == KMFolderTypeCachedImap ) {
105 assert( mFolderType == KMFolderTypeImap );
112 mStack->raiseWidget( mLabel );
113 if ( !mImapAccount ) {
114 mLabel->setText( i18n(
"Error: no IMAP account defined for this folder" ) );
117 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
118 if ( folder && folder->storage() == mImapAccount->rootFolder() )
120 mLabel->setText( i18n(
"Connecting to server %1, please wait..." ).arg( mImapAccount->host() ) );
121 ImapAccountBase::ConnectionState state = mImapAccount->makeConnection();
122 if ( state == ImapAccountBase::Error ) {
123 slotConnectionResult( -1, TQString() );
124 }
else if ( state == ImapAccountBase::Connecting ) {
125 connect( mImapAccount, TQT_SIGNAL( connectionResult(
int,
const TQString&) ),
126 this, TQT_SLOT( slotConnectionResult(
int,
const TQString&) ) );
128 slotConnectionResult( 0, TQString() );
133 void KMail::FolderDiaQuotaTab::slotConnectionResult(
int errorCode,
const TQString& errorMsg )
135 disconnect( mImapAccount, TQT_SIGNAL( connectionResult(
int,
const TQString&) ),
136 this, TQT_SLOT( slotConnectionResult(
int,
const TQString&) ) );
138 if ( errorCode == -1 )
139 mLabel->setText( i18n(
"Error connecting to server %1" ).arg( mImapAccount->host() ) );
142 mLabel->setText( TDEIO::buildErrorString( errorCode, errorMsg ) );
145 connect( mImapAccount, TQT_SIGNAL( receivedStorageQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& ) ),
146 this, TQT_SLOT( slotReceivedQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& ) ) );
147 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
148 mImapAccount->getStorageQuotaInfo( folder, mImapPath );
151 void KMail::FolderDiaQuotaTab::slotReceivedQuotaInfo(
KMFolder* folder,
153 const KMail::QuotaInfo& info )
155 if ( folder == mDlg->folder() ? mDlg->folder() : mDlg->parentFolder() ) {
158 disconnect( mImapAccount, TQT_SIGNAL(receivedStorageQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& )),
159 this, TQT_SLOT(slotReceivedQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& )) );
161 if ( job && job->error() ) {
162 if ( job->error() == TDEIO::ERR_UNSUPPORTED_ACTION )
163 mLabel->setText( i18n(
"This account does not have support for quota information." ) );
165 mLabel->setText( i18n(
"Error retrieving quota information from server\n%1" ).arg( job->errorString() ) );
173 void KMail::FolderDiaQuotaTab::showQuotaWidget()
175 if ( !mQuotaInfo.isValid() ) {
176 if ( !mImapAccount->hasQuotaSupport() ) {
177 mLabel->setText( i18n(
"This account does not have support for quota information." ) );
180 if ( !mQuotaInfo.isEmpty() ) {
181 mStack->raiseWidget( mQuotaWidget );
182 mQuotaWidget->setQuotaInfo( mQuotaInfo );
184 mLabel->setText( i18n(
"No quota is set for this folder." ) );
192 if ( mFolderType == KMFolderTypeCachedImap || mFolderType == KMFolderTypeImap )
205 bool KMail::FolderDiaQuotaTab::supports(
KMFolder* refFolder )
207 ImapAccountBase* imapAccount = 0;
208 if ( refFolder->
folderType() == KMFolderTypeImap )
209 imapAccount = static_cast<KMFolderImap*>( refFolder->storage() )->account();
210 else if ( refFolder->
folderType() == KMFolderTypeCachedImap )
211 imapAccount = static_cast<KMFolderCachedImap*>( refFolder->storage() )->account();
212 return imapAccount && imapAccount->hasQuotaSupport();
215 #include "folderdiaquotatab.moc" This is the base class for tabs in the folder dialog.
virtual bool save()
Unlike ConfigModuleTab, we return a bool from save.
KMFolderType folderType() const
Returns the type of this folder.
Dialog for handling the properties of a mail folder.
virtual AccepStatus accept()
Called when clicking OK.