root/trunk/qt4-gui/src/settings/status.cpp

Revision 6139, 9.8 kB (checked in by flynd, 8 months ago)

Added option to not change status until away message dialog is closed. This closes #1421.

Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of Licq, an instant messaging client for UNIX.
4 * Copyright (C) 2007 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 "status.h"
22
23#include "config.h"
24
25#include <QCheckBox>
26#include <QComboBox>
27#include <QGridLayout>
28#include <QGroupBox>
29#include <QHBoxLayout>
30#include <QLabel>
31#include <QPushButton>
32#include <QSpinBox>
33#include <QVBoxLayout>
34
35#include <licq_sar.h>
36
37#include "config/general.h"
38
39#include "core/mainwin.h"
40
41#include "widgets/mledit.h"
42
43#include "settingsdlg.h"
44
45using namespace LicqQtGui;
46/* TRANSLATOR LicqQtGui::Settings::Status */
47
48Settings::Status::Status(SettingsDlg* parent)
49  : QObject(parent)
50{
51  parent->addPage(SettingsDlg::StatusPage, createPageStatus(parent),
52      tr("Status"));
53  parent->addPage(SettingsDlg::RespMsgPage, createPageRespMsg(parent),
54      tr("Auto Response"), SettingsDlg::StatusPage);
55
56  load();
57}
58
59QWidget* Settings::Status::createPageStatus(QWidget* parent)
60{
61  QWidget* w = new QWidget(parent);
62  myPageStatusLayout = new QVBoxLayout(w);
63  myPageStatusLayout->setContentsMargins(0, 0, 0, 0);
64
65  myGeneralBox = new QGroupBox(tr("General Status Options"));
66  myGeneralLayout = new QVBoxLayout(myGeneralBox);
67
68  myDelayStatusChangeCheck = new QCheckBox(tr("Delay status changes"));
69  myDelayStatusChangeCheck->setToolTip(tr("Set status after closing the away message dialog instead of setting it directly."));
70  myGeneralLayout->addWidget(myDelayStatusChangeCheck);
71
72  myAutoLogonBox = new QGroupBox(tr("Startup"));
73  myAutoLogonLayout = new QVBoxLayout(myAutoLogonBox);
74
75  myAutoLogonCombo = new QComboBox();
76  myAutoLogonCombo->addItem(tr("Offline"));
77  myAutoLogonCombo->addItem(tr("Online"));
78  myAutoLogonCombo->addItem(tr("Away"));
79  myAutoLogonCombo->addItem(tr("Not Available"));
80  myAutoLogonCombo->addItem(tr("Occupied"));
81  myAutoLogonCombo->addItem(tr("Do Not Disturb"));
82  myAutoLogonCombo->addItem(tr("Free for Chat"));
83  myAutoLogonCombo->setToolTip(tr("Automatically log on when first starting up."));
84  myAutoLogonLayout->addWidget(myAutoLogonCombo);
85
86  myAutoLogonInvisibleCheck = new QCheckBox(tr("Invisible"));
87  myAutoLogonLayout->addWidget(myAutoLogonInvisibleCheck);
88
89
90  myAutoAwayBox = new QGroupBox(tr("Auto Change Status"));
91  myAutoAwayLayout = new QGridLayout(myAutoAwayBox);
92  myAutoAwayLayout->setColumnMinimumWidth(2, 20);
93
94  myAutoAwayLabel = new QLabel(tr("Auto Away:"));
95  myAutoAwayLabel->setToolTip(tr("Number of minutes of inactivity after which to "
96        "automatically be marked \"away\".  Set to \"0\" to disable."));
97  myAutoAwayLayout->addWidget(myAutoAwayLabel, 0, 0);
98
99  myAutoAwaySpin = new QSpinBox();
100  myAutoAwaySpin->setSpecialValueText(tr("Never"));
101  myAutoAwayLayout->addWidget(myAutoAwaySpin, 0, 1);
102
103  myAutoAwayMessCombo = new QComboBox();
104  myAutoAwayLayout->addWidget(myAutoAwayMessCombo, 0, 3);
105
106  myAutoNaLabel = new QLabel(tr("Auto N/A:"));
107  myAutoNaLabel->setToolTip(tr("Number of minutes of inactivity after which to "
108        "automatically be marked \"not available\".  Set to \"0\" to disable."));
109  myAutoAwayLayout->addWidget(myAutoNaLabel, 1, 0);
110
111  myAutoNaSpin = new QSpinBox();
112  myAutoNaSpin->setSpecialValueText(tr("Never"));
113  myAutoAwayLayout->addWidget(myAutoNaSpin, 1, 1);
114
115  myAutoNaMessCombo = new QComboBox();
116  myAutoAwayLayout->addWidget(myAutoNaMessCombo, 1, 3);
117
118  myAutoOfflineLabel = new QLabel(tr("Auto Offline:"));
119  myAutoOfflineLabel->setToolTip(tr("Number of minutes of inactivity after which to "
120        "automatically go offline.  Set to \"0\" to disable."));
121  myAutoAwayLayout->addWidget(myAutoOfflineLabel, 2, 0);
122
123  myAutoOfflineSpin = new QSpinBox();
124  myAutoOfflineSpin->setSpecialValueText(tr("Never"));
125  myAutoAwayLayout->addWidget(myAutoOfflineSpin, 2, 1);
126
127  buildAutoStatusCombos(1);
128
129  myPageStatusLayout->addWidget(myGeneralBox);
130  myPageStatusLayout->addWidget(myAutoLogonBox);
131  myPageStatusLayout->addWidget(myAutoAwayBox);
132  myPageStatusLayout->addStretch(1);
133
134  return w;
135}
136
137QWidget* Settings::Status::createPageRespMsg(QWidget* parent)
138{
139  QWidget* w = new QWidget(parent);
140  myPageRespMsgLayout = new QVBoxLayout(w);
141  myPageRespMsgLayout->setContentsMargins(0, 0, 0, 0);
142
143  myDefRespMsgBox = new QGroupBox(tr("Default Auto Response Messages"));
144  myPageRespMsgLayout->addWidget(myDefRespMsgBox);
145
146  myDefRespMsgLayout = new QGridLayout(myDefRespMsgBox);
147
148  mySarGroupLabel = new QLabel(tr("Status:"));
149  myDefRespMsgLayout->addWidget(mySarGroupLabel, 0, 0);
150
151  mySarGroupCombo = new QComboBox();
152  mySarGroupCombo->addItem(tr("Away"), SAR_AWAY);
153  mySarGroupCombo->addItem(tr("Not Available"), SAR_NA);
154  mySarGroupCombo->addItem(tr("Occupied"), SAR_OCCUPIED);
155  mySarGroupCombo->addItem(tr("Do Not Disturb"), SAR_DND);
156  mySarGroupCombo->addItem(tr("Free For Chat"), SAR_FFC);
157  connect(mySarGroupCombo, SIGNAL(activated(int)), SLOT(sarGroupChanged(int)));
158  myDefRespMsgLayout->addWidget(mySarGroupCombo, 0, 1);
159
160  mySarMsgLabel = new QLabel(tr("Preset slot:"));
161  myDefRespMsgLayout->addWidget(mySarMsgLabel, 1, 0);
162
163  mySarMsgCombo = new QComboBox();
164  mySarMsgCombo->setEditable(true);
165  mySarMsgCombo->setInsertPolicy(QComboBox::InsertAtCurrent);
166  connect(mySarMsgCombo, SIGNAL(activated(int)), SLOT(sarMsgChanged(int)));
167  myDefRespMsgLayout->addWidget(mySarMsgCombo, 1, 1);
168
169  mySartextEdit = new MLEdit(true);
170  myDefRespMsgLayout->addWidget(mySartextEdit, 2, 0, 1, 3);
171
172  QHBoxLayout* buttons = new QHBoxLayout();
173
174  mySarhintsButton = new QPushButton(tr("Hints"));
175  buttons->addWidget(mySarhintsButton);
176  connect(mySarhintsButton, SIGNAL(clicked()), SLOT(showSarHints()));
177
178  buttons->addStretch();
179
180  mySarsaveButton = new QPushButton(tr("Save"));
181  buttons->addWidget(mySarsaveButton);
182  connect(mySarsaveButton, SIGNAL(clicked()), SLOT(saveSar()));
183
184  myDefRespMsgLayout->addLayout(buttons, 3, 0, 1, 3);
185
186  myDefRespMsgLayout->setColumnStretch(2, 1);
187
188  sarGroupChanged(SAR_AWAY);
189
190  return w;
191}
192
193void Settings::Status::buildAutoStatusCombos(bool firstTime)
194{
195  int selectedNA, selectedAway;
196
197  //Save selection (or get first selection)
198  if (firstTime)
199  {
200    selectedAway = Config::General::instance()->autoAwayMess();
201    selectedNA   = Config::General::instance()->autoNaMess();
202  }
203  else
204  {
205    selectedAway = myAutoAwayMessCombo->currentIndex();
206    selectedNA   = myAutoNaMessCombo->currentIndex();
207  }
208
209  myAutoAwayMessCombo->clear();
210  myAutoAwayMessCombo->addItem(tr("Previous Message"),0);
211  SARList &sara = gSARManager.Fetch(SAR_AWAY);
212  for (unsigned i = 0; i < sara.size(); i++)
213    myAutoAwayMessCombo->addItem(sara[i]->Name(),i+1);
214  gSARManager.Drop();
215
216  myAutoNaMessCombo->clear();
217  myAutoNaMessCombo->addItem(tr("Previous Message"),0);
218  SARList &sarn = gSARManager.Fetch(SAR_NA);
219  for (unsigned i = 0; i < sarn.size(); i++)
220    myAutoNaMessCombo->addItem(sarn[i]->Name(),i+1);
221  gSARManager.Drop();
222
223  myAutoAwayMessCombo->setCurrentIndex(selectedAway);
224  myAutoNaMessCombo->setCurrentIndex(selectedNA);
225}
226
227void Settings::Status::sarMsgChanged(int msg)
228{
229  if (msg < 0)
230    return;
231
232  SARList &sar = gSARManager.Fetch(mySarGroupCombo->currentIndex());
233  mySartextEdit->setText(QString::fromLocal8Bit(sar[msg]->AutoResponse()));
234  gSARManager.Drop();
235}
236
237void Settings::Status::sarGroupChanged(int group)
238{
239  if (group < 0)
240    return;
241
242  mySarMsgCombo->clear();
243  SARList &sar = gSARManager.Fetch(group);
244  for (SARListIter i = sar.begin(); i != sar.end(); i++)
245    mySarMsgCombo->addItem(QString::fromLocal8Bit((*i)->Name()));
246  gSARManager.Drop();
247
248  sarMsgChanged(0);
249}
250
251void Settings::Status::saveSar()
252{
253  SARList& sar = gSARManager.Fetch(mySarGroupCombo->currentIndex());
254  delete sar[mySarMsgCombo->currentIndex()];
255  sar[mySarMsgCombo->currentIndex()] =
256    new CSavedAutoResponse(mySarMsgCombo->currentText().toLocal8Bit().data(),
257        mySartextEdit->toPlainText().toLocal8Bit().data());
258
259  gSARManager.Drop();
260  gSARManager.Save();
261
262  buildAutoStatusCombos(0);
263}
264
265void Settings::Status::showSarHints()
266{
267  gMainWindow->showAutoResponseHints(dynamic_cast<QWidget*>(parent()));
268}
269
270void Settings::Status::load()
271{
272  Config::General* generalConfig = Config::General::instance();
273
274  myDelayStatusChangeCheck->setChecked(generalConfig->delayStatusChange());
275  myAutoAwaySpin->setValue(generalConfig->autoAwayTime());
276  myAutoNaSpin->setValue(generalConfig->autoNaTime());
277  myAutoOfflineSpin->setValue(generalConfig->autoOfflineTime());
278  myAutoLogonCombo->setCurrentIndex(generalConfig->autoLogon() % 10);
279  myAutoLogonInvisibleCheck->setChecked(generalConfig->autoLogon() >= 10);
280  myAutoAwayMessCombo->setCurrentIndex(generalConfig->autoAwayMess());
281  myAutoNaMessCombo->setCurrentIndex(generalConfig->autoNaMess());
282}
283
284void Settings::Status::apply()
285{
286  Config::General* generalConfig = Config::General::instance();
287  generalConfig->blockUpdates(true);
288
289  generalConfig->setDelayStatusChange(myDelayStatusChangeCheck->isChecked());
290  generalConfig->setAutoAwayTime(myAutoAwaySpin->value());
291  generalConfig->setAutoNaTime(myAutoNaSpin->value());
292  generalConfig->setAutoOfflineTime(myAutoOfflineSpin->value());
293  generalConfig->setAutoLogon(myAutoLogonCombo->currentIndex() +
294      (myAutoLogonInvisibleCheck->isChecked() ? 10 : 0));
295  generalConfig->setAutoAwayMess(myAutoAwayMessCombo->currentIndex());
296  generalConfig->setAutoNaMess(myAutoNaMessCombo->currentIndex());
297
298  generalConfig->blockUpdates(false);
299}
Note: See TracBrowser for help on using the browser.