kmail

importarchivedialog.cpp
00001 /* Copyright 2009 Klarälvdalens Datakonsult AB
00002 
00003    This program is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU General Public License as
00005    published by the Free Software Foundation; either version 2 of
00006    the License or (at your option) version 3 or any later version
00007    accepted by the membership of KDE e.V. (or its successor approved
00008    by the membership of KDE e.V.), which shall act as a proxy
00009    defined in Section 14 of version 3 of the license.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include "importarchivedialog.h"
00020 
00021 #include "kmfolder.h"
00022 #include "folderrequester.h"
00023 #include "kmmainwidget.h"
00024 #include "importjob.h"
00025 
00026 #include <kurlrequester.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 
00030 #include <tqlayout.h>
00031 #include <tqlabel.h>
00032 
00033 using namespace KMail;
00034 
00035 ImportArchiveDialog::ImportArchiveDialog( TQWidget *parent, TQt::WidgetFlags flags )
00036   : KDialogBase( parent, "import_archive_dialog", false, i18n( "Import Archive" ),
00037                  KDialogBase::Ok | KDialogBase::Cancel,
00038                  KDialogBase::Ok, true ),
00039     mParentWidget( parent )
00040 {
00041   setWFlags( flags );
00042   TQWidget *mainWidget = new TQWidget( this );
00043   TQGridLayout *mainLayout = new TQGridLayout( mainWidget );
00044   mainLayout->setSpacing( KDialog::spacingHint() );
00045   mainLayout->setMargin( KDialog::marginHint() );
00046   setMainWidget( mainWidget );
00047 
00048   int row = 0;
00049 
00050   // TODO: Explaination label
00051   // TODO: Use TQFormLayout in KDE4
00052   // TODO: better label for "Ok" button
00053 
00054   TQLabel *folderLabel = new TQLabel( i18n( "&Folder:" ), mainWidget );
00055   mainLayout->addWidget( folderLabel, row, 0 );
00056   mFolderRequester = new FolderRequester( mainWidget, kmkernel->getKMMainWidget()->folderTree() );
00057   folderLabel->setBuddy( mFolderRequester );
00058   mainLayout->addWidget( mFolderRequester, row, 1 );
00059   row++;
00060 
00061   TQLabel *fileNameLabel = new TQLabel( i18n( "&Archive File:" ), mainWidget );
00062   mainLayout->addWidget( fileNameLabel, row, 0 );
00063   mUrlRequester = new KURLRequester( mainWidget );
00064   mUrlRequester->setMode( KFile::LocalOnly );
00065   mUrlRequester->setFilter( "*.tar *.zip *.tar.gz *.tar.bz2" );
00066   fileNameLabel->setBuddy( mUrlRequester );
00067   mainLayout->addWidget( mUrlRequester, row, 1 );
00068   row++;
00069 
00070   // TODO: what's this, tooltips
00071 
00072   mainLayout->setColStretch( 1, 1 );
00073   mainLayout->addItem( new TQSpacerItem( 1, 1, TQSizePolicy::Expanding, TQSizePolicy::Expanding ), row, 0 );
00074 
00075   // Make it a bit bigger, else the folder requester cuts off the text too early
00076   resize( 500, minimumSize().height() );
00077 }
00078 
00079 void ImportArchiveDialog::setFolder( KMFolder *defaultFolder )
00080 {
00081   mFolderRequester->setFolder( defaultFolder );
00082 }
00083 
00084 void ImportArchiveDialog::slotOk()
00085 {
00086   if ( !TQFile::exists( mUrlRequester->url() ) ) {
00087     KMessageBox::information( this, i18n( "Please select an archive file that should be imported." ),
00088                               i18n( "No archive file selected" ) );
00089     return;
00090   }
00091 
00092   if ( !mFolderRequester->folder() ) {
00093     KMessageBox::information( this, i18n( "Please select the folder where the archive should be imported to." ),
00094                               i18n( "No target folder selected" ) );
00095     return;
00096   }
00097 
00098   // TODO: check if url is empty. or better yet, disable ok button until file is chosen
00099 
00100   ImportJob *importJob = new KMail::ImportJob( mParentWidget );
00101   importJob->setFile( mUrlRequester->url() );
00102   importJob->setRootFolder( mFolderRequester->folder() );
00103   importJob->start();
00104   accept();
00105 }
00106 
00107 #include "importarchivedialog.moc"