Commit 812e301a authored by Laurent Montel's avatar Laurent Montel 😁

Fix Bug 340818 - Tries to attach directories

FIXED-IN: 14.12
BUG: 340818
parent 12adc93d
...@@ -3468,7 +3468,7 @@ void KMComposeWin::slotCreateAddressBookContact() ...@@ -3468,7 +3468,7 @@ void KMComposeWin::slotCreateAddressBookContact()
void KMComposeWin::slotAttachMissingFile() void KMComposeWin::slotAttachMissingFile()
{ {
mComposerBase->attachmentController()->showAddAttachmentDialog(); mComposerBase->attachmentController()->showAddAttachmentFileDialog();
} }
void KMComposeWin::slotVerifyMissingAttachmentTimeout() void KMComposeWin::slotVerifyMissingAttachmentTimeout()
......
...@@ -119,7 +119,8 @@ public: ...@@ -119,7 +119,8 @@ public:
QAction *saveAsContextAction; QAction *saveAsContextAction;
QAction *propertiesAction; QAction *propertiesAction;
QAction *propertiesContextAction; QAction *propertiesContextAction;
QAction *addAction; QAction *addAttachmentFileAction;
QAction *addAttachmentDirectoryAction;
QAction *addContextAction; QAction *addContextAction;
QAction *selectAllAction; QAction *selectAllAction;
KActionMenu *attachmentMenu; KActionMenu *attachmentMenu;
...@@ -148,7 +149,8 @@ AttachmentControllerBase::Private::Private( AttachmentControllerBase *qq ) ...@@ -148,7 +149,8 @@ AttachmentControllerBase::Private::Private( AttachmentControllerBase *qq )
, saveAsContextAction( 0 ) , saveAsContextAction( 0 )
, propertiesAction( 0 ) , propertiesAction( 0 )
, propertiesContextAction( 0 ) , propertiesContextAction( 0 )
, addAction( 0 ) , addAttachmentFileAction( 0 )
, addAttachmentDirectoryAction( 0 )
, addContextAction( 0 ) , addContextAction( 0 )
, selectAllAction( 0 ) , selectAllAction( 0 )
, attachmentMenu( 0 ) , attachmentMenu( 0 )
...@@ -460,23 +462,29 @@ void AttachmentControllerBase::createActions() ...@@ -460,23 +462,29 @@ void AttachmentControllerBase::createActions()
connect( d->attachMyPublicKeyAction, SIGNAL(triggered(bool)), this, SLOT(attachMyPublicKey()) ); connect( d->attachMyPublicKeyAction, SIGNAL(triggered(bool)), this, SLOT(attachMyPublicKey()) );
d->attachmentMenu = new KActionMenu( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "Attach" ), this ); d->attachmentMenu = new KActionMenu( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "Attach" ), this );
connect( d->attachmentMenu, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentDialog()) ); connect( d->attachmentMenu, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentFileDialog()) );
d->attachmentMenu->setDelayed(true); d->attachmentMenu->setDelayed(true);
d->addAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "&Attach File..." ), this ); d->addAttachmentFileAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "&Attach File..." ), this );
d->addAction->setIconText( i18n( "Attach" ) ); d->addAttachmentFileAction->setIconText( i18n( "Attach" ) );
d->addContextAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), d->addContextAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ),
i18n( "Add Attachment..." ), this ); i18n( "Add Attachment..." ), this );
connect( d->addAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentDialog()) ); connect( d->addAttachmentFileAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentFileDialog()) );
connect( d->addContextAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentDialog()) ); connect( d->addContextAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentFileDialog()) );
d->addAttachmentDirectoryAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "&Attach Directory..." ), this );
d->addAttachmentDirectoryAction->setIconText( i18n( "Attach" ) );
connect( d->addAttachmentDirectoryAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentCompressedDirectoryDialog()) );
d->addOwnVcardAction = new KAction( i18n("Attach Own vCard"),this ); d->addOwnVcardAction = new KAction( i18n("Attach Own vCard"),this );
d->addOwnVcardAction->setIconText( i18n( "Own vCard" ) ); d->addOwnVcardAction->setIconText( i18n( "Own vCard" ) );
d->addOwnVcardAction->setCheckable(true); d->addOwnVcardAction->setCheckable(true);
connect(d->addOwnVcardAction, SIGNAL(triggered(bool)), this, SIGNAL(addOwnVcard(bool))); connect(d->addOwnVcardAction, SIGNAL(triggered(bool)), this, SIGNAL(addOwnVcard(bool)));
d->attachmentMenu->addAction(d->addAction); d->attachmentMenu->addAction(d->addAttachmentFileAction);
d->attachmentMenu->addAction(d->addAttachmentDirectoryAction);
d->attachmentMenu->addSeparator(); d->attachmentMenu->addSeparator();
d->attachmentMenu->addAction(d->addOwnVcardAction); d->attachmentMenu->addAction(d->addOwnVcardAction);
...@@ -526,7 +534,8 @@ void AttachmentControllerBase::createActions() ...@@ -526,7 +534,8 @@ void AttachmentControllerBase::createActions()
KActionCollection *collection = d->mActionCollection; KActionCollection *collection = d->mActionCollection;
collection->addAction( QLatin1String( "attach_public_key" ), d->attachPublicKeyAction ); collection->addAction( QLatin1String( "attach_public_key" ), d->attachPublicKeyAction );
collection->addAction( QLatin1String( "attach_my_public_key" ), d->attachMyPublicKeyAction ); collection->addAction( QLatin1String( "attach_my_public_key" ), d->attachMyPublicKeyAction );
collection->addAction( QLatin1String( "attach" ), d->addAction ); collection->addAction( QLatin1String( "attach" ), d->addAttachmentFileAction );
collection->addAction( QLatin1String( "attach_directory" ), d->addAttachmentDirectoryAction );
collection->addAction( QLatin1String( "remove" ), d->removeAction ); collection->addAction( QLatin1String( "remove" ), d->removeAction );
collection->addAction( QLatin1String( "attach_save" ), d->saveAsAction ); collection->addAction( QLatin1String( "attach_save" ), d->saveAsAction );
collection->addAction( QLatin1String( "attach_properties" ), d->propertiesAction ); collection->addAction( QLatin1String( "attach_properties" ), d->propertiesAction );
...@@ -810,7 +819,49 @@ void AttachmentControllerBase::attachmentProperties( AttachmentPart::Ptr part ) ...@@ -810,7 +819,49 @@ void AttachmentControllerBase::attachmentProperties( AttachmentPart::Ptr part )
delete dialog; delete dialog;
} }
void AttachmentControllerBase::showAddAttachmentDialog() void AttachmentControllerBase::attachFileDirectory(const KUrl::List &urls, const QString &encoding)
{
const int numberOfFiles(urls.count());
for (int i=0; i<numberOfFiles; ++i) {
const KUrl url = urls.at( i );
KUrl urlWithEncoding = url;
urlWithEncoding.setFileEncoding( encoding );
if ( KMimeType::findByUrl( urlWithEncoding )->name() == QLatin1String( "inode/directory" ) ) {
const int rc = KMessageBox::warningYesNo( d->wParent,i18n("Do you really want to attach this directory \"%1\" ?", url.toLocalFile() ),i18n( "Attach directory" ) );
if ( rc == KMessageBox::Yes ) {
addAttachment( urlWithEncoding );
}
} else {
addAttachment( urlWithEncoding );
}
}
}
void AttachmentControllerBase::showAddAttachmentCompressedDirectoryDialog()
{
#ifndef KDEPIM_MOBILE_UI
QPointer<KEncodingFileDialog> dialog = new KEncodingFileDialog(
QString( /*startDir*/ ), QString( /*encoding*/ ), QString( /*filter*/ ),
i18n( "Attach Directory" ), KFileDialog::Other, d->wParent );
dialog->okButton()->setGuiItem( KGuiItem( i18n("&Attach"), QLatin1String( "document-open" ) ) );
dialog->setMode( KFile::Directory );
if( dialog->exec() == KDialog::Accepted && dialog ) {
const QString encoding = MessageViewer::NodeHelper::fixEncoding( dialog->selectedEncoding() );
attachFileDirectory(dialog->selectedUrls(), encoding);
}
delete dialog;
#else
// use native dialog, while being much simpler, it actually fits on the screen much better than our own monster dialog
const QString fileName = KFileDialog::getExistingDirectory(KUrl(), QString(), d->wParent, i18n("Attach Directory" ) );
if ( !fileName.isEmpty() ) {
addAttachment( KUrl::fromLocalFile( fileName ) );
}
#endif
}
void AttachmentControllerBase::showAddAttachmentFileDialog()
{ {
#ifndef KDEPIM_MOBILE_UI #ifndef KDEPIM_MOBILE_UI
QPointer<KEncodingFileDialog> dialog = new KEncodingFileDialog( QPointer<KEncodingFileDialog> dialog = new KEncodingFileDialog(
...@@ -818,24 +869,10 @@ void AttachmentControllerBase::showAddAttachmentDialog() ...@@ -818,24 +869,10 @@ void AttachmentControllerBase::showAddAttachmentDialog()
i18n( "Attach File" ), KFileDialog::Other, d->wParent ); i18n( "Attach File" ), KFileDialog::Other, d->wParent );
dialog->okButton()->setGuiItem( KGuiItem( i18n("&Attach"), QLatin1String( "document-open" ) ) ); dialog->okButton()->setGuiItem( KGuiItem( i18n("&Attach"), QLatin1String( "document-open" ) ) );
dialog->setMode( KFile::Files|KFile::Directory ); dialog->setMode( KFile::Files );
if( dialog->exec() == KDialog::Accepted && dialog ) { if( dialog->exec() == KDialog::Accepted && dialog ) {
const KUrl::List files = dialog->selectedUrls();
const QString encoding = MessageViewer::NodeHelper::fixEncoding( dialog->selectedEncoding() ); const QString encoding = MessageViewer::NodeHelper::fixEncoding( dialog->selectedEncoding() );
const int numberOfFiles(files.count()); attachFileDirectory(dialog->selectedUrls(), encoding);
for (int i=0; i<numberOfFiles; ++i) {
const KUrl url = files.at( i );
KUrl urlWithEncoding = url;
urlWithEncoding.setFileEncoding( encoding );
if ( KMimeType::findByUrl( urlWithEncoding )->name() == QLatin1String( "inode/directory" ) ) {
const int rc = KMessageBox::warningYesNo( d->wParent,i18n("Do you really want to attach this directory \"%1\" ?", url.toLocalFile() ),i18n( "Attach directory" ) );
if ( rc == KMessageBox::Yes ) {
addAttachment( urlWithEncoding );
}
} else {
addAttachment( urlWithEncoding );
}
}
} }
delete dialog; delete dialog;
#else #else
......
...@@ -73,7 +73,8 @@ public slots: ...@@ -73,7 +73,8 @@ public slots:
void editAttachmentWith( MessageCore::AttachmentPart::Ptr part ); void editAttachmentWith( MessageCore::AttachmentPart::Ptr part );
void saveAttachmentAs( MessageCore::AttachmentPart::Ptr part ); void saveAttachmentAs( MessageCore::AttachmentPart::Ptr part );
void attachmentProperties( MessageCore::AttachmentPart::Ptr part ); void attachmentProperties( MessageCore::AttachmentPart::Ptr part );
void showAddAttachmentDialog(); void showAddAttachmentFileDialog();
void showAddAttachmentCompressedDirectoryDialog();
/// sets sign, encrypt, shows properties dialog if so configured /// sets sign, encrypt, shows properties dialog if so configured
void addAttachment( MessageCore::AttachmentPart::Ptr part ); void addAttachment( MessageCore::AttachmentPart::Ptr part );
void addAttachment( const KUrl &url ); void addAttachment( const KUrl &url );
...@@ -96,6 +97,10 @@ protected: ...@@ -96,6 +97,10 @@ protected:
void enableAttachMyPublicKey( bool enable ); void enableAttachMyPublicKey( bool enable );
void byteArrayToRemoteFile(const QByteArray &aData, const KUrl &aURL, bool overwrite = false); void byteArrayToRemoteFile(const QByteArray &aData, const KUrl &aURL, bool overwrite = false);
void openWith(KService::Ptr offer = KService::Ptr()); void openWith(KService::Ptr offer = KService::Ptr());
private:
void attachFileDirectory(const KUrl::List &urls, const QString &encoding);
private slots: private slots:
void slotPutResult(KJob *job); void slotPutResult(KJob *job);
void slotOpenWithDialog(); void slotOpenWithDialog();
......
...@@ -1629,7 +1629,7 @@ MessageComposer::ComposerViewBase::MissingAttachment MessageComposer::ComposerVi ...@@ -1629,7 +1629,7 @@ MessageComposer::ComposerViewBase::MissingAttachment MessageComposer::ComposerVi
if ( rc == KMessageBox::Cancel ) if ( rc == KMessageBox::Cancel )
return FoundMissingAttachmentAndCancel; return FoundMissingAttachmentAndCancel;
if ( rc == KMessageBox::Yes ) { if ( rc == KMessageBox::Yes ) {
m_attachmentController->showAddAttachmentDialog(); m_attachmentController->showAddAttachmentFileDialog();
return FoundMissingAttachmentAndAddedAttachment; return FoundMissingAttachmentAndAddedAttachment;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment