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

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

Use a const pointer for user objects that are only fetched for read access. Fixed some places where we changed the user even though we just had a read lock.

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 "customautorespdlg.h"
22
23#include <QDialogButtonBox>
24#include <QPushButton>
25#include <QTimer>
26#include <QVBoxLayout>
27
28#include <licq_user.h>
29
30#include "core/licqgui.h"
31
32#include "helpers/licqstrings.h"
33#include "helpers/support.h"
34
35#include "widgets/mledit.h"
36
37#include "awaymsgdlg.h"
38
39using namespace LicqQtGui;
40/* TRANSLATOR LicqQtGui::CustomAutoRespDlg */
41
42CustomAutoRespDlg::CustomAutoRespDlg(QString id, unsigned long ppid, QWidget* parent)
43  : QDialog(parent),
44    myId(id),
45    myPpid(ppid)
46{
47  Support::setWidgetProps(this, "CustomAutoResponseDialog");
48  setAttribute(Qt::WA_DeleteOnClose, true);
49
50  QVBoxLayout* lay = new QVBoxLayout(this);
51
52  myMessage = new MLEdit(true);
53  myMessage->setSizeHintLines(5);
54  connect(myMessage, SIGNAL(ctrlEnterPressed()), SLOT(ok()));
55  lay->addWidget(myMessage);
56
57  QDialogButtonBox* buttons = new QDialogButtonBox(
58      QDialogButtonBox::Ok |
59      QDialogButtonBox::Cancel);
60  connect(buttons, SIGNAL(accepted()), SLOT(ok()));
61  connect(buttons, SIGNAL(rejected()), SLOT(close()));
62
63  QPushButton* btn;
64
65  btn = buttons->addButton(QDialogButtonBox::Discard);
66  btn->setText(tr("Clear"));
67  connect(btn, SIGNAL(clicked()), SLOT(clear()));
68
69  btn = buttons->addButton(QDialogButtonBox::Help);
70  btn->setText(tr("Hints"));
71  connect(btn, SIGNAL(clicked()), SLOT(hints()));
72
73  lay->addWidget(buttons);
74
75  const ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_R);
76
77  if (u == NULL)
78    return;
79
80  setWindowTitle(tr("Set Custom Auto Response for %1").arg(QString::fromUtf8(u->GetAlias())));
81  if (u->CustomAutoResponse()[0] != '\0')
82    myMessage->setText(QString::fromLocal8Bit(u->CustomAutoResponse()));
83  else
84    if (u->StatusToUser() != ICQ_STATUS_OFFLINE)
85      myMessage->setText(tr("I am currently %1.\nYou can leave me a message.")
86          .arg(LicqStrings::getStatus(u->StatusToUser(), false)));
87
88  gUserManager.DropUser(u);
89
90  myMessage->setFocus();
91  QTimer::singleShot(0, myMessage, SLOT(selectAll()));
92
93  show();
94}
95
96void CustomAutoRespDlg::ok()
97{
98  QString s = myMessage->toPlainText().trimmed();
99
100  ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_W);
101  if (u != NULL)
102  {
103    u->SetCustomAutoResponse(s.toLocal8Bit());
104    gUserManager.DropUser(u);
105
106    // Daemon doesn't send signal when autoresponse is changed so we must tell
107    // contact list to update since custom autoresponse affects extended icons
108    LicqGui::instance()->updateUserData(myId, myPpid);
109  }
110  close();
111}
112
113void CustomAutoRespDlg::clear()
114{
115  ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_W);
116  if (u != NULL)
117  {
118    u->ClearCustomAutoResponse();
119    gUserManager.DropUser(u);
120
121    // Daemon doesn't send signal when autoresponse is changed so we must tell
122    // contact list to update since custom autoresponse affects extended icons
123    LicqGui::instance()->updateUserData(myId, myPpid);
124  }
125  close();
126}
127
128void CustomAutoRespDlg::hints()
129{
130  AwayMsgDlg::showAutoResponseHints(this);
131}
Note: See TracBrowser for help on using the browser.