summaryrefslogtreecommitdiffstats
blob: 123e6a3b974e5e0718bdee74a20c53142fd7a8f2 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include "Swift/QtUI/QtSystemTray.h"

#include <QIcon>
#include <QPixmap>
#include <QResource>

namespace Swift {
QtSystemTray::QtSystemTray() : QObject(), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
	trayIcon_ = new QSystemTrayIcon(offlineIcon_);
	trayIcon_->setToolTip("Swift");
	connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
	connect(&throbberMovie_, SIGNAL(frameChanged(int)), this, SLOT(handleThrobberFrameChanged(int)));
	trayIcon_->show();
}

QtSystemTray::~QtSystemTray() {
	delete trayIcon_;
}

void QtSystemTray::setUnreadMessages(bool some) {
	unreadMessages_ = some;
	updateStatusIcon();
}

void QtSystemTray::handleThrobberFrameChanged(int /*frameNumber*/) {
	trayIcon_->setIcon(QIcon(throbberMovie_.currentPixmap()));
}

void QtSystemTray::setConnecting() {
	connecting_ = true;
	updateStatusIcon();
}

void QtSystemTray::handleIconActivated(QSystemTrayIcon::ActivationReason reason) {
	if (reason == QSystemTrayIcon::Trigger) {
		emit clicked();
	}
}
void QtSystemTray::setStatusType(StatusShow::Type type) {
	connecting_ = false;
	statusType_ = type;
	updateStatusIcon();
}

void QtSystemTray::updateStatusIcon() {
	throbberMovie_.stop();
	if (unreadMessages_) {
		trayIcon_->setIcon(newMessageIcon_);
	} else if (connecting_) {
		throbberMovie_.start();
	}	else {
		switch (statusType_) {
			case StatusShow::Online : trayIcon_->setIcon(onlineIcon_);break;
			case StatusShow::FFC : trayIcon_->setIcon(onlineIcon_);break;
			case StatusShow::Away : trayIcon_->setIcon(awayIcon_);break;
			case StatusShow::XA : trayIcon_->setIcon(awayIcon_);break;
			case StatusShow::DND : trayIcon_->setIcon(dndIcon_);break;
			case StatusShow::None : trayIcon_->setIcon(offlineIcon_);break;
		}
	}
}

}