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()
void KMComposeWin::slotAttachMissingFile()
{
mComposerBase->attachmentController()->showAddAttachmentDialog();
mComposerBase->attachmentController()->showAddAttachmentFileDialog();
}
void KMComposeWin::slotVerifyMissingAttachmentTimeout()
......
......@@ -119,7 +119,8 @@ public:
QAction *saveAsContextAction;
QAction *propertiesAction;
QAction *propertiesContextAction;
QAction *addAction;
QAction *addAttachmentFileAction;
QAction *addAttachmentDirectoryAction;
QAction *addContextAction;
QAction *selectAllAction;
KActionMenu *attachmentMenu;
......@@ -148,7 +149,8 @@ AttachmentControllerBase::Private::Private( AttachmentControllerBase *qq )
, saveAsContextAction( 0 )
, propertiesAction( 0 )
, propertiesContextAction( 0 )
, addAction( 0 )
, addAttachmentFileAction( 0 )
, addAttachmentDirectoryAction( 0 )
, addContextAction( 0 )
, selectAllAction( 0 )
, attachmentMenu( 0 )
......@@ -460,23 +462,29 @@ void AttachmentControllerBase::createActions()
connect( d->attachMyPublicKeyAction, SIGNAL(triggered(bool)), this, SLOT(attachMyPublicKey()) );
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->addAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "&Attach File..." ), this );
d->addAction->setIconText( i18n( "Attach" ) );
d->addAttachmentFileAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ), i18n( "&Attach File..." ), this );
d->addAttachmentFileAction->setIconText( i18n( "Attach" ) );
d->addContextAction = new KAction( KIcon( QLatin1String( "mail-attachment" ) ),
i18n( "Add Attachment..." ), this );
connect( d->addAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentDialog()) );
connect( d->addContextAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentDialog()) );
connect( d->addAttachmentFileAction, SIGNAL(triggered(bool)), this, SLOT(showAddAttachmentFileDialog()) );
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->setIconText( i18n( "Own vCard" ) );
d->addOwnVcardAction->setCheckable(true);
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->addAction(d->addOwnVcardAction);
......@@ -526,7 +534,8 @@ void AttachmentControllerBase::createActions()
KActionCollection *collection = d->mActionCollection;
collection->addAction( QLatin1String( "attach_public_key" ), d->attachPublicKeyAction );
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( "attach_save" ), d->saveAsAction );
collection->addAction( QLatin1String( "attach_properties" ), d->propertiesAction );
......@@ -810,21 +819,11 @@ void AttachmentControllerBase::attachmentProperties( AttachmentPart::Ptr part )
delete dialog;
}
void AttachmentControllerBase::showAddAttachmentDialog()
void AttachmentControllerBase::attachFileDirectory(const KUrl::List &urls, const QString &encoding)
{
#ifndef KDEPIM_MOBILE_UI
QPointer<KEncodingFileDialog> dialog = new KEncodingFileDialog(
QString( /*startDir*/ ), QString( /*encoding*/ ), QString( /*filter*/ ),
i18n( "Attach File" ), KFileDialog::Other, d->wParent );
dialog->okButton()->setGuiItem( KGuiItem( i18n("&Attach"), QLatin1String( "document-open" ) ) );
dialog->setMode( KFile::Files|KFile::Directory );
if( dialog->exec() == KDialog::Accepted && dialog ) {
const KUrl::List files = dialog->selectedUrls();
const QString encoding = MessageViewer::NodeHelper::fixEncoding( dialog->selectedEncoding() );
const int numberOfFiles(files.count());
const int numberOfFiles(urls.count());
for (int i=0; i<numberOfFiles; ++i) {
const KUrl url = files.at( i );
const KUrl url = urls.at( i );
KUrl urlWithEncoding = url;
urlWithEncoding.setFileEncoding( encoding );
if ( KMimeType::findByUrl( urlWithEncoding )->name() == QLatin1String( "inode/directory" ) ) {
......@@ -836,6 +835,44 @@ void AttachmentControllerBase::showAddAttachmentDialog()
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
QPointer<KEncodingFileDialog> dialog = new KEncodingFileDialog(
QString( /*startDir*/ ), QString( /*encoding*/ ), QString( /*filter*/ ),
i18n( "Attach File" ), KFileDialog::Other, d->wParent );
dialog->okButton()->setGuiItem( KGuiItem( i18n("&Attach"), QLatin1String( "document-open" ) ) );
dialog->setMode( KFile::Files );
if( dialog->exec() == KDialog::Accepted && dialog ) {
const QString encoding = MessageViewer::NodeHelper::fixEncoding( dialog->selectedEncoding() );
attachFileDirectory(dialog->selectedUrls(), encoding);
}
delete dialog;
#else
......
......@@ -73,7 +73,8 @@ public slots:
void editAttachmentWith( MessageCore::AttachmentPart::Ptr part );
void saveAttachmentAs( 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
void addAttachment( MessageCore::AttachmentPart::Ptr part );
void addAttachment( const KUrl &url );
......@@ -96,6 +97,10 @@ protected:
void enableAttachMyPublicKey( bool enable );
void byteArrayToRemoteFile(const QByteArray &aData, const KUrl &aURL, bool overwrite = false);
void openWith(KService::Ptr offer = KService::Ptr());
private:
void attachFileDirectory(const KUrl::List &urls, const QString &encoding);
private slots:
void slotPutResult(KJob *job);
void slotOpenWithDialog();
......
......@@ -1629,7 +1629,7 @@ MessageComposer::ComposerViewBase::MissingAttachment MessageComposer::ComposerVi
if ( rc == KMessageBox::Cancel )
return FoundMissingAttachmentAndCancel;
if ( rc == KMessageBox::Yes ) {
m_attachmentController->showAddAttachmentDialog();
m_attachmentController->showAddAttachmentFileDialog();
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