Indicators in KDE

Using libindicate-qt

Aurélien Gâteau

Canonical, Desktop Experience Team

What you need

CMake stuff

Find indicate-qt on the machine:

find_package(PkgConfig REQUIRED)
pkg_check_modules(INDICATEQT REQUIRED indicate-qt)

Use it:

include_directories(${INDICATEQT_INCLUDE_DIRS})
link_directories(${INDICATEQT_LIBRARY_DIRS})

target_link_libraries(myapp ...
                      ${INDICATEQT_LIBRARIES})

Creating a server

#include <KGlobal>
#include <qindicateserver.h>

void MyApp::createIndicateServer() {
    m_indicateServer = QIndicate::Server::defaultInstance();
    m_indicateServer->setType("message.irc");
    QString appName = KGlobal::mainComponent().componentName();
    KService::Ptr service = KService::serviceByDesktopName(appName);
    m_indicateServer->setDesktopFile(service->entryPath());
    m_indicateServer->show();
}

Handling clicks on the server 1/2

void MyApp::createIndicateServer() {
    m_indicateServer = QIndicate::Server::defaultInstance();
    m_indicateServer->setType("message.irc");
    QString appName = KGlobal::mainComponent().componentName();
    KService::Ptr service = KService::serviceByDesktopName(appName);
    m_indicateServer->setDesktopFile(service->entryPath());

»    connect(m_indicateServer, SIGNAL(serverDisplay()),
»        SLOT(showMainWindow()));

    m_indicateServer->show();
}

Handling clicks on the server 2/2

#include <KWindowSystem>

void MyApp::showMainWindow() {
    m_mainWindow->show();
    KWindowSystem::forceActiveWindow(m_mainWindow->winId());
}

Creating an indicator

void MyApp::addIndicator(const QString& text) {
    QIndicate::Indicator* indicator =
        new QIndicate::QIndicator(m_indicateServer);

    indicator->setNameProperty("#kubuntu-devel");
    indicator->setTimeProperty(QDateTime::currentDateTime());
    indicator->setDrawAttentionProperty(true);
    indicator->show();
    // Insert code to keep track of the indicator here
}

Handling clicks on the indicator 1/2

void MyApp::addIndicator(const QString& text) {
    QIndicate::Indicator* indicator =
        new QIndicate::QIndicator(m_indicateServer);

    indicator->setNameProperty("#kubuntu-devel");
    indicator->setTimeProperty(QDateTime::currentDateTime());
    indicator->setDrawAttentionProperty(true);
»    connect(indicator, SIGNAL(display(QIndicate::Indicator*)),
»        SLOT(displayIndicator(QIndicate::Indicator*)));
    indicator->show();
    // Insert code to keep track of the indicator here
}

Handling clicks on the indicator 2/2

void MyApp::displayIndicator(QIndicate::Indicator* indicator) {
    showMainWindow();
    // Do relevant action for this indicator

    delete indicator; // Or indicator->hide();
}

That's it!

Questions?