kmail

kmfoldercombobox.cpp
1 /* kmail folder-list combo-box */
2 /* Author: Ronen Tzur <rtzur@shani.net> */
3 
4 #include <config.h>
5 
6 #include "kmfoldercombobox.h"
7 #include "kmfoldermgr.h"
8 
9 //-----------------------------------------------------------------------------
10 
11 KMFolderComboBox::KMFolderComboBox( TQWidget *parent, char *name )
12  : TQComboBox( parent, name )
13 {
14  init();
15 }
16 
17 
18 //-----------------------------------------------------------------------------
19 
20 KMFolderComboBox::KMFolderComboBox( bool rw, TQWidget *parent, char *name )
21  : TQComboBox( rw, parent, name )
22 {
23  init();
24 }
25 
26 
27 //-----------------------------------------------------------------------------
28 
29 void KMFolderComboBox::init()
30 {
31  mSpecialIdx = -1;
32  mOutboxShown = true;
33  mImapShown = true;
34  refreshFolders();
35  connect( this, TQ_SIGNAL( activated(int) ),
36  this, TQ_SLOT( slotActivated(int) ) );
37  connect( kmkernel->folderMgr(), TQ_SIGNAL(changed()),
38  this, TQ_SLOT(refreshFolders()) );
39  connect( kmkernel->dimapFolderMgr(), TQ_SIGNAL(changed()),
40  this, TQ_SLOT(refreshFolders()) );
41  if (mImapShown)
42  connect( kmkernel->imapFolderMgr(), TQ_SIGNAL(changed()),
43  this, TQ_SLOT(refreshFolders()) );
44 }
45 
46 
47 //-----------------------------------------------------------------------------
48 
49 void KMFolderComboBox::showOutboxFolder(bool shown)
50 {
51  mOutboxShown = shown;
52  refreshFolders();
53 }
54 
55 //-----------------------------------------------------------------------------
56 
57 void KMFolderComboBox::showImapFolders(bool shown)
58 {
59  mImapShown = shown;
60  refreshFolders();
61  if (shown)
62  connect( kmkernel->imapFolderMgr(), TQ_SIGNAL(changed()),
63  this, TQ_SLOT(refreshFolders()) );
64  else
65  disconnect( kmkernel->imapFolderMgr(), TQ_SIGNAL(changed()),
66  this, TQ_SLOT(refreshFolders()) );
67 }
68 
69 //-----------------------------------------------------------------------------
70 
71 void KMFolderComboBox::createFolderList(TQStringList *names,
72  TQValueList<TQGuardedPtr<KMFolder> > *folders)
73 {
74  kmkernel->folderMgr()->createI18nFolderList( names, folders );
75  if ( !mOutboxShown ) {
76  TQValueList< TQGuardedPtr<KMFolder> >::iterator folderIt = folders->begin();
77  TQStringList::iterator namesIt = names->begin();
78  for ( ; folderIt != folders->end(); ++folderIt, ++namesIt ) {
79  KMFolder *folder = *folderIt;
80  if ( folder == kmkernel->outboxFolder() )
81  break;
82  }
83  if ( folderIt != folders->end() ) {
84  folders->remove( folderIt );
85  names->remove( namesIt );
86  }
87  }
88 
89  if (mImapShown)
90  kmkernel->imapFolderMgr()->createI18nFolderList( names, folders );
91 
92  kmkernel->dimapFolderMgr()->createI18nFolderList( names, folders );
93 }
94 
95 //-----------------------------------------------------------------------------
96 
97 void KMFolderComboBox::refreshFolders()
98 {
99  TQStringList names;
100  TQValueList<TQGuardedPtr<KMFolder> > folders;
101  createFolderList( &names, &folders );
102 
103  KMFolder *folder = getFolder();
104  this->clear();
105  insertStringList( names );
106  setFolder( folder );
107 }
108 
109 //-----------------------------------------------------------------------------
110 
111 void KMFolderComboBox::setFolder( KMFolder *aFolder )
112 {
113  TQStringList names;
114  TQValueList<TQGuardedPtr<KMFolder> > folders;
115  createFolderList( &names, &folders );
116 
117  int idx = folders.findIndex( aFolder );
118  if (idx == -1)
119  idx = folders.findIndex( kmkernel->draftsFolder() );
120  setCurrentItem( idx >= 0 ? idx : 0 );
121 
122  mFolder = aFolder;
123 }
124 
125 void KMFolderComboBox::setFolder( const TQString &idString )
126 {
127  KMFolder * folder = kmkernel->findFolderById( idString );
128  if (!folder && !idString.isEmpty())
129  {
130  if (mSpecialIdx >= 0)
131  removeItem(mSpecialIdx);
132  mSpecialIdx = count();
133  insertItem(idString, -1);
134  setCurrentItem(mSpecialIdx);
135 
136  mFolder = 0;
137  return;
138  }
139  setFolder( folder );
140 }
141 
142 //-----------------------------------------------------------------------------
143 
144 KMFolder *KMFolderComboBox::getFolder()
145 {
146  if (mFolder)
147  return mFolder;
148 
149  TQStringList names;
150  TQValueList<TQGuardedPtr<KMFolder> > folders;
151  createFolderList( &names, &folders );
152 
153  if (currentItem() == mSpecialIdx)
154  return 0;
155 
156  TQString text = currentText();
157  int idx = 0;
158  TQStringList::Iterator it;
159  for ( it = names.begin(); it != names.end(); ++it ) {
160  if ( ! (*it).compare( text ) )
161  return *folders.at( idx );
162  idx++;
163  }
164 
165  return kmkernel->draftsFolder();
166 }
167 
168 //-----------------------------------------------------------------------------
169 
170 void KMFolderComboBox::slotActivated(int index)
171 {
172  TQStringList names;
173  TQValueList<TQGuardedPtr<KMFolder> > folders;
174  createFolderList( &names, &folders );
175 
176  if (index == mSpecialIdx)
177  {
178  mFolder = 0;
179  }
180  else
181  {
182  mFolder = *folders.at( index );
183  }
184 }
185 
186 //-----------------------------------------------------------------------------
187 
188 #include "kmfoldercombobox.moc"
Mail folder.
Definition: kmfolder.h:69
void remove()
Removes the folder physically from disk and empties the contents of the folder in memory.
Definition: kmfolder.cpp:515