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

Add support of password protected MPD servers
Closes #1
Author: xaizek
Author date (UTC): 2012-04-11 06:09
Committer name: xaizek
Committer date (UTC): 2012-04-11 06:14
Parent(s): 09e7fd759d9f240389da9d0732179e4ef25e581a
Signing key:
Tree: 499b87cfc3d1eb915e5e727af4fde8095ba42f2b
File Lines added Lines deleted
NEWS 3 0
README 2 1
TODO 5 1
src/notifier.cpp 28 2
src/notifier.h 4 0
File NEWS changed (mode: 100644) (index 10a2ecd..a163005)
1 v2.0.4:
2 - added support of connecting to password protected MPD servers
3
1 4 v2.0.3: v2.0.3:
2 5 - substitute ampersand with & - substitute ampersand with &
3 6
File README changed (mode: 100644) (index ab9c17e..6ebdbaa)
... ... symbol. Here is full format of each entry:
56 56 Description. Description.
57 57
58 58 1) MPDHost [=localhost] 1) MPDHost [=localhost]
59 Sets IP address or DNS name of MPD server host.
59 Sets IP address or DNS name of MPD server host and host password in the
60 following format: [password@]host, where password is optional.
60 61
61 62 2) MPDPort [=6600] 2) MPDPort [=6600]
62 63 Sets number of port to connect to MPD server. Sets number of port to connect to MPD server.
File TODO changed (mode: 100644) (index be61baf..3d6995e)
1 1 - perhaps search for album art using custom patterns with format arguments - perhaps search for album art using custom patterns with format arguments
2 2
3 3 - perhaps search for album art in subdirectories (named like 'covers' or - perhaps search for album art in subdirectories (named like 'covers' or
4 similair)
4 similar)
5 5
6 6 - perhaps add an option to pop-up a message after stopping playback - perhaps add an option to pop-up a message after stopping playback
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 - refactor code and break it into several classes
12
13 - rewrite README file using markdown
File src/notifier.cpp changed (mode: 100644) (index 1bfc75f..a153877)
... ... Notifier::Notifier() : QObject()
37 37 { {
38 38 KConfig config("mpdknotifierrc"); KConfig config("mpdknotifierrc");
39 39 KConfigGroup generalGroup(&config, "General"); KConfigGroup generalGroup(&config, "General");
40 QString mpdHost = generalGroup.readEntry("MPDHost", "localhost");
40 QString mpdHostString = generalGroup.readEntry("MPDHost", "localhost");
41 QString mpdHost;
42 parseHostString(mpdHostString, mpdHost, m_password);
41 43 QString mpdPort = generalGroup.readEntry("MPDPort", "6600"); QString mpdPort = generalGroup.readEntry("MPDPort", "6600");
42 44
43 45 m_musicDir = generalGroup.readEntry("MusicDir", "/mnt/music/"); m_musicDir = generalGroup.readEntry("MusicDir", "/mnt/music/");
 
... ... void Notifier::slotNewData()
109 111 if (response.startsWith("OK")) { if (response.startsWith("OK")) {
110 112 debug("'OK' response"); debug("'OK' response");
111 113 // ask for notification on any changes in 'player' subsystem // ask for notification on any changes in 'player' subsystem
112 m_soc.write(QByteArray("idle player\n"));
114 if (!m_password.isEmpty()) {
115 m_soc.write(QString("password %1\n").arg(m_password).toLocal8Bit());
116 clearPassword(m_password);
117 } else {
118 m_soc.write(QByteArray("idle player\n"));
119 }
113 120 } else if (response.startsWith("changed")) { } else if (response.startsWith("changed")) {
114 121 // there are some changes in subsystem // there are some changes in subsystem
115 122 debug("'changed' response"); debug("'changed' response");
 
... ... void Notifier::slotNewData()
136 143 debug("currentsong response"); debug("currentsong response");
137 144 showSongInfo(response.split("\n")); showSongInfo(response.split("\n"));
138 145 m_soc.write(QByteArray("idle player\n")); m_soc.write(QByteArray("idle player\n"));
146 } else if (response.startsWith("ACK")) {
147 debug("'ACK' response: " + response);
148 m_soc.write(QByteArray("idle player\n"));
149 } else {
150 debug("unknown response: " + response);
139 151 } }
140 152 } }
141 153
154 void Notifier::clearPassword(QString& _password) const
155 {
156 _password.replace(0, m_password.length(), static_cast<QChar>('\0'));
157 _password.clear();
158 }
159
160 void Notifier::parseHostString(const QString& _hostString, QString& _host,
161 QString& _password) const
162 {
163 int atIndex = _hostString.indexOf('@');
164 _host = _hostString.mid(atIndex + 1);
165 _password = (atIndex >= 0) ? _hostString.left(atIndex) : "";
166 }
167
142 168 void Notifier::showSongInfo(const QStringList& _songInfo) void Notifier::showSongInfo(const QStringList& _songInfo)
143 169 { {
144 170 QString file, aart; QString file, aart;
File src/notifier.h changed (mode: 100644) (index ee850bb..9680fcc)
... ... private slots:
45 45 void displayError(QAbstractSocket::SocketError _socketError); void displayError(QAbstractSocket::SocketError _socketError);
46 46
47 47 private: private:
48 QString m_password;
48 49 // some state variables // some state variables
49 50 KNotification* m_notification; KNotification* m_notification;
50 51 QTcpSocket m_soc; QTcpSocket m_soc;
 
... ... private:
68 69 QString m_lastArt; QString m_lastArt;
69 70 QString m_lastArtFilename; QString m_lastArtFilename;
70 71
72 void clearPassword(QString& _password) const;
73 void parseHostString(const QString& _hostString, QString& _host,
74 QString& _password) const;
71 75 void showSongInfo(const QStringList& _songInfo); void showSongInfo(const QStringList& _songInfo);
72 76 void initLogging(const QString& _logFile); void initLogging(const QString& _logFile);
73 77 bool loadImg(const QString& _file, QPixmap& _pixmap); bool loadImg(const QString& _file, QPixmap& _pixmap);
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