int cmd_display(int argc, char *argv[]) { const char *errmsg; if (argc != 2) { paint_error("usage: display [ reset | show | <display-description> ]"); return 1; } /* show existng display? */ if (strcasecmp(argv[1], "show") == 0) { paint_message(":display %s", mi_display_tostr()); return 0; } /* reset display to default? */ if (strcasecmp(argv[1], "reset") == 0) { mi_display_reset(); paint_playlist(); return 0; } /* if reached here, setup global display description */ if (mi_display_set(argv[1], &errmsg) != 0) { paint_error("%s: bad display description: %s", argv[0], errmsg); return 1; } if(ui_is_init()) paint_playlist(); return 0; }
int cmd_new(int argc, char *argv[]) { playlist *p; char *name; char *filename; int i; if (argc > 2) { paint_error("usage: new [name]"); return 1; } /* defaults */ name = "untitled"; filename = NULL; /* was a name specified? */ if (argc == 2) { /* check for existing playlist with name */ for (i = 0; i < mdb.nplaylists; i++) { if (strcmp(mdb.playlists[i]->name, argv[1]) == 0) { paint_error("playlist \"%s\" already exists.", argv[1]); return 2; } } name = argv[1]; asprintf(&filename, "%s/%s.playlist", mdb.playlist_dir, name); if (filename == NULL) err(1, "cmd_new: asprintf(3) failed"); } /* create & setup playlist */ p = playlist_new(); p->needs_saving = true; p->filename = filename; if ((p->name = strdup(name)) == NULL) err(1, "cmd_new: strdup(3) failed"); /* add playlist to media library and update ui */ medialib_playlist_add(p); ui.library->nrows++; if (p->filename != NULL) playlist_save(p); /* redraw */ paint_library(); paint_message("playlist \"%s\" added", name); return 0; }
int cmd_reload(int argc, char *argv[]) { char *db_file; char *playlist_dir; if (argc != 2) { paint_error("usage: %s [ db | conf ]", argv[0]); return 1; } /* reload database or config file */ if (strcasecmp(argv[1], "db") == 0) { db_file = strdup(mdb.db_file); playlist_dir = strdup(mdb.playlist_dir); if (db_file == NULL || playlist_dir == NULL) err(1, "cmd_reload: strdup(3) failed"); /* stop playback TODO investigate a nice way around this */ player_stop(); /* reload db */ medialib_destroy(); medialib_load(db_file, playlist_dir); /* sort entries */ qsort(mdb.library->files, mdb.library->nfiles, sizeof(meta_info*), mi_compare); free(db_file); free(playlist_dir); /* re-setup ui basics */ playing_playlist = NULL; setup_viewing_playlist(mdb.library); ui.library->voffset = 0; ui.library->nrows = mdb.nplaylists; ui.library->crow = 0; paint_all(); } else if (strcasecmp(argv[1], "conf") == 0) { load_config(); paint_message("configuration reloaded"); } else { paint_error("usage: %s [ db | conf ]", argv[0]); return 2; } return 0; }
int cmd_playlist(int argc, char *argv[]) { int x; int idx = -1; if (argc != 2) { paint_error("usage: playlist <list-name>"); return 1; } for(x = 0; x < mdb.nplaylists; x++) { if(!strncmp(argv[1], mdb.playlists[x]->name, strlen(argv[1]))) { if(idx > -1) { idx = -2; break; } if(idx == -1) idx = x; } } if(idx > -1) { setup_viewing_playlist(mdb.playlists[idx]); ui.active = ui.playlist; paint_all(); paint_message("jumped to playlist: %s", mdb.playlists[idx]->name); return 0; } if(idx == -1) { paint_error("no match for: %s", argv[1]); return 0; } if(idx == -2) paint_error("no unique match for: %s", argv[1]); return 0; }
int cmd_mode(int argc, char *argv[]) { if (argc != 2) { paint_error("usage: mode [ linear | loop | random ]"); return 1; } if (strcasecmp(argv[1], "linear") == 0) player_info.mode = MODE_LINEAR; else if (strcasecmp(argv[1], "loop") == 0) player_info.mode = MODE_LOOP; else if (strcasecmp(argv[1], "random") == 0) player_info.mode = MODE_RANDOM; else { paint_error("invalid mode \"%s\". must be one of: linear, loop, or random", argv[1]); return 2; } paint_message("mode changed to: %s", argv[1]); return 0; }
void show_message(char *from, char *content) { debug("show_message(%s, %s)\n", from, content); if (strlen(from) == 0 && strlen(content) == 0 ) { gdk_window_resize(window->window, 1, 1); return; } //初始化cairo环境 paint_message (cr, from, content); cairo_surface_flush(sf); //复制生成位图 copy_surface_to_pixmap (sf, pixmap); copy_surface_to_pixmap (sf, pixmap_mask); //刷新显示 gtk_window_set_title(GTK_WINDOW(window), content); gdk_window_set_back_pixmap (window->window, pixmap, FALSE); gtk_widget_shape_combine_mask (window, pixmap_mask, 0, 0); gtk_widget_queue_draw(window); gdk_window_resize(window->window, window_width, window_height); }
int cmd_set(int argc, char *argv[]) { const char *err; char *property; char *value; bool tf; int max_w, max_h, new_width; /* lwidth */ bool player_is_setup; if (argc != 2) { paint_error("usage: %s <property>=<value>", argv[0]); return 1; } /* determine if the player has been setup (needed for redraws below) */ player_is_setup = (player.name != NULL) && (*player.name != NULL); /* extract property and value */ property = argv[1]; if ((value = strchr(property, '=')) == NULL) { paint_error("usage: %s <property>=<value>", argv[0]); return 2; } *value = '\0'; value++; /* handle property */ if (strcasecmp(property, "lwidth") == 0) { /* get max width and height */ getmaxyx(stdscr, max_h, max_w); /* validate and convert width user provided */ new_width = (int)strtonum(value, 1, max_w, &err); if (err != NULL) { paint_error("%s %s: bad width: '%s' %s", argv[0], property, value, err); return 3; } /* resize & redraw (if we're past setup & curses is running) */ ui.lwidth = new_width; ui_resize(); if(player_is_setup && ui_is_init()) { ui_clear(); paint_all(); } } else if (strcasecmp(property, "lhide") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 4; } ui.lhide = tf; if (ui.lhide) { if (ui.active == ui.playlist) ui_hide_library(); if (player_is_setup && ui_is_init()) { ui_clear(); paint_all(); paint_message("library window hidden"); } } else { if (ui.library->cwin == NULL) ui_unhide_library(); if (player_is_setup && ui_is_init()) paint_all(); paint_message("library window un-hidden"); } } else if (strcasecmp(property, "match-fname") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 5; } mi_query_match_filename = tf; if (mi_query_match_filename) paint_message("filenames will be matched against"); else paint_message("filenames will NOT be matched against"); } else if (strcasecmp(property, "save-sorts") == 0) { if (str2bool(value, &tf) < 0) { paint_error("%s %s: value must be boolean", argv[0], property); return 6; } sorts_need_saving = tf; if (sorts_need_saving) paint_message("changing sort will be prompted for saving"); else paint_message("changing sort will NOT be prompted for saving"); } else { paint_error("%s: unknown property '%s'", argv[0], property); return 7; } return 0; }
int cmd_write(int argc, char *argv[]) { playlist *dup; char *filename; bool forced; bool will_clobber; int i, clobber_index; if (argc > 2) { paint_error("usage: w[!] [name]"); return 1; } forced = (strcmp(argv[0], "w!") == 0); if (argc == 1) { /* "save" */ /* can't save library or filter results */ if (viewing_playlist == mdb.library || viewing_playlist == mdb.filter_results) { paint_error("use \"w name\" when saving psuedo-playlists like library/filter"); return 2; } /* can't save a new playlist that has no name */ if (viewing_playlist->filename == NULL) { paint_error("use \"w name\" for new playlists"); return 3; } /* do the save... */ playlist_save(viewing_playlist); viewing_playlist->needs_saving = false; paint_library(); paint_message("\"%s\" %d songs written", viewing_playlist->filename, viewing_playlist->nfiles); } else { /* "save as" */ /* build filename for playlist */ asprintf(&filename, "%s/%s.playlist", mdb.playlist_dir, argv[1]); if (filename == NULL) err(1, "cmd_write: asprintf(3) failed"); /* check to see if playlist with that name already exists */ will_clobber = false; clobber_index = -1; for (i = 0; i < mdb.nplaylists; i++) { if (mdb.playlists[i]->filename != NULL && strcmp(mdb.playlists[i]->filename, filename) == 0) { will_clobber = true; clobber_index = i; } } if (will_clobber && !forced) { paint_error("playlist with that name exists (use \"w!\" to overwrite)"); free(filename); return 4; } /* if reached here, we're going to do the save-as... */ /* duplicate playlist */ dup = playlist_dup(viewing_playlist, filename, argv[1]); if (will_clobber) medialib_playlist_remove(clobber_index); else ui.library->nrows++; /* * TODO If the original playlist was a new one, with no name (i.e. if * name == NULL) then we should remove that playlist from the medialib * and display here. */ /* do the save-as... */ playlist_save(dup); medialib_playlist_add(dup); dup->needs_saving = false; viewing_playlist->needs_saving = false; paint_library(); paint_message("\"%s\" %d songs written", filename, viewing_playlist->nfiles); } return 0; }