3
* Copyright (C) 2006 Remko Troncon
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "privacyruledlg.h"
22
#include "privacylistitem.h"
24
PrivacyRuleDlg::PrivacyRuleDlg()
28
connect(ui_.cb_type,SIGNAL(currentIndexChanged(const QString&)),SLOT(type_selected(const QString&)));
29
connect(ui_.pb_cancel,SIGNAL(clicked()),SLOT(reject()));
30
connect(ui_.pb_ok,SIGNAL(clicked()),SLOT(accept()));
33
void PrivacyRuleDlg::setRule(const PrivacyListItem& item)
36
if (item.type() == PrivacyListItem::SubscriptionType) {
37
ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("Subscription")));
38
if (item.value() == "both") {
39
ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("Both")));
41
else if (item.value() == "none") {
42
ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("None")));
44
else if (item.value() == "from") {
45
ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("From")));
47
else if (item.value() == "to") {
48
ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("To")));
52
if (item.type() == PrivacyListItem::JidType) {
53
ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("JID")));
55
else if (item.type() == PrivacyListItem::GroupType) {
56
ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("Group")));
59
ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("*")));
61
ui_.cb_value->setCurrentText(item.value());
65
if (item.action() == PrivacyListItem::Allow) {
66
ui_.cb_action->setCurrentIndex(ui_.cb_action->findText(tr("Allow")));
69
ui_.cb_action->setCurrentIndex(ui_.cb_action->findText(tr("Deny")));
73
ui_.ck_messages->setChecked(item.message());
74
ui_.ck_queries->setChecked(item.iq());
75
ui_.ck_presenceIn->setChecked(item.presenceIn());
76
ui_.ck_presenceOut->setChecked(item.presenceOut());
79
PrivacyListItem PrivacyRuleDlg::rule() const
84
if(ui_.cb_type->currentText() == tr("Subscription")) {
85
item.setType(PrivacyListItem::SubscriptionType);
86
if (ui_.cb_value->currentText() == tr("To"))
88
else if (ui_.cb_value->currentText() == tr("From"))
89
item.setValue("from");
90
else if (ui_.cb_value->currentText() == tr("Both"))
91
item.setValue("both");
92
else if (ui_.cb_value->currentText() == tr("None"))
93
item.setValue("none");
96
if (ui_.cb_type->currentText() == tr("JID")) {
97
item.setType(PrivacyListItem::JidType);
99
else if (ui_.cb_type->currentText() == tr("Group")) {
100
item.setType(PrivacyListItem::GroupType);
103
item.setType(PrivacyListItem::FallthroughType);
105
item.setValue(ui_.cb_value->currentText());
109
if(ui_.cb_action->currentText() == tr("Deny")) {
110
item.setAction(PrivacyListItem::Deny);
113
item.setAction(PrivacyListItem::Allow);
117
item.setMessage(ui_.ck_messages->isChecked());
118
item.setIQ(ui_.ck_queries->isChecked());
119
item.setPresenceIn(ui_.ck_presenceIn->isChecked());
120
item.setPresenceOut(ui_.ck_presenceOut->isChecked());
125
void PrivacyRuleDlg::type_selected(const QString& type)
127
ui_.cb_value->clear();
128
ui_.cb_value->setCurrentText("");
129
if (type == tr("Subscription")) {
130
ui_.cb_value->insertItem(tr("None"));
131
ui_.cb_value->insertItem(tr("Both"));
132
ui_.cb_value->insertItem(tr("From"));
133
ui_.cb_value->insertItem(tr("To"));
134
ui_.cb_value->setEditable(false);
137
ui_.cb_value->setEditable(true);
140
if (type == tr("*")) {
141
ui_.cb_value->setEnabled(false);
144
ui_.cb_value->setEnabled(true);