| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 1999-2006 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 "registeruser.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QCheckBox> |
|---|
| 26 | #include <QGridLayout> |
|---|
| 27 | #include <QLabel> |
|---|
| 28 | #include <QLineEdit> |
|---|
| 29 | #include <QList> |
|---|
| 30 | #include <QVariant> |
|---|
| 31 | #include <QVBoxLayout> |
|---|
| 32 | #include <QWizardPage> |
|---|
| 33 | |
|---|
| 34 | #include <licq_icqd.h> |
|---|
| 35 | |
|---|
| 36 | #include "core/licqgui.h" |
|---|
| 37 | #include "core/messagebox.h" |
|---|
| 38 | #include "core/signalmanager.h" |
|---|
| 39 | |
|---|
| 40 | #include "helpers/support.h" |
|---|
| 41 | |
|---|
| 42 | using namespace LicqQtGui; |
|---|
| 43 | /* TRANSLATOR LicqQtGui::RegisterUserDlg */ |
|---|
| 44 | /* TRANSLATOR LicqQtGui::VerifyDlg */ |
|---|
| 45 | |
|---|
| 46 | RegisterUserDlg::RegisterUserDlg(QWidget* parent) |
|---|
| 47 | : QWizard(parent), |
|---|
| 48 | myGotCaptcha(false), |
|---|
| 49 | myGotOwner(false), |
|---|
| 50 | mySuccess(false) |
|---|
| 51 | { |
|---|
| 52 | Support::setWidgetProps(this, "RegisterUserDialog"); |
|---|
| 53 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 54 | setWindowTitle(tr("Register Account")); |
|---|
| 55 | |
|---|
| 56 | QList<WizardButton> buttons; |
|---|
| 57 | buttons << Stretch << NextButton << FinishButton << CancelButton; |
|---|
| 58 | setButtonLayout(buttons); |
|---|
| 59 | |
|---|
| 60 | createIntroPage(); |
|---|
| 61 | createPasswordPage(); |
|---|
| 62 | createCaptchaPage(); |
|---|
| 63 | createResultPage(); |
|---|
| 64 | |
|---|
| 65 | show(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | RegisterUserDlg::~RegisterUserDlg() |
|---|
| 69 | { |
|---|
| 70 | emit signal_done(mySuccess, myId, myPpid); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | void RegisterUserDlg::createIntroPage() |
|---|
| 74 | { |
|---|
| 75 | // First page, just some welcome text |
|---|
| 76 | // in future this should be used to select protocol |
|---|
| 77 | myIntroPage = new QWizardPage; |
|---|
| 78 | |
|---|
| 79 | myIntroPage->setTitle(tr("Introduction")); |
|---|
| 80 | |
|---|
| 81 | QVBoxLayout* layout = new QVBoxLayout(myIntroPage); |
|---|
| 82 | |
|---|
| 83 | QLabel* introText = new QLabel(tr("Welcome to the Registration Wizard.\n\n" |
|---|
| 84 | "You can register a new ICQ account here.\n\n" |
|---|
| 85 | "Press \"Next\" to proceed.")); |
|---|
| 86 | |
|---|
| 87 | introText->setWordWrap(true); |
|---|
| 88 | layout->addWidget(introText); |
|---|
| 89 | |
|---|
| 90 | addPage(myIntroPage); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | void RegisterUserDlg::createPasswordPage() |
|---|
| 94 | { |
|---|
| 95 | // Ask user for password information |
|---|
| 96 | myPasswordPage = new QWizardPage; |
|---|
| 97 | |
|---|
| 98 | myPasswordPage->setTitle(tr("Select password")); |
|---|
| 99 | myPasswordPage->setSubTitle(tr("Specify a password for your account.\nLength must be 1 to 8 characters.")); |
|---|
| 100 | |
|---|
| 101 | QGridLayout* layout = new QGridLayout(myPasswordPage); |
|---|
| 102 | |
|---|
| 103 | QLabel* passwordLabel = new QLabel(tr("&Password:")); |
|---|
| 104 | myPasswordField = new QLineEdit(); |
|---|
| 105 | myPasswordField->setMaxLength(8); |
|---|
| 106 | myPasswordField->setEchoMode(QLineEdit::Password); |
|---|
| 107 | passwordLabel->setBuddy(myPasswordField); |
|---|
| 108 | layout->addWidget(passwordLabel, 0, 0); |
|---|
| 109 | layout->addWidget(myPasswordField, 0, 1); |
|---|
| 110 | |
|---|
| 111 | QLabel* verifyLabel = new QLabel(tr("&Verify:")); |
|---|
| 112 | myVerifyField = new QLineEdit(); |
|---|
| 113 | myVerifyField->setMaxLength(8); |
|---|
| 114 | myVerifyField->setEchoMode(QLineEdit::Password); |
|---|
| 115 | verifyLabel->setBuddy(myVerifyField); |
|---|
| 116 | layout->addWidget(verifyLabel, 1, 0); |
|---|
| 117 | layout->addWidget(myVerifyField, 1, 1); |
|---|
| 118 | |
|---|
| 119 | mySavePassword = new QCheckBox(tr("&Remember Password")); |
|---|
| 120 | mySavePassword->setChecked(true); |
|---|
| 121 | layout->addWidget(mySavePassword, 2, 0, 1, 2); |
|---|
| 122 | |
|---|
| 123 | addPage(myPasswordPage); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void RegisterUserDlg::createCaptchaPage() |
|---|
| 127 | { |
|---|
| 128 | // Present captcha image and ask for user verification |
|---|
| 129 | myCaptchaPage = new QWizardPage; |
|---|
| 130 | |
|---|
| 131 | myCaptchaPage->setTitle(tr("Account Verification")); |
|---|
| 132 | myCaptchaPage->setSubTitle(tr("Retype the letters shown in the image.")); |
|---|
| 133 | |
|---|
| 134 | QGridLayout* layout = new QGridLayout(myCaptchaPage); |
|---|
| 135 | |
|---|
| 136 | myCaptchaImage = new QLabel(); |
|---|
| 137 | layout->addWidget(myCaptchaImage, 0, 0, 1, 2, Qt::AlignHCenter); |
|---|
| 138 | |
|---|
| 139 | QLabel* captchaLabel = new QLabel(tr("&Verification:")); |
|---|
| 140 | myCaptchaField = new QLineEdit(); |
|---|
| 141 | captchaLabel->setBuddy(myCaptchaField); |
|---|
| 142 | layout->addWidget(captchaLabel, 1, 0); |
|---|
| 143 | layout->addWidget(myCaptchaField, 1, 1); |
|---|
| 144 | |
|---|
| 145 | addPage(myCaptchaPage); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void RegisterUserDlg::createResultPage() |
|---|
| 149 | { |
|---|
| 150 | // Last page, show information about the newly acquired account |
|---|
| 151 | myResultPage = new QWizardPage; |
|---|
| 152 | |
|---|
| 153 | myResultPage->setTitle(tr("Registration Completed")); |
|---|
| 154 | |
|---|
| 155 | QGridLayout* layout = new QGridLayout(myResultPage); |
|---|
| 156 | |
|---|
| 157 | QLabel* finishText1 = new QLabel(tr("Account registration has been successfuly completed.")); |
|---|
| 158 | layout->addWidget(finishText1, 0, 0, 1, 3); |
|---|
| 159 | |
|---|
| 160 | // Show user id in a readonly input field to make it more visible and allow copying it |
|---|
| 161 | QLabel* ownerIdLabel = new QLabel(tr("Your new user Id:")); |
|---|
| 162 | myOwnerIdField = new QLineEdit(); |
|---|
| 163 | myOwnerIdField->setReadOnly(true); |
|---|
| 164 | layout->addWidget(ownerIdLabel, 1, 0); |
|---|
| 165 | layout->addWidget(myOwnerIdField, 1, 1); |
|---|
| 166 | |
|---|
| 167 | QLabel* finishText2 = new QLabel(tr("You are now being automatically logged on.\n" |
|---|
| 168 | "Click Finish to edit your personal details.\n" |
|---|
| 169 | "After you are online, you can send your personal details to the server.")); |
|---|
| 170 | layout->addWidget(finishText2, 2, 0, 1, 3); |
|---|
| 171 | |
|---|
| 172 | addPage(myResultPage); |
|---|
| 173 | } |
|---|
| 174 | |
|---|
| 175 | bool RegisterUserDlg::validateCurrentPage() |
|---|
| 176 | { |
|---|
| 177 | if (currentPage() == myPasswordPage && !myGotCaptcha) |
|---|
| 178 | { |
|---|
| 179 | if (myPasswordField->text().isEmpty()) |
|---|
| 180 | return false; |
|---|
| 181 | |
|---|
| 182 | if (myPasswordField->text() != myVerifyField->text()) |
|---|
| 183 | { |
|---|
| 184 | WarnUser(this, tr("Passwords don't match.")); |
|---|
| 185 | return false; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | // Disable dialog while we're waiting for server to respond |
|---|
| 189 | setEnabled(false); |
|---|
| 190 | button(CancelButton)->setEnabled(true); |
|---|
| 191 | connect(LicqGui::instance()->signalManager(), |
|---|
| 192 | SIGNAL(verifyImage(unsigned long)), SLOT(gotCaptcha(unsigned long))); |
|---|
| 193 | gLicqDaemon->icqRegister(myPasswordField->text().toLatin1().data()); |
|---|
| 194 | return false; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | if (currentPage() == myCaptchaPage && !myGotOwner) |
|---|
| 198 | { |
|---|
| 199 | if (myCaptchaField->text().isEmpty()) |
|---|
| 200 | return false; |
|---|
| 201 | |
|---|
| 202 | // Disable dialog while we're waiting for server to respond |
|---|
| 203 | setEnabled(false); |
|---|
| 204 | button(CancelButton)->setEnabled(true); |
|---|
| 205 | connect(LicqGui::instance()->signalManager(), |
|---|
| 206 | SIGNAL(newOwner(QString, unsigned long)), SLOT(gotNewOwner(QString, unsigned long))); |
|---|
| 207 | gLicqDaemon->icqVerify(myCaptchaField->text().toLatin1().data()); |
|---|
| 208 | return false; |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | return true; |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | void RegisterUserDlg::gotCaptcha(unsigned long /* ppid */) |
|---|
| 215 | { |
|---|
| 216 | // We got the image so reenable the dialog, set the image and go to next page |
|---|
| 217 | disconnect(LicqGui::instance()->signalManager(), |
|---|
| 218 | SIGNAL(verifyImage(unsigned long)), this, SLOT(gotCaptcha(unsigned long))); |
|---|
| 219 | setEnabled(true); |
|---|
| 220 | myCaptchaImage->setPixmap(QPixmap(QString(BASE_DIR) + "/Licq_verify.jpg")); |
|---|
| 221 | myGotCaptcha = true; |
|---|
| 222 | next(); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | void RegisterUserDlg::gotNewOwner(QString id, unsigned long ppid) |
|---|
| 226 | { |
|---|
| 227 | // We got the new owner |
|---|
| 228 | disconnect(LicqGui::instance()->signalManager(), |
|---|
| 229 | SIGNAL(newOwner(QString, unsigned long)), this, SLOT(gotNewOwner(QString, unsigned long))); |
|---|
| 230 | |
|---|
| 231 | // Save "Remember password" setting |
|---|
| 232 | ICQOwner* o = gUserManager.FetchOwner(ppid, LOCK_W); |
|---|
| 233 | if (o != NULL) |
|---|
| 234 | { |
|---|
| 235 | o->SetSavePassword(mySavePassword->isChecked()); |
|---|
| 236 | gUserManager.DropOwner(o); |
|---|
| 237 | gLicqDaemon->SaveConf(); |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | // Mark that we have finished |
|---|
| 241 | mySuccess = true; |
|---|
| 242 | myId = id; |
|---|
| 243 | myPpid = ppid; |
|---|
| 244 | |
|---|
| 245 | // Go to result page |
|---|
| 246 | setEnabled(true); |
|---|
| 247 | myGotOwner = true; |
|---|
| 248 | myOwnerIdField->setText(id); |
|---|
| 249 | next(); |
|---|
| 250 | } |
|---|