Esempio n. 1
0
void k_redraw(const keyarg_u *a, unsigned repeat, const int from_ch)
{
	(void)a;
	ui_clear();
	ui_redraw();
	ui_cur_changed();
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
0
void
log_open(GSList   *filenames,
         gboolean  merge)
{
    gchar *filename;
    gzFile gzfp;
    gint n, err;
    guchar buffer[READ_BUFFER_LEN];
    const gchar *err_string;

    yajl_handle json;
    yajl_status status;
    read_ctx_t context;

    if(ui.changed && !ui_dialog_ask_unsaved())
        return;

    context.merge = merge;
    context.changed = FALSE;

    if(!merge)
        ui_clear();

    ui_view_lock(ui.treeview);

    while(filenames != NULL)
    {
        filename = (gchar*)filenames->data;
        gzfp = gzopen(filename, "r");
        if(!gzfp)
        {
            ui_dialog(ui.window,
                      GTK_MESSAGE_ERROR,
                      "Error",
                      "Failed to open a file:\n%s", filename);
        }
        else
        {
            context.key = KEY_UNKNOWN;
            context.level = LEVEL_ROOT;
            context.level_signals = FALSE;
            context.signal = NULL;
            network_init(&context.network);

            json = yajl_alloc(&json_callbacks, NULL, &context);
            do
            {
                n = gzread(gzfp, buffer, READ_BUFFER_LEN-1);
                status = yajl_parse(json, buffer, n);

                if(n < READ_BUFFER_LEN-1)
                {
                    if(gzeof(gzfp))
                        break;
                    err_string = gzerror(gzfp, &err);
                    if(err)
                    {
                        ui_dialog(ui.window,
                                  GTK_MESSAGE_ERROR,
                                  "Error",
                                  "Failed to read a file:\n%s\n\n%s",
                                  filename, err_string);
                        break;
                    }
                }
            } while (status == yajl_status_ok);
            gzclose(gzfp);

            if(status == yajl_status_ok)
                status = yajl_complete_parse(json);

            yajl_free(json);

            if(status != yajl_status_ok)
            {
                network_free(&context.network);
                g_free(context.signal);
                ui_dialog(ui.window,
                          GTK_MESSAGE_ERROR,
                          "Error",
                          "The selected file is corrupted or is not a valid MTscan log:\n%s",
                          filename);
            }
            else if(!merge)
            {
                /* Take the allocated filename for the UI */
                ui_set_title(filename);
                filenames->data = NULL;
            }
        }
        filenames = filenames->next;
    }

    ui_view_unlock(ui.treeview);

    if(context.changed)
    {
        ui_status_update_networks();
        if(merge)
        {
            /* Set filename to NULL after merge */
            ui_set_title(NULL);
            ui_changed();
        }
    }
}