summaryrefslogtreecommitdiffstats
path: root/src/sessiontreeitem.cpp
blob: c95b5cfce2f019b65b7feccde694e5574230fa6a (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "sessiontreeitem.h"
#include <QCoreApplication>

QString SessionTreeItem::typeToName(const SectionType type) {
    switch (type) {
    case SECTION_FOR_LOCATION:
        return QCoreApplication::instance()->translate("Dialog", "Working environments for this room");
    case SECTION_TEMPLATES:
        return QCoreApplication::instance()->translate("Dialog", "Templates");
    case SECTION_GENERIC:
        return QCoreApplication::instance()->translate("Dialog", "Working environments");
    case SECTION_XSESSION:
        return QCoreApplication::instance()->translate("Dialog", "X-Sessions");
    case SECTION_nullptr:
        return "<null>";
    default:
        break;
    }
    return "Missing case for SectionType";
}

SessionTreeItem::SessionTreeItem(const Session* session, SessionTreeItem *parent)
    : parent_(parent), session_(session), sectionType_(session->section()), text_(session->shortDescription()) {
}

SessionTreeItem::SessionTreeItem(const SectionType type, SessionTreeItem *parent)
    : parent_(parent), session_(nullptr), sectionType_(type), text_(typeToName(type)) {
}

SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent)
    : parent_(parent), session_(nullptr), sectionType_(SECTION_nullptr), text_(text) {
}

SessionTreeItem::~SessionTreeItem() {
    qDeleteAll(children_);
}

void SessionTreeItem::appendChild(SessionTreeItem *item) {
    children_.append(item);
}

void SessionTreeItem::removeChild(SessionTreeItem *item) {
    children_.removeOne(item);
}

SessionTreeItem *SessionTreeItem::child(int row) {
    return children_.value(row);
}

int SessionTreeItem::childCount() const {
    return children_.count();
}

SessionTreeItem *SessionTreeItem::parent() {
    return parent_;
}

int SessionTreeItem::row() const {
    if (parent_) {
        return parent_->children_.indexOf(const_cast<SessionTreeItem*>(this));
    }

    return 0;
}