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

Revision 6521, 16.9 kB (checked in by flynd, 2 months ago)

Use strings instead of char* in onevent class so we don't need to keep track of what to deallocate.

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 "events.h"
22
23#include "config.h"
24
25#include <QCheckBox>
26#include <QComboBox>
27#include <QGridLayout>
28#include <QGroupBox>
29#include <QLabel>
30#include <QLineEdit>
31#include <QVBoxLayout>
32
33#include <licq_icqd.h>
34#include <licq_onevent.h>
35
36#include "config/chat.h"
37#include "config/contactlist.h"
38#include "config/general.h"
39#include "core/mainwin.h"
40#include "widgets/filenameedit.h"
41
42#include "settingsdlg.h"
43
44
45using namespace LicqQtGui;
46/* TRANSLATOR LicqQtGui::Settings::Events */
47
48Settings::Events::Events(SettingsDlg* parent)
49  : QObject(parent)
50{
51  parent->addPage(SettingsDlg::OnEventPage, createPageOnEvent(parent),
52      tr("Events"));
53  parent->addPage(SettingsDlg::SoundsPage, createPageSounds(parent),
54      tr("Sounds"), SettingsDlg::OnEventPage);
55
56  load();
57}
58
59QWidget* Settings::Events::createPageOnEvent(QWidget* parent)
60{
61  QWidget* w = new QWidget(parent);
62  myPageOnEventLayout = new QVBoxLayout(w);
63  myPageOnEventLayout->setContentsMargins(0, 0, 0, 0);
64
65  myNewMsgActionsBox = new QGroupBox(tr("Actions On Incoming Messages"));
66  myMsgActionsLayout = new QGridLayout(myNewMsgActionsBox);
67
68  myBoldOnMsgCheck = new QCheckBox(tr("Bold message label"));
69  myBoldOnMsgCheck->setToolTip(tr("Show the message info label in bold font if there are incoming messages"));
70  myMsgActionsLayout->addWidget(myBoldOnMsgCheck, 0, 0);
71
72  myAutoFocusCheck = new QCheckBox(tr("Auto-focus message"));
73  myAutoFocusCheck->setToolTip(tr("Automatically focus opened message windows."));
74  myMsgActionsLayout->addWidget(myAutoFocusCheck, 1, 0);
75
76  myAutoRaiseCheck = new QCheckBox(tr("Auto-raise main window"));
77  myAutoRaiseCheck->setToolTip(tr("Raise the main window on incoming messages"));
78  myMsgActionsLayout->addWidget(myAutoRaiseCheck, 2, 0);
79
80  QHBoxLayout* autoPopupLayout = new QHBoxLayout();
81  QLabel* autoPopupLabel = new QLabel(tr("Auto-popup message:"));
82  autoPopupLayout->addWidget(autoPopupLabel);
83  myAutoPopupCombo = new QComboBox();
84  myAutoPopupCombo->addItem(tr("Never"));
85  myAutoPopupCombo->addItem(tr("Only when online"));
86  myAutoPopupCombo->addItem(tr("When online or away"));
87  myAutoPopupCombo->addItem(tr("When online, away or N/A"));
88  myAutoPopupCombo->addItem(tr("Always except DND"));
89  myAutoPopupCombo->addItem(tr("Always"));
90  myAutoPopupCombo->setToolTip(tr("Select for which statuses incoming messages should "
91      "open automatically.\nOnline also includes Free for chat."));
92  autoPopupLabel->setBuddy(myAutoPopupCombo);
93  autoPopupLayout->addWidget(myAutoPopupCombo);
94  myMsgActionsLayout->addLayout(autoPopupLayout, 3, 0);
95
96  myFlashTaskbarCheck = new QCheckBox(tr("Flash taskbar"));
97  myFlashTaskbarCheck->setToolTip(tr("Flash the taskbar on incoming messages"));
98  myMsgActionsLayout->addWidget(myFlashTaskbarCheck, 0, 1);
99
100  myFlashAllCheck = new QCheckBox(tr("Blink all events"));
101  myFlashAllCheck->setToolTip(tr("All incoming events will blink"));
102  myMsgActionsLayout->addWidget(myFlashAllCheck, 1, 1);
103
104  myFlashUrgentCheck = new QCheckBox(tr("Blink urgent events"));
105  myFlashUrgentCheck->setToolTip(tr("Only urgent events will blink"));
106  myMsgActionsLayout->addWidget(myFlashUrgentCheck, 2, 1);
107
108  QHBoxLayout* hotKeyLayout = new QHBoxLayout();
109  myHotKeyLabel = new QLabel(tr("Hot key:"));
110  hotKeyLayout->addWidget(myHotKeyLabel);
111  myHotKeyLabel->setToolTip(tr("Hotkey to pop up the next pending message.\n"
112      "Enter the hotkey literally, like \"shift+f10\", or \"none\" for disabling."));
113  myHotKeyField = new QLineEdit();
114  myHotKeyField->setToolTip(myHotKeyLabel->toolTip());
115  myHotKeyLabel->setBuddy(myHotKeyField);
116  hotKeyLayout->addWidget(myHotKeyField);
117  myMsgActionsLayout->addLayout(hotKeyLayout, 3, 1);
118
119  // Make the columns evenly wide, otherwise the QLineEdit gets too wide
120  myMsgActionsLayout->setColumnStretch(0, 1);
121  myMsgActionsLayout->setColumnStretch(1, 1);
122
123  myParanoiaBox = new QGroupBox(tr("Paranoia"));
124  myParanoiaLayout = new QVBoxLayout(myParanoiaBox);
125
126  myIgnoreNewUsersCheck = new QCheckBox(tr("Ignore new users"));
127  myIgnoreNewUsersCheck->setToolTip(tr("Determines if new users are automatically added to your list or must first request authorization."));
128  myParanoiaLayout->addWidget(myIgnoreNewUsersCheck);
129
130  myIgnoreMassMsgCheck = new QCheckBox(tr("Ignore mass messages"));
131  myIgnoreMassMsgCheck->setToolTip(tr("Determines if mass messages are ignored or not."));
132  myParanoiaLayout->addWidget(myIgnoreMassMsgCheck);
133
134  myIgnoreWebPanelCheck = new QCheckBox(tr("Ignore web panel"));
135  myIgnoreWebPanelCheck->setToolTip(tr("Determines if web panel messages are ignored or not."));
136  myParanoiaLayout->addWidget(myIgnoreWebPanelCheck);
137
138  myIgnoreEmailPagerCheck = new QCheckBox(tr("Ignore email pager"));
139  myIgnoreEmailPagerCheck->setToolTip(tr("Determines if email pager messages are ignored or not."));
140  myParanoiaLayout->addWidget(myIgnoreEmailPagerCheck);
141
142
143  myPageOnEventLayout->addWidget(myNewMsgActionsBox);
144  myPageOnEventLayout->addWidget(myParanoiaBox);
145  myPageOnEventLayout->addStretch(1);
146
147  return w;
148}
149
150QWidget* Settings::Events::createPageSounds(QWidget* parent)
151{
152  QWidget* w = new QWidget(parent);
153  myPageSoundsLayout = new QVBoxLayout(w);
154  myPageSoundsLayout->setContentsMargins(0, 0, 0, 0);
155
156  QHBoxLayout* mySndTopRowLayout = new QHBoxLayout();
157
158  myOnEventsCheck = new QCheckBox(tr("Sounds enabled"));
159  myOnEventsCheck->setToolTip(tr("Enable running of \"Command\" when the relevant event occurs."));
160  connect(myOnEventsCheck, SIGNAL(toggled(bool)), SLOT(setOnEventsEnabled(bool)));
161  mySndTopRowLayout->addWidget(myOnEventsCheck);
162
163  QWidget* dummy = new QWidget();
164  dummy->setFixedSize(50, 1);
165  mySndTopRowLayout->addWidget(dummy);
166
167  mySndPlayerLabel = new QLabel(tr("Command:"));
168  mySndPlayerLabel->setToolTip("<p>" + tr("Command to execute when an event is received.<br>"
169      "It will be passed the relevant parameters from below.<br>"
170      "Parameters can contain the following expressions <br> "
171      "which will be replaced with the relevant information:") + "</p>" +
172      gMainWindow->usprintfHelp);
173  mySndTopRowLayout->addWidget(mySndPlayerLabel);
174
175  mySndPlayerEdit = new FileNameEdit();
176  mySndPlayerEdit->setToolTip(mySndPlayerLabel->toolTip());
177  mySndPlayerLabel->setBuddy(mySndPlayerEdit);
178  mySndTopRowLayout->addWidget(mySndPlayerEdit);
179
180
181  myEventParamsBox = new QGroupBox(tr("Parameters"));
182  myEventParamsLayout = new QGridLayout(myEventParamsBox);
183
184  mySndMsgLabel = new QLabel(tr("Message:"));
185  mySndMsgLabel->setToolTip(tr("Parameter for received messages"));
186  myEventParamsLayout->addWidget(mySndMsgLabel, 0, 0);
187  mySndMsgEdit = new FileNameEdit();
188  mySndMsgEdit->setToolTip(mySndMsgLabel->toolTip());
189  mySndMsgLabel->setBuddy(mySndMsgEdit);
190  myEventParamsLayout->addWidget(mySndMsgEdit, 0, 1);
191
192  mySndUrlLabel = new QLabel(tr("URL:"));
193  mySndUrlLabel->setToolTip(tr("Parameter for received URLs"));
194  myEventParamsLayout->addWidget(mySndUrlLabel, 1, 0);
195  mySndUrlEdit = new FileNameEdit();
196  mySndUrlEdit->setToolTip(mySndUrlLabel->toolTip());
197  mySndUrlLabel->setBuddy(mySndUrlEdit);
198  myEventParamsLayout->addWidget(mySndUrlEdit, 1, 1);
199
200  mySndChatLabel = new QLabel(tr("Chat request:"));
201  mySndChatLabel->setToolTip(tr("Parameter for received chat requests"));
202  myEventParamsLayout->addWidget(mySndChatLabel, 2, 0);
203  mySndChatEdit = new FileNameEdit();
204  mySndChatEdit->setToolTip(mySndChatLabel->toolTip());
205  mySndChatLabel->setBuddy(mySndChatEdit);
206  myEventParamsLayout->addWidget(mySndChatEdit, 2, 1);
207
208  mySndFileLabel = new QLabel(tr("File transfer:"));
209  mySndFileLabel->setToolTip(tr("Parameter for received file transfers"));
210  myEventParamsLayout->addWidget(mySndFileLabel, 3, 0);
211  mySndFileEdit = new FileNameEdit();
212  mySndFileEdit->setToolTip(mySndFileLabel->toolTip());
213  mySndFileLabel->setBuddy(mySndFileEdit);
214  myEventParamsLayout->addWidget(mySndFileEdit, 3, 1);
215
216  mySndNotifyLabel = new QLabel(tr("Online notify:"));
217  mySndNotifyLabel->setToolTip(tr("Parameter for online notification"));
218  myEventParamsLayout->addWidget(mySndNotifyLabel, 4, 0);
219  mySndNotifyEdit = new FileNameEdit();
220  mySndNotifyEdit->setToolTip(mySndNotifyLabel->toolTip());
221  mySndNotifyLabel->setBuddy(mySndNotifyEdit);
222  myEventParamsLayout->addWidget(mySndNotifyEdit, 4, 1);
223
224  mySndSysMsgLabel = new QLabel(tr("System msg:"));
225  mySndSysMsgLabel->setToolTip(tr("Parameter for received system messages"));
226  myEventParamsLayout->addWidget(mySndSysMsgLabel, 5, 0);
227  mySndSysMsgEdit = new FileNameEdit();
228  mySndSysMsgEdit->setToolTip(mySndSysMsgLabel->toolTip());
229  mySndSysMsgLabel->setBuddy(mySndSysMsgEdit);
230  myEventParamsLayout->addWidget(mySndSysMsgEdit, 5, 1);
231
232  mySndMsgSentLabel = new QLabel(tr("Message sent:"));
233  mySndMsgSentLabel->setToolTip(tr("Parameter for sent messages"));
234  myEventParamsLayout->addWidget(mySndMsgSentLabel, 6, 0);
235  mySndMsgSentEdit = new FileNameEdit();
236  mySndMsgSentEdit->setToolTip(mySndMsgSentLabel->toolTip());
237  mySndMsgSentLabel->setBuddy(mySndMsgSentEdit);
238  myEventParamsLayout->addWidget(mySndMsgSentEdit, 6, 1);
239
240
241  myAcceptEventsBox = new QGroupBox(tr("Enable Events"));
242  myAcceptEventsLayout = new QGridLayout(myAcceptEventsBox);
243
244  myOnEventAwayCheck = new QCheckBox(tr("Sounds when Away"));
245  myOnEventAwayCheck->setToolTip(tr("Perform OnEvent command in away mode"));
246  myAcceptEventsLayout->addWidget(myOnEventAwayCheck, 0, 0);
247
248  myOnEventNaCheck = new QCheckBox(tr("Sounds when N/A"), myAcceptEventsBox);
249  myOnEventNaCheck->setToolTip(tr("Perform OnEvent command in not available mode"));
250  myAcceptEventsLayout->addWidget(myOnEventNaCheck, 1, 0);
251
252  myOnEventOccupiedCheck = new QCheckBox(tr("Sounds when Occupied"), myAcceptEventsBox);
253  myOnEventOccupiedCheck->setToolTip(tr("Perform OnEvent command in occupied mode"));
254  myAcceptEventsLayout->addWidget(myOnEventOccupiedCheck, 2, 0);
255
256  myOnEventDndCheck = new QCheckBox(tr("Sounds when DND"), myAcceptEventsBox);
257  myOnEventDndCheck->setToolTip(tr("Perform OnEvent command in do not disturb mode"));
258  myAcceptEventsLayout->addWidget(myOnEventDndCheck, 3, 0);
259
260  myAlwaysOnlineNotifyCheck = new QCheckBox(tr("Online notify when logging on"), myAcceptEventsBox);
261  myAlwaysOnlineNotifyCheck->setToolTip(tr("Perform the online notify OnEvent "
262     "when logging on (this is different from how the Mirabilis client works)"));
263  myAcceptEventsLayout->addWidget(myAlwaysOnlineNotifyCheck, 0, 1);
264
265
266  myPageSoundsLayout->addLayout(mySndTopRowLayout);
267  myPageSoundsLayout->addWidget(myEventParamsBox);
268  myPageSoundsLayout->addWidget(myAcceptEventsBox);
269  myPageSoundsLayout->addStretch(1);
270
271  setOnEventsEnabled(myOnEventsCheck->isChecked());
272
273  return w;
274}
275
276void Settings::Events::setOnEventsEnabled(bool enable)
277{
278  mySndPlayerEdit->setEnabled(enable);
279  mySndMsgEdit->setEnabled(enable);
280  mySndUrlEdit->setEnabled(enable);
281  mySndChatEdit->setEnabled(enable);
282  mySndFileEdit->setEnabled(enable);
283  mySndNotifyEdit->setEnabled(enable);
284  mySndSysMsgEdit->setEnabled(enable);
285  mySndMsgSentEdit->setEnabled(enable);
286  myOnEventAwayCheck->setEnabled(enable);
287  myOnEventNaCheck->setEnabled(enable);
288  myOnEventOccupiedCheck->setEnabled(enable);
289  myOnEventDndCheck->setEnabled(enable);
290  myAlwaysOnlineNotifyCheck->setEnabled(enable);
291}
292
293void Settings::Events::load()
294{
295  Config::Chat* chatConfig = Config::Chat::instance();
296  Config::ContactList* contactListConfig = Config::ContactList::instance();
297  Config::General* generalConfig = Config::General::instance();
298
299  myAutoRaiseCheck->setChecked(generalConfig->autoRaiseMainwin());
300  myBoldOnMsgCheck->setChecked(generalConfig->boldOnMsg());
301  myHotKeyField->setText(generalConfig->msgPopupKey().isEmpty() ? "none" : generalConfig->msgPopupKey());
302
303  Config::ContactList::FlashMode flash = contactListConfig->flash();
304  myFlashUrgentCheck->setChecked(flash == Config::ContactList::FlashUrgent || flash == Config::ContactList::FlashAll);
305  myFlashAllCheck->setChecked(flash == Config::ContactList::FlashAll);
306
307  myAutoPopupCombo->setCurrentIndex(chatConfig->autoPopup());
308  myAutoFocusCheck->setChecked(chatConfig->autoFocus());
309  myFlashTaskbarCheck->setChecked(chatConfig->flashTaskbar());
310
311  myIgnoreNewUsersCheck->setChecked(gLicqDaemon->Ignore(IGNORE_NEWUSERS));
312  myIgnoreMassMsgCheck->setChecked(gLicqDaemon->Ignore(IGNORE_MASSMSG));
313  myIgnoreWebPanelCheck->setChecked(gLicqDaemon->Ignore(IGNORE_WEBPANEL));
314  myIgnoreEmailPagerCheck->setChecked(gLicqDaemon->Ignore(IGNORE_EMAILPAGER));
315
316  COnEventManager* oem = gLicqDaemon->OnEventManager();
317  myOnEventsCheck->setChecked(oem->CommandType() != ON_EVENT_IGNORE);
318  oem->Lock();
319  mySndPlayerEdit->setFileName(QString::fromStdString(oem->command()));
320  mySndMsgEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_MSG)));
321  mySndUrlEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_URL)));
322  mySndChatEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_CHAT)));
323  mySndFileEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_FILE)));
324  mySndNotifyEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_NOTIFY)));
325  mySndSysMsgEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_SYSMSG)));
326  mySndMsgSentEdit->setFileName(QString::fromStdString(oem->parameter(ON_EVENT_MSGSENT)));
327  oem->Unlock();
328
329  //TODO make general for all plugins
330  const ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_R);
331  if (o != NULL)
332  {
333    myOnEventAwayCheck->setChecked(o->AcceptInAway());
334    myOnEventNaCheck->setChecked(o->AcceptInNA());
335    myOnEventOccupiedCheck->setChecked(o->AcceptInOccupied());
336    myOnEventDndCheck->setChecked(o->AcceptInDND());
337    gUserManager.DropOwner(o);
338  }
339  myAlwaysOnlineNotifyCheck->setChecked(gLicqDaemon->AlwaysOnlineNotify());
340}
341
342void Settings::Events::apply()
343{
344  Config::Chat* chatConfig = Config::Chat::instance();
345  Config::ContactList* contactListConfig = Config::ContactList::instance();
346  Config::General* generalConfig = Config::General::instance();
347  chatConfig->blockUpdates(true);
348  contactListConfig->blockUpdates(true);
349  generalConfig->blockUpdates(true);
350
351  generalConfig->setAutoRaiseMainwin(myAutoRaiseCheck->isChecked());
352  generalConfig->setBoldOnMsg(myBoldOnMsgCheck->isChecked());
353  generalConfig->setMsgPopupKey(myHotKeyField->text() != "none" ? myHotKeyField->text() : QString());
354
355  if (myFlashAllCheck->isChecked())
356    contactListConfig->setFlash(Config::ContactList::FlashAll);
357  else if(myFlashUrgentCheck->isChecked())
358    contactListConfig->setFlash(Config::ContactList::FlashUrgent);
359  else
360    contactListConfig->setFlash(Config::ContactList::FlashNone);
361
362  chatConfig->setAutoPopup(myAutoPopupCombo->currentIndex());
363  chatConfig->setAutoFocus(myAutoFocusCheck->isChecked());
364  chatConfig->setFlashTaskbar(myFlashTaskbarCheck->isChecked());
365
366  gLicqDaemon->SetIgnore(IGNORE_NEWUSERS, myIgnoreNewUsersCheck->isChecked());
367  gLicqDaemon->SetIgnore(IGNORE_MASSMSG, myIgnoreMassMsgCheck->isChecked());
368  gLicqDaemon->SetIgnore(IGNORE_WEBPANEL, myIgnoreWebPanelCheck->isChecked());
369  gLicqDaemon->SetIgnore(IGNORE_EMAILPAGER, myIgnoreEmailPagerCheck->isChecked());
370
371  COnEventManager* oem = gLicqDaemon->OnEventManager();
372  oem->SetCommandType(myOnEventsCheck->isChecked() ? ON_EVENT_RUN : ON_EVENT_IGNORE);
373
374  oem->setCommand(mySndPlayerEdit->fileName().toStdString());
375  oem->setParameter(ON_EVENT_MSG, mySndMsgEdit->fileName().toStdString());
376  oem->setParameter(ON_EVENT_URL, mySndUrlEdit->fileName().toStdString());
377  oem->setParameter(ON_EVENT_CHAT, mySndChatEdit->fileName().toStdString());
378  oem->setParameter(ON_EVENT_FILE, mySndFileEdit->fileName().toStdString());
379  oem->setParameter(ON_EVENT_NOTIFY, mySndNotifyEdit->fileName().toStdString());
380  oem->setParameter(ON_EVENT_SYSMSG, mySndSysMsgEdit->fileName().toStdString());
381  oem->setParameter(ON_EVENT_MSGSENT, mySndMsgSentEdit->fileName().toStdString());
382
383  //TODO Make general for all plugins
384  ICQOwner* o = gUserManager.FetchOwner(LICQ_PPID, LOCK_W);
385  if (o)
386  {
387    o->SetEnableSave(false);
388    o->SetAcceptInAway(myOnEventAwayCheck->isChecked());
389    o->SetAcceptInNA(myOnEventNaCheck->isChecked());
390    o->SetAcceptInOccupied(myOnEventOccupiedCheck->isChecked());
391    o->SetAcceptInDND(myOnEventDndCheck->isChecked());
392    o->SetEnableSave(true);
393    o->SaveLicqInfo();
394    gUserManager.DropOwner(o);
395  }
396  gLicqDaemon->SetAlwaysOnlineNotify(myAlwaysOnlineNotifyCheck->isChecked());
397
398  chatConfig->blockUpdates(false);
399  contactListConfig->blockUpdates(false);
400  generalConfig->blockUpdates(false);
401}
Note: See TracBrowser for help on using the browser.