From 2a22744ffcea2505b8a0951d4a0791891b99158b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 12 Dec 2010 18:02:01 +0100
Subject: Added menu to switch between 'show nickname' and 'show JID' in roster
 header.

Resolves: #627
Release-Notes: The roster header can now be configured to show the JID instead of the nick.

diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp
index 5cbc40c..ee83f4d 100644
--- a/Swift/QtUI/QtMainWindow.cpp
+++ b/Swift/QtUI/QtMainWindow.cpp
@@ -31,13 +31,13 @@
 
 namespace Swift {
 
-QtMainWindow::QtMainWindow(UIEventStream* uiEventStream) : QWidget(), MainWindow(false) {
+QtMainWindow::QtMainWindow(QtSettingsProvider* settings, UIEventStream* uiEventStream) : QWidget(), MainWindow(false) {
 	uiEventStream_ = uiEventStream;
 	setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
 	QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
 	mainLayout->setContentsMargins(0,0,0,0);
 	mainLayout->setSpacing(0);
-	meView_ = new QtRosterHeader(this);
+	meView_ = new QtRosterHeader(settings, this);
 	mainLayout->addWidget(meView_);
 	connect(meView_, SIGNAL(onChangeStatusRequest(StatusShow::Type, const QString&)), this, SLOT(handleStatusChanged(StatusShow::Type, const QString&)));
 
diff --git a/Swift/QtUI/QtMainWindow.h b/Swift/QtUI/QtMainWindow.h
index 62aafba..f494fd0 100644
--- a/Swift/QtUI/QtMainWindow.h
+++ b/Swift/QtUI/QtMainWindow.h
@@ -31,11 +31,12 @@ namespace Swift {
 	class TreeWidget;
 	class UIEventStream;
 	class QtTabWidget;
+	class QtSettingsProvider;
 
 	class QtMainWindow : public QWidget, public MainWindow {
 		Q_OBJECT
 		public:
-			QtMainWindow(UIEventStream* eventStream);
+			QtMainWindow(QtSettingsProvider*, UIEventStream* eventStream);
 			~QtMainWindow();
 			std::vector<QMenu*> getMenus() {return menus_;}
 			void setMyNick(const String& name);
diff --git a/Swift/QtUI/QtMainWindowFactory.cpp b/Swift/QtUI/QtMainWindowFactory.cpp
index 4405239..8833e03 100644
--- a/Swift/QtUI/QtMainWindowFactory.cpp
+++ b/Swift/QtUI/QtMainWindowFactory.cpp
@@ -9,12 +9,13 @@
 
 namespace Swift {
 
-QtMainWindowFactory::QtMainWindowFactory() {
+QtMainWindowFactory::QtMainWindowFactory(QtSettingsProvider* settings) {
+	settings_ = settings;
 	lastWindow_ = NULL;
 }
 
 MainWindow* QtMainWindowFactory::createMainWindow(UIEventStream* eventStream) {
-	lastWindow_  = new QtMainWindow(eventStream);
+	lastWindow_  = new QtMainWindow(settings_, eventStream);
 	return lastWindow_;
 }
 
diff --git a/Swift/QtUI/QtMainWindowFactory.h b/Swift/QtUI/QtMainWindowFactory.h
index 17eb53c..c6658a9 100644
--- a/Swift/QtUI/QtMainWindowFactory.h
+++ b/Swift/QtUI/QtMainWindowFactory.h
@@ -4,21 +4,21 @@
  * See Documentation/Licenses/GPLv3.txt for more information.
  */
 
-#ifndef SWIFT_QtMainWindowFactory_H
-#define SWIFT_QtMainWindowFactory_H
+#pragma once
 
 #include "Swift/Controllers/UIInterfaces/MainWindowFactory.h"
 
 namespace Swift {
 	class QtTreeWidgetFactory;
+	class QtSettingsProvider;
+
 	class QtMainWindowFactory : public MainWindowFactory{
 		public:
-			QtMainWindowFactory();
+			QtMainWindowFactory(QtSettingsProvider* settings);
 			MainWindow* createMainWindow(UIEventStream* eventStream);
 			MainWindow* getLastCreatedWindow();
 		private:
+			QtSettingsProvider* settings_;
 			MainWindow* lastWindow_;
 	};
 }
-
-#endif
diff --git a/Swift/QtUI/QtNameWidget.cpp b/Swift/QtUI/QtNameWidget.cpp
index d123bad..bbbfe3a 100644
--- a/Swift/QtUI/QtNameWidget.cpp
+++ b/Swift/QtUI/QtNameWidget.cpp
@@ -12,14 +12,17 @@
 #include <QtDebug>
 
 #include <Swift/QtUI/QtElidingLabel.h>
+#include <Swift/QtUI/QtSettingsProvider.h>
 
 namespace Swift {
 
-QtNameWidget::QtNameWidget(QWidget *parent) : QWidget(parent), mode(ShowNick) {
+QtNameWidget::QtNameWidget(QtSettingsProvider* settings, QWidget *parent) : QWidget(parent), settings(settings) {
 	QHBoxLayout* mainLayout = new QHBoxLayout(this);
 	mainLayout->setSpacing(0);
 	mainLayout->setContentsMargins(0,0,0,0);
 
+	mode = settings->getBoolSetting("showNickInRosterHeader", true) ? ShowNick : ShowJID;
+
 	textLabel = new QtElidingLabel(this);
 	QFont font = textLabel->font();
 	font.setBold(true);
@@ -61,6 +64,7 @@ void QtNameWidget::mousePressEvent(QMouseEvent* event) {
 	else {
 		mode = ShowNick;
 	}
+	settings->storeBool("showNickInRosterHeader", mode == ShowNick);
 	updateText();
 }
 
diff --git a/Swift/QtUI/QtNameWidget.h b/Swift/QtUI/QtNameWidget.h
index 52586b7..313108d 100644
--- a/Swift/QtUI/QtNameWidget.h
+++ b/Swift/QtUI/QtNameWidget.h
@@ -10,12 +10,13 @@
 
 namespace Swift {
 	class QtElidingLabel;
+	class QtSettingsProvider;
 
 	class QtNameWidget : public QWidget {
 			Q_OBJECT
 
 		public:
-			QtNameWidget(QWidget *parent);
+			QtNameWidget(QtSettingsProvider* settings, QWidget *parent);
 
 			void setNick(const QString& text);
 			void setJID(const QString& jid);
@@ -30,6 +31,7 @@ namespace Swift {
 				ShowJID,
 			};
 
+			QtSettingsProvider* settings;
 			Mode mode;
 			QtElidingLabel* textLabel;
 			QString jid;
diff --git a/Swift/QtUI/QtRosterHeader.cpp b/Swift/QtUI/QtRosterHeader.cpp
index 4649839..5aeaa5d 100644
--- a/Swift/QtUI/QtRosterHeader.cpp
+++ b/Swift/QtUI/QtRosterHeader.cpp
@@ -18,7 +18,7 @@
 #include <Swift/QtUI/QtNameWidget.h>
 
 namespace Swift {
-QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
+QtRosterHeader::QtRosterHeader(QtSettingsProvider* settings, QWidget* parent) : QWidget(parent) {
 	QHBoxLayout* topLayout = new QHBoxLayout();
 	topLayout->setSpacing(0);
 	topLayout->setContentsMargins(4,4,4,4);
@@ -39,7 +39,7 @@ QtRosterHeader::QtRosterHeader(QWidget* parent) : QWidget(parent) {
 	rightLayout->setContentsMargins(4,0,0,0);
 	topLayout->addLayout(rightLayout);
 
-	nameWidget_ = new QtNameWidget(this);
+	nameWidget_ = new QtNameWidget(settings, this);
 	rightLayout->addWidget(nameWidget_);
 
 
diff --git a/Swift/QtUI/QtRosterHeader.h b/Swift/QtUI/QtRosterHeader.h
index 23e6be0..5634bdf 100644
--- a/Swift/QtUI/QtRosterHeader.h
+++ b/Swift/QtUI/QtRosterHeader.h
@@ -22,11 +22,12 @@ class QHBoxLayout;
 namespace Swift {
 	class QtStatusWidget;
 	class QtNameWidget;
+	class QtSettingsProvider;
 	
 	class QtRosterHeader : public QWidget {
 		Q_OBJECT
 	public:
-		QtRosterHeader(QWidget* parent = NULL);
+		QtRosterHeader(QtSettingsProvider* settings, QWidget* parent = NULL);
 		void setAvatar(const QString& path);
 
 		void setJID(const QString& jid);
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 2890357..04b9d02 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -132,7 +132,7 @@ QtSwift::QtSwift(po::variables_map options) : autoUpdater_(NULL) {
 		systemTrays_.push_back(systemTray);
 		QtLoginWindowFactory* loginWindowFactory = new QtLoginWindowFactory(splitter_, systemTray, settings_);
 		loginWindowFactories_.push_back(loginWindowFactory);
-		QtMainWindowFactory* rosterWindowFactory = new QtMainWindowFactory();
+		QtMainWindowFactory* rosterWindowFactory = new QtMainWindowFactory(settings_);
 		rosterWindowFactories_.push_back(rosterWindowFactory);
 		QtEventWindowFactory* eventWindowFactory = new QtEventWindowFactory(rosterWindowFactory);
 		eventWindowFactories_.push_back(eventWindowFactory);
diff --git a/Swiften/Client/DummyNickManager.h b/Swiften/Client/DummyNickManager.h
index 27a42c0..b746f88 100644
--- a/Swiften/Client/DummyNickManager.h
+++ b/Swiften/Client/DummyNickManager.h
@@ -17,7 +17,7 @@ namespace Swift {
 				return "";
 			}
 
-			void setOwnNick(const String& nick) {
+			void setOwnNick(const String&) {
 			}
 	};
 }
-- 
cgit v0.10.2-6-g49f6