diff --git a/Telegram/SourceFiles/_other/packer.cpp b/Telegram/SourceFiles/_other/packer.cpp index 716961025..714a2f9b9 100644 --- a/Telegram/SourceFiles/_other/packer.cpp +++ b/Telegram/SourceFiles/_other/packer.cpp @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) } for (QFileInfoList::iterator i = files.begin(); i != files.end(); ++i) { QFileInfo info(*i); - if (info.canonicalFilePath().indexOf(remove) != 0) { + if (!info.canonicalFilePath().startsWith(remove)) { cout << "Can't find '" << remove.toUtf8().constData() << "' in file '" << info.canonicalFilePath().toUtf8().constData() << "' :(\n"; return -1; } diff --git a/Telegram/SourceFiles/application.cpp b/Telegram/SourceFiles/application.cpp index 197b3f482..da9884c6a 100644 --- a/Telegram/SourceFiles/application.cpp +++ b/Telegram/SourceFiles/application.cpp @@ -623,11 +623,11 @@ void Application::readClients() { int32 from = 0, l = cmds.length(); for (int32 to = cmds.indexOf(QChar(';'), from); to >= from; to = (from < l) ? cmds.indexOf(QChar(';'), from) : -1) { QStringRef cmd(&cmds, from, to - from); - if (cmd.indexOf("CMD:") == 0) { + if (cmd.startsWith(qsl("CMD:"))) { execExternal(cmds.mid(from + 4, to - from - 4)); - QByteArray response(QString("RES:%1;").arg(QCoreApplication::applicationPid()).toUtf8()); + QByteArray response(qsl("RES:%1;").arg(QCoreApplication::applicationPid()).toUtf8()); i->first->write(response.data(), response.size()); - } else if (cmd.indexOf("SEND:") == 0) { + } else if (cmd.startsWith(qsl("SEND:"))) { if (cSendPaths().isEmpty()) { toSend.append(_escapeFrom7bit(cmds.mid(from + 5, to - from - 5))); } diff --git a/Telegram/SourceFiles/boxes/addparticipantbox.cpp b/Telegram/SourceFiles/boxes/addparticipantbox.cpp index d9db93b38..cd3d73706 100644 --- a/Telegram/SourceFiles/boxes/addparticipantbox.cpp +++ b/Telegram/SourceFiles/boxes/addparticipantbox.cpp @@ -343,7 +343,7 @@ void AddParticipantInner::updateFilter(QString filter) { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index 242903f11..a6ded1e79 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -285,7 +285,7 @@ void ContactsInner::updateFilter(QString filter) { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } diff --git a/Telegram/SourceFiles/boxes/newgroupbox.cpp b/Telegram/SourceFiles/boxes/newgroupbox.cpp index d93e3518c..72c68509c 100644 --- a/Telegram/SourceFiles/boxes/newgroupbox.cpp +++ b/Telegram/SourceFiles/boxes/newgroupbox.cpp @@ -307,7 +307,7 @@ void NewGroupInner::updateFilter(QString filter) { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 2a53c27d8..51efd8bbf 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -395,7 +395,7 @@ void DialogsListWidget::onFilterUpdate(QString newFilter, bool force) { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } @@ -415,7 +415,7 @@ void DialogsListWidget::onFilterUpdate(QString newFilter, bool force) { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } diff --git a/Telegram/SourceFiles/gui/countryinput.cpp b/Telegram/SourceFiles/gui/countryinput.cpp index 55870cc4a..92fb1afc3 100644 --- a/Telegram/SourceFiles/gui/countryinput.cpp +++ b/Telegram/SourceFiles/gui/countryinput.cpp @@ -273,7 +273,7 @@ void CountryList::resetList() { for (fi = fb; fi != fe; ++fi) { QString filterName(*fi); for (ni = nb; ni != ne; ++ni) { - if ((*ni).indexOf(*fi) == 0) { + if (ni->startsWith(*fi)) { break; } } diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 402d8ab7b..3d0d10e50 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -3003,7 +3003,7 @@ void HistoryWidget::keyPressEvent(QKeyEvent *e) { void HistoryWidget::onFieldTabbed() { QString v = _field.getText(), t = supportTemplate(v.trimmed()); if (!t.isEmpty()) { - bool isImg = (t.indexOf(qsl("img:")) == 0), isFile = (t.indexOf(qsl("file:")) == 0); + bool isImg = t.startsWith(qsl("img:")), isFile = t.startsWith(qsl("file:")); if (isImg || isFile) { QString fname = t.mid(isImg ? 4 : 5).trimmed(), text; int32 lineEnd = fname.indexOf(QChar('\n')); diff --git a/Telegram/SourceFiles/supporttl.cpp b/Telegram/SourceFiles/supporttl.cpp index f4d4891a0..42802739c 100644 --- a/Telegram/SourceFiles/supporttl.cpp +++ b/Telegram/SourceFiles/supporttl.cpp @@ -36,58 +36,72 @@ namespace { } void readSupportTemplates() { - QFile f(cWorkingDir() + qsl("support_tl.txt")); - if (!f.open(QIODevice::ReadOnly)) return; + QStringList files(cWorkingDir() + qsl("support_tl.txt")); + QDir supp(cWorkingDir() + qsl("tsupport")); + if (supp.exists()) { + QStringList all = supp.entryList(QDir::Files); + for (QStringList::const_iterator i = all.cbegin(), e = all.cend(); i != e; ++i) { + if (i->startsWith(qsl("tl_"))) { + files.push_back(cWorkingDir() + qsl("tsupport/") + *i); + } + } + } typedef QList TemplatesLines; - TemplatesLines lines = f.readAll().split('\n'); - - f.close(); - enum ReadingState { ReadingNone = 0, ReadingKeys = 1, ReadingValue = 2, ReadingMoreValue = 3, }; - ReadingState state = ReadingNone; - QStringList keys; - QString value; - for (TemplatesLines::const_iterator i = lines.cbegin(), e = lines.cend(); i != e; ++i) { - QString line = QString::fromUtf8(*i).trimmed(); - QRegularExpressionMatch m = QRegularExpression(qsl("^\\{([A-Z_]+)\\}$")).match(line); - if (m.hasMatch()) { - saveTemplate(keys, value); - QString token = m.captured(1); - if (token == qsl("KEYS")) { - keys.clear(); - state = ReadingKeys; - } else if (token == qsl("VALUE")) { - state = ReadingValue; - } else { - keys.clear(); - state = ReadingNone; + for (QStringList::const_iterator i = files.cbegin(), e = files.cend(); i != e; ++i) { + QFile f(*i); + if (!f.open(QIODevice::ReadOnly)) continue; + + TemplatesLines lines = f.readAll().split('\n'); + + f.close(); + + ReadingState state = ReadingNone; + QStringList keys; + QString value; + for (TemplatesLines::const_iterator i = lines.cbegin(), e = lines.cend(); i != e; ++i) { + QString line = QString::fromUtf8(*i).trimmed(); + QRegularExpressionMatch m = QRegularExpression(qsl("^\\{([A-Z_]+)\\}$")).match(line); + if (m.hasMatch()) { + saveTemplate(keys, value); + + QString token = m.captured(1); + if (token == qsl("KEYS")) { + keys.clear(); + state = ReadingKeys; + } else if (token == qsl("VALUE")) { + state = ReadingValue; + } else { + keys.clear(); + state = ReadingNone; + } + continue; } - continue; - } - switch (state) { - case ReadingKeys: - if (!line.isEmpty()) { - keys.push_back(line); + switch (state) { + case ReadingKeys: + if (!line.isEmpty()) { + keys.push_back(line); + } + break; + + case ReadingMoreValue: + value += '\n'; + case ReadingValue: + value += line; + state = ReadingMoreValue; + break; } - break; - - case ReadingMoreValue: - value += '\n'; - case ReadingValue: - value += line; - state = ReadingMoreValue; - break; } + saveTemplate(keys, value); } - saveTemplate(keys, value); } const QString &supportTemplate(const QString &key) {