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
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
if [ ! -e "libs" ]; then mkdir libs; fi
if [ ! -e "ffmpeg" ]; then mkdir ffmpeg; fi

View File

@ -33,6 +33,8 @@
#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,
const QColor c)
: rawText(rwText)
@ -450,7 +452,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
cursor.endEditBlock();
QTextCharFormat format;
format.setBackground(QBrush(colorHighlight));
format.setBackground(QBrush(QColor(COLOR_HIGHLIGHT)));
cursor.mergeCharFormat(format);
regenerate();

View File

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

View File

@ -29,13 +29,6 @@
#include <QMetaObject>
#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

View File

@ -14,10 +14,13 @@
#include <functional>
#include <memory>
struct sqlite3;
struct sqlite3_stmt;
struct sqlite3_context;
struct sqlite3_value;
/// 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 : 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)
{
QList<QDateTime> counts;
auto rowCallback = [&counts](const QVector<QVariant>& row) {
counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong()));
QDateTime result;
auto rowCallback = [&result](const QVector<QVariant>& row) {
result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong());
};
phrase.replace("'", "''");
@ -389,11 +389,8 @@ QDateTime History::getDateWhereFindPhrase(const QString& friendPk, const QDateTi
.arg(period);
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)
{
QList<QDateTime> counts;
auto rowCallback = [&counts](const QVector<QVariant>& row) {
counts.append(QDateTime::fromMSecsSinceEpoch(row[0].toLongLong()));
QDateTime result;
auto rowCallback = [&result](const QVector<QVariant>& row) {
result = QDateTime::fromMSecsSinceEpoch(row[0].toLongLong());
};
QString queryText =
@ -418,11 +415,7 @@ QDateTime History::getStartDateChatHistory(const QString &friendPk)
db->execNow({queryText, rowCallback});
if (!counts.isEmpty()) {
return counts[0];
}
return QDateTime();
return result;
}
/**

View File

@ -540,7 +540,7 @@ void GenericChatForm::addSystemDateMessage()
QDate GenericChatForm::getDate(const ChatLine::Ptr &chatLine) const
{
if (chatLine) {
Timestamp* timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2));
Timestamp* const timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2));
if (timestamp) {
return timestamp->getTime().date();
@ -589,20 +589,26 @@ bool GenericChatForm::searchInText(const QString& phrase, const ParameterSearch&
if (parameter.period == PeriodSearch::WithTheFirst) {
startLine = 0;
} else if (parameter.period == PeriodSearch::AfterDate) {
for (int i = 0; i < lines.size(); ++i) {
auto d = getDate(lines[i]);
if (d.isValid() && parameter.date <= d) {
startLine = i;
break;
}
auto lambda = [=](const ChatLine::Ptr& item) {
auto d = getDate(item);
return d.isValid() && parameter.date <= d;
};
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) {
for (int i = lines.size() - 1; i >= 0; --i) {
auto d = getDate(lines[i]);
if (d.isValid() && parameter.date >= d) {
startLine = i;
break;
}
auto lambda = [=](const ChatLine::Ptr& item) {
auto d = getDate(item);
return d.isValid() && parameter.date >= d;
};
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) {
QString filter = QRegularExpression::escape(phrase);
QString symbols = {"\\[]/^$.|?*+(){}"};
const QString symbols = QStringLiteral("\\[]/^$.|?*+(){}");
if (filter != phrase) {
if (filter.left(1) != QLatin1String("\\")) {
filter = "\\b" + filter;
filter = QLatin1String("\\b") + filter;
} else {
filter = "(^|\\s)" + filter;
filter = QLatin1String("(^|\\s)") + filter;
}
if (!symbols.contains(filter.right(1))) {
filter += "\\b";
filter += QLatin1String("\\b");
} else {
filter += "($|\\s)";
filter += QLatin1String("($|\\s)");
}
} else {
filter = QStringLiteral("\\b%1\\b").arg(filter);