summaryrefslogtreecommitdiffstats
blob: 9526d63e28903b97c0b6d269d54d29156a373279 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (c) 2011-2014 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtProfileWindow.h"
#include "ui_QtProfileWindow.h"

#include <QCloseEvent>
#include <QMovie>
#include <QShortcut>
#include <QTextDocument>

#include <Swift/QtUI/QtSwiftUtil.h>
#include <Swift/QtUI/QtUtilities.h>

namespace Swift {

QtProfileWindow::QtProfileWindow() :
	QWidget(),
	ui(new Ui::QtProfileWindow) {
	ui->setupUi(this);

	ui->statusLabel->setText(tr("Retrieving profile information for this user."));
	ui->statusLabel->setVisible(false);

	ui->emptyLabel->setText(tr("No profile information is available for this user."));
	ui->emptyLabel->setVisible(false);

	new QShortcut(QKeySequence::Close, this, SLOT(close()));
	ui->throbberLabel->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
	connect(ui->savePushButton, SIGNAL(clicked()), SLOT(handleSave()));
	setEditable(false);
	setAttribute(Qt::WA_DeleteOnClose);
}

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

void QtProfileWindow::setJID(const JID& jid) {
	this->jid = jid;
	updateTitle();
}

void QtProfileWindow::setVCard(VCard::ref vcard) {
	ui->vcard->setVCard(vcard);
	if (vcard->isEmpty()) {
		ui->vcard->setVisible(false);
		ui->emptyLabel->setVisible(true);
	} else {
		ui->vcard->setVisible(true);
		ui->emptyLabel->setVisible(false);
	}

	updateWindowSize();
}

void QtProfileWindow::setEnabled(bool b) {
	ui->vcard->setEnabled(b);
	ui->savePushButton->setEnabled(b);
}

void QtProfileWindow::setEditable(bool b) {
	ui->throbberLabel->setVisible(b);
	ui->errorLabel->setVisible(b);
	ui->savePushButton->setVisible(b);
	ui->vcard->setEditable(b);
	updateTitle();
}

void QtProfileWindow::setProcessing(bool processing) {
	if (processing) {
		ui->throbberLabel->movie()->start();
		ui->throbberLabel->show();
		ui->statusLabel->setVisible(true);
		ui->vcard->setVisible(false);
	}
	else {
		ui->throbberLabel->hide();
		ui->throbberLabel->movie()->stop();
		ui->statusLabel->setVisible(false);
		ui->vcard->setVisible(true);
	}

	updateWindowSize();
}

void QtProfileWindow::setError(const std::string& error) {
	if (!error.empty()) {
		ui->errorLabel->setText("<font color='red'>" + QtUtilities::htmlEscape(P2QSTRING(error)) + "</font>");
	}
	else {
		ui->errorLabel->setText("");
	}
}

void QtProfileWindow::show() {
	QWidget::showNormal();
	QWidget::activateWindow();
	QWidget::raise();
}

void QtProfileWindow::hide() {
	QWidget::hide();
}

void QtProfileWindow::updateTitle() {
	QString jidString;
	if (jid.isValid()) {
		jidString = QString(" ( %1 )").arg(P2QSTRING(jid.toString()));
	}

	if (ui->vcard->isEditable()) {
		setWindowTitle(tr("Edit Profile") + jidString);
	} else {
		setWindowTitle(tr("Show Profile") + jidString);
	}
}

void QtProfileWindow::updateWindowSize() {
	int width = 0;
	int height = 0;

	QSize size = ui->statusLabel->size();
	width = std::max(width, size.width());
	height = std::max(height, size.height() * 3);

	size = ui->emptyLabel->size();
	width = std::max(width, size.width());
	height = std::max(height, size.height() * 3);

	size = ui->vcard->size();
	width = std::max(width, size.width());
	height = std::max(height, size.height());

	resize(width, height);
}

void QtProfileWindow::closeEvent(QCloseEvent* event) {
	event->accept();
	onWindowAboutToBeClosed(jid);
}

void QtProfileWindow::handleSave() {
	onVCardChangeRequest(ui->vcard->getVCard());
}

}