Example #1
0
/******************************************************************************
* DCOP call to add an application to the list of client applications,
* and add it to the config file.
* N.B. This method must not return a bool because DCOPClient::call() can cause
*      a hang if the daemon happens to send a notification to KAlarm at the
*      same time as KAlarm calls this DCCOP method.
*/
void AlarmDaemon::registerApp(const QCString &appName, const QString &appTitle,
                              const QCString &dcopObject, const QString &calendarUrl,
                              bool startClient)
{
    kdDebug(5900) << "AlarmDaemon::registerApp(" << appName << ", " << appTitle << ", "
                  <<  dcopObject << ", " << startClient << ")" << endl;
    KAlarmd::RegisterResult result;
    if(appName.isEmpty())
        result = KAlarmd::FAILURE;
    else if(startClient  &&  KStandardDirs::findExe(appName).isNull())
    {
        kdError() << "AlarmDaemon::registerApp(): app not found" << endl;
        result = KAlarmd::NOT_FOUND;
    }
    else
    {
        ADCalendar *keepCal = 0;
        ClientInfo *client = ClientInfo::get(appName);
        if(client)
        {
            // The application is already a client.
            // If it's the same calendar file, don't delete its calendar object.
            if(client->calendar()  &&  client->calendar()->urlString() == calendarUrl)
            {
                keepCal = client->calendar();
                client->detachCalendar();
            }
            ClientInfo::remove(appName);    // this deletes the calendar if not detached
        }

        if(keepCal)
            client = new ClientInfo(appName, appTitle, dcopObject, keepCal, startClient);
        else
            client = new ClientInfo(appName, appTitle, dcopObject, calendarUrl, startClient);
        client->calendar()->setUnregistered(false);
        ADConfigData::writeClient(appName, client);

        ADConfigData::enableAutoStart(true);
        setTimerStatus();
        notifyCalStatus(client->calendar());
        result = KAlarmd::SUCCESS;
    }

    // Notify the client of whether the call succeeded.
    AlarmGuiIface_stub stub(appName, dcopObject);
    stub.registered(false, result, DAEMON_VERSION_NUM);
    kdDebug(5900) << "AlarmDaemon::registerApp() -> " << result << endl;
}