// should be run from a timer. periodically flushes all unsaved data to disk. gboolean fl_flush(gpointer dat) { if(fl_needflush) { // save our file list GError *err = NULL; if(!fl_save(fl_local_list, var_get(0, VAR_cid), 0, FALSE, NULL, fl_local_list_file, &err)) { // this is a pretty fatal error... oh well, better luck next time ui_mf(uit_main_tab, UIP_MED, "Error saving file list: %s", err->message); g_error_free(err); } } fl_needflush = FALSE; return TRUE; }
// Removes duplicate files (that is, files with the same name in a // case-insensitive context) from a dirtectory. static void fl_scan_rmdupes(fl_list_t *fl, const char *vpath) { int i = 1; while(i<fl->sub->len) { fl_list_t *a = g_ptr_array_index(fl->sub, i-1); fl_list_t *b = g_ptr_array_index(fl->sub, i); if(fl_list_cmp_strict(a, b) == 0) { char *tmp = g_build_filename(vpath, b->name, NULL); ui_mf(uit_main_tab, UIP_MED, "Not sharing \"%s\": Other file with same name (but different case) already shared.", tmp); fl_list_remove(b); g_free(tmp); } else i++; } }
static void c_help(char *args) { char *sec = strchr(args, ' '); if(sec) *(sec++) = 0; // list available commands if(!args[0]) { ui_m(NULL, 0, "\nAvailable commands:"); struct cmd *c = cmds; for(; c->f; c++) ui_mf(NULL, 0, " /%s - %s", c->name, getdoc(c)->sum); ui_m(NULL, 0, "\nFor help on key bindings, use `/help keys'.\n"); // list information on a setting } else if((strcmp(args, "set") == 0 || strcmp(args, "hset") == 0) && sec) { sec = strncmp(sec, "color_", 6) == 0 ? "color_*" : sec; struct doc_set *s = (struct doc_set *)doc_sets; for(; s->name; s++) if(strcmp(s->name, sec) == 0) break; if(!s->name) ui_mf(NULL, 0, "\nUnknown setting '%s'.", sec); else ui_mf(NULL, 0, "\nSetting: %s.%s %s\n\n%s\n", s->hub ? "#hub" : "global", s->name, s->type, s->desc); // list available key sections } else if(strcmp(args, "keys") == 0 && !sec) { ui_m(NULL, 0, "\nAvailable sections:"); const struct doc_key *k = doc_keys; for(; k->sect; k++) ui_mf(NULL, 0, " %s - %s", k->sect, k->title); ui_m(NULL, 0, "\nUse `/help keys <name>' to get help on the key bindings for the selected section.\n"); // get information on a particular key section } else if(strcmp(args, "keys") == 0 && sec) { const struct doc_key *k = doc_keys; for(; k->sect; k++) if(strcmp(k->sect, sec) == 0) break; if(!k->sect) ui_mf(NULL, 0, "\nUnknown keys section '%s'.", sec); else ui_mf(NULL, 0, "\nKey bindings for: %s - %s.\n\n%s\n", k->sect, k->title, k->desc); // get information on a particular command } else if(!sec) { if(*args == '/') args++; struct cmd *c = getcmd(args); if(!c) ui_mf(NULL, 0, "\nUnknown command '%s'.", args); else { struct doc_cmd *d = getdoc(c); ui_mf(NULL, 0, "\nUsage: /%s %s\n %s\n", c->name, d->args ? d->args : "", d->sum); if(d->desc) ui_mf(NULL, 0, "%s\n", d->desc); } } else ui_mf(NULL, 0, "\nUnknown help section `%s'.", args); }
static char *p_connection(const char *val, GError **err) { if(!connection_to_speed(val)) ui_mf(NULL, 0, "Couldn't convert `%s' to bytes/second, won't broadcast upload speed on ADC. See `/help set connection' for more information.", val); return g_strdup(val); }
static void t_key(ui_tab_t *tab, guint64 key) { tab_t *t = (tab_t *)tab; if(ui_listing_key(t->list, key, winrows/2)) return; hub_user_t *sel = g_sequence_iter_is_end(t->list->sel) ? NULL : g_sequence_get(t->list->sel); gboolean sort = FALSE; switch(key) { case INPT_CHAR('?'): uit_main_keys("userlist"); break; // Sorting #define SETSORT(c) \ t->reverse = t->order == c ? !t->reverse : FALSE;\ t->order = c;\ sort = TRUE; case INPT_CHAR('s'): // s/S - sort on share size case INPT_CHAR('S'): SETSORT(SORT_SHARE); break; case INPT_CHAR('u'): // u/U - sort on username case INPT_CHAR('U'): SETSORT(SORT_USER) break; case INPT_CHAR('D'): // D - sort on description SETSORT(SORT_DESC) break; case INPT_CHAR('T'): // T - sort on client (= tag) SETSORT(SORT_CLIENT) break; case INPT_CHAR('E'): // E - sort on email SETSORT(SORT_MAIL) break; case INPT_CHAR('C'): // C - sort on connection SETSORT(SORT_CONN) break; case INPT_CHAR('P'): // P - sort on IP SETSORT(SORT_IP) break; case INPT_CHAR('o'): // o - toggle sorting OPs before others t->opfirst = !t->opfirst; sort = TRUE; break; #undef SETSORT // Column visibility case INPT_CHAR('d'): // d (toggle description visibility) t->hide_desc = !t->hide_desc; break; case INPT_CHAR('t'): // t (toggle tag visibility) t->hide_tag = !t->hide_tag; break; case INPT_CHAR('e'): // e (toggle e-mail visibility) t->hide_mail = !t->hide_mail; break; case INPT_CHAR('c'): // c (toggle connection visibility) t->hide_conn = !t->hide_conn; break; case INPT_CHAR('p'): // p (toggle IP visibility) t->hide_ip = !t->hide_ip; break; case INPT_CTRL('j'): // newline case INPT_CHAR('i'): // i (toggle user info) t->details = !t->details; break; case INPT_CHAR('m'): // m (/msg user) if(!sel) ui_m(NULL, 0, "No user selected."); else uit_msg_open(sel->uid, tab); break; case INPT_CHAR('g'): // g (grant slot) if(!sel) ui_m(NULL, 0, "No user selected."); else { db_users_set(sel->hub->id, sel->uid, sel->name, db_users_get(sel->hub->id, sel->name) | DB_USERFLAG_GRANT); ui_m(NULL, 0, "Slot granted."); } break; case INPT_CHAR('b'): // b (/browse userlist) case INPT_CHAR('B'): // B (force /browse userlist) if(!sel) ui_m(NULL, 0, "No user selected."); else uit_fl_queue(sel->uid, key == INPT_CHAR('B'), NULL, tab, TRUE, FALSE); break; case INPT_CHAR('q'): // q - download filelist and match queue for selected user if(!sel) ui_m(NULL, 0, "No user selected."); else uit_fl_queue(sel->uid, FALSE, NULL, NULL, FALSE, TRUE); break; } if(sort) { g_sequence_sort(t->list->list, sort_func, tab); ui_listing_sorted(t->list); ui_mf(NULL, 0, "Ordering by %s (%s%s)", t->order == SORT_USER ? "user name" : t->order == SORT_SHARE ? "share size" : t->order == SORT_CONN ? "connection" : t->order == SORT_DESC ? "description" : t->order == SORT_MAIL ? "e-mail" : t->order == SORT_CLIENT? "tag" : "IP address", t->reverse ? "descending" : "ascending", t->opfirst ? ", OPs first" : ""); } }