コード例 #1
0
ファイル: uit_userlist.c プロジェクト: Tilka/ncdc
static void draw_row(ui_listing_t *list, GSequenceIter *iter, int row, void *dat) {
  hub_user_t *user = g_sequence_get(iter);
  tab_t *t = dat;

  char *tag = hub_user_tag(user);
  char *conn = hub_user_conn(user);

  attron(iter == list->sel ? UIC(list_select) : UIC(list_default));
  mvhline(row, 0, ' ', wincols);
  if(iter == list->sel)
    mvaddch(row, 0, '>');

  if(user->isop)
    mvaddch(row, 2, 'o');
  if(!user->active)
    mvaddch(row, 3, 'p');
  if(user->hastls)
    mvaddch(row, 4, 't');

  int j = 6;
  const char *cc =
    !ip4_isany(user->ip4) ? geoip_country4(ip4_unpack(user->ip4)) :
    !ip6_isany(user->ip6) ? geoip_country6(ip6_unpack(user->ip6)) : NULL;
  DRAW_COL(row, j, t->cw_country, cc?cc:"");
  if(t->cw_user > 1)
    ui_listing_draw_match(list, iter, row, j, str_offset_from_columns(user->name, t->cw_user-1));
  j += t->cw_user;
  DRAW_COL(row, j, t->cw_share, user->hasinfo ? str_formatsize(user->sharesize) : "");
  DRAW_COL(row, j, t->cw_desc,  user->desc?user->desc:"");
  DRAW_COL(row, j, t->cw_tag,   tag?tag:"");
  DRAW_COL(row, j, t->cw_mail,  user->mail?user->mail:"");
  DRAW_COL(row, j, t->cw_conn,  conn?conn:"");
  DRAW_COL(row, j, t->cw_ip,    hub_user_ip(user, ""));
  g_free(conn);
  g_free(tag);

  attroff(iter == list->sel ? UIC(list_select) : UIC(list_default));
}
コード例 #2
0
ファイル: vars.c プロジェクト: srijan/ncdc
static char *f_speed(const char *val) {
  return g_strdup_printf("%s/s", str_formatsize(int_raw(val)));
}
コード例 #3
0
ファイル: uit_userlist.c プロジェクト: Tilka/ncdc
static void t_draw(ui_tab_t *tab) {
  tab_t *t = (tab_t *)tab;

  calc_widths(t);

  // header
  attron(UIC(list_header));
  mvhline(1, 0, ' ', wincols);
  mvaddstr(1, 2, "opt");
  int i = 6;
  DRAW_COL(1, i, t->cw_country, "CC");
  DRAW_COL(1, i, t->cw_user,    "Username");
  DRAW_COL(1, i, t->cw_share,   "Share");
  DRAW_COL(1, i, t->cw_desc,    "Description");
  DRAW_COL(1, i, t->cw_tag,     "Tag");
  DRAW_COL(1, i, t->cw_mail,    "E-Mail");
  DRAW_COL(1, i, t->cw_conn,    "Connection");
  DRAW_COL(1, i, t->cw_ip,      "IP");
  attroff(UIC(list_header));

  // rows
  int bottom = t->details ? winrows-7 : winrows-3;
  ui_cursor_t cursor;
  int pos = ui_listing_draw(t->list, 2, bottom-1, &cursor, draw_row);

  // footer
  attron(UIC(separator));
  mvhline(bottom, 0, ' ', wincols);
  int count = g_hash_table_size(t->tab.hub->users);
  mvaddstr(bottom, 0, "Totals:");
  mvprintw(bottom, t->cw_user+6, "%s%c   %d users",
    str_formatsize(t->tab.hub->sharesize), t->tab.hub->sharecount == count ? ' ' : '+', count);
  mvprintw(bottom, wincols-6, "%3d%%", pos);
  attroff(UIC(separator));

  // detailed info box
  if(t->details && g_sequence_iter_is_end(t->list->sel))
    mvaddstr(bottom+1, 2, "No user selected.");
  else if(t->details) {
    hub_user_t *u = g_sequence_get(t->list->sel);
    attron(A_BOLD);
    mvaddstr(bottom+1,     4, "Username:"******"Share:");
    mvaddstr(bottom+2,     2, "Connection:");
    mvaddstr(bottom+2, 25+19, "IP:");
    mvaddstr(bottom+3,     6, "E-Mail:");
    mvaddstr(bottom+3, 25+18, "Tag:");
    mvaddstr(bottom+4,     1, "Description:");
    attroff(A_BOLD);
    mvaddstr(bottom+1, 14, u->name);
    if(u->hasinfo)
      mvprintw(bottom+1, 25+23, "%s (%s bytes)", str_formatsize(u->sharesize), str_fullsize(u->sharesize));
    else
      mvaddstr(bottom+1, 25+23, "-");
    char *conn = hub_user_conn(u);
    mvaddstr(bottom+2, 14, conn?conn:"-");
    g_free(conn);
    mvaddstr(bottom+2, 25+23, hub_user_ip(u, "-"));
    mvaddstr(bottom+3, 14, u->mail?u->mail:"-");
    char *tag = hub_user_tag(u);
    mvaddstr(bottom+3, 25+23, tag?tag:"-");
    g_free(tag);
    mvaddstr(bottom+4, 14, u->desc?u->desc:"-");
    // TODO: CID?
  }

  move(cursor.y, cursor.x);
}