shared_ptr<Book> BooksDB::loadBook(const std::string &fileName) { AppLog(" BooksDB::loadBook(const std::string &fileName)"); if (!isInitialized()) { return 0; } myFindFileId->setFileName(fileName); if (!myFindFileId->run()) { return false; } ((DBIntValue&)*myLoadBook->parameter("@file_id").value()) = myFindFileId->fileId(); shared_ptr<DBDataReader> reader = myLoadBook->executeReader(); if (reader.isNull() || !reader->next() || reader->type(0) != DBValue::DBINT /* book_id */) { return 0; } const int bookId = reader->intValue(0); shared_ptr<Book> book = Book::createBook( ZLFile(fileName), bookId, reader->textValue(1, Book::AutoEncoding), reader->textValue(2, ZLLanguageUtil::OtherLanguageCode), reader->textValue(3, std::string()) ); loadSeries(*book); AppLog("loadSeries(*book);"); loadAuthors(*book); AppLog("loadSeries(*book);"); loadTags(*book); AppLog("loadSeries(*book);"); return book; }
bool BooksDB::loadBooks(BookList &books) { AppLog(" BooksDB::loadBooks(BookList &books)"); shared_ptr<DBDataReader> reader = myLoadBooks->executeReader(); books.clear(); std::map<int,shared_ptr<Book> > bookMap; while (reader->next()) { if (reader->type(0) != DBValue::DBINT || /* book_id */ reader->type(4) != DBValue::DBINT) { /* file_id */ return false; } const int bookId = reader->intValue(0); const int fileId = reader->intValue(4); const std::string fileName = getFileName(fileId); shared_ptr<Book> book = Book::createBook( ZLFile(fileName), bookId, reader->textValue(1, Book::AutoEncoding), reader->textValue(2, ZLLanguageUtil::OtherLanguageCode), reader->textValue(3, std::string()) ); books.push_back(book); bookMap[bookId] = book; } loadSeries(bookMap); AppLog("loadSeries(bookMap);"); loadAuthors(bookMap); AppLog("loadAuthors(bookMap);"); loadTags(bookMap); AppLog("loadTags(bookMap);"); return true; }
SeriesIndex::SeriesIndex(uint64_t indexID, IndexManager *parent) { id = indexID; manager = parent; if(!this->init()){ shutdown(); } allocateMemory(); if(!loadSeries()){ shutdown(); } }
void BSClient::replySeriesFinished() { qDebug() << "BSClient::replySeriesFinished()"; QByteArray byteArray = m_reply->readAll(); if(isCaptcha(byteArray)) { loadSeries(); return; } QJsonDocument document = QJsonDocument::fromJson(byteArray); if(!document.isArray()) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0001")); return; } QList<QPair<QString, QString> > series; QJsonArray array = document.array(); Q_FOREACH(const QJsonValue &value, array) { if(!value.isObject()) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0002")); return; } QJsonObject object = value.toObject(); if(!object.contains("id")) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0003")); return; } QJsonValue idValue = object.value("id"); if(!idValue.isString()) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0004")); return; } if(!object.contains("series")) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0005")); return; } QJsonValue seriesValue = object.value("series"); if(!seriesValue.isString()) { Q_EMIT error(tr("JSON-Parse-Fehler: 0x0006")); return; } series << qMakePair(idValue.toString(), seriesValue.toString()); } Q_EMIT loadSeriesFinished(series); }