xaizek / mpdknotifier (License: GPLv2+) (since 2018-12-07)
A notification application that informs you about currently played song.
Commit fba6e05d1710ee1072453ce88d701245e03f9590

Added option "NoCoverImg".

Author: xaizek
Author date (UTC): 2011-04-10 14:19
Committer: xaizek
Commit date (UTC): 2011-04-10 14:19
Tree: 2f90fe6bd95354a818e3c8182405ad16f1e968c2
Parents: 6312982e057a1b0b5ce484e3c4a0295f2e8b7e5b
File Lines added Lines deleted
CMakeLists.txt 1 0
NEWS 3 0
README 4 0
TODO 0 2
nocover.jpg 0 0
src/main.cpp 1 1
src/notifier.cpp 33 15
src/notifier.h 3 0

File CMakeLists.txt changed (mode: 100644) (index 1cc4a90..c02551a)
... ... set(mpdknotifier_SRCS src/main.cpp src/notifier.cpp)
6 6 kde4_add_executable(mpdknotifier ${mpdknotifier_SRCS}) kde4_add_executable(mpdknotifier ${mpdknotifier_SRCS})
7 7 target_link_libraries(mpdknotifier ${KDE4_KDEUI_LIBS}) target_link_libraries(mpdknotifier ${KDE4_KDEUI_LIBS})
8 8 install(FILES mpdknotifier.notifyrc DESTINATION ${DATA_INSTALL_DIR}/mpdknotifier) install(FILES mpdknotifier.notifyrc DESTINATION ${DATA_INSTALL_DIR}/mpdknotifier)
9 install(FILES nocover.jpg DESTINATION ${DATA_INSTALL_DIR}/mpdknotifier)
9 10 install(TARGETS mpdknotifier ${INSTALL_TARGETS_DEFAULT_ARGS}) install(TARGETS mpdknotifier ${INSTALL_TARGETS_DEFAULT_ARGS})

File NEWS changed (mode: 100644) (index ddd9798..e974754)
1 v2.0.2:
2 - added option "NoCoverImg"
3
1 4 v2.0.1: v2.0.1:
2 5 - added debug mode, it can be enabled using '--debug' argument - added debug mode, it can be enabled using '--debug' argument
3 6

File README changed (mode: 100644) (index 2019888..ab9c17e)
... ... below:
46 46 9. PreferredCoverWidth 9. PreferredCoverWidth
47 47 10. PreferredCoverHeight 10. PreferredCoverHeight
48 48 11. ArtResizeCmd 11. ArtResizeCmd
49 12. NoCoverImg
49 50
50 51 Note: Note:
51 52 There is a default value for each option. So you can skip some of theme in your There is a default value for each option. So you can skip some of theme in your
 
... ... album art and to decide if we need to call ArtResizeCmd.
104 105 Contains command for resizing images bigger than PreferredCoverWidth x Contains command for resizing images bigger than PreferredCoverWidth x
105 106 PreferredCoverHeight. You can use all special sequences like in Commands option. PreferredCoverHeight. You can use all special sequences like in Commands option.
106 107
108 12) NoCoverImg [=/usr/share/apps/mpdknotifier/nocover.jpg]
109 Path to the image file, that would be used when no cover was found.
110
107 111 5. Album art search algorithm 5. Album art search algorithm
108 112
109 113 Firstly a search for any jpg, png or gif file in parent directory of current Firstly a search for any jpg, png or gif file in parent directory of current

File TODO changed (mode: 100644) (index 5f02f34..be61baf)
7 7
8 8 - tunable duration of notifications (it seems like this depends only from - tunable duration of notifications (it seems like this depends only from
9 9 notification daemon) notification daemon)
10
11 - ability to set an image file for albums without cover

File nocover.jpg added (mode: 100644) (index 0000000..0cd0217)

File src/main.cpp changed (mode: 100644) (index 823cba0..a7fe695)
... ... int main(int argc, char** argv)
33 33 KAboutData aboutData("mpdknotifier", KAboutData aboutData("mpdknotifier",
34 34 0, 0,
35 35 ki18n("MPD KDE Notifier"), ki18n("MPD KDE Notifier"),
36 "2.0.1",
36 "2.0.2",
37 37 ki18n("A notification application that informs you " ki18n("A notification application that informs you "
38 38 "about currently played song."), "about currently played song."),
39 39 KAboutData::KAboutData::License_GPL_V2); KAboutData::KAboutData::License_GPL_V2);

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);
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/mpdknotifier

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/mpdknotifier

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master