Mercurial > audlegacy
comparison src/audtool/audtool_handlers_test.c @ 3873:f3341c2d6b9e
audacious remote functions:
- playlist_ins_url_string() and playlist_enqueue_to_temp() have been implemented.
- now get_version() returns audacious version instead of protocol version.
audtool:
- now argc check works properly.
- some cleanups.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Tue, 30 Oct 2007 22:12:47 +0900 |
parents | e48f2f4c116d |
children | 86c9abc83fbd |
comparison
equal
deleted
inserted
replaced
3872:b02853ac8466 | 3873:f3341c2d6b9e |
---|---|
42 audacious_remote_activate(dbus_proxy); | 42 audacious_remote_activate(dbus_proxy); |
43 } | 43 } |
44 | 44 |
45 void test_enqueue_to_temp(gint argc, gchar **argv) | 45 void test_enqueue_to_temp(gint argc, gchar **argv) |
46 { | 46 { |
47 gint playpos; | |
48 | |
49 if (argc < 2) | 47 if (argc < 2) |
50 { | 48 { |
51 audtool_whine("invalid parameters for %s.", argv[0]); | 49 audtool_whine("invalid parameters for %s.", argv[0]); |
52 audtool_whine("syntax: %s <position>", argv[0]); | 50 audtool_whine("syntax: %s <url>", argv[0]); |
53 return; | 51 exit(1); |
54 } | 52 } |
55 | 53 |
56 playpos = atoi(argv[1]); | 54 audacious_remote_playlist_enqueue_to_temp(dbus_proxy, argv[1]); |
57 | |
58 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
59 { | |
60 audtool_whine("invalid playlist position %d", playpos); | |
61 return; | |
62 } | |
63 | |
64 audacious_remote_get_playqueue_queue_position(dbus_proxy, playpos - 1); // xxx playpos - 1? | |
65 } | 55 } |
66 | 56 |
67 void test_toggle_aot(gint argc, gchar **argv) | 57 void test_toggle_aot(gint argc, gchar **argv) |
68 { | 58 { |
69 gboolean ontop; | |
70 | |
71 if (argc < 2) | 59 if (argc < 2) |
72 { | 60 { |
73 audtool_whine("invalid parameters for %s.", argv[0]); | 61 audtool_whine("invalid parameters for %s.", argv[0]); |
74 audtool_whine("syntax: %s <boolean>", argv[0]); | 62 audtool_whine("syntax: %s <on/off>", argv[0]); |
75 return; | 63 exit(1); |
76 } | 64 } |
77 | 65 |
78 ontop = (gboolean)atoi(argv[1]); | 66 if (!g_ascii_strcasecmp(argv[1], "on")) { |
79 printf("ontop = %d\n", ontop); | 67 audacious_remote_toggle_aot(dbus_proxy, TRUE); |
80 audacious_remote_toggle_aot(dbus_proxy, ontop); | 68 return; |
69 } | |
70 else if (!g_ascii_strcasecmp(argv[1], "off")) { | |
71 audacious_remote_toggle_aot(dbus_proxy, FALSE); | |
72 return; | |
73 } | |
81 } | 74 } |
82 | 75 |
83 void test_get_skin(gint argc, gchar **argv) | 76 void test_get_skin(gint argc, gchar **argv) |
84 { | 77 { |
85 gchar *skin = NULL; | 78 gchar *skin = NULL; |
86 skin = audacious_remote_get_skin(dbus_proxy); | 79 skin = audacious_remote_get_skin(dbus_proxy); |
87 printf("skin = %s\n", skin); | 80 audtool_report("%s", skin); |
88 g_free(skin); | 81 g_free(skin); |
89 } | 82 } |
90 | 83 |
91 void test_set_skin(gint argc, gchar **argv) | 84 void test_set_skin(gint argc, gchar **argv) |
92 { | 85 { |
93 if (argc < 2) | 86 if (argc < 2) |
94 { | 87 { |
95 audtool_whine("invalid parameters for %s.", argv[0]); | 88 audtool_whine("invalid parameters for %s.", argv[0]); |
96 audtool_whine("syntax: %s <skin>", argv[0]); | 89 audtool_whine("syntax: %s <skin>", argv[0]); |
97 return; | 90 exit(1); |
98 } | 91 } |
99 printf("argc = %d\n", argc); | |
100 printf("skin = %p\n", argv[1]); | |
101 | |
102 | 92 |
103 if(!argv[1] || !strcmp(argv[1], "")) | 93 if(!argv[1] || !strcmp(argv[1], "")) |
104 return; | 94 return; |
105 | 95 |
106 audacious_remote_set_skin(dbus_proxy, argv[1]); | 96 audacious_remote_set_skin(dbus_proxy, argv[1]); |
109 void test_get_info(gint argc, gchar **argv) | 99 void test_get_info(gint argc, gchar **argv) |
110 { | 100 { |
111 gint rate, freq, nch; | 101 gint rate, freq, nch; |
112 | 102 |
113 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch); | 103 audacious_remote_get_info(dbus_proxy, &rate, &freq, &nch); |
114 printf("rate = %d freq = %d nch = %d\n", rate, freq, nch); | 104 audtool_report("rate = %d freq = %d nch = %d", rate, freq, nch); |
115 } | 105 } |
116 | 106 |
117 | 107 void test_ins_url_string(gint argc, gchar **argv) |
118 | |
119 | |
120 #if 0 | |
121 void playlist_reverse(gint argc, gchar **argv) | |
122 { | 108 { |
123 audacious_remote_playlist_prev(dbus_proxy); | 109 gint pos = -1; |
124 } | |
125 | |
126 void playlist_advance(gint argc, gchar **argv) | |
127 { | |
128 audacious_remote_playlist_next(dbus_proxy); | |
129 } | |
130 | |
131 void playlist_add_url_string(gint argc, gchar **argv) | |
132 { | |
133 if (argc < 2) | |
134 { | |
135 audtool_whine("invalid parameters for %s.", argv[0]); | |
136 audtool_whine("syntax: %s <url>", argv[0]); | |
137 return; | |
138 } | |
139 | |
140 audacious_remote_playlist_add_url_string(dbus_proxy, argv[1]); | |
141 } | |
142 | |
143 void playlist_delete(gint argc, gchar **argv) | |
144 { | |
145 gint playpos; | |
146 | |
147 if (argc < 2) | |
148 { | |
149 audtool_whine("invalid parameters for %s.", argv[0]); | |
150 audtool_whine("syntax: %s <position>", argv[0]); | |
151 return; | |
152 } | |
153 | |
154 playpos = atoi(argv[1]); | |
155 | |
156 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
157 { | |
158 audtool_whine("invalid playlist position %d", playpos); | |
159 return; | |
160 } | |
161 | |
162 audacious_remote_playlist_delete(dbus_proxy, playpos - 1); | |
163 } | |
164 | |
165 void playlist_length(gint argc, gchar **argv) | |
166 { | |
167 gint i; | |
168 | |
169 i = audacious_remote_get_playlist_length(dbus_proxy); | |
170 | |
171 audtool_report("%d", i); | |
172 } | |
173 | |
174 void playlist_song(gint argc, gchar **argv) | |
175 { | |
176 gint playpos; | |
177 gchar *song; | |
178 | |
179 if (argc < 2) | |
180 { | |
181 audtool_whine("invalid parameters for %s.", argv[0]); | |
182 audtool_whine("syntax: %s <position>", argv[0]); | |
183 return; | |
184 } | |
185 | |
186 playpos = atoi(argv[1]); | |
187 | |
188 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
189 { | |
190 audtool_whine("invalid playlist position %d", playpos); | |
191 return; | |
192 } | |
193 | |
194 song = audacious_remote_get_playlist_title(dbus_proxy, playpos - 1); | |
195 | |
196 audtool_report("%s", song); | |
197 } | |
198 | |
199 | |
200 void playlist_song_length(gint argc, gchar **argv) | |
201 { | |
202 gint playpos, frames, length; | |
203 | |
204 if (argc < 2) | |
205 { | |
206 audtool_whine("invalid parameters for %s.", argv[0]); | |
207 audtool_whine("syntax: %s <position>", argv[0]); | |
208 return; | |
209 } | |
210 | |
211 playpos = atoi(argv[1]); | |
212 | |
213 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
214 { | |
215 audtool_whine("invalid playlist position %d", playpos); | |
216 return; | |
217 } | |
218 | |
219 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
220 length = frames / 1000; | |
221 | |
222 audtool_report("%d:%.2d", length / 60, length % 60); | |
223 } | |
224 | |
225 void playlist_song_length_seconds(gint argc, gchar **argv) | |
226 { | |
227 gint playpos, frames, length; | |
228 | |
229 if (argc < 2) | |
230 { | |
231 audtool_whine("invalid parameters for %s.", argv[0]); | |
232 audtool_whine("syntax: %s <position>", argv[0]); | |
233 return; | |
234 } | |
235 | |
236 playpos = atoi(argv[1]); | |
237 | |
238 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
239 { | |
240 audtool_whine("invalid playlist position %d", playpos); | |
241 return; | |
242 } | |
243 | |
244 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
245 length = frames / 1000; | |
246 | |
247 audtool_report("%d", length); | |
248 } | |
249 | |
250 void playlist_song_length_frames(gint argc, gchar **argv) | |
251 { | |
252 gint playpos, frames; | |
253 | |
254 if (argc < 2) | |
255 { | |
256 audtool_whine("invalid parameters for %s.", argv[0]); | |
257 audtool_whine("syntax: %s <position>", argv[0]); | |
258 return; | |
259 } | |
260 | |
261 playpos = atoi(argv[1]); | |
262 | |
263 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) | |
264 { | |
265 audtool_whine("invalid playlist position %d", playpos); | |
266 return; | |
267 } | |
268 | |
269 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); | |
270 | |
271 audtool_report("%d", frames); | |
272 } | |
273 | |
274 void playlist_display(gint argc, gchar **argv) | |
275 { | |
276 gint i, ii, frames, length, total; | |
277 gchar *songname; | |
278 gchar *fmt = NULL, *p; | |
279 gint column; | |
280 | |
281 i = audacious_remote_get_playlist_length(dbus_proxy); | |
282 | |
283 audtool_report("%d track%s.", i, i != 1 ? "s" : ""); | |
284 | |
285 total = 0; | |
286 | |
287 for (ii = 0; ii < i; ii++) | |
288 { | |
289 songname = audacious_remote_get_playlist_title(dbus_proxy, ii); | |
290 frames = audacious_remote_get_playlist_time(dbus_proxy, ii); | |
291 length = frames / 1000; | |
292 total += length; | |
293 | |
294 /* adjust width for multi byte characters */ | |
295 column = 60; | |
296 if(songname){ | |
297 p = songname; | |
298 while(*p){ | |
299 gint stride; | |
300 stride = g_utf8_next_char(p) - p; | |
301 if(g_unichar_iswide(g_utf8_get_char(p)) | |
302 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) ) | |
303 || g_unichar_iswide_cjk(g_utf8_get_char(p)) | |
304 #endif | |
305 ){ | |
306 column += (stride - 2); | |
307 } | |
308 else { | |
309 column += (stride - 1); | |
310 } | |
311 p = g_utf8_next_char(p); | |
312 } | |
313 | |
314 } | |
315 | |
316 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d", column); | |
317 audtool_report(fmt, ii + 1, songname, length / 60, length % 60); | |
318 g_free(fmt); | |
319 } | |
320 | |
321 audtool_report("Total length: %d:%.2d", total / 60, total % 60); | |
322 } | |
323 | |
324 void playlist_position(gint argc, gchar **argv) | |
325 { | |
326 gint i; | |
327 | |
328 i = audacious_remote_get_playlist_pos(dbus_proxy); | |
329 | |
330 audtool_report("%d", i + 1); | |
331 } | |
332 | |
333 void playlist_song_filename(gint argc, gchar **argv) | |
334 { | |
335 gint i; | |
336 | |
337 if (argc < 2) | |
338 { | |
339 audtool_whine("invalid parameters for %s.", argv[0]); | |
340 audtool_whine("syntax: %s <position>", argv[0]); | |
341 return; | |
342 } | |
343 | |
344 i = atoi(argv[1]); | |
345 | |
346 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
347 { | |
348 audtool_whine("invalid playlist position %d", i); | |
349 return; | |
350 } | |
351 | |
352 audtool_report("%s", audacious_remote_get_playlist_file(dbus_proxy, i - 1)); | |
353 } | |
354 | |
355 void playlist_jump(gint argc, gchar **argv) | |
356 { | |
357 gint i; | |
358 | |
359 if (argc < 2) | |
360 { | |
361 audtool_whine("invalid parameters for %s.", argv[0]); | |
362 audtool_whine("syntax: %s <position>", argv[0]); | |
363 return; | |
364 } | |
365 | |
366 i = atoi(argv[1]); | |
367 | |
368 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
369 { | |
370 audtool_whine("invalid playlist position %d", i); | |
371 return; | |
372 } | |
373 | |
374 audacious_remote_set_playlist_pos(dbus_proxy, i - 1); | |
375 } | |
376 | |
377 void playlist_clear(gint argc, gchar **argv) | |
378 { | |
379 audacious_remote_playlist_clear(dbus_proxy); | |
380 } | |
381 | |
382 void playlist_repeat_status(gint argc, gchar **argv) | |
383 { | |
384 if (audacious_remote_is_repeat(dbus_proxy)) | |
385 { | |
386 audtool_report("on"); | |
387 return; | |
388 } | |
389 else | |
390 { | |
391 audtool_report("off"); | |
392 return; | |
393 } | |
394 } | |
395 | |
396 void playlist_repeat_toggle(gint argc, gchar **argv) | |
397 { | |
398 audacious_remote_toggle_repeat(dbus_proxy); | |
399 } | |
400 | |
401 void playlist_shuffle_status(gint argc, gchar **argv) | |
402 { | |
403 if (audacious_remote_is_shuffle(dbus_proxy)) | |
404 { | |
405 audtool_report("on"); | |
406 return; | |
407 } | |
408 else | |
409 { | |
410 audtool_report("off"); | |
411 return; | |
412 } | |
413 } | |
414 | |
415 void playlist_shuffle_toggle(gint argc, gchar **argv) | |
416 { | |
417 audacious_remote_toggle_shuffle(dbus_proxy); | |
418 } | |
419 | |
420 void playlist_tuple_field_data(gint argc, gchar **argv) | |
421 { | |
422 gint i; | |
423 gpointer data; | |
424 | 110 |
425 if (argc < 3) | 111 if (argc < 3) |
426 { | 112 { |
427 audtool_whine("invalid parameters for %s.", argv[0]); | 113 audtool_whine("invalid parameters for %s.", argv[0]); |
428 audtool_whine("syntax: %s <fieldname> <position>", argv[0]); | 114 audtool_whine("syntax: %s <url> <position>", argv[0]); |
429 audtool_whine(" - fieldname example choices: performer, album_name,"); | 115 exit(1); |
430 audtool_whine(" track_name, track_number, year, date, genre, comment,"); | |
431 audtool_whine(" file_name, file_ext, file_path, length, formatter,"); | |
432 audtool_whine(" custom, mtime"); | |
433 return; | |
434 } | 116 } |
435 | 117 |
436 i = atoi(argv[2]); | 118 pos = atoi(argv[2]) - 1; |
119 if(pos >= 0) | |
120 audacious_remote_playlist_ins_url_string(dbus_proxy, argv[1], pos); | |
121 } | |
437 | 122 |
438 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | 123 void test_get_version(gint argc, gchar **argv) |
439 { | 124 { |
440 audtool_whine("invalid playlist position %d", i); | 125 gchar *version = NULL; |
441 return; | 126 version = audacious_remote_get_version(dbus_proxy); |
442 } | 127 if(version) |
443 | 128 audtool_report("Audacious %s", version); |
444 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[1], i - 1))) | 129 g_free(version); |
445 { | |
446 return; | |
447 } | |
448 | |
449 if (!g_ascii_strcasecmp(argv[1], "track_number") || !g_ascii_strcasecmp(argv[1], "year") || !g_ascii_strcasecmp(argv[1], "length") || !g_ascii_strcasecmp(argv[1], "mtime")) | |
450 { | |
451 if (*(gint *)data > 0) | |
452 { | |
453 audtool_report("%d", *(gint *)data); | |
454 } | |
455 return; | |
456 } | |
457 | |
458 audtool_report("%s", (gchar *)data); | |
459 } | 130 } |
460 #endif |