AddBookmarkDialog::AddBookmarkDialog(QWidget *parent, CR3View * docView, CRBookmark * bm ) : QDialog(parent), m_ui(new Ui::AddBookmarkDialog), _docview( docView ), _bm(bm), _edit(bm!=NULL) { initialized = false; m_ui->setupUi(this); setWindowTitle( tr("Add bookmark") ); if ( _bm==NULL ) _bm = docView->createBookmark(); if ( _bm ) { if ( _bm->getType() == bmkt_pos ) { m_ui->cbType->addItem( tr("Position") ); } else { m_ui->cbType->addItem( tr("Comment") ); m_ui->cbType->addItem( tr("Correction") ); m_ui->cbType->setCurrentIndex(0); } m_ui->edPositionText->setPlainText( cr2qt(_bm->getPosText()) ); m_ui->edPositionText->setReadOnly( true ); m_ui->edComment->setPlainText( cr2qt(_bm->getCommentText()) ); m_ui->edComment->setReadOnly( false ); m_ui->lblPosition->setText( crpercent(_bm->getPercent()) ); m_ui->lblTitle->setText( cr2qt(_bm->getTitleText()) ); } _docview->restoreWindowPos( this, "bookmarkedit." ); initialized = 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); }
TocItem(LVTocItem * item, int currPage, int & nearestPage, TocItem * & nearestItem) : QTreeWidgetItem(QStringList() << (item ? cr2qt(item->getName()) : "No TOC items") << (item ? cr2qt(lString16::itoa(item->getPage()+1)) : "")) , _item(item) { setTextAlignment(1, Qt::AlignRight|Qt::AlignVCenter); int page = item->getPage(); if (!nearestItem || (page <= currPage && page > nearestPage)) { nearestItem = this; nearestPage = page; } setData(0, Qt::UserRole, QVariant(cr2qt(item->getXPointer().toString()))); for (int i = 0; i < item->getChildCount(); i++) { addChild(new TocItem(item->getChild(i), currPage, nearestPage, nearestItem)); } }
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(); } }
void cr2qt( QStringList & dst, const lString16Collection & src ) { dst.clear(); for ( unsigned i=0; i<src.length(); i++ ) { dst.append( cr2qt( src[i] ) ); } }
virtual bool getString( const char * prop, QString & result ) { lString16 value; if ( !_ref->getString(prop, value) ) return false; result = cr2qt( value ); return true; }
void RecentBooksDlg::openBook(int row) { int firstItem = m_docview->getDocView()->isDocumentOpened() ? 1 : 0; row+=firstItem; LVPtrVector<CRFileHistRecord> & files = m_docview->getDocView()->getHistory()->getRecords(); if(row>files.length()) return; // go to file m_docview->loadDocument(cr2qt(files[row-1]->getFilePathName())); close(); }
void RecentBooksDlg::accept() { int bn = getBookNum(); if ( bn >= 0 ) { LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords(); fileName = cr2qt(files[bn]->getFilePathName()); QDialog::accept(); } }
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(); }
void AddBookmarkDialog::on_cbType_currentIndexChanged(int index) { if ( !initialized ) return; if ( index == 0 ) { _bm->setType( bmkt_comment ); m_ui->edComment->setPlainText( QString() ); m_ui->lblComment->setText( tr("Comment") ); } else { _bm->setType( bmkt_correction ); m_ui->edComment->setPlainText( cr2qt(_bm->getPosText()) ); m_ui->lblComment->setText( tr("Correction") ); } }
void RecentBooksDlg::on_btnRemove_clicked() { int bn = getBookNum(); if ( bn >= 0 ) { LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords(); int result = 0; int value = docview->getOptions()->getIntDef(PROP_APP_UI_RECENT_REMOVE_FILES, 0); if ( value ) { RecentRemoveDlg dlg(this); dlg.exec(false); result = dlg.getResult(); } else { result = 1; } switch( result ) { case 0: default: break; case 1: if ( bn > 0 || !docview->getDocView()->isDocumentOpened() ) { files.remove(bn); ui->tableWidget->removeRow(bn); } break; case 2: if ( 0 == bn && docview->getDocView()->isDocumentOpened() ) { docview->getDocView()->createDefaultDocument( qt2cr(tr("Removed")), qt2cr(tr("Document was removed") ) ); } { QString fileName(cr2qt(files[bn]->getFilePathName())); files.remove(bn); ui->tableWidget->removeRow(bn); QFile::remove(fileName); docview->update(); } break; } } }
void RecentBooksDlg::on_btnFolder_clicked() { int bn = getBookNum(); if ( bn >= 0 ) { LVPtrVector<CRFileHistRecord>& files = docview->getDocView()->getHistory()->getRecords(); QString path(cr2qt(files[bn]->getFilePath())); OpenFileDlg dlg( this, docview, path ); if ( dlg.exec() && !dlg.fileName.isEmpty() ) { fileName = dlg.fileName; QDialog::accept(); } } }
void removeFile(LVPtrVector<CRFileHistRecord> & files, int num) { // remove cache file QString filename = cr2qt(files.get(num-1)->getFileName()); // trim file extension, need for archive files int pos = filename.lastIndexOf("."); if(pos != -1) filename.resize(pos); QDir Dir(qApp->applicationDirPath() + QDir::toNativeSeparators(QString("/data/cache/"))); QStringList fileList = Dir.entryList(QStringList() << filename + "*.cr3", QDir::Files); if(fileList.count()) Dir.remove(fileList.at(0)); files.remove(num-1); }
QString FilePropsDialog::getDocAuthors( const char * path, const char * delim ) { lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; lString16 firstName = qt2cr(getDocText( (p + "/first-name").c_str(), " " )); lString16 lastName = qt2cr(getDocText( (p + "/last-name").c_str(), " " )); lString16 middleName = qt2cr(getDocText( (p + "/middle-name").c_str(), " " )); lString16 nickName = qt2cr(getDocText( (p + "/nickname").c_str(), " " )); lString16 homePage = qt2cr(getDocText( (p + "/homepage").c_str(), " " )); lString16 email = qt2cr(getDocText( (p + "/email").c_str(), " " )); lString16 s = firstName; if ( !middleName.empty() ) s << L" " << middleName; if ( !lastName.empty() ) { if ( !s.empty() ) s << L" "; s << lastName; } if ( !nickName.empty() ) { if ( !s.empty() ) s << L" "; s << nickName; } if ( !homePage.empty() ) { if ( !s.empty() ) s << L" "; s << homePage; } if ( !email.empty() ) { if ( !s.empty() ) s << L" "; s << email; } if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return cr2qt(res); }
QString FilePropsDialog::getDocText( const char * path, const char * delim ) { ldomDocument * doc = _docview->getDocument(); lString16 res; for ( int i=0; i<100; i++ ) { lString8 p = lString8(path) + "[" + lString8::itoa(i+1) + "]"; lString16 p16 = Utf8ToUnicode(p); ldomXPointer ptr = doc->createXPointer( p16 ); if ( ptr.isNull() ) break; lString16 s = ptr.getText( L' ' ); if ( s.empty() ) continue; if ( !res.empty() && delim!=NULL ) res << Utf8ToUnicode( lString8( delim ) ); res << s; } return cr2qt(res); }
void RecentBooksDlg::removeFile(LVPtrVector<CRFileHistRecord> & files, int num) { QDir Dir0( cr2qt(files[num-1]->getFilePath()) ); // Удаляемый файл ещё существует if((Dir0.exists( cr2qt(files.get(num-1)->getFileName()) )) && (files.length() > 1)){ // Нужно чтобы в истории было больше одной книжки, чтобы можно было загрузить удяляемую запись а потом удалить m_docview->loadDocument(cr2qt(files[num-1]->getFilePathName())); // remove cache file QString filename = cr2qt(files.get(num-1)->getFileName()); filename = cr2qt(m_docview->getDocView()->getDocProps()->getStringDef(DOC_PROP_FILE_NAME)); // Уточняем CRC удаляемого файла lUInt32 crc = m_docview->getDocView()->getDocProps()->getIntDef(DOC_PROP_FILE_CRC32, 0); char s[16]; sprintf(s, ".%08x", (unsigned)crc); filename = filename+ QString(s); // Возвращаем активным первоначально просматриваемый документ (он сейчас первым в списке истории стоит) m_docview->loadDocument(cr2qt(files[1]->getFilePathName())); // // для отладки // trim file extension, need for archive files QDir Dir(qApp->applicationDirPath() + QDir::toNativeSeparators(QString("/data/cache/"))); QStringList fileList = Dir.entryList(QStringList() << filename + "*.cr3", QDir::Files); if(fileList.count()) Dir.remove(fileList.at(0)); files.remove(1); } else { // Известно лишь название архива и если его название не совпадает с названием файла то кеш файл не будет удалён // remove cache file QString filename = cr2qt(files.get(num-1)->getFileName()); // trim file extension, need for archive files int pos = filename.lastIndexOf("."); if(pos != -1) filename.resize(pos); QDir Dir(qApp->applicationDirPath() + QDir::toNativeSeparators(QString("/data/cache/"))); QStringList fileList = Dir.entryList(QStringList() << filename + "*.cr3", QDir::Files); if(fileList.count()) Dir.remove(fileList.at(0)); files.remove(num-1); } }
void MainWindow::on_actionDeleteCurrentDocument_triggered() { LVPtrVector<CRFileHistRecord>& files = ui->view->getDocView()->getHistory()->getRecords(); if ( !files.empty() && ui->view->getDocView()->isDocumentOpened() ) { QMessageBox::StandardButton result = ::questionBox( this, tr("Delete"), tr("Do you really want to delete the current document?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); if ( QMessageBox::Yes == result ) { ui->view->getDocView()->createDefaultDocument( qt2cr(tr("Removed")), qt2cr(tr("Document was removed") ) ); QString fileName(cr2qt(files[0]->getFilePathName())); files.remove(0); QFile::remove(fileName); update(); } } }
void crGetFontFaceList( QStringList & dst ) { lString16Collection faceList; fontMan->getFaceList( faceList ); cr2qt( dst, faceList ); }
void FilePropsDialog::fillItems() { _docview->savePosition(); CRPropRef props = _docview->getDocProps(); addPropLine(tr("Archive name"), cr2qt(props->getStringDef(DOC_PROP_ARC_NAME)) ); addPropLine(tr("Archive path"), cr2qt(props->getStringDef(DOC_PROP_ARC_PATH)) ); addPropLine(tr("Archive size"), cr2qt(props->getStringDef(DOC_PROP_ARC_SIZE)) ); addPropLine(tr("File name"), cr2qt(props->getStringDef(DOC_PROP_FILE_NAME)) ); addPropLine(tr("File path"), cr2qt(props->getStringDef(DOC_PROP_FILE_PATH)) ); addPropLine(tr("File size"), cr2qt(props->getStringDef(DOC_PROP_FILE_SIZE)) ); addPropLine(tr("File format"), cr2qt(props->getStringDef(DOC_PROP_FILE_FORMAT)) ); addInfoSection(tr("File info")); addPropLine(tr("Title"), cr2qt(props->getStringDef(DOC_PROP_TITLE)) ); addPropLine(tr("Author(s)"), cr2qt(props->getStringDef(DOC_PROP_AUTHORS)) ); addPropLine(tr("Series name"), cr2qt(props->getStringDef(DOC_PROP_SERIES_NAME)) ); addPropLine(tr("Series number"), cr2qt(props->getStringDef(DOC_PROP_SERIES_NUMBER)) ); addPropLine(tr("Date"), getDocText( "/FictionBook/description/title-info/date", ", " ) ); addPropLine(tr("Genres"), getDocText( "/FictionBook/description/title-info/genre", ", " ) ); addPropLine(tr("Translator"), getDocText( "/FictionBook/description/title-info/translator", ", " ) ); addInfoSection(tr("Book info") ); addPropLine(tr("Document author"), getDocAuthors( "/FictionBook/description/document-info/author", " " ) ); addPropLine(tr("Document date"), getDocText( "/FictionBook/description/document-info/date", " " ) ); addPropLine(tr("Document source URL"), getDocText( "/FictionBook/description/document-info/src-url", " " ) ); addPropLine(tr("OCR by"), getDocText( "/FictionBook/description/document-info/src-ocr", " " ) ); addPropLine(tr("Document version"), getDocText( "/FictionBook/description/document-info/version", " " ) ); addInfoSection( tr("Document info") ); addPropLine(tr("Publication name"), getDocText( "/FictionBook/description/publish-info/book-name", " " ) ); addPropLine(tr("Publisher"), getDocText( "/FictionBook/description/publish-info/publisher", " " ) ); addPropLine(tr("Publisher city"), getDocText( "/FictionBook/description/publish-info/city", " " ) ); addPropLine(tr("Publication year"), getDocText( "/FictionBook/description/publish-info/year", " " ) ); addPropLine(tr("ISBN"), getDocText( "/FictionBook/description/publish-info/isbn", " " ) ); addInfoSection(tr("Publication info")); addPropLine(tr("Custom info"), getDocText( "/FictionBook/description/custom-info", " " ) ); }
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(); }
int main(int argc, char *argv[]) { int res = 0; { Device::instance(); // initialize device #ifndef i386 QProcess::execute("eips -c"); pTouch = new TouchScreen(); #endif lString16 exedir = LVExtractPath(LocalToUnicode(lString8(argv[0]))); LVAppendPathDelimiter(exedir); lString16 datadir = exedir + "data/"; lString16 exefontpath = exedir + "fonts"; lString16Collection fontDirs; fontDirs.add(exefontpath); #ifndef i386 fontDirs.add("/usr/java/lib/fonts"); fontDirs.add("/mnt/us/fonts"); #endif CRPropRef props = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_READ); if(!cfg.isNull()) props->loadFromStream(cfg.get()); } lString16 lang = props->getStringDef(PROP_WINDOW_LANG, ""); InitCREngineLog(props); CRLog::info("main()"); if(!InitCREngine(argv[0], fontDirs)) { printf("Cannot init CREngine - exiting\n"); return 2; } #ifndef i386 PrintString(1, 1, "crengine version: " + QString(CR_ENGINE_VERSION)); PrintString(1, 2, QString("build date: %1 %2").arg(__DATE__).arg(__TIME__)); if (!Device::isTouch()) { QString message = "Please wait while application is loading..."; int xpos = ((Device::getWidth()/12-1)-message.length())/2; int ypos = (Device::getHeight()/20-2)/2; PrintString(xpos, ypos, message); } #endif // to catch crashes and remove current cache file on crash (SIGSEGV etc.) crSetSignalHandler(); // set row count depending on device model (used in lists) int rc = props->getIntDef(PROP_WINDOW_ROW_COUNT, 0); if(!rc) { #ifndef i386 switch(Device::getModel()) { case Device::KDX: rc = 20; break; case Device::KT: case Device::KPW: rc = 8; break; default: rc = 10; } props->setInt(PROP_WINDOW_ROW_COUNT, rc); #else props->setInt(PROP_WINDOW_ROW_COUNT, 10); #endif LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + "cr3.ini").data(), LVOM_WRITE); props->saveToStream(cfg.get()); } QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); MyApplication a(argc, argv); pMyApp = &a; // set app stylesheet #ifndef i386 QString style = Device::isTouch() ? "stylesheet_pw.qss" : "stylesheet_k3.qss"; QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + style); // set up full update interval for the graphics driver Device::setFullScreenUpdateEvery(props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); #else QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + "stylesheet_k3.qss"); #endif qss.open(QFile::ReadOnly); if(qss.error() == QFile::NoError) { a.setStyleSheet(qss.readAll()); qss.close(); } QMap<QString, QString> langToCode; langToCode["Russian"] = "ru"; langToCode["French"] = "fr"; langToCode["Hungarian"] = "hu"; langToCode["Italian"] = "it"; langToCode["German"] = "de"; langToCode["Ukrainian"] = "uk"; QString translations = cr2qt(datadir) + "i18n"; QTranslator myappTranslator, qtr; if (!lang.empty() && lang.compare("English")) { QString lng = cr2qt(lang); if (myappTranslator.load(lng, translations)) { // default translator for Qt standard dialogs if (qtr.load("qt_" + langToCode[lng], translations)) { QApplication::installTranslator(&qtr); } else { qDebug() << "Failed to load Qt translation for " << lng; } // load after default to allow overriding translations QApplication::installTranslator(&myappTranslator); } else { qDebug() << "Can`t load translation file " << lng << " from dir " << translations; } } (void) signal(SIGUSR1, sigCatcher); MainWindow mainWin; a.setMainWindow(&mainWin); mainWin.showFullScreen(); mainWin.doStartupActions(); res = a.exec(); } ShutdownCREngine(); return res; }
int main(int argc, char *argv[]) { int res = 0; { #ifdef DEBUG lString8 loglevel("TRACE"); lString8 logfile("stdout"); #else lString8 loglevel("ERROR"); lString8 logfile("stderr"); #endif for ( int i=1; i<argc; i++ ) { if ( !strcmp("-h", argv[i]) || !strcmp("-?", argv[i]) || !strcmp("/?", argv[i]) || !strcmp("--help", argv[i]) ) { printHelp(); return 0; } if ( !strcmp("-v", argv[i]) || !strcmp("/v", argv[i]) || !strcmp("--version", argv[i]) ) { printVersion(); return 0; } if ( !strcmp("--stats", argv[i]) && i<argc-4 ) { if ( i!=argc-5 ) { printf("To calculate character encoding statistics, use cr3 <infile.txt> <outfile.cpp> <codepagename> <langname>\n"); return 1; } lString8 list; FILE * out = fopen(argv[i+2], "wb"); if ( !out ) { printf("Cannot create file %s", argv[i+2]); return 1; } MakeStatsForFile( argv[i+1], argv[i+3], argv[i+4], 0, out, list ); fclose(out); return 0; } lString8 s(argv[i]); if ( s.startsWith(lString8("--loglevel=")) ) { loglevel = s.substr(11, s.length()-11); } else if ( s.startsWith(lString8("--logfile=")) ) { logfile = s.substr(10, s.length()-10); } } // set logger if ( logfile=="stdout" ) CRLog::setStdoutLogger(); else if ( logfile=="stderr" ) CRLog::setStderrLogger(); else if ( !logfile.empty() ) CRLog::setFileLogger(logfile.c_str()); if ( loglevel=="TRACE" ) CRLog::setLogLevel(CRLog::LL_TRACE); else if ( loglevel=="DEBUG" ) CRLog::setLogLevel(CRLog::LL_DEBUG); else if ( loglevel=="INFO" ) CRLog::setLogLevel(CRLog::LL_INFO); else if ( loglevel=="WARN" ) CRLog::setLogLevel(CRLog::LL_WARN); else if ( loglevel=="ERROR" ) CRLog::setLogLevel(CRLog::LL_ERROR); else CRLog::setLogLevel(CRLog::LL_FATAL); lString16 exename = LocalToUnicode( lString8(argv[0]) ); lString16 exedir = LVExtractPath(exename); lString16 datadir = lString16(CR3_DATA_DIR); LVAppendPathDelimiter(exedir); LVAppendPathDelimiter(datadir); lString16 exefontpath = exedir + L"fonts"; CRLog::info("main()"); lString16Collection fontDirs; //fontDirs.add( lString16(L"/usr/local/share/crengine/fonts") ); //fontDirs.add( lString16(L"/usr/local/share/fonts/truetype/freefont") ); //fontDirs.add( lString16(L"/mnt/fonts") ); #if 0 fontDirs.add( exefontpath ); fontDirs.add( lString16(L"/usr/share/fonts/truetype") ); fontDirs.add( lString16(L"/usr/share/fonts/truetype/liberation") ); fontDirs.add( lString16(L"/usr/share/fonts/truetype/freefont") ); #endif // TODO: use fontconfig instead //fontDirs.add( lString16(L"/root/fonts/truetype") ); if ( !InitCREngine( argv[0], fontDirs ) ) { printf("Cannot init CREngine - exiting\n"); return 2; } if ( argc>=2 && !strcmp(argv[1], "unittest") ) { #ifdef _DEBUG runTinyDomUnitTests(); #endif CRLog::info("UnitTests finished: exiting"); return 0; } //if ( argc!=2 ) { // printf("Usage: cr3 <filename_to_open>\n"); // return 3; //} { QApplication a(argc, argv); #ifdef _WIN32 QString exeDir = QDir::toNativeSeparators(qApp->applicationDirPath() + "/"); //QDir::separator(); QString translations = exeDir + "i18n"; #else QString exeDir = cr2qt(datadir); QString translations = exeDir + "i18n/"; #endif QTranslator qtTranslator; if (qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) QApplication::installTranslator(&qtTranslator); QTranslator myappTranslator; QString trname = "cr3_" + QLocale::system().name(); CRLog::info("Using translation file %s from dir %s", UnicodeToUtf8(qt2cr(trname)).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str() ); if ( myappTranslator.load(trname, translations) ) QApplication::installTranslator(&myappTranslator); else CRLog::error("Canot load translation file %s from dir %s", UnicodeToUtf8(qt2cr(trname)).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str() ); MainWindow w; w.show(); res = a.exec(); } } ShutdownCREngine(); return res; }
virtual QString getStringDef( const char * prop, const char * defValue ) { return cr2qt( _ref->getStringDef(prop, defValue) ); }
virtual QString value( int index ) { return cr2qt(_ref->getValue( index )); }
SettingsDlg::SettingsDlg(QWidget *parent, CR3View * docView ) : QDialog(parent), m_ui(new Ui::SettingsDlg), m_docview( docView ) { initDone = false; m_ui->setupUi(this); m_props = m_docview->getOptions(); m_oldHyph = cr2qt(HyphMan::getSelectedDictionary()->getId()); #ifdef _LINUX QString homeDir = QDir::toNativeSeparators(QDir::homePath() + "/.cr3/"); #else QString homeDir = QDir::toNativeSeparators(QDir::homePath() + "/cr3/"); #endif #if MAC==1 QString exeDir = QDir::toNativeSeparators(qApp->applicationDirPath() + "/../Resources/"); //QDir::separator(); #elif _LINUX QString exeDir = QString(CR3_DATA_DIR); #else QString exeDir = QDir::toNativeSeparators(qApp->applicationDirPath() + "/"); //QDir::separator(); #endif lString16Collection baseDirs; baseDirs.add(qt2cr(homeDir)); baseDirs.add(qt2cr(exeDir)); #ifdef _LINUX baseDirs.add(cs16("/usr/local/share/cr3/")); #endif lString16Collection bgFiles; QStringList bgFileLabels; findBackgrounds( baseDirs, bgFiles ); int bgIndex = 0; m_backgroundFiles.append("[NONE]"); bgFileLabels.append("[NONE]"); QString bgFile = m_props->getStringDef(PROP_BACKGROUND_IMAGE, ""); for ( int i=0; i<bgFiles.length(); i++ ) { lString16 fn = bgFiles[i]; QString f = cr2qt(fn); if ( f==bgFile ) bgIndex = i; m_backgroundFiles.append(f); fn = LVExtractFilenameWithoutExtension(fn); bgFileLabels.append(cr2qt(fn)); } m_ui->cbPageSkin->clear(); m_ui->cbPageSkin->addItems( bgFileLabels ); m_ui->cbPageSkin->setCurrentIndex(bgIndex+1); optionToUi( PROP_WINDOW_FULLSCREEN, m_ui->cbWindowFullscreen ); optionToUi( PROP_WINDOW_SHOW_MENU, m_ui->cbWindowShowMenu ); optionToUi( PROP_WINDOW_SHOW_SCROLLBAR, m_ui->cbWindowShowScrollbar ); optionToUi( PROP_WINDOW_TOOLBAR_SIZE, m_ui->cbWindowShowToolbar ); optionToUi( PROP_WINDOW_SHOW_STATUSBAR, m_ui->cbWindowShowStatusBar ); optionToUi( PROP_FOOTNOTES, m_ui->cbShowFootNotes ); optionToUi( PROP_SHOW_BATTERY, m_ui->cbShowBattery ); optionToUi( PROP_SHOW_TIME, m_ui->cbShowClock ); optionToUi( PROP_SHOW_TITLE, m_ui->cbShowBookName ); optionToUi( PROP_TXT_OPTION_PREFORMATTED, m_ui->cbTxtPreFormatted ); optionToUi( PROP_EMBEDDED_STYLES, m_ui->cbEnableDocumentStyles ); optionToUi( PROP_EMBEDDED_FONTS, m_ui->cbEnableEmbeddedFonts ); m_ui->cbEnableEmbeddedFonts->setEnabled(m_props->getBoolDef(PROP_EMBEDDED_STYLES, true) ? Qt::Checked : Qt::Unchecked); optionToUi( PROP_TXT_OPTION_PREFORMATTED, m_ui->cbTxtPreFormatted ); optionToUi( PROP_FLOATING_PUNCTUATION, m_ui->cbFloatingPunctuation ); optionToUiIndex( PROP_IMG_SCALING_ZOOMIN_INLINE_MODE, m_ui->cbImageInlineZoominMode ); optionToUiIndex( PROP_IMG_SCALING_ZOOMIN_INLINE_SCALE, m_ui->cbImageInlineZoominScale ); optionToUiIndex( PROP_IMG_SCALING_ZOOMOUT_INLINE_MODE, m_ui->cbImageInlineZoomoutMode ); optionToUiIndex( PROP_IMG_SCALING_ZOOMOUT_INLINE_SCALE, m_ui->cbImageInlineZoomoutScale ); optionToUiIndex( PROP_IMG_SCALING_ZOOMIN_BLOCK_MODE, m_ui->cbImageBlockZoominMode ); optionToUiIndex( PROP_IMG_SCALING_ZOOMIN_BLOCK_SCALE, m_ui->cbImageBlockZoominScale ); optionToUiIndex( PROP_IMG_SCALING_ZOOMOUT_BLOCK_MODE, m_ui->cbImageBlockZoomoutMode ); optionToUiIndex( PROP_IMG_SCALING_ZOOMOUT_BLOCK_SCALE, m_ui->cbImageBlockZoomoutScale ); QString gamma = m_props->getStringDef(PROP_FONT_GAMMA, ""); if ( gamma=="" ) m_props->setString(PROP_FONT_GAMMA, "1.0"); optionToUiString(PROP_FONT_GAMMA, m_ui->cbFontGamma); optionToUiInversed( PROP_STATUS_LINE, m_ui->cbShowPageHeader ); bool b = m_props->getIntDef( PROP_STATUS_LINE, 0 )==0; m_ui->cbShowBattery->setEnabled( b ); m_ui->cbShowClock->setEnabled( b ); m_ui->cbShowBookName->setEnabled( b ); m_ui->cbStartupAction->setCurrentIndex( m_props->getIntDef( PROP_APP_START_ACTION, 0 ) ); int lp = m_props->getIntDef( PROP_LANDSCAPE_PAGES, 2 ); int vm = m_props->getIntDef( PROP_PAGE_VIEW_MODE, 1 ); if ( vm==0 ) m_ui->cbViewMode->setCurrentIndex( 2 ); else m_ui->cbViewMode->setCurrentIndex( lp==1 ? 0 : 1 ); int hinting = m_props->getIntDef(PROP_FONT_HINTING, 2); m_ui->cbFontHinting->setCurrentIndex(hinting); int highlight = m_props->getIntDef(PROP_HIGHLIGHT_COMMENT_BOOKMARKS, 1); m_ui->cbBookmarkHighlightMode->setCurrentIndex(highlight); int n = m_props->getIntDef( PROP_PAGE_MARGIN_LEFT, 8 ); int mi = 0; for (int i=0; i < (int)MAX_MARGIN_INDEX; i++) { if (n <= def_margins[i]) { mi = i; break; } } CRLog::debug("initial margins index: %d", mi); m_ui->cbMargins->setCurrentIndex( mi ); QStringList styles = QStyleFactory::keys(); QString style = m_props->getStringDef( PROP_WINDOW_STYLE, "" ); m_ui->cbLookAndFeel->addItems( styles ); QStyle * s = QApplication::style(); QString currStyle = s->objectName(); CRLog::debug("Current system style is %s", currStyle.toUtf8().data() ); if ( !styles.contains(style, Qt::CaseInsensitive) ) style = currStyle; int index = styles.indexOf( style, Qt::CaseInsensitive ); if ( index >=0 ) m_ui->cbLookAndFeel->setCurrentIndex( index ); crGetFontFaceList( m_faceList ); m_ui->cbTextFontFace->addItems( m_faceList ); m_ui->cbTitleFontFace->addItems( m_faceList ); m_ui->cbFallbackFontFace->addItems( m_faceList ); QStringList sizeList; LVArray<int> sizes( cr_font_sizes, sizeof(cr_font_sizes)/sizeof(int) ); for ( int i=0; i<sizes.length(); i++ ) sizeList.append( QString("%1").arg(sizes[i]) ); m_ui->cbTextFontSize->addItems( sizeList ); m_ui->cbTitleFontSize->addItems( sizeList ); const char * defFontFace = "DejaVu Sans"; static const char * goodFonts[] = { "DejaVu Sans", "FreeSans", "Liberation Sans", "Arial", NULL }; for ( int i=0; goodFonts[i]; i++ ) { if ( m_faceList.indexOf(QString(goodFonts[i]))>=0 ) { defFontFace = goodFonts[i]; break; } } fontToUi( PROP_FONT_FACE, PROP_FONT_SIZE, m_ui->cbTextFontFace, m_ui->cbTextFontSize, defFontFace ); fontToUi( PROP_STATUS_FONT_FACE, PROP_STATUS_FONT_SIZE, m_ui->cbTitleFontFace, m_ui->cbTitleFontSize, defFontFace ); fontToUi( PROP_FALLBACK_FONT_FACE, PROP_FALLBACK_FONT_FACE, m_ui->cbFallbackFontFace, NULL, defFontFace ); // {_("90%"), "90"}, // {_("100%"), "100"}, // {_("110%"), "110"}, // {_("120%"), "120"}, // {_("140%"), "140"}, //PROP_INTERLINE_SPACE //PROP_HYPHENATION_DICT QString v = QString("%1").arg(m_props->getIntDef(PROP_INTERLINE_SPACE, 100)) + "%"; QStringList isitems; for (int i = 0; i < (int)(sizeof(interline_spaces) / sizeof(int)); i++) isitems.append(QString("%1").arg(interline_spaces[i]) + "%"); m_ui->cbInterlineSpace->addItems(isitems); int isi = m_ui->cbInterlineSpace->findText(v); m_ui->cbInterlineSpace->setCurrentIndex(isi>=0 ? isi : 6); int hi = -1; v = m_props->getStringDef(PROP_HYPHENATION_DICT,"@algorithm"); //HYPH_DICT_ID_ALGORITHM; for ( int i=0; i<HyphMan::getDictList()->length(); i++ ) { HyphDictionary * item = HyphMan::getDictList()->get( i ); if (v == cr2qt(item->getFilename() ) || v == cr2qt(item->getId() )) hi = i; QString s = cr2qt( item->getTitle() ); if ( item->getType()==HDT_NONE ) s = tr("[No hyphenation]"); else if ( item->getType()==HDT_ALGORITHM ) s = tr("[Algorythmic hyphenation]"); m_ui->cbHyphenation->addItem( s ); } m_ui->cbHyphenation->setCurrentIndex(hi>=0 ? hi : 1); m_ui->crSample->setOptions( m_props ); m_ui->crSample->getDocView()->setShowCover( false ); m_ui->crSample->getDocView()->setViewMode( DVM_SCROLL, 1 ); QString testPhrase = tr("The quick brown fox jumps over the lazy dog. "); m_ui->crSample->getDocView()->createDefaultDocument(lString16::empty_str, qt2cr(testPhrase+testPhrase+testPhrase)); updateStyleSample(); m_styleNames.clear(); m_styleNames.append(tr("Default paragraph style")); m_styleNames.append(tr("Title")); m_styleNames.append(tr("Subtitle")); m_styleNames.append(tr("Preformatted text")); m_styleNames.append(tr("Link")); m_styleNames.append(tr("Cite / quotation")); m_styleNames.append(tr("Epigraph")); m_styleNames.append(tr("Poem")); m_styleNames.append(tr("Text author")); m_styleNames.append(tr("Footnote link")); m_styleNames.append(tr("Footnote")); m_styleNames.append(tr("Footnote title")); m_styleNames.append(tr("Annotation")); m_ui->cbStyleName->clear(); m_ui->cbStyleName->addItems(m_styleNames); m_ui->cbStyleName->setCurrentIndex(0); initStyleControls("def"); initDone = true; //m_ui->cbPageSkin->addItem(QString("[None]"), QVariant()); }
int main(int argc, char *argv[]) { int res = 0; { Device::instance(); // initialize device #ifndef i386 QProcess::execute("eips -c"); pTouch = new TouchScreen(); #endif lString16 exedir = LVExtractPath(LocalToUnicode(lString8(argv[0]))); LVAppendPathDelimiter(exedir); lString16 datadir = exedir + L"data/"; lString16 exefontpath = exedir + L"fonts"; lString16Collection fontDirs; fontDirs.add(exefontpath); #ifndef i386 fontDirs.add(lString16(L"/usr/java/lib/fonts")); fontDirs.add(lString16(L"/mnt/us/fonts")); #endif CRPropRef props = LVCreatePropsContainer(); { LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + L"cr3.ini").data(), LVOM_READ); if(!cfg.isNull()) props->loadFromStream(cfg.get()); } lString16 lang = props->getStringDef(PROP_WINDOW_LANG, ""); InitCREngineLog(props); CRLog::info("main()"); if(!InitCREngine(argv[0], fontDirs)) { printf("Cannot init CREngine - exiting\n"); return 2; } #ifndef i386 PrintString(1, 1, "crengine version: " + QString(CR_ENGINE_VERSION)); PrintString(1, 2, QString("buid date: %1 %2").arg(__DATE__).arg(__TIME__)); if (!Device::isTouch()) { QString message = "Please wait while application is loading..."; int xpos = ((Device::getWidth()/12-1)-message.length())/2; int ypos = (Device::getHeight()/20-2)/2; PrintString(xpos, ypos, message); } #endif // set row count int rc = props->getIntDef(PROP_WINDOW_ROW_COUNT, 0); if(!rc) { #ifndef i386 props->setInt(PROP_WINDOW_ROW_COUNT, Device::getModel() != Device::KDX ? 10 : 16); #else props->setInt(PROP_WINDOW_ROW_COUNT, 10); #endif LVStreamRef cfg = LVOpenFileStream(UnicodeToUtf8(datadir + L"cr3.ini").data(), LVOM_WRITE); props->saveToStream(cfg.get()); } QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); MyApplication a(argc, argv); pMyApp = &a; // set app stylesheet #ifndef i386 QString style = (Device::getModel() != Device::KDX ? "stylesheet_k3.qss" : "stylesheet_dx.qss"); if (Device::getModel() == Device::KPW) style = "stylesheet_pw.qss"; QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + style); // set up full update interval for the graphics driver QKindleFb *pscreen = static_cast<QKindleFb*>(QScreen::instance()); pscreen->setFullUpdateEvery(props->getIntDef(PROP_DISPLAY_FULL_UPDATE_INTERVAL, 1)); #else QFile qss(QDir::toNativeSeparators(cr2qt(datadir)) + "stylesheet_k3.qss"); #endif qss.open(QFile::ReadOnly); if(qss.error() == QFile::NoError) { a.setStyleSheet(qss.readAll()); qss.close(); } QString translations = cr2qt(datadir) + "i18n"; QTranslator myappTranslator; if(!lang.empty() && lang.compare(L"English")) { if(myappTranslator.load(cr2qt(lang), translations)) QApplication::installTranslator(&myappTranslator); else qDebug("Can`t load translation file %s from dir %s", UnicodeToUtf8(lang).c_str(), UnicodeToUtf8(qt2cr(translations)).c_str()); } (void) signal(SIGUSR1, sigCatcher); MainWindow mainWin; a.setMainWindow(&mainWin); mainWin.showFullScreen(); mainWin.doStartupActions(); res = a.exec(); } ShutdownCREngine(); return res; }