void MainWindow::on_actionOpen_triggered() { QString lastPath; LVPtrVector<CRFileHistRecord> & files = ui->view->getDocView()->getHistory()->getRecords(); if ( files.length()>0 ) { lastPath = cr2qt( files[0]->getFilePath() ); } QString fileName = QFileDialog::getOpenFileName(this, tr("Open book file"), lastPath, tr("All supported formats (*.fb2 *.txt *.tcr *.rtf *.doc *.epub *.html *.htm *.chm *.zip *.pdb *.pml *.prc *.pml *.mobi);;FB2 books (*.fb2 *.fb2.zip);;Text files (*.txt);;Rich text (*.rtf);;MS Word document (*.doc);;HTML files (*.htm *.html);;EPUB files (*.epub);;CHM files (*.chm);;MOBI files (*.mobi *.prc *.azw);;PalmDOC files (*.pdb *.pml);;ZIP archives (*.zip)")); if ( fileName.length()==0 ) return; if ( !ui->view->loadDocument( fileName ) ) { // error } else { #ifdef _DEBUG LVStreamRef in = ui->view->getDocView()->getCoverPageImageStream(); if ( !in.isNull() ) { LVStreamRef out = LVOpenFileStream("/tmp/cover.png", LVOM_WRITE); if ( !out.isNull() ) { LVPumpStream( out.get(), in.get() ); } } #endif update(); } }
bool CRFileHist::saveToStream( LVStream * targetStream ) { LVStreamRef streamref = LVCreateMemoryStream(NULL, 0, false, LVOM_WRITE); LVStream * stream = streamref.get(); const char * xml_hdr = "\xef\xbb\xbf<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<FictionBookMarks>\r\n"; const char * xml_ftr = "</FictionBookMarks>\r\n"; //const char * crlf = "\r\n"; *stream << xml_hdr; for ( int i=0; i<_records.length(); i++ ) { CRFileHistRecord * rec = _records[i]; putTag( stream, 1, "file" ); putTag( stream, 2, "file-info" ); putTagValue( stream, 3, "doc-title", rec->getTitle() ); putTagValue( stream, 3, "doc-author", rec->getAuthor() ); putTagValue( stream, 3, "doc-series", rec->getSeries() ); putTagValue( stream, 3, "doc-filename", rec->getFileName() ); putTagValue( stream, 3, "doc-filepath", rec->getFilePath() ); putTagValue( stream, 3, "doc-filesize", lString16::itoa( (unsigned int)rec->getFileSize() ) ); putTag( stream, 2, "/file-info" ); putTag( stream, 2, "bookmark-list" ); putBookmark( stream, rec->getLastPos() ); for ( int j=0; j<rec->getBookmarks().length(); j++) { CRBookmark * bmk = rec->getBookmarks()[j]; putBookmark( stream, bmk ); } putTag( stream, 2, "/bookmark-list" ); putTag( stream, 1, "/file" ); } *stream << xml_ftr; LVPumpStream( targetStream, stream ); return true; }
static void dumpZip( LVContainerRef arc ) { lString16 arcName = LVExtractFilenameWithoutExtension( arc->GetName() ); if ( arcName.empty() ) arcName = L"unziparc"; lString16 outDir = lString16("/tmp/") + arcName; LVCreateDirectory(outDir); for ( int i=0; i<arc->GetObjectCount(); i++ ) { const LVContainerItemInfo * info = arc->GetObjectInfo(i); if ( !info->IsContainer() ) { lString16 outFileName = outDir + L"/" + info->GetName(); LVCreateDirectory(LVExtractPath(outFileName)); LVStreamRef in = arc->OpenStream(info->GetName(), LVOM_READ); LVStreamRef out = LVOpenFileStream(outFileName.c_str(), LVOM_WRITE); if ( !in.isNull() && !out.isNull() ) { CRLog::trace("Writing %s", LCSTR(outFileName)); LVPumpStream(out.get(), in.get()); } } } }