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

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

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

Line 
1/*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2007 Licq developers
4 *
5 * Licq is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * Licq 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 Licq; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include "ownereditdlg.h"
21
22#include "config.h"
23
24#include <QComboBox>
25#include <QCheckBox>
26#include <QDialogButtonBox>
27#include <QGridLayout>
28#include <QLabel>
29#include <QLineEdit>
30#include <QPushButton>
31
32#include <licq_icqd.h>
33#include <licq_user.h>
34
35#include "core/messagebox.h"
36
37#include "helpers/support.h"
38
39#include "widgets/protocombobox.h"
40
41using namespace LicqQtGui;
42/* TRANSLATOR LicqQtGui::OwnerEditDlg */
43
44OwnerEditDlg::OwnerEditDlg(unsigned long ppid, QWidget* parent)
45  : QDialog(parent),
46    myPpid(ppid)
47{
48  Support::setWidgetProps(this, "OwnerEdit");
49  setAttribute(Qt::WA_DeleteOnClose, true);
50  setWindowTitle(tr("Edit Account"));
51
52  QGridLayout* lay = new QGridLayout(this);
53  lay->setColumnStretch(2, 2);
54  lay->setColumnMinimumWidth(1, 8);
55
56  cmbProtocol = new ProtoComboBox(ppid == 0, this);
57
58  edtId = new QLineEdit();
59  connect(edtId, SIGNAL(returnPressed()), SLOT(slot_ok()));
60
61  edtPassword = new QLineEdit();
62  edtPassword->setEchoMode(QLineEdit::Password);
63  connect(edtPassword, SIGNAL(returnPressed()), SLOT(slot_ok()));
64
65  unsigned short i = 0;
66  QLabel* lbl;
67
68#define ADDWIDGET(name, widget) \
69  lbl = new QLabel(name); \
70  lbl->setBuddy(widget); \
71  lay->addWidget(lbl, i, 0); \
72  lay->addWidget(widget, i++, 2)
73
74  ADDWIDGET(tr("Pro&tocol:"), cmbProtocol);
75  ADDWIDGET(tr("&User ID:"), edtId);
76  ADDWIDGET(tr("&Password:"), edtPassword);
77
78#undef ADDWIDGET
79
80  chkSave = new QCheckBox(tr("&Save Password"));
81  lay->addWidget(chkSave, i++, 0, 1, 3);
82
83  QDialogButtonBox* buttons = new QDialogButtonBox();
84  buttons->addButton(QDialogButtonBox::Ok);
85  buttons->addButton(QDialogButtonBox::Cancel);
86  connect(buttons, SIGNAL(accepted()), SLOT(slot_ok()));
87  connect(buttons, SIGNAL(rejected()), SLOT(close()));
88  lay->addWidget(buttons, i++, 0, 1, 3);
89
90  // Set the fields
91  if (ppid != 0)
92  {
93    const ICQOwner* o = gUserManager.FetchOwner(ppid, LOCK_R);
94    if (o != NULL)
95    {
96      edtId->setText(o->IdString());
97      edtId->setEnabled(false);
98      edtPassword->setText(o->Password());
99      chkSave->setChecked(o->SavePassword());
100      gUserManager.DropOwner(o);
101    }
102
103    cmbProtocol->setCurrentPpid(ppid);
104    cmbProtocol->setEnabled(false);
105  }
106  else
107  {
108    if (cmbProtocol->count() == 0)
109    {
110      InformUser(this, tr("Currently only one account per protocol is supported."));
111      close();
112      return;
113    }
114  }
115
116  show();
117}
118
119void OwnerEditDlg::slot_ok()
120{
121  QString id = edtId->text();
122  QString pwd = edtPassword->text();
123  unsigned long ppid = myPpid == 0 ? cmbProtocol->currentPpid() : myPpid;
124
125  if (id.isEmpty())
126  {
127    InformUser(this, tr("User ID field cannot be empty."));
128    return;
129  }
130
131  if (myPpid == 0)
132    gUserManager.AddOwner(id.toLocal8Bit(), ppid);
133
134  ICQOwner* o = gUserManager.FetchOwner(ppid, LOCK_W);
135  if (o == NULL)
136    return;
137
138  o->SetPassword(pwd.toLocal8Bit());
139  o->SetSavePassword(chkSave->isChecked());
140
141  gUserManager.DropOwner(o);
142  gLicqDaemon->SaveConf();
143
144  close();
145}
Note: See TracBrowser for help on using the browser.