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/libraryActions | |
| 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/libraryActions')
| -rw-r--r-- | fbreader/src/libraryActions/AuthorInfoDialog.cpp | 164 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/AuthorInfoDialog.h | 64 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/BooksUtil.cpp | 88 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/BooksUtil.h | 39 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryAuthorActions.cpp | 41 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryAuthorActions.h | 41 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryBookActions.cpp | 132 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryBookActions.h | 67 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryTagActions.cpp | 159 | ||||
| -rw-r--r-- | fbreader/src/libraryActions/LibraryTagActions.h | 80 |
10 files changed, 0 insertions, 875 deletions
diff --git a/fbreader/src/libraryActions/AuthorInfoDialog.cpp b/fbreader/src/libraryActions/AuthorInfoDialog.cpp deleted file mode 100644 index fdc2252..0000000 --- a/fbreader/src/libraryActions/AuthorInfoDialog.cpp +++ /dev/null @@ -1,164 +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 <algorithm> - -#include <ZLDialogManager.h> -#include <ZLDialog.h> -#include <ZLOptionEntry.h> - -#include "AuthorInfoDialog.h" - -#include "../library/Library.h" -#include "../library/Author.h" - -class AuthorNameEntry : public ZLComboOptionEntry { - -public: - AuthorNameEntry(AuthorInfoDialog &dialog, std::size_t index); - - const std::string &initialValue() const; - const std::vector<std::string> &values() const; - void onAccept(const std::string &value); - void onValueSelected(int index); - -public: - std::size_t Index; - -private: - AuthorInfoDialog &myInfoDialog; - mutable std::vector<std::string> myValues; - std::string myValue; -}; - -class AuthorSortKeyEntry : public ZLStringOptionEntry { -public: - AuthorSortKeyEntry(AuthorInfoDialog &dialog); - - const std::string &initialValue() const; - void onAccept(const std::string &value); - -private: - AuthorInfoDialog &myInfoDialog; -}; - -AuthorNameEntry::AuthorNameEntry(AuthorInfoDialog &dialog, std::size_t index) : ZLComboOptionEntry(true), Index(index), myInfoDialog(dialog) { -} - -const std::string &AuthorNameEntry::initialValue() const { - return myInfoDialog.initialAuthor()->name(); -} - -void AuthorNameEntry::onAccept(const std::string &value) { - myInfoDialog.name() = value; -} - -const std::vector<std::string> &AuthorNameEntry::values() const { - if (myValues.empty()) { - const AuthorList &authors = myInfoDialog.authors(); - for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { - myValues.push_back((*it)->name()); - } - } - return myValues; -} - -void AuthorNameEntry::onValueSelected(int index) { - Index = index; - myInfoDialog.sortKeyEntry().resetView(); -} - -AuthorSortKeyEntry::AuthorSortKeyEntry(AuthorInfoDialog &dialog) : myInfoDialog(dialog) { -} - -const std::string &AuthorSortKeyEntry::initialValue() const { - const AuthorList &authors = myInfoDialog.authors(); - std::size_t index = std::min(myInfoDialog.nameEntry().Index, authors.size() - 1); - return authors[index]->sortKey(); -} - -void AuthorSortKeyEntry::onAccept(const std::string &value) { - myInfoDialog.sortKey() = value; -} - - - -bool AuthorInfoDialog::run(shared_ptr<Author> author) { - AuthorInfoDialog dlg(author); - if (dlg.dialog().run()) { - dlg.dialog().acceptValues(); - shared_ptr<Author> newAuthor = Author::getAuthor(dlg.name(), dlg.sortKey()); - Library::Instance().replaceAuthor(author, newAuthor); - return true; - } - return false; -} - - -AuthorInfoDialog::AuthorInfoDialog(shared_ptr<Author> author) : myInitialAuthor(author) { - const AuthorList &authors = Library::Instance().authors(); - for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) { - if (!it->isNull()) { - myAuthors.push_back(*it); - } - } - AuthorList::iterator jt = std::lower_bound(myAuthors.begin(), myAuthors.end(), myInitialAuthor, AuthorComparator()); - if (jt == myAuthors.end() || *jt != myInitialAuthor) { - myAuthors.insert(jt, myInitialAuthor); - } - - myDialog = ZLDialogManager::Instance().createDialog(ZLResourceKey("AuthorInfoDialog")); - - myNameEntry = new AuthorNameEntry(*this, jt - myAuthors.begin()); - mySortKeyEntry = new AuthorSortKeyEntry(*this); - - myDialog->addOption(ZLResourceKey("name"), myNameEntry); - myDialog->addOption(ZLResourceKey("sortKey"), mySortKeyEntry); - - myDialog->addButton(ZLDialogManager::OK_BUTTON, true); - myDialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); -} - -ZLDialog &AuthorInfoDialog::dialog() { - return *myDialog; -} - -shared_ptr<Author> AuthorInfoDialog::initialAuthor() { - return myInitialAuthor; -} - -const AuthorList &AuthorInfoDialog::authors() const { - return myAuthors; -} - -std::string &AuthorInfoDialog::name() { - return myName; -} - -std::string &AuthorInfoDialog::sortKey() { - return mySortKey; -} - -AuthorNameEntry &AuthorInfoDialog::nameEntry() { - return *myNameEntry; -} - -AuthorSortKeyEntry &AuthorInfoDialog::sortKeyEntry() { - return *mySortKeyEntry; -} diff --git a/fbreader/src/libraryActions/AuthorInfoDialog.h b/fbreader/src/libraryActions/AuthorInfoDialog.h deleted file mode 100644 index e4194aa..0000000 --- a/fbreader/src/libraryActions/AuthorInfoDialog.h +++ /dev/null @@ -1,64 +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 __AUTHORINFODIALOG_H__ -#define __AUTHORINFODIALOG_H__ - -#include <string> - -#include "../library/Lists.h" - -class ZLDialog; -class AuthorNameEntry; -class AuthorSortKeyEntry; - -class AuthorInfoDialog { - -public: - static bool run(shared_ptr<Author> author); - -private: - AuthorInfoDialog(shared_ptr<Author> author); - - ZLDialog &dialog(); - -public: - shared_ptr<Author> initialAuthor(); - const AuthorList &authors() const; - - std::string &name(); - std::string &sortKey(); - - AuthorNameEntry &nameEntry(); - AuthorSortKeyEntry &sortKeyEntry(); - -private: - const shared_ptr<Author> myInitialAuthor; - AuthorList myAuthors; - - shared_ptr<ZLDialog> myDialog; - - AuthorNameEntry *myNameEntry; - AuthorSortKeyEntry *mySortKeyEntry; - - std::string myName; - std::string mySortKey; -}; - -#endif /* __AUTHORINFODIALOG_H__ */ diff --git a/fbreader/src/libraryActions/BooksUtil.cpp b/fbreader/src/libraryActions/BooksUtil.cpp deleted file mode 100644 index ee831bd..0000000 --- a/fbreader/src/libraryActions/BooksUtil.cpp +++ /dev/null @@ -1,88 +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 <ZLDialogManager.h> -#include <ZLStringUtil.h> - -#include "BooksUtil.h" - -#include "../library/Library.h" -#include "../library/Tag.h" -#include "../fbreader/FBReader.h" - -void BooksUtil::removeTag(shared_ptr<Tag> tag) { - ZLResourceKey boxKey("removeTagBox"); - const std::string message = - ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), tag->fullName()); - enum { REMOVE_TAG, REMOVE_SUBTREE, DONT_REMOVE } code = DONT_REMOVE; - - Library &library = Library::Instance(); - if (library.hasSubtags(tag)) { - if (library.hasBooks(tag)) { - switch (ZLDialogManager::Instance().questionBox(boxKey, message, - ZLResourceKey("thisOnly"), - ZLResourceKey("withSubtags"), - ZLDialogManager::CANCEL_BUTTON - )) { - case 0: - code = REMOVE_TAG; - break; - case 1: - code = REMOVE_SUBTREE; - break; - } - } else { - if (ZLDialogManager::Instance().questionBox(boxKey, message, - ZLResourceKey("withSubtags"), ZLDialogManager::CANCEL_BUTTON) == 0) { - code = REMOVE_SUBTREE; - } - } - } else { - if (ZLDialogManager::Instance().questionBox(boxKey, message, - ZLDialogManager::YES_BUTTON, ZLDialogManager::CANCEL_BUTTON) == 0) { - code = REMOVE_TAG; - } - } - if (code != DONT_REMOVE) { - library.removeTag(tag, code == REMOVE_SUBTREE); - // TODO: select current node (?) again - FBReader::Instance().refreshWindow(); - } -} - -void BooksUtil::collectTagsFromLibrary(TagList &tags) { - const TagList &lTags = Library::Instance().tags(); - TagSet tagSet; - - for (TagList::const_iterator it = lTags.begin(); it != lTags.end(); ++it) { - shared_ptr<Tag> tag = *it; - if (tag.isNull()) { - tagSet.insert(tag); - tags.push_back(tag); - } else { - TagList tagStack; - do { - tagStack.push_back(tag); - tag = tag->parent(); - } while (!tag.isNull() && tagSet.find(tag) == tagSet.end()); - tagSet.insert(tagStack.begin(), tagStack.end()); - tags.insert(tags.end(), tagStack.rbegin(), tagStack.rend()); - } - } -} diff --git a/fbreader/src/libraryActions/BooksUtil.h b/fbreader/src/libraryActions/BooksUtil.h deleted file mode 100644 index b12c8e8..0000000 --- a/fbreader/src/libraryActions/BooksUtil.h +++ /dev/null @@ -1,39 +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 __BOOKSUTIL_H__ -#define __BOOKSUTIL_H__ - -#include <shared_ptr.h> - -#include "../library/Lists.h" - -class Tag; - -class BooksUtil { - -public: - static void removeTag(shared_ptr<Tag> tag); - static void collectTagsFromLibrary(TagList &tags); - -private: - BooksUtil(); -}; - -#endif /* __BOOKSUTIL_H__ */ diff --git a/fbreader/src/libraryActions/LibraryAuthorActions.cpp b/fbreader/src/libraryActions/LibraryAuthorActions.cpp deleted file mode 100644 index d0c87b2..0000000 --- a/fbreader/src/libraryActions/LibraryAuthorActions.cpp +++ /dev/null @@ -1,41 +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 "LibraryAuthorActions.h" -#include "AuthorInfoDialog.h" - -#include "../library/Author.h" -#include "../fbreader/FBReader.h" - -AuthorEditInfoAction::AuthorEditInfoAction(shared_ptr<Author> author) : myAuthor(author) { -} - -AuthorEditInfoAction::~AuthorEditInfoAction() { -} - -void AuthorEditInfoAction::run() { - if (AuthorInfoDialog::run(myAuthor)) { - // TODO: select current node (?) again - FBReader::Instance().refreshWindow(); - } -} - -ZLResourceKey AuthorEditInfoAction::key() const { - return ZLResourceKey("edit"); -} diff --git a/fbreader/src/libraryActions/LibraryAuthorActions.h b/fbreader/src/libraryActions/LibraryAuthorActions.h deleted file mode 100644 index 2fddb7a..0000000 --- a/fbreader/src/libraryActions/LibraryAuthorActions.h +++ /dev/null @@ -1,41 +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 __LIBRARYAUTHORACTIONS_H__ -#define __LIBRARYAUTHORACTIONS_H__ - -#include <shared_ptr.h> - -#include <ZLRunnable.h> - -class Author; - -class AuthorEditInfoAction : public ZLRunnableWithKey { - -public: - AuthorEditInfoAction(shared_ptr<Author> author); - ~AuthorEditInfoAction(); - void run(); - ZLResourceKey key() const; - -private: - const shared_ptr<Author> myAuthor; -}; - -#endif /* __LIBRARYAUTHORACTIONS_H__ */ diff --git a/fbreader/src/libraryActions/LibraryBookActions.cpp b/fbreader/src/libraryActions/LibraryBookActions.cpp deleted file mode 100644 index 6e72411..0000000 --- a/fbreader/src/libraryActions/LibraryBookActions.cpp +++ /dev/null @@ -1,132 +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 <ZLDialogManager.h> -#include <ZLOptionsDialog.h> -#include <ZLFile.h> -#include <ZLStringUtil.h> - -#include "LibraryBookActions.h" -#include "../library/Book.h" -#include "../fbreader/FBReader.h" -#include "../optionsDialog/bookInfo/BookInfoDialog.h" - -BookReadAction::BookReadAction(shared_ptr<Book> book) : myBook(book) { -} - -void BookReadAction::run() { - FBReader &fbreader = FBReader::Instance(); - fbreader.openBook(myBook); - fbreader.showBookTextView(); -} - -ZLResourceKey BookReadAction::key() const { - return ZLResourceKey("read"); -} - -BookRemoveAction::BookRemoveAction(shared_ptr<Book> book) : myBook(book) { -} - -void BookRemoveAction::run() { - switch (removeBookDialog()) { - case Library::REMOVE_FROM_DISK: - { - const std::string path = myBook->file().physicalFilePath(); - ZLFile physicalFile(path); - if (!physicalFile.remove()) { - ZLResourceKey boxKey("removeFileErrorBox"); - const std::string message = - ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), path); - ZLDialogManager::Instance().errorBox(boxKey, message); - } - } - // yes, we go through this label - case Library::REMOVE_FROM_LIBRARY: - Library::Instance().removeBook(myBook); - FBReader::Instance().refreshWindow(); - case Library::REMOVE_DONT_REMOVE: - break; - } -} - -ZLResourceKey BookRemoveAction::key() const { - return ZLResourceKey("delete"); -} - -bool BookRemoveAction::makesSense() const { - return Library::Instance().canRemove(myBook) != Library::REMOVE_DONT_REMOVE; -} - -int BookRemoveAction::removeBookDialog() const { - ZLResourceKey boxKey("removeBookBox"); - const ZLResource &msgResource = ZLResource::resource("dialog")[boxKey]; - - switch (Library::Instance().canRemove(myBook)) { - case Library::REMOVE_DONT_REMOVE: - return Library::REMOVE_DONT_REMOVE; - case Library::REMOVE_FROM_DISK: - { - ZLFile physFile(myBook->file().physicalFilePath()); - const std::string message = ZLStringUtil::printf(msgResource["deleteFile"].value(), physFile.name(false)); - if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) == 0) { - return Library::REMOVE_FROM_DISK; - } - return Library::REMOVE_DONT_REMOVE; - } - case Library::REMOVE_FROM_LIBRARY: - { - 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 Library::REMOVE_FROM_LIBRARY; - } - return Library::REMOVE_DONT_REMOVE; - } - case Library::REMOVE_FROM_LIBRARY_AND_DISK: - { - ZLResourceKey removeFileKey("removeFile"); - ZLResourceKey removeLinkKey("removeLink"); - - const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook->title()); - switch(ZLDialogManager::Instance().questionBox(boxKey, message, removeLinkKey, removeFileKey, ZLDialogManager::CANCEL_BUTTON)) { - case 0: - return Library::REMOVE_FROM_LIBRARY; - case 1: - return Library::REMOVE_FROM_DISK; - case 2: - return Library::REMOVE_DONT_REMOVE; - } - } - } - return Library::REMOVE_DONT_REMOVE; -} - -BookEditInfoAction::BookEditInfoAction(shared_ptr<Book> book) : myBook(book) { -} - -void BookEditInfoAction::run() { - if (BookInfoDialog(myBook).dialog().run()) { - // TODO: select current node (?) again - FBReader::Instance().refreshWindow(); - } -} - -ZLResourceKey BookEditInfoAction::key() const { - return ZLResourceKey("edit"); -} diff --git a/fbreader/src/libraryActions/LibraryBookActions.h b/fbreader/src/libraryActions/LibraryBookActions.h deleted file mode 100644 index 873fbb7..0000000 --- a/fbreader/src/libraryActions/LibraryBookActions.h +++ /dev/null @@ -1,67 +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 __LIBRARYBOOKACTIONS_H__ -#define __LIBRARYBOOKACTIONS_H__ - -#include <shared_ptr.h> - -#include <ZLRunnable.h> - -class Book; - -class BookReadAction : public ZLRunnableWithKey { - -public: - BookReadAction(shared_ptr<Book> book); - void run(); - ZLResourceKey key() const; - -private: - const shared_ptr<Book> myBook; -}; - -class BookEditInfoAction : public ZLRunnableWithKey { - -public: - BookEditInfoAction(shared_ptr<Book> book); - void run(); - ZLResourceKey key() const; - -private: - const shared_ptr<Book> myBook; -}; - -class BookRemoveAction : public ZLRunnableWithKey { - -public: - BookRemoveAction(shared_ptr<Book> book); - -private: - void run(); - ZLResourceKey key() const; - bool makesSense() const; - - int removeBookDialog() const; - -private: - const shared_ptr<Book> myBook; -}; - -#endif /* __LIBRARYBOOKACTIONS_H__ */ diff --git a/fbreader/src/libraryActions/LibraryTagActions.cpp b/fbreader/src/libraryActions/LibraryTagActions.cpp deleted file mode 100644 index 0fe945e..0000000 --- a/fbreader/src/libraryActions/LibraryTagActions.cpp +++ /dev/null @@ -1,159 +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 <ZLDialogManager.h> -#include <ZLDialog.h> -#include <ZLOptionEntry.h> - -#include "LibraryTagActions.h" - -#include "BooksUtil.h" - -#include "../library/Library.h" -#include "../library/Tag.h" -#include "../library/Lists.h" - -class TagNameEntry : public ZLComboOptionEntry { - -public: - TagNameEntry(const std::vector<std::string> &values, const std::string &initialValue); - - const std::string &initialValue() const; - const std::vector<std::string> &values() const; - void onAccept(const std::string &value); - -private: - const std::vector<std::string> &myValues; - std::string myValue; -}; - -class TagIncludeSubtagsEntry : public ZLBooleanOptionEntry { - -public: - TagIncludeSubtagsEntry(); - - bool initialState() const; - void onAccept(bool state); - -private: - bool myValue; -}; - -TagEditOrCloneAction::TagEditOrCloneAction(shared_ptr<Tag> tag) : myTag(tag) { -} - -void TagEditOrCloneAction::run() { - shared_ptr<ZLDialog> dialog = ZLDialogManager::Instance().createDialog(ZLResourceKey(resourceKeyName())); - - TagList tags; - BooksUtil::collectTagsFromLibrary(tags); - std::vector<std::string> names; - for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) { - if (!it->isNull()) { - names.push_back((*it)->fullName()); - } - } - TagNameEntry *tagNameEntry = new TagNameEntry(names, myTag->fullName()); - dialog->addOption(ZLResourceKey("name"), tagNameEntry); - - TagIncludeSubtagsEntry *includeSubtagsEntry = new TagIncludeSubtagsEntry(); - const Library &library = Library::Instance(); - if (library.hasSubtags(myTag)) { - if (!library.hasBooks(myTag)) { - includeSubtagsEntry->setActive(false); - } - dialog->addOption(ZLResourceKey("includeSubtags"), includeSubtagsEntry); - } - - dialog->addButton(ZLDialogManager::OK_BUTTON, true); - dialog->addButton(ZLDialogManager::CANCEL_BUTTON, false); - - if (dialog->run()) { - dialog->acceptValues(); - onAccept(tagNameEntry->initialValue(), includeSubtagsEntry->initialState()); - } -} - -TagEditAction::TagEditAction(shared_ptr<Tag> tag) : TagEditOrCloneAction(tag) { -} - -void TagEditAction::onAccept(const std::string &name, bool includeSubTags) { - Library::Instance().renameTag(myTag, Tag::getTagByFullName(name), includeSubTags); -} - -ZLResourceKey TagEditAction::key() const { - return ZLResourceKey("edit"); -} - -std::string TagEditAction::resourceKeyName() const { - return "editTagDialog"; -} - -TagCloneAction::TagCloneAction(shared_ptr<Tag> tag) : TagEditOrCloneAction(tag) { -} - -void TagCloneAction::onAccept(const std::string &name, bool includeSubTags) { - Library::Instance().cloneTag(myTag, Tag::getTagByFullName(name), includeSubTags); -} - -ZLResourceKey TagCloneAction::key() const { - return ZLResourceKey("clone"); -} - -std::string TagCloneAction::resourceKeyName() const { - return "cloneTagDialog"; -} - -TagRemoveAction::TagRemoveAction(shared_ptr<Tag> tag) : myTag(tag) { -} - -void TagRemoveAction::run() { - BooksUtil::removeTag(myTag); -} - -ZLResourceKey TagRemoveAction::key() const { - return ZLResourceKey("delete"); -} - -TagNameEntry::TagNameEntry(const std::vector<std::string> &values, const std::string &initialValue) : ZLComboOptionEntry(true), myValues(values), myValue(initialValue) { -} - -const std::string &TagNameEntry::initialValue() const { - return myValue; -} - -const std::vector<std::string> &TagNameEntry::values() const { - return myValues; -} - -void TagNameEntry::onAccept(const std::string &value) { - myValue = value; -} - -TagIncludeSubtagsEntry::TagIncludeSubtagsEntry() : myValue(true) { -} - -bool TagIncludeSubtagsEntry::initialState() const { - return myValue; -} - -void TagIncludeSubtagsEntry::onAccept(bool state) { - myValue = state; -} diff --git a/fbreader/src/libraryActions/LibraryTagActions.h b/fbreader/src/libraryActions/LibraryTagActions.h deleted file mode 100644 index de9d6a9..0000000 --- a/fbreader/src/libraryActions/LibraryTagActions.h +++ /dev/null @@ -1,80 +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 __LIBRARYTAGACTIONS_H__ -#define __LIBRARYTAGACTIONS_H__ - -#include <shared_ptr.h> - -#include <ZLRunnable.h> - -class Tag; - -class TagEditOrCloneAction : public ZLRunnableWithKey { - -public: - TagEditOrCloneAction(shared_ptr<Tag> tag); - -private: - void run(); - -protected: - virtual void onAccept(const std::string &name, bool includeSubTags) = 0; - virtual std::string resourceKeyName() const = 0; - -protected: - const shared_ptr<Tag> myTag; -}; - -class TagEditAction : public TagEditOrCloneAction { - -public: - TagEditAction(shared_ptr<Tag> tag); - -private: - ZLResourceKey key() const; - void onAccept(const std::string &name, bool includeSubTags); - std::string resourceKeyName() const; -}; - -class TagCloneAction : public TagEditOrCloneAction { - -public: - TagCloneAction(shared_ptr<Tag> tag); - -private: - ZLResourceKey key() const; - void onAccept(const std::string &name, bool includeSubTags); - std::string resourceKeyName() const; -}; - -class TagRemoveAction : public ZLRunnableWithKey { - -public: - TagRemoveAction(shared_ptr<Tag> tag); - -private: - void run(); - ZLResourceKey key() const; - -private: - const shared_ptr<Tag> myTag; -}; - -#endif /* __LIBRARYTAGACTIONS_H__ */ |
