1
#include "opt_general.h"
3
#include "iconwidget.h"
5
#include <qbuttongroup.h>
6
#include <qwhatsthis.h>
8
#include <qradiobutton.h>
10
#include <qlineedit.h>
11
#include <qsignalmapper.h>
14
#include <qcolordialog.h>
16
#include "opt_general_roster.h"
17
#include "opt_general_docking.h"
18
#include "opt_general_misc.h"
19
#include "opt_general_notify.h"
20
#include "opt_general_groupchat.h"
22
//----------------------------------------------------------------------------
24
//----------------------------------------------------------------------------
26
OptionsTabGeneral::OptionsTabGeneral(QObject *parent)
27
: MetaOptionsTab(parent, "general", "", tr("General"), tr("General options"), "psi/psi16")
29
addTab( new OptionsTabGeneralRoster(this) );
30
addTab( new OptionsTabGeneralDocking(this) );
31
addTab( new OptionsTabGeneralMisc(this) );
32
addTab( new OptionsTabGeneralNotifications(this) );
33
addTab( new OptionsTabGeneralGroupchat(this) );
36
//----------------------------------------------------------------------------
37
// OptionsTabGeneralRoster
38
//----------------------------------------------------------------------------
40
OptionsTabGeneralRoster::OptionsTabGeneralRoster(QObject *parent)
41
: OptionsTab(parent, "general_roster", "general", tr("Roster"), tr("Configure your roster"))
47
OptionsTabGeneralRoster::~OptionsTabGeneralRoster()
53
QWidget *OptionsTabGeneralRoster::widget()
58
w = new GeneralRosterUI();
59
GeneralRosterUI *d = (GeneralRosterUI *)w;
61
bg_defAct = new QButtonGroup;
62
bg_defAct->setRadioButtonExclusive( true );
63
bg_defAct->insert( d->rb_defActMsg, 0 );
64
bg_defAct->insert( d->rb_defActChat, 1 );
66
QWhatsThis::add(d->ck_useleft,
67
tr("Normally, right-clicking with the mouse on a contact will activate the context-menu."
68
" Check this option if you'd rather use a left-click."));
69
QWhatsThis::add(d->ck_singleclick,
70
tr("Normally, a double-click on a contact will invoke the default action."
71
" Check this option if you'd rather invoke with a single-click."));
73
QWhatsThis::add(d->rb_defActMsg,
74
tr("Make the default action open a chat window."));
75
QWhatsThis::add(d->rb_defActChat,
76
tr("Make the default action open a normal message window."));
78
QWhatsThis::add(d->ck_showself,
79
tr("If checked, always show the self-contact in roster, "
80
"otherwise it is shown only when multiple resources are connected to your account."));
85
void OptionsTabGeneralRoster::applyOptions(Options *opt)
90
GeneralRosterUI *d = (GeneralRosterUI *)w;
91
opt->useleft = d->ck_useleft->isChecked();
92
opt->singleclick = d->ck_singleclick->isChecked();
93
opt->defaultAction = bg_defAct->id(bg_defAct->selected());
94
opt->alwaysShowSelf = d->ck_showself->isChecked();
97
void OptionsTabGeneralRoster::restoreOptions(const Options *opt)
102
GeneralRosterUI *d = (GeneralRosterUI *)w;
103
d->ck_useleft->setChecked( opt->useleft );
104
d->ck_singleclick->setChecked( opt->singleclick );
105
bg_defAct->setButton( opt->defaultAction );
106
d->ck_showself->setChecked( opt->alwaysShowSelf );
109
//----------------------------------------------------------------------------
110
// OptionsTabGeneralDocking
111
//----------------------------------------------------------------------------
113
OptionsTabGeneralDocking::OptionsTabGeneralDocking(QObject *parent)
114
: OptionsTab(parent, "general_docking", "general", tr("Docking"), tr("Configure the Psi docklet"))
119
QWidget *OptionsTabGeneralDocking::widget()
124
w = new GeneralDockingUI();
125
GeneralDockingUI *d = (GeneralDockingUI *)w;
127
connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockDCstyle, SLOT(setEnabled(bool)));
128
connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockHideMW, SLOT(setEnabled(bool)));
129
connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockToolMW, SLOT(setEnabled(bool)));
131
QWhatsThis::add(d->ck_docklet,
132
tr("Makes Psi use a docklet icon, also known as system tray icon."));
133
QWhatsThis::add(d->ck_dockDCstyle,
134
tr("Normally, single-clicking on the Psi docklet icon brings the main window to"
135
" the foreground. Check this option if you would rather use a double-click."));
136
QWhatsThis::add(d->ck_dockHideMW,
137
tr("Starts Psi with only the docklet icon visible."));
138
QWhatsThis::add(d->ck_dockToolMW,
139
tr("Prevents Psi from taking up a slot on the taskbar and makes the main "
140
"window use a small titlebar."));
145
void OptionsTabGeneralDocking::applyOptions(Options *opt)
150
GeneralDockingUI *d = (GeneralDockingUI *)w;
151
opt->useDock = d->ck_docklet->isChecked();
152
opt->dockDCstyle = d->ck_dockDCstyle->isChecked();
153
opt->dockHideMW = d->ck_dockHideMW->isChecked();
154
opt->dockToolMW = d->ck_dockToolMW->isChecked();
157
void OptionsTabGeneralDocking::restoreOptions(const Options *opt)
162
GeneralDockingUI *d = (GeneralDockingUI *)w;
163
d->ck_docklet->setChecked( opt->useDock );
164
d->ck_dockDCstyle->setChecked( opt->dockDCstyle );
165
d->ck_dockHideMW->setChecked( opt->dockHideMW );
166
d->ck_dockToolMW->setChecked( opt->dockToolMW );
168
if( !d->ck_docklet->isChecked() ) {
169
d->ck_dockDCstyle->setEnabled(false);
170
d->ck_dockHideMW->setEnabled(false);
171
d->ck_dockToolMW->setEnabled(false);
175
//----------------------------------------------------------------------------
176
// OptionsTabGeneralMisc
177
//----------------------------------------------------------------------------
179
OptionsTabGeneralMisc::OptionsTabGeneralMisc(QObject *parent)
180
: OptionsTab(parent, "general_misc", "general", tr("Misc"), tr("Miscellaneous settings"))
186
OptionsTabGeneralMisc::~OptionsTabGeneralMisc()
192
QWidget *OptionsTabGeneralMisc::widget()
197
w = new GeneralMiscUI();
198
GeneralMiscUI *d = (GeneralMiscUI *)w;
201
QWhatsThis::add(d->ck_chatSays,
202
tr("<P>Changes the normal chat style from:</P>"
203
"<P>[01:23:45] <MyName> Hi</P>"
204
"<P>[01:23:56] <YourName> How are you?</P>"
206
"<P>[01:23:45] MyName says:</P>"
208
"<P>[01:23:56] YourName says:</P>"
209
"<P>How are you?</P>"));
210
QWhatsThis::add(d->ck_chatSoftReturn,
211
tr("<P>When checked, pressing Enter in a chat window will send your message."
212
" You must use Shift+Enter in order to create a newline in the chat message."
213
" If unchecked, messages are sent by pressing Alt-S or Control-Enter, just as they are with regular messages.</P>"));
216
bg_delChats = new QButtonGroup;
217
bg_delChats->setRadioButtonExclusive( true );
218
bg_delChats->insert( d->rb_delChatsClose, 0 );
219
bg_delChats->insert( d->rb_delChatsHour, 1 );
220
bg_delChats->insert( d->rb_delChatsDay, 2 );
221
bg_delChats->insert( d->rb_delChatsNever, 3 );
223
QWhatsThis::add(d->ck_alwaysOnTop,
224
tr("Makes the main Psi window always be in front of other windows."));
225
QWhatsThis::add(d->ck_keepSizes,
226
tr("Makes Psi remember window size and positions for chats and messages."
227
" If disabled, the windows will always appear in their default positions and sizes."));
228
QWhatsThis::add(d->ck_jidComplete,
229
tr("Enables as-you-type JID autocompletion in message dialog."));
230
QWhatsThis::add(d->ck_grabUrls,
231
tr("Automatically attaches URLs from clipboard to the messages when enabled"));
233
QString s = tr("<P>Controls how long the chat log will be kept in memory after the"
234
" chat window is closed.</P>");
235
QWhatsThis::add(d->rb_delChatsClose, s +
236
tr("<P>This option does not keep the chat log in memory.</P>"));
237
QWhatsThis::add(d->rb_delChatsHour, s +
238
tr("<P>This option keeps the chat log for 1 hour before deleting it.</P>"));
239
QWhatsThis::add(d->rb_delChatsDay, s +
240
tr("<P>This option keeps the chat log for 1 day before deleting it.</P>"));
241
QWhatsThis::add(d->rb_delChatsNever, s +
242
tr("<P>This options keeps the chat log forever.</P>"));
245
QWhatsThis::add(d->cb_link,
246
tr("Selects what applications to use for handling URLs and e-mail addresses."
247
" You can choose between the system default and custom applications."));
249
s = tr("Enter the path to the application's executable and choose \"Custom\" in the list above.");
250
QWhatsThis::add(d->le_linkBrowser,
251
tr("Specify what custom browser application to use for handling URLs here.") + " " + s);
252
QWhatsThis::add(d->le_linkMailer,
253
tr("Specify what custom mailer application to use for handling e-mail addresses here.") + " " + s);
258
static int om_x11browse[] = { 0, 2, 1 };
260
void OptionsTabGeneralMisc::applyOptions(Options *opt)
265
GeneralMiscUI *d = (GeneralMiscUI *)w;
268
opt->chatSays = d->ck_chatSays->isChecked();
269
opt->chatSoftReturn = d->ck_chatSoftReturn->isChecked();
272
opt->alwaysOnTop = d->ck_alwaysOnTop->isChecked();
273
opt->keepSizes = d->ck_keepSizes->isChecked();
274
opt->jidComplete = d->ck_jidComplete->isChecked();
275
opt->grabUrls = d->ck_grabUrls->isChecked();
276
opt->delChats = bg_delChats->id( bg_delChats->selected() );
280
opt->browser = om_x11browse[ d->cb_link->currentItem() ];
282
opt->browser = d->cb_link->currentItem();
284
opt->customBrowser = d->le_linkBrowser->text();
285
opt->customMailer = d->le_linkMailer->text();
288
void OptionsTabGeneralMisc::restoreOptions(const Options *opt)
293
GeneralMiscUI *d = (GeneralMiscUI *)w;
296
d->ck_chatSays->setChecked( opt->chatSays );
297
d->ck_chatSoftReturn->setChecked( opt->chatSoftReturn );
301
d->ck_alwaysOnTop->setEnabled( false );
303
d->ck_alwaysOnTop->setChecked( opt->alwaysOnTop );
305
d->ck_keepSizes->setChecked( opt->keepSizes );
306
d->ck_jidComplete->setChecked( opt->jidComplete );
307
d->ck_grabUrls->setChecked( opt->grabUrls );
309
bg_delChats->setButton( opt->delChats );
312
connect(d->cb_link, SIGNAL(activated(int)), SLOT(selectBrowser(int)));
314
d->cb_link->insertItem(tr("Windows Default Browser/Mail"));
315
d->cb_link->insertItem(tr("Custom"));
316
d->cb_link->setCurrentItem( opt->browser );
317
selectBrowser( opt->browser );
320
d->cb_link->insertItem(tr("KDE Default Browser/Mail"));
321
d->cb_link->insertItem(tr("GNOME2 Default Browser/Mail"));
322
d->cb_link->insertItem(tr("Custom"));
323
int rbi = om_x11browse[ opt->browser ];
324
d->cb_link->setCurrentItem( rbi );
325
selectBrowser( rbi );
328
d->cb_link->insertItem(tr("MacOS Default Browser/Mail"));
329
d->cb_link->setCurrentItem( opt->browser );
330
selectBrowser( opt->browser );
332
d->le_linkBrowser->setText( opt->customBrowser );
333
d->le_linkMailer->setText( opt->customMailer );
336
void OptionsTabGeneralMisc::selectBrowser(int x)
341
bool enableCustom = TRUE;
345
enableCustom = FALSE;
349
enableCustom = FALSE;
353
enableCustom = FALSE;
356
GeneralMiscUI *d = (GeneralMiscUI *)w;
357
d->gb_linkCustom->setEnabled(enableCustom);
360
//----------------------------------------------------------------------------
361
// OptionsTabGeneralNotifications
362
//----------------------------------------------------------------------------
364
OptionsTabGeneralNotifications::OptionsTabGeneralNotifications(QObject *parent)
365
: OptionsTab(parent, "general_notifications", "general", tr("Notifications"), tr("Configure the popup notifications"))
370
QWidget *OptionsTabGeneralNotifications::widget()
375
w = new GeneralNotifyUI();
376
//GeneralNotifyUI *d = (GeneralNotifyUI *)w;
378
// TODO: add QWhatsThis for all controls on widget
383
void OptionsTabGeneralNotifications::applyOptions(Options *opt)
388
GeneralNotifyUI *d = (GeneralNotifyUI *)w;
389
opt->ppIsOn = d->ck_popupOn->isChecked();
390
opt->ppMessage = d->ck_popupOnMessage->isChecked();
391
opt->ppChat = d->ck_popupOnChat->isChecked();
392
opt->ppHeadline = d->ck_popupOnHeadline->isChecked();
393
opt->ppStatus = d->ck_popupOnStatus->isChecked();
394
opt->ppOnline = d->ck_popupOnOnline->isChecked();
395
opt->ppOffline = d->ck_popupOnOffline->isChecked();
398
void OptionsTabGeneralNotifications::restoreOptions(const Options *opt)
403
GeneralNotifyUI *d = (GeneralNotifyUI *)w;
404
d->ck_popupOn->setChecked( true );
405
d->ck_popupOn->setChecked( opt->ppIsOn );
406
d->ck_popupOnMessage->setChecked( opt->ppMessage );
407
d->ck_popupOnChat->setChecked( opt->ppChat );
408
d->ck_popupOnHeadline->setChecked( opt->ppHeadline );
409
d->ck_popupOnStatus->setChecked( opt->ppStatus );
410
d->ck_popupOnOnline->setChecked( opt->ppOnline );
411
d->ck_popupOnOffline->setChecked( opt->ppOffline );
414
//----------------------------------------------------------------------------
415
// OptionsTabGeneralGroupchat -- TODO: simplify the code
416
//----------------------------------------------------------------------------
418
OptionsTabGeneralGroupchat::OptionsTabGeneralGroupchat(QObject *parent)
419
: OptionsTab(parent, "general_groupchat", "general", tr("Groupchat"), tr("Configure the groupchat"))
424
void OptionsTabGeneralGroupchat::setData(PsiCon *, QWidget *_dlg)
429
QWidget *OptionsTabGeneralGroupchat::widget()
434
w = new GeneralGroupchatUI();
435
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
437
connect(d->pb_nickColor, SIGNAL(clicked()), SLOT(chooseGCNickColor()));
438
connect(d->lb_nickColors, SIGNAL(highlighted(int)), SLOT(selectedGCNickColor()));
440
connect(d->pb_addHighlightWord, SIGNAL(clicked()), SLOT(addGCHighlight()));
441
connect(d->pb_removeHighlightWord, SIGNAL(clicked()), SLOT(removeGCHighlight()));
443
connect(d->pb_addNickColor, SIGNAL(clicked()), SLOT(addGCNickColor()));
444
connect(d->pb_removeNickColor, SIGNAL(clicked()), SLOT(removeGCNickColor()));
446
// TODO: add QWhatsThis for all controls on widget
451
void OptionsTabGeneralGroupchat::applyOptions(Options *opt)
456
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
457
opt->gcHighlighting = d->ck_gcHighlights->isChecked();
458
opt->gcNickColoring = d->ck_gcNickColoring->isChecked();
460
QStringList highlight;
462
for (i = 0; i < (int)d->lb_highlightWords->count(); i++)
463
highlight << d->lb_highlightWords->item(i)->text();
464
opt->gcHighlights = highlight;
467
for (i = 0; i < (int)d->lb_nickColors->count(); i++)
468
colors << d->lb_nickColors->item(i)->text();
469
opt->gcNickColors = colors;
472
void OptionsTabGeneralGroupchat::restoreOptions(const Options *opt)
477
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
479
// no need to call dataChanged() when these widgets are modified
480
disconnect(d->le_newNickColor, SIGNAL(textChanged(const QString &)), 0, 0);
481
disconnect(d->le_newHighlightWord, SIGNAL(textChanged(const QString &)), 0, 0);
482
connect(d->le_newNickColor, SIGNAL(textChanged(const QString &)), SLOT(displayGCNickColor()));
484
d->ck_gcHighlights->setChecked( true );
485
d->ck_gcHighlights->setChecked( opt->gcHighlighting );
486
d->ck_gcNickColoring->setChecked( true );
487
d->ck_gcNickColoring->setChecked( opt->gcNickColoring );
488
d->lb_highlightWords->clear();
489
d->lb_highlightWords->insertStringList( opt->gcHighlights );
490
d->lb_nickColors->clear();
492
QStringList::ConstIterator it = opt->gcNickColors.begin();
493
for ( ; it != opt->gcNickColors.end(); ++it)
496
d->le_newHighlightWord->setText("");
497
d->le_newNickColor->setText("#FFFFFF");
500
static QPixmap name2color(QString name)
506
p.fillRect(0, 0, pix.width(), pix.height(), QBrush(c));
507
p.setPen( QColor(0, 0, 0) );
508
p.drawRect(0, 0, pix.width(), pix.height());
514
void OptionsTabGeneralGroupchat::addNickColor(QString name)
516
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
517
d->lb_nickColors->insertItem(name2color(name), name);
520
void OptionsTabGeneralGroupchat::addGCHighlight()
522
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
523
if ( d->le_newHighlightWord->text().isEmpty() )
526
d->lb_highlightWords->insertItem( d->le_newHighlightWord->text() );
527
d->le_newHighlightWord->setFocus();
528
d->le_newHighlightWord->setText("");
533
void OptionsTabGeneralGroupchat::removeGCHighlight()
535
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
536
int id = d->lb_highlightWords->currentItem();
540
d->lb_highlightWords->removeItem(id);
545
void OptionsTabGeneralGroupchat::addGCNickColor()
547
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
548
if ( d->le_newNickColor->text().isEmpty() )
551
addNickColor( d->le_newNickColor->text() );
552
d->le_newNickColor->setFocus();
553
d->le_newNickColor->setText("");
558
void OptionsTabGeneralGroupchat::removeGCNickColor()
560
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
561
int id = d->lb_nickColors->currentItem();
565
d->lb_nickColors->removeItem(id);
570
void OptionsTabGeneralGroupchat::chooseGCNickColor()
572
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
573
QColor c = QColorDialog::getColor(QColor(d->le_newNickColor->text()), dlg);
575
QString cs = c.name();
576
d->le_newNickColor->setText(cs);
580
void OptionsTabGeneralGroupchat::selectedGCNickColor()
582
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
583
int id = d->lb_nickColors->currentItem();
587
d->le_newNickColor->setText( d->lb_nickColors->text(id) );
590
void OptionsTabGeneralGroupchat::displayGCNickColor()
592
GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
593
d->pb_nickColor->setPixmap( name2color(d->le_newNickColor->text()) );