/* 
 * This file is part of DesktopBSD, see the README file.
 *
 * Author: Reinhard Pointner <rpointner@desktopbsd.net>
 *         (C) 2006
 *
 * Copyright: BSD, see the COPYING file included in this distribution
 *
 */
#include "packagemgrtray.h"

#include <kiconloader.h>
#include <ksystemtray.h>
#include <kaboutdata.h>
#include <kapplication.h>
#include <kpassivepopup.h>

#include <qstring.h>
#include <qtooltip.h>
#include <qwidget.h>
#include <qpixmap.h>
#include <qapplication.h>

#include <dbsdglobal.h>
#include <dbsdiconloader.h>
#include <packagesettings.h>


PackageMgrTray::PackageMgrTray(QWidget *parent, bool menuEnabled) : KSystemTray(parent) {
	this->menuEnabled = menuEnabled;
	setState(Normal);
	QObject::connect(this, SIGNAL(quitSelected()), qApp, SLOT(quit()));
}


void PackageMgrTray::setTooltip(QString tooltip) {
	QToolTip::add(this, tooltip);
}


void PackageMgrTray::clearTooltip() {
	QToolTip::remove(this);
}


void PackageMgrTray::setState(PkgMgrState state) {
	setPixmap(getIcon(state));
}


QPixmap PackageMgrTray::getIcon(PkgMgrState state) {
	QString icon;

	if (state == Normal)
		icon = "dbsd-pkg";
	else if (state == Notify)
		icon = "dbsd-pkg-notify";
	else if (state == Working)
		icon = "dbsd-pkg-working";

	return DBSDGlobal::getIconLoader()->loadIcon(icon, DBSDIconLoader::Size22x22);
}


void PackageMgrTray::mousePressEvent(QMouseEvent *e) {
	if (menuEnabled) {
		KSystemTray::mousePressEvent(e);
	} else {
		e->accept();
	}
}



void PackageMgrTray::displayMessage(QString message) {
	KApplication *a = KApplication::kApplication();

	KPassivePopup::message(a->caption(), message, getIcon(Notify), this, NULL,
									PackageSettings().getNotificationTimeout());
}

