bool SourcesOnRequestEngine::updateSourceEvent(const QString &source)
{
    // Whenever a visualization has requested an update, such as when passing
    // an update interval to DataEngine::connectSource, this method will be called.
    // When this method is called we can assume that:
    //     * the source exists
    //     * it hasn't been updated more frequently than the minimum update interval
    //
    // If not data is set in this method, then the update is skipped for the visualiation
    // and that is just fine.
    //
    // We can also set data for other sources here if we wish, but as with
    // sourceRequestEvent this may not be what the visualization expects. Unlike in
    // sourceRequestEvent, however, this will result in expected behavior: visualizations
    // connected to the sources which have setData called for them will be notified
    // of these changes.
    const int updateCount = containerForSource(source)->data().value("Update Count").toInt() + 1;
    setData(source, "Update Count", updateCount);

    QStandardItemModel *m = qobject_cast<QStandardItemModel *>(modelForSource(source));
    if (m) {
        m->clear();
        m->appendRow(new QStandardItem(QString("Item1, update %1").arg(updateCount)));
        m->appendRow(new QStandardItem(QString("Item2, update %1").arg(updateCount)));
        m->appendRow(new QStandardItem(QString("Item3, update %1").arg(updateCount)));
    }

    // Since we updated the source immediately here, we need to return true so the DataEngine
    // knows to continue with the update notification for visualizations.
    return true;
}
bool AppsEngine::sourceRequestEvent(const QString &name)
{
    if (containerForSource(name)) {
        return true;
    }

    if (name.startsWith(QLatin1String("Apps"))) {
        AppSource *appSource = new AppSource(name, this);
        addSource(appSource);
        return true;
    } else if (name.startsWith(QLatin1String("Categories"))) {
        CategoriesSource *catSource = new CategoriesSource(name, this);
        addSource(catSource);
        return true;
    } else if (name.startsWith(QLatin1String("Groups"))) {
        GroupsSource *grpsSource = new GroupsSource(name, this);
        addSource(grpsSource);
        return true;
    } else if (name.startsWith(QLatin1String("Group"))) {
        GroupSource *grpSource = new GroupSource(name, this);
        addSource(grpSource);
        return true;
    }

    return false;
}
Beispiel #3
0
bool DataContainersEngine::updateSourceEvent(const QString &source)
{
    HttpContainer *container = qobject_cast<HttpContainer *>(containerForSource(source));
    if (container) {
        container->fetchUrl();
    }

    // HttpContainer is asynchronous, so the data hasn't actually been updated yet. So
    // we return false here to let the DataEngine know that nothing has changed quite yet.
    return false;
}
Plasma::Service *AppsEngine::serviceForSource(const QString &name)
{
    if (name == "Groups") {
        return Plasma::DataEngine::serviceForSource(name);
    }

    AppSource *source = dynamic_cast<AppSource*>(containerForSource(name));
    // if source does not exist, return null service
    if (!source) {
        return Plasma::DataEngine::serviceForSource(name);
    }

    // if source is a group of apps, return real service
    Plasma::Service *service = new AppService(source);
    service->setParent(this);
    return service;
}
Plasma::Service* KimpanelEngine::serviceForSource(const QString& source)
{
    if (source == INPUTPANEL_SOURCE_NAME) {
        KimpanelInputPanelContainer* container = qobject_cast< KimpanelInputPanelContainer* >(containerForSource(source));
        if (container)
            return container->service(this);
    } else if (source == STATUSBAR_SOURCE_NAME) {
        KimpanelStatusBarContainer* container = qobject_cast< KimpanelStatusBarContainer* >(containerForSource(source));
        if (container)
            return container->service(this);
    }

    return Plasma::DataEngine::serviceForSource(source);
}
uint NotificationsEngine::Notify(const QString &app_name, uint replaces_id,
                                 const QString &app_icon, const QString &summary, const QString &body,
                                 const QStringList &actions, const QVariantMap &hints, int timeout)
{
    uint partOf = 0;

    if (m_activeNotifications.values().contains(app_name + summary)) {
        // cut off the "notification " from the source name
        partOf = m_activeNotifications.key(app_name + summary).mid(13).toUInt();

    }

    qDebug() << "Currrent active notifications:" << m_activeNotifications;
    qDebug() << "Guessing partOf as:" << partOf;
    qDebug() << " New Notification: " << summary << body << timeout << "& Part of:" << partOf;
    QString _body;

    if (partOf > 0) {
        const QString source = QString("notification %1").arg(partOf);
        Plasma::DataContainer *container = containerForSource(source);
        if (container) {
            // append the body text
            _body = container->data()["body"].toString();
            if (_body != body) {
                _body.append("\n").append(body);
            } else {
                _body = body;
            }

            // remove the old notification and replace it with the new one
            // TODO: maybe just update the current notification?
            CloseNotification(partOf);
        }
    }

    uint id = 0;
    id = replaces_id ? replaces_id : m_nextId++;

    QString appname_str = app_name;
    if (appname_str.isEmpty()) {
        appname_str = i18n("Unknown Application");
    }

    bool isPersistent = timeout == 0;

    const int AVERAGE_WORD_LENGTH = 6;
    const int WORD_PER_MINUTE = 250;
    int count = summary.length() + body.length();
    timeout = 60000 * count / AVERAGE_WORD_LENGTH / WORD_PER_MINUTE;

    // Add two seconds for the user to notice the notification, and ensure
    // it last at least five seconds, otherwise all the user see is a
    // flash
    timeout = 2000 + qMax(timeout, 3000);

    const QString source = QString("notification %1").arg(id);

    Plasma::DataEngine::Data notificationData;
    notificationData.insert("id", QString::number(id));
    notificationData.insert("appName", appname_str);
    notificationData.insert("appIcon", app_icon);
    notificationData.insert("summary", summary);
    notificationData.insert("body", partOf == 0 ? body : _body);
    notificationData.insert("actions", actions);
    notificationData.insert("isPersistent", isPersistent);
    notificationData.insert("expireTimeout", timeout);

    QString appRealName;
    bool configurable = false;
    if (hints.contains("x-kde-appname")) {
        appRealName = hints["x-kde-appname"].toString();
        configurable = true;
    }
    notificationData.insert("appRealName", appRealName);
    notificationData.insert("configurable", configurable);

    QImage image;
    if (hints.contains("image_data")) {
        QDBusArgument arg = hints["image_data"].value<QDBusArgument>();
        image = decodeNotificationSpecImageHint(arg);
    } else if (hints.contains("image_path")) {
        QString path = findImageForSpecImagePath(hints["image_path"].toString());
        if (!path.isEmpty()) {
            image.load(path);
        }
    } else if (hints.contains("icon_data")) {
        // This hint was in use in version 1.0 of the spec but has been
        // replaced by "image_data" in version 1.1. We need to support it for
        // users of the 1.0 version of the spec.
        QDBusArgument arg = hints["icon_data"].value<QDBusArgument>();
        image = decodeNotificationSpecImageHint(arg);
    }
    notificationData.insert("image", image);

    if (hints.contains("urgency")) {
        notificationData.insert("urgency", hints["urgency"].toInt());
    }

    setData(source, notificationData);

    m_activeNotifications.insert(source, app_name + summary);

    return id;
}
uint NotificationsEngine::Notify(const QString &app_name, uint replaces_id,
                                 const QString &app_icon, const QString &summary, const QString &body,
                                 const QStringList &actions, const QVariantMap &hints, int timeout)
{
    uint id = 0;
    id = replaces_id ? replaces_id : m_nextId++;

    QString appname_str = app_name;
    if (appname_str.isEmpty()) {
        appname_str = i18n("Unknown Application");
    }

    if (timeout == -1) {
        const int AVERAGE_WORD_LENGTH = 6;
        const int WORD_PER_MINUTE = 250;
        int count = summary.length() + body.length();
        timeout = 60000 * count / AVERAGE_WORD_LENGTH / WORD_PER_MINUTE;

        // Add two seconds for the user to notice the notification, and ensure
        // it last at least five seconds, otherwise all the user see is a
        // flash
        timeout = 2000 + qMax(timeout, 3000);
    }

    const QString source = QString("notification %1").arg(id);
    if (replaces_id) {
        Plasma::DataContainer *container = containerForSource(source);
        if (container && container->data()["expireTimeout"].toInt() != timeout) {
            int timerId = m_sourceTimers.value(source);
            killTimer(timerId);
            m_sourceTimers.remove(source);
            m_timeouts.remove(timerId);
        }
    }

    Plasma::DataEngine::Data notificationData;
    notificationData.insert("id", QString::number(id));
    notificationData.insert("appName", appname_str);
    notificationData.insert("appIcon", app_icon);
    notificationData.insert("summary", summary);
    notificationData.insert("body", body);
    notificationData.insert("actions", actions);
    notificationData.insert("expireTimeout", timeout);

    QImage image;
    if (hints.contains("image_data")) {
        QDBusArgument arg = hints["image_data"].value<QDBusArgument>();
        image = decodeNotificationSpecImageHint(arg);
    } else if (hints.contains("image_path")) {
        QString path = findImageForSpecImagePath(hints["image_path"].toString());
        if (!path.isEmpty()) {
            image.load(path);
        }
    } else if (hints.contains("icon_data")) {
        // This hint was in use in version 1.0 of the spec but has been
        // replaced by "image_data" in version 1.1. We need to support it for
        // users of the 1.0 version of the spec.
        QDBusArgument arg = hints["icon_data"].value<QDBusArgument>();
        image = decodeNotificationSpecImageHint(arg);
    }
    notificationData.insert("image", image);

    if (hints.contains("urgency")) {
        notificationData.insert("urgency", hints["urgency"].toInt());
    }

    setData(source, notificationData );

    if (timeout) {
        int timerId = startTimer(timeout);
        m_sourceTimers.insert(source, timerId);
        m_timeouts.insert(timerId, source);
    }

    return id;
}