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); }
void CRRecentBookMenuItem::Draw( LVDrawBuf & buf, lvRect & rc, CRRectSkinRef skin, CRRectSkinRef valueSkin, bool selected ) { if ( !_book ) { CRMenuItem::Draw( buf, rc, skin, valueSkin, selected ); return; } lvRect itemBorders = skin->getBorderWidths(); skin->draw( buf, rc ); buf.SetTextColor( 0x000000 ); buf.SetBackgroundColor( 0xFFFFFF ); int imgWidth = 0; int hh = rc.bottom - rc.top - itemBorders.top - itemBorders.bottom; if ( !_image.isNull() ) { int w = _image->GetWidth(); int h = _image->GetHeight(); buf.Draw( _image, rc.left + hh/2-w/2 + itemBorders.left, rc.top + hh/2 - h/2 + itemBorders.top, w, h ); imgWidth = w + 8; } lvRect textRect = rc; textRect.left += imgWidth; lString16 author = _book->getAuthor(); lString16 title = _book->getTitle(); lString16 series = _book->getSeries(); if ( title.empty() ) title = _book->getFileName(); else if ( !series.empty() ) title << " - " << series; lvRect posRect = textRect; if ( !author.empty() ) { posRect.bottom = posRect.top + skin->getFont()->getHeight() + itemBorders.top + itemBorders.bottom; textRect.top = posRect.bottom - itemBorders.bottom; skin->drawText( buf, posRect, author ); } if ( !title.empty() ) valueSkin->drawText( buf, textRect, title ); }
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("")); }
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(); }