summaryrefslogtreecommitdiffstats
path: root/src/gui/inviteform.cpp
blob: 433fb2272139cbb42b998544f94020219373879d (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
157
158
159
160
161
162
163
164
165
166
#include "inviteform.h"
//Added by qt3to4:
#include <QCloseEvent>
#include "gui.h"
#include "util.h"
#include "audits/memman.h"
#include "sys_settings.h"
#include <QRegExp>
#include <QValidator>

/*
    Copyright (C) 2005-2009  Michel de Boer <michel@twinklephone.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

InviteForm::InviteForm(QWidget *parent)
    : QDialog(parent)
{
	setupUi(this);
	init();
}

InviteForm::~InviteForm()
{
	destroy();
}

void InviteForm::init()
{
	getAddressForm = 0;
	
	// Set toolbutton icons for disabled options.
	setDisabledIcon(addressToolButton, ":/icons/images/kontact_contacts-disabled.png");
	
	// A QComboBox accepts a new line through copy/paste.
	QRegExp rxNoNewLine("[^\\n\\r]*");
	inviteComboBox->setValidator(new QRegExpValidator(rxNoNewLine, this));
}

void InviteForm::destroy()
{
	if (getAddressForm) {
		MEMMAN_DELETE(getAddressForm);
		delete getAddressForm;
	}
}

void InviteForm::clear()
{
    inviteComboBox->clearEditText();
	subjectLineEdit->clear();
	hideUserCheckBox->setChecked(false);
	inviteComboBox->setFocus();
}

void InviteForm::show(t_user *user_config, const QString &dest, const QString &subject,
		      bool anonymous)
{
	((t_gui *)ui)->fill_user_combo(fromComboBox);
	
	// Select from user
	if (user_config) {
		for (int i = 0; i < fromComboBox->count(); i++) {
            if (fromComboBox->itemText(i) ==
			    user_config->get_profile_name().c_str())
			{
                fromComboBox->setCurrentIndex(i);
				break;
			}
		}
	}
	
	inviteComboBox->setEditText(dest);
	subjectLineEdit->setText(subject);
	hideUserCheckBox->setChecked(anonymous);
	QDialog::show();
}

void InviteForm::validate()
{
	string display, dest_str;
	t_user *from_user = phone->ref_user_profile(
                fromComboBox->currentText().toStdString());
	
	ui->expand_destination(from_user, 
                   inviteComboBox->currentText().trimmed().toStdString(),
			       display, dest_str);
	t_url dest(dest_str);
	
	if (dest.is_valid()) {
		addToInviteComboBox(inviteComboBox->currentText());
		emit raw_destination(inviteComboBox->currentText());
		emit destination(from_user, display.c_str(), dest, subjectLineEdit->text(),
				 hideUserCheckBox->isChecked());
		accept();
	} else {
		inviteComboBox->setFocus();
		inviteComboBox->lineEdit()->selectAll();
	}
}

// Add a destination to the history list of inviteComboBox
void InviteForm::addToInviteComboBox(const QString &destination)
{
    inviteComboBox->insertItem(0, destination);
	if (inviteComboBox->count() > SIZE_REDIAL_LIST) {
		inviteComboBox->removeItem(inviteComboBox->count() - 1);
	}
}


void InviteForm::reject()
{
	// Unseize the line
	((t_gui *)ui)->action_unseize();
	QDialog::reject();
}

void InviteForm::closeEvent(QCloseEvent *)
{
	reject();
}

void InviteForm::showAddressBook()
{
	if (!getAddressForm) {
        getAddressForm = new GetAddressForm(this);
        getAddressForm->setModal(true);
		MEMMAN_NEW(getAddressForm);
	}
	
	connect(getAddressForm, 
		SIGNAL(address(const QString &)),
		this, SLOT(selectedAddress(const QString &)));
	
	getAddressForm->show();
}

void InviteForm::selectedAddress(const QString &address)
{
	inviteComboBox->setEditText(address);
}

void InviteForm::warnHideUser(void) {
	// Warn only once
	if (!sys_config->get_warn_hide_user()) return;
	
	QString msg = tr("Not all SIP providers support identity hiding. Make sure your SIP provider "
			 "supports it if you really need it.");
    ((t_gui *)ui)->cb_show_msg(this, msg.toStdString(), MSG_WARNING);
	
	// Do not warn again
	sys_config->set_warn_hide_user(false);
}