From fe1c7fc8a8b1eb29f92795d760bbfc8f3cf618e8 Mon Sep 17 00:00:00 2001
From: Kevin Smith <git@kismith.co.uk>
Date: Tue, 25 May 2010 17:14:50 +0100
Subject: Add status annotation for each of the status types when changing
 status.

Resolves: #383

diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp
index e5a4eff..6281b52 100644
--- a/Swift/QtUI/QtStatusWidget.cpp
+++ b/Swift/QtUI/QtStatusWidget.cpp
@@ -20,6 +20,7 @@
 
 #include "Swift/QtUI/QtElidingLabel.h"
 #include "Swift/QtUI/QtLineEdit.h"
+#include "Swift/QtUI/QtSwiftUtil.h"
 
 namespace Swift {
 
@@ -77,6 +78,12 @@ QtStatusWidget::QtStatusWidget(QWidget *parent) : QWidget(parent), editCursor_(Q
 	menu_->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint );
 	menu_->setAlternatingRowColors(true);
 	menu_->setFocusProxy(statusEdit_);
+	menu_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+	menu_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+	QSizePolicy policy(menu_->sizePolicy());
+	policy.setVerticalPolicy(QSizePolicy::Expanding);
+	menu_->setSizePolicy(policy);
+
 
 	connect(menu_, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleItemClicked(QListWidgetItem*)));
 
@@ -116,6 +123,11 @@ void QtStatusWidget::generateList() {
 		item->setIcon(icons_[type]);
 		item->setData(Qt::UserRole, QVariant(type));
 	}
+	foreach (StatusShow::Type type, icons_.keys()) {
+		QListWidgetItem* item = new QListWidgetItem(P2QSTRING(StatusShow::typeToFriendlyName(type)), menu_);
+		item->setIcon(icons_[type]);
+		item->setData(Qt::UserRole, QVariant(type));
+	}
 }
 
 
@@ -131,13 +143,12 @@ void QtStatusWidget::handleClicked() {
 	if (x + width > screenWidth) {
 		x = screenWidth - width;
 	}
+	generateList();
+
+	height = menu_->sizeHintForRow(0) * menu_->count();
 	menu_->setGeometry(x, y, width, height);
 	menu_->setMaximumWidth(width);
-	QSizePolicy policy(menu_->sizePolicy());
-	policy.setVerticalPolicy(QSizePolicy::Expanding);
-	menu_->setSizePolicy(policy);
-	menu_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-	generateList();
+
 
 	menu_->show();
 	activateWindow();
@@ -174,6 +185,8 @@ StatusShow::Type QtStatusWidget::getSelectedStatusShow() {
 void QtStatusWidget::handleItemClicked(QListWidgetItem* item) {
 	editing_ = false;
 	selectedStatusType_ = (StatusShow::Type)(item->data(Qt::UserRole).toInt());
+	newStatusText_ = item->data(Qt::DisplayRole).toString();
+	statusEdit_->setText(newStatusText_);
 	handleEditComplete();
 }
 
diff --git a/Swiften/Elements/StatusShow.h b/Swiften/Elements/StatusShow.h
index 0501bf6..747ddf1 100644
--- a/Swiften/Elements/StatusShow.h
+++ b/Swiften/Elements/StatusShow.h
@@ -8,6 +8,7 @@
 #define SWIFTEN_StatusShow_H
 
 #include "Swiften/Elements/Payload.h"
+#include "Swiften/Base/String.h"
 
 namespace Swift {
 	class StatusShow : public Payload {
@@ -25,6 +26,18 @@ namespace Swift {
 				return type_;
 			}
 
+			static String typeToFriendlyName(Type type) {
+				switch (type) {
+				case Online: return "Available";
+				case FFC: return "Available";
+				case Away: return "Away";
+				case XA: return "Away";
+				case DND: return "Busy";
+				case None: return "Offline";
+				}
+				return "Unknown";
+			}
+
 		private:
 			Type type_;
 	};
-- 
cgit v0.10.2-6-g49f6