1 /* MOC Conky integration
3 * Please see COPYING for details
5 * Copyright (c) 2008, Henri Häkkinen
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 void init_moc(struct moc_s *moc)
36 moc->totaltime = NULL;
43 static void update_infos(struct moc_s *moc)
48 fp = popen("mocp -i", "r");
50 moc->state = strndup("Can't run 'mocp -i'", text_buffer_size);
58 /* Read a line from the pipe and strip the possible '\n'. */
59 if (!fgets(line, 100, fp))
61 if ((p = strrchr(line, '\n')))
65 if (strncmp(line, "State:", 6) == 0)
66 moc->state = strndup(line + 7, text_buffer_size);
67 else if (strncmp(line, "File:", 5) == 0)
68 moc->file = strndup(line + 6, text_buffer_size);
69 else if (strncmp(line, "Title:", 6) == 0)
70 moc->title = strndup(line + 7, text_buffer_size);
71 else if (strncmp(line, "Artist:", 7) == 0)
72 moc->artist = strndup(line + 8, text_buffer_size);
73 else if (strncmp(line, "SongTitle:", 10) == 0)
74 moc->song = strndup(line + 11, text_buffer_size);
75 else if (strncmp(line, "Album:", 6) == 0)
76 moc->album = strndup(line + 7, text_buffer_size);
77 else if (strncmp(line, "TotalTime:", 10) == 0)
78 moc->totaltime = strndup(line + 11, text_buffer_size);
79 else if (strncmp(line, "TimeLeft:", 9) == 0)
80 moc->timeleft = strndup(line + 10, text_buffer_size);
81 else if (strncmp(line, "CurrentTime:", 12) == 0)
82 moc->curtime = strndup(line + 13, text_buffer_size);
83 else if (strncmp(line, "Bitrate:", 8) == 0)
84 moc->bitrate = strndup(line + 9, text_buffer_size);
85 else if (strncmp(line, "Rate:", 5) == 0)
86 moc->rate = strndup(line + 6, text_buffer_size);
92 void *update_moc(void *arg)
97 CRIT_ERR("update_moc called with a null argument!");
100 moc = (struct moc_s *) arg;
103 timed_thread_lock(moc->timed_thread);
105 timed_thread_unlock(moc->timed_thread);
106 if (timed_thread_test(moc->timed_thread)) {
107 timed_thread_exit(moc->timed_thread);
113 void free_moc(struct moc_s *moc)
121 free(moc->totaltime);