summaryrefslogblamecommitdiffstats
path: root/src/sessiontreeitem.cpp
blob: 5f3c28ef9b93a31d3d32defc87783bfc84ed4a23 (plain) (tree)
1
2
3
4
5
6
7
8
9
                            
                           
 


                                                             
                                                                                                       
                           
                                                                              
                         
                                                                                         
                          
                                                                               













                                                                                                                


                                                                              
                                                                                









                                                          
                                                          
                              

 







                                                  











                                                                              
#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_NULL:
        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_(NULL), sectionType_(type), text_(typeToName(type)) {
}

SessionTreeItem::SessionTreeItem(const QString& text, SessionTreeItem *parent)
    : parent_(parent), session_(NULL), sectionType_(SECTION_NULL), 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;
}