summaryrefslogtreecommitdiffstats
blob: 5868128c9d60ec3f95dd5a14bf0a7d766e4fb363 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Slimber/MenuletController.h>

#include <iostream>
#include <string>

#include <Swiften/Base/foreach.h>

#include <Slimber/Menulet.h>

MenuletController::MenuletController(Menulet* menulet) :
        menulet(menulet), xmppStatus(Offline) {
    menulet->onRestartClicked.connect(boost::ref(onRestartRequested));
    update();
}

MenuletController::~MenuletController() {
}

void MenuletController::setXMPPStatus(const std::string& message, Status status) {
    xmppStatus = status;
    xmppStatusMessage = message;
    update();
}

void MenuletController::setUserNames(const std::vector<std::string>& users) {
    linkLocalUsers = users;
    update();
}

void MenuletController::update() {
    menulet->clear();
    if (linkLocalUsers.empty()) {
        menulet->setIcon("UsersOffline");
        menulet->addItem("No online users");
    }
    else {
        menulet->setIcon("UsersOnline");
        menulet->addItem("Online users:");
        foreach(const std::string& user, linkLocalUsers) {
            menulet->addItem(std::string("  ") + user);
        }
    }
    menulet->addSeparator();
    menulet->addItem(xmppStatusMessage, (xmppStatus == Online ? "Online" : "Offline"));
    menulet->addSeparator();
    menulet->addAboutItem();
    menulet->addSeparator();
    menulet->addRestartItem();
    menulet->addExitItem();
}