File src/notifier.cpp changed (mode: 100644) (index 1be436b..6799eb1) |
... |
... |
Notifier::Notifier() : QObject() |
53 |
53 |
m_commands = generalGroup.readEntry("Commands", "terminal -x ncmpcpp") |
m_commands = generalGroup.readEntry("Commands", "terminal -x ncmpcpp") |
54 |
54 |
.split(';'); |
.split(';'); |
55 |
55 |
|
|
|
56 |
|
m_noCoverImg = generalGroup.readEntry("NoCoverImg", |
|
57 |
|
"/usr/share/apps/mpdknotifier/nocover.jpg"); |
56 |
58 |
m_artFindCmd = generalGroup.readEntry("ArtFindCmd", ""); |
m_artFindCmd = generalGroup.readEntry("ArtFindCmd", ""); |
57 |
59 |
m_artResizeCmd = generalGroup.readEntry("ArtResizeCmd", ""); |
m_artResizeCmd = generalGroup.readEntry("ArtResizeCmd", ""); |
58 |
60 |
m_preferredWidth = generalGroup.readEntry("PreferredCoverWidth", "200") |
m_preferredWidth = generalGroup.readEntry("PreferredCoverWidth", "200") |
|
... |
... |
void Notifier::showSongInfo(const QStringList& _songInfo) |
156 |
158 |
aart = findAlbumArt(file); |
aart = findAlbumArt(file); |
157 |
159 |
if (aart == "" && m_artFindCmd != "") { |
if (aart == "" && m_artFindCmd != "") { |
158 |
160 |
debug("aart: '" + aart + "'"); |
debug("aart: '" + aart + "'"); |
159 |
|
debug("advanced search for albim art"); |
|
|
161 |
|
debug("advanced search for album art"); |
160 |
162 |
system(substInCmd(m_artFindCmd).toLatin1()); |
system(substInCmd(m_artFindCmd).toLatin1()); |
161 |
163 |
aart = findAlbumArt(file); |
aart = findAlbumArt(file); |
162 |
164 |
} |
} |
|
... |
... |
void Notifier::popup(const QString& _text, QString _imageFilename) |
182 |
184 |
debug("previous pop-up art: '" + m_lastImgFile + "'"); |
debug("previous pop-up art: '" + m_lastImgFile + "'"); |
183 |
185 |
if (_imageFilename != "" && _imageFilename != m_lastImgFile) { |
if (_imageFilename != "" && _imageFilename != m_lastImgFile) { |
184 |
186 |
debug("try to load album art"); |
debug("try to load album art"); |
185 |
|
// TODO: someday figure out where is bug in Qt QPixmapCache with |
|
186 |
|
// generating key for implicit caching |
|
187 |
|
// TODO: maybe add an option to clear cache |
|
188 |
|
//QPixmapCache::clear(); |
|
189 |
|
if (!m_pmap.load(_imageFilename, "JPG") |
|
190 |
|
&& !m_pmap.load(_imageFilename, "PNG") |
|
191 |
|
&& !m_pmap.load(_imageFilename, "GIF")) { |
|
192 |
|
_imageFilename = ""; |
|
193 |
|
debug("album art load failed"); |
|
194 |
|
logEvent(tr("Album art file is not JPG, PNG or GIF.")); |
|
195 |
|
} else { |
|
196 |
|
if (shouldImageBeScaled(m_pmap)) { |
|
197 |
|
m_pmap = m_pmap.scaled(m_preferredWidth, m_preferredHeight); |
|
198 |
|
} |
|
|
187 |
|
if (loadImg(_imageFilename, m_pmap)) { |
199 |
188 |
m_lastImgFile = _imageFilename; |
m_lastImgFile = _imageFilename; |
|
189 |
|
} else { |
|
190 |
|
_imageFilename = ""; |
200 |
191 |
} |
} |
201 |
192 |
} |
} |
202 |
193 |
|
|
|
... |
... |
void Notifier::popup(const QString& _text, QString _imageFilename) |
205 |
196 |
m_notification->setText(_text); |
m_notification->setText(_text); |
206 |
197 |
if (_imageFilename != "") { |
if (_imageFilename != "") { |
207 |
198 |
m_notification->setPixmap(m_pmap); |
m_notification->setPixmap(m_pmap); |
|
199 |
|
} else if (m_noCoverImg != "") { |
|
200 |
|
if (m_noCoverPixmap.isNull()) { |
|
201 |
|
debug("loading no cover art"); |
|
202 |
|
loadImg(m_noCoverImg, m_noCoverPixmap); |
|
203 |
|
} |
|
204 |
|
debug("using no cover art"); |
|
205 |
|
m_notification->setPixmap(m_noCoverPixmap); |
208 |
206 |
} |
} |
209 |
207 |
|
|
210 |
208 |
connect(m_notification, SIGNAL(activated(unsigned int)), |
connect(m_notification, SIGNAL(activated(unsigned int)), |
|
... |
... |
void Notifier::displayError(QAbstractSocket::SocketError _socketError) |
259 |
257 |
} |
} |
260 |
258 |
} |
} |
261 |
259 |
|
|
|
260 |
|
bool Notifier::loadImg(const QString& _file, QPixmap& _pixmap) |
|
261 |
|
{ |
|
262 |
|
debug(QString("try to load image \"%1\"").arg(_file)); |
|
263 |
|
if (!_pixmap.load(_file, "JPG") |
|
264 |
|
&& !_pixmap.load(_file, "PNG") |
|
265 |
|
&& !_pixmap.load(_file, "GIF")) { |
|
266 |
|
// TODO: someday figure out where is bug in Qt QPixmapCache with |
|
267 |
|
// generating key for implicit caching |
|
268 |
|
// TODO: maybe add an option to clear cache |
|
269 |
|
//QPixmapCache::clear(); |
|
270 |
|
debug("image load failed"); |
|
271 |
|
logEvent(tr("Image file is not JPG, PNG or GIF.")); |
|
272 |
|
return (false); |
|
273 |
|
} |
|
274 |
|
if (shouldImageBeScaled(_pixmap)) { |
|
275 |
|
_pixmap = _pixmap.scaled(m_preferredWidth, m_preferredHeight); |
|
276 |
|
} |
|
277 |
|
return (true); |
|
278 |
|
} |
|
279 |
|
|
262 |
280 |
QString Notifier::applyFormat(QString _frmt, const QStringList& _l) |
QString Notifier::applyFormat(QString _frmt, const QStringList& _l) |
263 |
281 |
{ |
{ |
264 |
282 |
int i = _frmt.lastIndexOf("%"); |
int i = _frmt.lastIndexOf("%"); |
File src/notifier.h changed (mode: 100644) (index 1b5a283..ee850bb) |
... |
... |
private: |
50 |
50 |
QTcpSocket m_soc; |
QTcpSocket m_soc; |
51 |
51 |
bool m_shownPopup; |
bool m_shownPopup; |
52 |
52 |
QPixmap m_pmap; |
QPixmap m_pmap; |
|
53 |
|
QPixmap m_noCoverPixmap; |
53 |
54 |
QString m_lastImgFile; |
QString m_lastImgFile; |
54 |
55 |
// preferences |
// preferences |
55 |
56 |
QString m_musicDir; |
QString m_musicDir; |
56 |
57 |
QString m_format; |
QString m_format; |
57 |
58 |
QStringList m_commandsNames; |
QStringList m_commandsNames; |
58 |
59 |
QStringList m_commands; |
QStringList m_commands; |
|
60 |
|
QString m_noCoverImg; |
59 |
61 |
QString m_artFindCmd; |
QString m_artFindCmd; |
60 |
62 |
QString m_artResizeCmd; |
QString m_artResizeCmd; |
61 |
63 |
int m_preferredWidth, m_preferredHeight; |
int m_preferredWidth, m_preferredHeight; |
|
... |
... |
private: |
68 |
70 |
|
|
69 |
71 |
void showSongInfo(const QStringList& _songInfo); |
void showSongInfo(const QStringList& _songInfo); |
70 |
72 |
void initLogging(const QString& _logFile); |
void initLogging(const QString& _logFile); |
|
73 |
|
bool loadImg(const QString& _file, QPixmap& _pixmap); |
71 |
74 |
QString applyFormat(QString _frmt, const QStringList& _l); |
QString applyFormat(QString _frmt, const QStringList& _l); |
72 |
75 |
QString findAlbumArt(const QString& _dirpath); |
QString findAlbumArt(const QString& _dirpath); |
73 |
76 |
bool shouldImageBeScaled(const QPixmap& _image); |
bool shouldImageBeScaled(const QPixmap& _image); |