From e4e4e1bf3e58e6098fa479eef4db540081ac5785 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sun, 4 Jan 2004 23:59:01 +0000 Subject: [PATCH] Move cmdline handling to DCOP-enabled method, move cmdline def to header file (inspired by Waldo's patch), ensured header file is translated. Added missing activateWindow() calls so that new window created by e.g. "kmail foo@kde.org" is brought to front. Note: the existing activateWindow in openReader doesn't work though, even in the standalone kmail case, when typing kmail. kwin bug? Added bool param and return value to distinguish the no-arguments case from the other cases (so that "kmail" doesn't open a window if kontact is running). svn path=/trunk/kdepim/; revision=276853 --- kmailIface.h | 10 +++++ kmail_options.h | 30 ++++++++++++++ kmkernel.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++-- kmkernel.h | 2 + main.cpp | 103 ++---------------------------------------------- 5 files changed, 142 insertions(+), 103 deletions(-) create mode 100644 kmail_options.h diff --git a/kmailIface.h b/kmailIface.h index efc1cc68a..b024dc86d 100644 --- a/kmailIface.h +++ b/kmailIface.h @@ -102,6 +102,16 @@ k_dcop_signals: k_dcop_hidden: virtual bool showMail( Q_UINT32 serialNumber, QString messageId ) = 0; + /** + * DCOP-enabled for KMailUniqueAppHandler in the kontact plugin + * @param noArgsOpensReader true in the kmail process, meaning that launching "kmail" + * will open a reader window or bring to front an existing one. + * noArgsOpensReader is false when this is called from kontact, so that typing + * "kmail" doesn't open a window. + * Returns true if the command line was handled, false if it was empty and + * not handled (due to noArgsOpensReader==false). + */ + virtual bool handleCommandLine( bool /*noArgsOpensReader*/ ) = 0; }; #endif diff --git a/kmail_options.h b/kmail_options.h new file mode 100644 index 000000000..3f8fea2a5 --- /dev/null +++ b/kmail_options.h @@ -0,0 +1,30 @@ +/* -*- mode: C++; c-file-style: "gnu" -*- */ +#ifndef KMAIL_OPTIONS_H +#define KMAIL_OPTIONS_H + +#include +#include + +KCmdLineOptions kmail_options[] = +{ + { "s", 0 , 0 }, + { "subject ", I18N_NOOP("Set subject of message."), 0 }, + { "c", 0 , 0 }, + { "cc
", I18N_NOOP("Send CC: to 'address'."), 0 }, + { "b", 0 , 0 }, + { "bcc
", I18N_NOOP("Send BCC: to 'address'."), 0 }, + { "h", 0 , 0 }, + { "header
", I18N_NOOP("Add 'header' to message."), 0 }, + { "msg ", I18N_NOOP("Read message body from 'file'."), 0 }, + { "body ", I18N_NOOP("Set body of message."), 0 }, + { "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 }, + { "+[address|URL]", I18N_NOOP("Send message to 'address' resp. " + "attach the file the 'URL' points " + "to."), 0 }, +// { "+[file]", I18N_NOOP("Show message from file 'file'."), 0 }, + KCmdLineLastOption +}; + +#endif diff --git a/kmkernel.cpp b/kmkernel.cpp index 2ce406e42..da2d9bdbd 100644 --- a/kmkernel.cpp +++ b/kmkernel.cpp @@ -66,6 +66,7 @@ using KMail::FolderIface; #include #include +#include KMKernel *KMKernel::mySelf = 0; @@ -156,6 +157,89 @@ KMKernel::~KMKernel () kdDebug(5006) << "KMKernel::~KMKernel" << endl; } +bool KMKernel::handleCommandLine( bool noArgsOpensReader ) +{ + QString to, cc, bcc, subj, body; + KURL messageFile = QString::null; + KURL::List attachURLs; + bool mailto = false; + bool checkMail = false; + //bool viewOnly = false; + + // process args: + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + if (args->getOption("subject")) + { + mailto = true; + subj = QString::fromLocal8Bit(args->getOption("subject")); + } + + if (args->getOption("cc")) + { + mailto = true; + cc = QString::fromLocal8Bit(args->getOption("cc")); + } + + if (args->getOption("bcc")) + { + mailto = true; + bcc = QString::fromLocal8Bit(args->getOption("bcc")); + } + + if (args->getOption("msg")) + { + mailto = true; + messageFile.setPath( QString::fromLocal8Bit(args->getOption("msg")) ); + } + + if (args->getOption("body")) + { + mailto = true; + body = QString::fromLocal8Bit(args->getOption("body")); + } + + QCStringList attachList = args->getOptionList("attach"); + if (!attachList.isEmpty()) + { + mailto = true; + for ( QCStringList::Iterator it = attachList.begin() ; it != attachList.end() ; ++it ) + if ( !(*it).isEmpty() ) + attachURLs += KURL( QString::fromLocal8Bit( *it ) ); + } + + if (args->isSet("composer")) + mailto = true; + + if (args->isSet("check")) + checkMail = true; + + for(int i= 0; i < args->count(); i++) + { + if (strncasecmp(args->arg(i),"mailto:",7)==0) + to += args->url(i).path() + ", "; + else { + QString tmpArg = QString::fromLocal8Bit( args->arg(i) ); + KURL url( tmpArg ); + if ( url.isValid() ) + attachURLs += url; + else + to += tmpArg + ", "; + } + mailto = true; + } + if ( !to.isEmpty() ) { + // cut off the superfluous trailing ", " + to.truncate( to.length() - 2 ); + } + + args->clear(); + + if (!noArgsOpensReader && !mailto && !checkMail) + return false; + + action (mailto, checkMail, to, cc, bcc, subj, body, messageFile, attachURLs); + return true; +} /********************************************************************/ /* DCOP-callable, and command line actions */ @@ -230,8 +314,11 @@ int KMKernel::openComposer (const QString &to, const QString &cc, cWin->setCharset("", TRUE); for ( KURL::List::ConstIterator it = attachURLs.begin() ; it != attachURLs.end() ; ++it ) cWin->addAttach((*it)); - if (hidden == 0) + if (hidden == 0) { cWin->show(); + // This is called via DCOP, so ensure the new window appears on top + KWin::activateWindow( cWin->winId() ); + } return 1; } @@ -273,8 +360,11 @@ int KMKernel::openComposer (const QString &to, const QString &cc, cWin->addAttach(msgPart); } - if (hidden == 0) + if (hidden == 0) { cWin->show(); + // This is called via DCOP, so ensure the new window appears on top + KWin::activateWindow( cWin->winId() ); + } return 1; } @@ -293,7 +383,11 @@ DCOPRef KMKernel::openComposer(const QString &to, const QString &cc, KMComposeWin *cWin = new KMComposeWin(msg); cWin->setCharset("", TRUE); - if (!hidden) cWin->show(); + if (!hidden) { + cWin->show(); + // This is called via DCOP, so ensure the new window appears on top + KWin::activateWindow( cWin->winId() ); + } return DCOPRef(cWin); } diff --git a/kmkernel.h b/kmkernel.h index 9fa01e643..f9e7f2f9a 100644 --- a/kmkernel.h +++ b/kmkernel.h @@ -192,6 +192,8 @@ public: bool registerSystemTrayApplet( const KSystemTray* ); bool unregisterSystemTrayApplet( const KSystemTray* ); + /// Reimplemented from KMailIface + bool handleCommandLine( bool noArgsOpensReader ); void emergencyExit( const QString& reason ); /** Returns a message serial number that hasn't been used yet. */ diff --git a/main.cpp b/main.cpp index cde0d9637..f5f882e81 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,7 @@ #include #include #include "kmkernel.h" //control center -#include +#include "kmail_options.h" #include #undef Status // stupid X headers @@ -31,28 +31,6 @@ "Please send bugreports to taferner@kde.org"; */ -static KCmdLineOptions kmoptions[] = -{ - { "s", 0 , 0 }, - { "subject ", I18N_NOOP("Set subject of message."), 0 }, - { "c", 0 , 0 }, - { "cc
", I18N_NOOP("Send CC: to 'address'."), 0 }, - { "b", 0 , 0 }, - { "bcc
", I18N_NOOP("Send BCC: to 'address'."), 0 }, - { "h", 0 , 0 }, - { "header
", I18N_NOOP("Add 'header' to message."), 0 }, - { "msg ", I18N_NOOP("Read message body from 'file'."), 0 }, - { "body ", I18N_NOOP("Set body of message."), 0 }, - { "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 }, - { "+[address|URL]", I18N_NOOP("Send message to 'address' resp. " - "attach the file the 'URL' points " - "to."), 0 }, -// { "+[file]", I18N_NOOP("Show message from file 'file'."), 0 }, - KCmdLineLastOption -}; - //----------------------------------------------------------------------------- class KMailApplication : public KUniqueApplication @@ -73,13 +51,6 @@ void KMailApplication::commitData(QSessionManager& sm) { int KMailApplication::newInstance() { - QString to, cc, bcc, subj, body; - KURL messageFile = QString::null; - KURL::List attachURLs; - bool mailto = false; - bool checkMail = false; - //bool viewOnly = false; - if (dcopClient()->isSuspended()) { // Try again later. @@ -87,76 +58,8 @@ int KMailApplication::newInstance() return 0; } - // process args: - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->getOption("subject")) - { - mailto = true; - subj = QString::fromLocal8Bit(args->getOption("subject")); - } - - if (args->getOption("cc")) - { - mailto = true; - cc = QString::fromLocal8Bit(args->getOption("cc")); - } - - if (args->getOption("bcc")) - { - mailto = true; - bcc = QString::fromLocal8Bit(args->getOption("bcc")); - } - - if (args->getOption("msg")) - { - mailto = true; - messageFile.setPath( QString::fromLocal8Bit(args->getOption("msg")) ); - } - - if (args->getOption("body")) - { - mailto = true; - body = QString::fromLocal8Bit(args->getOption("body")); - } - - QCStringList attachList = args->getOptionList("attach"); - if (!attachList.isEmpty()) - { - mailto = true; - for ( QCStringList::Iterator it = attachList.begin() ; it != attachList.end() ; ++it ) - if ( !(*it).isEmpty() ) - attachURLs += KURL( QString::fromLocal8Bit( *it ) ); - } - - if (args->isSet("composer")) - mailto = true; - - if (args->isSet("check")) - checkMail = true; - - for(int i= 0; i < args->count(); i++) - { - if (strncasecmp(args->arg(i),"mailto:",7)==0) - to += args->url(i).path() + ", "; - else { - QString tmpArg = QString::fromLocal8Bit( args->arg(i) ); - KURL url( tmpArg ); - if ( url.isValid() ) - attachURLs += url; - else - to += tmpArg + ", "; - } - mailto = true; - } - if ( !to.isEmpty() ) { - // cut off the superfluous trailing ", " - to.truncate( to.length() - 2 ); - } - - args->clear(); - if (!kmkernel->firstInstance() || !kapp->isRestored()) - kmkernel->action (mailto, checkMail, to, cc, bcc, subj, body, messageFile, attachURLs); + kmkernel->handleCommandLine( true ); kmkernel->setFirstInstance(FALSE); return 0; } @@ -171,7 +74,7 @@ int main(int argc, char *argv[]) KMail::AboutData about; KCmdLineArgs::init(argc, argv, &about); - KCmdLineArgs::addCmdLineOptions( kmoptions ); // Add kmail options + KCmdLineArgs::addCmdLineOptions( kmail_options ); // Add kmail options if (!KMailApplication::start()) return 0;