#include "BuddyHolder.h"

BuddyHolder::BuddyHolder(ChatBuddy * buddy) {

	nameItem_ = 0;
	msgItem_ = 0;

	this->buddy_ = buddy;

	unselectedStyle = QString("#BuddyFrame { border: 2px solid rgb(78, 115, 71); background: rgb(153, 153, 153); color: #000000; } #BuddyFrame:hover{ border: 2px solid rgb(39, 57, 35); }");
	selectedStyle = QString("#BuddyFrame { border: 2px solid rgb(78, 115, 71); background: rgb(70, 70, 70); color: #eeeeee; } #BuddyFrame:hover{ border: 2px solid rgb(39, 57, 35); }");

	setUnselected();

	unreadMessagesCount_ = 0;
	setTitle();		
}

int BuddyHolder::getBuddyId() {
	return buddy_->getId();
}

ChatBuddy * BuddyHolder::getBuddy() {
	return buddy_;
}

BuddyHolder::~BuddyHolder() {
	// Do not delete buddy, it is shared
	// Do not delete table items, they are shared
}

void BuddyHolder::setTitle() {
	if (nameItem_ != NULL) {
		nameItem_->setText(buddy_->getName().c_str());
	}

	if (msgItem_ != NULL) {
		msgItem_->setText(QString::number(unreadMessagesCount_));
	}
}

void BuddyHolder::addUnreadMessage() {
	unreadMessagesCount_++;
	setTitle();
}

void BuddyHolder::readAllMessages() {
	unreadMessagesCount_ = 0;
	setTitle();
}

void BuddyHolder::setNameItem(QTableWidgetItem * item) {
	nameItem_ = item;

	setTitle();
}

void BuddyHolder::setMsgItem(QTableWidgetItem * item) {
	msgItem_ = item;

	setTitle();
}

void BuddyHolder::setUnselected() {
}

void BuddyHolder::setSelected() {
}