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

Revision 6374, 6.4 kB (checked in by flynd, 5 months ago)

Use the new DropOwner? function to properly specify which owner to unlock.

  • Property svn:eol-style set to native
Line 
1/*
2 * This file is part of Licq, an instant messaging client for UNIX.
3 * Copyright (C) 2004-2006 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 "ownermanagerdlg.h"
21
22#include "config.h"
23
24#include <QDialogButtonBox>
25#include <QPushButton>
26#include <QStringList>
27#include <QTreeWidget>
28#include <QVBoxLayout>
29
30#include <licq_icqd.h>
31#include <licq_user.h>
32
33#include "config/iconmanager.h"
34
35#include "core/gui-defines.h"
36#include "core/licqgui.h"
37#include "core/messagebox.h"
38
39#include "helpers/support.h"
40
41#include "ownereditdlg.h"
42#include "registeruser.h"
43
44using namespace LicqQtGui;
45/* TRANSLATOR LicqQtGui::OwnerManagerDlg */
46
47OwnerManagerDlg* OwnerManagerDlg::myInstance = NULL;
48
49void OwnerManagerDlg::showOwnerManagerDlg()
50{
51  if (myInstance == NULL)
52    myInstance = new OwnerManagerDlg();
53  else
54    myInstance->raise();
55}
56
57OwnerManagerDlg::OwnerManagerDlg(QWidget* parent)
58  : QDialog(parent),
59    registerUserDlg(NULL)
60{
61  setAttribute(Qt::WA_DeleteOnClose, true);
62  Support::setWidgetProps(this, "AccountDialog");
63  setWindowTitle(tr("Licq - Account Manager"));
64
65  QVBoxLayout* toplay = new QVBoxLayout(this);
66
67  // Add the list box
68  ownerView = new QTreeWidget();
69  QStringList headers;
70  headers << tr("Protocol") << tr("User ID");
71  ownerView->setHeaderLabels(headers);
72  ownerView->setIndentation(0);
73  toplay->addWidget(ownerView);
74
75  // Add the buttons now
76  QDialogButtonBox* buttons = new QDialogButtonBox();
77  toplay->addWidget(buttons);
78
79  addButton = new QPushButton(tr("&Add"));
80  buttons->addButton(addButton, QDialogButtonBox::ActionRole);
81
82  registerButton = new QPushButton(tr("&Register"));
83  buttons->addButton(registerButton, QDialogButtonBox::ActionRole);
84
85  modifyButton = new QPushButton(tr("&Modify"));
86  buttons->addButton(modifyButton, QDialogButtonBox::ActionRole);
87
88  removeButton = new QPushButton(tr("D&elete"));
89  buttons->addButton(removeButton, QDialogButtonBox::ActionRole);
90
91  closeButton = new QPushButton(tr("&Done"));
92  buttons->addButton(closeButton, QDialogButtonBox::RejectRole);
93
94  // Connect all the signals
95  connect(ownerView, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
96      SLOT(listClicked(QTreeWidgetItem*)));
97  connect(ownerView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
98      SLOT(modifyOwner(QTreeWidgetItem*, int)));
99  connect(addButton, SIGNAL(clicked()), SLOT(addOwner()));
100  connect(registerButton, SIGNAL(clicked()), SLOT(registerOwner()));
101  connect(modifyButton, SIGNAL(clicked()), SLOT(modifyOwner()));
102  connect(removeButton, SIGNAL(clicked()), SLOT(removeOwner()));
103  connect(closeButton, SIGNAL(clicked()), SLOT(close()));
104
105  // Add the owners to the list now
106  updateOwners();
107
108  // Show information to the user
109  if (gUserManager.NumOwners() == 0)
110  {
111    InformUser(this, tr("From the Account Manager dialog you are able to add"
112        " and register your accounts.\n"
113        "Currently, only one account per protocol is supported, but this will"
114        " be changed in future versions."));
115  }
116
117  show();
118}
119
120OwnerManagerDlg::~OwnerManagerDlg()
121{
122  myInstance = NULL;
123}
124
125void OwnerManagerDlg::updateOwners()
126{
127  ownerView->clear();
128
129  if (gUserManager.NumOwners() != 0)
130  {
131    QString id, proto;
132    unsigned long ppid = 0;
133
134    IconManager* iconman = IconManager::instance();
135
136    FOR_EACH_OWNER_START(LOCK_R)
137      id = pOwner->IdString();
138      ppid = pOwner->PPID();
139      proto = gLicqDaemon->ProtoPluginName(ppid);
140
141      QTreeWidgetItem* item = new QTreeWidgetItem(ownerView);
142      item->setIcon(0, iconman->iconForStatus(ICQ_STATUS_ONLINE, id.toLatin1(), ppid));
143      item->setText(0, proto.isNull() ? tr("(Invalid Protocol)") : proto);
144      item->setData(0, Qt::UserRole, QString::number(ppid));
145      item->setText(1, id.isNull() ? tr("(Invalid ID)") : id);
146    FOR_EACH_OWNER_END
147  }
148
149  ownerView->resizeColumnToContents(0);
150  ownerView->resizeColumnToContents(1);
151  ownerView->sortByColumn(0, Qt::AscendingOrder);
152
153  modifyButton->setEnabled(false);
154  removeButton->setEnabled(false);
155}
156
157void OwnerManagerDlg::listClicked(QTreeWidgetItem* item)
158{
159  modifyButton->setEnabled(item != NULL);
160  removeButton->setEnabled(item != NULL);
161}
162
163void OwnerManagerDlg::addOwner()
164{
165  OwnerEditDlg* d = new OwnerEditDlg(0, this);
166  connect(d, SIGNAL(destroyed()), SLOT(updateOwners()));
167}
168
169void OwnerManagerDlg::registerOwner()
170{
171  if (!gUserManager.OwnerId(LICQ_PPID).empty())
172  {
173    QString buf = tr("You are currently registered as\n"
174        "UIN (User ID): %1\n"
175        "Base Directory: %2\n"
176        "Rerun licq with the -b option to select a new\n"
177        "base directory and then register a new user.")
178        .arg(gUserManager.OwnerId(LICQ_PPID).c_str()).arg(BASE_DIR);
179    InformUser(this, buf);
180    return;
181  }
182
183  if (registerUserDlg != 0)
184    registerUserDlg->raise();
185  else
186  {
187    registerUserDlg = new RegisterUserDlg(this);
188    connect(registerUserDlg, SIGNAL(signal_done(bool, QString, unsigned long)),
189        SLOT(registerDone(bool, QString, unsigned long)));
190  }
191}
192
193void OwnerManagerDlg::registerDone(bool success, QString newId, unsigned long newPpid)
194{
195  registerUserDlg = 0;
196
197  if (success)
198  {
199    updateOwners();
200    LicqGui::instance()->showInfoDialog(mnuUserGeneral, newId, newPpid);
201  }
202}
203
204void OwnerManagerDlg::modifyOwner()
205{
206  modifyOwner(ownerView->currentItem());
207}
208
209void OwnerManagerDlg::modifyOwner(QTreeWidgetItem* item, int /* column */)
210{
211  if (item == NULL)
212    return;
213
214  OwnerEditDlg* editDlg = new OwnerEditDlg(
215      item->data(0, Qt::UserRole).toString().toULong(), this);
216  connect(editDlg, SIGNAL(destroyed()), SLOT(updateOwners()));
217}
218
219void OwnerManagerDlg::removeOwner()
220{
221  QTreeWidgetItem* item = ownerView->currentItem();
222  if (item == NULL)
223    return;
224
225  gUserManager.RemoveOwner(item->data(0, Qt::UserRole).toString().toULong());
226  gLicqDaemon->SaveConf();
227  updateOwners();
228}
Note: See TracBrowser for help on using the browser.