File indexing completed on 2024-04-28 04:02:31
0001 /*************************************************************************** 0002 dlgeditprofile.cpp - Edit Profile dialog 0003 This file is a part of KMuddy distribution. 0004 ------------------- 0005 begin : Pá Aug 9 2002 0006 copyright : (C) 2002-2008 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 "dlgeditprofile.h" 0020 0021 //needed by gcc 3.2 0022 #define max(a,b) (((a) >= (b)) ? (a) : (b)) 0023 0024 #include <QDialogButtonBox> 0025 #include <QGridLayout> 0026 #include <QLabel> 0027 #include <QLineEdit> 0028 #include <QPushButton> 0029 #include <QSpinBox> 0030 0031 #include <KLocalizedString> 0032 #include <kpassworddialog.h> 0033 #include <kmessagebox.h> 0034 #include <KTextEdit> 0035 0036 dlgEditProfile::dlgEditProfile(QWidget *parent) : QDialog (parent) 0037 { 0038 setWindowTitle (i18n ("Edit profile")); 0039 0040 //create main dialog's widget 0041 QGridLayout *layout = new QGridLayout (this); 0042 0043 // put some edit boxes there 0044 QLabel *l1 = new QLabel (i18n ("Profile &name:"), this); 0045 ed1 = new QLineEdit (this); 0046 ed1->setWhatsThis( i18n ("Enter profile name here. You can enter any name, but it must be <b>unique</b>.")); 0047 QLabel *l2 = new QLabel (i18n ("&Server:"), this); 0048 ed2 = new QLineEdit (this); 0049 ed2->setWhatsThis( i18n ("Enter address of the server where your MUD is running.")); 0050 QLabel *l3 = new QLabel (i18n ("&Port:"), this); 0051 ed3 = new QSpinBox (this); 0052 ed3->setRange(1, 65535); 0053 ed3->setValue(23); 0054 ed3->setWhatsThis( i18n ("Enter port on which your MUD is running (usually some 4-digit number).")); 0055 QLabel *l4 = new QLabel (i18n ("&Login name:"), this); 0056 ed4 = new QLineEdit (this); 0057 ed4->setWhatsThis( i18n ("Enter your login name on the MUD here.<p><i>This setting is optional.</i>")); 0058 QLabel *l5 = new QLabel (i18n ("Pass&word:"), this); 0059 ed5 = new QLineEdit (this); 0060 ed5->setEchoMode (QLineEdit::Password); 0061 ed5->setWhatsThis( i18n ("Enter your password on the MUD here.<p><i>This setting is optional.</i>")); 0062 QLabel *l6 = new QLabel (i18n ("&Connect sequence"), this); 0063 connstr = new KTextEdit (this); 0064 connstr->setAcceptRichText (false); 0065 connstr->setWordWrapMode (QTextOption::NoWrap); 0066 connstr->setWhatsThis( i18n ("Commands to be sent to the MUD after " 0067 "logging in.<br><b>$name</b> expands to username.<br><b>$password</b> " 0068 "expands to your password.<p><b>Important:</b> these commands are sent " 0069 "exactly as you type them, with leading/trailing spaces removed. " 0070 "No aliases, no macros, no speed-walk. Also note that empty lines " 0071 "will also be sent, including the very last line.")); 0072 0073 QDialogButtonBox *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0074 connect (buttons, &QDialogButtonBox::accepted, this, &QDialog::accept); 0075 connect (buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); 0076 0077 l1->setBuddy (ed1); 0078 l2->setBuddy (ed2); 0079 l3->setBuddy (ed3); 0080 l4->setBuddy (ed4); 0081 l5->setBuddy (ed5); 0082 l6->setBuddy (connstr); 0083 0084 layout->setSpacing (10); 0085 // layout->addWidget (btlist, 0, 0); 0086 layout->addWidget (l1, 1, 0); 0087 layout->addWidget (l2, 2, 0); 0088 layout->addWidget (l3, 3, 0); 0089 layout->addWidget (l4, 4, 0); 0090 layout->addWidget (l5, 5, 0); 0091 layout->addWidget (l6, 6, 0); 0092 layout->addWidget (ed1, 1, 1); 0093 layout->addWidget (ed2, 2, 1); 0094 layout->addWidget (ed3, 3, 1); 0095 layout->addWidget (ed4, 4, 1); 0096 layout->addWidget (ed5, 5, 1); 0097 layout->addWidget (connstr, 7, 0, 1, 2); 0098 layout->addWidget (buttons, 8, 0, 1, 2); 0099 0100 ed1->setFocus (); 0101 } 0102 0103 dlgEditProfile::~dlgEditProfile() 0104 { 0105 //nothing here 0106 } 0107 0108 QSize dlgEditProfile::sizeHint() const 0109 { 0110 return QSize (350, 350); 0111 } 0112 0113 QString dlgEditProfile::name () 0114 { 0115 return ed1->text (); 0116 } 0117 0118 QString dlgEditProfile::server () 0119 { 0120 return ed2->text(); 0121 } 0122 0123 int dlgEditProfile::port () 0124 { 0125 return ed3->value(); 0126 } 0127 0128 QString dlgEditProfile::login () 0129 { 0130 return ed4->text (); 0131 } 0132 0133 QString dlgEditProfile::password () 0134 { 0135 return ed5->text (); 0136 } 0137 0138 QStringList dlgEditProfile::connectionString () 0139 { 0140 return connstr->toPlainText().split ("\n"); 0141 } 0142 0143 void dlgEditProfile::setName (QString name) 0144 { 0145 ed1->setText (name); 0146 } 0147 0148 void dlgEditProfile::setServer (QString server) 0149 { 0150 ed2->setText (server); 0151 } 0152 0153 void dlgEditProfile::setPort (int port) 0154 { 0155 ed3->setValue (port); 0156 } 0157 0158 void dlgEditProfile::setLogin (QString login) 0159 { 0160 ed4->setText (login); 0161 } 0162 0163 void dlgEditProfile::setPassword (QString password) 0164 { 0165 ed5->setText (password); 0166 } 0167 0168 void dlgEditProfile::setConnectionString (QStringList conn) 0169 { 0170 connstr->setPlainText (conn.join ("\n")); 0171 } 0172 0173 void dlgEditProfile::accept () 0174 { 0175 QString s = name ().simplified (); 0176 bool failed = false; 0177 if (s == "") 0178 { 0179 failed = true; 0180 KMessageBox::error (this, i18n ("Profile name cannot be empty."), i18n ("Edit profile")); 0181 } 0182 //looks like filenames can contain '/' char, but who knows? 0183 if (s.contains ('/')) 0184 { 0185 KMessageBox::error (this, i18n ("Profile name cannot contain '/' character."), i18n ("Edit profile")); 0186 failed = true; 0187 } 0188 0189 //if name is okay, accept the dialog... 0190 if (failed) return; 0191 0192 QDialog::accept (); 0193 } 0194 0195 #include "moc_dlgeditprofile.cpp"