~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/privacyruledlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * privacyruledlg.cpp
 
3
 * Copyright (C) 2006  Remko Troncon
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#include "privacyruledlg.h"
 
22
#include "privacylistitem.h"
 
23
 
 
24
PrivacyRuleDlg::PrivacyRuleDlg()
 
25
{
 
26
        ui_.setupUi(this);
 
27
        
 
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()));
 
31
}
 
32
 
 
33
void PrivacyRuleDlg::setRule(const PrivacyListItem& item)
 
34
{
 
35
        // Type
 
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")));
 
40
                }
 
41
                else if (item.value() == "none") {
 
42
                        ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("None")));
 
43
                }
 
44
                else if (item.value() == "from") {
 
45
                        ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("From")));
 
46
                }
 
47
                else if (item.value() == "to") {
 
48
                        ui_.cb_value->setCurrentIndex(ui_.cb_value->findText(tr("To")));
 
49
                }
 
50
        }
 
51
        else {
 
52
                if (item.type() == PrivacyListItem::JidType) {
 
53
                        ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("JID")));
 
54
                }
 
55
                else if (item.type() == PrivacyListItem::GroupType) {
 
56
                        ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("Group")));
 
57
                }
 
58
                else {
 
59
                        ui_.cb_type->setCurrentIndex(ui_.cb_type->findText(tr("*")));
 
60
                }
 
61
                ui_.cb_value->setCurrentText(item.value());
 
62
        }
 
63
 
 
64
        // Action
 
65
        if (item.action() == PrivacyListItem::Allow) {
 
66
                ui_.cb_action->setCurrentIndex(ui_.cb_action->findText(tr("Allow")));
 
67
        }
 
68
        else {
 
69
                ui_.cb_action->setCurrentIndex(ui_.cb_action->findText(tr("Deny")));
 
70
        }
 
71
 
 
72
        // Selection
 
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());
 
77
}
 
78
 
 
79
PrivacyListItem PrivacyRuleDlg::rule() const
 
80
{
 
81
        PrivacyListItem item;
 
82
 
 
83
        // Type & value
 
84
        if(ui_.cb_type->currentText() == tr("Subscription")) {
 
85
                item.setType(PrivacyListItem::SubscriptionType);
 
86
                if (ui_.cb_value->currentText() == tr("To")) 
 
87
                        item.setValue("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");
 
94
        }
 
95
        else {
 
96
                if (ui_.cb_type->currentText() == tr("JID")) {
 
97
                        item.setType(PrivacyListItem::JidType);
 
98
                }
 
99
                else if (ui_.cb_type->currentText() == tr("Group")) {
 
100
                        item.setType(PrivacyListItem::GroupType);
 
101
                }
 
102
                else {
 
103
                        item.setType(PrivacyListItem::FallthroughType);
 
104
                }
 
105
                item.setValue(ui_.cb_value->currentText());
 
106
        }
 
107
        
 
108
        // Action
 
109
        if(ui_.cb_action->currentText() == tr("Deny")) {
 
110
                item.setAction(PrivacyListItem::Deny);
 
111
        }
 
112
        else {
 
113
                item.setAction(PrivacyListItem::Allow);
 
114
        }
 
115
        
 
116
        // Selection
 
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());
 
121
 
 
122
        return item;
 
123
}
 
124
 
 
125
void PrivacyRuleDlg::type_selected(const QString& type)
 
126
{
 
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);
 
135
        }
 
136
        else {
 
137
                ui_.cb_value->setEditable(true);
 
138
        }
 
139
        
 
140
        if (type == tr("*")) {
 
141
                ui_.cb_value->setEnabled(false);
 
142
        }
 
143
        else {
 
144
                ui_.cb_value->setEnabled(true);
 
145
        }
 
146
}