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

Revision 6543, 28.3 kB (checked in by root_42, 3 weeks ago)

Allow user to override Qt 4 browser selection.
Introduced new option for that.
Fixes #1645, or rather implements a new feature for this to be fixed.

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 "chat.h"
22
23#include "config.h"
24
25#include <QCheckBox>
26#include <QComboBox>
27#include <QDateTime>
28#include <QGridLayout>
29#include <QGroupBox>
30#include <QHBoxLayout>
31#include <QLabel>
32#include <QLineEdit>
33#include <QSpinBox>
34#include <QTextCodec>
35#include <QVBoxLayout>
36
37#include <licq_icqd.h>
38
39#include "config/chat.h"
40#include "config/general.h"
41
42#include "core/gui-defines.h"
43
44#include "helpers/usercodec.h"
45
46#include "widgets/colorbutton.h"
47#include "widgets/historyview.h"
48#include "widgets/tabwidget.h"
49
50#include "settingsdlg.h"
51
52using namespace LicqQtGui;
53/* TRANSLATOR LicqQtGui::Settings::Chat */
54
55Settings::Chat::Chat(SettingsDlg* parent)
56  : QObject(parent)
57{
58  parent->addPage(SettingsDlg::ChatPage, createPageChat(parent),
59      tr("Chat"));
60  parent->addPage(SettingsDlg::ChatDispPage, createPageChatDisp(parent),
61      tr("Chat Display"), SettingsDlg::ChatPage);
62  parent->addPage(SettingsDlg::HistDispPage, createPageHistDisp(parent),
63      tr("History Display"), SettingsDlg::ChatPage);
64
65  load();
66}
67
68QWidget* Settings::Chat::createPageChat(QWidget* parent)
69{
70  QWidget* w = new QWidget(parent);
71  myPageChatLayout = new QVBoxLayout(w);
72  myPageChatLayout->setContentsMargins(0, 0, 0, 0);
73
74  myChatBox = new QGroupBox(tr("General Chat Options"));
75  myChatLayout = new QGridLayout(myChatBox);
76
77  myMsgChatViewCheck = new QCheckBox(tr("Chatmode messageview"));
78  myMsgChatViewCheck->setToolTip(tr("Show the current chat history in Send Window"));
79  connect(myMsgChatViewCheck, SIGNAL(toggled(bool)), SLOT(useMsgChatViewChanged(bool)));
80  myChatLayout->addWidget(myMsgChatViewCheck, 0, 0);
81
82  myTabbedChattingCheck = new QCheckBox(tr("Tabbed chatting"));
83  myTabbedChattingCheck->setToolTip(tr("Use tabs in Send Window"));
84  myChatLayout->addWidget(myTabbedChattingCheck, 1, 0);
85
86  mySingleLineChatModeCheck = new QCheckBox(tr("Single line chat mode"));
87  mySingleLineChatModeCheck->setToolTip(tr("Send messages with Return and insert new lines with Ctrl+Return, opposite of the normal mode"));
88  myChatLayout->addWidget(mySingleLineChatModeCheck, 0, 1);
89
90  myUseDoubleReturnCheck = new QCheckBox(tr("Use double return"));
91  myUseDoubleReturnCheck->setToolTip(tr("Hitting Return twice will be used instead of Ctrl+Return\n"
92      "to send messages and close input dialogs.\n"
93      "Multiple new lines can be inserted with Ctrl+Return."));
94  myChatLayout->addWidget(myUseDoubleReturnCheck, 1, 1);
95
96  myShowSendCloseCheck = new QCheckBox(tr("Show Send/Close buttons"));
97  myShowSendCloseCheck->setToolTip(tr("Show Send and Close buttons in the chat dialog."));
98  myChatLayout->addWidget(myShowSendCloseCheck, 2, 0);
99
100  myPopupAutoResponseCheck = new QCheckBox(tr("Popup auto response"));
101  myPopupAutoResponseCheck->setToolTip(tr("Popup auto responses received when sending to contacts that are away."));
102  myChatLayout->addWidget(myPopupAutoResponseCheck, 2, 1);
103
104  myMsgWinStickyCheck = new QCheckBox(tr("Sticky message window(s)"));
105  myMsgWinStickyCheck->setToolTip(tr("Makes the message window(s) visible on all desktops"));
106  myChatLayout->addWidget(myMsgWinStickyCheck, 3, 0);
107
108  myAutoCloseCheck = new QCheckBox(tr("Auto close function window"));
109  myAutoCloseCheck->setToolTip(tr("Auto close the user function window after a successful event"));
110  myChatLayout->addWidget(myAutoCloseCheck, 3, 1);
111
112  mySendFromClipboardCheck = new QCheckBox(tr("Check clipboard For URIs/files"));
113  mySendFromClipboardCheck->setToolTip(tr("When double-clicking on a user to send a message check for urls/files in the clipboard"));
114  myChatLayout->addWidget(mySendFromClipboardCheck, 4, 0);
115
116  myAutoPosReplyWinCheck = new QCheckBox(tr("Auto position the reply window"));
117  myAutoPosReplyWinCheck->setToolTip(tr("Position a new reply window just underneath the message view window"));
118  myChatLayout->addWidget(myAutoPosReplyWinCheck, 4, 1);
119
120  myAutoSendThroughServerCheck = new QCheckBox(tr("Auto send through server"));
121  myAutoSendThroughServerCheck->setToolTip(tr("Automatically send messages through the server if direct connection fails"));
122  myChatLayout->addWidget(myAutoSendThroughServerCheck, 5, 0);
123
124  mySendTNCheck = new QCheckBox(tr("Send typing notifications"));
125  mySendTNCheck->setToolTip(tr("Send a notification to the user so they can see when you are typing a message to them"));
126  myChatLayout->addWidget(mySendTNCheck, 5, 1);
127
128  myShowUserPicCheck = new QCheckBox(tr("Show user picture"));
129  myShowUserPicCheck->setToolTip(tr("Show user picture next to the input area"));
130  myChatLayout->addWidget(myShowUserPicCheck, 6, 0);
131
132  myShowUserPicHiddenCheck = new QCheckBox(tr("Minimize user picture"));
133  myShowUserPicHiddenCheck->setToolTip(tr("Hide user picture upon opening"));
134  myChatLayout->addWidget(myShowUserPicHiddenCheck, 6, 1);
135
136  myCheckSpelling = new QCheckBox(tr("Check spelling"));
137  myCheckSpelling->setToolTip(tr("Mark misspelled words as you type."));
138#ifndef USE_KDE
139  myCheckSpelling->setVisible(false);
140#endif
141  myChatLayout->addWidget(myCheckSpelling, 7, 0);
142
143
144  myLocaleBox = new QGroupBox(tr("Localization"));
145  myLocaleLayout = new QVBoxLayout(myLocaleBox);
146
147  QHBoxLayout* defaultEncodingLayout = new QHBoxLayout();
148  myDefaultEncodingLabel = new QLabel(tr("Default encoding:"));
149  myDefaultEncodingLabel->setToolTip(tr(
150      "Sets which default encoding should be used for newly added contacts."));
151  defaultEncodingLayout->addWidget(myDefaultEncodingLabel);
152  myDefaultEncodingCombo = new QComboBox();
153  myDefaultEncodingCombo->addItem(tr("System default (%1)").arg(
154      QString(QTextCodec::codecForLocale()->name())));
155  {
156    UserCodec::encoding_t* it = &UserCodec::m_encodings[0];
157    while (it->encoding != NULL)
158    {
159      myDefaultEncodingCombo->addItem(UserCodec::nameForEncoding(it->encoding));
160      ++it;
161    }
162  }
163  myDefaultEncodingCombo->setToolTip(myDefaultEncodingLabel->toolTip());
164  myDefaultEncodingLabel->setBuddy(myDefaultEncodingCombo);
165  defaultEncodingLayout->addWidget(myDefaultEncodingCombo);
166  myLocaleLayout->addLayout(defaultEncodingLayout);
167
168  myShowAllEncodingsCheck = new QCheckBox(tr("Show all encodings"));
169  myShowAllEncodingsCheck->setToolTip(tr(
170      "Show all available encodings in the User Encoding selection menu.\n"
171      "Normally, this menu shows only commonly used encodings."));
172  myLocaleLayout->addWidget(myShowAllEncodingsCheck);
173
174
175  myExtensionsBox = new QGroupBox(tr("Extensions"));
176  myExtensionsLayout = new QGridLayout(myExtensionsBox);
177  myExtensionsLayout->setColumnStretch(1, 1);
178
179  myTerminalLabel = new QLabel(tr("Terminal:"));
180  myTerminalLabel->setToolTip(tr("The command to run to start your terminal program."));
181  myExtensionsLayout->addWidget(myTerminalLabel, 0, 0);
182
183  myTerminalEdit = new QLineEdit(tr("Terminal:"));
184  myTerminalEdit->setToolTip(myTerminalLabel->toolTip());
185  myTerminalLabel->setBuddy(myTerminalEdit);
186  myExtensionsLayout->addWidget(myTerminalEdit, 0, 1);
187
188  myUseCustomUrlViewer = new QCheckBox(tr("Use custom URI viewer"));
189  myUseCustomUrlViewer->setToolTip(tr("Use a custom browser for URIs, instead of the system wide setting."));
190  myExtensionsLayout->addWidget(myUseCustomUrlViewer, 1, 0, 1, 2);
191
192  myUrlViewerLabel = new QLabel(tr("URI viewer:"));
193  myUrlViewerLabel->setToolTip(tr("The command to run in case Qt is unable to open an URL.\n"
194        "It is passed an URL as the last parameter.\n"
195        "Refer to the hints dialog for Qt URL handling rules."));
196  myExtensionsLayout->addWidget(myUrlViewerLabel, 2, 0);
197
198  myUrlViewerCombo = new QComboBox();
199  myUrlViewerCombo->setEditable(true);
200  myUrlViewerCombo->addItem("viewurl-firefox.sh");
201  myUrlViewerCombo->addItem("viewurl-firefox.sh");
202  myUrlViewerCombo->addItem("viewurl-lynx.sh");
203  myUrlViewerCombo->addItem("viewurl-mozilla.sh");
204  myUrlViewerCombo->addItem("viewurl-ncftp.sh");
205  myUrlViewerCombo->addItem("viewurl-netscape.sh");
206  myUrlViewerCombo->addItem("viewurl-opera.sh");
207  myUrlViewerCombo->addItem("viewurl-seamonkey.sh");
208  myUrlViewerCombo->addItem("viewurl-w3m.sh");
209  myUrlViewerCombo->setToolTip(myUrlViewerLabel->toolTip());
210  myUrlViewerLabel->setBuddy(myUrlViewerCombo);
211  myExtensionsLayout->addWidget(myUrlViewerCombo, 2, 1);
212#ifdef USE_KDE
213  myUseCustomUrlViewer->setVisible(false);
214  myUrlViewerLabel->setVisible(false);
215  myUrlViewerCombo->setVisible(false);
216#else
217  connect(myUseCustomUrlViewer, SIGNAL(toggled(bool)), myUrlViewerCombo, SLOT(setEnabled(bool)));
218  connect(myUseCustomUrlViewer, SIGNAL(toggled(bool)), myUrlViewerLabel, SLOT(setEnabled(bool)));
219#endif
220
221  myPageChatLayout->addWidget(myChatBox);
222  myPageChatLayout->addWidget(myLocaleBox);
223  myPageChatLayout->addWidget(myExtensionsBox);
224  myPageChatLayout->addStretch(1);
225
226  return w;
227}
228
229static const int dateFormatsLength = 7;
230static const char* const dateFormats[dateFormatsLength] = {
231    "hh:mm:ss",
232    "yyyy-MM-dd hh:mm:ss",
233    "yyyy-MM-dd",
234    "yyyy/MM/dd hh:mm:ss",
235    "yyyy/MM/dd",
236    "dd.MM.yyyy hh:mm:ss",
237    "dd.MM.yyyy"
238};
239
240static const char* const helpDateFormat
241  = QT_TRANSLATE_NOOP("LicqQtGui::OptionsDlg",
242    "<p>Available custom date format variables.</p>"
243    "<table>"
244    "<tr><th>Expression</th><th>Output</th></tr>"
245    "<tr><td>d</td><td>the day as number without a leading zero (1-31)</td></tr>"
246    "<tr><td>dd</td><td>the day as number with a leading zero (01-31)</td></tr>"
247    "<tr><td>ddd</td><td>the abbreviated localized day name (e.g. 'Mon'..'Sun')</td></tr>"
248    "<tr><td>dddd</td><td>the long localized day name (e.g. 'Monday'..'Sunday')</td></tr>"
249    "<tr><td>M</td><td>the month as number without a leading zero (1-12)</td></tr>"
250    "<tr><td>MM</td><td>the month as number with a leading zero (01-12)</td></tr>"
251    "<tr><td>MMM</td><td>the abbreviated localized month name (e.g. 'Jan'..'Dec')</td></tr>"
252    "<tr><td>MMMM</td><td>the long localized month name (e.g. 'January'..'December')</td></tr>"
253    "<tr><td>yy</td><td>the year as two digit number (00-99)</td></tr>"
254    "<tr><td>yyyy</td><td>the year as four digit number (1752-8000)</td></tr>"
255    "<tr><td colspan=2></td></tr>"
256    "<tr><td>h</td><td>the hour without a leading zero (0..23 or 1..12 if AM/PM display)</td></tr>"
257    "<tr><td>hh</td><td>the hour with a leading zero (00..23 or 01..12 if AM/PM display)</td></tr>"
258    "<tr><td>m</td><td>the minute without a leading zero (0..59)</td></tr>"
259    "<tr><td>mm</td><td>the minute with a leading zero (00..59)</td></tr>"
260    "<tr><td>s</td><td>the second without a leading zero (0..59)</td></tr>"
261    "<tr><td>ss</td><td>the second with a leading zero (00..59)</td></tr>"
262    "<tr><td>z</td><td>the millisecond without leading zero (0..999)</td></tr>"
263    "<tr><td>zzz</td><td>the millisecond with leading zero (000..999)</td></tr>"
264    "<tr><td>AP</td><td>use AM/PM display. AP will be replaced by either 'AM' or 'PM'</td></tr>"
265    "<tr><td>ap</td><td>use am/pm display. ap will be replaced by either 'am' or 'pm'</td></tr>"
266    "</table>"
267  );
268
269QWidget* Settings::Chat::createPageChatDisp(QWidget* parent)
270{
271  QWidget* w = new QWidget(parent);
272  myPageChatDispLayout = new QGridLayout(w);
273  myPageChatDispLayout->setContentsMargins(0, 0, 0, 0);
274  myPageChatDispLayout->setRowStretch(1, 1);
275
276  myChatDispBox = new QGroupBox(tr("Chat Display"));
277  myChatDispLayout = new QVBoxLayout(myChatDispBox);
278
279  QHBoxLayout* myChatLayoutStyle = new QHBoxLayout();
280  myChatStyleLabel = new QLabel(tr("Style:"));
281  myChatLayoutStyle->addWidget(myChatStyleLabel);
282  myChatStyleCombo = new QComboBox();
283  myChatStyleCombo->addItems(HistoryView::getStyleNames(false));
284  myChatStyleLabel->setBuddy(myChatStyleCombo);
285  connect(myChatStyleCombo, SIGNAL(activated(int)), SLOT(updatePreviews()));
286  myChatLayoutStyle->addWidget(myChatStyleCombo);
287  myChatDispLayout->addLayout(myChatLayoutStyle);
288
289  QHBoxLayout* myChatLayoutDateFormat = new QHBoxLayout();
290  myChatDateFormatLabel = new QLabel(tr("Date format:"));
291  myChatDateFormatLabel->setToolTip(tr(helpDateFormat));
292  myChatLayoutDateFormat->addWidget(myChatDateFormatLabel);
293  myChatDateFormatCombo = new QComboBox();
294  myChatDateFormatCombo->setEditable(true);
295  myChatDateFormatCombo->setToolTip(myChatDateFormatLabel->toolTip());
296  myChatDateFormatLabel->setBuddy(myChatDateFormatCombo);
297  for(int i = 0; i < dateFormatsLength; ++i)
298    myChatDateFormatCombo->addItem(dateFormats[i]);
299  connect(myChatDateFormatCombo, SIGNAL(activated(int)), SLOT(updatePreviews()));
300  connect(myChatDateFormatCombo, SIGNAL(editTextChanged(const QString&)), SLOT(updatePreviews()));
301  myChatLayoutDateFormat->addWidget(myChatDateFormatCombo);
302  myChatDispLayout->addLayout(myChatLayoutDateFormat);
303
304  myChatVertSpacingCheck = new QCheckBox(tr("Insert vertical spacing"));
305  connect(myChatVertSpacingCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
306  myChatVertSpacingCheck->setToolTip(tr("Insert extra space between messages."));
307  myChatDispLayout->addWidget(myChatVertSpacingCheck);
308
309  myChatLineBreakCheck = new QCheckBox(tr("Insert horizontal line"));
310  connect(myChatLineBreakCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
311  myChatLineBreakCheck->setToolTip(tr("Insert a line between each message."));
312  myChatDispLayout->addWidget(myChatLineBreakCheck);
313
314  myShowHistoryCheck = new QCheckBox(tr("Show recent messages"));
315  myShowHistoryCheck->setToolTip(tr("Show the last 5 messages when a Send Window is opened"));
316  connect(myShowHistoryCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
317  myChatDispLayout->addWidget(myShowHistoryCheck);
318
319  myShowNoticesCheck = new QCheckBox(tr("Show join/left notices"));
320  myShowNoticesCheck->setToolTip(tr("Show a notice in the chat window when a user joins or leaves the conversation."));
321  connect(myShowNoticesCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
322  myChatDispLayout->addWidget(myShowNoticesCheck);
323
324  myChatDispLayout->addStretch(1);
325
326
327  myChatColorsBox = new QGroupBox(tr("Colors"));
328  myChatColorsLayout = new QGridLayout(myChatColorsBox);
329
330  myColorRcvLabel = new QLabel(tr("Message received:"));
331  myChatColorsLayout->addWidget(myColorRcvLabel, 0, 0);
332  myColorRcvButton = new ColorButton();
333  connect(myColorRcvButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
334  myChatColorsLayout->addWidget(myColorRcvButton, 0, 1);
335
336  myColorSntLabel = new QLabel(tr("Message sent:"));
337  myChatColorsLayout->addWidget(myColorSntLabel, 1, 0);
338  myColorSntButton = new ColorButton();
339  connect(myColorSntButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
340  myChatColorsLayout->addWidget(myColorSntButton, 1, 1);
341
342  myColorRcvHistoryLabel = new QLabel(tr("History received:"));
343  myChatColorsLayout->addWidget(myColorRcvHistoryLabel, 2, 0);
344  myColorRcvHistoryButton = new ColorButton();
345  connect(myColorRcvHistoryButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
346  myChatColorsLayout->addWidget(myColorRcvHistoryButton, 2, 1);
347
348  myColorSntHistoryLabel = new QLabel(tr("History sent:"));
349  myChatColorsLayout->addWidget(myColorSntHistoryLabel, 3, 0);
350  myColorSntHistoryButton = new ColorButton();
351  connect(myColorSntHistoryButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
352  myChatColorsLayout->addWidget(myColorSntHistoryButton, 3, 1);
353
354  myColorNoticeLabel = new QLabel(tr("Notice:"));
355  myChatColorsLayout->addWidget(myColorNoticeLabel, 4, 0);
356  myColorNoticeButton = new ColorButton();
357  connect(myColorNoticeButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
358  myChatColorsLayout->addWidget(myColorNoticeButton, 4, 1);
359
360  myColorTypingLabelLabel = new QLabel(tr("Typing notification color:"));
361  myChatColorsLayout->addWidget(myColorTypingLabelLabel, 5, 0);
362  myColorTypingLabelButton = new ColorButton();
363  connect(myColorTypingLabelButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
364  myChatColorsLayout->addWidget(myColorTypingLabelButton, 5, 1);
365
366  myColorChatBkgLabel = new QLabel(tr("Background color:"));
367  myChatColorsLayout->addWidget(myColorChatBkgLabel, 6, 0);
368  myColorChatBkgButton = new ColorButton();
369  connect(myColorChatBkgButton, SIGNAL(changed(const QColor&)), SLOT(updatePreviews()));
370  myChatColorsLayout->addWidget(myColorChatBkgButton, 6, 1);
371
372  myChatColorsLayout->setRowStretch(7, 1);
373
374  myChatTabs = new TabWidget(w);
375  myChatView = new HistoryView(false, QString(), 0, myChatTabs);
376  myChatTabs->addTab(myChatView, "Marge");
377
378  myPageChatDispLayout->addWidget(myChatDispBox, 0, 0);
379  myPageChatDispLayout->addWidget(myChatColorsBox, 0, 1);
380  myPageChatDispLayout->addWidget(myChatTabs, 1, 0, 1, 2);
381
382  return w;
383}
384
385QWidget* Settings::Chat::createPageHistDisp(QWidget* parent)
386{
387  QWidget* w = new QWidget(parent);
388  myPageHistDispLayout = new QVBoxLayout(w);
389  myPageHistDispLayout->setContentsMargins(0, 0, 0, 0);
390
391  myHistDispBox = new QGroupBox(tr("History Display"));
392  myHistDispLayout = new QVBoxLayout(myHistDispBox);
393
394  QHBoxLayout* myHistStyleLayout = new QHBoxLayout();
395  myHistStyleLabel = new QLabel(tr("Style:"));
396  myHistStyleLayout->addWidget(myHistStyleLabel);
397  myHistStyleCombo = new QComboBox();
398  myHistStyleCombo->addItems(HistoryView::getStyleNames(true));
399  myHistStyleLabel->setBuddy(myHistStyleCombo);
400  connect(myHistStyleCombo, SIGNAL(activated(int)), SLOT(updatePreviews()));
401  myHistStyleLayout->addWidget(myHistStyleCombo);
402  myHistDispLayout->addLayout(myHistStyleLayout);
403
404  QHBoxLayout* myHistDateFormatLayout = new QHBoxLayout();
405  myHistDateFormatLabel = new QLabel(tr("Date format:"));
406  myHistDateFormatLabel->setToolTip(tr(helpDateFormat));
407  myHistDateFormatLayout->addWidget(myHistDateFormatLabel);
408  myHistDateFormatCombo = new QComboBox();
409  myHistDateFormatCombo->setEditable(true);
410  for(int i = 0; i < dateFormatsLength; ++i)
411    myHistDateFormatCombo->addItem(dateFormats[i]);
412  myHistDateFormatCombo->setToolTip(myHistDateFormatLabel->toolTip());
413  myHistDateFormatLabel->setBuddy(myHistDateFormatCombo);
414  connect(myHistDateFormatCombo, SIGNAL(activated(int)), SLOT(updatePreviews()));
415  connect(myHistDateFormatCombo, SIGNAL(editTextChanged(const QString&)), SLOT(updatePreviews()));
416  myHistDateFormatLayout->addWidget(myHistDateFormatCombo);
417  myHistDispLayout->addLayout(myHistDateFormatLayout);
418
419  QHBoxLayout* myHistOptsLayout = new QHBoxLayout();
420  myHistVertSpacingCheck = new QCheckBox(tr("Insert vertical spacing"));
421  connect(myHistVertSpacingCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
422  myHistVertSpacingCheck->setToolTip(tr("Insert extra space between messages."));
423  myHistOptsLayout->addWidget(myHistVertSpacingCheck);
424
425  myHistReverseCheck = new QCheckBox(tr("Reverse history"));
426  connect(myHistReverseCheck, SIGNAL(toggled(bool)), SLOT(updatePreviews()));
427  myHistReverseCheck->setToolTip(tr("Put recent messages on top."));
428  myHistOptsLayout->addWidget(myHistReverseCheck);
429  myHistDispLayout->addLayout(myHistOptsLayout);
430
431  myHistPreviewBox = new QGroupBox(tr("Preview"));
432  myHistPreviewLayout = new QVBoxLayout(myHistPreviewBox);
433
434  myHistoryView = new HistoryView(true);
435  myHistPreviewLayout->addWidget(myHistoryView);
436
437  myPageHistDispLayout->addWidget(myHistDispBox);
438  myPageHistDispLayout->addWidget(myHistPreviewBox);
439
440  return w;
441}
442
443void Settings::Chat::useMsgChatViewChanged(bool b)
444{
445  if (!b)
446  {
447    myTabbedChattingCheck->setChecked(false);
448    myShowHistoryCheck->setChecked(false);
449    myShowNoticesCheck->setEnabled(false);
450  }
451
452  myTabbedChattingCheck->setEnabled(b);
453  myShowHistoryCheck->setEnabled(b);
454  myShowNoticesCheck->setEnabled(b);
455}
456
457void Settings::Chat::updatePreviews()
458{
459  // Don't update the time at every refresh
460  static QDateTime date = QDateTime::currentDateTime();
461
462  const char* const names[2] = {"Marge", "Homer"};
463  const char* const msgs[8] = {
464      QT_TR_NOOP("This is a received message"),
465      QT_TR_NOOP("This is a sent message"),
466      QT_TR_NOOP("Have you gone to the Licq IRC Channel?"),
467      QT_TR_NOOP("No, where is it?"),
468      QT_TR_NOOP("#Licq on irc.freenode.net"),
469      QT_TR_NOOP("Cool, I'll see you there :)"),
470      QT_TR_NOOP("We'll be waiting!"),
471      QT_TR_NOOP("Marge has left the conversation.")
472  };
473
474  myChatView->setChatConfig(myChatStyleCombo->currentIndex(), myChatDateFormatCombo->currentText(),
475      myChatVertSpacingCheck->isChecked(), myChatLineBreakCheck->isChecked(), myShowNoticesCheck->isChecked());
476
477  myChatView->setColors(myColorChatBkgButton->colorName(), myColorRcvButton->colorName(),
478      myColorSntButton->colorName(), myColorRcvHistoryButton->colorName(),
479      myColorSntHistoryButton->colorName(), myColorNoticeButton->colorName());
480  myChatTabs->setTabColor(myChatView, myColorTypingLabelButton->color());
481
482  myHistoryView->setHistoryConfig(myHistStyleCombo->currentIndex(), myHistDateFormatCombo->currentText(),
483      myHistVertSpacingCheck->isChecked(), myHistReverseCheck->isChecked());
484  myHistoryView->setColors(myColorChatBkgButton->colorName(), myColorRcvButton->colorName(), myColorSntButton->colorName());
485
486  myChatView->clear();
487  myHistoryView->clear();
488
489  QDateTime msgDate = date;
490  for (unsigned int i = 0; i<7; i++)
491  {
492    if (i < 2 && myShowHistoryCheck->isChecked() == false)
493      continue;
494
495    myChatView->addMsg(i%2 == 0 ? D_RECEIVER : D_SENDER, (i<2),
496          QString(""),
497          msgDate,
498          true, false, false, false,
499          names[i % 2],
500          MLView::toRichText(tr(msgs[i]), true, true));
501
502    myHistoryView->addMsg(i%2 == 0 ? D_RECEIVER : D_SENDER, false,
503          QString(""),
504          msgDate,
505          true, false, false, false,
506          names[i % 2],
507          MLView::toRichText(tr(msgs[i]), true, true));
508
509    msgDate = msgDate.addSecs(i + 12);
510  }
511  msgDate = msgDate.addSecs(12);
512  myChatView->addNotice(msgDate, MLView::toRichText(tr(msgs[7]), true, true));
513
514  myHistoryView->updateContent();
515}
516
517void Settings::Chat::load()
518{
519  Config::Chat* chatConfig = Config::Chat::instance();
520  Config::General* generalConfig = Config::General::instance();
521
522  myUseDoubleReturnCheck->setChecked(generalConfig->useDoubleReturn());
523
524  myAutoCloseCheck->setChecked(chatConfig->autoClose());
525  mySendFromClipboardCheck->setChecked(chatConfig->sendFromClipboard());
526  myMsgChatViewCheck->setChecked(chatConfig->msgChatView());
527  myChatDateFormatCombo->lineEdit()->setText(chatConfig->chatDateFormat());
528  myChatVertSpacingCheck->setChecked(chatConfig->chatVertSpacing());
529  myChatLineBreakCheck->setChecked(chatConfig->chatAppendLineBreak());
530  myChatStyleCombo->setCurrentIndex(chatConfig->chatMsgStyle());
531  myHistStyleCombo->setCurrentIndex(chatConfig->histMsgStyle());
532  myHistVertSpacingCheck->setChecked(chatConfig->histVertSpacing());
533  myHistReverseCheck->setChecked(chatConfig->reverseHistory());
534  myHistDateFormatCombo->lineEdit()->setText(chatConfig->histDateFormat());
535  myColorRcvButton->setColor(chatConfig->recvColor());
536  myColorSntButton->setColor(chatConfig->sentColor());
537  myColorRcvHistoryButton->setColor(chatConfig->recvHistoryColor());
538  myColorSntHistoryButton->setColor(chatConfig->sentHistoryColor());
539  myColorNoticeButton->setColor(chatConfig->noticeColor());
540  myColorTypingLabelButton->setColor(chatConfig->tabTypingColor());
541  myColorChatBkgButton->setColor(chatConfig->chatBackColor());
542  myAutoPosReplyWinCheck->setChecked(chatConfig->autoPosReplyWin());
543  myAutoSendThroughServerCheck->setChecked(chatConfig->autoSendThroughServer());
544  myShowSendCloseCheck->setChecked(chatConfig->showDlgButtons());
545  myCheckSpelling->setChecked(chatConfig->checkSpelling());
546  myMsgWinStickyCheck->setChecked(chatConfig->msgWinSticky());
547  mySingleLineChatModeCheck->setChecked(chatConfig->singleLineChatMode());
548  myTabbedChattingCheck->setChecked(chatConfig->tabbedChatting());
549  myShowHistoryCheck->setChecked(chatConfig->showHistory());
550  myShowNoticesCheck->setChecked(chatConfig->showNotices());
551  myShowUserPicCheck->setChecked(chatConfig->showUserPic());
552  myShowUserPicHiddenCheck->setChecked(chatConfig->showUserPicHidden());
553  myPopupAutoResponseCheck->setChecked(chatConfig->popupAutoResponse());
554
555  myUseCustomUrlViewer->setChecked(chatConfig->useCustomUrlBrowser());
556  if (!chatConfig->useCustomUrlBrowser())
557  {
558    myUrlViewerLabel->setEnabled(false);
559    myUrlViewerCombo->setEnabled(false);
560  }
561
562  if (!chatConfig->msgChatView())
563  {
564    myTabbedChattingCheck->setEnabled(false);
565    myShowHistoryCheck->setEnabled(false);
566    myShowNoticesCheck->setChecked(false);
567  }
568
569  mySendTNCheck->setChecked(gLicqDaemon->SendTypingNotification());
570
571  QByteArray defaultEncoding = gUserManager.DefaultUserEncoding();
572  if (defaultEncoding.isEmpty())
573    myDefaultEncodingCombo->setCurrentIndex(0);
574  else
575  {
576    for (int i = 1; i < myDefaultEncodingCombo->count(); i++)
577    {
578      if (UserCodec::encodingForName(myDefaultEncodingCombo->itemText(i)) == defaultEncoding)
579      {
580        myDefaultEncodingCombo->setCurrentIndex(i);
581        break;
582      }
583    }
584  }
585  myShowAllEncodingsCheck->setChecked(chatConfig->showAllEncodings());
586
587  QString urlViewer = gLicqDaemon->getUrlViewer();
588  myUrlViewerCombo->setItemText(myUrlViewerCombo->currentIndex(),
589      urlViewer.isNull() ? DEFAULT_URL_VIEWER : urlViewer);
590  myTerminalEdit->setText(gLicqDaemon->Terminal() == NULL ?
591      tr("none") : QString(gLicqDaemon->Terminal()));
592
593  updatePreviews();
594}
595
596void Settings::Chat::apply()
597{
598  Config::Chat* chatConfig = Config::Chat::instance();
599  Config::General* generalConfig = Config::General::instance();
600  chatConfig->blockUpdates(true);
601  generalConfig->blockUpdates(true);
602
603  generalConfig->setUseDoubleReturn(myUseDoubleReturnCheck->isChecked());
604
605  chatConfig->setAutoClose(myAutoCloseCheck->isChecked());
606  chatConfig->setSendFromClipboard(mySendFromClipboardCheck->isChecked());
607  chatConfig->setMsgChatView(myMsgChatViewCheck->isChecked());
608  chatConfig->setChatVertSpacing(myChatVertSpacingCheck->isChecked());
609  chatConfig->setChatAppendLineBreak(myChatLineBreakCheck->isChecked());
610  chatConfig