32 #include "folderdiaquotatab.h"
34 #include "kmfoldertype.h"
35 #include "kmfolderimap.h"
36 #include "kmfoldercachedimap.h"
37 #include "kmacctcachedimap.h"
38 #include "imapaccountbase.h"
40 #include <tqwidgetstack.h>
43 #include <tqprogressbar.h>
44 #include <tqwhatsthis.h>
46 #include "folderdiaquotatab_p.h"
50 using namespace KMail;
52 KMail::FolderDiaQuotaTab::FolderDiaQuotaTab(
KMFolderDialog* dlg, TQWidget* parent,
const char* name )
57 TQVBoxLayout* topLayout =
new TQVBoxLayout(
this );
60 mStack =
new TQWidgetStack(
this );
61 topLayout->addWidget( mStack );
63 mLabel =
new TQLabel( mStack );
64 mLabel->setAlignment( AlignHCenter | AlignVCenter | WordBreak );
65 mStack->addWidget( mLabel );
67 mQuotaWidget =
new KMail::QuotaWidget( mStack );
71 void KMail::FolderDiaQuotaTab::initializeWithValuesFromFolder(
KMFolder* folder )
75 if ( mFolderType == KMFolderTypeImap ) {
76 KMFolderImap* folderImap =
static_cast<KMFolderImap*
>( folder->storage() );
77 mImapAccount = folderImap->account();
78 mImapPath = folderImap->imapPath();
80 else if ( mFolderType == KMFolderTypeCachedImap ) {
81 KMFolderCachedImap* folderImap =
static_cast<KMFolderCachedImap*
>( folder->storage() );
82 mImapAccount = folderImap->account();
83 mQuotaInfo = folderImap->quotaInfo();
89 void KMail::FolderDiaQuotaTab::load()
91 if ( mDlg->folder() ) {
93 initializeWithValuesFromFolder( mDlg->folder() );
94 }
else if ( mDlg->parentFolder() ) {
96 initializeWithValuesFromFolder( mDlg->parentFolder() );
99 if ( mFolderType == KMFolderTypeCachedImap ) {
104 assert( mFolderType == KMFolderTypeImap );
111 mStack->raiseWidget( mLabel );
112 if ( !mImapAccount ) {
113 mLabel->setText( i18n(
"Error: no IMAP account defined for this folder" ) );
116 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
117 if ( folder && folder->storage() == mImapAccount->rootFolder() )
119 mLabel->setText( i18n(
"Connecting to server %1, please wait..." ).arg( mImapAccount->host() ) );
120 ImapAccountBase::ConnectionState state = mImapAccount->makeConnection();
121 if ( state == ImapAccountBase::Error ) {
122 slotConnectionResult( -1, TQString() );
123 }
else if ( state == ImapAccountBase::Connecting ) {
124 connect( mImapAccount, TQ_SIGNAL( connectionResult(
int,
const TQString&) ),
125 this, TQ_SLOT( slotConnectionResult(
int,
const TQString&) ) );
127 slotConnectionResult( 0, TQString() );
132 void KMail::FolderDiaQuotaTab::slotConnectionResult(
int errorCode,
const TQString& errorMsg )
134 disconnect( mImapAccount, TQ_SIGNAL( connectionResult(
int,
const TQString&) ),
135 this, TQ_SLOT( slotConnectionResult(
int,
const TQString&) ) );
137 if ( errorCode == -1 )
138 mLabel->setText( i18n(
"Error connecting to server %1" ).arg( mImapAccount->host() ) );
141 mLabel->setText( TDEIO::buildErrorString( errorCode, errorMsg ) );
144 connect( mImapAccount, TQ_SIGNAL( receivedStorageQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& ) ),
145 this, TQ_SLOT( slotReceivedQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& ) ) );
146 KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
147 mImapAccount->getStorageQuotaInfo( folder, mImapPath );
150 void KMail::FolderDiaQuotaTab::slotReceivedQuotaInfo(
KMFolder* folder,
152 const KMail::QuotaInfo& info )
154 if ( folder == mDlg->folder() ? mDlg->folder() : mDlg->parentFolder() ) {
157 disconnect( mImapAccount, TQ_SIGNAL(receivedStorageQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& )),
158 this, TQ_SLOT(slotReceivedQuotaInfo(
KMFolder*, TDEIO::Job*,
const KMail::QuotaInfo& )) );
160 if ( job && job->error() ) {
161 if ( job->error() == TDEIO::ERR_UNSUPPORTED_ACTION )
162 mLabel->setText( i18n(
"This account does not have support for quota information." ) );
164 mLabel->setText( i18n(
"Error retrieving quota information from server\n%1" ).arg( job->errorString() ) );
172 void KMail::FolderDiaQuotaTab::showQuotaWidget()
174 if ( !mQuotaInfo.isValid() ) {
175 if ( !mImapAccount->hasQuotaSupport() ) {
176 mLabel->setText( i18n(
"This account does not have support for quota information." ) );
179 if ( !mQuotaInfo.isEmpty() ) {
180 mStack->raiseWidget( mQuotaWidget );
181 mQuotaWidget->setQuotaInfo( mQuotaInfo );
183 mLabel->setText( i18n(
"No quota is set for this folder." ) );
191 if ( mFolderType == KMFolderTypeCachedImap || mFolderType == KMFolderTypeImap )
204 bool KMail::FolderDiaQuotaTab::supports(
KMFolder* refFolder )
206 ImapAccountBase* imapAccount = 0;
207 if ( refFolder->
folderType() == KMFolderTypeImap )
208 imapAccount =
static_cast<KMFolderImap*
>( refFolder->storage() )->account();
209 else if ( refFolder->
folderType() == KMFolderTypeCachedImap )
210 imapAccount =
static_cast<KMFolderCachedImap*
>( refFolder->storage() )->account();
211 return imapAccount && imapAccount->hasQuotaSupport();
214 #include "folderdiaquotatab.moc"
Dialog for handling the properties of a mail folder.
KMFolderType folderType() const
Returns the type of this folder.
virtual bool save()
Unlike ConfigModuleTab, we return a bool from save.
virtual AccepStatus accept()
Called when clicking OK.
This is the base class for tabs in the folder dialog.