summaryrefslogtreecommitdiffstats
path: root/kmail/importarchivedialog.cpp
blob: e820f1139b0dfc540e314ffcca659476d946c4d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright 2009 Klarälvdalens Datakonsult AB

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of
   the License or (at your option) version 3 or any later version
   accepted by the membership of KDE e.V. (or its successor approved
   by the membership of KDE e.V.), which shall act as a proxy
   defined in Section 14 of version 3 of the license.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "importarchivedialog.h"

#include "kmfolder.h"
#include "folderrequester.h"
#include "kmmainwidget.h"
#include "importjob.h"

#include <kurlrequester.h>
#include <klocale.h>
#include <kmessagebox.h>

#include <tqlayout.h>
#include <tqlabel.h>

using namespace KMail;

ImportArchiveDialog::ImportArchiveDialog( TQWidget *tqparent, TQt::WidgetFlags flags )
  : KDialogBase( tqparent, "import_archive_dialog", false, i18n( "Import Archive" ),
                 KDialogBase::Ok | KDialogBase::Cancel,
                 KDialogBase::Ok, true ),
    mParentWidget( tqparent )
{
  setWFlags( flags );
  TQWidget *mainWidget = new TQWidget( this );
  TQGridLayout *mainLayout = new TQGridLayout( mainWidget );
  mainLayout->setSpacing( KDialog::spacingHint() );
  mainLayout->setMargin( KDialog::marginHint() );
  setMainWidget( mainWidget );

  int row = 0;

  // TODO: Explaination label
  // TODO: Use TQFormLayout in KDE4
  // TODO: better label for "Ok" button

  TQLabel *folderLabel = new TQLabel( i18n( "&Folder:" ), mainWidget );
  mainLayout->addWidget( folderLabel, row, 0 );
  mFolderRequester = new FolderRequester( mainWidget, kmkernel->getKMMainWidget()->folderTree() );
  folderLabel->setBuddy( mFolderRequester );
  mainLayout->addWidget( mFolderRequester, row, 1 );
  row++;

  TQLabel *fileNameLabel = new TQLabel( i18n( "&Archive File:" ), mainWidget );
  mainLayout->addWidget( fileNameLabel, row, 0 );
  mUrlRequester = new KURLRequester( mainWidget );
  mUrlRequester->setMode( KFile::LocalOnly );
  mUrlRequester->setFilter( "*.tar *.zip *.tar.gz *.tar.bz2" );
  fileNameLabel->setBuddy( mUrlRequester );
  mainLayout->addWidget( mUrlRequester, row, 1 );
  row++;

  // TODO: what's this, tooltips

  mainLayout->setColStretch( 1, 1 );
  mainLayout->addItem( new TQSpacerItem( 1, 1, TQSizePolicy::Expanding, TQSizePolicy::Expanding ), row, 0 );

  // Make it a bit bigger, else the folder requester cuts off the text too early
  resize( 500, tqminimumSize().height() );
}

void ImportArchiveDialog::setFolder( KMFolder *defaultFolder )
{
  mFolderRequester->setFolder( defaultFolder );
}

void ImportArchiveDialog::slotOk()
{
  if ( !TQFile::exists( mUrlRequester->url() ) ) {
    KMessageBox::information( this, i18n( "Please select an archive file that should be imported." ),
                              i18n( "No archive file selected" ) );
    return;
  }

  if ( !mFolderRequester->folder() ) {
    KMessageBox::information( this, i18n( "Please select the folder where the archive should be imported to." ),
                              i18n( "No target folder selected" ) );
    return;
  }

  // TODO: check if url is empty. or better yet, disable ok button until file is chosen

  ImportJob *importJob = new KMail::ImportJob( mParentWidget );
  importJob->setFile( mUrlRequester->url() );
  importJob->setRootFolder( mFolderRequester->folder() );
  importJob->start();
  accept();
}

#include "importarchivedialog.moc"