summaryrefslogtreecommitdiffstats
blob: 078275b028037aa152b9b6bc05fe3026774d1ffb (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
/*
 * Copyright (c) 2010 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include "Slimber/MenuletController.h"

#include <Swiften/Base/foreach.h>
#include <string>
#include "Slimber/Menulet.h"

#include <iostream>

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();
}