1
//============================================================================
3
// File : optw_identity.cpp
4
// Creation date : Tue Nov 14 2000 23:06:53 CEST by Szymon Stefanek
6
// This file is part of the KVirc irc client distribution
7
// Copyright (C) 2000-2008 Szymon Stefanek (pragma at kvirc dot net)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//============================================================================
25
#include "optw_identity.h"
27
#include "kvi_defaults.h"
28
#include "kvi_settings.h"
29
#include "kvi_options.h"
30
#include "kvi_locale.h"
32
#include "kvi_window.h"
33
#include "kvi_console.h"
34
#include "kvi_optionswidget.h"
35
#include "kvi_filedialog.h"
36
#include "kvi_fileextensions.h"
37
#include "kvi_iconmanager.h"
39
#include "kvi_identityprofile.h"
40
#include "kvi_tal_tooltip.h"
41
#include "kvi_tal_hbox.h"
42
#include <QTreeWidget>
46
#include <QPushButton>
50
#include <QMessageBox>
53
#include <QCloseEvent>
56
KviNickAlternativesDialog::KviNickAlternativesDialog(QWidget * par,const QString &n1,const QString &n2,const QString &n3)
59
QGridLayout * g = new QGridLayout(this);
61
setWindowTitle(__tr2qs_ctx("Nickname alternatives","options"));
63
QLabel * l = new QLabel(this);
64
l->setText(__tr2qs_ctx("<center>Here you can choose up to three nicknames " \
65
"alternative to the primary one. KVIrc will use the alternatives " \
66
"if the primary nick is already used by someone else on a particular " \
67
"IRC network.</center>","options"));
70
g->addWidget(l,0,0,1,3);
73
l->setText(__tr2qs_ctx("Alt. Nickname 1:","options"));
75
m_pNickEdit1 = new QLineEdit(this);
76
g->addWidget(m_pNickEdit1,1,1,1,2);
77
m_pNickEdit1->setText(n1);
80
l->setText(__tr2qs_ctx("Alt. Nickname 2:","options"));
82
m_pNickEdit2 = new QLineEdit(this);
83
g->addWidget(m_pNickEdit2,2,1,1,2);
84
m_pNickEdit2->setText(n2);
87
l->setText(__tr2qs_ctx("Alt. Nickname 3:","options"));
89
m_pNickEdit3 = new QLineEdit(this);
90
g->addWidget(m_pNickEdit3,3,1,1,2);
91
m_pNickEdit3->setText(n3);
92
KviTalHBox * h = new KviTalHBox(this);
96
QPushButton * pb = new QPushButton(__tr2qs_ctx("Cancel","options"),h);
97
connect(pb,SIGNAL(clicked()),this,SLOT(reject()));
99
pb = new QPushButton(__tr2qs_ctx("Ok","options"),h);
100
pb->setDefault(true);
101
connect(pb,SIGNAL(clicked()),this,SLOT(accept()));
103
g->setColumnStretch(0,1);
106
KviNickAlternativesDialog::~KviNickAlternativesDialog()
110
void KviNickAlternativesDialog::fill(QString &n1,QString &n2,QString &n3)
112
n1 = m_pNickEdit1->text();
113
n2 = m_pNickEdit2->text();
114
n3 = m_pNickEdit3->text();
118
KviAvatarDownloadDialog::KviAvatarDownloadDialog(QWidget * par,const QString &szUrl)
121
setWindowTitle(__tr2qs_ctx("Avatar Download - KVIrc","options"));
125
QGridLayout * g = new QGridLayout(this);
127
m_pOutput = new QLabel(__tr2qs_ctx("<center>Please wait while the avatar is being downloaded</center>","options"),this);
128
g->addWidget(m_pOutput,0,0,1,2);
130
QPushButton * b = new QPushButton(__tr2qs_ctx("Abort","options"),this);
132
connect(b,SIGNAL(clicked()),this,SLOT(cancelClicked()));
134
m_pRequest = new KviHttpRequest();
136
QTimer::singleShot(0,this,SLOT(startDownload()));
138
g->setRowStretch(0,1);
139
g->setColumnStretch(0,1);
141
setMinimumSize(250,120);
144
KviAvatarDownloadDialog::~KviAvatarDownloadDialog()
149
void KviAvatarDownloadDialog::startDownload()
151
connect(m_pRequest,SIGNAL(terminated(bool)),this,SLOT(downloadTerminated(bool)));
152
connect(m_pRequest,SIGNAL(status(const QString &)),this,SLOT(downloadMessage(const QString &)));
154
QString tmp = m_szUrl;
155
g_pIconManager->urlToCachedFileName(tmp);
156
g_pApp->getLocalKvircDirectory(m_szLocalFileName,KviApp::Avatars,tmp);
158
m_pRequest->setExistingFileAction(KviHttpRequest::RenameExisting);
159
if(!m_pRequest->get(KviUrl(m_szUrl),KviHttpRequest::StoreToFile,m_szLocalFileName.toUtf8().data()))
161
m_szErrorMessage = __tr2qs_ctx("Failed to start the download","options");
166
void KviAvatarDownloadDialog::closeEvent(QCloseEvent * e)
168
m_szErrorMessage = __tr2qs_ctx("Download aborted by user","options");
173
void KviAvatarDownloadDialog::cancelClicked()
175
m_szErrorMessage = __tr2qs_ctx("Download aborted by user","options");
179
void KviAvatarDownloadDialog::downloadMessage(const QString &szMsg)
183
QString txt = "<center>";
186
m_pOutput->setText(szMsg);
190
void KviAvatarDownloadDialog::downloadTerminated(bool bSuccess)
196
m_szErrorMessage = m_pRequest->lastError();
201
KviAvatarSelectionDialog::KviAvatarSelectionDialog(QWidget * par,const QString &szInitialPath)
204
setWindowTitle(__tr2qs_ctx("Choose Avatar - KVIrc","options"));
206
QGridLayout * g = new QGridLayout(this);
208
QString msg = "<center>";
209
msg += __tr2qs_ctx("Please select an avatar image. " \
210
"The full path to a local file or an image on the Web can be used.<br>" \
211
"If you wish to use a local image file, click the \"<b>Browse</b>\"" \
212
"button to browse local folders.<br>" \
213
"The full URL for an image (including <b>http://</b>) can be entered manually.","options");
214
msg += "</center><br>";
216
QLabel * l = new QLabel(msg,this);
217
l->setMinimumWidth(250);
219
g->addWidget(l,0,0,1,3);
221
m_pLineEdit = new QLineEdit(this);
222
m_pLineEdit->setText(szInitialPath);
223
m_pLineEdit->setMinimumWidth(180);
225
g->addWidget(m_pLineEdit,1,0,1,2);
227
QPushButton * b = new QPushButton(__tr2qs_ctx("&Browse...","options"),this);
228
connect(b,SIGNAL(clicked()),this,SLOT(chooseFileClicked()));
231
KviTalHBox * h = new KviTalHBox(this);
233
g->addWidget(h,2,1,1,2);
234
b = new QPushButton(__tr2qs_ctx("&OK","options"),h);
235
b->setMinimumWidth(80);
237
connect(b,SIGNAL(clicked()),this,SLOT(okClicked()));
239
b = new QPushButton(__tr2qs_ctx("Cancel","options"),h);
240
b->setMinimumWidth(80);
241
connect(b,SIGNAL(clicked()),this,SLOT(cancelClicked()));
243
g->setRowStretch(0,1);
244
g->setColumnStretch(0,1);
247
KviAvatarSelectionDialog::~KviAvatarSelectionDialog()
251
void KviAvatarSelectionDialog::okClicked()
253
m_szAvatarName = m_pLineEdit->text().trimmed();
257
void KviAvatarSelectionDialog::cancelClicked()
262
void KviAvatarSelectionDialog::chooseFileClicked()
265
if(KviFileDialog::askForOpenFileName(tmp,__tr2qs_ctx("Choose an Image File - KVIrc","options"),QString(),KVI_FILTER_IMAGE,false,true,this))
267
m_pLineEdit->setText(tmp);
271
void KviAvatarSelectionDialog::closeEvent(QCloseEvent * e)
278
KviIdentityOptionsWidget::KviIdentityOptionsWidget(QWidget * parent)
279
: KviOptionsWidget(parent)
283
KviIdentityOptionsWidget::~KviIdentityOptionsWidget()
288
KviIdentityGeneralOptionsWidget::KviIdentityGeneralOptionsWidget(QWidget * parent)
289
: KviOptionsWidget(parent)
291
m_szAltNicknames[0] = KVI_OPTION_STRING(KviOption_stringNickname2);
292
m_szAltNicknames[1] = KVI_OPTION_STRING(KviOption_stringNickname3);
293
m_szAltNicknames[2] = KVI_OPTION_STRING(KviOption_stringNickname4);
297
layout()->setMargin(10);
299
KviTalGroupBox * gbox = addGroupBox(0,0,0,0,Qt::Horizontal,__tr2qs_ctx("Basic Properties","options"));
300
KviTalHBox * hb = new KviTalHBox(gbox);
304
KviStringSelector * sel = addStringSelector(hb,__tr2qs_ctx("Nickname:","options"),KviOption_stringNickname1);
305
sel->setMinimumLabelWidth(120);
306
mergeTip(sel,__tr2qs_ctx("<center>Your <b>nickname</b> is your primary form of identification on IRC.<br>" \
307
"Since servers cannot accept multiple users sharing the same nickname " \
308
"(case insensitive), you can provide alternative nicknames to be used in case"\
309
"the server refuses to accept the default one.</center>","options"));
311
QValidator * v = new QRegExpValidator(QRegExp("[^-0-9 ][^ ]*"),hb);
312
sel->setValidator(v);
314
QPushButton * pb = new QPushButton(__tr2qs_ctx("Alternatives...","options"),hb);
315
connect(pb,SIGNAL(clicked()),this,SLOT(setNickAlternatives()));
317
sel = addStringSelector(gbox,__tr2qs_ctx("Username:","options"),KviOption_stringUsername);
318
sel->setMinimumLabelWidth(120);
319
mergeTip(sel,__tr2qs_ctx("<center>This is the <b>username</b> that you will use to connect to the server.<br>" \
320
"In the past, it was used as a form of authentication, but it normally has no special use now.<br>" \
321
"In addition to your nickname, you are identified on IRC by your <b>username@hostname</b>.</br>" \
322
"Basically, you can enter any word you like here. :D</center>","options"));
324
sel = addStringSelector(gbox,__tr2qs_ctx("Real name:","options"),KviOption_stringRealname);
325
sel->setMinimumLabelWidth(120);
327
mergeTip(sel,__tr2qs_ctx("<center>This text will appear when someone does a /WHOIS on you.<br>" \
328
"It is intended to be your real name, but people tend to put random quotes and phrases here too.</center>","options"));
331
QString szOptionalCtcpUserInfo = __tr2qs_ctx("This field is optional and will appear as part of the CTCP USERINFO reply.","options");
332
QString szCenterBegin("<center>");
333
QString szCenterEnd("</center>");
334
QString szTrailing = "<br><br>" + szOptionalCtcpUserInfo + szCenterEnd;
336
gbox = addGroupBox(0,1,0,1,Qt::Horizontal,__tr2qs_ctx("Profile","options"));
338
hb = new KviTalHBox(gbox);
341
QLabel * l = new QLabel(__tr2qs_ctx("Age:","options"),hb);
342
l->setMinimumWidth(120);
344
m_pAgeCombo = new QComboBox(hb);
345
QString szTip1 = szCenterBegin + __tr2qs_ctx("Here you can specify your age.","options") + szTrailing;
346
KviTalToolTip::add(l,szTip1);
347
KviTalToolTip::add(m_pAgeCombo,szTip1);
348
m_pAgeCombo->addItem(__tr2qs_ctx("Unspecified","options"));
354
m_pAgeCombo->insertItem(m_pAgeCombo->count(),tmp);
358
i = KVI_OPTION_STRING(KviOption_stringCtcpUserInfoAge).toUInt(&bOk);
361
m_pAgeCombo->setCurrentIndex(i);
363
hb->setStretchFactor(m_pAgeCombo,1);
366
hb = new KviTalHBox(gbox);
369
l = new QLabel(__tr2qs_ctx("Gender:","options"),hb);
370
l->setMinimumWidth(120);
372
m_pGenderCombo = new QComboBox(hb);
373
QString szTip2 = szCenterBegin + __tr2qs_ctx("Here you can specify your gender.","options") + szTrailing;
374
KviTalToolTip::add(l,szTip2);
375
KviTalToolTip::add(m_pGenderCombo,szTip2);
376
m_pGenderCombo->addItem(__tr2qs_ctx("Unspecified","options"));
377
m_pGenderCombo->addItem(__tr2qs_ctx("Female","options"));
378
m_pGenderCombo->addItem(__tr2qs_ctx("Male","options"));
380
if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender),"Male"))
381
m_pGenderCombo->setCurrentIndex(2);
382
else if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender),"Female"))
383
m_pGenderCombo->setCurrentIndex(1);
385
m_pGenderCombo->setCurrentIndex(0);
387
hb->setStretchFactor(m_pGenderCombo,1);
389
sel = addStringSelector(gbox,__tr2qs_ctx("Location:","options"),KviOption_stringCtcpUserInfoLocation);
390
sel->setMinimumLabelWidth(120);
391
mergeTip(sel,szCenterBegin + __tr2qs_ctx("You can describe here your approximate physical location. " \
392
"Something like \"Region, Country\" will be ok. Please note that this information will be viewable " \
393
"by anyone so putting more data (like the exact address), generally, <b>is not a good idea</b>.","options") + szTrailing);
395
sel = addStringSelector(gbox,__tr2qs_ctx("Languages:","options"),KviOption_stringCtcpUserInfoLanguages);
396
sel->setMinimumLabelWidth(120);
397
mergeTip(sel,szCenterBegin + __tr2qs_ctx("You can put here the short names of the languages you can speak. " \
398
"An example might be \"EN,IT\" that would mean that you speak both Italian and English.","options") + szTrailing);
400
sel = addStringSelector(gbox,__tr2qs_ctx("Other:","options"),KviOption_stringCtcpUserInfoOther);
401
sel->setMinimumLabelWidth(120);
402
mergeTip(sel,szCenterBegin + __tr2qs_ctx("You can put here some additional personal data. " \
403
"It might be a funny quote or your homepage url... " \
404
"Please note that this information will be viewable " \
405
"by anyone so <b>don't put any sensible data</b> (passwords, telephone or credit card numbers).","options") + szTrailing);
407
addRowSpacer(0,2,0,2);
410
KviIdentityGeneralOptionsWidget::~KviIdentityGeneralOptionsWidget()
414
void KviIdentityGeneralOptionsWidget::setNickAlternatives()
416
KviNickAlternativesDialog * dlg = new KviNickAlternativesDialog(this,m_szAltNicknames[0],m_szAltNicknames[1],m_szAltNicknames[2]);
417
if(dlg->exec() != QDialog::Accepted)return;
418
dlg->fill(m_szAltNicknames[0],m_szAltNicknames[1],m_szAltNicknames[2]);
422
void KviIdentityGeneralOptionsWidget::commit()
424
KviOptionsWidget::commit();
426
if(KVI_OPTION_STRING(KviOption_stringRealname).isEmpty()) KVI_OPTION_STRING(KviOption_stringRealname)=KVI_DEFAULT_REALNAME;
427
if(KVI_OPTION_STRING(KviOption_stringUsername).isEmpty()) KVI_OPTION_STRING(KviOption_stringUsername)=KVI_DEFAULT_USERNAME;
429
KVI_OPTION_STRING(KviOption_stringNickname2) = m_szAltNicknames[0];
430
KVI_OPTION_STRING(KviOption_stringNickname3) = m_szAltNicknames[1];
431
KVI_OPTION_STRING(KviOption_stringNickname4) = m_szAltNicknames[2];
434
int i = m_pAgeCombo->currentIndex();
437
if(i <= 0)KVI_OPTION_STRING(KviOption_stringCtcpUserInfoAge) = "";
438
else KVI_OPTION_STRING(KviOption_stringCtcpUserInfoAge).setNum(i);
440
switch(m_pGenderCombo->currentIndex())
443
// this should be in english
444
KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender) = "Female";
447
// this should be in english
448
KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender) = "Male";
451
KVI_OPTION_STRING(KviOption_stringCtcpUserInfoGender) = "";
457
KviIdentityAvatarOptionsWidget::KviIdentityAvatarOptionsWidget(QWidget * parent)
458
: KviOptionsWidget(parent)
461
layout()->setMargin(10);
463
m_pLocalAvatar = new KviPixmap(KVI_OPTION_PIXMAP(KviOption_pixmapMyAvatar));
465
bool bHaveAvatar = (!KVI_OPTION_STRING(KviOption_stringMyAvatar).isEmpty()) && m_pLocalAvatar->pixmap();
467
QString szTip = __tr2qs_ctx("Here you can choose your avatar image. It will be visible<br>" \
468
"by other people that request it. Choose a nice image of yourself,<br>" \
469
"possibly avoiding obscenity and offending images. It is a good idea<br>" \
470
"to choose a relatively small file (say 150 Kb max) because<br>" \
471
"most clients have a limit on the size of avatars being downloaded.<br>" \
472
"The image also should be smaller than 800x600 pixels since<br>" \
473
"it will have to be viewable in everyone's monitor.","options");
475
m_pUseAvatarCheck = new QCheckBox(__tr2qs_ctx("Use avatar","options"),this);
476
addWidgetToLayout(m_pUseAvatarCheck,0,0,0,0);
477
m_pUseAvatarCheck->setChecked(bHaveAvatar);
478
mergeTip(m_pUseAvatarCheck,szTip);
480
m_pAvatarPreview = new KviPixmapPreview(this);
481
addWidgetToLayout(m_pAvatarPreview,0,1,0,1);
482
m_pAvatarPreview->setPixmap(m_pLocalAvatar);
483
m_pAvatarPreview->setEnabled(bHaveAvatar);
484
connect(m_pUseAvatarCheck,SIGNAL(toggled(bool)),m_pAvatarPreview,SLOT(setEnabled(bool)));
485
mergeTip(m_pAvatarPreview,szTip);
487
KviTalHBox * hb = new KviTalHBox(this);
489
addWidgetToLayout(hb,0,2,0,2);
491
m_pAvatarNameEdit = new QLineEdit(hb);
492
m_pAvatarNameEdit->setReadOnly(true);
493
m_pAvatarNameEdit->setEnabled(bHaveAvatar);
494
m_pAvatarNameEdit->setText(KVI_OPTION_STRING(KviOption_stringMyAvatar));
495
connect(m_pUseAvatarCheck,SIGNAL(toggled(bool)),m_pAvatarNameEdit,SLOT(setEnabled(bool)));
497
m_pChooseAvatarButton = new QPushButton(__tr2qs_ctx("Choose...","options"),hb);
498
m_pChooseAvatarButton->setEnabled(bHaveAvatar);
499
connect(m_pUseAvatarCheck,SIGNAL(toggled(bool)),m_pChooseAvatarButton,SLOT(setEnabled(bool)));
501
connect(m_pChooseAvatarButton,SIGNAL(clicked()),this,SLOT(chooseAvatar()));
503
layout()->setRowStretch(1,2);
506
KviIdentityAvatarOptionsWidget::~KviIdentityAvatarOptionsWidget()
508
delete m_pLocalAvatar;
511
void KviIdentityAvatarOptionsWidget::commit(void)
513
KviOptionsWidget::commit();
515
QString szAvatarName = m_pAvatarNameEdit->text();
517
if(m_pUseAvatarCheck->isChecked() && m_pLocalAvatar->pixmap() && (!szAvatarName.isEmpty()))
519
KVI_OPTION_STRING(KviOption_stringMyAvatar) = szAvatarName;
520
KVI_OPTION_PIXMAP(KviOption_pixmapMyAvatar) = *m_pLocalAvatar;
521
g_pApp->setAvatarFromOptions();
523
KVI_OPTION_STRING(KviOption_stringMyAvatar) = "";
524
KVI_OPTION_PIXMAP(KviOption_pixmapMyAvatar) = KviPixmap();
528
void KviIdentityAvatarOptionsWidget::chooseAvatar()
530
QString szCurrent = m_pAvatarNameEdit->text();
532
KviAvatarSelectionDialog dlg(this,szCurrent);
533
if(dlg.exec() != QDialog::Accepted)return;
535
szCurrent = dlg.avatarName();
538
if(KviQString::equalCIN(szCurrent,"http://",7))
541
// first check if we have it in the cache
542
KviAvatar * a = g_pIconManager->getAvatar(QString(),szCurrent);
545
// no cache... try downloading
546
KviAvatarDownloadDialog dlg(this,szCurrent);
547
if(dlg.exec() == QDialog::Accepted)
551
if(!m_pLocalAvatar->load(dlg.localFileName()))
555
QMessageBox::warning(this,__tr2qs_ctx("Failed to Load Avatar - KVIrc","options"),
556
__tr2qs_ctx("Failed to load the avatar image.<br>" \
557
"It may be an unaccessible file or an " \
558
"unsupported image format.","options"),QMessageBox::Ok,QMessageBox::NoButton);
563
KviQString::sprintf(tmp,__tr2qs_ctx("Failed to download the avatar image.<br>" \
564
"<b>%Q</b>","options"),&(dlg.errorMessage()));
565
QMessageBox::warning(this,__tr2qs_ctx("Avatar Download Failed - KVIrc","options"),tmp,QMessageBox::Ok,QMessageBox::NoButton);
567
m_pLocalAvatar->setNull();
570
// else OK.. got it in the cache
571
m_pLocalAvatar->set(*(a->pixmap()),a->localPath());
575
// this is a local path
576
if(m_pLocalAvatar->load(szCurrent))
578
// local path, loaded
579
QString tmp = szCurrent;
580
int idx = tmp.lastIndexOf("/");
583
szCurrent = tmp.right(tmp.length() - (idx + 1));
586
idx = tmp.lastIndexOf("\\");
589
szCurrent = tmp.right(tmp.length() - (idx + 1));
594
QMessageBox::warning(this,__tr2qs_ctx("Failed to Load Avatar - KVIrc","options"),
595
__tr2qs_ctx("Failed to load the avatar image.<br>" \
596
"It may be an unaccessible file or an " \
597
"unsupported image format.","options"),QMessageBox::Ok,QMessageBox::NoButton);
602
if(m_pLocalAvatar->pixmap())
604
if((m_pLocalAvatar->pixmap()->width() > 1024) || (m_pLocalAvatar->pixmap()->height() > 768))
606
QMessageBox::warning(
608
__tr2qs_ctx("Avatar Might Be Too Big - KVIrc","options"),
610
"The avatar you have chosen is bigger than 1024x768 pixels.<br>" \
611
"Such a big image will not be seen on all the user monitors<br>" \
612
"and will probably be scaled by the remote clients with poor quality<br>" \
613
"algorithms to improve performance. You *should* scale it manually<br>" \
614
"to a sane size (like 800x600) or choose a different image.",
619
QFileInfo inf(m_pLocalAvatar->path());
620
if(inf.size() > 524288)
622
QMessageBox::warning(
624
__tr2qs_ctx("Avatar Might Be Too Big - KVIrc","options"),
626
"The avatar you have chosen is bigger than 500 KiB<br>" \
627
"and most clients will refuse to download it.<br>" \
628
"You *should* either scale it, use a different storage<br>" \
629
"format or choose a different image.",
637
m_pAvatarNameEdit->setText(szCurrent);
638
m_pAvatarPreview->setPixmap(m_pLocalAvatar);
642
KviIdentityAdvancedOptionsWidget::KviIdentityAdvancedOptionsWidget(QWidget * parent)
643
: KviOptionsWidget(parent)
649
m_sModeStr = KVI_OPTION_STRING(KviOption_stringDefaultUserMode);
650
m_bI = m_sModeStr.contains('i');
651
m_bW = m_sModeStr.contains('w');
652
m_bS = m_sModeStr.contains('s');
655
layout()->setMargin(10);
657
KviTalGroupBox * gbox = addGroupBox(0,0,0,0,Qt::Horizontal,__tr2qs_ctx("User Mode","options"));
658
m_pISelector = addBoolSelector(gbox,__tr2qs_ctx("Invisible (+i)","options"),&m_bI);
659
m_pSSelector = addBoolSelector(gbox,__tr2qs_ctx("Server notices (+s)","options"),&m_bS);
660
m_pWSelector = addBoolSelector(gbox,__tr2qs_ctx("Wallops (+w)","options"),&m_bW);
662
gbox = addGroupBox(0,1,0,1,Qt::Horizontal,__tr2qs_ctx("Default Messages","options"));
664
KviStringSelector * sel = addStringSelector(gbox, __tr2qs_ctx("Part message:","options"),KviOption_stringPartMessage);
665
sel->setMinimumLabelWidth(120);
667
mergeTip(sel,__tr2qs_ctx("<center>This is the default part message that will be used when you<br>" \
668
"leave a channel by closing a channel window.</center>","options"));
670
sel = addStringSelector(gbox, __tr2qs_ctx("Quit message:","options"),KviOption_stringQuitMessage);
671
sel->setMinimumLabelWidth(120);
672
mergeTip(sel,__tr2qs_ctx("<center>This is the default quit message that will be used when you<br>" \
673
"quit your IRC session by closing the console window or disconnecting by pressing the disconnect button.</center>","options"));
675
addRowSpacer(0,2,0,2);
678
KviIdentityAdvancedOptionsWidget::~KviIdentityAdvancedOptionsWidget()
682
void KviIdentityAdvancedOptionsWidget::commit()
684
KviOptionsWidget::commit();
686
m_sModeStr = m_bI ? "i" : "";
687
if(m_bS)m_sModeStr += "s";
688
if(m_bW)m_sModeStr += "w";
690
KVI_OPTION_STRING(KviOption_stringDefaultUserMode) = m_sModeStr.ptr();
693
KviIdentityProfileOptionsWidget::KviIdentityProfileOptionsWidget(QWidget * pParent)
694
: KviOptionsWidget(pParent)
696
setObjectName("identity_profiles_option_widget");
698
m_iCurrentEditedProfile = -1;
701
QGridLayout * pLayout = layout();
703
KviIdentityProfileSet * pSet = KviIdentityProfileSet::instance();
704
bool bEnabled = pSet ? (pSet->isEnabled() && !pSet->isEmpty()) : false;
706
m_pProfilesCheck = new QCheckBox(__tr2qs_ctx("Enable Network Profiles","options"),this);
707
KviTalToolTip::add(m_pProfilesCheck,__tr2qs_ctx("This check enables the use of network profiles","options"));
708
m_pProfilesCheck->setChecked(bEnabled);
709
pLayout->addWidget(m_pProfilesCheck,0,0,1,3);
710
connect(m_pProfilesCheck,SIGNAL(toggled(bool)),this,SLOT(toggleControls()));
713
m_pTreeWidget = new QTreeWidget(this);
714
m_pTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
715
m_pTreeWidget->setAllColumnsShowFocus(true);
718
labels.append(__tr2qs_ctx("Name","options"));
719
labels.append(__tr2qs_ctx("Network","options"));
720
labels.append(__tr2qs_ctx("Nickname","options"));
721
labels.append(__tr2qs_ctx("Alt. Nick","options"));
722
labels.append(__tr2qs_ctx("Username","options"));
723
labels.append(__tr2qs_ctx("Realname","options"));
724
m_pTreeWidget->setHeaderLabels(labels);
726
KviTalToolTip::add(m_pTreeWidget, \
727
__tr2qs_ctx("<center>This is a set of rules to use profiles." \
728
"KVIrc will use them to handle the user connection " \
729
"data before the data is sent to the IRC server.<br>" \
730
"This is useful if a user wants to use different data " \
731
"on different networks without changing them at every " \
732
"connection attempt.","options"));
733
pLayout->addWidget(m_pTreeWidget,1,0,1,3);
734
connect(m_pTreeWidget,SIGNAL(itemSelectionChanged()),this,SLOT(toggleControls()));
737
KviTalHBox * pBtnBox = new KviTalHBox(this);
738
pLayout->addWidget(pBtnBox,2,0);
740
m_pBtnAddProfile = new QPushButton(__tr2qs_ctx("Add Profile","options"),pBtnBox);
741
connect(m_pBtnAddProfile,SIGNAL(clicked()),this,SLOT(addProfileEntry()));
743
m_pBtnEditProfile = new QPushButton(__tr2qs_ctx("Edit Profile","options"),pBtnBox);
744
connect(m_pBtnEditProfile,SIGNAL(clicked()),this,SLOT(editProfileEntry()));
746
m_pBtnDelProfile = new QPushButton(__tr2qs_ctx("Delete Profile","options"),pBtnBox);
747
connect(m_pBtnDelProfile,SIGNAL(clicked()),this,SLOT(delProfileEntry()));
749
// Fill in the treewidget
750
if(pSet && pSet->profiles())
752
QTreeWidgetItem * pItem;
753
KviPointerList<KviIdentityProfile> * pList = pSet->profiles();
754
for(KviIdentityProfile * pProfile = pList->first(); pProfile; pProfile = pList->next())
756
pItem = new QTreeWidgetItem(m_pTreeWidget);
757
pItem->setText(0,pProfile->name());
758
pItem->setText(1,pProfile->network());
759
pItem->setText(2,pProfile->nick());
760
pItem->setText(3,pProfile->altNick());
761
pItem->setText(4,pProfile->userName());
762
pItem->setText(5,pProfile->realName());
769
KviIdentityProfileOptionsWidget::~KviIdentityProfileOptionsWidget()
773
void KviIdentityProfileOptionsWidget::toggleControls()
775
bool bEnabled = m_pProfilesCheck->isChecked();
776
m_pTreeWidget->setEnabled(bEnabled);
777
m_pBtnAddProfile->setEnabled(bEnabled);
779
bEnabled = bEnabled && (m_pTreeWidget->topLevelItemCount()) && m_pTreeWidget->currentItem();
780
m_pBtnEditProfile->setEnabled(bEnabled);
781
m_pBtnDelProfile->setEnabled(bEnabled);
784
void KviIdentityProfileOptionsWidget::addProfileEntry()
786
KviIdentityProfile profile;
787
m_iCurrentEditedProfile = -1;
791
m_pEditor = new KviIdentityProfileEditor(this);
793
if(m_pEditor->editProfile(&profile))
795
QTreeWidgetItem * pItem = new QTreeWidgetItem(m_pTreeWidget);
796
pItem->setText(0,profile.name());
797
pItem->setText(1,profile.network());
798
pItem->setText(2,profile.nick());
799
pItem->setText(3,profile.altNick());
800
pItem->setText(4,profile.userName());
801
pItem->setText(5,profile.realName());
805
void KviIdentityProfileOptionsWidget::editProfileEntry()
807
QTreeWidgetItem * pItem = (QTreeWidgetItem *)m_pTreeWidget->currentItem();
811
// Fill in the editor data
812
KviIdentityProfile profile;
813
profile.setName(pItem->text(0));
814
profile.setNetwork(pItem->text(1));
815
profile.setNick(pItem->text(2));
816
profile.setAltNick(pItem->text(3));
817
profile.setUserName(pItem->text(4));
818
profile.setRealName(pItem->text(5));
820
m_iCurrentEditedProfile=m_pTreeWidget->indexOfTopLevelItem(pItem);
824
m_pEditor = new KviIdentityProfileEditor(this);
825
if(m_pEditor->editProfile(&profile))
827
pItem->setText(0,profile.name());
828
pItem->setText(1,profile.network());
829
pItem->setText(2,profile.nick());
830
pItem->setText(3,profile.altNick());
831
pItem->setText(4,profile.userName());
832
pItem->setText(5,profile.realName());
836
void KviIdentityProfileOptionsWidget::editProfileOkPressed()
838
for(int i=0; i < m_pTreeWidget->topLevelItemCount(); i++)
840
if(m_pEditor->m_pNameEdit->text() == m_pTreeWidget->topLevelItem(i)->text(0) && i!=m_iCurrentEditedProfile)
842
QMessageBox::warning(this,__tr2qs_ctx("Invalid Profile Rule","options"),__tr2qs_ctx("There is already a profile with that name","options"),__tr2qs_ctx("OK","options"));
850
void KviIdentityProfileOptionsWidget::delProfileEntry()
852
QTreeWidgetItem * pItem = (QTreeWidgetItem *)m_pTreeWidget->currentItem();
860
void KviIdentityProfileOptionsWidget::commit()
862
KviIdentityProfileSet::instance()->clear();
863
if(m_pTreeWidget->topLevelItemCount())
865
KviIdentityProfileSet::instance()->setEnabled(m_pProfilesCheck->isChecked());
866
QTreeWidgetItem * pItem;
867
for(int i=0; i < m_pTreeWidget->topLevelItemCount(); i++)
869
pItem = (QTreeWidgetItem *)m_pTreeWidget->topLevelItem(i);
871
KviIdentityProfile * pProfile = new KviIdentityProfile();
872
pProfile->setName(pItem->text(0));
873
pProfile->setNetwork(pItem->text(1));
874
pProfile->setNick(pItem->text(2));
875
pProfile->setAltNick(pItem->text(3));
876
pProfile->setUserName(pItem->text(4));
877
pProfile->setRealName(pItem->text(5));
879
KviIdentityProfileSet::instance()->addProfile(pProfile);
883
KviOptionsWidget::commit();
886
KviIdentityProfileEditor::KviIdentityProfileEditor(QWidget * pParent)
889
setObjectName("identity_profile_editor");
890
setWindowTitle(__tr2qs_ctx("Profile Editor - KVIrc","options"));
892
m_szName = __tr2qs_ctx("Profile Name","options");
893
m_szNetwork = __tr2qs_ctx("MyNetwork","options");
894
m_szNick = __tr2qs_ctx("MyNick","options");
895
m_szAltNick = __tr2qs_ctx("MyNick2","options");
896
m_szUserName = __tr2qs_ctx("MyUserName","options");
897
m_szRealName = __tr2qs_ctx("MyRealName","options");
899
QGridLayout * pLayout = new QGridLayout(this);
901
QLabel * pLabel = new QLabel(__tr2qs_ctx("Profile Name:","options"),this);
902
pLayout->addWidget(pLabel,0,0);
904
m_pNameEdit = new QLineEdit(this);
905
KviTalToolTip::add(m_pNameEdit,__tr2qs_ctx("Put here the name of the profile","options"));
906
pLayout->addWidget(m_pNameEdit,0,1,1,2);
907
connect(m_pNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
909
pLabel = new QLabel(__tr2qs_ctx("Network Name:","options"),this);
910
pLayout->addWidget(pLabel,1,0);
912
m_pNetworkEdit = new QLineEdit(this);
913
KviTalToolTip::add(m_pNetworkEdit,__tr2qs_ctx("Put here the name of the network","options"));
914
pLayout->addWidget(m_pNetworkEdit,1,1,1,2);
915
connect(m_pNetworkEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
917
pLabel = new QLabel(__tr2qs_ctx("Nickname:","options"),this);
918
pLayout->addWidget(pLabel,2,0);
920
m_pNickEdit = new QLineEdit(this);
921
KviTalToolTip::add(m_pNickEdit,__tr2qs_ctx("Put here the nickname you want to use","options"));
922
pLayout->addWidget(m_pNickEdit,2,1,1,2);
923
connect(m_pNickEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
925
pLabel = new QLabel(__tr2qs_ctx("Alternative Nickname:","options"),this);
926
pLayout->addWidget(pLabel,3,0);
928
m_pAltNickEdit = new QLineEdit(this);
929
KviTalToolTip::add(m_pAltNickEdit,__tr2qs_ctx("Put here the alternative nickname you want to use","options"));
930
pLayout->addWidget(m_pAltNickEdit,3,1,1,2);
931
connect(m_pAltNickEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
933
pLabel = new QLabel(__tr2qs_ctx("Username:","options"),this);
934
pLayout->addWidget(pLabel,4,0);
936
m_pUserNameEdit = new QLineEdit(this);
937
KviTalToolTip::add(m_pUserNameEdit,__tr2qs_ctx("Put here the username you want to use","options"));
938
pLayout->addWidget(m_pUserNameEdit,4,1,1,2);
939
connect(m_pUserNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
941
pLabel = new QLabel(__tr2qs_ctx("Realname:","options"),this);
942
pLayout->addWidget(pLabel,5,0);
944
m_pRealNameEdit = new QLineEdit(this);
945
KviTalToolTip::add(m_pRealNameEdit,__tr2qs_ctx("Put here the realname you want to use","options"));
946
pLayout->addWidget(m_pRealNameEdit,5,1,1,2);
947
connect(m_pRealNameEdit,SIGNAL(textChanged(const QString &)),this,SLOT(toggleButton(const QString &)));
949
KviTalHBox * pBox = new KviTalHBox(this);
950
pBox->setAlignment(Qt::AlignRight);
951
pLayout->addWidget(pBox,6,0);
953
QPushButton * p = new QPushButton(__tr2qs_ctx("Cancel","options"),pBox);
954
//p->setMinimumWidth(100);
955
connect(p,SIGNAL(clicked()),this,SLOT(reject()));
957
m_pBtnOk = new QPushButton(__tr2qs_ctx("OK","options"),pBox);
958
m_pBtnOk->setEnabled(false);
959
connect(m_pBtnOk,SIGNAL(clicked()),pParent,SLOT(editProfileOkPressed()));
961
pLayout->setColumnStretch(1,1);
963
setMinimumWidth(250);
966
KviIdentityProfileEditor::~KviIdentityProfileEditor()
970
bool KviIdentityProfileEditor::editProfile(KviIdentityProfile * pProfile)
972
// Fill in the fields
973
m_pNameEdit->setText(pProfile->name().isEmpty() ? QString(m_szName) : pProfile->name());
974
m_pNetworkEdit->setText(pProfile->network().isEmpty() ? QString(m_szNetwork) : pProfile->network());
975
m_pNickEdit->setText(pProfile->nick().isEmpty() ? QString(m_szNick) : pProfile->nick());
976
m_pAltNickEdit->setText(pProfile->altNick().isEmpty() ? QString(m_szAltNick) : pProfile->altNick());
977
m_pUserNameEdit->setText(pProfile->userName().isEmpty() ? QString(m_szUserName) : pProfile->userName());
978
m_pRealNameEdit->setText(pProfile->realName().isEmpty() ? QString(m_szRealName) : pProfile->realName());
981
m_pNameEdit->selectAll();
984
if(exec() != QDialog::Accepted) return false;
986
// Store data in the object
987
pProfile->setName(m_pNameEdit->text());
988
pProfile->setNetwork(m_pNetworkEdit->text());
989
pProfile->setNick(m_pNickEdit->text());
990
pProfile->setAltNick(m_pAltNickEdit->text());
991
pProfile->setUserName(m_pUserNameEdit->text());
992
pProfile->setRealName(m_pRealNameEdit->text());
997
void KviIdentityProfileEditor::toggleButton(const QString & szText)
999
bool bEnabled = true;
1002
(m_pNameEdit->text() == m_szName) ||
1003
(m_pNetworkEdit->text() == m_szNetwork) ||
1004
(m_pNickEdit->text() == m_szNick) ||
1005
(m_pAltNickEdit->text() == m_szAltNick) ||
1006
(m_pUserNameEdit->text() == m_szUserName) ||
1007
(m_pRealNameEdit->text() == m_szRealName) ||
1012
m_pBtnOk->setEnabled(bEnabled);
1015
#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES
1016
#include "m_optw_identity.moc"
1017
#endif //COMPILE_USE_STANDALONE_MOC_SOURCES