static gboolean location_changed(GntFileSel *sel, GError **err) { GList *files, *iter; gboolean success; if (!sel->dirs) return TRUE; gnt_tree_remove_all(GNT_TREE(sel->dirs)); if (sel->files) gnt_tree_remove_all(GNT_TREE(sel->files)); gnt_entry_set_text(GNT_ENTRY(sel->location), NULL); if (sel->current == NULL) { if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(sel)); return TRUE; } /* XXX:\ * XXX: This is blocking. * XXX:/ */ files = NULL; if (sel->read_fn) success = sel->read_fn(sel->current, &files, err); else success = local_read_fn(sel->current, &files, err); if (!success || *err) { gnt_warning("error opening location %s (%s)", sel->current, *err ? (*err)->message : "reason unknown"); return FALSE; } for (iter = files; iter; iter = iter->next) { GntFile *file = iter->data; char *str = file->basename; if (file->type == GNT_FILE_DIR) { gnt_tree_add_row_after(GNT_TREE(sel->dirs), g_strdup(str), gnt_tree_create_row(GNT_TREE(sel->dirs), str), NULL, NULL); if (sel->multiselect && sel->dirsonly && is_tagged(sel, str)) gnt_tree_set_row_flags(GNT_TREE(sel->dirs), (gpointer)str, GNT_TEXT_FLAG_BOLD); } else if (!sel->dirsonly) { char size[128]; snprintf(size, sizeof(size), "%ld", file->size); gnt_tree_add_row_after(GNT_TREE(sel->files), g_strdup(str), gnt_tree_create_row(GNT_TREE(sel->files), str, size, ""), NULL, NULL); if (sel->multiselect && is_tagged(sel, str)) gnt_tree_set_row_flags(GNT_TREE(sel->files), (gpointer)str, GNT_TEXT_FLAG_BOLD); } } g_list_foreach(files, (GFunc)gnt_file_free, NULL); g_list_free(files); if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(sel), GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(sel)); return TRUE; }
static void redraw_slider(GntSlider *slider) { GntWidget *widget = GNT_WIDGET(slider); if (GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) gnt_widget_draw(widget); }
static void toggle_selection(GntWidget *widget) { GNT_CHECK_BOX(widget)->checked = !GNT_CHECK_BOX(widget)->checked; g_signal_emit(widget, signals[SIG_TOGGLED], 0); gnt_widget_draw(widget); }
static void menuitem_activate(GntMenu *menu, GntMenuItem *item) { if (!item) return; if (gnt_menuitem_activate(item)) { menu_hide_all(menu); } else { if (item->submenu) { GntMenu *sub = GNT_MENU(item->submenu); menu->submenu = sub; sub->type = GNT_MENU_POPUP; /* Submenus are *never* toplevel */ sub->parentmenu = menu; if (menu->type != GNT_MENU_TOPLEVEL) { GntWidget *widget = GNT_WIDGET(menu); item->priv.x = widget->priv.x + widget->priv.width - 1; item->priv.y = widget->priv.y + gnt_tree_get_selection_visible_line(GNT_TREE(menu)); } gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y); GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE); gnt_widget_draw(GNT_WIDGET(sub)); } else { menu_hide_all(menu); } } }
static void gnt_text_view_reflow(GntTextView *view) { /* This is pretty ugly, and inefficient. Someone do something about it. */ GntTextLine *line; GList *back, *iter, *list; GString *string; int pos = 0; /* no. of 'real' lines */ list = view->list; while (list->prev) { line = list->data; if (!line->soft) pos++; list = list->prev; } back = g_list_last(view->list); view->list = NULL; string = view->string; view->string = NULL; reset_text_view(view); view->string = g_string_set_size(view->string, string->len); view->string->len = 0; GNT_WIDGET_SET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); for (; back; back = back->prev) { line = back->data; if (back->next && !line->soft) { gnt_text_view_append_text_with_flags(view, "\n", GNT_TEXT_FLAG_NORMAL); } for (iter = line->segments; iter; iter = iter->next) { GntTextSegment *seg = iter->data; char *start = string->str + seg->start; char *end = string->str + seg->end; char back = *end; *end = '\0'; gnt_text_view_append_text_with_flags(view, start, seg->tvflag); *end = back; } free_text_line(line, NULL); } g_list_free(list); list = view->list = g_list_first(view->list); /* Go back to the line that was in view before resizing started */ while (pos--) { while (((GntTextLine*)list->data)->soft) list = list->next; list = list->next; } view->list = list; GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(view), GNT_WIDGET_DRAWING); if (GNT_WIDGET(view)->window) gnt_widget_draw(GNT_WIDGET(view)); g_string_free(string, TRUE); }
static void gnt_box_gained_focus(GntWidget *widget) { GntWidget *w = GNT_BOX(widget)->active; if (w) gnt_widget_set_focus(w, TRUE); gnt_widget_draw(widget); }
static void gnt_box_lost_focus(GntWidget *widget) { GntWidget *w = GNT_BOX(widget)->active; if (w) gnt_widget_set_focus(w, FALSE); gnt_widget_draw(widget); }
static gboolean gnt_text_view_clicked(GntWidget *widget, GntMouseEvent event, int x, int y) { if (event == GNT_MOUSE_SCROLL_UP) { gnt_text_view_scroll(GNT_TEXT_VIEW(widget), -1); } else if (event == GNT_MOUSE_SCROLL_DOWN) { gnt_text_view_scroll(GNT_TEXT_VIEW(widget), 1); } else if (event == GNT_LEFT_MOUSE_DOWN) { select_start = gnt_text_view_get_p(GNT_TEXT_VIEW(widget), x - widget->priv.x, y - widget->priv.y); g_timeout_add(500, too_slow, NULL); } else if (event == GNT_MOUSE_UP) { GntTextView *view = GNT_TEXT_VIEW(widget); if (text_view_contains(view, select_start)) { GString *clip; select_end = gnt_text_view_get_p(view, x - widget->priv.x, y - widget->priv.y); if (select_end < select_start) { gchar *t = select_start; select_start = select_end; select_end = t; } if (select_start == select_end) { if (double_click) { clip = select_word_text(view, select_start); double_click = FALSE; } else { double_click = TRUE; select_start = 0; select_end = 0; gnt_widget_draw(widget); return TRUE; } } else { gchar *endsize = g_utf8_next_char(select_end); /* End at the correct byte */ clip = g_string_new_len(select_start, endsize - select_start); } gnt_widget_draw(widget); gnt_set_clipboard_string(clip->str); g_string_free(clip, TRUE); } } else return FALSE; return TRUE; }
static void decide_conf_button(PurplePlugin *plugin) { if (has_prefs(plugin)) gnt_widget_set_visible(plugins.conf, TRUE); else gnt_widget_set_visible(plugins.conf, FALSE); gnt_box_readjust(GNT_BOX(plugins.window)); gnt_widget_draw(plugins.window); }
static void fl_destroy(PurpleRoomlist *list) { if (!froomlist.window) return; if (froomlist.roomlist == list) { froomlist.roomlist = NULL; gnt_tree_remove_all(GNT_TREE(froomlist.tree)); gnt_widget_draw(froomlist.tree); } }
static void load_pref_window(const char * profile) { gint i; finch_sound_set_active_profile(profile); gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->method), (gchar *)purple_prefs_get_string(make_pref("/method"))); gnt_entry_set_text(GNT_ENTRY(pref_dialog->command), purple_prefs_get_path(make_pref("/command"))); gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog->conv_focus), purple_prefs_get_bool(make_pref("/conv_focus"))); gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status"))); gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100)); for (i = 0; i < PURPLE_NUM_SOUNDS; i++) { FinchSoundEvent * event = &sounds[i]; gchar *boolpref; gchar *filepref, *basename = NULL; const char * profile = finch_sound_get_active_profile(); filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref); g_free(event->file); event->file = g_strdup(purple_prefs_get_path(filepref)); g_free(filepref); if (event->label == NULL) { continue; } boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref); gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label); gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, event->file[0] ? (basename = g_path_get_basename(event->file)) : _("(default)")); g_free(basename); gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref)); g_free(boolpref); } gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), (gchar *)finch_sound_get_active_profile()); gnt_widget_draw(pref_dialog->window); }
static void set_selection(GntComboBox *box, gpointer key) { if (box->selected != key) { /* XXX: make sure the key actually does exist */ gpointer old = box->selected; box->selected = key; if (GNT_WIDGET(box)->window) gnt_widget_draw(GNT_WIDGET(box)); if (box->dropdown) gnt_tree_set_selected(GNT_TREE(box->dropdown), key); g_signal_emit(box, signals[SIG_SELECTION_CHANGED], 0, old, key); } }
static void decide_conf_button(PurplePlugin *plugin) { if (purple_plugin_is_loaded(plugin) && ((PURPLE_IS_GNT_PLUGIN(plugin) && FINCH_PLUGIN_UI_INFO(plugin) != NULL) || (plugin->info->prefs_info && plugin->info->prefs_info->get_plugin_pref_frame))) gnt_widget_set_visible(plugins.conf, TRUE); else gnt_widget_set_visible(plugins.conf, FALSE); gnt_box_readjust(GNT_BOX(plugins.window)); gnt_widget_draw(plugins.window); }
static void update_selected_account(GntEntry *screenname, const char *start, const char *end, GntComboBox *accountlist) { GList *accounts = gnt_tree_get_rows(GNT_TREE(accountlist->dropdown)); const char *name = gnt_entry_get_text(screenname); while (accounts) { if (purple_find_buddy(accounts->data, name)) { gnt_combo_box_set_selected(accountlist, accounts->data); gnt_widget_draw(GNT_WIDGET(accountlist)); break; } accounts = accounts->next; } }
void gnt_progress_bar_set_fraction (GntProgressBar *pbar, gdouble fraction) { GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar); if (fraction > 1.0) priv->fraction = 1.0; else if (fraction < 0.0) priv->fraction = 0.0; else priv->fraction = fraction; if ((GNT_WIDGET_FLAGS(pbar) & GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(pbar)); }
static void roomlist_account_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null) { if (froomlist.account == current) { return; } froomlist.account = current; if (froomlist.roomlist) { if (purple_roomlist_get_in_progress(froomlist.roomlist)) purple_roomlist_cancel_get_list(froomlist.roomlist); update_roomlist(NULL); } gnt_tree_remove_all(GNT_TREE(froomlist.tree)); gnt_widget_draw(froomlist.tree); }
gboolean gnt_screen_menu_show(gpointer newmenu) { if (wm->menu) { /* For now, if a menu is being displayed, then another menu * can NOT take over. */ return FALSE; } wm->menu = newmenu; GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(wm->menu), GNT_WIDGET_INVISIBLE); gnt_widget_draw(GNT_WIDGET(wm->menu)); g_signal_connect(G_OBJECT(wm->menu), "hide", G_CALLBACK(reset_menu), NULL); g_signal_connect(G_OBJECT(wm->menu), "destroy", G_CALLBACK(reset_menu), NULL); return TRUE; }
static void popup_dropdown(GntComboBox *box) { GntWidget *widget = GNT_WIDGET(box); GntWidget *parent = box->dropdown->parent; int height = g_list_length(GNT_TREE(box->dropdown)->list); int y = widget->priv.y + widget->priv.height - 1; gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2); if (y + height + 2 >= getmaxy(stdscr)) y = widget->priv.y - height - 1; gnt_widget_set_position(parent, widget->priv.x, y); if (parent->window) { mvwin(parent->window, y, widget->priv.x); wresize(parent->window, height+2, widget->priv.width); } parent->priv.width = widget->priv.width; parent->priv.height = height + 2; GNT_WIDGET_UNSET_FLAGS(parent, GNT_WIDGET_INVISIBLE); gnt_widget_draw(parent); }
void gnt_progress_bar_set_orientation (GntProgressBar *pbar, GntProgressBarOrientation orientation) { GntProgressBarPrivate *priv = GNT_PROGRESS_BAR_GET_PRIVATE (pbar); GntWidget *widget = GNT_WIDGET(pbar); priv->orientation = orientation; if (orientation == GNT_PROGRESS_LEFT_TO_RIGHT || orientation == GNT_PROGRESS_RIGHT_TO_LEFT) { GNT_WIDGET_SET_FLAGS(pbar, GNT_WIDGET_GROW_X); GNT_WIDGET_UNSET_FLAGS(pbar, GNT_WIDGET_GROW_Y); widget->priv.minw = 8; widget->priv.minh = 1; } else { GNT_WIDGET_UNSET_FLAGS(pbar, GNT_WIDGET_GROW_X); GNT_WIDGET_SET_FLAGS(pbar, GNT_WIDGET_GROW_Y); widget->priv.minw = 1; widget->priv.minh = 8; } if ((GNT_WIDGET_FLAGS(pbar) & GNT_WIDGET_MAPPED)) gnt_widget_draw(GNT_WIDGET(pbar)); }
static gboolean show_suggest_dropdown(GntEntry *entry) { char *suggest = NULL; int len; int offset = 0, x, y; int count = 0; GList *iter; const char *text = NULL; const char *sgst = NULL; int max = -1; if (entry->word) { char *s = get_beginning_of_word(entry); suggest = g_strndup(s, entry->cursor - s); if (entry->scroll < s) offset = gnt_util_onscreen_width(entry->scroll, s); } else suggest = g_strdup(entry->start); len = strlen(suggest); /* Don't need to use the utf8-function here */ if (entry->ddown == NULL) { GntWidget *box = gnt_vbox_new(FALSE); entry->ddown = gnt_tree_new(); gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate); gnt_box_add_widget(GNT_BOX(box), entry->ddown); GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); gnt_widget_get_position(GNT_WIDGET(entry), &x, &y); x += offset; y++; if (y + 10 >= getmaxy(stdscr)) y -= 11; gnt_widget_set_position(box, x, y); } else gnt_tree_remove_all(GNT_TREE(entry->ddown)); for (count = 0, iter = entry->suggests; iter; iter = iter->next) { text = iter->data; if (g_ascii_strncasecmp(suggest, text, len) == 0 && strlen(text) >= len) { gnt_tree_add_row_after(GNT_TREE(entry->ddown), (gpointer)text, gnt_tree_create_row(GNT_TREE(entry->ddown), text), NULL, NULL); count++; if (max == -1) max = strlen(text) - len; else if (max) max = MIN(max, max_common_prefix(sgst + len, text + len)); sgst = text; } } g_free(suggest); if (count == 0) { destroy_suggest(entry); return FALSE; } else if (count == 1) { char *store = g_strndup(entry->start, entry->end - entry->start); gboolean ret; destroy_suggest(entry); complete_suggest(entry, sgst); ret = (strncmp(store, entry->start, entry->end - entry->start) != 0); g_free(store); return ret; } else { if (max > 0) { GntWidget *ddown = entry->ddown; char *match = g_strndup(sgst + len, max); entry->ddown = NULL; gnt_entry_key_pressed(GNT_WIDGET(entry), match); g_free(match); if (entry->ddown) gnt_widget_destroy(ddown); else entry->ddown = ddown; } gnt_widget_draw(entry->ddown->parent); } return TRUE; }
static void notify(PurpleConversation *conv, const char *fmt, ...) { GntWidget *window; GntToast *toast; char *str; int h, w, i; va_list args; if (purple_prefs_get_bool(PREFS_BEEP)) beep(); if (conv != NULL) { FinchConv *fc = FINCH_CONV(conv); if (gnt_widget_has_focus(fc->window)) return; } #ifdef HAVE_X11 if (purple_prefs_get_bool(PREFS_URGENT)) urgent(); #endif window = gnt_vbox_new(FALSE); GNT_WIDGET_SET_FLAGS(window, GNT_WIDGET_TRANSIENT); GNT_WIDGET_UNSET_FLAGS(window, GNT_WIDGET_NO_BORDER); va_start(args, fmt); str = g_strdup_vprintf(fmt, args); va_end(args); gnt_box_add_widget(GNT_BOX(window), gnt_label_new_with_format(str, GNT_TEXT_FLAG_HIGHLIGHT)); g_free(str); gnt_widget_size_request(window); gnt_widget_get_size(window, &w, &h); for (i = 0; i < MAX_COLS && gpsy[i] + h >= getmaxy(stdscr) ; ++i) ; if (i >= MAX_COLS) { purple_debug_warning("GntGf", "Dude, that's way too many popups\n"); gnt_widget_destroy(window); return; } toast = g_new0(GntToast, 1); toast->window = window; toast->column = i; gpsy[i] += h; if (w > gpsw[i]) { if (i == 0) gpsw[i] = w; else gpsw[i] = gpsw[i - 1] + w + 1; } if (i == 0 || (w + gpsw[i - 1] >= getmaxx(stdscr))) { /* if it's going to be too far left, overlap. */ gnt_widget_set_position(window, getmaxx(stdscr) - w - 1, getmaxy(stdscr) - gpsy[i] - 1); } else { gnt_widget_set_position(window, getmaxx(stdscr) - gpsw[i - 1] - w - 1, getmaxy(stdscr) - gpsy[i] - 1); } gnt_widget_draw(window); toast->timer = purple_timeout_add_seconds(4, (GSourceFunc)remove_toaster, toast); toasters = g_list_prepend(toasters, toast); }
static gboolean location_key_pressed(GntTree *tree, const char *key, GntFileSel *sel) { char *path; char *str; #if 0 int count; glob_t gl; struct stat st; int glob_ret; #endif if (strcmp(key, "\r") && strcmp(key, "\n")) return FALSE; str = (char*)gnt_entry_get_text(GNT_ENTRY(sel->location)); if (*str == G_DIR_SEPARATOR) path = g_strdup(str); else path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", sel->current, str); str = process_path(path); g_free(path); path = str; if (gnt_file_sel_set_current_location(sel, path)) goto success; path = g_path_get_dirname(str); g_free(str); if (!gnt_file_sel_set_current_location(sel, path)) { g_free(path); return FALSE; } #if 0 /* XXX: there needs to be a way to allow other methods for globbing, * like the read_fn stuff. */ glob_ret = glob(path, GLOB_MARK, NULL, &gl); if (!glob_ret) { /* XXX: do something with the return value */ char *loc = g_path_get_dirname(gl.gl_pathv[0]); stat(gl.gl_pathv[0], &st); gnt_file_sel_set_current_location(sel, loc); /* XXX: check the return value */ g_free(loc); if (!S_ISDIR(st.st_mode) && !sel->dirsonly) { gnt_tree_remove_all(GNT_TREE(sel->files)); for (count = 0; count < gl.gl_pathc; count++) { char *tmp = process_path(gl.gl_pathv[count]); loc = g_path_get_dirname(tmp); if (g_utf8_collate(sel->current, loc) == 0) { char *base = g_path_get_basename(tmp); char size[128]; snprintf(size, sizeof(size), "%ld", (long)st.st_size); gnt_tree_add_row_after(GNT_TREE(sel->files), base, gnt_tree_create_row(GNT_TREE(sel->files), base, size, ""), NULL, NULL); } g_free(loc); g_free(tmp); } gnt_widget_draw(sel->files); } } else if (sel->files) { gnt_tree_remove_all(GNT_TREE(sel->files)); gnt_widget_draw(sel->files); } globfree(&gl); #endif success: g_free(path); return TRUE; }
void gnt_screen_rename_widget(GntWidget *widget, const char *text) { gnt_box_set_title(GNT_BOX(widget), text); gnt_widget_draw(widget); gnt_wm_update_window(wm, widget); }
static gboolean gnt_menu_key_pressed(GntWidget *widget, const char *text) { GntMenu *menu = GNT_MENU(widget); guint current = menu->selected; if (menu->submenu) { GntMenu *sub = menu; do sub = sub->submenu; while (sub->submenu); if (gnt_widget_key_pressed(GNT_WIDGET(sub), text)) return TRUE; if (menu->type != GNT_MENU_TOPLEVEL) return FALSE; } if ((text[0] == 27 && text[1] == 0) || (menu->type != GNT_MENU_TOPLEVEL && strcmp(text, GNT_KEY_LEFT) == 0)) { /* Escape closes menu */ GntMenu *par = menu->parentmenu; if (par != NULL) { par->submenu = NULL; gnt_widget_hide(widget); } else gnt_widget_hide(widget); if (par && par->type == GNT_MENU_TOPLEVEL) gnt_menu_key_pressed(GNT_WIDGET(par), text); return TRUE; } if (menu->type == GNT_MENU_TOPLEVEL) { GntMenuItem *item; GList *it; if (strcmp(text, GNT_KEY_LEFT) == 0) { do { if (menu->selected == 0) menu->selected = g_list_length(menu->list) - 1; else menu->selected--; it = g_list_nth(menu->list, menu->selected); item = it ? it->data : NULL; } while (!gnt_menuitem_is_visible(item)); } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { do { menu->selected++; if (menu->selected >= g_list_length(menu->list)) menu->selected = 0; it = g_list_nth(menu->list, menu->selected); item = it ? it->data : NULL; } while (!gnt_menuitem_is_visible(item)); } else if (strcmp(text, GNT_KEY_ENTER) == 0 || strcmp(text, GNT_KEY_DOWN) == 0) { gnt_widget_activate(widget); } if (current != menu->selected) { GntMenu *sub = menu->submenu; if (sub) gnt_widget_hide(GNT_WIDGET(sub)); show_submenu(menu); gnt_widget_draw(widget); return TRUE; } } else { if (text[1] == '\0') { if (check_for_trigger(menu, text[0])) return TRUE; } else if (strcmp(text, GNT_KEY_RIGHT) == 0) { GntMenuItem *item = gnt_tree_get_selection_data(GNT_TREE(menu)); if (item && item->submenu) { menuitem_activate(menu, item); return TRUE; } } if (gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text)) return TRUE; return org_key_pressed(widget, text); } return gnt_bindable_perform_action_key(GNT_BINDABLE(widget), text); }