summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorYohann Ferreira <bertram@cegetel.net>2008-04-25 23:15:03 +0000
committerYohann Ferreira <bertram@cegetel.net>2008-04-25 23:15:03 +0000
commit536f18bdaae32831aa92702535586f26d0628a42 (patch)
treef438efa69af7a6588bd00df126cd1f7c07bb8641 /src/gui
parent23e6d031b6c9f20dea6ba48dd1826d3286e18233 (diff)
downloadmana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.gz
mana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.bz2
mana-client-536f18bdaae32831aa92702535586f26d0628a42.tar.xz
mana-client-536f18bdaae32831aa92702535586f26d0628a42.zip
Added client-side email address change ability.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/changeemaildialog.cpp191
-rw-r--r--src/gui/changeemaildialog.h74
-rw-r--r--src/gui/changepassworddialog.cpp7
-rw-r--r--src/gui/char_select.cpp31
-rw-r--r--src/gui/char_select.h1
5 files changed, 289 insertions, 15 deletions
diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp
new file mode 100644
index 00000000..bb0329e6
--- /dev/null
+++ b/src/gui/changeemaildialog.cpp
@@ -0,0 +1,191 @@
+/*
+ * The Mana World
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "changeemaildialog.h"
+
+#include <string>
+#include <sstream>
+
+#include <guichan/widgets/label.hpp>
+
+#include "../main.h"
+#include "../log.h"
+#include "../logindata.h"
+
+#include "button.h"
+#include "register.h"
+#include "textfield.h"
+#include "ok_dialog.h"
+
+#include "../utils/gettext.h"
+#include "../utils/strprintf.h"
+
+ChangeEmailDialog::ChangeEmailDialog(Window *parent, LoginData *loginData):
+ Window(_("Change Email Address"), true, parent),
+ mWrongDataNoticeListener(new WrongDataNoticeListener()),
+ mLoginData(loginData)
+{
+ gcn::Label *accountLabel = new gcn::Label(strprintf(_("Account: %s"),
+ mLoginData->username.c_str()));
+ gcn::Label *oldEmailLabel = new gcn::Label(_("Current Email:"));
+ gcn::Label *newEmailLabel = new gcn::Label(_("Type New Email Address twice:"));
+ mOldEmailField = new TextField();
+ mFirstEmailField = new TextField();
+ mSecondEmailField = new TextField();
+ mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this);
+ mCancelButton = new Button(_("Cancel"), "cancel", this);
+
+ const int width = 200;
+ const int height = 170;
+ setContentSize(width, height);
+
+ accountLabel->setPosition(5, 5);
+ accountLabel->setWidth(130);
+ oldEmailLabel->setPosition(
+ 5, accountLabel->getY() + accountLabel->getHeight() + 7);
+ oldEmailLabel->setWidth(130);
+
+ mOldEmailField->setPosition(
+ 5, oldEmailLabel->getY() + oldEmailLabel->getHeight() + 7);
+ mOldEmailField->setWidth(width - 5);
+ mOldEmailField->setWidth(130);
+
+ newEmailLabel->setPosition(
+ 5, mOldEmailField->getY() + mOldEmailField->getHeight() + 7);
+ newEmailLabel->setWidth(width - 5);
+
+ mFirstEmailField->setPosition(
+ 5, newEmailLabel->getY() + newEmailLabel->getHeight() + 7);
+ mFirstEmailField->setWidth(130);
+
+ mSecondEmailField->setPosition(
+ 5, mFirstEmailField->getY() + mFirstEmailField->getHeight() + 7);
+ mSecondEmailField->setWidth(130);
+
+ mCancelButton->setPosition(
+ width - 5 - mCancelButton->getWidth(),
+ height - 5 - mCancelButton->getHeight());
+ mChangeEmailButton->setPosition(
+ mCancelButton->getX() - 5 - mChangeEmailButton->getWidth(),
+ mCancelButton->getY());
+
+ add(accountLabel);
+ add(oldEmailLabel);
+ add(mOldEmailField);
+ add(newEmailLabel);
+ add(mFirstEmailField);
+ add(mSecondEmailField);
+ add(mChangeEmailButton);
+ add(mCancelButton);
+
+ setLocationRelativeTo(getParent());
+ setVisible(true);
+ mOldEmailField->requestFocus();
+
+ mOldEmailField->setActionEventId("change_email");
+ mFirstEmailField->setActionEventId("change_email");
+ mSecondEmailField->setActionEventId("change_email");
+}
+
+ChangeEmailDialog::~ChangeEmailDialog()
+{
+ delete mWrongDataNoticeListener;
+}
+
+void
+ChangeEmailDialog::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "cancel")
+ {
+ scheduleDelete();
+ }
+ else if (event.getId() == "change_email")
+ {
+
+ const std::string username = mLoginData->username.c_str();
+ const std::string oldEmail = mOldEmailField->getText();
+ const std::string newFirstEmail = mFirstEmailField->getText();
+ const std::string newSecondEmail = mSecondEmailField->getText();
+ logger->log("ChangeEmailDialog::Email change, Username is %s",
+ username.c_str());
+
+ std::stringstream errorMsg;
+ int error = 0;
+
+ // Checking current Email
+ if (oldEmail.empty())
+ {
+ // First email address too short
+ errorMsg << "Please type your Email address.";
+ error = 1;
+ }
+ else if (newFirstEmail.length() < LEN_MIN_PASSWORD)
+ {
+ // First email address too short
+ errorMsg << "The new email address needs to be at least "
+ << LEN_MIN_PASSWORD
+ << " characters long.";
+ error = 2;
+ }
+ else if (newFirstEmail.length() > LEN_MAX_PASSWORD - 1 )
+ {
+ // First email address too long
+ errorMsg << "The new email address needs to be less than "
+ << LEN_MAX_PASSWORD
+ << " characters long.";
+ error = 2;
+ }
+ else if (newFirstEmail != newSecondEmail)
+ {
+ // Second Pass mismatch
+ errorMsg << "The email address entries mismatch.";
+ error = 2;
+ }
+
+ if (error > 0)
+ {
+ if (error == 1)
+ {
+ mWrongDataNoticeListener->setTarget(this->mOldEmailField);
+ }
+ else if (error == 2)
+ {
+ mWrongDataNoticeListener->setTarget(this->mFirstEmailField);
+ }
+
+ OkDialog *dlg = new OkDialog("Error", errorMsg.str());
+ dlg->addActionListener(mWrongDataNoticeListener);
+ }
+ else
+ {
+ // No errors detected, change account password.
+ mChangeEmailButton->setEnabled(false);
+ // Set the new email address
+ mLoginData->email = oldEmail;
+ mLoginData->newEmail = newFirstEmail;
+ state = STATE_CHANGEEMAIL_ATTEMPT;
+ scheduleDelete();
+ }
+
+ }
+}
diff --git a/src/gui/changeemaildialog.h b/src/gui/changeemaildialog.h
new file mode 100644
index 00000000..22dc1263
--- /dev/null
+++ b/src/gui/changeemaildialog.h
@@ -0,0 +1,74 @@
+/*
+ * The Mana World
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_GUI_CHANGEEMAIL_H
+#define _TMW_GUI_CHANGEEMAIL_H
+
+#include <iosfwd>
+#include <guichan/actionlistener.hpp>
+
+#include "window.h"
+#include "../guichanfwd.h"
+
+class LoginData;
+class OkDialog;
+class WrongDataNoticeListener;
+
+/**
+ * The Change email dialog.
+ *
+ * \ingroup Interface
+ */
+class ChangeEmailDialog : public Window, public gcn::ActionListener {
+ public:
+ /**
+ * Constructor
+ *
+ * @see Window::Window
+ */
+ ChangeEmailDialog(Window *parent, LoginData *loginData);
+
+ /**
+ * Destructor
+ */
+ ~ChangeEmailDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const gcn::ActionEvent &event);
+
+ private:
+ gcn::TextField *mOldEmailField;
+ gcn::TextField *mFirstEmailField;
+ gcn::TextField *mSecondEmailField;
+
+ gcn::Button *mChangeEmailButton;
+ gcn::Button *mCancelButton;
+
+ WrongDataNoticeListener *mWrongDataNoticeListener;
+
+ LoginData *mLoginData;
+};
+
+#endif
diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp
index 6f30d296..e3bb0511 100644
--- a/src/gui/changepassworddialog.cpp
+++ b/src/gui/changepassworddialog.cpp
@@ -33,7 +33,6 @@
#include "../logindata.h"
#include "button.h"
-#include "checkbox.h"
#include "register.h"
#include "passwordfield.h"
#include "textfield.h"
@@ -43,7 +42,7 @@
#include "../utils/strprintf.h"
ChangePasswordDialog::ChangePasswordDialog(Window *parent, LoginData *loginData):
- Window("Change Password", true, parent),
+ Window(_("Change Password"), true, parent),
mWrongDataNoticeListener(new WrongDataNoticeListener()),
mLoginData(loginData)
{
@@ -54,8 +53,8 @@ ChangePasswordDialog::ChangePasswordDialog(Window *parent, LoginData *loginData)
gcn::Label *newPassLabel = new gcn::Label(_("Type New Password twice:"));
mFirstPassField = new PasswordField();
mSecondPassField = new PasswordField();
- mChangePassButton = new Button("Change Password", "change_password", this);
- mCancelButton = new Button("Cancel", "cancel", this);
+ mChangePassButton = new Button(_("Change Password"), "change_password", this);
+ mCancelButton = new Button(_("Cancel"), "cancel", this);
const int width = 200;
const int height = 170;
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index d5a487fb..c011aa84 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -37,6 +37,7 @@
#include "unregisterdialog.h"
#include "changepassworddialog.h"
+#include "changeemaildialog.h"
#include "widgets/layout.h"
@@ -99,6 +100,7 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
mNextButton = new Button(_("Next"), "next", this);
mUnRegisterButton = new Button(_("Unregister"), "unregister", this);
mChangePasswordButton = new Button(_("Change Password"), "change_password", this);
+ mChangeEmailButton = new Button(_("Change Email Address"), "change_email", this);
mAccountNameLabel = new gcn::Label(strprintf(_("Account: %s"), mLoginData->username.c_str()));
mNameLabel = new gcn::Label(strprintf(_("Name: %s"), ""));
@@ -113,25 +115,28 @@ CharSelectDialog::CharSelectDialog(LockedArray<LocalPlayer*> *charInfo,
place = getPlacer(0, 0);
place(0, 0, mAccountNameLabel);
place(0, 1, mUnRegisterButton);
- place(1, 1, mChangePasswordButton);
- place(0, 2, mPlayerBox, 1, 5).setPadding(3);
- place(1, 2, mNameLabel, 3);
- place(1, 3, mLevelLabel, 3);
- place(1, 4, mMoneyLabel, 3);
- place(1, 5, mPreviousButton);
- place(2, 5, mNextButton);
- place(1, 6, mNewCharButton);
- place(2, 6, mDelCharButton);
- place.getCell().matchColWidth(1, 2);
+ place(0, 2, mChangePasswordButton);
+ place(1, 2, mChangeEmailButton);
place = getPlacer(0, 1);
+ place(0, 0, mPlayerBox, 1, 5).setPadding(3);
+ place(1, 0, mNameLabel, 3);
+ place(1, 1, mLevelLabel, 3);
+ place(1, 2, mMoneyLabel, 3);
+ place(1, 3, mPreviousButton);
+ place(2, 3, mNextButton);
+ place(1, 4, mNewCharButton);
+ place(2, 4, mDelCharButton);
+ place.getCell().matchColWidth(1, 2);
+ place = getPlacer(0, 2);
place(0, 0, mSelectButton);
place(1, 0, mCancelButton);
- reflowLayout(350, 0);
+ reflowLayout(265, 0);
setLocationRelativeTo(getParent());
setVisible(true);
mSelectButton->requestFocus();
updatePlayerInfo();
+
}
void CharSelectDialog::action(const gcn::ActionEvent &event)
@@ -191,6 +196,10 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
{
new ChangePasswordDialog(this, mLoginData);
}
+ else if (event.getId() == "change_email")
+ {
+ new ChangeEmailDialog(this, mLoginData);
+ }
}
void CharSelectDialog::updatePlayerInfo()
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index 9c7bac24..0c1dbe45 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -71,6 +71,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener
gcn::Button *mNextButton;
gcn::Button *mUnRegisterButton;
gcn::Button *mChangePasswordButton;
+ gcn::Button *mChangeEmailButton;
gcn::Label *mAccountNameLabel;
gcn::Label *mNameLabel;