From 806157b94327f8c41f5e4402a73608cd9e5225b0 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Wed, 16 Oct 2013 20:41:41 +0200
Subject: VCard: Remove name fields from field menu. They're always displayed
 in edit mode now.

Change-Id: I9ee5faae53e9300300e01a1782b51645399f1669
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.

diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
index 4ad12c8..aaea194 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.cpp
@@ -33,17 +33,10 @@ QtVCardPhotoAndNameFields::QtVCardPhotoAndNameFields(QWidget* parent) :
 	ui->lineEditSUFFIX->setPlaceholderText(tr("Suffix"));
 #endif
 
-	addFieldMenu = new QMenu("Name", this);
-
-	actionSignalMapper = new QSignalMapper(this);
-
-	connect(actionSignalMapper, SIGNAL(mapped(const QString &)), this, SLOT(showField(const QString &)));
-	prepareAddFieldMenu();
 }
 
 QtVCardPhotoAndNameFields::~QtVCardPhotoAndNameFields() {
 	delete ui;
-	delete actionSignalMapper;
 }
 
 bool QtVCardPhotoAndNameFields::isEditable() const {
@@ -75,12 +68,6 @@ void QtVCardPhotoAndNameFields::setEditable(bool editable) {
 	fullname << ui->lineEditFAMILY->text() << ui->lineEditSUFFIX->text();
 	fullname = fullname.filter(".*\\S.*");
 	ui->labelFULLNAME->setText(fullname.join(" "));
-
-	prepareAddFieldMenu();
-}
-
-QMenu* QtVCardPhotoAndNameFields::getAddFieldMenu() const {
-	return addFieldMenu;
 }
 
 void QtVCardPhotoAndNameFields::setAvatar(const ByteArray &data, const std::string &type) {
@@ -151,31 +138,4 @@ QString QtVCardPhotoAndNameFields::getSuffix() const {
 	return ui->lineEditSUFFIX->text();
 }
 
-void QtVCardPhotoAndNameFields::prepareAddFieldMenu() {
-	foreach(QAction* action, addFieldMenu->actions()) {
-		actionSignalMapper->removeMappings(action);
-	}
-
-	addFieldMenu->clear();
-	foreach(QObject* obj, children()) {
-		QLineEdit* lineEdit = 0;
-		if (!(lineEdit = dynamic_cast<QLineEdit*>(obj))) continue;
-		if (lineEdit->isHidden()) {
-#if QT_VERSION >= 0x040700
-			QAction* action = addFieldMenu->addAction(QString("Add ") + lineEdit->placeholderText(), actionSignalMapper, SLOT(map()));
-#else
-			QAction* action = addFieldMenu->addAction(QString("Add ") + lineEdit->toolTip(), actionSignalMapper, SLOT(map()));
-#endif
-			actionSignalMapper->setMapping(action, lineEdit->objectName());
-		}
-	}
-}
-
-void QtVCardPhotoAndNameFields::showField(const QString& widgetName) {
-	QLineEdit* lineEditToShow = findChild<QLineEdit*>(widgetName);
-	if (lineEditToShow) lineEditToShow->show();
-
-	prepareAddFieldMenu();
-}
-
 }
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
index f279701..6a5ae46 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardPhotoAndNameFields.h
@@ -7,8 +7,8 @@
 #pragma once
 
 #include <QMenu>
-#include <QSignalMapper>
 #include <QWidget>
+
 #include <Swiften/Base/ByteArray.h>
 
 namespace Ui {
@@ -29,8 +29,6 @@ namespace Swift {
 			bool isEditable() const;
 			void setEditable(bool);
 
-			QMenu* getAddFieldMenu() const;
-
 			void setAvatar(const ByteArray& data, const std::string& type);
 			ByteArray getAvatarData() const;
 			std::string getAvatarType() const;
@@ -56,18 +54,9 @@ namespace Swift {
 			void setSuffix(const QString suffix);
 			QString getSuffix() const;
 
-		public slots:
-			void showField(const QString& widgetName);
-
-		private:
-			void prepareAddFieldMenu();
-
 		private:
 			Ui::QtVCardPhotoAndNameFields* ui;
 			bool editable;
-
-			QMenu* addFieldMenu;
-			QSignalMapper* actionSignalMapper;
 	};
 
 }
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
index 1c80fa4..160482e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
@@ -4,30 +4,27 @@
  * See Documentation/Licenses/BSD-simplified.txt for more information.
  */
 
-#include "QtVCardWidget.h"
-#include "ui_QtVCardWidget.h"
+#include <Swift/QtUI/QtVCardWidget/QtVCardWidget.h>
 
 #include <QDebug>
 #include <QLineEdit>
 #include <QMenu>
 
-#include "QtVCardAddressField.h"
-#include "QtVCardAddressLabelField.h"
-#include "QtVCardBirthdayField.h"
-#include "QtVCardDescriptionField.h"
-#include "QtVCardGeneralField.h"
-#include "QtVCardInternetEMailField.h"
-#include "QtVCardJIDField.h"
-#include "QtVCardOrganizationField.h"
-#include "QtVCardRoleField.h"
-#include "QtVCardTelephoneField.h"
-#include "QtVCardTitleField.h"
-#include "QtVCardURLField.h"
-
+#include <Swift/QtUI/QtVCardWidget/ui_QtVCardWidget.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardAddressField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardBirthdayField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardJIDField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardOrganizationField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardRoleField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardTelephoneField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardTitleField.h>
+#include <Swift/QtUI/QtVCardWidget/QtVCardURLField.h>
 #include <Swift/QtUI/QtSwiftUtil.h>
 
-#include <Swiften/Base/Log.h>
-
 namespace Swift {
 
 QtVCardWidget::QtVCardWidget(QWidget* parent) :
@@ -42,7 +39,6 @@ QtVCardWidget::QtVCardWidget(QWidget* parent) :
 	ui->cardFields->setColumnStretch(4,2);
 	menu = new QMenu(this);
 
-	menu->addMenu(ui->photoAndName->getAddFieldMenu());
 	ui->toolButton->setMenu(menu);
 
 	addFieldType(menu, boost::make_shared<QtVCardInternetEMailField::FieldInfo>());
@@ -89,7 +85,6 @@ void QtVCardWidget::setEditable(bool editable) {
 }
 
 void QtVCardWidget::setVCard(VCard::ref vcard) {
-	SWIFT_LOG(debug) << std::endl;
 	clearFields();
 	this->vcard = vcard;
 	ui->photoAndName->setFormattedName(P2QSTRING(vcard->getFullName()));
@@ -184,7 +179,6 @@ void QtVCardWidget::setVCard(VCard::ref vcard) {
 }
 
 VCard::ref QtVCardWidget::getVCard() {
-	SWIFT_LOG(debug) << std::endl;
 	clearEmptyFields();
 	vcard->setFullName(Q2PSTRING(ui->photoAndName->getFormattedName()));
 	vcard->setNickname(Q2PSTRING(ui->photoAndName->getNickname()));
-- 
cgit v0.10.2-6-g49f6