Commit 44b1c7af authored by Laurent Montel's avatar Laurent Montel 😁

Use enum here

parent fea6a804
......@@ -248,14 +248,13 @@ void AttachmentControllerBase::Private::viewSelectedAttachments()
void AttachmentControllerBase::Private::editSelectedAttachment()
{
Q_ASSERT( selectedParts.count() == 1 );
q->editAttachment( selectedParts.first(), false /*openWith*/ );
// TODO nicer api would be enum { OpenWithDialog, NoOpenWithDialog }
q->editAttachment( selectedParts.first(), MessageViewer::EditorWatcher::NoOpenWithDialog );
}
void AttachmentControllerBase::Private::editSelectedAttachmentWith()
{
Q_ASSERT( selectedParts.count() == 1 );
q->editAttachment( selectedParts.first(), true /*openWith*/ );
q->editAttachment( selectedParts.first(), MessageViewer::EditorWatcher::OpenWithDialog );
}
void AttachmentControllerBase::Private::removeSelectedAttachments()
......@@ -672,7 +671,7 @@ void AttachmentControllerBase::Private::slotAttachmentContentCreated( KJob *job
}
}
void AttachmentControllerBase::editAttachment( AttachmentPart::Ptr part, bool openWith )
void AttachmentControllerBase::editAttachment( AttachmentPart::Ptr part, MessageViewer::EditorWatcher::OpenWithOption openWithOption )
{
KTemporaryFile *tempFile = dumpAttachmentToTempFile( part );
if( !tempFile ) {
......@@ -684,7 +683,7 @@ void AttachmentControllerBase::editAttachment( AttachmentPart::Ptr part, bool op
MessageViewer::EditorWatcher *watcher = new MessageViewer::EditorWatcher(
KUrl::fromPath( tempFile->fileName() ),
QString::fromLatin1( part->mimeType() ), openWith,
QString::fromLatin1( part->mimeType() ), openWithOption,
this, d->wParent );
connect( watcher, SIGNAL(editDone(MessageViewer::EditorWatcher*)),
this, SLOT(editDone(MessageViewer::EditorWatcher*)) );
......@@ -706,7 +705,7 @@ void AttachmentControllerBase::editAttachment( AttachmentPart::Ptr part, bool op
void AttachmentControllerBase::editAttachmentWith( AttachmentPart::Ptr part )
{
editAttachment( part, true );
editAttachment( part, MessageViewer::EditorWatcher::OpenWithDialog );
}
void AttachmentControllerBase::saveAttachmentAs( AttachmentPart::Ptr part )
......
......@@ -33,6 +33,7 @@
#include <KJob>
#include <KService>
#include "messagecomposer_export.h"
#include "messageviewer/viewer/editorwatcher.h"
class KActionCollection;
class QAction;
namespace MessageCore {
......@@ -68,7 +69,7 @@ public slots:
void showContextMenu();
void openAttachment( MessageCore::AttachmentPart::Ptr part );
void viewAttachment( MessageCore::AttachmentPart::Ptr part );
void editAttachment( MessageCore::AttachmentPart::Ptr part, bool openWith = false );
void editAttachment( MessageCore::AttachmentPart::Ptr part, MessageViewer::EditorWatcher::OpenWithOption option = MessageViewer::EditorWatcher::NoOpenWithDialog );
void editAttachmentWith( MessageCore::AttachmentPart::Ptr part );
void saveAttachmentAs( MessageCore::AttachmentPart::Ptr part );
void attachmentProperties( MessageCore::AttachmentPart::Ptr part );
......
......@@ -41,7 +41,7 @@
#endif
namespace MessageViewer {
EditorWatcher::EditorWatcher( const KUrl & url, const QString &mimeType, bool openWith,
EditorWatcher::EditorWatcher( const KUrl & url, const QString &mimeType, OpenWithOption option,
QObject * parent, QWidget *parentWidget ) :
QObject( parent ),
mUrl( url ),
......@@ -50,7 +50,7 @@ EditorWatcher::EditorWatcher( const KUrl & url, const QString &mimeType, bool op
mInotifyWatch(-1),
mEditor( 0 ),
mParentWidget( parentWidget ),
mOpenWith( openWith ),
mOpenWithOption( option ),
mHaveInotify( false ),
mFileOpen( false ),
mEditorRunning( false ),
......@@ -68,7 +68,7 @@ bool EditorWatcher::start()
KUrl::List list;
list.append( mUrl );
KService::Ptr offer = KMimeTypeTrader::self()->preferredService( mMimeType, QLatin1String("Application") );
if ( mOpenWith || !offer ) {
if ( (mOpenWithOption == OpenWithDialog) || !offer ) {
AutoQPointer<KOpenWithDialog> dlg( new KOpenWithDialog( list, i18n("Edit with:"),
QString(), mParentWidget ) );
const int dlgrc = dlg->exec();
......
......@@ -40,7 +40,10 @@ class MESSAGEVIEWER_EXPORT EditorWatcher : public QObject
{
Q_OBJECT
public:
enum OpenWithOption {
OpenWithDialog,
NoOpenWithDialog
};
/**
* Constructs an EditorWatcher.
* @param parent the parent object of this EditorWatcher, which will take care of deleting
......@@ -48,7 +51,7 @@ public:
* @param parentWidget the parent widget of this EditorWatcher, which will be used as the parent
* widget for message dialogs.
*/
EditorWatcher( const KUrl &url, const QString &mimeType, bool openWith,
EditorWatcher( const KUrl &url, const QString &mimeType, OpenWithOption option,
QObject *parent, QWidget *parentWidget );
bool start();
......@@ -74,7 +77,7 @@ private:
KProcess *mEditor;
QWidget *mParentWidget;
bool mOpenWith;
OpenWithOption mOpenWithOption;
bool mHaveInotify;
bool mFileOpen;
bool mEditorRunning;
......
......@@ -505,7 +505,7 @@ bool ViewerPrivate::editAttachment( KMime::Content * node, bool showWarning )
EditorWatcher *watcher =
new EditorWatcher( KUrl( file.fileName() ), QLatin1String(node->contentType()->mimeType()),
false, this, mMainWindow );
MessageViewer::EditorWatcher::NoOpenWithDialog, this, mMainWindow );
mEditorWatchers[ watcher ] = node;
connect( watcher, SIGNAL(editDone(EditorWatcher*)), SLOT(slotAttachmentEditDone(EditorWatcher*)) );
......
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