// kmfolderseldlg.cpp #include "kmfolderseldlg.h" #include "kmfoldertree.h" #include "kmmainwin.h" #include #include #include #include #include QString KMFolderSelDlg::oldSelection; //----------------------------------------------------------------------------- KMFolderSelDlg::KMFolderSelDlg(KMMainWin * parent, const QString& caption) : KMFolderSelDlgInherited(parent, "folder dialog", true, caption, Ok|Cancel, Ok, true) // mainwin as parent, modal { QGuardedPtr cur; mListBox = new QListBox(makeVBoxMainWidget()); connect(mListBox, SIGNAL(selected(int)), this, SLOT(slotSelect(int))); resize(220, 300); QStringList str; KMFolderTree * ft = parent->folderTree(); assert( ft ); ft->createFolderList( &str, &mFolder ); mListBox->insertStringList( str ); int i = 0; while (mFolder.at(i) != mFolder.end()) { cur = *mFolder.at(i); // cur will be NULL for accounts. Don't crash on that, // but ignore them for now. if(!cur) mListBox->item(i)->setSelectable(false); else if (!oldSelection.isNull() && oldSelection == cur->label()) mListBox->setCurrentItem(i); ++i; } // make sure item is visible if(mListBox->currentItem() != -1) { unsigned idx = 0; while(mListBox->numItemsVisible()-2 + mListBox->topItem() < mListBox->currentItem() && idx < mListBox->count()) mListBox->setTopItem(idx++); } mListBox->setFocus(); } //----------------------------------------------------------------------------- KMFolderSelDlg::~KMFolderSelDlg() { } //----------------------------------------------------------------------------- KMFolder* KMFolderSelDlg::folder(void) { int idx = mListBox->currentItem(); if (idx < 0) return NULL; return *mFolder.at(idx); } //----------------------------------------------------------------------------- void KMFolderSelDlg::slotSelect(int) { if(mListBox->currentItem() != -1) oldSelection = mListBox->text(mListBox->currentItem()); accept(); } //----------------------------------------------------------------------------- void KMFolderSelDlg::slotCancel() { disconnect(mListBox, SIGNAL(selected(int)), this, SLOT(slotSelect(int))); if(mListBox->currentItem() != -1) oldSelection = mListBox->text(mListBox->currentItem()); reject(); } //----------------------------------------------------------------------------- #include "kmfolderseldlg.moc"