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
00086 if( pageID == 1 )
00087 {
00088
00089 lstMailboxes->clear();
00090
00091
00092 QDir mailDir( txtMailDir->text() );
00093 if( mailDir.isReadable() )
00094 {
00095
00096 const QStringList entries = mailDir.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware );
00097
00098 for( QStringList::const_iterator it = entries.begin(); it != entries.end(); ++it )
00099 {
00100
00101 QDir newMailDir( mailDir );
00102 newMailDir.cd( (*it) );
00103 if( (*it) != ".." && (*it) != "." && isMailDir( newMailDir ) )
00104 addMailBoxListItem( *it, mailDir );
00105 }
00106 }
00107 }
00108
00109 }
00110
00111 bool MailBoxWizard::isMailDir( const QDir & path )
00112 {
00113
00114 const QStringList entries = path.entryList( QDir::Dirs | QDir::Readable | QDir::Writable | QDir::Hidden, QDir::Name | QDir::IgnoreCase | QDir::LocaleAware );
00115
00116
00117 bool curFound = false;
00118 bool newFound = false;
00119 bool tmpFound = false;
00120
00121
00122 QStringList::const_iterator it = entries.begin();
00123 while( it != entries.end() && !( curFound && newFound && tmpFound ) )
00124 {
00125 if( *it == "tmp" )
00126 tmpFound = true;
00127 else if( *it == "cur" )
00128 curFound = true;
00129 else if( *it == "new" )
00130 newFound = true;
00131
00132 ++it;
00133 }
00134
00135 return curFound && newFound && tmpFound;
00136 }
00137
00138 void MailBoxWizard::addMailBoxListItem( QString boxname, QDir path )
00139 {
00140
00141 QString boxnameTrans;
00142 if( boxname.toLower() == "inbox" )
00143 boxnameTrans = i18n( "Inbox" );
00144 else if( boxname.toLower() == "outbox" )
00145 boxnameTrans = i18n( "Outbox" );
00146 else if( boxname.toLower() == "drafts" )
00147 boxnameTrans = i18n( "Drafts" );
00148 else if( boxname.toLower() == "sent-mail" )
00149 boxnameTrans = i18n( "sent-mail" );
00150 else if( boxname.toLower() == "trash" )
00151 boxnameTrans = i18n( "Trash" );
00152 else
00153 boxnameTrans = boxname;
00154
00155
00156 MailBoxWizardListItem* newItem;
00157 newItem = new MailBoxWizardListItem( lstMailboxes, boxnameTrans, path.absolutePath() + '/' + boxname + '/' );
00158
00159
00160 }
00161
00162 QString MailBoxWizard::getPath( )
00163 {
00164
00165 QList<QTreeWidgetItem *> selectedItems = lstMailboxes->selectedItems();
00166 if( selectedItems.isEmpty() ) return "";
00167
00168 MailBoxWizardListItem* item = (MailBoxWizardListItem*)selectedItems.first();
00169
00170 QString path( "" );
00171 if( item != NULL )
00172 path = item->getPath();
00173
00174 return path;
00175 }
00176
00177 #include "mailboxwizard.moc"