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
wilder-work
David Faure 23 years ago
parent 2c5b0ca760
commit e4e4e1bf3e
  1. 10
      kmailIface.h
  2. 30
      kmail_options.h
  3. 100
      kmkernel.cpp
  4. 2
      kmkernel.h
  5. 103
      main.cpp

@ -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

@ -0,0 +1,30 @@
/* -*- mode: C++; c-file-style: "gnu" -*- */
#ifndef KMAIL_OPTIONS_H
#define KMAIL_OPTIONS_H
#include <kcmdlineargs.h>
#include <klocale.h>
KCmdLineOptions kmail_options[] =
{
{ "s", 0 , 0 },
{ "subject <subject>", I18N_NOOP("Set subject of message."), 0 },
{ "c", 0 , 0 },
{ "cc <address>", I18N_NOOP("Send CC: to 'address'."), 0 },
{ "b", 0 , 0 },
{ "bcc <address>", I18N_NOOP("Send BCC: to 'address'."), 0 },
{ "h", 0 , 0 },
{ "header <header>", I18N_NOOP("Add 'header' to message."), 0 },
{ "msg <file>", I18N_NOOP("Read message body from 'file'."), 0 },
{ "body <text>", I18N_NOOP("Set body of message."), 0 },
{ "attach <url>", 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

@ -66,6 +66,7 @@ using KMail::FolderIface;
#include <X11/Xlib.h>
#include <fixx11h.h>
#include <kcmdlineargs.h>
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);
}

@ -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. */

@ -9,7 +9,7 @@
#include <knotifyclient.h>
#include <dcopclient.h>
#include "kmkernel.h" //control center
#include <kcmdlineargs.h>
#include "kmail_options.h"
#include <qtimer.h>
#undef Status // stupid X headers
@ -31,28 +31,6 @@
"Please send bugreports to taferner@kde.org";
*/
static KCmdLineOptions kmoptions[] =
{
{ "s", 0 , 0 },
{ "subject <subject>", I18N_NOOP("Set subject of message."), 0 },
{ "c", 0 , 0 },
{ "cc <address>", I18N_NOOP("Send CC: to 'address'."), 0 },
{ "b", 0 , 0 },
{ "bcc <address>", I18N_NOOP("Send BCC: to 'address'."), 0 },
{ "h", 0 , 0 },
{ "header <header>", I18N_NOOP("Add 'header' to message."), 0 },
{ "msg <file>", I18N_NOOP("Read message body from 'file'."), 0 },
{ "body <text>", I18N_NOOP("Set body of message."), 0 },
{ "attach <url>", 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;

Loading…
Cancel
Save