summaryrefslogtreecommitdiffstats
blob: 543d39af679d4bf2cac39ded4698f41a2c7b863c (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
/*
 * Copyright (c) 2010 Kevin Smith
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */

#include "QtContactEditWindow.h"

#include <algorithm>

#include <QScrollArea>
#include <QBoxLayout>
#include <QLabel>
#include <QCheckBox>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>

#include "Swift/QtUI/QtSwiftUtil.h"
#include "QtContactEditWidget.h"

namespace Swift {

QtContactEditWindow::QtContactEditWindow() : contactEditWidget_(NULL) {
	resize(300,300);
	setWindowTitle(tr("Edit contact"));
	setContentsMargins(0,0,0,0);

	QBoxLayout* layout = new QVBoxLayout(this);

	jidLabel_ = new QLabel(this);
	jidLabel_->setAlignment(Qt::AlignHCenter);
	layout->addWidget(jidLabel_);

	groupsLayout_ = new QVBoxLayout();
	groupsLayout_->setContentsMargins(0,0,0,0);
	layout->addLayout(groupsLayout_);

	QHBoxLayout* buttonLayout = new QHBoxLayout();
	layout->addLayout(buttonLayout);
	QPushButton* removeButton = new QPushButton(tr("Remove contact"), this);
	connect(removeButton, SIGNAL(clicked()), this, SLOT(handleRemoveContact()));
	buttonLayout->addWidget(removeButton);
	QPushButton* okButton = new QPushButton(tr("Ok"), this);
	connect(okButton, SIGNAL(clicked()), this, SLOT(handleUpdateContact()));
	buttonLayout->addStretch();
	buttonLayout->addWidget(okButton);
}

void QtContactEditWindow::setContact(const JID& jid, const std::string& name, const std::vector<std::string>& groups, const std::set<std::string>& allGroups) {
	delete contactEditWidget_;
	jid_ = jid;
	jidLabel_->setText("<b>" + P2QSTRING(jid.toString()) + "</b>");

	contactEditWidget_ = new QtContactEditWidget(allGroups, this);
	groupsLayout_->addWidget(contactEditWidget_);
	contactEditWidget_->setName(name);
	contactEditWidget_->setSelectedGroups(groups);
}

void QtContactEditWindow::setEnabled(bool b) {
	QWidget::setEnabled(b);
}

void QtContactEditWindow::show() {
	QWidget::show();
	QWidget::activateWindow();
}

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

void QtContactEditWindow::handleRemoveContact() {
	QMessageBox msgBox;
	msgBox.setWindowTitle(tr("Confirm contact deletion"));
	msgBox.setText(tr("Are you sure you want to delete this contact?"));
	msgBox.setInformativeText(QString(tr("This will remove the contact '%1' from all groups they may be in.")).arg(P2QSTRING(jid_.toString())));
	msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
	msgBox.setDefaultButton(QMessageBox::Yes);
	int ret = msgBox.exec();
	if (ret == QMessageBox::Yes) {
		onRemoveContactRequest();
	}
}

void QtContactEditWindow::handleUpdateContact() {
	onChangeContactRequest(contactEditWidget_->getName(), contactEditWidget_->getSelectedGroups());
}

}