summaryrefslogtreecommitdiffstats
blob: 69e228518fd575ef858105976019419e89c55983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtVCardJIDField.h"
#include "ui_QtVCardJIDField.h"

#include <Swiften/JID/JID.h>

#include <Swift/QtUI/QtSwiftUtil.h>

namespace Swift {

QtVCardJIDField::QtVCardJIDField(QWidget* parent, bool editable) :
	QWidget(parent),
	ui(new Ui::QtVCardJIDField) {
	ui->setupUi(this);
	connect(ui->lineEditJID, SIGNAL(textChanged(QString)), SLOT(onTextChanged(QString)));
	setEditable(editable);
}

QtVCardJIDField::~QtVCardJIDField() {
	delete ui;
}

bool QtVCardJIDField::isEditable() const {
	return editable;
}

void QtVCardJIDField::setEditable(bool editable) {
	this->editable = editable;
	if (this->editable) {
		ui->lineEditJID->show();
		ui->labelJID->hide();
	} else {
		ui->lineEditJID->hide();
		ui->labelJID->show();
	}
}

bool QtVCardJIDField::isEmpty() const {
	return ui->lineEditJID->text().isEmpty();
}

void QtVCardJIDField::setJID(const QString jid) {
	ui->lineEditJID->setText(jid);
}

QString QtVCardJIDField::getJID() const {
	return ui->lineEditJID->text();
}

void QtVCardJIDField::onTextChanged(const QString& text) {
	if (text.isEmpty()) {
		ui->labelJID->setText("");
	} else {
		if (JID(Q2PSTRING(text)).isValid()) {
			ui->labelJID->setText(QString("<a href=\"xmpp:%1\">%1</a>").arg(text));
		} else {
			ui->labelJID->setText(text);
		}
	}
}

}