diff options
| author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-06-07 23:30:05 +0900 |
|---|---|---|
| committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-06-07 23:30:05 +0900 |
| commit | 17b259df9cb6b28779d4881b2b6c805ee2e48eea (patch) | |
| tree | 5ed61937459cb7081089111b0242c01ec178f1f3 /fbreader/src/networkActions | |
| parent | 1cba8bce178eb2d6719c6f7f21e2c9352c5513a6 (diff) | |
| download | tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.tar.gz tde-ebook-reader-17b259df9cb6b28779d4881b2b6c805ee2e48eea.zip | |
Rename to tde-ebook-reader
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'fbreader/src/networkActions')
| -rw-r--r-- | fbreader/src/networkActions/AuthenticationDialog.cpp | 122 | ||||
| -rw-r--r-- | fbreader/src/networkActions/AuthenticationDialog.h | 50 | ||||
| -rw-r--r-- | fbreader/src/networkActions/AuthenticationDialogManager.cpp | 192 | ||||
| -rw-r--r-- | fbreader/src/networkActions/AuthenticationDialogManager.h | 37 | ||||
| -rw-r--r-- | fbreader/src/networkActions/NetworkActions.cpp | 357 | ||||
| -rw-r--r-- | fbreader/src/networkActions/NetworkActions.h | 103 | ||||
| -rw-r--r-- | fbreader/src/networkActions/NetworkOperationRunnable.cpp | 187 | ||||
| -rw-r--r-- | fbreader/src/networkActions/NetworkOperationRunnable.h | 184 | ||||
| -rw-r--r-- | fbreader/src/networkActions/PasswordRecoveryDialog.cpp | 95 | ||||
| -rw-r--r-- | fbreader/src/networkActions/PasswordRecoveryDialog.h | 46 | ||||
| -rw-r--r-- | fbreader/src/networkActions/RegisterUserDialog.cpp | 146 | ||||
| -rw-r--r-- | fbreader/src/networkActions/RegisterUserDialog.h | 50 |
12 files changed, 0 insertions, 1569 deletions
diff --git a/fbreader/src/networkActions/AuthenticationDialog.cpp b/fbreader/src/networkActions/AuthenticationDialog.cpp deleted file mode 100644 index 4f4ed1a..0000000 --- a/fbreader/src/networkActions/AuthenticationDialog.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLDialog.h> -#include <ZLDialogManager.h> -#include <ZLOptionsDialog.h> -#include <ZLOptionEntry.h> - -#include <ZLSimpleOptionEntry.h> - -#include "../network/NetworkLink.h" -#include "AuthenticationDialog.h" -#include "NetworkOperationRunnable.h" -#include "../network/UserList.h" -#include "../network/authentication/NetworkAuthenticationManager.h" - -class UserNamesEntry : public ZLComboOptionEntry { - -public: - UserNamesEntry(UserList &userList, ZLStringOption &userNameOption); - - const std::string &initialValue() const; - const std::vector<std::string> &values() const; - void onAccept(const std::string &value); - -private: - UserList &myUserList; - ZLStringOption &myUserNameOption; -}; - -UserNamesEntry::UserNamesEntry(UserList &userList, ZLStringOption &userNameOption) : - ZLComboOptionEntry(true), myUserList(userList), myUserNameOption(userNameOption) { -} - -const std::string &UserNamesEntry::initialValue() const { - return myUserNameOption.value(); -} - -const std::vector<std::string> &UserNamesEntry::values() const { - return myUserList.users(); -} - -void UserNamesEntry::onAccept(const std::string &value) { - myUserList.addUser(value); - myUserNameOption.setValue(value); -} - - -class PasswordOptionEntry : public ZLPasswordOptionEntry { - -public: - PasswordOptionEntry(std::string &password); - - virtual const std::string &initialValue() const; - virtual void onAccept(const std::string &value); - -private: - std::string &myPassword; -}; - -PasswordOptionEntry::PasswordOptionEntry(std::string &password) : myPassword(password) { -} - -const std::string &PasswordOptionEntry::initialValue() const { - static const std::string _empty; - return _empty; -} - -void PasswordOptionEntry::onAccept(const std::string &value) { - myPassword = value; -} - -AuthenticationDialog::AuthenticationDialog(ZLStringOption &userNameOption, UserList &userList, const std::string &errorMessage, std::string &password) : - myUserList(userList) { - myDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("AuthenticationDialog")); - - if (!errorMessage.empty()) { - myDialog->addOption("", "", new ZLSimpleStaticTextOptionEntry(errorMessage)); - } - - myDialog->addOption(ZLResourceKey("login"), new UserNamesEntry(myUserList, userNameOption)); - myDialog->addOption(ZLResourceKey("password"), new PasswordOptionEntry(password)); - - myDialog->addButton(ZLDialogManager::OK_BUTTON, true); - myDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); -} - -bool AuthenticationDialog::run(ZLStringOption &userNameOption, UserList &userList, const std::string &errorMessage, std::string &password) { - AuthenticationDialog dlg(userNameOption, userList, errorMessage, password); - if (dlg.dialog().run()) { - dlg.dialog().acceptValues(); - return true; - } - return false; -} - -bool AuthenticationDialog::run(const std::string &siteName, std::string &userName, std::string &password, const std::string &message) { - UserList userList(siteName); - //TODO fix it: using unexisted string option, just for dialog showing - ZLStringOption userNameOption(ZLCategoryKey::NETWORK, "", "userName", userName); - userNameOption.setValue(std::string()); - bool result = run(userNameOption, userList, message, password); - userName = userNameOption.value(); - userNameOption.clearGroup(""); - return result; -} diff --git a/fbreader/src/networkActions/AuthenticationDialog.h b/fbreader/src/networkActions/AuthenticationDialog.h deleted file mode 100644 index ff5148c..0000000 --- a/fbreader/src/networkActions/AuthenticationDialog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __AUTHENTICATIONDIALOG_H__ -#define __AUTHENTICATIONDIALOG_H__ - -#include <string> - -#include <ZLOptionEntry.h> - -#include "../network/UserList.h" - -class ZLDialog; -class NetworkAuthenticationManager; - -class AuthenticationDialog { - -public: - static bool run(ZLStringOption &userNameOption, UserList &userList, const std::string &errorMessage, std::string &password); - static bool run(const std::string &siteName, std::string &username, std::string &password, const std::string &message); - -private: - AuthenticationDialog(ZLStringOption &userNameOption, UserList &userList, const std::string &errorMessage, std::string &password); - - ZLDialog &dialog(); - -private: - shared_ptr<ZLDialog> myDialog; - UserList &myUserList; -}; - -inline ZLDialog &AuthenticationDialog::dialog() { return *myDialog; } - -#endif /* __AUTHENTICATIONDIALOG_H__ */ diff --git a/fbreader/src/networkActions/AuthenticationDialogManager.cpp b/fbreader/src/networkActions/AuthenticationDialogManager.cpp deleted file mode 100644 index 165ab01..0000000 --- a/fbreader/src/networkActions/AuthenticationDialogManager.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLExecutionUtil.h> -#include <ZLResource.h> -#include <ZLTimeManager.h> - -#include "../network/NetworkErrors.h" -#include "../network/NetworkLink.h" -#include "AuthenticationDialog.h" -#include "NetworkOperationRunnable.h" - -#include "AuthenticationDialogManager.h" - -class AuthenticationDialogListener : public ZLNetworkRequest::Listener { -public: - AuthenticationDialogListener(NetworkAuthenticationManager &mgr, shared_ptr<ZLNetworkRequest::Listener> listener); - - void returnAnswer(bool result); - virtual void finished(const std::string &error = std::string()); - -private: - void restart(const std::string &error); - - enum State { LogOut, Authorisation, Initialization }; - - shared_ptr<ZLNetworkRequest::Listener> myHolder; - - NetworkAuthenticationManager &myManager; - shared_ptr<ZLNetworkRequest::Listener> myListener; - std::string myPassword; - UserList myUserList; - std::string myError; - State myState; -}; - -AuthenticationDialogListener::AuthenticationDialogListener(NetworkAuthenticationManager &mgr, shared_ptr<ZLNetworkRequest::Listener> listener) - : myHolder(this), myManager(mgr), myListener(listener), myUserList(mgr.Link.getSiteName()), myState(LogOut) { - finished(std::string()); //start state machine from LogOut state -} - -void AuthenticationDialogListener::returnAnswer(bool result) { - if (result) { - myUserList.saveUser(myManager.currentUserName()); - } - // TODO: Return notable error - myListener->setUIStatus(false); - myListener->finished(result ? std::string() : "Some error"); - ZLTimeManager::deleteLater(myHolder); - myHolder.reset(); -} - - - -void AuthenticationDialogListener::finished(const std::string &error) { - myError = error; - myListener->setUIStatus(false); - switch (myState) { - case LogOut: - if (!AuthenticationDialog::run(myManager.UserNameOption, myUserList, myError, myPassword)) { - myManager.logOut(); - returnAnswer(false); - return; - } - if (myManager.UserNameOption.value().empty()) { - const ZLResource &resource = ZLResource::resource("dialog")["AuthenticationDialog"]; - restart(resource["loginIsEmpty"].value()); - } else { - myState = Authorisation; - myListener->setUIStatus(true); - myManager.authorise(myPassword, myHolder); - return; - } - break; - case Authorisation: - if (!myError.empty()) { - restart(myError); - return; - } - if (myManager.needsInitialization()) { - myState = Initialization; - myListener->setUIStatus(true); - myManager.initialize(myHolder); - } else { - returnAnswer(true); - } - break; - case Initialization: - if (!myError.empty()) { - restart(myError); - return; - } - returnAnswer(true); - break; - } -} - -void AuthenticationDialogListener::restart(const std::string &error) { - myPassword.clear(); - myState = LogOut; - finished(error); - //TODO it was autoremovable task here -} - - -class AuthoriseIfCanListener : public ZLNetworkRequest::Listener { -public: - AuthoriseIfCanListener(NetworkAuthenticationManager &mgr, shared_ptr<ZLNetworkRequest::Listener> listener); - - void returnAnswer(std::string answer = std::string()); - virtual void finished(const std::string &error = std::string()); - -private: - enum State { Init, AuthorisationCheck, Initialization}; - - shared_ptr<ZLNetworkRequest::Listener> myHolder; - - NetworkAuthenticationManager &myManager; - shared_ptr<ZLNetworkRequest::Listener> myListener; - State myState; -}; - -AuthoriseIfCanListener::AuthoriseIfCanListener(NetworkAuthenticationManager &mgr, shared_ptr<ZLNetworkRequest::Listener> listener) - : myHolder(this), myManager(mgr), myListener(listener), myState(Init) { - finished(std::string()); //start state machine from Init state -} - -void AuthoriseIfCanListener::returnAnswer(std::string answer) { - myListener->setUIStatus(false); - myListener->finished(answer); - ZLTimeManager::deleteLater(myHolder); - myHolder.reset(); -} - -void AuthoriseIfCanListener::finished(const std::string &error) { - myListener->setUIStatus(false); - switch (myState) { - case Init: - myListener->setUIStatus(true); - myState = AuthorisationCheck; - myManager.isAuthorised(myHolder); - break; - case AuthorisationCheck: - if (!error.empty()) { - NetworkErrors::showErrorMessage(error); - returnAnswer(error); - return; - } - if (myManager.needsInitialization()) { - myState = Initialization; - myListener->setUIStatus(true); - myManager.initialize(myHolder); - } else { - returnAnswer(); - } - break; - case Initialization: - if (!error.empty()) { - NetworkErrors::showErrorMessage(error); - returnAnswer(error); - return; - } - returnAnswer(); - break; - } -} - -std::string AuthenticationDialogManager::authAndInitAsync(NetworkAuthenticationManager &manager, shared_ptr<ZLNetworkRequest::Listener> listener) { - new AuthenticationDialogListener(manager, listener); - return std::string(); -} - -std::string AuthenticationDialogManager::athoriseIfCan(NetworkAuthenticationManager &manager, shared_ptr<ZLNetworkRequest::Listener> listener) { - new AuthoriseIfCanListener(manager, listener); - return std::string(); -} diff --git a/fbreader/src/networkActions/AuthenticationDialogManager.h b/fbreader/src/networkActions/AuthenticationDialogManager.h deleted file mode 100644 index 3648d59..0000000 --- a/fbreader/src/networkActions/AuthenticationDialogManager.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __AUTHENTICATIONDIALOGMANAGER_H__ -#define __AUTHENTICATIONDIALOGMANAGER_H__ - -#include <ZLNetworkRequest.h> - -#include "../network/authentication/NetworkAuthenticationManager.h" - -class AuthenticationDialogManager { - -public: - static std::string authAndInitAsync(NetworkAuthenticationManager &manager, shared_ptr<ZLNetworkRequest::Listener> listener); - static std::string athoriseIfCan(NetworkAuthenticationManager &manager, shared_ptr<ZLNetworkRequest::Listener> listener); - -private: - AuthenticationDialogManager() {} -}; - -#endif /* __AUTHENTICATIONDIALOGMANAGER_H__ */ diff --git a/fbreader/src/networkActions/NetworkActions.cpp b/fbreader/src/networkActions/NetworkActions.cpp deleted file mode 100644 index 90a9725..0000000 --- a/fbreader/src/networkActions/NetworkActions.cpp +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLResource.h> -#include <ZLFile.h> -#include <ZLStringUtil.h> -#include <ZLDialogManager.h> -#include <ZLNetworkRequest.h> -#include <ZLExecutionUtil.h> - -#include "../network/NetworkLinkCollection.h" -#include "../network/NetworkErrors.h" -#include "NetworkActions.h" -#include "AuthenticationDialogManager.h" -#include "NetworkOperationRunnable.h" - -#include "../network/NetworkItems.h" -#include "../network/NetworkLink.h" -#include "../network/authentication/NetworkAuthenticationManager.h" - -#include "../library/Book.h" -#include "../fbreader/FBReader.h" - -NetworkBookReadAction::NetworkBookReadAction(const NetworkBookItem &book, bool demo) : myBook(book), myDemo(demo) { -} - -ZLResourceKey NetworkBookReadAction::key() const { - return ZLResourceKey(myDemo ? "readDemo" : "read"); -} - -bool NetworkBookReadAction::makesSense() const { - if (myDemo) { - if (!myBook.localCopyFileName().empty() || - !myBook.reference(BookReference::DOWNLOAD_FULL).isNull()) { - return false; - } - shared_ptr<BookReference> reference = - myBook.reference(BookReference::DOWNLOAD_DEMO); - return !reference.isNull() && !reference->localCopyFileName().empty(); - } else { - return !myBook.localCopyFileName().empty(); - } -} - -void NetworkBookReadAction::run() { - std::string fileName; - if (myDemo) { - shared_ptr<BookReference> reference = - myBook.reference(BookReference::DOWNLOAD_DEMO); - if (!reference.isNull()) { - fileName = reference->localCopyFileName(); - } - } else { - fileName = myBook.localCopyFileName(); - } - if (!fileName.empty()) { - FBReader &fbreader = FBReader::Instance(); - shared_ptr<Book> bookPtr; - fbreader.createBook(ZLFile(fileName), bookPtr); - if (!bookPtr.isNull()) { - fbreader.openBook(bookPtr); - fbreader.setMode(FBReader::BOOK_TEXT_MODE); - fbreader.refreshWindow(); - NetworkLibrary::Instance().refresh(); - } - } -} - -NetworkBookDownloadAction::NetworkBookDownloadAction(NetworkBookTree &tree, const NetworkBookItem &book, bool demo, const std::string &tag) : myTree(tree), myBook(book), myDemo(demo), myTag(tag) { -} - -ZLResourceKey NetworkBookDownloadAction::key() const { - return ZLResourceKey(myDemo ? "downloadDemo" : "download"); -} - -bool NetworkBookDownloadAction::makesSense() const { - if (myDemo) { - if (!myBook.localCopyFileName().empty() || - !myBook.reference(BookReference::DOWNLOAD_FULL).isNull()) { - return false; - } - shared_ptr<BookReference> reference = - myBook.reference(BookReference::DOWNLOAD_DEMO); - return !reference.isNull() && reference->localCopyFileName().empty(); - } else { - return - myBook.localCopyFileName().empty() && - !myBook.reference(BookReference::DOWNLOAD_FULL).isNull(); - } -} - -class NetworkBookDownloadActionListener : public ZLNetworkRequest::Listener { -public: - NetworkBookDownloadActionListener(NetworkBookDownloadAction *action) : myAction(action) {} - void finished(const std::string &error) { - myAction->onBookDownloaded(error); - } - -private: - NetworkBookDownloadAction *myAction; -}; - -void NetworkBookDownloadAction::run() { - - myTree.notifyDownloadStarted(); - - if (!NetworkOperationRunnable::tryConnect()) { - return; - } - - shared_ptr<BookReference> reference = myBook.reference( - myDemo ? BookReference::DOWNLOAD_DEMO : BookReference::DOWNLOAD_FULL - ); - if (reference.isNull()) { - return; - } - bool result = NetworkLinkCollection::Instance().downloadBook(*reference, myFileName, new NetworkBookDownloadActionListener(this)); - if (!result) { - NetworkErrors::showErrorMessage(NetworkLinkCollection::Instance().errorMessage()); - } -} - -void NetworkBookDownloadAction::onBookDownloaded(const std::string &error) { - - myTree.notifyDownloadStopped(); - - if (!error.empty()) { - NetworkErrors::showErrorMessage(error); - } - FBReader &fbreader = FBReader::Instance(); - shared_ptr<Book> downloaderBook; - fbreader.createBook(ZLFile(myFileName), downloaderBook); - if (downloaderBook.isNull()) { - ZLFile(myFileName).remove(); - ZLResourceKey boxKey("cantOpenDownloadedFile"); - const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); - ZLDialogManager::Instance().errorBox(boxKey, message); - fbreader.refreshWindow(); - NetworkLibrary::Instance().refresh(); - return; - } - - downloaderBook->removeAllAuthors(); - for (std::vector<NetworkBookItem::AuthorData>::const_iterator it = myBook.Authors.begin(); it != myBook.Authors.end(); ++it) { - downloaderBook->addAuthor(it->DisplayName, it->SortKey); - } - std::string bookTitle = myBook.Title; - if (!myTag.empty()) { - bookTitle += " (" + myTag + ")"; - } - downloaderBook->setTitle(bookTitle); - downloaderBook->setLanguage(myBook.Language); - for (std::vector<std::string>::const_iterator it = myBook.Tags.begin(); it != myBook.Tags.end(); ++it) { - downloaderBook->addTag(*it); - } - if (!myTag.empty()) { - downloaderBook->addTag(myTag); - } - Library::Instance().addBook(downloaderBook); - - fbreader.openBook(downloaderBook); - fbreader.setMode(FBReader::BOOK_TEXT_MODE); - fbreader.refreshWindow(); - NetworkLibrary::Instance().refresh(); -} - -NetworkBookBuyDirectlyAction::NetworkBookBuyDirectlyAction(NetworkBookTree &tree, const NetworkBookItem &book) :NetworkBookDownloadAction(tree, book, false) { -} - -ZLResourceKey NetworkBookBuyDirectlyAction::key() const { - return ZLResourceKey("buy"); -} - -bool NetworkBookBuyDirectlyAction::makesSense() const { - return - myBook.localCopyFileName().empty() && - myBook.reference(BookReference::DOWNLOAD_FULL).isNull() && - !myBook.reference(BookReference::BUY).isNull(); -} - -std::string NetworkBookBuyDirectlyAction::text(const ZLResource &resource) const { - const std::string text = ZLRunnableWithKey::text(resource); - shared_ptr<BookReference> reference = myBook.reference(BookReference::BUY); - if (!reference.isNull()) { - return ZLStringUtil::printf(text, ((BuyBookReference&)*reference).Price); - } - return text; -} - -void NetworkBookBuyDirectlyAction::run() { - if (myBook.Link.authenticationManager().isNull()) { - finished(std::string()); - return; - } - if (!NetworkOperationRunnable::tryConnect()) { - finished(std::string()); - return; - } - - NetworkAuthenticationManager &mgr = *myBook.Link.authenticationManager(); - myTree.notifyDownloadStarted(); - mgr.isAuthorised(ZLExecutionUtil::createListener(this, &NetworkBookBuyDirectlyAction::onAuthorisationCheck)); -} - -class BuyActionAuthListener : public ZLNetworkRequest::Listener { -public: - BuyActionAuthListener(NetworkBookBuyDirectlyAction &action) : myAction(action) { - } - - void finished(const std::string &error) { - myAction.onAuthorised(error); - } - - void setUIStatus(bool enabled) { - if (enabled) { - myAction.myTree.notifyDownloadStarted(); - } else { - myAction.myTree.notifyDownloadStopped(); - } - } - -private: - NetworkBookBuyDirectlyAction &myAction; -}; - -void NetworkBookBuyDirectlyAction::onAuthorisationCheck(ZLUserDataHolder &/*data*/, const std::string &error) { - myTree.notifyDownloadStopped(); - if (error.empty()) { - onAuthorised(error); - } else { - AuthenticationDialogManager::authAndInitAsync( - *myBook.Link.authenticationManager(), - new BuyActionAuthListener(*this) - ); - } -} - -void NetworkBookBuyDirectlyAction::onAuthorised(const std::string &error) { - if (!error.empty()) { - finished(std::string()); //ignore error message - return; - } - NetworkAuthenticationManager &mgr = *myBook.Link.authenticationManager(); - if (!mgr.needPurchase(myBook)) { - finished(std::string()); - return; - } - ZLResourceKey boxKey("purchaseConfirmBox"); - const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); - const int code = ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("buy"), ZLResourceKey("buyAndDownload"), ZLDialogManager::CANCEL_BUTTON); - if (code == 2) { - finished(std::string()); - return; - } - bool downloadBook = code == 1; - if (mgr.needPurchase(myBook)) { - ZLUserDataHolder *bookData = new ZLUserDataHolder; - if (downloadBook) { - bookData->addUserData("downloadBook", new ZLUserData); - } - myTree.notifyDownloadStarted(); - mgr.purchaseBook(myBook, ZLExecutionUtil::createListener(bookData, this, &NetworkBookBuyDirectlyAction::onPurchased)); - } else if (downloadBook) { - NetworkBookDownloadAction::run(); - } -} - -void NetworkBookBuyDirectlyAction::onPurchased(ZLUserDataHolder &data, const std::string &error) { - if (!error.empty()) { - finished(error); - return; - } - if (data.getUserData("downloadBook").isNull()) { - finished(std::string()); - } else { - NetworkBookDownloadAction::run(); - } -} - -void NetworkBookBuyDirectlyAction::finished(const std::string &error) { - myTree.notifyDownloadStopped(); - NetworkLibrary::Instance().refresh(); - if (!error.empty()) { - ZLDialogManager::Instance().errorBox(ZLResourceKey("networkError"), error); - } -} - -NetworkBookBuyInBrowserAction::NetworkBookBuyInBrowserAction(const NetworkBookItem &book) : myBook(book) { -} - -ZLResourceKey NetworkBookBuyInBrowserAction::key() const { - return ZLResourceKey("buy"); -} - -bool NetworkBookBuyInBrowserAction::makesSense() const { - return - myBook.localCopyFileName().empty() && - myBook.reference(BookReference::DOWNLOAD_FULL).isNull() && - myBook.reference(BookReference::BUY).isNull() && - !myBook.reference(BookReference::BUY_IN_BROWSER).isNull(); -} - -std::string NetworkBookBuyInBrowserAction::text(const ZLResource &resource) const { - const std::string text = ZLRunnableWithKey::text(resource); - shared_ptr<BookReference> reference = myBook.reference(BookReference::BUY_IN_BROWSER); - if (!reference.isNull()) { - return ZLStringUtil::printf(text, ((BuyBookReference&)*reference).Price); - } - return text; -} - -void NetworkBookBuyInBrowserAction::run() { - shared_ptr<BookReference> reference = myBook.reference(BookReference::BUY_IN_BROWSER); - if (!reference.isNull()) { - FBReader::Instance().openLinkInBrowser(reference->URL); - } - NetworkLibrary::Instance().refresh(); -} - -NetworkBookDeleteAction::NetworkBookDeleteAction(const NetworkBookItem &book) : myBook(book) { -} - -ZLResourceKey NetworkBookDeleteAction::key() const { - return ZLResourceKey("delete"); -} - -bool NetworkBookDeleteAction::makesSense() const { - return !myBook.localCopyFileName().empty(); -} - -void NetworkBookDeleteAction::run() { - ZLResourceKey boxKey("deleteLocalCopyBox"); - const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title); - if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) != 0) { - return; - } - - myBook.removeLocalFiles(); - FBReader::Instance().refreshWindow(); - NetworkLibrary::Instance().refresh(); -} diff --git a/fbreader/src/networkActions/NetworkActions.h b/fbreader/src/networkActions/NetworkActions.h deleted file mode 100644 index f0cf513..0000000 --- a/fbreader/src/networkActions/NetworkActions.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __NETWORKACTIONS_H__ -#define __NETWORKACTIONS_H__ - -#include <ZLRunnable.h> -#include <ZLNetworkRequest.h> -#include "../network/tree/NetworkLibrary.h" - -class NetworkBookItem; - -class NetworkBookDownloadAction : public ZLRunnableWithKey { - -public: - NetworkBookDownloadAction(NetworkBookTree &tree, const NetworkBookItem &book, bool demo, const std::string &tag = std::string()); - ZLResourceKey key() const; - bool makesSense() const; - void run(); - - virtual void onBookDownloaded(const std::string &error); //virtual for using redefined in NetworkTreeBookDownloadAction - -protected: - NetworkBookTree &myTree; - const NetworkBookItem &myBook; - const bool myDemo; - const std::string myTag; - std::string myFileName; -}; - -class NetworkBookReadAction : public ZLRunnableWithKey { - -public: - NetworkBookReadAction(const NetworkBookItem &book, bool demo); - ZLResourceKey key() const; - bool makesSense() const; - void run(); - -private: - const NetworkBookItem &myBook; - const bool myDemo; -}; - -class NetworkBookBuyDirectlyAction : public NetworkBookDownloadAction { - -public: - NetworkBookBuyDirectlyAction(NetworkBookTree &tree, const NetworkBookItem &book); - ZLResourceKey key() const; - bool makesSense() const; - std::string text(const ZLResource &resource) const; - void run(); - -private: - void onAuthorisationCheck(ZLUserDataHolder &data, const std::string &error); - void onAuthorised(const std::string &error); - void onPurchased(ZLUserDataHolder &data, const std::string &error); - void finished(const std::string &error); - -friend class BuyActionAuthListener; -}; - -class NetworkBookBuyInBrowserAction : public ZLRunnableWithKey { - -public: - NetworkBookBuyInBrowserAction(const NetworkBookItem &book); - ZLResourceKey key() const; - bool makesSense() const; - std::string text(const ZLResource &resource) const; - void run(); - -private: - const NetworkBookItem &myBook; -}; - -class NetworkBookDeleteAction : public ZLRunnableWithKey { - -public: - NetworkBookDeleteAction(const NetworkBookItem &book); - ZLResourceKey key() const; - bool makesSense() const; - void run(); - -private: - const NetworkBookItem &myBook; -}; - -#endif /* __NETWORKACTIONS_H__ */ diff --git a/fbreader/src/networkActions/NetworkOperationRunnable.cpp b/fbreader/src/networkActions/NetworkOperationRunnable.cpp deleted file mode 100644 index 11a874c..0000000 --- a/fbreader/src/networkActions/NetworkOperationRunnable.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (C) 2008-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLDialogManager.h> -#include <ZLProgressDialog.h> -#include <ZLNetworkManager.h> - -#include "NetworkOperationRunnable.h" - -#include "../network/NetworkItems.h" -#include "../network/NetworkLink.h" -#include "../network/NetworkLinkCollection.h" -#include "../network/authentication/NetworkAuthenticationManager.h" - -NetworkOperationRunnable::NetworkOperationRunnable(const std::string &uiMessageKey) { - myDialog = - ZLDialogManager::Instance().createProgressDialog(ZLResourceKey(uiMessageKey), true); -} - -NetworkOperationRunnable::~NetworkOperationRunnable() { -} - -void NetworkOperationRunnable::executeWithUI() { - myDialog->run(*this); -} - -bool NetworkOperationRunnable::hasErrors() const { - return !myErrorMessage.empty(); -} - -void NetworkOperationRunnable::showErrorMessage(const std::string &message) { - ZLDialogManager::Instance().errorBox( - ZLResourceKey("networkError"), - message - ); -} - -const std::string &NetworkOperationRunnable::errorMessage() const { - return myErrorMessage; -} - -bool NetworkOperationRunnable::tryConnect() { - if (!ZLNetworkManager::Instance().connect()) { - showErrorMessage( - ZLResource::resource("dialog") - ["networkError"] - ["couldntConnectToNetworkMessage"].value() - ); - return false; - } - return true; -} - -void NetworkOperationRunnable::showErrorMessage() const { - if (!myErrorMessage.empty()) { - showErrorMessage(myErrorMessage); - } -} - -DownloadBookRunnable::DownloadBookRunnable(shared_ptr<BookReference> reference, shared_ptr<NetworkAuthenticationManager> authManager) : NetworkOperationRunnable("downloadBook") { - myReference = reference; - myAuthManager = authManager; -} - -DownloadBookRunnable::DownloadBookRunnable(const std::string &url) : NetworkOperationRunnable("downloadBook") { - myReference = new BookReference(url, BookReference::NONE, BookReference::DOWNLOAD_FULL); -} - -DownloadBookRunnable::~DownloadBookRunnable() { -} - -void DownloadBookRunnable::run() { - NetworkLinkCollection::Instance().downloadBook( - *myReference, myFileName, - myDialog->listener() - ); - myErrorMessage = NetworkLinkCollection::Instance().errorMessage(); -} - -const std::string &DownloadBookRunnable::fileName() const { - return myFileName; -} - -//AuthoriseRunnable::AuthoriseRunnable(NetworkAuthenticationManager &mgr, const std::string &password) : -// NetworkOperationRunnable("authentication"), -// myManager(mgr), -// myPassword(password) { -//} - -//void AuthoriseRunnable::run() { -// myErrorMessage = myManager.authorise(myPassword); -//} - -//LogOutRunnable::LogOutRunnable(NetworkAuthenticationManager &mgr) : -// NetworkOperationRunnable("signOut"), -// myManager(mgr) { -//} - -//void LogOutRunnable::run() { -// if (myManager.isAuthorised().Status != B3_FALSE) { -// myManager.logOut(); -// } -//} - -PasswordRecoveryRunnable::PasswordRecoveryRunnable(NetworkAuthenticationManager &mgr, const std::string &email) : - NetworkOperationRunnable("passwordRecovery"), - myManager(mgr), - myEMail(email) { -} - -void PasswordRecoveryRunnable::run() { - myErrorMessage = myManager.recoverPassword(myEMail); -} - -RegisterUserRunnable::RegisterUserRunnable(NetworkAuthenticationManager &mgr, const std::string &login, const std::string &password, const std::string &email) : - NetworkOperationRunnable("registerUser"), - myManager(mgr), - myLogin(login), - myPassword(password), - myEMail(email) { -} - -void RegisterUserRunnable::run() { - myErrorMessage = myManager.registerUser(myLogin, myPassword, myEMail); -} - - -SearchRunnable::SearchRunnable() : NetworkOperationRunnable("downloadBookList") { -} - - -SimpleSearchRunnable::SimpleSearchRunnable(const std::string &pattern) : myPattern(pattern) { -} - -void SimpleSearchRunnable::run() { - mySearchResult = NetworkLinkCollection::Instance().simpleSearch(myPattern); - myErrorMessage = NetworkLinkCollection::Instance().errorMessage(); -} - - -AdvancedSearchRunnable::AdvancedSearchRunnable(const std::string &titleAndSeries, const std::string &author, const std::string &category, const std::string &description) : myTitleAndSeries(titleAndSeries), myAuthor(author), myCategory(category), myDescription(description) { -} - -void AdvancedSearchRunnable::run() { - mySearchResult = NetworkLinkCollection::Instance().advancedSearch(myTitleAndSeries, myAuthor, myCategory, myDescription); - myErrorMessage = NetworkLinkCollection::Instance().errorMessage(); -} - - -LoadSubCatalogRunnable::LoadSubCatalogRunnable(NetworkCatalogItem &item, NetworkItem::List &children) : - NetworkOperationRunnable("loadSubCatalog"), - myItem(item), - myChildren(children) { -} - -void LoadSubCatalogRunnable::run() { - myErrorMessage = myItem.loadChildren(myChildren); -} - -DownloadBookRunnableAsync::DownloadBookRunnableAsync(shared_ptr<BookReference> reference, shared_ptr<NetworkAuthenticationManager> authManager) { - myReference = reference; - myAuthManager = authManager; -} - -void DownloadBookRunnableAsync::run() { -} - -void DownloadBookRunnableAsync::showPercent(int /*ready*/, int /*full*/) {} - -void DownloadBookRunnableAsync::finished(const std::string &error) { -} diff --git a/fbreader/src/networkActions/NetworkOperationRunnable.h b/fbreader/src/networkActions/NetworkOperationRunnable.h deleted file mode 100644 index 4a7e8da..0000000 --- a/fbreader/src/networkActions/NetworkOperationRunnable.h +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2008-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __NETWORKOPERATIONRUNNABLE_H__ -#define __NETWORKOPERATIONRUNNABLE_H__ - -#include <string> - -#include <ZLRunnable.h> -#include <ZLBoolean3.h> - -#include "../network/NetworkItems.h" -#include "../network/NetworkBookCollection.h" - -class ZLProgressDialog; - -class NetworkAuthenticationManager; - -class NetworkOperationRunnable : public ZLRunnable { - -public: - static void showErrorMessage(const std::string &message); - static bool tryConnect(); - -protected: - NetworkOperationRunnable(const std::string &uiMessageKey); - ~NetworkOperationRunnable(); - -public: - void executeWithUI(); - bool hasErrors() const; - void showErrorMessage() const; - const std::string &errorMessage() const; - -protected: - std::string myErrorMessage; - shared_ptr<ZLProgressDialog> myDialog; -}; - -class DownloadBookRunnable : public NetworkOperationRunnable { - -public: - DownloadBookRunnable(shared_ptr<BookReference> reference, shared_ptr<NetworkAuthenticationManager> authManager); - DownloadBookRunnable(const std::string &url); - ~DownloadBookRunnable(); - void run(); - - const std::string &fileName() const; - -private: - shared_ptr<BookReference> myReference; - shared_ptr<NetworkAuthenticationManager> myAuthManager; - std::string myFileName; -}; - -class DownloadBookRunnableAsync : public ZLNetworkRequest::Listener { - -public: - DownloadBookRunnableAsync(shared_ptr<BookReference> reference, shared_ptr<NetworkAuthenticationManager> authManager); - void run(); - - void showPercent(int ready, int full); - void finished(const std::string &error); - -private: - shared_ptr<BookReference> myReference; - shared_ptr<NetworkAuthenticationManager> myAuthManager; - std::string myFileName; -}; - -//class AuthoriseRunnable : public NetworkOperationRunnable { - -//public: -// AuthoriseRunnable(NetworkAuthenticationManager &mgr, const std::string &password); -// void run(); - -//private: -// NetworkAuthenticationManager &myManager; -// const std::string &myPassword; -//}; - -//class LogOutRunnable : public NetworkOperationRunnable { - -//public: -// LogOutRunnable(NetworkAuthenticationManager &mgr); -// void run(); - -//private: -// NetworkAuthenticationManager &myManager; -//}; - -class PasswordRecoveryRunnable : public NetworkOperationRunnable { - -public: - PasswordRecoveryRunnable(NetworkAuthenticationManager &mgr, const std::string &email); - void run(); - -private: - NetworkAuthenticationManager &myManager; - const std::string &myEMail; -}; - -class RegisterUserRunnable : public NetworkOperationRunnable { - -public: - RegisterUserRunnable(NetworkAuthenticationManager &mgr, const std::string &login, const std::string &password, const std::string &email); - void run(); - -private: - NetworkAuthenticationManager &myManager; - const std::string &myLogin; - const std::string &myPassword; - const std::string &myEMail; -}; - - -class SearchRunnable : public NetworkOperationRunnable { - -protected: - SearchRunnable(); - -public: - shared_ptr<NetworkBookCollection> result(); - -protected: - shared_ptr<NetworkBookCollection> mySearchResult; -}; - -inline shared_ptr<NetworkBookCollection> SearchRunnable::result() { return mySearchResult; } - - -class SimpleSearchRunnable : public SearchRunnable { - -public: - SimpleSearchRunnable(const std::string &pattern); - void run(); - -private: - const std::string myPattern; -}; - - -class AdvancedSearchRunnable : public SearchRunnable { - -public: - AdvancedSearchRunnable(const std::string &titleAndSeries, const std::string &author, const std::string &category, const std::string &description); - void run(); - -private: - const std::string myTitleAndSeries; - const std::string myAuthor; - const std::string myCategory; - const std::string myDescription; -}; - - -class LoadSubCatalogRunnable : public NetworkOperationRunnable { - -public: - LoadSubCatalogRunnable(NetworkCatalogItem &item, NetworkItem::List &children); - void run(); - -private: - NetworkCatalogItem &myItem; - NetworkItem::List &myChildren; -}; - -#endif /* __NETWORKOPERATIONRUNNABLE_H__ */ diff --git a/fbreader/src/networkActions/PasswordRecoveryDialog.cpp b/fbreader/src/networkActions/PasswordRecoveryDialog.cpp deleted file mode 100644 index c02fa15..0000000 --- a/fbreader/src/networkActions/PasswordRecoveryDialog.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLStringUtil.h> -#include <ZLDialog.h> -#include <ZLDialogManager.h> -#include <ZLOptionsDialog.h> -#include <ZLOptionEntry.h> - -#include <ZLSimpleOptionEntry.h> -#include <ZLStringEditOptionEntry.h> - -#include "PasswordRecoveryDialog.h" -#include "NetworkOperationRunnable.h" - -#include "../network/authentication/NetworkAuthenticationManager.h" -#include "../network/NetworkErrors.h" - -#include "../fbreader/FBReader.h" - -PasswordRecoveryDialog::PasswordRecoveryDialog(std::string &email, const std::string &errorMessage) { - myDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("PasswordRecoveryDialog")); - - if (!errorMessage.empty()) { - myDialog->addOption("", "", new ZLSimpleStaticTextOptionEntry(errorMessage)); - } - - myDialog->addOption(ZLResourceKey("email"), new ZLStringEditOptionEntry(email)); - - myDialog->addButton(ZLDialogManager::OK_BUTTON, true); - myDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); -} - -bool PasswordRecoveryDialog::runDialog(std::string &email, std::string &errorMessage) { - //const ZLResource &resource = ZLResource::resource("dialog")["PasswordRecoveryDialog"]; - while (true) { - PasswordRecoveryDialog dlg(email, errorMessage); - if (dlg.dialog().run()) { - dlg.dialog().acceptValues(); - if (email.empty()) { - errorMessage = NetworkErrors::errorMessage(NetworkErrors::ERROR_EMAIL_WAS_NOT_SPECIFIED); - continue; - } - std::size_t atPos = email.find('@'); - if (atPos >= (email.size() - 1) || email.find('.', atPos) == std::string::npos) { - errorMessage = NetworkErrors::errorMessage(NetworkErrors::ERROR_INVALID_EMAIL); - continue; - } - return true; - } - return false; - } -} - -bool PasswordRecoveryDialog::run(NetworkAuthenticationManager &mgr) { - std::string errorMessage; - std::string email; - while (true) { - if (!runDialog(email, errorMessage)) { - mgr.logOut(); - return false; - } - - PasswordRecoveryRunnable recovery(mgr, email); - recovery.executeWithUI(); - if (recovery.hasErrors()) { - errorMessage = recovery.errorMessage(); - mgr.logOut(); - continue; - } - - ZLResourceKey boxKey("recoverySuccessfulBox"); - const std::string message = - ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), email); - ZLDialogManager::Instance().informationBox(boxKey, message); - - return true; - } -} diff --git a/fbreader/src/networkActions/PasswordRecoveryDialog.h b/fbreader/src/networkActions/PasswordRecoveryDialog.h deleted file mode 100644 index b2d9c86..0000000 --- a/fbreader/src/networkActions/PasswordRecoveryDialog.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __PASSWORDRECOVERYDIALOG_H__ -#define __PASSWORDRECOVERYDIALOG_H__ - -#include <string> - -class ZLDialog; -class NetworkAuthenticationManager; - -class PasswordRecoveryDialog { - -private: - PasswordRecoveryDialog(std::string &email, const std::string &errorMessage); - - ZLDialog &dialog(); - - static bool runDialog(std::string &email, std::string &errorMessage); - -public: - static bool run(NetworkAuthenticationManager &mgr); - -private: - shared_ptr<ZLDialog> myDialog; -}; - -inline ZLDialog &PasswordRecoveryDialog::dialog() { return *myDialog; } - -#endif /* __PASSWORDRECOVERYDIALOG_H__ */ diff --git a/fbreader/src/networkActions/RegisterUserDialog.cpp b/fbreader/src/networkActions/RegisterUserDialog.cpp deleted file mode 100644 index 4d93d8c..0000000 --- a/fbreader/src/networkActions/RegisterUserDialog.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#include <ZLDialog.h> -#include <ZLDialogManager.h> -#include <ZLOptionsDialog.h> -#include <ZLOptionEntry.h> - -#include <ZLSimpleOptionEntry.h> -#include <ZLStringEditOptionEntry.h> - - -#include "RegisterUserDialog.h" -#include "NetworkOperationRunnable.h" - -#include "../network/authentication/NetworkAuthenticationManager.h" -#include "../network/NetworkErrors.h" - -#include "../fbreader/FBReader.h" - - -class HiddenValueEntry : public ZLPasswordOptionEntry { - -public: - HiddenValueEntry(std::string &value); - - const std::string &initialValue() const; - void onAccept(const std::string &value); - -private: - std::string &myValue; -}; - -HiddenValueEntry::HiddenValueEntry(std::string &value) : myValue(value) { -} - -const std::string &HiddenValueEntry::initialValue() const { - return myValue; -} - -void HiddenValueEntry::onAccept(const std::string &value) { - myValue = value; -} - - -RegisterUserDialog::RegisterUserDialog(const std::string &login, const std::string &password, const std::string &email, const std::string &errorMessage) { - myDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("RegisterUserDialog")); - - if (!errorMessage.empty()) { - myDialog->addOption("", "", new ZLSimpleStaticTextOptionEntry(errorMessage)); - } - - myLogin = login; - myPassword0 = myPassword1 = password; - myEMail = email; - - myDialog->addOption(ZLResourceKey("login"), new ZLStringEditOptionEntry(myLogin)); - myDialog->addOption(ZLResourceKey("password"), new HiddenValueEntry(myPassword0)); - myDialog->addOption(ZLResourceKey("confirmPassword"), new HiddenValueEntry(myPassword1)); - myDialog->addOption(ZLResourceKey("email"), new ZLStringEditOptionEntry(myEMail)); - - myDialog->addButton(ZLDialogManager::OK_BUTTON, true); - myDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); -} - -bool RegisterUserDialog::runDialog(std::string &login, std::string &password, std::string &email, std::string &errorMessage) { - const ZLResource &resource = ZLResource::resource("dialog")["RegisterUserDialog"]; - while (true) { - RegisterUserDialog dlg(login, password, email, errorMessage); - if (dlg.dialog().run()) { - dlg.dialog().acceptValues(); - login = dlg.myLogin; - password = dlg.myPassword0; - email = dlg.myEMail; - if (login.empty()) { - errorMessage = NetworkErrors::errorMessage(NetworkErrors::ERROR_LOGIN_WAS_NOT_SPECIFIED); - continue; - } - if (dlg.myPassword0 != dlg.myPassword1) { - errorMessage = resource["differentPasswords"].value(); - password.clear(); - continue; - } - if (email.empty()) { - errorMessage = NetworkErrors::errorMessage(NetworkErrors::ERROR_EMAIL_WAS_NOT_SPECIFIED); - continue; - } - std::size_t atPos = email.find('@'); - if (atPos >= (email.size() - 1) || email.find('.', atPos) == std::string::npos) { - errorMessage = NetworkErrors::errorMessage(NetworkErrors::ERROR_INVALID_EMAIL); - continue; - } - return true; - } - return false; - } -} - -bool RegisterUserDialog::run(NetworkAuthenticationManager &mgr) { - std::string errorMessage; - std::string login; - std::string password; - std::string email; - while (true) { - if (!runDialog(login, password, email, errorMessage)) { - mgr.logOut(); - return false; - } - - RegisterUserRunnable registration(mgr, login, password, email); - registration.executeWithUI(); - if (registration.hasErrors()) { - errorMessage = registration.errorMessage(); - mgr.logOut(); - continue; - } - -// if (mgr.isAuthorised().Status != B3_FALSE && mgr.needsInitialization()) { -// InitializeAuthenticationManagerRunnable initializer(mgr); -// initializer.executeWithUI(); -// if (initializer.hasErrors()) { -// initializer.showErrorMessage(); -// LogOutRunnable logout(mgr); -// logout.executeWithUI(); -// return false; -// } -// } - return true; - } -} diff --git a/fbreader/src/networkActions/RegisterUserDialog.h b/fbreader/src/networkActions/RegisterUserDialog.h deleted file mode 100644 index 6dcb3d1..0000000 --- a/fbreader/src/networkActions/RegisterUserDialog.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2004-2012 Geometer Plus <contact@geometerplus.com> - * - * This program 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 - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef __REGISTERUSERDIALOG_H__ -#define __REGISTERUSERDIALOG_H__ - -#include <string> - -class ZLDialog; -class NetworkAuthenticationManager; - -class RegisterUserDialog { - -private: - RegisterUserDialog(const std::string &login, const std::string &password, const std::string &email, const std::string &errorMessage); - - ZLDialog &dialog(); - - static bool runDialog(std::string &login, std::string &password, std::string &email, std::string &errorMessage); - -public: - static bool run(NetworkAuthenticationManager &mgr); - -private: - shared_ptr<ZLDialog> myDialog; - std::string myLogin; - std::string myPassword0; - std::string myPassword1; - std::string myEMail; -}; - -inline ZLDialog &RegisterUserDialog::dialog() { return *myDialog; } - -#endif /* __REGISTERUSERDIALOG_H__ */ |
