Esempio 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;
}
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);
}
Esempio n. 3
0
wxString HistList::OnGetItemText(long item, long column) const
{
    if ( _records && item>=0 && item<_records->length() ) {
        CRFileHistRecord * rec = (*_records)[item];
        lString16 data;
        switch ( column ) {
        case 0:
            data = rec->getLastTimeString();
            break;
        case 1:
            {
                lString16 fname = rec->getFileName();
                lString16 author = rec->getAuthor();
                lString16 title = rec->getTitle();
                lString16 series = rec->getSeries();
                if ( !series.empty() ) {
                    if ( !title.empty() )
                        title << " ";
                    title << series;
                }
                if ( !author.empty() && !title.empty() )
                    author << ". ";
                data << author << title;
                if ( data.empty() )
                    data = fname;
            }
            break;
        case 2:
            {
                data = lString16::itoa(rec->getLastPos()->getPercent()/100) + "%";
            }
            break;
        }
        return wxString(data.c_str());
    } else
        return wxString(wxT(""));
}
Esempio n. 4
0
RecentBooksDlg::RecentBooksDlg(QWidget *parent, CR3View * docView )
    : Dialog(parent)
    , ui(new Ui::RecentBooksDlg)
    , docview(docView)
{
    ui->setupUi(this);

    QFont f(ui->tableWidget->font());
    f.setPointSize(docview->getOptions()->getIntDef("cr3.app.ui.recent.font.size", 12));
    ui->tableWidget->setFont(f);

    f = ui->lblPosition->font();
    f.setPointSize(f.pointSize()/2);
    ui->lblPosition->setFont(f);

    f = ui->lblTitle->font();
    f.setBold(true);
    ui->lblTitle->setFont(f);

    ui->tableWidget->setColumnCount(1);

    ui->tableWidget->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
    ui->tableWidget->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
    ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Custom);

    bool isVscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_VSCROLLBAR, 1) != 0;
    ui->tableWidget->setVerticalScrollBarPolicy(isVscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);
    bool isHscroll = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_HSCROLLBAR, 1) != 0;
    ui->tableWidget->setHorizontalScrollBarPolicy(isHscroll? Qt::ScrollBarAsNeeded : Qt::ScrollBarAlwaysOff);

    // fill rows
    QFont fontTitle = ui->tableWidget->font();
    fontTitle.setBold(true);

    QFont fontAuthor = ui->tableWidget->font();
    fontAuthor.setItalic(true);

    QFont fontInfo = ui->tableWidget->font();
    fontInfo.setItalic(true);
    fontInfo.setPointSize(fontInfo.pointSize()*2/3);

    QFontMetrics tfm(fontTitle);
    QFontMetrics afm(fontAuthor);

    int rowHeight = tfm.height() + afm.height();
    ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed);
    ui->tableWidget->verticalHeader()->setDefaultSectionSize(rowHeight);

    ui->tableWidget->setItemDelegate(new RecentBooksListDelegate(ui->tableWidget, fontTitle, fontAuthor));

    LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords();

    // remove non-existing entries
    for( int k=0; k<files.length(); )
    {
        QString fn(cr2qt(files.get(k)->getFilePathName()));
        if (!QFile::exists(fn))
            files.remove(k);
        else
            ++k;
    }

    ui->tableWidget->setRowCount( files.length() );

    // insert items
    for( int index=0; index<files.length(); ++index )
    {
        CRFileHistRecord* book = files.get(index);

        RecentTableWidgetItem* titleItem = new RecentTableWidgetItem();
        titleItem->title   = cr2qt(book->getTitle());
        if ( titleItem->title.isEmpty() )
            titleItem->title = cr2qt(book->getFileName());
        titleItem->info  = cr2qt(book->getAuthor());
        if ( titleItem->info.isEmpty() )
            titleItem->info = "-";
        titleItem->percent = " " + crpercent(book->getLastPos()->getPercent());

        ui->tableWidget->setItem(index, 0, titleItem);
    }

    ui->navBar->setControls(ui->tableWidget, ui->lblPosition,
                            QSize( docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_X_WEIGHT, 1),
                                   docview->getOptions()->getIntDef(PROP_APP_UI_SWIPES_Y_WEIGHT, 1) ) );

    ui->tableWidget->setEditFocus(true);
    ui->tableWidget->setCurrentCell(0,0);

    QObject::connect( ui->tableWidget, SIGNAL(itemActivated(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) );
    QObject::connect( ui->tableWidget, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(onClicked(QTableWidgetItem*)) );

    init();
}
Esempio n. 5
0
void V3DocViewWin::showAboutDialog()
{
	_docview->savePosition();
	CRFileHistRecord * hist = _docview->getCurrentFileHistRecord();
    lString16 title = L"Cool Reader ";
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION CR_ENGINE_VERSION
#endif
    title << Utf8ToUnicode(lString8(PACKAGE_VERSION));

    lString8 txt;
    //=========================================================
    txt << "<table><col width=\"30%\"/><col width=\"70%\"/>\n";
    CRPropRef props = _docview->getDocProps();

    lString8 statusInfo;
	addPropLine( statusInfo, _("Current page"), lString16::itoa(_docview->getCurPage()+1) );
	addPropLine( statusInfo, _("Total pages"), lString16::itoa(_docview->getPageCount()) );
    addPropLine( statusInfo, _("Battery state"), _docview->getBatteryState()==-1 ? lString16(_("charging...")) : lString16::itoa(_docview->getBatteryState()) + L"%" );
	addPropLine( statusInfo, _("Current Time"), _docview->getTimeString() );
	// TODO:
	if ( hist ) {
		CRBookmark * lastpos = hist->getLastPos();
		if ( lastpos ) {
			addPropLine( statusInfo, _("Current chapter"), lastpos->getTitleText() );
		}
	}
    addInfoSection( txt, statusInfo, _("Status") );

    lString8 fileInfo;
    addPropLine( fileInfo, _("Archive name"), props->getStringDef(DOC_PROP_ARC_NAME) );
    addPropLine( fileInfo, _("Archive path"), props->getStringDef(DOC_PROP_ARC_PATH) );
    addPropLine( fileInfo, _("Archive size"), props->getStringDef(DOC_PROP_ARC_SIZE) );
    addPropLine( fileInfo, _("File name"), props->getStringDef(DOC_PROP_FILE_NAME) );
    addPropLine( fileInfo, _("File path"), props->getStringDef(DOC_PROP_FILE_PATH) );
    addPropLine( fileInfo, _("File size"), props->getStringDef(DOC_PROP_FILE_SIZE) );
    addPropLine( fileInfo, _("File format"), props->getStringDef(DOC_PROP_FILE_FORMAT) );
    addInfoSection( txt, fileInfo, _("File info") );

    lString8 bookInfo;
    addPropLine( bookInfo, _("Title"), props->getStringDef(DOC_PROP_TITLE) );
    addPropLine( bookInfo, _("Author(s)"), props->getStringDef(DOC_PROP_AUTHORS) );
    addPropLine( bookInfo, _("Series name"), props->getStringDef(DOC_PROP_SERIES_NAME) );
    addPropLine( bookInfo, _("Series number"), props->getStringDef(DOC_PROP_SERIES_NUMBER) );
    addPropLine( bookInfo, _("Date"), getDocText( getDocView()->getDocument(), "/FictionBook/description/title-info/date", ", " ) );
    addPropLine( bookInfo, _("Genres"), getDocText( getDocView()->getDocument(), "/FictionBook/description/title-info/genre", ", " ) );
    addPropLine( bookInfo, _("Translator"), getDocText( getDocView()->getDocument(), "/FictionBook/description/title-info/translator", ", " ) );
    addInfoSection( txt, bookInfo, _("Book info") );

    lString8 docInfo;
    addPropLine( docInfo, _("Document author"), getDocAuthors( getDocView()->getDocument(), "/FictionBook/description/document-info/author", " " ) );
    addPropLine( docInfo, _("Document date"), getDocText( getDocView()->getDocument(), "/FictionBook/description/document-info/date", " " ) );
    addPropLine( docInfo, _("Document source URL"), getDocText( getDocView()->getDocument(), "/FictionBook/description/document-info/src-url", " " ) );
    addPropLine( docInfo, _("OCR by"), getDocText( getDocView()->getDocument(), "/FictionBook/description/document-info/src-ocr", " " ) );
    addPropLine( docInfo, _("Document version"), getDocText( getDocView()->getDocument(), "/FictionBook/description/document-info/version", " " ) );
    addPropLine( docInfo, _("Change history"), getDocText( getDocView()->getDocument(), "/FictionBook/description/document-info/history", " " ) );
    addInfoSection( txt, docInfo, _("Document info") );

    lString8 pubInfo;
    addPropLine( pubInfo, _("Publication name"), getDocText( getDocView()->getDocument(), "/FictionBook/description/publish-info/book-name", " " ) );
    addPropLine( pubInfo, _("Publisher"), getDocText( getDocView()->getDocument(), "/FictionBook/description/publish-info/publisher", " " ) );
    addPropLine( pubInfo, _("Publisher city"), getDocText( getDocView()->getDocument(), "/FictionBook/description/publish-info/city", " " ) );
    addPropLine( pubInfo, _("Publication year"), getDocText( getDocView()->getDocument(), "/FictionBook/description/publish-info/year", " " ) );
    addPropLine( pubInfo, _("ISBN"), getDocText( getDocView()->getDocument(), "/FictionBook/description/publish-info/isbn", " " ) );
    addInfoSection( txt, pubInfo, _("Publication info") );

    addPropLine( txt, _("Custom info"), getDocText( getDocView()->getDocument(), "/FictionBook/description/custom-info", " " ) );

    txt << "</table>\n";

    //CRLog::trace(txt.c_str());
    //=========================================================
    txt = CRViewDialog::makeFb2Xml(txt);
    CRViewDialog * dlg = new CRViewDialog( _wm, title, txt, lvRect(), true, true );
    dlg->getDocView()->setVisiblePageCount(1);
    //int fs = _props->getIntDef( PROP_FILE_PROPS_FONT_SIZE, 26 );
    //dlg->getDocView()->setFontSize(fs);
    _wm->activateWindow( dlg );
}