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();
|
_filters.clear();
|
||||||
_filterNames.clear();
|
_filterNames.clear();
|
||||||
|
|
||||||
foreach (const QString &filter, filters) {
|
for_const (auto &filter, filters) {
|
||||||
GtkFileFilter *gtkFilter = Libs::gtk_file_filter_new();
|
GtkFileFilter *gtkFilter = Libs::gtk_file_filter_new();
|
||||||
const QString name = filter.left(filter.indexOf(QLatin1Char('(')));
|
auto name = filter;//.left(filter.indexOf(QLatin1Char('(')));
|
||||||
const QStringList extensions = cleanFilterList(filter);
|
auto extensions = cleanFilterList(filter);
|
||||||
|
|
||||||
Libs::gtk_file_filter_set_name(gtkFilter, name.isEmpty() ? extensions.join(QStringLiteral(", ")).toUtf8() : name.toUtf8());
|
Libs::gtk_file_filter_set_name(gtkFilter, name.isEmpty() ? extensions.join(QStringLiteral(", ")).toUtf8() : name.toUtf8());
|
||||||
foreach (const QString &ext, extensions)
|
for_const (auto &ext, extensions) {
|
||||||
Libs::gtk_file_filter_add_pattern(gtkFilter, ext.toUtf8());
|
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);
|
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);
|
&& (Libs::gdk_pixbuf_new_from_file != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString escapeNotificationHtml(QString text) {
|
QString escapeHtml(const QString &text) {
|
||||||
text = text.replace(QChar('<'), qstr("<"));
|
auto result = QString();
|
||||||
text = text.replace(QChar('>'), qstr(">"));
|
auto copyFrom = 0, textSize = text.size();
|
||||||
text = text.replace(QChar('&'), qstr("&"));
|
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;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +281,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString escapeNotificationText(const QString &text) const;
|
||||||
void showNextNotification();
|
void showNextNotification();
|
||||||
|
|
||||||
struct QueuedNotification {
|
struct QueuedNotification {
|
||||||
|
@ -327,10 +349,14 @@ bool Manager::Impl::init() {
|
||||||
return !_serverName.isEmpty();
|
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) {
|
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 titleText = escapeNotificationText(title);
|
||||||
auto subtitleText = escapeNotificationHtml(subtitle);
|
auto subtitleText = escapeNotificationText(subtitle);
|
||||||
auto msgText = escapeNotificationHtml(msg);
|
auto msgText = escapeNotificationText(msg);
|
||||||
if (_markupSupported && !subtitleText.isEmpty()) {
|
if (_markupSupported && !subtitleText.isEmpty()) {
|
||||||
subtitleText = qstr("<b>") + subtitleText + qstr("</b>");
|
subtitleText = qstr("<b>") + subtitleText + qstr("</b>");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue