• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmail

folderdialogquotatab.cpp

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "gnu" -*-
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   // We need a widget stack to show either a label ("no qutoa support", "please wait"...)
00060   // or quota info
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   // This can be simplified once KMFolderImap and KMFolderCachedImap have a common base class
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 ); // see KMFolderDialog constructor
00090 }
00091 
00092 void KMail::FolderDialogQuotaTab::load()
00093 {
00094   if ( mDlg->folder() ) {
00095     // existing folder
00096     initializeWithValuesFromFolder( mDlg->folder() );
00097   } else if ( mDlg->parentFolder() ) {
00098     // new folder
00099     initializeWithValuesFromFolder( mDlg->parentFolder() );
00100   }
00101 
00102   if ( mFolderType == KMFolderTypeCachedImap ) {
00103     showQuotaWidget();
00104     return;
00105   }
00106 
00107   assert( mFolderType == KMFolderTypeImap );
00108 
00109   // Loading, for online IMAP, consists of two steps:
00110   // 1) connect
00111   // 2) get quota info
00112 
00113   // First ensure we are connected
00114   mStack->setCurrentWidget( mLabel );
00115   if ( !mImapAccount ) { // hmmm?
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; // nothing to be done for the (virtual) account folder
00122   mLabel->setText( i18n( "Connecting to server %1, please wait...", mImapAccount->host() ) );
00123   ImapAccountBase::ConnectionState state = mImapAccount->makeConnection();
00124   if ( state == ImapAccountBase::Error ) { // Cancelled by user, or slave can't start
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 { // Connected
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 )  // unspecified error
00141       mLabel->setText( i18n( "Error connecting to server %1", mImapAccount->host() ) );
00142     else
00143       // Connection error (error message box already shown by the account)
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     //KMFolderImap* folderImap = static_cast<KMFolderImap*>( folder->storage() );
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   // nothing to do, we are read-only
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(); // support for Quotas (or not tried connecting yet)
00215 }
00216 
00217 #include "folderdialogquotatab.moc"

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal