kmail

folderdiaquotatab.cpp
1 
32 #include "folderdiaquotatab.h"
33 #include "kmfolder.h"
34 #include "kmfoldertype.h"
35 #include "kmfolderimap.h"
36 #include "kmfoldercachedimap.h"
37 #include "kmacctcachedimap.h"
38 #include "imapaccountbase.h"
39 
40 #include <tqwidgetstack.h>
41 #include <tqlayout.h>
42 #include <tqlabel.h>
43 #include <tqprogressbar.h>
44 #include <tqwhatsthis.h>
45 
46 #include "folderdiaquotatab_p.h"
47 
48 #include <assert.h>
49 
50 using namespace KMail;
51 
52 KMail::FolderDiaQuotaTab::FolderDiaQuotaTab( KMFolderDialog* dlg, TQWidget* parent, const char* name )
53  : FolderDiaTab( parent, name ),
54  mImapAccount( 0 ),
55  mDlg( dlg )
56 {
57  TQVBoxLayout* topLayout = new TQVBoxLayout( this );
58  // We need a widget stack to show either a label ("no qutoa support", "please wait"...)
59  // or quota info
60  mStack = new TQWidgetStack( this );
61  topLayout->addWidget( mStack );
62 
63  mLabel = new TQLabel( mStack );
64  mLabel->setAlignment( AlignHCenter | AlignVCenter | WordBreak );
65  mStack->addWidget( mLabel );
66 
67  mQuotaWidget = new KMail::QuotaWidget( mStack );
68 }
69 
70 
71 void KMail::FolderDiaQuotaTab::initializeWithValuesFromFolder( KMFolder* folder )
72 {
73  // This can be simplified once KMFolderImap and KMFolderCachedImap have a common base class
74  mFolderType = folder->folderType();
75  if ( mFolderType == KMFolderTypeImap ) {
76  KMFolderImap* folderImap = static_cast<KMFolderImap*>( folder->storage() );
77  mImapAccount = folderImap->account();
78  mImapPath = folderImap->imapPath();
79  }
80  else if ( mFolderType == KMFolderTypeCachedImap ) {
81  KMFolderCachedImap* folderImap = static_cast<KMFolderCachedImap*>( folder->storage() );
82  mImapAccount = folderImap->account();
83  mQuotaInfo = folderImap->quotaInfo();
84  }
85  else
86  assert( 0 ); // see KMFolderDialog constructor
87 }
88 
89 void KMail::FolderDiaQuotaTab::load()
90 {
91  if ( mDlg->folder() ) {
92  // existing folder
93  initializeWithValuesFromFolder( mDlg->folder() );
94  } else if ( mDlg->parentFolder() ) {
95  // new folder
96  initializeWithValuesFromFolder( mDlg->parentFolder() );
97  }
98 
99  if ( mFolderType == KMFolderTypeCachedImap ) {
100  showQuotaWidget();
101  return;
102  }
103 
104  assert( mFolderType == KMFolderTypeImap );
105 
106  // Loading, for online IMAP, consists of two steps:
107  // 1) connect
108  // 2) get quota info
109 
110  // First ensure we are connected
111  mStack->raiseWidget( mLabel );
112  if ( !mImapAccount ) { // hmmm?
113  mLabel->setText( i18n( "Error: no IMAP account defined for this folder" ) );
114  return;
115  }
116  KMFolder* folder = mDlg->folder() ? mDlg->folder() : mDlg->parentFolder();
117  if ( folder && folder->storage() == mImapAccount->rootFolder() )
118  return; // nothing to be done for the (virtual) account folder
119  mLabel->setText( i18n( "Connecting to server %1, please wait..." ).arg( mImapAccount->host() ) );
120  ImapAccountBase::ConnectionState state = mImapAccount->makeConnection();
121  if ( state == ImapAccountBase::Error ) { // Cancelled by user, or slave can't start
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&) ) );
126  } else { // Connected
127  slotConnectionResult( 0, TQString() );
128  }
129 
130 }
131 
132 void KMail::FolderDiaQuotaTab::slotConnectionResult( int errorCode, const TQString& errorMsg )
133 {
134  disconnect( mImapAccount, TQ_SIGNAL( connectionResult(int, const TQString&) ),
135  this, TQ_SLOT( slotConnectionResult(int, const TQString&) ) );
136  if ( errorCode ) {
137  if ( errorCode == -1 ) // unspecified error
138  mLabel->setText( i18n( "Error connecting to server %1" ).arg( mImapAccount->host() ) );
139  else
140  // Connection error (error message box already shown by the account)
141  mLabel->setText( TDEIO::buildErrorString( errorCode, errorMsg ) );
142  return;
143  }
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 );
148 }
149 
150 void KMail::FolderDiaQuotaTab::slotReceivedQuotaInfo( KMFolder* folder,
151  TDEIO::Job* job,
152  const KMail::QuotaInfo& info )
153 {
154  if ( folder == mDlg->folder() ? mDlg->folder() : mDlg->parentFolder() ) {
155  //KMFolderImap* folderImap = static_cast<KMFolderImap*>( folder->storage() );
156 
157  disconnect( mImapAccount, TQ_SIGNAL(receivedStorageQuotaInfo( KMFolder*, TDEIO::Job*, const KMail::QuotaInfo& )),
158  this, TQ_SLOT(slotReceivedQuotaInfo( KMFolder*, TDEIO::Job*, const KMail::QuotaInfo& )) );
159 
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." ) );
163  else
164  mLabel->setText( i18n( "Error retrieving quota information from server\n%1" ).arg( job->errorString() ) );
165  } else {
166  mQuotaInfo = info;
167  }
168  showQuotaWidget();
169  }
170 }
171 
172 void KMail::FolderDiaQuotaTab::showQuotaWidget()
173 {
174  if ( !mQuotaInfo.isValid() ) {
175  if ( !mImapAccount->hasQuotaSupport() ) {
176  mLabel->setText( i18n( "This account does not have support for quota information." ) );
177  }
178  } else {
179  if ( !mQuotaInfo.isEmpty() ) {
180  mStack->raiseWidget( mQuotaWidget );
181  mQuotaWidget->setQuotaInfo( mQuotaInfo );
182  } else {
183  mLabel->setText( i18n( "No quota is set for this folder." ) );
184  }
185  }
186 }
187 
188 
189 KMail::FolderDiaTab::AccepStatus KMail::FolderDiaQuotaTab::accept()
190 {
191  if ( mFolderType == KMFolderTypeCachedImap || mFolderType == KMFolderTypeImap )
192  return Accepted;
193  else
194  assert(0);
195  return Accepted; // our code sanity checker doesn't know there is no coming back from assert(0)
196 }
197 
199 {
200  // nothing to do, we are read-only
201  return true;
202 }
203 
204 bool KMail::FolderDiaQuotaTab::supports( KMFolder* refFolder )
205 {
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(); // support for Quotas (or not tried connecting yet)
212 }
213 
214 #include "folderdiaquotatab.moc"
Dialog for handling the properties of a mail folder.
Definition: kmfolderdia.h:199
Mail folder.
Definition: kmfolder.h:69
KMFolderType folderType() const
Returns the type of this folder.
Definition: kmfolder.cpp:233
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.
Definition: kmfolderdia.h:70
folderdiaquotatab.h
Definition: aboutdata.cpp:40