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/>.
29 void init_moc(struct moc_s *moc)
37 moc->totaltime = NULL;
44 static void update_infos(struct moc_s *moc)
49 fp = popen("mocp -i", "r");
51 moc->state = strndup("Can't run 'mocp -i'", text_buffer_size);
59 /* Read a line from the pipe and strip the possible '\n'. */
60 if (!fgets(line, 100, fp))
62 if ((p = strrchr(line, '\n')))
66 if (strncmp(line, "State:", 6) == 0)
67 moc->state = strndup(line + 7, text_buffer_size);
68 else if (strncmp(line, "File:", 5) == 0)
69 moc->file = strndup(line + 6, text_buffer_size);
70 else if (strncmp(line, "Title:", 6) == 0)
71 moc->title = strndup(line + 7, text_buffer_size);
72 else if (strncmp(line, "Artist:", 7) == 0)
73 moc->artist = strndup(line + 8, text_buffer_size);
74 else if (strncmp(line, "SongTitle:", 10) == 0)
75 moc->song = strndup(line + 11, text_buffer_size);
76 else if (strncmp(line, "Album:", 6) == 0)
77 moc->album = strndup(line + 7, text_buffer_size);
78 else if (strncmp(line, "TotalTime:", 10) == 0)
79 moc->totaltime = strndup(line + 11, text_buffer_size);
80 else if (strncmp(line, "TimeLeft:", 9) == 0)
81 moc->timeleft = strndup(line + 10, text_buffer_size);
82 else if (strncmp(line, "CurrentTime:", 12) == 0)
83 moc->curtime = strndup(line + 13, text_buffer_size);
84 else if (strncmp(line, "Bitrate:", 8) == 0)
85 moc->bitrate = strndup(line + 9, text_buffer_size);
86 else if (strncmp(line, "Rate:", 5) == 0)
87 moc->rate = strndup(line + 6, text_buffer_size);
93 void *update_moc(void *arg)
98 CRIT_ERR("update_moc called with a null argument!");
101 moc = (struct moc_s *) arg;
104 timed_thread_lock(moc->timed_thread);
106 timed_thread_unlock(moc->timed_thread);
107 if (timed_thread_test(moc->timed_thread, 0)) {
108 timed_thread_exit(moc->timed_thread);
114 void free_moc(struct moc_s *moc)
122 free(moc->totaltime);