Mercurial > audlegacy
comparison src/audtool/audtool_handlers_general.c @ 2929:b0ca7bddaec9 trunk
Split out playqueue functions.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 29 Jun 2007 08:17:02 -0500 |
parents | ede9a8b8deff |
children | fe27b67d8c37 |
comparison
equal
deleted
inserted
replaced
2928:ede9a8b8deff | 2929:b0ca7bddaec9 |
---|---|
34 #include <glib.h> | 34 #include <glib.h> |
35 #include <mowgli.h> | 35 #include <mowgli.h> |
36 #include <locale.h> | 36 #include <locale.h> |
37 #include "libaudclient/audctrl.h" | 37 #include "libaudclient/audctrl.h" |
38 #include "audtool.h" | 38 #include "audtool.h" |
39 | |
40 void playqueue_add(gint argc, gchar **argv) | |
41 { | |
42 gint i; | |
43 | |
44 if (argc < 2) | |
45 { | |
46 g_print("%s: invalid parameters for playqueue-add.\n", argv[0]); | |
47 g_print("%s: syntax: %s playqueue-add <position>\n", argv[0], argv[0]); | |
48 return; | |
49 } | |
50 | |
51 i = atoi(argv[1]); | |
52 | |
53 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
54 { | |
55 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
56 return; | |
57 } | |
58 | |
59 if (!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1))) | |
60 audacious_remote_playqueue_add(dbus_proxy, i - 1); | |
61 } | |
62 | |
63 void playqueue_remove(gint argc, gchar **argv) | |
64 { | |
65 gint i; | |
66 | |
67 if (argc < 2) | |
68 { | |
69 g_print("%s: invalid parameters for playqueue-remove.\n", argv[0]); | |
70 g_print("%s: syntax: %s playqueue-remove <position>\n", argv[0], argv[0]); | |
71 return; | |
72 } | |
73 | |
74 i = atoi(argv[1]); | |
75 | |
76 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
77 { | |
78 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
79 return; | |
80 } | |
81 | |
82 if (audacious_remote_playqueue_is_queued(dbus_proxy, i - 1)) | |
83 audacious_remote_playqueue_remove(dbus_proxy, i - 1); | |
84 } | |
85 | |
86 void playqueue_is_queued(gint argc, gchar **argv) | |
87 { | |
88 gint i; | |
89 | |
90 if (argc < 2) | |
91 { | |
92 g_print("%s: invalid parameters for playqueue-is-queued.\n", argv[0]); | |
93 g_print("%s: syntax: %s playqueue-is-queued <position>\n", argv[0], argv[0]); | |
94 return; | |
95 } | |
96 | |
97 i = atoi(argv[1]); | |
98 | |
99 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
100 { | |
101 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
102 return; | |
103 } | |
104 | |
105 exit(!(audacious_remote_playqueue_is_queued(dbus_proxy, i - 1))); | |
106 } | |
107 | |
108 void playqueue_get_position(gint argc, gchar **argv) | |
109 { | |
110 gint i, pos; | |
111 | |
112 if (argc < 2) | |
113 { | |
114 g_print("%s: invalid parameters for playqueue-get-position.\n", argv[0]); | |
115 g_print("%s: syntax: %s playqueue-get-position <position>\n", argv[0], argv[0]); | |
116 return; | |
117 } | |
118 | |
119 i = atoi(argv[1]); | |
120 | |
121 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) | |
122 { | |
123 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
124 return; | |
125 } | |
126 | |
127 pos = audacious_remote_get_playqueue_position(dbus_proxy, i - 1) + 1; | |
128 | |
129 if (pos < 1) | |
130 return; | |
131 | |
132 g_print("%d\n", pos); | |
133 } | |
134 | |
135 void playqueue_get_qposition(gint argc, gchar **argv) | |
136 { | |
137 gint i, pos; | |
138 | |
139 if (argc < 2) | |
140 { | |
141 g_print("%s: invalid parameters for playqueue-get-qposition.\n", argv[0]); | |
142 g_print("%s: syntax: %s playqueue-get-qposition <position>\n", argv[0], argv[0]); | |
143 return; | |
144 } | |
145 | |
146 i = atoi(argv[1]); | |
147 | |
148 if (i < 1 || i > audacious_remote_get_playqueue_length(dbus_proxy)) | |
149 { | |
150 g_print("%s: invalid playlist position %d\n", argv[0], i); | |
151 return; | |
152 } | |
153 | |
154 pos = audacious_remote_get_playqueue_queue_position(dbus_proxy, i - 1) + 1; | |
155 | |
156 if (pos < 1) | |
157 return; | |
158 | |
159 g_print("%d\n", pos); | |
160 } | |
161 | |
162 void playqueue_display(gint argc, gchar **argv) | |
163 { | |
164 gint i, ii, position, frames, length, total; | |
165 gchar *songname; | |
166 gchar *fmt = NULL, *p; | |
167 gint column; | |
168 | |
169 i = audacious_remote_get_playqueue_length(dbus_proxy); | |
170 | |
171 g_print("%d queued tracks.\n", i); | |
172 | |
173 total = 0; | |
174 | |
175 for (ii = 0; ii < i; ii++) | |
176 { | |
177 position = audacious_remote_get_playqueue_queue_position(dbus_proxy, ii); | |
178 songname = audacious_remote_get_playlist_title(dbus_proxy, position); | |
179 frames = audacious_remote_get_playlist_time(dbus_proxy, position); | |
180 length = frames / 1000; | |
181 total += length; | |
182 | |
183 /* adjust width for multi byte characters */ | |
184 column = 60; | |
185 if(songname) { | |
186 p = songname; | |
187 while(*p){ | |
188 gint stride; | |
189 stride = g_utf8_next_char(p) - p; | |
190 if(g_unichar_iswide(g_utf8_get_char(p)) | |
191 #if ( (GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 12) ) | |
192 || g_unichar_iswide_cjk(g_utf8_get_char(p)) | |
193 #endif | |
194 ){ | |
195 column += (stride - 2); | |
196 } | |
197 else { | |
198 column += (stride - 1); | |
199 } | |
200 p = g_utf8_next_char(p); | |
201 } | |
202 } | |
203 | |
204 fmt = g_strdup_printf("%%4d | %%4d | %%-%ds | %%d:%%.2d\n", column); | |
205 g_print(fmt, ii + 1, position + 1, songname, length / 60, length % 60); | |
206 g_free(fmt); | |
207 } | |
208 | |
209 g_print("Total length: %d:%.2d\n", total / 60, total % 60); | |
210 } | |
211 | |
212 void playqueue_length(gint argc, gchar **argv) | |
213 { | |
214 gint i; | |
215 | |
216 i = audacious_remote_get_playqueue_length(dbus_proxy); | |
217 | |
218 g_print("%d\n", i); | |
219 } | |
220 | |
221 void playqueue_clear(gint argc, gchar **argv) | |
222 { | |
223 audacious_remote_playqueue_clear(dbus_proxy); | |
224 } | |
225 | 39 |
226 void get_volume(gint argc, gchar **argv) | 40 void get_volume(gint argc, gchar **argv) |
227 { | 41 { |
228 gint i; | 42 gint i; |
229 | 43 |