00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include "stdinc.h"
00032
00033 #include "audio_file.h"
00034 #include "audio_output.h"
00035 #include "gui.h"
00036 #include "gui_internal.h"
00037 #include "gui_vfslist.h"
00038 #include "playq.h"
00039 #include "vfs.h"
00040
00045 static GString *str_time;
00049 static const char *str_status = NULL;
00054 static GString *str_song;
00058 static WINDOW *win_statbar;
00062 static struct gui_vfslist *win_playq;
00063
00068 static void
00069 gui_playq_statbar_song(struct audio_file *fd)
00070 {
00071 char *artist, *title;
00072
00073 if (fd == NULL) {
00074 g_string_assign(str_song, "");
00075 } else {
00076
00077 g_assert(fd->title != NULL);
00078 title = g_convert_with_fallback(fd->title,
00079 -1, "", "UTF-8", "?", NULL, NULL, NULL);
00080 if (title == NULL)
00081
00082 title = g_strdup(fd->title);
00083
00084 if (fd->artist == NULL) {
00085
00086 g_string_assign(str_song, title);
00087 } else {
00088
00089 artist = g_convert_with_fallback(fd->artist,
00090 -1, "", "UTF-8", "?", NULL, NULL, NULL);
00091 if (artist == NULL)
00092
00093 artist = g_strdup(fd->artist);
00094 g_string_printf(str_song, "%s - %s",
00095 artist, title);
00096 g_free(artist);
00097 }
00098 g_free(title);
00099 }
00100 }
00101
00105 static void
00106 gui_playq_statbar_status(struct audio_file *fd, int paused)
00107 {
00108 if (fd == NULL) {
00109 str_status = _("Idle");
00110 } else {
00111 if (paused)
00112 str_status = _("Paused");
00113 else
00114 str_status = _("Playing");
00115 }
00116 }
00117
00122 static void
00123 gui_playq_statbar_time_calc(GString *str, unsigned int time)
00124 {
00125 if (time < 3600)
00126
00127 g_string_append_printf(str, "%u:%02u",
00128 time / 60, time % 60);
00129 else
00130
00131 g_string_append_printf(str, "%u:%02u:%02u",
00132 time / 3600, (time / 60) % 60, time % 60);
00133 }
00134
00140 static void
00141 gui_playq_statbar_time(struct audio_file *fd)
00142 {
00143 if (fd == NULL) {
00144 g_string_assign(str_time, "");
00145 } else {
00146 g_string_assign(str_time, " [");
00147 gui_playq_statbar_time_calc(str_time, fd->time_cur);
00148 if (!fd->stream) {
00149 g_string_append_c(str_time, '/');
00150 gui_playq_statbar_time_calc(str_time, fd->time_len);
00151 }
00152 g_string_append_c(str_time, ']');
00153 }
00154 }
00155
00159 static void
00160 gui_playq_song_set(struct audio_file *fd, int paused, int timeonly)
00161 {
00162 gui_lock();
00163 if (!timeonly)
00164 gui_playq_statbar_song(fd);
00165 gui_playq_statbar_time(fd);
00166 gui_playq_statbar_status(fd, paused);
00167 gui_unlock();
00168 }
00169
00175 static void
00176 gui_playq_statbar_refresh(void)
00177 {
00178 const char *percent;
00179 int plen;
00180
00181 gui_lock();
00182
00183 werase(win_statbar);
00184
00185
00186 mvwaddstr(win_statbar, 0, 1, str_status);
00187 waddstr(win_statbar, " | ");
00188 waddstr(win_statbar, str_song->str);
00189
00190 percent = gui_vfslist_getpercentage(win_playq);
00191 plen = strlen(percent);
00192 mvwaddstr(win_statbar, 0, COLS - str_time->len - plen, str_time->str);
00193 waddstr(win_statbar, percent);
00194
00195
00196 wnoutrefresh(win_statbar);
00197 gui_unlock();
00198 }
00199
00200 void
00201 gui_playq_init(void)
00202 {
00203 win_statbar = newwin(1, 0, 0, 0);
00204 clearok(win_statbar, TRUE);
00205 if (gui_draw_colors)
00206 wbkgdset(win_statbar, COLOR_PAIR(GUI_COLOR_BAR));
00207 else
00208 wbkgdset(win_statbar, A_REVERSE);
00209
00210 str_time = g_string_sized_new(24);
00211 str_song = g_string_sized_new(128);
00212
00213 gui_playq_song_set(NULL, 0, 0);
00214
00215 win_playq = gui_vfslist_new(1);
00216 gui_vfslist_setcallback(win_playq, gui_playq_statbar_refresh);
00217 gui_vfslist_setlist(win_playq, &playq_list);
00218 gui_vfslist_move(win_playq, 0, 1, COLS, GUI_SIZE_PLAYQ_HEIGHT);
00219 }
00220
00221 void
00222 gui_playq_destroy(void)
00223 {
00224 delwin(win_statbar);
00225 gui_vfslist_destroy(win_playq);
00226
00227 g_string_free(str_time, TRUE);
00228 g_string_free(str_song, TRUE);
00229 }
00230
00231 void
00232 gui_playq_song_update(struct audio_file *fd, int paused, int timeonly)
00233 {
00234 gui_playq_song_set(fd, paused, timeonly);
00235
00236 #ifdef BUILD_SETPROCTITLE
00237
00238 setproctitle("%s %s%s", str_status, str_song->str, str_time->str);
00239 #endif
00240
00241 gui_playq_statbar_refresh();
00242 gui_draw_done();
00243 }
00244
00245 void
00246 gui_playq_resize(void)
00247 {
00248 gui_lock();
00249 wresize(win_statbar, 1, COLS);
00250 clearok(win_statbar, TRUE);
00251 gui_unlock();
00252
00253 playq_lock();
00254 gui_vfslist_move(win_playq, 0, 1, COLS, GUI_SIZE_PLAYQ_HEIGHT);
00255 playq_unlock();
00256 }
00257
00258 void
00259 gui_playq_notify_pre_removal(unsigned int index)
00260 {
00261 gui_vfslist_notify_pre_removal(win_playq, index);
00262 }
00263
00264 void
00265 gui_playq_notify_post_insertion(unsigned int index)
00266 {
00267 gui_vfslist_notify_post_insertion(win_playq, index);
00268 }
00269
00270 void
00271 gui_playq_notify_post_randomization(void)
00272 {
00273 gui_vfslist_notify_post_randomization(win_playq);
00274 }
00275
00276 void
00277 gui_playq_notify_done(void)
00278 {
00279 gui_vfslist_notify_done(win_playq);
00280 gui_draw_done();
00281 }
00282
00283 void
00284 gui_playq_cursor_up(void)
00285 {
00286 playq_lock();
00287 gui_vfslist_cursor_up(win_playq);
00288 playq_unlock();
00289 }
00290
00291 void
00292 gui_playq_cursor_down(void)
00293 {
00294 playq_lock();
00295 gui_vfslist_cursor_down(win_playq, 0);
00296 playq_unlock();
00297 }
00298
00299 void
00300 gui_playq_cursor_pageup(void)
00301 {
00302 playq_lock();
00303 gui_vfslist_cursor_pageup(win_playq);
00304 playq_unlock();
00305 }
00306
00307 void
00308 gui_playq_cursor_pagedown(void)
00309 {
00310 playq_lock();
00311 gui_vfslist_cursor_pagedown(win_playq);
00312 playq_unlock();
00313 }
00314
00315 void
00316 gui_playq_cursor_head(void)
00317 {
00318 playq_lock();
00319 gui_vfslist_cursor_head(win_playq);
00320 playq_unlock();
00321 }
00322
00323 void
00324 gui_playq_cursor_tail(void)
00325 {
00326 playq_lock();
00327 gui_vfslist_cursor_tail(win_playq);
00328 playq_unlock();
00329 }
00330
00331 void
00332 gui_playq_song_remove(void)
00333 {
00334 struct vfsref *vr;
00335
00336 playq_lock();
00337 if (!gui_vfslist_warn_isempty(win_playq)) {
00338 vr = gui_vfslist_getselected(win_playq);
00339 playq_song_fast_remove(vr,
00340 gui_vfslist_getselectedidx(win_playq));
00341 }
00342 playq_unlock();
00343 }
00344
00345 void
00346 gui_playq_song_remove_all(void)
00347 {
00348
00349 if (gui_vfslist_warn_isempty(win_playq))
00350 return;
00351
00352 if (gui_input_askyesno(_("Remove all songs from the playlist?")) == 0)
00353 playq_song_remove_all();
00354 }
00355
00356 void
00357 gui_playq_song_randomize(void)
00358 {
00359
00360 if (gui_vfslist_warn_isempty(win_playq))
00361 return;
00362
00363 if (gui_input_askyesno(_("Randomize the playlist?")) == 0)
00364 playq_song_randomize();
00365 }
00366
00367 void
00368 gui_playq_song_add_before(struct vfsref *vr)
00369 {
00370 struct vfsref *vr_selected;
00371
00372 playq_lock();
00373 vr_selected = gui_vfslist_getselected(win_playq);
00374 if (vr_selected == vfs_list_first(&playq_list)) {
00375 playq_unlock();
00376
00377 playq_song_add_head(vr);
00378 } else {
00379 playq_song_fast_add_before(vr, vr_selected,
00380 gui_vfslist_getselectedidx(win_playq));
00381 playq_unlock();
00382 }
00383 }
00384
00385 void
00386 gui_playq_song_add_after(struct vfsref *vr)
00387 {
00388 struct vfsref *vr_selected;
00389
00390 playq_lock();
00391 vr_selected = gui_vfslist_getselected(win_playq);
00392 if (vr_selected == vfs_list_last(&playq_list)) {
00393 playq_unlock();
00394
00395 playq_song_add_tail(vr);
00396 } else {
00397 playq_song_fast_add_after(vr, vr_selected,
00398 gui_vfslist_getselectedidx(win_playq));
00399 playq_unlock();
00400 }
00401 }
00402
00403 void
00404 gui_playq_song_move_up(void)
00405 {
00406 struct vfsref *vr_selected;
00407
00408 playq_lock();
00409 if (!gui_vfslist_warn_isempty(win_playq)) {
00410 vr_selected = gui_vfslist_getselected(win_playq);
00411 if (vr_selected == vfs_list_first(&playq_list)) {
00412 gui_msgbar_warn(_("The song is already at the "
00413 "top of the playlist."));
00414 } else {
00415 playq_song_fast_move_up(vr_selected,
00416 gui_vfslist_getselectedidx(win_playq));
00417 }
00418 }
00419 playq_unlock();
00420 }
00421
00422 void
00423 gui_playq_song_move_down(void)
00424 {
00425 struct vfsref *vr_selected;
00426
00427 playq_lock();
00428 if (!gui_vfslist_warn_isempty(win_playq)) {
00429 vr_selected = gui_vfslist_getselected(win_playq);
00430 if (vr_selected == vfs_list_last(&playq_list)) {
00431 gui_msgbar_warn(_("The song is already at the "
00432 "bottom of the playlist."));
00433 } else {
00434 playq_song_fast_move_down(vr_selected,
00435 gui_vfslist_getselectedidx(win_playq));
00436 }
00437 }
00438 playq_unlock();
00439 }
00440
00441 void
00442 gui_playq_song_move_head(void)
00443 {
00444 struct vfsref *vr_selected;
00445
00446 playq_lock();
00447 if (!gui_vfslist_warn_isempty(win_playq)) {
00448 vr_selected = gui_vfslist_getselected(win_playq);
00449 if (vr_selected == vfs_list_first(&playq_list)) {
00450 gui_msgbar_warn(_("The song is already at the "
00451 "top of the playlist."));
00452 } else {
00453 playq_song_fast_move_head(vr_selected,
00454 gui_vfslist_getselectedidx(win_playq));
00455 }
00456 }
00457 playq_unlock();
00458 }
00459
00460 void
00461 gui_playq_song_move_tail(void)
00462 {
00463 struct vfsref *vr_selected;
00464
00465 playq_lock();
00466 if (!gui_vfslist_warn_isempty(win_playq)) {
00467 vr_selected = gui_vfslist_getselected(win_playq);
00468 if (vr_selected == vfs_list_last(&playq_list)) {
00469 gui_msgbar_warn(_("The song is already at the "
00470 "bottom of the playlist."));
00471 } else {
00472 playq_song_fast_move_tail(vr_selected,
00473 gui_vfslist_getselectedidx(win_playq));
00474 }
00475 }
00476 playq_unlock();
00477 }
00478
00479 void
00480 gui_playq_song_select(void)
00481 {
00482 playq_lock();
00483 if (!gui_vfslist_warn_isempty(win_playq))
00484 playq_song_fast_select(gui_vfslist_getselected(win_playq));
00485 playq_unlock();
00486 }
00487
00488 int
00489 gui_playq_searchnext(const struct vfsmatch *vm)
00490 {
00491 int ret;
00492
00493 playq_lock();
00494 ret = gui_vfslist_searchnext(win_playq, vm);
00495 playq_unlock();
00496
00497 return (ret);
00498 }
00499
00500 void
00501 gui_playq_setfocus(int focus)
00502 {
00503 playq_lock();
00504 gui_vfslist_setfocus(win_playq, focus);
00505 playq_unlock();
00506 }
00507
00508 void
00509 gui_playq_fullpath(void)
00510 {
00511 playq_lock();
00512 gui_vfslist_fullpath(win_playq);
00513 playq_unlock();
00514 }
00515
00516 #ifdef BUILD_VOLUME
00517
00520 static void
00521 gui_playq_volume_show(int nval)
00522 {
00523 char *str;
00524
00525 if (nval < 0) {
00526 gui_msgbar_warn(_("Failed to adjust the volume."));
00527 } else {
00528 str = g_strdup_printf(_("Volume: %d%%"), nval);
00529 gui_msgbar_warn(str);
00530 g_free(str);
00531 }
00532 }
00533
00534 void
00535 gui_playq_volume_up(void)
00536 {
00537 int nval;
00538
00539 nval = audio_output_volume_up();
00540 gui_playq_volume_show(nval);
00541 }
00542
00543 void
00544 gui_playq_volume_down(void)
00545 {
00546 int nval;
00547
00548 nval = audio_output_volume_down();
00549 gui_playq_volume_show(nval);
00550 }
00551 #endif
00552
00553 void
00554 gui_playq_gotofolder(void)
00555 {
00556 struct vfsref *vr;
00557
00558 playq_lock();
00559 if (gui_vfslist_warn_isempty(win_playq)) {
00560 playq_unlock();
00561 } else {
00562 vr = gui_vfslist_getselected(win_playq);
00563 playq_unlock();
00564
00565 gui_browser_gotofile(vr);
00566 }
00567 }