Commit 109dfe13 authored by Laurent Montel's avatar Laurent Montel 😁

Use .toStdString() + const'ify variables

parent 7c317f3e
Pipeline #36007 passed with stage
in 20 minutes and 37 seconds
......@@ -54,8 +54,8 @@ void AkonotesIndexer::index(const Akonadi::Item &item)
process(msg);
Akonadi::Collection::Id colId = item.parentCollection().id();
QByteArray term = 'C' + QByteArray::number(colId);
const Akonadi::Collection::Id colId = item.parentCollection().id();
const QByteArray term = 'C' + QByteArray::number(colId);
m_doc->add_boolean_term(term.data());
m_db->replace_document(item.id(), *m_doc);
......@@ -74,7 +74,7 @@ void AkonotesIndexer::process(const KMime::Message::Ptr &msg)
// (Give the subject a higher priority)
KMime::Headers::Subject *subject = msg->subject(false);
if (subject) {
std::string str(subject->asUnicodeString().toUtf8().constData());
const std::string str(subject->asUnicodeString().toStdString());
qCDebug(AKONADI_INDEXER_AGENT_LOG) << "Indexing" << str.c_str();
m_termGen->index_text_without_positions(str, 1, "SU");
m_termGen->index_text_without_positions(str, 100);
......@@ -83,7 +83,7 @@ void AkonotesIndexer::process(const KMime::Message::Ptr &msg)
KMime::Content *mainBody = msg->mainBodyPart("text/plain");
if (mainBody) {
const std::string text(mainBody->decodedText().toUtf8().constData());
const std::string text(mainBody->decodedText().toStdString());
m_termGen->index_text_without_positions(text);
m_termGen->index_text_without_positions(text, 1, "BO");
} else {
......@@ -115,7 +115,7 @@ void AkonotesIndexer::processPart(KMime::Content *content, KMime::Content *mainC
QTextDocument doc;
doc.setHtml(content->decodedText());
const std::string text(doc.toPlainText().toUtf8().constData());
const std::string text(doc.toPlainText().toStdString());
m_termGen->index_text_without_positions(text);
}
}
......@@ -153,7 +153,7 @@ void AkonotesIndexer::remove(const Akonadi::Collection &collection)
return;
}
try {
Xapian::Query query('C' + QString::number(collection.id()).toStdString());
const Xapian::Query query('C' + QString::number(collection.id()).toStdString());
Xapian::Enquire enquire(*m_db);
enquire.set_query(query);
......
......@@ -87,7 +87,7 @@ void CalendarIndexer::remove(const Akonadi::Collection &collection)
return;
}
try {
Xapian::Query query('C' + QString::number(collection.id()).toStdString());
const Xapian::Query query('C' + QString::number(collection.id()).toStdString());
Xapian::Enquire enquire(*(m_db->db()));
enquire.set_query(query);
......@@ -129,7 +129,7 @@ void CalendarIndexer::indexEventItem(const Akonadi::Item &item, const KCalendarC
doc.indexText(event->organizer().email(), QStringLiteral("O"));
doc.indexText(event->summary(), QStringLiteral("S"));
doc.indexText(event->location(), QStringLiteral("L"));
KCalendarCore::Attendee::List attendees = event->attendees();
const KCalendarCore::Attendee::List attendees = event->attendees();
KCalendarCore::Attendee::List::ConstIterator it;
KCalendarCore::Attendee::List::ConstIterator end(attendees.constEnd());
for (it = attendees.constBegin(); it != end; ++it) {
......
......@@ -63,8 +63,8 @@ void CollectionIndexer::index(const Akonadi::Collection &collection)
gen.set_document(doc);
gen.set_database(*m_db);
gen.index_text_without_positions(collection.displayName().toUtf8().constData());
gen.index_text_without_positions(collection.displayName().toUtf8().constData(), 1, "N");
gen.index_text_without_positions(collection.displayName().toStdString());
gen.index_text_without_positions(collection.displayName().toStdString(), 1, "N");
//We index with positions so we can do phrase searches (required for exact matches)
{
......@@ -74,7 +74,7 @@ void CollectionIndexer::index(const Akonadi::Collection &collection)
doc.add_term(term.constData());
}
Akonadi::Collection::Id colId = collection.parentCollection().id();
const Akonadi::Collection::Id colId = collection.parentCollection().id();
const QByteArray term = 'C' + QByteArray::number(colId);
doc.add_boolean_term(term.constData());
......
......@@ -30,7 +30,7 @@ private Q_SLOTS:
private:
bool shouldIndex(const Akonadi::Collection &col) const;
Akonadi::Collection mCol;
const Akonadi::Collection mCol;
Index &mIndex;
};
......
......@@ -103,7 +103,7 @@ void EmailIndexer::index(const Akonadi::Item &item)
void EmailIndexer::insert(const QByteArray &key, KMime::Headers::Base *unstructured)
{
if (unstructured) {
m_termGen->index_text_without_positions(unstructured->asUnicodeString().toUtf8().constData(), 1, key.data());
m_termGen->index_text_without_positions(unstructured->asUnicodeString().toStdString(), 1, key.data());
}
}
......@@ -141,7 +141,7 @@ void EmailIndexer::insert(const QByteArray &key, const KMime::Types::Mailbox::Li
return;
}
for (const KMime::Types::Mailbox &mbox : list) {
std::string name(mbox.name().toUtf8().constData());
std::string name(mbox.name().toStdString());
m_termGen->index_text_without_positions(name, 1, key.data());
m_termGen->index_text_without_positions(name, 1);
m_termGen->index_text_without_positions(mbox.address().data(), 1, key.data());
......@@ -160,7 +160,7 @@ void EmailIndexer::insert(const QByteArray &key, const KMime::Types::Mailbox::Li
continue;
} catch (const Xapian::DocNotFoundError &) {
Xapian::Document doc;
std::string pretty(pa.toUtf8().constData());
std::string pretty(pa.toStdString());
doc.set_data(pretty);
Xapian::TermGenerator termGen;
......@@ -181,7 +181,7 @@ void EmailIndexer::process(const KMime::Message::Ptr &msg)
// (Give the subject a higher priority)
KMime::Headers::Subject *subject = msg->subject(false);
if (subject) {
std::string str(subject->asUnicodeString().toUtf8().constData());
std::string str(subject->asUnicodeString().toStdString());
qCDebug(AKONADI_INDEXER_AGENT_LOG) << "Indexing" << str.c_str();
m_termGen->index_text_without_positions(str, 1, "SU");
m_termGen->index_text_without_positions(str, 100);
......@@ -217,7 +217,7 @@ void EmailIndexer::process(const KMime::Message::Ptr &msg)
KMime::Content *mainBody = msg->mainBodyPart("text/plain");
if (mainBody) {
const std::string text(mainBody->decodedText().toUtf8().constData());
const std::string text(mainBody->decodedText().toStdString());
m_termGen->index_text_without_positions(text);
m_termGen->index_text_without_positions(text, 1, "BO");
} else {
......@@ -248,7 +248,7 @@ void EmailIndexer::processPart(KMime::Content *content, KMime::Content *mainCont
QTextDocument doc;
doc.setHtml(content->decodedText());
const std::string text(doc.toPlainText().toUtf8().constData());
const std::string text(doc.toPlainText().toStdString());
m_termGen->index_text_without_positions(text);
}
}
......
......@@ -95,7 +95,7 @@ ResultIterator CollectionQuery::exec()
parser.set_database(db);
parser.add_prefix("", "N");
parser.set_default_op(Xapian::Query::OP_AND);
queries << parser.parse_query(d->nameString.toUtf8().constData(),
queries << parser.parse_query(d->nameString.toStdString(),
Xapian::QueryParser::FLAG_PARTIAL);
}
......@@ -104,7 +104,7 @@ ResultIterator CollectionQuery::exec()
parser.set_database(db);
parser.add_prefix("", "I");
parser.set_default_op(Xapian::Query::OP_AND);
queries << parser.parse_query(d->identifierString.toUtf8().constData(),
queries << parser.parse_query(d->identifierString.toStdString(),
Xapian::QueryParser::FLAG_PARTIAL);
}
......@@ -113,7 +113,7 @@ ResultIterator CollectionQuery::exec()
parser.set_database(db);
parser.add_prefix("", "P");
parser.set_default_op(Xapian::Query::OP_AND);
queries << parser.parse_query(d->pathString.toUtf8().constData(),
queries << parser.parse_query(d->pathString.toStdString(),
Xapian::QueryParser::FLAG_PARTIAL | Xapian::QueryParser::FLAG_PHRASE);
}
......
......@@ -22,11 +22,11 @@ class AKONADI_SEARCH_PIM_EXPORT ContactCompleter
public:
explicit ContactCompleter(const QString &prefix, int limit = 10);
QStringList complete();
Q_REQUIRED_RESULT QStringList complete();
private:
QString m_prefix;
int m_limit;
const QString m_prefix;
const int m_limit;
};
}
}
......
......@@ -22,7 +22,7 @@ PIMContactsRunnerConfig::PIMContactsRunnerConfig(QWidget *parent, const QVariant
{
QVBoxLayout *vbox = new QVBoxLayout(this);
mQueryCompletionCheckBox = new QCheckBox(i18n("Search in contacts indexed from sent and received emails too"));
mQueryCompletionCheckBox = new QCheckBox(i18n("Search in contacts indexed from sent and received emails too"), this);
connect(mQueryCompletionCheckBox, &QCheckBox::stateChanged,
this, &PIMContactsRunnerConfig::configChanged);
......
......@@ -17,27 +17,27 @@ using namespace Akonadi::Search;
AgePostingSource::AgePostingSource(Xapian::valueno slot_)
: Xapian::ValuePostingSource(slot_)
, m_currentTime_t(QDateTime::currentDateTimeUtc().toSecsSinceEpoch())
{
m_currentTime_t = QDateTime::currentDateTimeUtc().toSecsSinceEpoch();
}
Xapian::weight AgePostingSource::get_weight() const
{
std::string s = *value_it;
QString str = QString::fromUtf8(s.c_str(), s.length());
const std::string s = *value_it;
const QString str = QString::fromUtf8(s.c_str(), s.length());
bool ok = false;
uint time = str.toUInt(&ok);
const uint time = str.toUInt(&ok);
if (!ok) {
return 0.0;
}
uint diff = m_currentTime_t - time;
const uint diff = m_currentTime_t - time;
// Each day is given a penalty of penalty of 1.0
double penalty = 1.0 / (24 * 60 * 60);
double result = 1000.0 - (diff * penalty);
const double penalty = 1.0 / (24 * 60 * 60);
const double result = 1000.0 - (diff * penalty);
if (result < 0.0) {
return 0.0;
......
......@@ -29,7 +29,7 @@ public:
void init(const Xapian::Database &db_) override;
private:
unsigned int m_currentTime_t;
const unsigned int m_currentTime_t;
};
}
}
......
......@@ -92,7 +92,7 @@ QString EmailSearchStore::text(int queryId)
// Nothing to do, move along
}
QString subject = QString::fromUtf8(data.c_str(), data.length());
const QString subject = QString::fromUtf8(data.c_str(), data.length());
if (subject.isEmpty()) {
return QStringLiteral("No Subject");
}
......
......@@ -90,7 +90,7 @@ Xapian::Query PIMSearchStore::constructQuery(const QString &property, const QVar
if (m_boolWithValue.contains(prop)) {
std::string term(m_prefix.value(prop).toStdString());
std::string val(value.toString().toUtf8().constData());
std::string val(value.toString().toStdString());
return Xapian::Query(term + val);
}
......@@ -117,7 +117,7 @@ Xapian::Query PIMSearchStore::constructQuery(const QString &property, const QVar
parser.set_database(*xapianDb());
std::string p = m_prefix.value(prop).toStdString();
std::string str(value.toString().toUtf8().constData());
std::string str(value.toString().toStdString());
int flags = Xapian::QueryParser::FLAG_DEFAULT;
if (com == Term::Contains) {
flags |= Xapian::QueryParser::FLAG_PARTIAL;
......
......@@ -56,7 +56,7 @@ Xapian::Document XapianDocument::doc() const
void XapianDocument::addValue(int pos, const QString &value)
{
m_doc.add_value(pos, value.toUtf8().constData());
m_doc.add_value(pos, value.toStdString());
}
QString XapianDocument::fetchTermStartsWith(const QByteArray &term)
......
......@@ -37,8 +37,8 @@ struct Term {
Xapian::Query makeQuery(const QString &string, int position, Xapian::Database *db)
{
if (!db) {
QByteArray arr = string.toUtf8();
std::string stdString(arr.constData(), arr.size());
const QByteArray arr = string.toUtf8();
const std::string stdString(arr.constData(), arr.size());
return Xapian::Query(stdString, 1, position);
}
......@@ -47,7 +47,7 @@ Xapian::Query makeQuery(const QString &string, int position, Xapian::Database *d
QList<Term> topTerms;
topTerms.reserve(MaxTerms + 1);
const std::string stdString(string.toUtf8().constData());
const std::string stdString(string.toStdString());
Xapian::TermIterator it = db->allterms_begin(stdString);
Xapian::TermIterator end = db->allterms_end(stdString);
for (; it != end; ++it) {
......@@ -76,7 +76,7 @@ Xapian::Query makeQuery(const QString &string, int position, Xapian::Database *d
}
if (queries.isEmpty()) {
return Xapian::Query(string.toUtf8().constData(), 1, position);
return Xapian::Query(string.toStdString(), 1, position);
}
Xapian::Query finalQ(Xapian::Query::OP_SYNONYM, queries.begin(), queries.end());
return finalQ;
......@@ -105,7 +105,7 @@ Xapian::Query XapianQueryParser::parseQuery(const QString &text, const QString &
int flags = Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_PARTIAL;
std::string stdString(text.toUtf8().constData());
std::string stdString(text.toStdString());
return parser.parse_query(stdString, flags);
*/
......@@ -198,7 +198,7 @@ Xapian::Query XapianQueryParser::parseQuery(const QString &text, const QString &
if (m_autoExpand) {
queries << makeQuery(term, position, m_db);
} else {
queries << Xapian::Query(term.toUtf8().constData(), 1, position);
queries << Xapian::Query(term.toStdString(), 1, position);
}
}
}
......
......@@ -81,10 +81,10 @@ void XapianTermGenerator::indexText(const QString &text, const QString &prefix,
const QStringList terms = termList(text);
for (const QString &term : terms) {
QByteArray arr = term.toUtf8();
const QByteArray arr = term.toUtf8();
QByteArray finalArr = par + arr;
std::string stdString(finalArr.constData(), finalArr.size());
const QByteArray finalArr = par + arr;
const std::string stdString(finalArr.constData(), finalArr.size());
m_doc->add_posting(stdString, m_position, wdfInc);
m_position++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment