summaryrefslogtreecommitdiffstats
path: root/reader/src/libraryActions
diff options
context:
space:
mode:
Diffstat (limited to 'reader/src/libraryActions')
-rw-r--r--reader/src/libraryActions/AuthorInfoDialog.cpp164
-rw-r--r--reader/src/libraryActions/AuthorInfoDialog.h64
-rw-r--r--reader/src/libraryActions/BooksUtil.cpp88
-rw-r--r--reader/src/libraryActions/BooksUtil.h39
-rw-r--r--reader/src/libraryActions/LibraryAuthorActions.cpp41
-rw-r--r--reader/src/libraryActions/LibraryAuthorActions.h41
-rw-r--r--reader/src/libraryActions/LibraryBookActions.cpp132
-rw-r--r--reader/src/libraryActions/LibraryBookActions.h67
-rw-r--r--reader/src/libraryActions/LibraryTagActions.cpp159
-rw-r--r--reader/src/libraryActions/LibraryTagActions.h80
10 files changed, 875 insertions, 0 deletions
diff --git a/reader/src/libraryActions/AuthorInfoDialog.cpp b/reader/src/libraryActions/AuthorInfoDialog.cpp
new file mode 100644
index 0000000..fdc2252
--- /dev/null
+++ b/reader/src/libraryActions/AuthorInfoDialog.cpp
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/AuthorInfoDialog.h b/reader/src/libraryActions/AuthorInfoDialog.h
new file mode 100644
index 0000000..e4194aa
--- /dev/null
+++ b/reader/src/libraryActions/AuthorInfoDialog.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2004-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/BooksUtil.cpp b/reader/src/libraryActions/BooksUtil.cpp
new file mode 100644
index 0000000..93f9f06
--- /dev/null
+++ b/reader/src/libraryActions/BooksUtil.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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 "../reader/Reader.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
+ Reader::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/reader/src/libraryActions/BooksUtil.h b/reader/src/libraryActions/BooksUtil.h
new file mode 100644
index 0000000..b12c8e8
--- /dev/null
+++ b/reader/src/libraryActions/BooksUtil.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/LibraryAuthorActions.cpp b/reader/src/libraryActions/LibraryAuthorActions.cpp
new file mode 100644
index 0000000..5f4363d
--- /dev/null
+++ b/reader/src/libraryActions/LibraryAuthorActions.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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 "../reader/Reader.h"
+
+AuthorEditInfoAction::AuthorEditInfoAction(shared_ptr<Author> author) : myAuthor(author) {
+}
+
+AuthorEditInfoAction::~AuthorEditInfoAction() {
+}
+
+void AuthorEditInfoAction::run() {
+ if (AuthorInfoDialog::run(myAuthor)) {
+ // TODO: select current node (?) again
+ Reader::Instance().refreshWindow();
+ }
+}
+
+ZLResourceKey AuthorEditInfoAction::key() const {
+ return ZLResourceKey("edit");
+}
diff --git a/reader/src/libraryActions/LibraryAuthorActions.h b/reader/src/libraryActions/LibraryAuthorActions.h
new file mode 100644
index 0000000..2fddb7a
--- /dev/null
+++ b/reader/src/libraryActions/LibraryAuthorActions.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/LibraryBookActions.cpp b/reader/src/libraryActions/LibraryBookActions.cpp
new file mode 100644
index 0000000..0c490c4
--- /dev/null
+++ b/reader/src/libraryActions/LibraryBookActions.cpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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 "../reader/Reader.h"
+#include "../optionsDialog/bookInfo/BookInfoDialog.h"
+
+BookReadAction::BookReadAction(shared_ptr<Book> book) : myBook(book) {
+}
+
+void BookReadAction::run() {
+ Reader &reader = Reader::Instance();
+ reader.openBook(myBook);
+ reader.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);
+ Reader::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
+ Reader::Instance().refreshWindow();
+ }
+}
+
+ZLResourceKey BookEditInfoAction::key() const {
+ return ZLResourceKey("edit");
+}
diff --git a/reader/src/libraryActions/LibraryBookActions.h b/reader/src/libraryActions/LibraryBookActions.h
new file mode 100644
index 0000000..873fbb7
--- /dev/null
+++ b/reader/src/libraryActions/LibraryBookActions.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/LibraryTagActions.cpp b/reader/src/libraryActions/LibraryTagActions.cpp
new file mode 100644
index 0000000..0fe945e
--- /dev/null
+++ b/reader/src/libraryActions/LibraryTagActions.cpp
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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/reader/src/libraryActions/LibraryTagActions.h b/reader/src/libraryActions/LibraryTagActions.h
new file mode 100644
index 0000000..de9d6a9
--- /dev/null
+++ b/reader/src/libraryActions/LibraryTagActions.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2009-2012 Geometer Plus <[email protected]>
+ *
+ * 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__ */