19 #include "archivefolderdialog.h"
21 #include "backupjob.h"
24 #include "kmmainwidget.h"
25 #include "folderrequester.h"
28 #include <tdelocale.h>
29 #include <kcombobox.h>
30 #include <kurlrequester.h>
31 #include <tdemessagebox.h>
32 #include <tdefiledialog.h>
35 #include <tqcheckbox.h>
38 using namespace KMail;
40 static TQString standardArchivePath(
const TQString &folderName )
42 TQString currentPath = TDEGlobalSettings::documentPath();
43 TQDir dir( currentPath );
45 currentPath = TQDir::homeDirPath() +
'/';
48 i18n(
"Start of the filename for a mail archive file" ,
"Archive" ) +
"_" + folderName +
49 "_" + TQDate::currentDate().toString( TQt::ISODate ) +
".tar.bz2";
52 ArchiveFolderDialog::ArchiveFolderDialog( TQWidget *parent )
53 : KDialogBase( parent,
"archive_folder_dialog", false, i18n(
"Archive Folder" ),
54 KDialogBase::
Ok | KDialogBase::Cancel,
55 KDialogBase::
Ok, true ),
56 mParentWidget( parent )
58 TQWidget *mainWidget =
new TQWidget(
this );
59 TQGridLayout *mainLayout =
new TQGridLayout( mainWidget );
60 mainLayout->setSpacing( KDialog::spacingHint() );
61 mainLayout->setMargin( KDialog::marginHint() );
62 setMainWidget( mainWidget );
70 TQLabel *folderLabel =
new TQLabel( i18n(
"&Folder:" ), mainWidget );
71 mainLayout->addWidget( folderLabel, row, 0 );
72 mFolderRequester =
new FolderRequester( mainWidget, kmkernel->getKMMainWidget()->folderTree() );
73 mFolderRequester->setMustBeReadWrite(
false );
74 connect( mFolderRequester, TQ_SIGNAL(folderChanged(
KMFolder *)),
75 TQ_SLOT(slotFolderChanged(
KMFolder *)) );
76 folderLabel->setBuddy( mFolderRequester );
77 mainLayout->addWidget( mFolderRequester, row, 1 );
80 TQLabel *formatLabel =
new TQLabel( i18n(
"F&ormat:" ), mainWidget );
81 mainLayout->addWidget( formatLabel, row, 0 );
82 mFormatComboBox =
new KComboBox( mainWidget );
83 formatLabel->setBuddy( mFormatComboBox );
86 mFormatComboBox->insertItem( i18n(
"Compressed Zip Archive (.zip)" ) );
87 mFormatComboBox->insertItem( i18n(
"Uncompressed Archive (.tar)" ) );
88 mFormatComboBox->insertItem( i18n(
"BZ2-Compressed Tar Archive (.tar.bz2)" ) );
89 mFormatComboBox->insertItem( i18n(
"GZ-Compressed Tar Archive (.tar.gz)" ) );
90 mFormatComboBox->setCurrentItem( 2 );
91 connect( mFormatComboBox, TQ_SIGNAL(activated(
int)),
92 this, TQ_SLOT(slotFixFileExtension()) );
93 mainLayout->addWidget( mFormatComboBox, row, 1 );
96 TQLabel *fileNameLabel =
new TQLabel( i18n(
"&Archive File:" ), mainWidget );
97 mainLayout->addWidget( fileNameLabel, row, 0 );
98 mUrlRequester =
new KURLRequester( mainWidget );
99 mUrlRequester->setMode( KFile::LocalOnly );
100 mUrlRequester->setFilter(
"*.tar *.zip *.tar.gz *.tar.bz2" );
101 mUrlRequester->fileDialog()->setKeepLocation(
true );
102 fileNameLabel->setBuddy( mUrlRequester );
103 connect( mUrlRequester->lineEdit(), TQ_SIGNAL(textChanged(
const TQString &)),
104 TQ_SLOT(slotUrlChanged(
const TQString &)) );
105 connect( mUrlRequester, TQ_SIGNAL(urlSelected(
const TQString&)),
106 this, TQ_SLOT(slotFixFileExtension()) );
107 mainLayout->addWidget( mUrlRequester, row, 1 );
111 mDeleteCheckBox =
new TQCheckBox( i18n(
"&Delete folders after completion" ), mainWidget );
112 mainLayout->addMultiCellWidget( mDeleteCheckBox, row, row, 0, 1, TQt::AlignLeft );
119 mainLayout->setColStretch( 1, 1 );
120 mainLayout->addItem(
new TQSpacerItem( 1, 1, TQSizePolicy::Expanding, TQSizePolicy::Expanding ), row, 0 );
123 resize( 500, minimumSize().height() );
126 void ArchiveFolderDialog::slotUrlChanged(
const TQString &text )
128 enableButton( Ok, !text.isEmpty() );
131 bool canRemoveFolder(
KMFolder *folder )
140 void ArchiveFolderDialog::slotFolderChanged(
KMFolder *folder )
142 mDeleteCheckBox->setEnabled( canRemoveFolder( folder ) );
143 enableButton( Ok, folder && !folder->
noContent());
146 void ArchiveFolderDialog::setFolder(
KMFolder *defaultFolder )
148 mFolderRequester->setFolder( defaultFolder );
150 mUrlRequester->setURL( standardArchivePath( defaultFolder->name() ) );
151 mDeleteCheckBox->setEnabled( canRemoveFolder( defaultFolder ) );
154 void ArchiveFolderDialog::slotOk()
156 if ( !Util::checkOverwrite( mUrlRequester->url(),
this ) ) {
160 if ( !mFolderRequester->folder() ) {
161 KMessageBox::information(
this, i18n(
"Please select the folder that should be archived." ),
162 i18n(
"No folder selected" ) );
168 backupJob->setRootFolder( mFolderRequester->folder() );
169 backupJob->setSaveLocation( mUrlRequester->url() );
170 backupJob->setArchiveType(
static_cast<BackupJob::ArchiveType
>( mFormatComboBox->currentItem() ) );
171 backupJob->setDeleteFoldersAfterCompletion( mDeleteCheckBox->isEnabled() &&
172 mDeleteCheckBox->isChecked() );
177 void ArchiveFolderDialog::slotFixFileExtension()
180 const int numExtensions = 4;
184 const char *sortedExtensions[numExtensions] = {
".zip",
".tar.bz2",
".tar.gz",
".tar" };
187 const char *extensions[numExtensions] = {
".zip",
".tar",
".tar.bz2",
".tar.gz" };
189 TQString fileName = mUrlRequester->url();
190 if ( fileName.isEmpty() ) {
191 fileName = standardArchivePath( mFolderRequester->folder() ?
192 mFolderRequester->folder()->name() :
"" );
196 for(
int i = 0; i < numExtensions; i++ ) {
197 int index = fileName.lower().findRev( sortedExtensions[i] );
199 fileName = fileName.left( fileName.length() - TQString( sortedExtensions[i] ).length() );
205 fileName += extensions[mFormatComboBox->currentItem()];
206 mUrlRequester->setURL( fileName );
209 #include "archivefolderdialog.moc"
bool canDeleteMessages() const
Can messages in this folder be deleted?
bool isSystemFolder() const
Returns true if the folder is a kmail system folder.
bool noContent() const
Returns, if the folder can't contain mails, but only subfolder.
Writes an entire folder structure to an archive file.
A widget that contains a KLineEdit which shows the current folder and a button that fires a KMFolderS...
@ Ok
The user rights/ACL have been fetched from the server sucessfully.