00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mailboxwizard.h"
00019
00020 MailBoxWizard::MailBoxWizard( QWidget* parent )
00021 : QWizard( parent )
00022 {
00023
00024
00025
00026
00027 QWizardPage* page1 = new QWizardPage();
00028 page1->setTitle( i18n( "Please choose the path to the mailboxes." ) );
00029 page1->setSubTitle( i18n( "KShowmail supports only MailDir boxes." ) );
00030 QHBoxLayout* layMain1 = new QHBoxLayout();
00031 page1->setLayout( layMain1 );
00032
00033 txtMailDir = new KLineEdit( page1 );
00034 layMain1->addWidget( txtMailDir );
00035
00036 btnMailDir = new KPushButton( KGuiItem( QString(), QString( "folder" ), i18n( "Press to choose the mail directory" ), i18n( "Press to choose the mail directory" ) ), page1 );
00037 btnMailDir->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
00038 layMain1->addWidget( btnMailDir );
00039 connect( btnMailDir, SIGNAL( clicked() ), this, SLOT( slotOpenDirDialog() ) );
00040
00041 addPage( page1 );
00042
00043
00044
00045
00046
00047 QWizardPage* page2 = new QWizardPage();
00048 page2->setTitle( i18n( "Please choose the mailbox" ) );
00049 QHBoxLayout* layMain2 = new QHBoxLayout();
00050 page2->setLayout( layMain2 );
00051
00052 lstMailboxes = new QTreeWidget( page2 );
00053 lstMailboxes->setColumnCount( 1 );
00054 lstMailboxes->setHeaderLabel( "Mailbox" );
00055 lstMailboxes->setIndentation( 0 );
00056 layMain2->addWidget( lstMailboxes );
00057
00058 addPage( page2 );
00059
00060 connect( this, SIGNAL( currentIdChanged(int) ), this, SLOT( slotPageChanged( int ) ) );
00061 }
00062
00063
00064 MailBoxWizard::~MailBoxWizard()
00065 {
00066 }
00067
00068 void MailBoxWizard::slotOpenDirDialog( )
00069 {
00070
00071 QString oldPath = txtMailDir->text();
00072
00073
00074 QString path = KFileDialog::getExistingDirectory( KUrl::fromPathOrUrl( oldPath ), this, i18n( "Choose the mailbox directory") );
00075
00076
00077 if( path.isEmpty() )
00078 txtMailDir->setText( oldPath );
00079 else
00080 txtMailDir->setText( path );
00081 }
00082
00083 void MailBoxWizard::slotPageChanged( int pageID )
00084 {
00085 kdDebug() << pageID << endl;
00086
00087 if( pageID == 1 )
00088 {
00089
00090 lstMailboxes->clear();
00091
00092
00093 QDir mailDir( txtMailDir->text() );
00094 if( mailDir.isReadable() )
00095 {
00096
00097 const QStringList entries = mailDir.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware );
00098
00099 for( QStringList::const_iterator it = entries.begin(); it != entries.end(); ++it )
00100 {
00101
00102 QDir newMailDir( mailDir );
00103 newMailDir.cd( (*it) );
00104 if( (*it) != ".." && (*it) != "." && isMailDir( newMailDir ) )
00105 addMailBoxListItem( *it, mailDir );
00106 }
00107 }
00108 }
00109
00110 }
00111
00112 bool MailBoxWizard::isMailDir( const QDir & path )
00113 {
00114
00115 const QStringList entries = path.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware );
00116
00117
00118 bool curFound = false;
00119 bool newFound = false;
00120 bool tmpFound = false;
00121
00122
00123 QStringList::const_iterator it = entries.begin();
00124 while( it != entries.end() && !( curFound && newFound && tmpFound ) )
00125 {
00126 if( *it == "tmp" )
00127 tmpFound = true;
00128 else if( *it == "cur" )
00129 curFound = true;
00130 else if( *it == "new" )
00131 newFound = true;
00132
00133 ++it;
00134 }
00135
00136 return curFound && newFound && tmpFound;
00137 }
00138
00139 void MailBoxWizard::addMailBoxListItem( QString boxname, QDir path )
00140 {
00141
00142 QString boxnameTrans;
00143 if( boxname.toLower() == "inbox" )
00144 boxnameTrans = i18n( "Inbox" );
00145 else if( boxname.toLower() == "outbox" )
00146 boxnameTrans = i18n( "Outbox" );
00147 else if( boxname.toLower() == "drafts" )
00148 boxnameTrans = i18n( "Drafts" );
00149 else if( boxname.toLower() == "sent-mail" )
00150 boxnameTrans = i18n( "sent-mail" );
00151 else if( boxname.toLower() == "trash" )
00152 boxnameTrans = i18n( "Trash" );
00153 else
00154 boxnameTrans = boxname;
00155
00156
00157 MailBoxWizardListItem* newItem;
00158 newItem = new MailBoxWizardListItem( lstMailboxes, boxnameTrans, path.absolutePath() + '/' + boxname + '/' );
00159
00160
00161 }
00162
00163 QString MailBoxWizard::getPath( )
00164 {
00165 MailBoxWizardListItem* item = (MailBoxWizardListItem*)lstMailboxes->selectedItems().first();
00166
00167 QString path;
00168 if( item != NULL )
00169 path = item->getPath();
00170
00171 return path;
00172 }
00173
00174 #include "mailboxwizard.moc"