kmail

importarchivedialog.cpp
1 /* Copyright 2009 Klarälvdalens Datakonsult AB
2 
3  This program is free software; you can redistribute it and/or
4  modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation; either version 2 of
6  the License or (at your option) version 3 or any later version
7  accepted by the membership of KDE e.V. (or its successor approved
8  by the membership of KDE e.V.), which shall act as a proxy
9  defined in Section 14 of version 3 of the license.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "importarchivedialog.h"
20 
21 #include "kmfolder.h"
22 #include "folderrequester.h"
23 #include "kmmainwidget.h"
24 #include "importjob.h"
25 
26 #include <kurlrequester.h>
27 #include <tdelocale.h>
28 #include <tdemessagebox.h>
29 
30 #include <tqlayout.h>
31 #include <tqlabel.h>
32 
33 using namespace KMail;
34 
35 ImportArchiveDialog::ImportArchiveDialog( TQWidget *parent, TQt::WidgetFlags flags )
36  : KDialogBase( parent, "import_archive_dialog", false, i18n( "Import Archive" ),
37  KDialogBase::Ok | KDialogBase::Cancel,
38  KDialogBase::Ok, true ),
39  mParentWidget( parent )
40 {
41  setWFlags( flags );
42  TQWidget *mainWidget = new TQWidget( this );
43  TQGridLayout *mainLayout = new TQGridLayout( mainWidget );
44  mainLayout->setSpacing( KDialog::spacingHint() );
45  mainLayout->setMargin( KDialog::marginHint() );
46  setMainWidget( mainWidget );
47 
48  int row = 0;
49 
50  // TODO: Explaination label
51  // TODO: Use TQFormLayout in KDE4
52  // TODO: better label for "Ok" button
53 
54  TQLabel *folderLabel = new TQLabel( i18n( "&Folder:" ), mainWidget );
55  mainLayout->addWidget( folderLabel, row, 0 );
56  mFolderRequester = new FolderRequester( mainWidget, kmkernel->getKMMainWidget()->folderTree() );
57  folderLabel->setBuddy( mFolderRequester );
58  mainLayout->addWidget( mFolderRequester, row, 1 );
59  row++;
60 
61  TQLabel *fileNameLabel = new TQLabel( i18n( "&Archive File:" ), mainWidget );
62  mainLayout->addWidget( fileNameLabel, row, 0 );
63  mUrlRequester = new KURLRequester( mainWidget );
64  mUrlRequester->setMode( KFile::LocalOnly );
65  mUrlRequester->setFilter( "*.tar *.zip *.tar.gz *.tar.bz2" );
66  fileNameLabel->setBuddy( mUrlRequester );
67  mainLayout->addWidget( mUrlRequester, row, 1 );
68  row++;
69 
70  // TODO: what's this, tooltips
71 
72  mainLayout->setColStretch( 1, 1 );
73  mainLayout->addItem( new TQSpacerItem( 1, 1, TQSizePolicy::Expanding, TQSizePolicy::Expanding ), row, 0 );
74 
75  // Make it a bit bigger, else the folder requester cuts off the text too early
76  resize( 500, minimumSize().height() );
77 }
78 
79 void ImportArchiveDialog::setFolder( KMFolder *defaultFolder )
80 {
81  mFolderRequester->setFolder( defaultFolder );
82 }
83 
84 void ImportArchiveDialog::slotOk()
85 {
86  if ( !TQFile::exists( mUrlRequester->url() ) ) {
87  KMessageBox::information( this, i18n( "Please select an archive file that should be imported." ),
88  i18n( "No archive file selected" ) );
89  return;
90  }
91 
92  if ( !mFolderRequester->folder() ) {
93  KMessageBox::information( this, i18n( "Please select the folder where the archive should be imported to." ),
94  i18n( "No target folder selected" ) );
95  return;
96  }
97 
98  // TODO: check if url is empty. or better yet, disable ok button until file is chosen
99 
100  ImportJob *importJob = new KMail::ImportJob( mParentWidget );
101  importJob->setFile( mUrlRequester->url() );
102  importJob->setRootFolder( mFolderRequester->folder() );
103  importJob->start();
104  accept();
105 }
106 
107 #include "importarchivedialog.moc"
Mail folder.
Definition: kmfolder.h:69
A widget that contains a KLineEdit which shows the current folder and a button that fires a KMFolderS...
Imports an archive that was previously backed up with an BackupJob.
Definition: importjob.h:53
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66
folderdiaquotatab.h
Definition: aboutdata.cpp:40