1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: delete sqlite in travis, edit some functions

This commit is contained in:
TriKriSta 2018-07-14 00:06:04 +03:00
parent 42f5ac67e7
commit 706822123f
8 changed files with 42 additions and 55 deletions

View File

@ -52,15 +52,6 @@ sudo apt-get install -y --force-yes \
# Qt # Qt
source /opt/qt55/bin/qt55-env.sh || yes source /opt/qt55/bin/qt55-env.sh || yes
# sqlite
wget https://sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
tar xvfz sqlite-autoconf-3240000.tar.gz
cd sqlite-autoconf-3240000
./configure
make -j$(nproc)
sudo make install
cd ..
# ffmpeg # ffmpeg
if [ ! -e "libs" ]; then mkdir libs; fi if [ ! -e "libs" ]; then mkdir libs; fi
if [ ! -e "ffmpeg" ]; then mkdir ffmpeg; fi if [ ! -e "ffmpeg" ]; then mkdir ffmpeg; fi

View File

@ -33,6 +33,8 @@
#include "src/widget/style.h" #include "src/widget/style.h"
static const QString COLOR_HIGHLIGHT = QStringLiteral("#ff7626");
Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText, Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText,
const QColor c) const QColor c)
: rawText(rwText) : rawText(rwText)
@ -450,7 +452,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
cursor.endEditBlock(); cursor.endEditBlock();
QTextCharFormat format; QTextCharFormat format;
format.setBackground(QBrush(colorHighlight)); format.setBackground(QBrush(QColor(COLOR_HIGHLIGHT)));
cursor.mergeCharFormat(format); cursor.mergeCharFormat(format);
regenerate(); regenerate();

View File

@ -97,7 +97,6 @@ private:
QFont defFont; QFont defFont;
QString defStyleSheet; QString defStyleSheet;
QColor color; QColor color;
const QColor colorHighlight{"#ff7626"};
}; };
#endif // TEXT_H #endif // TEXT_H

View File

@ -29,13 +29,6 @@
#include <QMetaObject> #include <QMetaObject>
#include <QMutexLocker> #include <QMutexLocker>
/// The two following defines are required to use SQLCipher
/// They are used by the sqlite3.h header
#define SQLITE_HAS_CODEC
#define SQLITE_TEMP_STORE 2
#include <sqlite3.h>
/** /**
* @class RawDatabase * @class RawDatabase

View File

@ -14,10 +14,13 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
struct sqlite3; /// The two following defines are required to use SQLCipher
struct sqlite3_stmt; /// They are used by the sqlite3.h header
struct sqlite3_context; #define SQLITE_HAS_CODEC
struct sqlite3_value; #define SQLITE_TEMP_STORE 2
#include <sqlite3.h>
class RawDatabase : QObject class RawDatabase : QObject
{ {

View File

@ -325,9 +325,9 @@ QList<History::DateMessages> History::getChatHistoryCounts(const ToxPk& friendPk
*/ */
QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, QString phrase, const ParameterSearch& parameter) QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTime& from, QString phrase, const ParameterSearch& parameter)
{ {
QList<QDateTime> counts; QDateTime result;
auto rowCallback = [&counts](const QVector<QVariant>& row) { auto rowCallback = [&result](const QVector<QVariant>& row) {
counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong())); result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong());
}; };
phrase.replace("'", "''"); phrase.replace("'", "''");
@ -389,11 +389,8 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
.arg(period); .arg(period);
db->execNow({queryText, rowCallback}); db->execNow({queryText, rowCallback});
if (!counts.isEmpty()) {
return counts[0];
}
return QDateTime(); return result;
} }
/** /**
@ -403,9 +400,9 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
*/ */
QDateTime History::getStartDateChatHistory(const QString &friendPk) QDateTime History::getStartDateChatHistory(const QString &friendPk)
{ {
QList<QDateTime> counts; QDateTime result;
auto rowCallback = [&counts](const QVector<QVariant>& row) { auto rowCallback = [&result](const QVector<QVariant>& row) {
counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong())); result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong());
}; };
QString queryText = QString queryText =
@ -418,11 +415,7 @@ QDateTime History::getStartDateChatHistory(const QString &friendPk)
db->execNow({queryText, rowCallback}); db->execNow({queryText, rowCallback});
if (!counts.isEmpty()) { return result;
return counts[0];
}
return QDateTime();
} }
/** /**

View File

@ -540,7 +540,7 @@ void GenericChatForm::addSystemDateMessage()
QDate GenericChatForm::getDate(const ChatLine::Ptr &chatLine) const QDate GenericChatForm::getDate(const ChatLine::Ptr &chatLine) const
{ {
if (chatLine) { if (chatLine) {
Timestamp* timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2)); Timestamp* const timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2));
if (timestamp) { if (timestamp) {
return timestamp->getTime().date(); return timestamp->getTime().date();
@ -589,20 +589,26 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch&
if (parameter.period == PeriodSearch::WithTheFirst) { if (parameter.period == PeriodSearch::WithTheFirst) {
startLine = 0; startLine = 0;
} else if (parameter.period == PeriodSearch::AfterDate) { } else if (parameter.period == PeriodSearch::AfterDate) {
for (int i = 0; i < lines.size(); ++i) { auto lambda = [=](const ChatLine::Ptr& item) {
auto d = getDate(lines[i]); auto d = getDate(item);
if (d.isValid() && parameter.date <= d) { return d.isValid() && parameter.date <= d;
startLine = i; };
break;
} auto find = std::find_if(lines.begin(), lines.end(), lambda);
if (find != lines.end()) {
startLine = static_cast<int>(std::distance(lines.begin(), find));
} }
} else if (parameter.period == PeriodSearch::BeforeDate) { } else if (parameter.period == PeriodSearch::BeforeDate) {
for (int i = lines.size() - 1; i >= 0; --i) { auto lambda = [=](const ChatLine::Ptr& item) {
auto d = getDate(lines[i]); auto d = getDate(item);
if (d.isValid() && parameter.date >= d) { return d.isValid() && parameter.date >= d;
startLine = i; };
break;
} auto find = std::find_if(lines.rbegin(), lines.rend(), lambda);
if (find != lines.rend()) {
startLine = static_cast<int>(std::distance(find, lines.rend())) - 1;
} }
} }

View File

@ -49,18 +49,18 @@ public:
static QString generateFilterWordsOnly(const QString &phrase) { static QString generateFilterWordsOnly(const QString &phrase) {
QString filter = QRegularExpression::escape(phrase); QString filter = QRegularExpression::escape(phrase);
QString symbols = {"\\[]/^$.|?*+(){}"}; const QString symbols = QStringLiteral("\\[]/^$.|?*+(){}");
if (filter != phrase) { if (filter != phrase) {
if (filter.left(1) != QLatin1String("\\")) { if (filter.left(1) != QLatin1String("\\")) {
filter = "\\b" + filter; filter = QLatin1String("\\b") + filter;
} else { } else {
filter = "(^|\\s)" + filter; filter = QLatin1String("(^|\\s)") + filter;
} }
if (!symbols.contains(filter.right(1))) { if (!symbols.contains(filter.right(1))) {
filter += "\\b"; filter += QLatin1String("\\b");
} else { } else {
filter += "($|\\s)"; filter += QLatin1String("($|\\s)");
} }
} else { } else {
filter = QStringLiteral("\\b%1\\b").arg(filter); filter = QStringLiteral("\\b%1\\b").arg(filter);