From 0fd513ea7f7fe5e7ab6eb45faedd04439d5f13b2 Mon Sep 17 00:00:00 2001 From: Ingo Klcker Date: Sun, 2 May 2004 20:42:43 +0000 Subject: [PATCH] Add --view command line option to allow viewing msg files. If someone knows a better solution for the 'prevent invisible KMail from running if viewing message fails' problem then let me know. Hint: Now someone needs to write a desktop file which associates message/rfc822 files with 'kmail --view %u'. svn path=/trunk/kdepim/; revision=308138 --- kmail_options.h | 1 + kmcommands.cpp | 12 ++++++++++++ kmkernel.cpp | 33 +++++++++++++++++++++++++++++---- kmkernel.h | 1 + 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/kmail_options.h b/kmail_options.h index 3f8fea2a5..703211b19 100644 --- a/kmail_options.h +++ b/kmail_options.h @@ -20,6 +20,7 @@ KCmdLineOptions kmail_options[] = { "attach ", I18N_NOOP("Add an attachment to the mail. This can be repeated."), 0 }, { "check", I18N_NOOP("Only check for new mail."), 0 }, { "composer", I18N_NOOP("Only open composer window."), 0 }, + { "view ", I18N_NOOP("View the given message file." ), 0 }, { "+[address|URL]", I18N_NOOP("Send message to 'address' resp. " "attach the file the 'URL' points " "to."), 0 }, diff --git a/kmcommands.cpp b/kmcommands.cpp index c8139e76b..cab82e6ed 100644 --- a/kmcommands.cpp +++ b/kmcommands.cpp @@ -72,6 +72,8 @@ using KMail::FolderJob; #include "mailsourceviewer.h" using KMail::MailSourceViewer; #include "kmreadermainwin.h" +#include "secondarywindow.h" +using KMail::SecondaryWindow; #include "kmcommands.moc" @@ -808,6 +810,12 @@ void KMOpenMsgCommand::slotResult( KIO::Job *job ) if ( startOfMessage == -1 ) { KMessageBox::sorry( parentWidget(), i18n( "The file doesn't contain a message." ) ); + // Emulate closing of a secondary window so that KMail exits in case it + // was started with the --view command line option. Otherwise an + // invisible KMail would keep running. + SecondaryWindow *win = new SecondaryWindow(); + win->close(); + win->deleteLater(); deleteLater(); return; } @@ -829,6 +837,10 @@ void KMOpenMsgCommand::slotResult( KIO::Job *job ) KMessageBox::sorry( parentWidget(), i18n( "The file doesn't contain a message." ) ); delete dwMsg; dwMsg = 0; + // Emulate closing of a secondary window (see above). + SecondaryWindow *win = new SecondaryWindow(); + win->close(); + win->deleteLater(); deleteLater(); return; } diff --git a/kmkernel.cpp b/kmkernel.cpp index e4d67bdb9..5c84f36f7 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -33,6 +33,7 @@ using KRecentAddress::RecentAddresses; #include "kmidentity.h" #include "identitymanager.h" #include "configuredialog.h" +#include "kmcommands.h" // #### disabled for now #include "startupwizard.h" @@ -87,7 +88,7 @@ KMKernel::KMKernel (QObject *parent, const char *name) : mIdentityManager(0), mProgress(0), mConfigureDialog(0), mContextMenuShown( false ) { - //kdDebug(5006) << "KMKernel::KMKernel" << endl; + kdDebug(5006) << "KMKernel::KMKernel" << endl; mySelf = this; the_startingUp = true; closed_by_user = true; @@ -178,7 +179,7 @@ bool KMKernel::handleCommandLine( bool noArgsOpensReader ) KURL::List attachURLs; bool mailto = false; bool checkMail = false; - //bool viewOnly = false; + bool viewOnly = false; // process args: KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); @@ -227,6 +228,17 @@ bool KMKernel::handleCommandLine( bool noArgsOpensReader ) if (args->isSet("check")) checkMail = true; + if ( args->getOption( "view" ) ) { + viewOnly = true; + const QString filename = + QString::fromLocal8Bit( args->getOption( "view" ) ); + messageFile = KURL( filename ); + if ( !messageFile.isValid() ) { + messageFile = KURL(); + messageFile.setPath( filename ); + } + } + for(int i= 0; i < args->count(); i++) { if (strncasecmp(args->arg(i),"mailto:",7)==0) @@ -248,10 +260,14 @@ bool KMKernel::handleCommandLine( bool noArgsOpensReader ) args->clear(); - if (!noArgsOpensReader && !mailto && !checkMail) + if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly ) return false; - action (mailto, checkMail, to, cc, bcc, subj, body, messageFile, attachURLs); + if ( viewOnly ) + viewMessage( messageFile ); + else + action( mailto, checkMail, to, cc, bcc, subj, body, messageFile, + attachURLs ); return true; } @@ -424,6 +440,15 @@ DCOPRef KMKernel::openComposer(const QString &to, const QString &cc, return DCOPRef(cWin); } +int KMKernel::viewMessage( const KURL & messageFile ) +{ + KMOpenMsgCommand *openCommand = new KMOpenMsgCommand( 0, messageFile ); + + openCommand->start(); + + return 1; +} + int KMKernel::sendCertificate( const QString& to, const QByteArray& certData ) { KMMessage *msg = new KMMessage; diff --git a/kmkernel.h b/kmkernel.h index 071e603d3..1266e1de0 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -112,6 +112,7 @@ public: DCOPRef getFolder( const QString& vpath ); void selectFolder( QString folder ); virtual bool showMail( Q_UINT32 serialNumber, QString messageId ); + int viewMessage( const KURL & messageFile ); /** normal control stuff */ static KMKernel *self() { return mySelf; }