root/trunk/qt4-gui/src/dialogs/securitydlg.cpp

Revision 6466, 4.8 kB (checked in by flynd, 4 months ago)

Use const pointer for owner objects that are fetched only for read access.

  • Property svn:eol-style set to native
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 1999-2006 Licq developers
5 *
6 * Licq is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Licq is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Licq; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 */
20
21#include "securitydlg.h"
22
23#include "config.h"
24
25#include <QCheckBox>
26#include <QDialogButtonBox>
27#include <QGroupBox>
28#include <QPushButton>
29#include <QVBoxLayout>
30
31#include <licq_events.h>
32#include <licq_icqd.h>
33#include <licq_user.h>
34
35#include "core/licqgui.h"
36#include "core/messagebox.h"
37#include "core/signalmanager.h"
38
39#include "helpers/support.h"
40
41using namespace LicqQtGui;
42/* TRANSLATOR LicqQtGui::SecurityDlg */
43
44SecurityDlg::SecurityDlg(QWidget* parent)
45  : QDialog(parent),
46    title(tr("ICQ Security")),
47    eSecurityInfo(0)
48{
49  Support::setWidgetProps(this, "SecurityDialog");
50  setAttribute(Qt::WA_DeleteOnClose, true);
51  setWindowTitle(title);
52
53  const ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R);
54  if (o == NULL)
55  {
56    InformUser(this, tr("No ICQ owner found.\nPlease create one first."));
57    close();
58    return;
59  }
60
61  QVBoxLayout* top_lay = new QVBoxLayout(this);
62
63  QGroupBox* boxOptions = new QGroupBox(tr("Options"));
64  QVBoxLayout* layOptions = new QVBoxLayout(boxOptions);
65
66#define ADD_CHECK(var, name, tip, status) \
67  (var) = new QCheckBox((name)); \
68  (var)->setChecked((status)); \
69  (var)->setToolTip((tip)); \
70  layOptions->addWidget((var));
71
72  ADD_CHECK(chkAuthorization, tr("&Authorization Required"), tr("Determines "
73        "whether regular ICQ clients require\nyour authorization to add you to "
74        "their contact list."), o->GetAuthorization());
75  ADD_CHECK(chkWebAware, tr("&Web Presence"), tr("Web Presence allows users to"
76        " see\nif you are online through your web indicator."), o->WebAware());
77  ADD_CHECK(chkHideIp, tr("&Hide IP"), tr("Hide IP stops users from seeing your"
78        " IP address.\nIt doesn't guarantee it will be hidden though."),
79      o->HideIp());
80#undef ADD_CHECK
81
82  gUserManager.DropOwner(o);
83
84  top_lay->addWidget(boxOptions);
85
86  QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel);
87
88  btnUpdate = buttons->addButton(QDialogButtonBox::Ok);
89  btnUpdate->setText(tr("&Update"));
90
91  connect(buttons, SIGNAL(accepted()), SLOT(ok()));
92  connect(buttons, SIGNAL(rejected()), SLOT(close()));
93
94  top_lay->addWidget(buttons);
95
96  show();
97}
98
99void SecurityDlg::ok()
100{
101  const ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R);
102
103  if (o == NULL)
104  {
105    // Even though we protected from this in constructor,
106    // it's never too bad to persuade
107    close();
108    return;
109  }
110
111  if (o->Status() == ICQ_STATUS_OFFLINE)
112  {
113    gUserManager.DropOwner(o);
114    InformUser(this, tr("You need to be connected to the\n"
115          "ICQ Network to change the settings."));
116    return;
117  }
118
119  bool auth = chkAuthorization->isChecked();
120  bool web = chkWebAware->isChecked();
121  bool ip = chkHideIp->isChecked();
122
123  if (auth != o->GetAuthorization() ||
124      web != o->WebAware() ||
125      ip != o->HideIp())
126  {
127    gUserManager.DropOwner(o);
128    btnUpdate->setEnabled(false);
129
130    connect(LicqGui::instance()->signalManager(),
131        SIGNAL(doneUserFcn(ICQEvent*)), SLOT(doneUserFcn(ICQEvent*)));
132
133    setWindowTitle(title + " [" + tr("Setting...") + "]");
134
135    eSecurityInfo = gLicqDaemon->icqSetSecurityInfo(auth, ip, web);
136
137    return; // prevents the dialog from closing
138  }
139
140  gUserManager.DropOwner(o);
141
142  close();
143}
144
145void SecurityDlg::doneUserFcn(ICQEvent* e)
146{
147  if (!e->Equals(eSecurityInfo))
148    return;
149
150  eSecurityInfo = 0;
151  QString result = QString::null;
152  btnUpdate->setEnabled(true);
153
154  disconnect(LicqGui::instance()->signalManager(),
155      SIGNAL(doneUserFcn(ICQEvent*)), this, SLOT(doneUserFcn(ICQEvent*)));
156
157  switch (e->Result())
158  {
159    case EVENT_FAILED:
160      result = tr("failed");
161      InformUser(this, tr("Setting security options failed."));
162      break;
163
164    case EVENT_TIMEDOUT:
165      result = tr("timed out");
166      InformUser(this, tr("Timeout while setting security options."));
167      break;
168
169    case EVENT_ERROR:
170      result = tr("error");
171      InformUser(this, tr("Internal error while setting security options."));
172      break;
173
174    default:
175      break;
176  }
177
178  if (result.isEmpty())
179    close();
180  else
181    setWindowTitle(title + " [" + tr("Setting...") + " " + result + "]");
182}
Note: See TracBrowser for help on using the browser.