Compare commits

..

No commits in common. "43a0f085796d78ffa10c74e6858a99747e78e0b8" and "4ce14a7284f7c0e1a436518a44c7390564223a38" have entirely different histories.

13 changed files with 56 additions and 173 deletions

View File

@ -36,11 +36,9 @@ 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 \
@ -56,11 +54,9 @@ 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 \
@ -70,7 +66,6 @@ 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

View File

@ -33,6 +33,28 @@ 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());
@ -69,8 +91,6 @@ 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()
@ -171,9 +191,6 @@ 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)
{ {
@ -193,26 +210,6 @@ 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()
@ -439,46 +436,19 @@ 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);
QVBoxLayout *previewLayout = new QVBoxLayout(); connect(label, &ClickLabel::leftClick, [this, docPath, previewPage]() { openDocument(docPath, previewPage); });
connect(label, &ClickLabel::rightClick,
QFont font = label->font(); [this, docPath, previewPage]()
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", menu.addAction("Copy page number", [previewPage]
[previewPage] { QGuiApplication::clipboard()->setText(QString::number(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);
} }
} }
@ -597,13 +567,6 @@ 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())
@ -615,6 +578,8 @@ 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})+))#");
@ -643,10 +608,9 @@ void MainWindow::makePreviews(int page)
begin = 0; begin = 0;
} }
int currentScale = currentSelectedScale();
RenderConfig renderConfig; RenderConfig renderConfig;
renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (currentScale / 100.); renderConfig.scaleX = QGuiApplication::primaryScreen()->physicalDotsPerInchX() * (scaleText.toInt() / 100.);
renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (currentScale / 100.); renderConfig.scaleY = QGuiApplication::primaryScreen()->physicalDotsPerInchY() * (scaleText.toInt() / 100.);
renderConfig.wordsToHighlight = wordsToHighlight; renderConfig.wordsToHighlight = wordsToHighlight;
QVector<RenderTarget> targets; QVector<RenderTarget> targets;

View File

@ -62,7 +62,6 @@ 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);

View File

@ -626,7 +626,6 @@
<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"/>
@ -648,11 +647,6 @@
<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/>

View File

@ -2,15 +2,13 @@
#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)
{ {

View File

@ -1,32 +0,0 @@
#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);
}

View File

@ -1,12 +0,0 @@
#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

View File

@ -3,15 +3,24 @@
#include "previewgeneratorplaintext.h" #include "previewgeneratorplaintext.h"
#include "previewresultplaintext.h" #include "previewresultplaintext.h"
QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderConfig config, QString fileName) QSharedPointer<PreviewResult> PreviewGeneratorPlainText::generate(RenderConfig config, QString documentPath,
unsigned int page)
{ {
QString resulText = ""; 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 content = in.readAll();
QMap<int, QString> snippet; QMap<int, QString> snippet;
int coveredRange = -1; int coveredRange = 0;
int lastWordPos = -1;
int lastWordPos = 0;
QHash<QString, int> countmap; QHash<QString, int> countmap;
const unsigned int maxSnippets = 7; const unsigned int maxSnippets = 7;
@ -62,7 +71,9 @@ QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderCo
resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive); resulText.replace(word, "<span style=\"background-color: yellow;\">" + word + "</span>", Qt::CaseInsensitive);
} }
QString header = "<b>" + fileName + "</b> "; QFileInfo info{documentPath};
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]) + " ";
@ -74,22 +85,6 @@ QString PreviewGeneratorPlainText::generatePreviewText(QString content, RenderCo
header += "<hr>"; header += "<hr>";
return header + resulText.replace("\n", "<br>").mid(0, 1000); result->setText(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);
} }

View File

@ -6,7 +6,6 @@ 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);
}; };

View File

@ -1 +0,0 @@
#include "previewresultodt.h"

View File

@ -1,10 +0,0 @@
#ifndef PREVIEWRESULTODT_H
#define PREVIEWRESULTODT_H
#include "previewresultplaintext.h"
class PreviewResultOdt : public PreviewResultPlainText
{
using PreviewResultPlainText::PreviewResultPlainText;
};
#endif // PREVIEWRESULTODT_H

View File

@ -234,8 +234,3 @@ 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));
}

View File

@ -25,6 +25,5 @@ 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