21 #include "mailcommon/job/backupjob.h"
24 #include "folderrequester.h"
25 #include "messageviewer/utils/util.h"
27 #include <Akonadi/Collection>
30 #include <kcombobox.h>
31 #include <kurlrequester.h>
32 #include <kmessagebox.h>
37 #include <qcheckbox.h>
38 #include <QGridLayout>
40 using namespace KMail;
41 using namespace MailCommon;
45 QString currentPath = KGlobalSettings::documentPath();
46 QDir dir( currentPath );
48 currentPath = QDir::homePath();
49 return currentPath + QLatin1Char(
'/' ) +
50 i18nc(
"Start of the filename for a mail archive file" ,
"Archive" ) + QLatin1Char(
'_' ) + folderName + QLatin1Char(
'_' ) + QDate::currentDate().toString( Qt::ISODate ) + QLatin1String(
".tar.bz2" );
54 :
KDialog( parent ), mParentWidget( parent )
56 setObjectName( QLatin1String(
"archive_folder_dialog") );
57 setCaption( i18n(
"Archive Folder" ) );
58 setButtons( Ok|Cancel );
59 setDefaultButton( Ok );
60 setButtonText(KDialog::Ok,i18n(
"Archive"));
63 QGridLayout *mainLayout =
new QGridLayout( mainWidget );
64 mainLayout->setSpacing( KDialog::spacingHint() );
65 mainLayout->setMargin( KDialog::marginHint() );
66 setMainWidget( mainWidget );
72 QLabel *folderLabel =
new QLabel( i18n(
"&Folder:" ), mainWidget );
73 mainLayout->addWidget( folderLabel, row, 0 );
74 mFolderRequester =
new FolderRequester( mainWidget );
75 mFolderRequester->setMustBeReadWrite(
false );
76 mFolderRequester->setNotAllowToCreateNewFolder(
true );
77 connect( mFolderRequester, SIGNAL(folderChanged(Akonadi::Collection)), SLOT(slotFolderChanged(Akonadi::Collection)) );
78 folderLabel->setBuddy( mFolderRequester );
79 mainLayout->addWidget( mFolderRequester, row, 1 );
82 QLabel *formatLabel =
new QLabel( i18n(
"F&ormat:" ), mainWidget );
83 mainLayout->addWidget( formatLabel, row, 0 );
84 mFormatComboBox =
new KComboBox( mainWidget );
85 formatLabel->setBuddy( mFormatComboBox );
88 mFormatComboBox->addItem( i18n(
"Compressed Zip Archive (.zip)" ) );
89 mFormatComboBox->addItem( i18n(
"Uncompressed Archive (.tar)" ) );
90 mFormatComboBox->addItem( i18n(
"BZ2-Compressed Tar Archive (.tar.bz2)" ) );
91 mFormatComboBox->addItem( i18n(
"GZ-Compressed Tar Archive (.tar.gz)" ) );
92 mFormatComboBox->setCurrentIndex( 2 );
93 connect( mFormatComboBox, SIGNAL(activated(
int)),
94 this, SLOT(slotFixFileExtension()) );
95 mainLayout->addWidget( mFormatComboBox, row, 1 );
98 QLabel *fileNameLabel =
new QLabel( i18n(
"&Archive File:" ), mainWidget );
99 mainLayout->addWidget( fileNameLabel, row, 0 );
100 mUrlRequester =
new KUrlRequester( mainWidget );
101 mUrlRequester->setMode( KFile::LocalOnly | KFile::File );
102 mUrlRequester->setFilter( QLatin1String(
"*.tar *.zip *.tar.gz *.tar.bz2") );
103 fileNameLabel->setBuddy( mUrlRequester );
104 connect( mUrlRequester, SIGNAL(urlSelected(KUrl)),
105 this, SLOT(slotFixFileExtension()) );
106 connect( mUrlRequester, SIGNAL(textChanged(QString)),
107 this, SLOT(slotUrlChanged(QString)) );
108 mainLayout->addWidget( mUrlRequester, row, 1 );
112 mDeleteCheckBox =
new QCheckBox( i18n(
"&Delete folder and subfolders after completion" ), mainWidget );
113 mainLayout->addWidget( mDeleteCheckBox, row, 0, 1, 2, Qt::AlignLeft );
116 mRecursiveCheckBox =
new QCheckBox( i18n(
"Archive all subfolders" ), mainWidget );
117 connect( mRecursiveCheckBox, SIGNAL(clicked()),
this, SLOT(slotRecursiveCheckboxClicked()) );
118 mainLayout->addWidget( mRecursiveCheckBox, row, 0, 1, 2, Qt::AlignLeft );
119 mRecursiveCheckBox->setChecked(
true );
126 mainLayout->addWidget(
new KSeparator(), row, 0, 1, 2);
128 mainLayout->setColumnStretch( 1, 1 );
129 mainLayout->addItem(
new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding ), row, 0 );
132 resize( 500, minimumSize().height() );
141 && ( col.rights() & Akonadi::Collection::CanDeleteCollection )
142 && !folder->isStructural()
143 && !folder->isSystemFolder()
144 && ( col.resource() != QLatin1String(
"akonadi_nepomuktag_resource" ) );
147 void ArchiveFolderDialog::slotRecursiveCheckboxClicked()
149 slotFolderChanged( mFolderRequester->collection() );
152 void ArchiveFolderDialog::slotFolderChanged(
const Akonadi::Collection &folder )
154 mDeleteCheckBox->setEnabled( allowToDeleteFolders( folder ) );
157 bool ArchiveFolderDialog::allowToDeleteFolders(
const Akonadi::Collection &folder)
const
164 mFolderRequester->setCollection( defaultCollection );
168 mDeleteCheckBox->setEnabled( allowToDeleteFolders( defaultCollection ) );
169 enableButtonOk( defaultCollection.isValid() && folder && !folder->isStructural() );
172 void ArchiveFolderDialog::slotButtonClicked(
int button )
174 if ( button == KDialog::Cancel ) {
178 Q_ASSERT( button == KDialog::Ok );
180 if ( !MessageViewer::Util::checkOverwrite( mUrlRequester->url(), this ) ) {
184 if ( !mFolderRequester->hasCollection() ) {
185 KMessageBox::information(
this, i18n(
"Please select the folder that should be archived." ),
186 i18n(
"No folder selected" ) );
190 MailCommon::BackupJob *backupJob =
new MailCommon::BackupJob( mParentWidget );
191 backupJob->setRootFolder( mFolderRequester->collection() );
192 backupJob->setSaveLocation( mUrlRequester->url() );
193 backupJob->setArchiveType( static_cast<BackupJob::ArchiveType>( mFormatComboBox->currentIndex() ) );
194 backupJob->setDeleteFoldersAfterCompletion( mDeleteCheckBox->isEnabled() && mDeleteCheckBox->isChecked());
195 backupJob->setRecursive( mRecursiveCheckBox->isChecked() );
200 void ArchiveFolderDialog::slotFixFileExtension()
202 const int numExtensions = 4;
204 const char *extensions[numExtensions] = {
".zip",
".tar",
".tar.bz2",
".tar.gz" };
206 QString fileName = mUrlRequester->url().path();
207 if ( fileName.isEmpty() )
209 mFolderRequester->collection().name() : QString() );
211 const QString extension = KMimeType::extractKnownExtension(fileName);
212 if(!extension.isEmpty()) {
213 fileName = fileName.left( fileName.length() - extension.length() - 1 );
217 fileName += QLatin1String(extensions[mFormatComboBox->currentIndex()]);
218 mUrlRequester->setUrl( fileName );
221 void ArchiveFolderDialog::slotUrlChanged(
const QString &url)
223 enableButtonOk(!url.isEmpty());
226 #include "archivefolderdialog.moc"
ArchiveFolderDialog(QWidget *parent=0)
static QString standardArchivePath(const QString &folderName)
void setFolder(const Akonadi::Collection &defaultCollection)
bool canRemoveFolder(const Akonadi::Collection &col)