mirror of https://github.com/procxx/kepka.git
Fixed html encoding in native linux notifications. #2532
Also use case-insensitive filters in GTK file chooser.
This commit is contained in:
parent
c773bffec6
commit
77df38b4fd
|
@ -476,14 +476,27 @@ void GtkFileDialog::setNameFilters(const QStringList &filters) {
|
|||
_filters.clear();
|
||||
_filterNames.clear();
|
||||
|
||||
foreach (const QString &filter, filters) {
|
||||
for_const (auto &filter, filters) {
|
||||
GtkFileFilter *gtkFilter = Libs::gtk_file_filter_new();
|
||||
const QString name = filter.left(filter.indexOf(QLatin1Char('(')));
|
||||
const QStringList extensions = cleanFilterList(filter);
|
||||
auto name = filter;//.left(filter.indexOf(QLatin1Char('(')));
|
||||
auto extensions = cleanFilterList(filter);
|
||||
|
||||
Libs::gtk_file_filter_set_name(gtkFilter, name.isEmpty() ? extensions.join(QStringLiteral(", ")).toUtf8() : name.toUtf8());
|
||||
foreach (const QString &ext, extensions)
|
||||
Libs::gtk_file_filter_add_pattern(gtkFilter, ext.toUtf8());
|
||||
for_const (auto &ext, extensions) {
|
||||
auto caseInsensitiveExt = QString();
|
||||
caseInsensitiveExt.reserve(4 * ext.size());
|
||||
for_const (auto ch, ext) {
|
||||
auto chLower = ch.toLower();
|
||||
auto chUpper = ch.toUpper();
|
||||
if (chLower != chUpper) {
|
||||
caseInsensitiveExt.append('[').append(chLower).append(chUpper).append(']');
|
||||
} else {
|
||||
caseInsensitiveExt.append(ch);
|
||||
}
|
||||
}
|
||||
|
||||
Libs::gtk_file_filter_add_pattern(gtkFilter, caseInsensitiveExt.toUtf8());
|
||||
}
|
||||
|
||||
Libs::gtk_file_chooser_add_filter(Libs::gtk_file_chooser_cast(gtkDialog), gtkFilter);
|
||||
|
||||
|
|
|
@ -71,10 +71,31 @@ bool LibNotifyLoaded() {
|
|||
&& (Libs::gdk_pixbuf_new_from_file != nullptr);
|
||||
}
|
||||
|
||||
QString escapeNotificationHtml(QString text) {
|
||||
text = text.replace(QChar('<'), qstr("<"));
|
||||
text = text.replace(QChar('>'), qstr(">"));
|
||||
text = text.replace(QChar('&'), qstr("&"));
|
||||
QString escapeHtml(const QString &text) {
|
||||
auto result = QString();
|
||||
auto copyFrom = 0, textSize = text.size();
|
||||
auto data = text.constData();
|
||||
for (auto i = 0; i != textSize; ++i) {
|
||||
auto ch = data[i];
|
||||
if (ch == '<' || ch == '>' || ch == '&') {
|
||||
if (!copyFrom) {
|
||||
result.reserve(textSize * 5);
|
||||
}
|
||||
if (i > copyFrom) {
|
||||
result.append(data + copyFrom, i - copyFrom);
|
||||
}
|
||||
switch (ch.unicode()) {
|
||||
case '<': result.append(qstr("<")); break;
|
||||
case '>': result.append(qstr(">")); break;
|
||||
case '&': result.append(qstr("&")); break;
|
||||
}
|
||||
copyFrom = i + 1;
|
||||
}
|
||||
}
|
||||
if (copyFrom > 0) {
|
||||
result.append(data + copyFrom, textSize - copyFrom);
|
||||
return result;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
@ -260,6 +281,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
QString escapeNotificationText(const QString &text) const;
|
||||
void showNextNotification();
|
||||
|
||||
struct QueuedNotification {
|
||||
|
@ -327,10 +349,14 @@ bool Manager::Impl::init() {
|
|||
return !_serverName.isEmpty();
|
||||
}
|
||||
|
||||
QString Manager::Impl::escapeNotificationText(const QString &text) const {
|
||||
return _markupSupported ? escapeHtml(text) : text;
|
||||
}
|
||||
|
||||
void Manager::Impl::showNotification(PeerData *peer, MsgId msgId, const QString &title, const QString &subtitle, const QString &msg, bool hideNameAndPhoto, bool hideReplyButton) {
|
||||
auto titleText = escapeNotificationHtml(title);
|
||||
auto subtitleText = escapeNotificationHtml(subtitle);
|
||||
auto msgText = escapeNotificationHtml(msg);
|
||||
auto titleText = escapeNotificationText(title);
|
||||
auto subtitleText = escapeNotificationText(subtitle);
|
||||
auto msgText = escapeNotificationText(msg);
|
||||
if (_markupSupported && !subtitleText.isEmpty()) {
|
||||
subtitleText = qstr("<b>") + subtitleText + qstr("</b>");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue