Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void RecentBooksDlg::ShowPage(int updown, int selectRow)
{
    Device::forceFullScreenUpdate();

    if(updown>0) {
        if(curPage+1>pageCount) curPage=0;
        curPage+=1;
    } else {
        if(curPage-1<=0) curPage=pageCount+1;
        curPage-=1;
    }
    setWindowTitle(titleMask + " (" + QString::number(curPage) + "/" + QString::number(pageCount) + ")");

    int rc = m_docview->rowCount;
    int firstItem = m_docview->getDocView()->isDocumentOpened() ? 1 : 0;
    int startPos = ((curPage-1)*rc)+firstItem;
    LVPtrVector<CRFileHistRecord> & files = m_docview->getDocView()->getHistory()->getRecords();
    for(int k=startPos, index=0; index<rc*2; ++k, index+=2) {
        if(k<files.length()) {
            CRFileHistRecord * book = files.get(k);

            lString16 title = book->getTitle();
            lString16 author = book->getAuthor();
            lString16 series = book->getSeries();
            lString16 filename = book->getFileName();
            if(title.empty()) title = filename;
            QString fileExt = cr2qt(filename);
            fileExt = fileExt.mid(fileExt.lastIndexOf(".")+1);

            int fileSize = book->getFileSize();
            CRBookmark *bm = book->getLastPos();
            int percent = bm->getPercent();

            if(author.empty()) author = L"-";
            if(title.empty()) title = L"-";
            if(!series.empty()) series = L"(" + series + L")";

            QTableWidgetItem *item = m_ui->tableWidget->item(index, 0);
            item->setText(cr2qt(title));

            item = m_ui->tableWidget->item(index+1, 0);
            item->setText(cr2qt(author)+"\n"+cr2qt(series));

            item = m_ui->tableWidget->item(index+1, 1);
            item->setText(crpercent(percent) + "\n" + fileExt+" / "+crFileSize(fileSize));

            m_ui->tableWidget->showRow(index);
            m_ui->tableWidget->showRow(index+1);
        } else {
            m_ui->tableWidget->hideRow(index);
            m_ui->tableWidget->hideRow(index+1);
        }
    }
    // select first row
    if(m_ui->tableWidget->rowCount()>0)
        m_ui->tableWidget->selectRow(selectRow);
}
Ejemplo n.º 3
0
int CRFileHist::findEntry( const lString16 & fname, const lString16 & fpath, lvsize_t sz )
{
    CR_UNUSED(fpath);
    for ( int i=0; i<_records.length(); i++ ) {
        CRFileHistRecord * rec = _records[i];
        if ( rec->getFileName().compare(fname) )
            continue;
        if ( rec->getFileSize()!=sz ) {
            CRLog::warn("CRFileHist::findEntry() Filename matched %s but sizes are different %d!=%d", LCSTR(fname), sz, rec->getFileSize() );
            continue;
        }
        return i;
    }
    return -1;
}