Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
0
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;
}
Beispiel #4
0
int
cmd_color(int argc, char *argv[])
{
   char  *item;
   char  *fg, *bg;
   int    i_item, i_fg, i_bg, j;

   if (argc != 2) {
      paint_error("usage: %s ITEM=FG,BG", argv[0]);
      return 1;
   }

   /* extract item and foreground/background colors */
   item = argv[1];
   if ((fg = strchr(item, '=')) == NULL) {
      paint_error("usage: %s ITEM=FG,BG", argv[0]);
      return 2;
   }
   *fg = '\0';
   fg++;

   if ((bg = strchr(fg, ',')) == NULL) {
      paint_error("usage: %s ITEM=FG,BG", argv[0]);
      return 3;
   }
   *bg = '\0';
   bg++;

   /* convert all */
   if ((i_item = paint_str2item(item)) < 0) {
      paint_error("invalid item '%s'", item);
      return 4;
   }

   if ((i_fg = paint_str2color(fg)) == -2) {
      paint_error("invalid foreground color '%s'", fg);
      return 5;
   }

   if ((i_bg = paint_str2color(bg)) == -2) {
      paint_error("invalid background color '%s'", bg);
      return 6;
   }

   /* init color */
   init_pair(i_item, i_fg, i_bg);

   /* if this was a cinfo item, indicate that it was set */
   for (j = 0; j < MI_NUM_CINFO; j++) {
      if (i_item == colors.cinfos[j])
         colors.cinfos_set[j] = true;
   }

   /* redraw */
   if (ui_is_init()) {
      ui_clear();
      paint_all();
   }

   return 0;
}
Beispiel #5
0
void DiagramCanvas::paintEvent(QPaintEvent *e)
{
    QRect r = e->rect();
    paint_all( r);
}