예제 #1
0
파일: commands.c 프로젝트: ok100/vitunes
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;
}
예제 #2
0
파일: commands.c 프로젝트: sahne/vitunes
int
cmd_filter(int argc, char *argv[])
{
   playlist *results;
   char     *search_phrase;
   bool      match;
   int       i;

   if (argc == 1) {
      paint_error("usage: filter[!] token [token2 ...]");
      return 1;
   }

   /* determine what kind of filter we're doing */
   match = argv[0][strlen(argv[0]) - 1] != '!';

   /* set the raw query */
   search_phrase = argv2str(argc - 1, argv + 1);
   mi_query_setraw(search_phrase);
   free(search_phrase);

   /* clear existing global query & set new one */
   mi_query_clear();
   for (i = 1; i < argc; i++)
      mi_query_add_token(argv[i]);

   /* do actual filter */
   results = playlist_filter(viewing_playlist, match);

   /* swap necessary bits of results with filter playlist */
   swap(meta_info **, results->files,    mdb.filter_results->files);
   swap(int, results->nfiles,   mdb.filter_results->nfiles);
   swap(int, results->capacity, mdb.filter_results->capacity);
   playlist_free(results);

   /* redraw */
   setup_viewing_playlist(mdb.filter_results);
   paint_library();
   paint_playlist();

   return 0;
}
예제 #3
0
파일: commands.c 프로젝트: sahne/vitunes
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;
}