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 OnyxMainWindow::bookmarkModel(QStandardItemModel & model,
                                   QModelIndex & selected)
{
    CRFileHistRecord * rec = view_->getDocView()->getCurrentFileHistRecord();
    if ( !rec )
        return;
    LVPtrVector<CRBookmark> & list( rec->getBookmarks() );
    model.setColumnCount(2);
    int row = 0;
    for(int i  = 0; i < list.length(); ++i)
    {
        // skip cites
        CRBookmark * bmk = list[i];
        if (!bmk || (bmk->getType() == bmkt_comment || bmk->getType() == bmkt_correction))
            continue;

        QString t =cr2qt(view_->getDocView()->getPageText(true, list[i]->getBookmarkPage()));
        t.truncate(100);
        QStandardItem *title = new QStandardItem(t);
        title->setData((int)list[i]);
        title->setEditable(false);
        model.setItem(row, 0, title);

        int pos = list[i]->getPercent();
        QString str(tr("%1"));
        str = str.arg(pos);
        QStandardItem *page = new QStandardItem(str);
        page->setTextAlignment(Qt::AlignCenter);
        page->setEditable(false);
        model.setItem(row, 1, page);

        row++;
    }
}
Ejemplo n.º 3
0
CRCitesMenu::CRCitesMenu(CRGUIWindowManager * wm, LVDocView * docview, int numItems, lvRect & rc)
    : CRFullScreenMenu( wm, MCMD_CITES_LIST, lString16(_("Citations")), numItems, rc )
    , _docview(docview)
{
    CRGUIAcceleratorTableRef acc = _wm->getAccTables().get("bookmarks");
    if ( acc.isNull() )
        acc = _wm->getAccTables().get("menu");
    setAccelerators( acc );
    setSkinName(lString16("#cites-list"), lString16("#bookmarks"));
    int mc = getSkin()->getMinItemCount();
    if ( _pageItems < mc )
        _pageItems = mc;
    CRFileHistRecord * rec = docview->getCurrentFileHistRecord();
    LVPtrVector < CRBookmark > &bookmarks = rec->getBookmarks();
    for ( int i=0; i < bookmarks.length(); i++ ) {
        CRBookmark * bmk = bookmarks[i];
        if (!bmk || ((bmk->getType() != bmkt_comment && bmk->getType() != bmkt_correction)))
            continue;
        ldomXPointer p = docview->getDocument()->createXPointer( bmk->getStartPos() );
        if ( p.isNull() )
            continue;
        int page = docview->getBookmarkPage( p );
        /// get bookmark position text
        if ( page<0 )
            continue;
        CRBookmarkMenuItem * item = new CRBookmarkMenuItem( this, i, bmk, page );
        addItem( item );
    }
#ifdef CR_POCKETBOOK
    citesDialog = this;
#endif
    if (_items.length() == 0)
        createDefaultItem();
}
Ejemplo n.º 4
0
BookmarkListDialog::BookmarkListDialog(QWidget *parent, CR3View * docView ) :
	QDialog(parent),
	m_ui(new Ui::BookmarkListDialog),
	_docview(docView)
{
	m_ui->setupUi(this);

	addAction(m_ui->actionRemoveBookmark);
	addAction(m_ui->actionRemoveAllBookmarks);
	QAction *actionSelect = m_ui->actionSelectBookmark;
	actionSelect->setShortcut(Qt::Key_Select);
	addAction(actionSelect);

	int i = 0;
	m_ui->tableWidget->horizontalHeader()->setResizeMode( i++, QHeaderView::ResizeToContents);
	m_ui->tableWidget->horizontalHeader()->setResizeMode( i++, QHeaderView::Stretch );
	m_ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
	m_ui->tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);

	CRFileHistRecord * rec = _docview->getDocView()->getCurrentFileHistRecord();
	if (!rec) return;
	LVPtrVector<CRBookmark> & list( rec->getBookmarks() );
	int curpercent = _docview->getDocView()->getPosPercent();
	int bestdiff = -1;
	int bestindex = -1;
	int y = 0;
	for ( int i=0; i<list.length(); i++ ) {
		CRBookmark * bm = list[i];
		if ( bm->getType() == bmkt_lastpos ) continue;
		int diff = bm->getPercent() - curpercent;
		if ( diff < 0 )
			diff = -diff;
		if ( bestindex==-1 || diff < bestdiff ) {
			bestindex = i;
			bestdiff = diff;
		}
		m_ui->tableWidget->setRowCount(y+1);
		{
			int i=0;
			_list.append( bm );
			m_ui->tableWidget->setItem( y, i++, new QTableWidgetItem(crpercent( bm->getPercent())));
			m_ui->tableWidget->setItem( y, i++, new QTableWidgetItem(limit(cr2qt(bm->getPosText()))));
			m_ui->tableWidget->verticalHeader()->setResizeMode(y, QHeaderView::ResizeToContents);
		}
		y++;
	}
	if (bestindex>=0) m_ui->tableWidget->selectRow(bestindex);

	m_ui->tableWidget->resizeColumnsToContents();
	m_ui->tableWidget->resizeRowsToContents();
}
Ejemplo n.º 5
0
 /// called on closing
 virtual void OnTagClose( const lChar16 * nsname, const lChar16 * tagname )
 {
     if ( lStr_cmp(nsname, "FictionBookMarks")==0 && state==in_fbm ) {
         state = in_xml;
     } else if ( lStr_cmp(tagname, "file")==0 && state==in_file ) {
         state = in_fbm;
         if ( _curr_file )
             _hist->getRecords().add( _curr_file );
         _curr_file = NULL;
     } else if ( lStr_cmp(tagname, "file-info")==0 && state==in_file_info ) {
         state = in_file;
     } else if ( lStr_cmp(tagname, "bookmark-list")==0 && state==in_bm_list ) {
         state = in_file;
     } else if ( lStr_cmp(tagname, "doc-title")==0 && state==in_title ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "doc-author")==0 && state==in_author ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "doc-series")==0 && state==in_series ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "doc-filename")==0 && state==in_filename ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "doc-filepath")==0 && state==in_filepath ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "doc-filesize")==0 && state==in_filesize ) {
         state = in_file_info;
     } else if ( lStr_cmp(tagname, "bookmark")==0 && state==in_bm ) {
         state = in_bm_list;
         if ( _curr_bookmark ) {
             if ( _curr_bookmark->getType() == bmkt_lastpos ) {
                 _curr_file->setLastPos(_curr_bookmark);
                 delete _curr_bookmark;
             } else {
                 _curr_file->getBookmarks().add(_curr_bookmark);
             }
             _curr_bookmark = NULL;
         }
     } else if ( lStr_cmp(tagname, "start-point")==0 && state==in_start_point ) {
         state = in_bm;
     } else if ( lStr_cmp(tagname, "end-point")==0 && state==in_end_point ) {
         state = in_bm;
     } else if ( lStr_cmp(tagname, "header-text")==0 && state==in_header_txt ) {
         state = in_bm;
     } else if ( lStr_cmp(tagname, "selection-text")==0 && state==in_selection_txt ) {
         state = in_bm;
     } else if ( lStr_cmp(tagname, "comment-text")==0 && state==in_comment_txt ) {
         state = in_bm;
     }
 }