File indexing completed on 2024-04-28 04:02:31
0001 /*************************************************************************** 0002 dlgprofilesettings.cpp - profile settings 0003 This file is a part of KMuddy distribution. 0004 ------------------- 0005 begin : oct 18 2002 0006 copyright : (C) 2002-2007 by Tomas Mecir 0007 email : kmuddy@kmuddy.com 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 ***************************************************************************/ 0018 0019 #include "dlgprofilesettings.h" 0020 0021 #include "cdirlist.h" 0022 #include "cdialoglist.h" 0023 0024 #include <QCheckBox> 0025 #include <QComboBox> 0026 #include <QFileDialog> 0027 #include <QIcon> 0028 #include <QLabel> 0029 #include <QLineEdit> 0030 #include <QPushButton> 0031 #include <QGridLayout> 0032 #include <QVBoxLayout> 0033 0034 #include <kcodecaction.h> 0035 #include <KLocalizedString> 0036 0037 dlgProfileSettings::dlgProfileSettings (QWidget *parent) : KPageDialog (parent) 0038 { 0039 cDialogList::self()->addDialog ("profile-prefs", this); 0040 0041 //initial dialog size 0042 setWindowTitle (i18n ("MUD preferences")); 0043 setStandardButtons (QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply); 0044 setFaceType (KPageDialog::List); 0045 0046 //prepare dialog pages 0047 KPageWidgetItem *item; 0048 QFrame *frmconn = new QFrame (this); 0049 item = addPage (frmconn, i18n ("Connection")); 0050 item->setIcon (QIcon::fromTheme ("connection-established")); 0051 QFrame *frmcommands = new QFrame (this); 0052 item = addPage (frmcommands, i18n ("Commands")); 0053 item->setIcon (QIcon::fromTheme ("gear")); 0054 QFrame *frmdirs = new QFrame (this); 0055 item = addPage (frmdirs, i18n ("Folders")); 0056 item->setIcon (QIcon::fromTheme ("folder")); 0057 QFrame *frmsound = new QFrame (this); 0058 item = addPage (frmsound, i18n ("Sound")); 0059 item->setIcon (QIcon::fromTheme ("media-playback-start")); 0060 #ifdef HAVE_MXP 0061 QFrame *frmmxp = new QFrame (this); 0062 item = addPage (frmmxp, i18n ("MXP")); 0063 item->setIcon (QIcon::fromTheme ("go-jump")); 0064 #endif 0065 0066 //page 1 0067 QGridLayout *connlayout = new QGridLayout (frmconn); 0068 useansi = new QCheckBox (i18n ("&Use colorized output (if available)"), frmconn); 0069 limitrepeater = new QCheckBox (i18n ("&Do not allow more than 100 repeated commands"), frmconn); 0070 limitrepeater->setWhatsThis( "<qt>With this option turned on, usage of repeater string " 0071 "is limited to one hundred repeats. This is here to prevent you from sending " 0072 "lots of commands accidentally. Note that you can always cancel those " 0073 "unwanted commands with <b>Edit / Cancel pending commands</b>.</qt>"); 0074 0075 startupneg = new QCheckBox (i18n ("Enable telnet &negotiation on startup"), frmconn); 0076 startupneg->setWhatsThis( i18n ("Enables telnet negotiation for some option. Disabling " 0077 "it may resolve problems with some servers that do not understand these.")); 0078 0079 // encoding 0080 QLabel *lblencoding = new QLabel (i18n ("&Encoding:"), frmconn); 0081 btencoding = new QPushButton (frmconn); 0082 lblencoding->setBuddy (btencoding); 0083 btencoding->setWhatsThis( i18n ("Lets you pick the output character encoding used by the server. This usually only needs to be set for non-English servers.")); 0084 codecAction = new KCodecAction (this); 0085 btencoding->setMenu (codecAction->menu ()); 0086 connect (codecAction, &KCodecAction::textTriggered, this, &dlgProfileSettings::encodingChanged); 0087 0088 // LPMud prompt handling 0089 lpmudstyle = new QCheckBox (i18n ("&Auto-append newlines after prompt"), frmconn); 0090 lpmudstyle->setWhatsThis( i18n ("Enables adding linefeeds after GA-terminated prompts " 0091 "to have properly aligned output.")); 0092 0093 promptlabel = new QCheckBox (i18n ("&Show prompt in a separate field"), frmconn); 0094 promptlabel->setWhatsThis( "<qt>You will have prompt displayed in a special field " 0095 "on the left from your primary input line.</qt>"); 0096 0097 statusprompt = new QCheckBox (i18n ("Show prompt in the s&tatus bar"), frmconn); 0098 statusprompt->setWhatsThis( "<qt>Enables prompt display in the status bar.</qt>"); 0099 0100 consoleprompt = new QCheckBox (i18n ("Show prompt in the &console"), frmconn); 0101 consoleprompt->setWhatsThis( "<qt>Enables prompt display in the console.</qt>"); 0102 0103 autoadvtranscript = new QCheckBox (i18n ("Start advanced transcript when session starts"), frmconn); 0104 autoadvtranscript->setWhatsThis( "<qt>Starts advanced logging of the session upon session " 0105 "startup</qt>"); 0106 0107 connlayout->setSpacing (10); 0108 connlayout->addWidget (useansi, 0, 0, 1, 2); 0109 connlayout->addWidget (limitrepeater, 1, 0, 1, 2); 0110 connlayout->addWidget (lblencoding, 2, 0); 0111 connlayout->addWidget (btencoding, 2, 1); 0112 connlayout->addWidget (startupneg, 3, 0, 1, 2); 0113 connlayout->addWidget (lpmudstyle, 4, 0, 1, 2); 0114 connlayout->addWidget (promptlabel, 5, 0, 1, 2); 0115 connlayout->addWidget (statusprompt, 6, 0, 1, 2); 0116 connlayout->addWidget (consoleprompt, 7, 0, 1, 2); 0117 connlayout->addWidget (autoadvtranscript, 8, 0, 1, 2); 0118 connlayout->setRowStretch (9, 10); 0119 connlayout->setColumnStretch (1, 5); 0120 0121 //page 2 0122 QGridLayout *commlayout = new QGridLayout (frmcommands); 0123 0124 QLabel *cl[10]; 0125 QString texts[10] = { i18n ("&North"), i18n ("No&rtheast"), i18n ("&East"), 0126 i18n ("So&utheast"), i18n ("&South"), i18n ("Sou&thwest"), 0127 i18n ("&West"), i18n ("Nort&hwest"), i18n ("&Up"), i18n ("&Down")}; 0128 QString mcommandhelp = i18n ("This is a movement command. It is used" 0129 " by speed-walking and will also be used by the auto-mapper."); 0130 for (int i = 0; i < 10; i++) 0131 { 0132 cl[i] = new QLabel (texts[i], frmcommands); 0133 edcmd[i] = new QLineEdit ("", frmcommands); 0134 cl[i]->setBuddy (edcmd[i]); 0135 edcmd[i]->setWhatsThis( mcommandhelp); 0136 } 0137 0138 commlayout->setColumnStretch (1, 10); 0139 commlayout->setSpacing (5); 0140 for (int i = 0; i < 10; i++) 0141 { 0142 commlayout->addWidget (cl[i], i, 0); 0143 commlayout->addWidget (edcmd[i], i, 1); 0144 } 0145 commlayout->setRowStretch (10, 10); 0146 0147 //page 3 0148 QGridLayout *dirslayout = new QGridLayout (frmdirs); 0149 0150 QLabel *sl1 = new QLabel (i18n ("External &scripts directory"), frmdirs); 0151 edscriptdir = new QLineEdit (frmdirs); 0152 sl1->setBuddy (edscriptdir); 0153 QPushButton *locbutton = new QPushButton (i18n ("Browse..."), frmdirs); 0154 edscriptdir->setWhatsThis( i18n ("Default directory where we will look for " 0155 "scripts.")); 0156 0157 QLabel *sl2 = new QLabel (i18n ("&Working directory"), frmdirs); 0158 edscriptworkdir = new QLineEdit (frmdirs); 0159 sl2->setBuddy (edscriptworkdir); 0160 QPushButton *wrkbutton = new QPushButton (i18n ("Browse..."), frmdirs); 0161 edscriptworkdir->setWhatsThis( i18n ("Default working directory for your " 0162 "scripts. Making this the same as above is usually a good choice.")); 0163 0164 QLabel *sl3 = new QLabel (i18n ("&Transcripts directory"), frmdirs); 0165 edtranscriptdir = new QLineEdit (frmdirs); 0166 sl3->setBuddy (edtranscriptdir); 0167 QPushButton *trnbutton = new QPushButton (i18n ("Browse..."), frmdirs); 0168 edtranscriptdir->setWhatsThis( i18n ("Directory where session " 0169 "transcripts will be saved by default.")); 0170 0171 connect (locbutton, &QPushButton::clicked, this, &dlgProfileSettings::choosedir1); 0172 connect (wrkbutton, &QPushButton::clicked, this, &dlgProfileSettings::choosedir2); 0173 connect (trnbutton, &QPushButton::clicked, this, &dlgProfileSettings::choosedir3); 0174 0175 dirslayout->setSpacing (5); 0176 dirslayout->addWidget (sl1, 0, 0); 0177 dirslayout->addWidget (edscriptdir, 0, 1); 0178 dirslayout->addWidget (locbutton, 0, 2); 0179 dirslayout->addWidget (sl2, 1, 0); 0180 dirslayout->addWidget (edscriptworkdir, 1, 1); 0181 dirslayout->addWidget (wrkbutton, 1, 2); 0182 dirslayout->addWidget (sl3, 2, 0); 0183 dirslayout->addWidget (edtranscriptdir, 2, 1); 0184 dirslayout->addWidget (trnbutton, 2, 2); 0185 dirslayout->setRowStretch (3, 10); 0186 0187 //page 4 0188 QVBoxLayout *soundlayout = new QVBoxLayout (frmsound); 0189 usemsp = new QCheckBox (i18n ("&Enable sounds for this profile"), frmsound); 0190 usemsp->setWhatsThis( i18n ("Enable playing sounds with this profile.\n" 0191 "Note that this will only work if you enable sounds in global preferences.\n" 0192 "Also note that this will only work if your MUD supports <b>MSP</b> " 0193 "(MUD Sound Protocol).")); 0194 dirlist = new cDirList (frmsound); 0195 QLabel *lblmspwarning = new QLabel (i18n ("Only enable these if you need them:"), frmsound); 0196 alwaysmsp = new QCheckBox (i18n ("&Use MSP even if not negotiated"), frmsound); 0197 alwaysmsp->setWhatsThis( i18n ("When this option is enabled, KMuddy " 0198 "will interpret MSP sequences all the time, even if no negotiation " 0199 "took place. Useful for MUDs that don't support telnet negotiation of " 0200 "MSP.\nBut beware - only turn this on if your MUD really supports " 0201 "MSP to prevent other players from sending malicious MSP sequences, " 0202 "if you allow downloading of sounds.")); 0203 midlinemsp = new QCheckBox (i18n ("Allow &mid-line MSP sequences"), frmsound); 0204 midlinemsp->setWhatsThis( i18n ("Mid-line MSP sequences are a zMUD's " 0205 "extension to the MSP spec that some MUDs seem to be using. You can " 0206 "enable support for this feature here, but ensure that other players " 0207 "cannot say/tell/whatever these sequences, or disable downloading " 0208 "support; otherwise players could instruct your client to download " 0209 "any file on the net...")); 0210 0211 soundlayout->setSpacing (5); 0212 soundlayout->addWidget (usemsp); 0213 soundlayout->addWidget (dirlist); 0214 soundlayout->addWidget (lblmspwarning); 0215 soundlayout->addWidget (alwaysmsp); 0216 soundlayout->addWidget (midlinemsp); 0217 #ifdef HAVE_MXP 0218 QGridLayout *mxplayout = new QGridLayout (frmmxp); 0219 0220 QLabel *lblmxp1 = new QLabel (i18n ("&Use MXP"), frmmxp); 0221 cbmxpallowed = new QComboBox (frmmxp); 0222 lblmxp1->setBuddy (cbmxpallowed); 0223 cbmxpallowed->addItem (i18n ("Never")); 0224 cbmxpallowed->addItem (i18n ("If negotiated")); 0225 cbmxpallowed->addItem (i18n ("Auto-detect")); 0226 cbmxpallowed->addItem (i18n ("Always on")); 0227 cbmxpallowed->setWhatsThis( i18n ("<qt><p>Here you can choose when will MXP be used.</p>" 0228 "<ul><li><b>Never</b> MXP tags will never be parsed</li>" 0229 "<li><b>If negotiated</b> MXP support will depend on successful telnet negotiation.</li>" 0230 "<li><b>Auto-detect</b> MXP support will be auto-detected.</li>" 0231 "<li><b>Always on</b> KMuddy will always look for MXP sequences.</li></ul></qt>")); 0232 0233 QLabel *lblmxp2 = new QLabel (i18n ("MXP &variable prefix"), frmmxp); 0234 edvarprefix = new QLineEdit (frmmxp); 0235 lblmxp2->setBuddy (edvarprefix); 0236 edvarprefix->setWhatsThis( i18n ("Prefix prepended to each MXP variable from the server. " 0237 "Note that changing the prefix won't affect existing variables with old prefix.")); 0238 0239 mxplayout->setSpacing (5); 0240 mxplayout->addWidget (lblmxp1, 0, 0); 0241 mxplayout->addWidget (cbmxpallowed, 0, 1); 0242 mxplayout->addWidget (lblmxp2, 1, 0); 0243 mxplayout->addWidget (edvarprefix, 1, 1); 0244 mxplayout->setRowStretch (3, 10); 0245 #endif //HAVE_MXP 0246 } 0247 0248 dlgProfileSettings::~dlgProfileSettings () 0249 { 0250 cDialogList::self()->removeDialog ("profile-prefs"); 0251 0252 } 0253 0254 QSize dlgProfileSettings::sizeHint() const 0255 { 0256 return QSize (450, 350); 0257 } 0258 0259 bool dlgProfileSettings::useAnsi () 0260 { 0261 return useansi->isChecked (); 0262 } 0263 0264 void dlgProfileSettings::setUseAnsi (bool val) 0265 { 0266 useansi->setChecked (val); 0267 } 0268 0269 bool dlgProfileSettings::limitRepeater () 0270 { 0271 return limitrepeater->isChecked (); 0272 } 0273 0274 void dlgProfileSettings::setLimitRepeater (bool val) 0275 { 0276 limitrepeater->setChecked (val); 0277 } 0278 0279 bool dlgProfileSettings::negotiateOnStartup () 0280 { 0281 return startupneg->isChecked(); 0282 } 0283 0284 void dlgProfileSettings::setNegotiateOnStartup (bool val) 0285 { 0286 startupneg->setChecked (val); 0287 } 0288 0289 bool dlgProfileSettings::promptLabel() 0290 { 0291 return promptlabel->isChecked (); 0292 } 0293 0294 void dlgProfileSettings::setPromptLabel(bool val) 0295 { 0296 promptlabel->setChecked (val); 0297 } 0298 0299 bool dlgProfileSettings::LPMudStyle() 0300 { 0301 return lpmudstyle->isChecked(); 0302 } 0303 0304 void dlgProfileSettings::setLPMudStyle(bool val) 0305 { 0306 lpmudstyle->setChecked(val); 0307 } 0308 0309 QString dlgProfileSettings::encoding () 0310 { 0311 return codecAction->currentCodecName(); 0312 } 0313 0314 void dlgProfileSettings::setEncoding (const QString &encoding) 0315 { 0316 btencoding->setText (encoding); 0317 codecAction->setCurrentCodec (encoding); 0318 } 0319 0320 0321 bool dlgProfileSettings::statusPrompt() 0322 { 0323 return statusprompt->isChecked(); 0324 } 0325 0326 void dlgProfileSettings::setStatusPrompt(bool val) 0327 { 0328 statusprompt->setChecked(val); 0329 } 0330 0331 bool dlgProfileSettings::consolePrompt() 0332 { 0333 return consoleprompt->isChecked(); 0334 } 0335 0336 void dlgProfileSettings::setConsolePrompt(bool val) 0337 { 0338 consoleprompt->setChecked(val); 0339 } 0340 0341 bool dlgProfileSettings::autoAdvTranscript() 0342 { 0343 return autoadvtranscript->isChecked(); 0344 } 0345 0346 void dlgProfileSettings::setAutoAdvTranscript(bool val) 0347 { 0348 autoadvtranscript->setChecked(val); 0349 } 0350 QString dlgProfileSettings::movementCmd (int which) 0351 { 0352 if ((which >= 0) && (which <= 9)) 0353 return edcmd[which]->text (); 0354 else 0355 return ""; 0356 } 0357 0358 void dlgProfileSettings::setMovementCmd (int which, QString val) 0359 { 0360 if ((which >= 0) && (which <= 9)) 0361 edcmd[which]->setText (val); 0362 } 0363 0364 QString dlgProfileSettings::scriptDir () 0365 { 0366 return edscriptdir->text (); 0367 } 0368 0369 void dlgProfileSettings::setScriptDir (const QString &s) 0370 { 0371 edscriptdir->setText (s); 0372 } 0373 0374 QString dlgProfileSettings::scriptWorkDir () 0375 { 0376 return edscriptworkdir->text (); 0377 } 0378 0379 void dlgProfileSettings::setTranscriptDir (const QString &s) 0380 { 0381 edtranscriptdir->setText (s); 0382 } 0383 0384 QString dlgProfileSettings::transcriptDir () 0385 { 0386 return edtranscriptdir->text (); 0387 } 0388 0389 void dlgProfileSettings::setScriptWorkDir (const QString &s) 0390 { 0391 edscriptworkdir->setText (s); 0392 } 0393 0394 void dlgProfileSettings::choosedir1 () 0395 { 0396 edscriptdir->setText (QFileDialog::getExistingDirectory (this, i18n ("Choose default script location"), edscriptdir->text())); 0397 } 0398 0399 void dlgProfileSettings::choosedir2 () 0400 { 0401 edscriptworkdir->setText (QFileDialog::getExistingDirectory (this, i18n ("Choose default script working directory"), edscriptworkdir->text())); 0402 } 0403 0404 void dlgProfileSettings::choosedir3 () 0405 { 0406 edtranscriptdir->setText (QFileDialog::getExistingDirectory (this, i18n ("Choose default transcript directory"), edtranscriptdir->text())); 0407 } 0408 0409 void dlgProfileSettings::encodingChanged (const QString &enc) 0410 { 0411 btencoding->setText (enc); 0412 } 0413 0414 bool dlgProfileSettings::useMSP () 0415 { 0416 return usemsp->isChecked (); 0417 } 0418 0419 void dlgProfileSettings::setUseMSP (bool val) 0420 { 0421 usemsp->setChecked (val); 0422 } 0423 0424 bool dlgProfileSettings::alwaysMSP () 0425 { 0426 return alwaysmsp->isChecked (); 0427 } 0428 0429 void dlgProfileSettings::setAlwaysMSP (bool val) 0430 { 0431 alwaysmsp->setChecked (val); 0432 } 0433 0434 bool dlgProfileSettings::midlineMSP () 0435 { 0436 return midlinemsp->isChecked (); 0437 } 0438 0439 void dlgProfileSettings::setMidlineMSP (bool val) 0440 { 0441 midlinemsp->setChecked (val); 0442 } 0443 0444 const QStringList &dlgProfileSettings::soundDirList () 0445 { 0446 return dirlist->getDirList (); 0447 } 0448 0449 void dlgProfileSettings::setSoundDirList (const QStringList &list) 0450 { 0451 dirlist->setDirList (list); 0452 } 0453 0454 #ifdef HAVE_MXP 0455 0456 int dlgProfileSettings::MXPAllowed () 0457 { 0458 return cbmxpallowed->currentIndex() + 1; 0459 } 0460 0461 void dlgProfileSettings::setMXPAllowed (int allow) 0462 { 0463 cbmxpallowed->setCurrentIndex (allow - 1); 0464 } 0465 0466 void dlgProfileSettings::setVariablePrefix (const QString &prefix) 0467 { 0468 edvarprefix->setText (prefix); 0469 } 0470 0471 QString dlgProfileSettings::variablePrefix () 0472 { 0473 return edvarprefix->text (); 0474 } 0475 0476 #endif //HAVE_MXP 0477 0478 #include "moc_dlgprofilesettings.cpp"