std::list<std::pair<std::string, std::string> > ReadiumJSApi::getSpineList() { // CSingleLock lock(&g_cs, TRUE); std::list<std::pair<std::string, std::string> > ret; if (!pkg) return ret; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// size_t idx = 0; shared_ptr<SpineItem> pSpineItem = pkg->SpineItemAt(idx++); //listTOC->clear(); //listTOC->addItem(new QListWidgetItem()); while (pSpineItem != 0) { QJsonObject curItem; shared_ptr<ManifestItem> manifestItem = pSpineItem->ManifestItem(); //qDebug() << pSpineItem->Title().c_str(); //pSpineItem->Title(); // TOC title if (manifestItem) { //qDebug() << QString(manifestItem->BaseHref().c_str()); ret.push_back(std::make_pair(manifestItem->BaseHref().c_str(), manifestItem->BaseHref().c_str())); //listTOC->addItem(QString(manifestItem->BaseHref().c_str())); //curItem["href"] = QString(manifestItem->BaseHref().c_str()); //[dict setObject : _href forKey : @"href"]; } //else //curItem["href"] = QString(""); //curItem["idref"] = QString(pSpineItem->Idref().c_str()); //[dict setObject : _idref forKey : @"idref"]; pSpineItem = pkg->SpineItemAt(idx++); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// return ret; // TOC TOC TOC ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //shared_ptr<NavigationTable> toc = pkg->TableOfContents(); //const NavigationList& list = toc->Children(); ////qDebug() << toc->SourceHref().c_str(); //for (NavigationList::const_iterator v = list.begin(); v != list.end(); ++v) //{ // //qDebug() << (*v)->Title().c_str(); //} }
json::Object ReadiumJSApi::getPackageJSON(PackagePtr pckg) { json::Object obj; // Level 0 { obj["rootUrl"] = std::string("/"); //[dict setObject : @"/" forKey:@"rootUrl"]; obj["rendition_layout"] = std::string(""); //[dict setObject : _rendition_layout forKey : @"rendition_layout"]; obj["rendition_flow"] = std::string(""); //[dict setObject : _rendition_flow forKey : @"rendition_flow"]; json::Object spine; json::Array spineItems; size_t idx = 0; shared_ptr<SpineItem> pSpineItem = pckg->SpineItemAt(idx++); while (pSpineItem != 0) { json::Object curItem; shared_ptr<ManifestItem> manifestItem = pSpineItem->ManifestItem(); if (manifestItem) { curItem["href"] = std::string(manifestItem->BaseHref().c_str()); //[dict setObject : _href forKey : @"href"]; } else curItem["href"] = std::string(""); curItem["idref"] = std::string(pSpineItem->Idref().c_str()); //[dict setObject : _idref forKey : @"idref"]; curItem["media_type"] = std::string(pSpineItem->ManifestItem()->MediaType().c_str()); //[dict setObject : _idref forKey : @"idref"]; //pSpineItem->Spread() //enum class PageSpread //{ // Automatic, ///< No value specified by the author. // Left, ///< This is the left page of a spread. // Right, ///< This is the right page of a spread. // Center, ///< This is a double-width page, spread across both left & right. //}; curItem["page_spread"] = std::string(""); //[dict setObject : _page_spread forKey : @"page_spread"]; curItem["rendition_layout"] = std::string(""); //[dict setObject : _rendition_layout forKey : @"rendition_layout"]; curItem["rendition_spread"] = std::string(""); //[dict setObject : _rendition_spread forKey : @"rendition_spread"]; curItem["rendition_flow"] = std::string(""); //[dict setObject : _rendition_flow forKey : @"rendition_flow"]; curItem["media_overlay_id"] = std::string(""); //[dict setObject : _media_overlay_id forKey : @"media_overlay_id"]; spineItems.push_back(curItem); pSpineItem = pckg->SpineItemAt(idx++); } spine["items"] = spineItems; spine["direction"] = std::string("default"); //[dict setObject : _direction forKey : @"direction"]; obj["spine"] = spine; //[dict setObject : [_spine toDictionary] forKey : @"spine"]; json::Object media_overlay; { std::shared_ptr<MediaOverlaysSmilModel> smilModel = pckg->MediaOverlaysSmilModel(); std::vector<std::shared_ptr<SMILData>>::size_type n = smilModel->GetSmilCount(); json::Array smil_models; std::vector<std::shared_ptr<SMILData>>::size_type i = 0; for (i = 0; i < n; ++i) { std::shared_ptr<SMILData> curSmil = smilModel->GetSmil(i); json::Object smilModel; if (curSmil->XhtmlSpineItem()) smilModel["spineItemId"] = std::string(curSmil->XhtmlSpineItem()->Idref().c_str()); else smilModel["spineItemId"] = std::string(""); //smilModel["id"] std::ostringstream stringStream; stringStream << curSmil->DurationMilliseconds_Calculated() / 1000.; std::string copyOfStr = stringStream.str(); smilModel["duration"] = copyOfStr; if (curSmil->SmilManifestItem()) { smilModel["id"] = std::string(curSmil->SmilManifestItem()->Identifier().c_str()); smilModel["href"] = std::string(curSmil->SmilManifestItem()->Href().c_str()); } else { smilModel["id"] = std::string(""); smilModel["href"] = std::string("fake.smil"); } smilModel["smilVersion"] = std::string("3.0"); //[dict setObject : self.children forKey : @"children"]; shared_ptr<const ePub3::SMILData::Sequence> seqBody = curSmil->Body(); json::Array arrChildren = getJSON(seqBody); smilModel["children"] = arrChildren; smil_models.push_back(smilModel); } /* [dict setObject : smilDictionaries forKey : @"smil_models"]; { for (DNSmilModel *mo in _smilModels) { [smilDictionaries addObject : [mo toDictionary]]; } [ [dict setObject : self.id forKey : @"id"]; [dict setObject : self.spineItemId forKey : @"spineItemId"]; [dict setObject : self.href forKey : @"href"]; [dict setObject : self.smilVersion forKey : @"smilVersion"]; [dict setObject : self.duration forKey : @"duration"]; [dict setObject : self.children forKey : @"children"]; ] }*/ media_overlay["smil_models"] = smil_models; json::Array skippables; json::Array escapables; smilModel = pckg->MediaOverlaysSmilModel(); if (smilModel) { std::vector<string>::size_type nCount = smilModel->GetSkippablesCount(); for (std::vector<string>::size_type i = 0; i < nCount; ++i) { string sSkippable = smilModel->GetSkippable(i); skippables.push_back(sSkippable.c_str()); } nCount = smilModel->GetEscapablesCount(); for (std::vector<string>::size_type i = 0; i < nCount; ++i) { string sEsc = smilModel->GetEscapable(i); escapables.push_back(sEsc.c_str()); } } media_overlay["skippables"] = skippables;//[dict setObject : self.skippables forKey : @"skippables"]; media_overlay["escapables"] = escapables;//[dict setObject : self.escapables forKey : @"escapables"]; media_overlay["duration"] = std::string(pckg->MediaOverlays_DurationTotal().c_str()); //[dict setObject : self.duration forKey : @"duration"]; = 1403.5 media_overlay["narrator"] = std::string(pckg->MediaOverlays_Narrator().c_str());//[dict setObject : self.narrator forKey : @"narrator"]; media_overlay["activeClass"] = std::string(pckg->MediaOverlays_ActiveClass().c_str());//[dict setObject : self.activeClass forKey : @"activeClass"];, "activeClass" : "-epub-media-overlay-active", media_overlay["playbackActiveClass"] = std::string(pckg->MediaOverlays_PlaybackActiveClass().c_str());//[dict setObject : self.playbackActiveClass forKey : @"playbackActiveClass"]; } obj["media_overlay"] = media_overlay; //[dict setObject : [_mediaOverlay toDictionary] forKey : @"media_overlay"]; return obj; } return obj; }