[Kde-pim] Running KMail and calling via D-Bus

David Jarvie djarvie at kde.org
Sun Aug 2 12:30:31 BST 2009


Can anybody help resolve this D-Bus problem with KMail?

KAlarm has functions to invoke KMail and issue a D-Bus call to show a mail. 
The problem is that if KMail isn't already running, the D-Bus call doesn't 
work when called immediately after starting up KMail, since the relevant D-Bus 
interface is not immediately available. I've experimented with various tweaks, 
and compared the code to other places in kdepim, but still can't think of any 
other way of doing it except to introduce timer-based calls to wait for the D-
Bus interface to become active. Yet other applications (KOrganizer etc) don't 
seem to have this problem (or do they just ignore it?).

The relevant code is below. If kmail wasn't running before this is called, it 
always returns with the "KMail not yet available" debug message. If called 
when kmail is already running, it succeeds.

if (KToolInvocation::startServiceByDesktopName("kmail"))
{
     kError() << "Couldn't start kmail";
     return false;
}
org::kde::kmail::kmail kmail("org.kde.kmail", "/KMail",
                                               QDBusConnection::sessionBus());
if (!kmail.isValid())
{
    kDebug() << "KMail not yet available:" << kmail.lastError().message();
    return false;
}
QDBusReply<bool> reply = kmail.showMail(serialNumber, QString());
if (!reply.isValid())
    kError() << "kmail D-Bus call failed:" << reply.error().message();
else if (!reply.value())
    kDebug() << "function error";

-- 
David Jarvie.
KDE developer.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list