Porównaj commity
	
		
			8 Commity
		
	
	
		
			4ce14a7284
			...
			43a0f08579
		
	
	| Autor | SHA1 | Data | |
|---|---|---|---|
| 43a0f08579 | |||
| 1aa5ae0ccc | |||
| 20d42a66a6 | |||
| cba4df3eac | |||
| fdbf3a7358 | |||
| ac4d7dd0a5 | |||
| ab064c3e3b | |||
| a33c7f1859 | 
| @@ -36,9 +36,11 @@ SOURCES += \ | |||||||
|       clicklabel.cpp \ |       clicklabel.cpp \ | ||||||
|     previewgenerator.cpp \ |     previewgenerator.cpp \ | ||||||
|     previewgeneratormapfunctor.cpp \ |     previewgeneratormapfunctor.cpp \ | ||||||
|  |     previewgeneratorodt.cpp \ | ||||||
|     previewgeneratorpdf.cpp \ |     previewgeneratorpdf.cpp \ | ||||||
|     previewgeneratorplaintext.cpp \ |     previewgeneratorplaintext.cpp \ | ||||||
|     previewresult.cpp \ |     previewresult.cpp \ | ||||||
|  |     previewresultodt.cpp \ | ||||||
|     previewresultpdf.cpp \ |     previewresultpdf.cpp \ | ||||||
|     previewresultplaintext.cpp \ |     previewresultplaintext.cpp \ | ||||||
|     renderconfig.cpp \ |     renderconfig.cpp \ | ||||||
| @@ -54,9 +56,11 @@ HEADERS += \ | |||||||
|     clicklabel.h \ |     clicklabel.h \ | ||||||
|     previewgenerator.h \ |     previewgenerator.h \ | ||||||
|     previewgeneratormapfunctor.h \ |     previewgeneratormapfunctor.h \ | ||||||
|  |     previewgeneratorodt.h \ | ||||||
|     previewgeneratorpdf.h \ |     previewgeneratorpdf.h \ | ||||||
|     previewgeneratorplaintext.h \ |     previewgeneratorplaintext.h \ | ||||||
|     previewresult.h \ |     previewresult.h \ | ||||||
|  |     previewresultodt.h \ | ||||||
|     previewresultpdf.h \ |     previewresultpdf.h \ | ||||||
|     previewresultplaintext.h \ |     previewresultplaintext.h \ | ||||||
|     renderconfig.h \ |     renderconfig.h \ | ||||||
| @@ -66,6 +70,7 @@ FORMS += \ | |||||||
|         mainwindow.ui |         mainwindow.ui | ||||||
|  |  | ||||||
| INCLUDEPATH += /usr/include/poppler/qt5/ | INCLUDEPATH += /usr/include/poppler/qt5/ | ||||||
|  | INCLUDEPATH += /usr/include/quazip5 | ||||||
|  |  | ||||||
| QT += widgets sql | QT += widgets sql | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,28 +33,6 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath) | |||||||
| 	setWindowTitle(QCoreApplication::applicationName()); | 	setWindowTitle(QCoreApplication::applicationName()); | ||||||
| 	this->ipcPreviewClient.moveToThread(&this->ipcClientThread); | 	this->ipcPreviewClient.moveToThread(&this->ipcClientThread); | ||||||
| 	this->ipcPreviewClient.setSocketPath(socketPath); | 	this->ipcPreviewClient.setSocketPath(socketPath); | ||||||
|  |  | ||||||
| 	connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &MainWindow::previewReceived, |  | ||||||
| 			Qt::QueuedConnection); |  | ||||||
| 	connect(&ipcPreviewClient, &IPCPreviewClient::finished, this, |  | ||||||
| 			[&] |  | ||||||
| 			{ |  | ||||||
| 				this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum()); |  | ||||||
| 				this->ui->spinPreviewPage->setEnabled(true); |  | ||||||
| 				this->ui->comboPreviewFiles->setEnabled(true); |  | ||||||
| 			}); |  | ||||||
| 	connect(&ipcPreviewClient, &IPCPreviewClient::error, this, |  | ||||||
| 			[this](QString msg) |  | ||||||
| 			{ |  | ||||||
| 				qCritical() << msg << Qt::endl; |  | ||||||
| 				QMessageBox::critical(this, "IPC error", msg); |  | ||||||
| 			}); |  | ||||||
|  |  | ||||||
| 	connect(this, &MainWindow::startIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::startGeneration, |  | ||||||
| 			Qt::QueuedConnection); |  | ||||||
| 	connect(this, &MainWindow::stopIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::stopGeneration, |  | ||||||
| 			Qt::QueuedConnection); |  | ||||||
| 	this->ipcClientThread.start(); |  | ||||||
| 	QSettings settings; | 	QSettings settings; | ||||||
|  |  | ||||||
| 	this->dbFactory = new DatabaseFactory(Common::databasePath()); | 	this->dbFactory = new DatabaseFactory(Common::databasePath()); | ||||||
| @@ -91,6 +69,8 @@ MainWindow::MainWindow(QWidget *parent, QString socketPath) | |||||||
| 	auto policy = ui->btnOpenFailed->sizePolicy(); | 	auto policy = ui->btnOpenFailed->sizePolicy(); | ||||||
| 	policy.setRetainSizeWhenHidden(true); | 	policy.setRetainSizeWhenHidden(true); | ||||||
| 	ui->btnOpenFailed->setSizePolicy(policy); | 	ui->btnOpenFailed->setSizePolicy(policy); | ||||||
|  |  | ||||||
|  | 	this->ipcClientThread.start(); | ||||||
| } | } | ||||||
|  |  | ||||||
| void MainWindow::addPathToIndex() | void MainWindow::addPathToIndex() | ||||||
| @@ -191,6 +171,9 @@ void MainWindow::connectSignals() | |||||||
| 	connect(ui->menuAboutQtAction, &QAction::triggered, this, | 	connect(ui->menuAboutQtAction, &QAction::triggered, this, | ||||||
| 			[this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); }); | 			[this](bool checked) { QMessageBox::aboutQt(this, "About Qt"); }); | ||||||
| 	connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync); | 	connect(ui->menuSyncIndexAction, &QAction::triggered, this, &MainWindow::startIndexSync); | ||||||
|  | 	connect(ui->menuOpenUserManualAction, &QAction::triggered, this, | ||||||
|  | 			[this]() { QDesktopServices::openUrl(Common::userManualUrl()); }); | ||||||
|  |  | ||||||
| 	connect(indexSyncer, &IndexSyncer::finished, this, | 	connect(indexSyncer, &IndexSyncer::finished, this, | ||||||
| 			[&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) | 			[&](unsigned int totalUpdated, unsigned int totalDeleted, unsigned int totalErrored) | ||||||
| 			{ | 			{ | ||||||
| @@ -210,6 +193,26 @@ void MainWindow::connectSignals() | |||||||
| 	connect( | 	connect( | ||||||
| 		ui->comboPreviewFiles, qOverload<int>(&QComboBox::currentIndexChanged), this, [&]() { makePreviews(1); }, | 		ui->comboPreviewFiles, qOverload<int>(&QComboBox::currentIndexChanged), this, [&]() { makePreviews(1); }, | ||||||
| 		Qt::QueuedConnection); | 		Qt::QueuedConnection); | ||||||
|  | 	connect(&ipcPreviewClient, &IPCPreviewClient::previewReceived, this, &MainWindow::previewReceived, | ||||||
|  | 			Qt::QueuedConnection); | ||||||
|  | 	connect(&ipcPreviewClient, &IPCPreviewClient::finished, this, | ||||||
|  | 			[&] | ||||||
|  | 			{ | ||||||
|  | 				this->ui->previewProcessBar->setValue(this->ui->previewProcessBar->maximum()); | ||||||
|  | 				this->ui->spinPreviewPage->setEnabled(true); | ||||||
|  | 				this->ui->comboPreviewFiles->setEnabled(true); | ||||||
|  | 			}); | ||||||
|  | 	connect(&ipcPreviewClient, &IPCPreviewClient::error, this, | ||||||
|  | 			[this](QString msg) | ||||||
|  | 			{ | ||||||
|  | 				qCritical() << msg << Qt::endl; | ||||||
|  | 				QMessageBox::critical(this, "IPC error", msg); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 	connect(this, &MainWindow::startIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::startGeneration, | ||||||
|  | 			Qt::QueuedConnection); | ||||||
|  | 	connect(this, &MainWindow::stopIpcPreviews, &ipcPreviewClient, &IPCPreviewClient::stopGeneration, | ||||||
|  | 			Qt::QueuedConnection); | ||||||
| } | } | ||||||
|  |  | ||||||
| void MainWindow::exportFailedPaths() | void MainWindow::exportFailedPaths() | ||||||
| @@ -436,19 +439,46 @@ void MainWindow::previewReceived(QSharedPointer<PreviewResult> preview, unsigned | |||||||
| 		QString docPath = preview->getDocumentPath(); | 		QString docPath = preview->getDocumentPath(); | ||||||
| 		auto previewPage = preview->getPage(); | 		auto previewPage = preview->getPage(); | ||||||
|  |  | ||||||
|  | 		ClickLabel *headerLabel = new ClickLabel(); | ||||||
|  | 		headerLabel->setText(QString("Path: ") + preview->getDocumentPath()); | ||||||
|  |  | ||||||
| 		ClickLabel *label = dynamic_cast<ClickLabel *>(preview->createPreviewWidget()); | 		ClickLabel *label = dynamic_cast<ClickLabel *>(preview->createPreviewWidget()); | ||||||
| 		ui->scrollAreaWidgetContents->layout()->addWidget(label); |  | ||||||
| 		connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { openDocument(docPath, previewPage); }); | 		QVBoxLayout *previewLayout = new QVBoxLayout(); | ||||||
| 		connect(label, &ClickLabel::rightClick, |  | ||||||
| 				[this, docPath, previewPage]() | 		QFont font = label->font(); | ||||||
|  | 		font.setPointSize(QApplication::font().pointSize() * currentSelectedScale() / 100); | ||||||
|  | 		label->setFont(font); | ||||||
|  | 		headerLabel->setFont(font); | ||||||
|  |  | ||||||
|  | 		auto leftClickHandler = [this, docPath, previewPage]() { openDocument(docPath, previewPage); }; | ||||||
|  | 		auto rightClickhandler = [this, docPath, previewPage]() | ||||||
| 		{ | 		{ | ||||||
| 			QFileInfo fileInfo{docPath}; | 			QFileInfo fileInfo{docPath}; | ||||||
| 			QMenu menu("labeRightClick", this); | 			QMenu menu("labeRightClick", this); | ||||||
| 			createSearchResutlMenu(menu, fileInfo); | 			createSearchResutlMenu(menu, fileInfo); | ||||||
| 					menu.addAction("Copy page number", [previewPage] | 			menu.addAction("Copy page number", | ||||||
| 								   { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); | 						   [previewPage] { QGuiApplication::clipboard()->setText(QString::number(previewPage)); }); | ||||||
| 			menu.exec(QCursor::pos()); | 			menu.exec(QCursor::pos()); | ||||||
| 				}); | 		}; | ||||||
|  |  | ||||||
|  | 		connect(label, &ClickLabel::leftClick, leftClickHandler); | ||||||
|  | 		connect(label, &ClickLabel::rightClick, rightClickhandler); | ||||||
|  |  | ||||||
|  | 		connect(headerLabel, &ClickLabel::rightClick, rightClickhandler); | ||||||
|  |  | ||||||
|  | 		previewLayout->addWidget(label); | ||||||
|  |  | ||||||
|  | 		previewLayout->addWidget(headerLabel); | ||||||
|  |  | ||||||
|  | 		previewLayout->setMargin(0); | ||||||
|  | 		previewLayout->insertStretch(0, 1); | ||||||
|  | 		previewLayout->insertStretch(-1, 1); | ||||||
|  | 		QWidget *previewWidget = new QWidget(); | ||||||
|  |  | ||||||
|  | 		previewWidget->setLayout(previewLayout); | ||||||
|  |  | ||||||
|  | 		ui->scrollAreaWidgetContents->layout()->addWidget(previewWidget); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -567,6 +597,13 @@ void MainWindow::handleSearchResults(const QVector<SearchResult> &results) | |||||||
| 	ui->lblSearchResults->setText(statusText); | 	ui->lblSearchResults->setText(statusText); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int MainWindow::currentSelectedScale() | ||||||
|  | { | ||||||
|  | 	QString scaleText = ui->comboScale->currentText(); | ||||||
|  | 	scaleText.chop(1); | ||||||
|  | 	return scaleText.toInt(); | ||||||
|  | } | ||||||
|  |  | ||||||
| void MainWindow::makePreviews(int page) | void MainWindow::makePreviews(int page) | ||||||
| { | { | ||||||
| 	if(this->previewableSearchResults.empty()) | 	if(this->previewableSearchResults.empty()) | ||||||
| @@ -578,8 +615,6 @@ void MainWindow::makePreviews(int page) | |||||||
| 	ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout()); | 	ui->scrollAreaWidgetContents->setLayout(new QHBoxLayout()); | ||||||
| 	ui->previewProcessBar->setMaximum(this->previewableSearchResults.size()); | 	ui->previewProcessBar->setMaximum(this->previewableSearchResults.size()); | ||||||
| 	processedPdfPreviews = 0; | 	processedPdfPreviews = 0; | ||||||
| 	QString scaleText = ui->comboScale->currentText(); |  | ||||||
| 	scaleText.chop(1); |  | ||||||
|  |  | ||||||
| 	QVector<QString> wordsToHighlight; | 	QVector<QString> wordsToHighlight; | ||||||
| 	QRegularExpression extractor(R"#("([^"]*)"|((\p{L}|\p{N})+))#"); | 	QRegularExpression extractor(R"#("([^"]*)"|((\p{L}|\p{N})+))#"); | ||||||
| @@ -608,9 +643,10 @@ void MainWindow::makePreviews(int page) | |||||||
| 		begin = 0; | 		begin = 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	int currentScale = currentSelectedScale(); | ||||||
| 	RenderConfig renderConfig; | 	RenderConfig renderConfig; | ||||||
| 	renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.); | 	renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (currentScale / 100.); | ||||||
| 	renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (scaleText.toInt() / 100.); | 	renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.); | ||||||
| 	renderConfig.wordsToHighlight = wordsToHighlight; | 	renderConfig.wordsToHighlight = wordsToHighlight; | ||||||
|  |  | ||||||
| 	QVector<RenderTarget> targets; | 	QVector<RenderTarget> targets; | ||||||
|   | |||||||
| @@ -62,6 +62,7 @@ class MainWindow : public QMainWindow | |||||||
| 	void openFile(QString path); | 	void openFile(QString path); | ||||||
| 	unsigned int currentPreviewGeneration = 1; | 	unsigned int currentPreviewGeneration = 1; | ||||||
| 	void initSettingsTabs(); | 	void initSettingsTabs(); | ||||||
|  | 	int currentSelectedScale(); | ||||||
|   private slots: |   private slots: | ||||||
| 	void lineEditReturnPressed(); | 	void lineEditReturnPressed(); | ||||||
| 	void treeSearchItemActivated(QTreeWidgetItem *item, int i); | 	void treeSearchItemActivated(QTreeWidgetItem *item, int i); | ||||||
|   | |||||||
| @@ -626,6 +626,7 @@ | |||||||
|      <string>looqs</string> |      <string>looqs</string> | ||||||
|     </property> |     </property> | ||||||
|     <addaction name="menuSyncIndexAction"/> |     <addaction name="menuSyncIndexAction"/> | ||||||
|  |     <addaction name="menuOpenUserManualAction"/> | ||||||
|     <addaction name="menuAboutAction"/> |     <addaction name="menuAboutAction"/> | ||||||
|     <addaction name="menuAboutQtAction"/> |     <addaction name="menuAboutQtAction"/> | ||||||
|     <addaction name="separator"/> |     <addaction name="separator"/> | ||||||
| @@ -647,6 +648,11 @@ | |||||||
|     <string>Sync index (remove deleted, update existing files)</string> |     <string>Sync index (remove deleted, update existing files)</string> | ||||||
|    </property> |    </property> | ||||||
|   </action> |   </action> | ||||||
|  |   <action name="menuOpenUserManualAction"> | ||||||
|  |    <property name="text"> | ||||||
|  |     <string>Open user manual</string> | ||||||
|  |    </property> | ||||||
|  |   </action> | ||||||
|  </widget> |  </widget> | ||||||
|  <layoutdefault spacing="6" margin="11"/> |  <layoutdefault spacing="6" margin="11"/> | ||||||
|  <resources/> |  <resources/> | ||||||
|   | |||||||
| @@ -2,13 +2,15 @@ | |||||||
| #include "previewgenerator.h" | #include "previewgenerator.h" | ||||||
| #include "previewgeneratorpdf.h" | #include "previewgeneratorpdf.h" | ||||||
| #include "previewgeneratorplaintext.h" | #include "previewgeneratorplaintext.h" | ||||||
|  | #include "previewgeneratorodt.h" | ||||||
|  |  | ||||||
| static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText(); | static PreviewGenerator *plainTextGenerator = new PreviewGeneratorPlainText(); | ||||||
|  |  | ||||||
| static QMap<QString, PreviewGenerator *> generators{ | static QMap<QString, PreviewGenerator *> generators{ | ||||||
| 	{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator},  {"md", plainTextGenerator}, | 	{"pdf", new PreviewGeneratorPdf()}, {"txt", plainTextGenerator},  {"md", plainTextGenerator}, | ||||||
| 	{"py", plainTextGenerator},			{"java", plainTextGenerator}, {"js", plainTextGenerator}, | 	{"py", plainTextGenerator},			{"java", plainTextGenerator}, {"js", plainTextGenerator}, | ||||||
| 	{"cpp", plainTextGenerator},		{"c", plainTextGenerator},	  {"sql", plainTextGenerator}}; | 	{"cpp", plainTextGenerator},		{"c", plainTextGenerator},	  {"sql", plainTextGenerator}, | ||||||
|  | 	{"odt", new PreviewGeneratorOdt()}}; | ||||||
|  |  | ||||||
| PreviewGenerator *PreviewGenerator::get(QFileInfo &info) | PreviewGenerator *PreviewGenerator::get(QFileInfo &info) | ||||||
| { | { | ||||||
|   | |||||||
							
								
								
									
										32
									
								
								gui/previewgeneratorodt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								gui/previewgeneratorodt.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | #include <quazip.h> | ||||||
|  | #include <quazipfile.h> | ||||||
|  | #include "previewgeneratorplaintext.h" | ||||||
|  | #include "previewgeneratorodt.h" | ||||||
|  | #include "previewresultodt.h" | ||||||
|  | #include "../shared/tagstripperprocessor.h" | ||||||
|  |  | ||||||
|  | QSharedPointer<PreviewResult> PreviewGeneratorOdt::generate(RenderConfig config, QString documentPath, | ||||||
|  | 															unsigned int page) | ||||||
|  | { | ||||||
|  | 	PreviewResultOdt *result = new PreviewResultOdt(documentPath, page); | ||||||
|  |  | ||||||
|  | 	QFileInfo info{documentPath}; | ||||||
|  |  | ||||||
|  | 	QuaZipFile zipFile(documentPath); | ||||||
|  | 	zipFile.setFileName("content.xml"); | ||||||
|  | 	if(!zipFile.open(QIODevice::ReadOnly)) | ||||||
|  | 	{ | ||||||
|  | 		return QSharedPointer<PreviewResult>(result); | ||||||
|  | 	} | ||||||
|  | 	QByteArray entireContent = zipFile.readAll(); | ||||||
|  | 	if(entireContent.isEmpty()) | ||||||
|  | 	{ | ||||||
|  | 		throw LooqsGeneralException("Error while reading content.xml of " + documentPath); | ||||||
|  | 	} | ||||||
|  | 	TagStripperProcessor tsp; | ||||||
|  | 	QString content = tsp.process(entireContent).first().content; | ||||||
|  |  | ||||||
|  | 	PreviewGeneratorPlainText plainTextGenerator; | ||||||
|  | 	result->setText(plainTextGenerator.generatePreviewText(content, config, info.fileName())); | ||||||
|  | 	return QSharedPointer<PreviewResult>(result); | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								gui/previewgeneratorodt.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								gui/previewgeneratorodt.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | #ifndef PREVIEWGENERATORODT_H | ||||||
|  | #define PREVIEWGENERATORODT_H | ||||||
|  |  | ||||||
|  | #include "previewgenerator.h" | ||||||
|  | class PreviewGeneratorOdt : public PreviewGenerator | ||||||
|  | { | ||||||
|  |   public: | ||||||
|  | 	using PreviewGenerator::PreviewGenerator; | ||||||
|  |  | ||||||
|  | 	QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page); | ||||||
|  | }; | ||||||
|  | #endif // PREVIEWGENERATORODT_H | ||||||
| @@ -3,24 +3,15 @@ | |||||||
| #include "previewgeneratorplaintext.h" | #include "previewgeneratorplaintext.h" | ||||||
| #include "previewresultplaintext.h" | #include "previewresultplaintext.h" | ||||||
|  |  | ||||||
| QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath, | QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderConfig config, QString fileName) | ||||||
| 																  unsigned int page) |  | ||||||
| { | { | ||||||
| 	PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page); |  | ||||||
| 	QFile file(documentPath); |  | ||||||
| 	if(!file.open(QFile::ReadOnly | QFile::Text)) |  | ||||||
| 	{ |  | ||||||
| 		return QSharedPointer<PreviewResultPlainText>(result); |  | ||||||
| 	} |  | ||||||
| 	QTextStream in(&file); |  | ||||||
|  |  | ||||||
| 	QString resulText = ""; | 	QString resulText = ""; | ||||||
| 	QString content = in.readAll(); |  | ||||||
| 	QMap<int, QString> snippet; | 	QMap<int, QString> snippet; | ||||||
|  |  | ||||||
| 	int coveredRange = 0; | 	int coveredRange = -1; | ||||||
|  | 	int lastWordPos = -1; | ||||||
|  |  | ||||||
| 	int lastWordPos = 0; |  | ||||||
| 	QHash<QString, int> countmap; | 	QHash<QString, int> countmap; | ||||||
|  |  | ||||||
| 	const unsigned int maxSnippets = 7; | 	const unsigned int maxSnippets = 7; | ||||||
| @@ -71,9 +62,7 @@ QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig c | |||||||
| 		resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive); | 		resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	QFileInfo info{documentPath}; | 	QString header = "<b>" + fileName + "</b> "; | ||||||
|  |  | ||||||
| 	QString header = "<b>" + info.fileName() + "</b> "; |  | ||||||
| 	for(QString &word : config.wordsToHighlight) | 	for(QString &word : config.wordsToHighlight) | ||||||
| 	{ | 	{ | ||||||
| 		header += word + ": " + QString::number(countmap[word]) + " "; | 		header += word + ": " + QString::number(countmap[word]) + " "; | ||||||
| @@ -85,6 +74,22 @@ QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig c | |||||||
|  |  | ||||||
| 	header += "<hr>"; | 	header += "<hr>"; | ||||||
|  |  | ||||||
| 	result->setText(header + resulText.replace("\n", "<br>").mid(0, 1000)); | 	return header + resulText.replace("\n", "<br>").mid(0, 1000); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath, | ||||||
|  | 																  unsigned int page) | ||||||
|  | { | ||||||
|  | 	PreviewResultPlainText *result = new PreviewResultPlainText(documentPath, page); | ||||||
|  | 	QFile file(documentPath); | ||||||
|  | 	if(!file.open(QFile::ReadOnly | QFile::Text)) | ||||||
|  | 	{ | ||||||
|  | 		return QSharedPointer<PreviewResultPlainText>(result); | ||||||
|  | 	} | ||||||
|  | 	QTextStream in(&file); | ||||||
|  |  | ||||||
|  | 	QString content = in.readAll(); | ||||||
|  | 	QFileInfo info{documentPath}; | ||||||
|  | 	result->setText(generatePreviewText(content, config, info.fileName())); | ||||||
| 	return QSharedPointer<PreviewResultPlainText>(result); | 	return QSharedPointer<PreviewResultPlainText>(result); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ class PreviewGeneratorPlainText : public PreviewGenerator | |||||||
| { | { | ||||||
|   public: |   public: | ||||||
| 	using PreviewGenerator::PreviewGenerator; | 	using PreviewGenerator::PreviewGenerator; | ||||||
|  | 	QString generatePreviewText(QString content, RenderConfig config, QString fileName); | ||||||
| 	QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page); | 	QSharedPointer<PreviewResult> generate(RenderConfig config, QString documentPath, unsigned int page); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								gui/previewresultodt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								gui/previewresultodt.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | #include "previewresultodt.h" | ||||||
							
								
								
									
										10
									
								
								gui/previewresultodt.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								gui/previewresultodt.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | |||||||
|  | #ifndef PREVIEWRESULTODT_H | ||||||
|  | #define PREVIEWRESULTODT_H | ||||||
|  | #include "previewresultplaintext.h" | ||||||
|  |  | ||||||
|  | class PreviewResultOdt : public PreviewResultPlainText | ||||||
|  | { | ||||||
|  | 	using PreviewResultPlainText::PreviewResultPlainText; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif // PREVIEWRESULTODT_H | ||||||
| @@ -234,3 +234,8 @@ QString Common::versionText() | |||||||
| 	QString tag = GIT_TAG; | 	QString tag = GIT_TAG; | ||||||
| 	return tag + " (" + commitid + ") built " + __DATE__ + " " + __TIME__; | 	return tag + " (" + commitid + ") built " + __DATE__ + " " + __TIME__; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | QString Common::userManualUrl() | ||||||
|  | { | ||||||
|  | 	return QString("https://github.com/quitesimpleorg/looqs/blob/%1/USAGE.md").arg(QString(GIT_COMMIT_ID)); | ||||||
|  | } | ||||||
|   | |||||||
| @@ -25,5 +25,6 @@ bool isTextFile(QFileInfo fileInfo); | |||||||
| bool isMountPath(QString path); | bool isMountPath(QString path); | ||||||
| bool noSandboxModeRequested(); | bool noSandboxModeRequested(); | ||||||
| QString versionText(); | QString versionText(); | ||||||
|  | QString userManualUrl(); | ||||||
| } // namespace Common | } // namespace Common | ||||||
| #endif | #endif | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user