Show only a basic tooltip in the system tray

For environments that implements the D-Bus
http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem
specification HTML is not supported in the tool tip title. (It is
supported in the tool tip subtitle but this field is not set by
QSystemTrayIcon.)

See the discussion in #6733 for more info.
This commit is contained in:
Mattias Andersson 2020-07-08 17:28:26 +02:00 committed by John Maguire
parent 7d28e8700b
commit ebf9ebf080
4 changed files with 0 additions and 84 deletions

View File

@ -282,7 +282,6 @@
<file>mainwindow.css</file>
<file>nocover.png</file>
<file>nomusic.png</file>
<file>now_playing_tooltip.txt</file>
<file>nyancat.png</file>
<file>oauthsuccess.html</file>
<file>osd_background.png</file>

View File

@ -1,41 +0,0 @@
<table cellspacing="5" cellpadding="5">
<tr>
<td colspan="%columns">
<center><h4>%appName</h4></center>
</td>
</tr>
<tr>
%image
<td>
<table cellspacing="1" cellpadding="1">
<tr>
<td>
<p align="right">%titleKey</p>
</td>
<td>%titleValue</td>
</tr>
<tr>
<td>
<p align="right">%artistKey</p>
</td>
<td>%artistValue</td>
</tr>
<tr>
<td>
<p align="right">%albumKey</p>
</td>
<td>%albumValue</td>
</tr>
<tr>
<td colspan="2" height="20" />
</tr>
<tr>
<td>
<p align="right">%lengthKey</p>
</td>
<td>%lengthValue</td>
</tr>
</table>
</td>
</tr>
</table>

View File

@ -56,10 +56,6 @@ QtSystemTrayIcon::QtSystemTrayIcon(QObject* parent)
tray_->installEventFilter(this);
ClearNowPlaying();
QFile pattern_file(":/now_playing_tooltip.txt");
pattern_file.open(QIODevice::ReadOnly);
pattern_ = QString::fromLatin1(pattern_file.readAll());
connect(tray_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
SLOT(Clicked(QSystemTrayIcon::ActivationReason)));
}
@ -231,44 +227,8 @@ void QtSystemTrayIcon::SetVisible(bool visible) { tray_->setVisible(visible); }
void QtSystemTrayIcon::SetNowPlaying(const Song& song,
const QString& image_path) {
#ifdef Q_OS_WIN
// Windows doesn't support HTML in tooltips, so just show something basic
tray_->setToolTip(song.PrettyTitleWithArtist());
return;
#endif
int columns = image_path == nullptr ? 1 : 2;
QString clone = pattern_;
clone.replace("%columns", QString::number(columns));
clone.replace("%appName", QCoreApplication::applicationName());
clone.replace("%titleKey", tr("Title") % ":");
clone.replace("%titleValue", song.PrettyTitle().toHtmlEscaped());
clone.replace("%artistKey", tr("Artist") % ":");
clone.replace("%artistValue", song.artist().toHtmlEscaped());
clone.replace("%albumKey", tr("Album") % ":");
clone.replace("%albumValue", song.album().toHtmlEscaped());
clone.replace("%lengthKey", tr("Length") % ":");
clone.replace("%lengthValue", song.PrettyLength().toHtmlEscaped());
if (columns == 2) {
QString final_path =
image_path.startsWith("file://") ? image_path.mid(7) : image_path;
clone.replace("%image",
" <td>"
" <img src=\"" %
final_path %
"\" />"
" </td>");
} else {
clone.replace("%image", "");
}
// TODO: we should also repaint this
tray_->setToolTip(clone);
}
void QtSystemTrayIcon::ClearNowPlaying() {

View File

@ -66,8 +66,6 @@ class QtSystemTrayIcon : public SystemTrayIcon {
QAction* action_mute_;
QAction* action_love_;
QString pattern_;
QPixmap orange_icon_;
QPixmap grey_icon_;
};