summaryrefslogtreecommitdiff
path: root/src/lib/xdgautostart.cpp
blob: bd712617f064ab071184c78243d77b496686bdb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "xdgautostart.h"
#include "xdgbasedir.h"
#include "xdgentry.h"
#include "debug.h"

xdg::AutoStart::AutoStart(QObject *parent)
    : QObject{parent}
{
    qCDebug(AUTO_START) << "Create Auto start";
    QStringList configdirs = xdg::configDirs();
    for (auto dir = configdirs.rbegin(); dir != configdirs.rend(); ++dir)
    {
        m_entries.addDirectory(*dir + "/autostart");
    }
    m_entries.addDirectory(xdg::configHome() + "/autostart");
}

void xdg::AutoStart::start(QString key, QString value)
{
    qCDebug(AUTO_START) << "Start " << key << value;
    for(xdg::Entry *entry: m_entries.getEntries())
    {
        if((!value.isNull()) && (!key.isNull()))
        {
            QString c = entry->data(key);
            if(c.trimmed().toLower() == value.trimmed().toLower())
            {
                qCDebug(AUTO_START) << "Start app " << entry->appId() << "with" << key << value;
                entry->start(QStringList());
            }
        }
        else
        {
            qCDebug(AUTO_START) << "Start app " << entry->appId();
            entry->start(QStringList());
        }
    }
}