bookitemlist.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef BOOKITEMLIST_H
  2. #define BOOKITEMLIST_H
  3. #include <QtDeclarative/QDeclarativeItem>
  4. #include <QDir>
  5. #include <QUrl>
  6. const int ITEM_BOOK_INDEX = Qt::UserRole+1;
  7. const static QString PRIVATE_BOOKDIR= QDir::homePath()+"/.comicbook";
  8. const static QString PRIVATE_BOOKDIR_EXTRACTED = PRIVATE_BOOKDIR+"/extracted";
  9. const static QString PRIVATE_BOOKDIR_THUMBS = PRIVATE_BOOKDIR+"/thumbs";
  10. const static QString ARCHIVE_DIRECTORY = QDir::homePath()+"/MyDocs/comicbooks";
  11. const static QSize SCALED_ICON_SIZE = QSize(256,256);
  12. class Book;
  13. class BookUnzipper;
  14. class BookUnrar;
  15. class BookItemList : public QDeclarativeItem
  16. {
  17. Q_OBJECT
  18. Q_DISABLE_COPY(BookItemList)
  19. Q_PROPERTY(QDeclarativeListProperty<Book> books READ books CONSTANT)
  20. Q_ENUMS(ErrorCodes)
  21. public:
  22. BookItemList(QDeclarativeItem *parent = 0);
  23. ~BookItemList();
  24. enum ErrorCodes{
  25. NoError,
  26. NotEnoughSpace,
  27. ZipBroken
  28. };
  29. enum CleanDirectories {
  30. Nothing,
  31. Thumbs,
  32. Extracted,
  33. CleanAll
  34. };
  35. QDeclarativeListProperty<Book> books();
  36. Q_INVOKABLE void openBook(int index);
  37. Q_INVOKABLE void refreshBooks();
  38. signals:
  39. void bookOpen(bool success, Book* book);
  40. void refreshBooksDone(bool foundBooks);
  41. void pluginReady();
  42. private slots:
  43. void onExtractingFinished(BookItemList::ErrorCodes code);
  44. void onFirstImageExtracted(BookItemList::ErrorCodes code, Book* book);
  45. void searchArchives();
  46. private:
  47. void cleanDirectories(CleanDirectories toClean);
  48. void createPrivateDirectories();
  49. static Book* atFunction(QDeclarativeListProperty<Book> *property, int index);
  50. static int countFunction(QDeclarativeListProperty<Book> *property);
  51. private:
  52. QList<Book*> m_books;
  53. BookUnzipper* m_unzipper;
  54. BookUnrar* m_unrar;
  55. int m_openedBookIndex;
  56. int m_bookCount;
  57. };
  58. QML_DECLARE_TYPE(BookItemList)
  59. Q_DECLARE_METATYPE(BookItemList::ErrorCodes)
  60. #endif // BOOKITEMLIST_H