Example #1
0
static void
selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
{
	PurplePlugin *plugin = current;
	char *text;
	GList *list = NULL, *iter = NULL;

	if (!plugin)
		return;

	/* If the selected plugin was unseen before, mark it as seen. But save the list
	 * only when the plugin list is closed. So if the user enables a plugin, and it
	 * crashes, it won't get marked as seen so the user can fix the bug and still
	 * quickly find the plugin in the list.
	 * I probably mean 'plugin developers' by 'users' here. */
	list = g_object_get_data(G_OBJECT(widget), "seen-list");
	if (list)
		iter = g_list_find_custom(list, plugin->path, (GCompareFunc)strcmp);
	if (!iter) {
		list = g_list_prepend(list, g_strdup(plugin->path));
		g_object_set_data(G_OBJECT(widget), "seen-list", list);
	}

	/* XXX: Use formatting and stuff */
	gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot));
	text = g_strdup_printf(_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n"),
			SAFE(_(plugin->info->name)), SAFE(_(plugin->info->version)), SAFE(_(plugin->info->description)),
			SAFE(_(plugin->info->author)), SAFE(_(plugin->info->homepage)), SAFE(plugin->path));
	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot),
			text, GNT_TEXT_FLAG_NORMAL);
	gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0);
	g_free(text);
	decide_conf_button(plugin);
}
Example #2
0
static PurpleCmdRet
lastlog_cb(PurpleConversation *conv, const char *cmd, char **args, char **error, gpointer null)
{
	FinchConv *ggconv = FINCH_CONV(conv);
	char **strings = g_strsplit(GNT_TEXT_VIEW(ggconv->tv)->string->str, "\n", 0);
	GntWidget *win, *tv;
	int i, j;

	win = gnt_window_new();
	gnt_box_set_title(GNT_BOX(win), _("Lastlog"));

	tv = gnt_text_view_new();
	gnt_box_add_widget(GNT_BOX(win), tv);

	gnt_widget_show(win);

	for (i = 0; strings[i]; i++) {
		if (strstr(strings[i], args[0]) != NULL) {
			char **finds = g_strsplit(strings[i], args[0], 0);
			for (j = 0; finds[j]; j++) {
				if (j)
					gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), args[0], GNT_TEXT_FLAG_BOLD);
				gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), finds[j], GNT_TEXT_FLAG_NORMAL);
			}
			g_strfreev(finds);
			gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(tv), "\n", GNT_TEXT_FLAG_NORMAL);
		}
	}

	g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(window_kpress_cb), tv);
	g_strfreev(strings);
	return PURPLE_CMD_RET_OK;
}
Example #3
0
static void
selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
{
	PurplePlugin *plugin = current;
	PurplePluginInfo *info;
	char *text, *authors = NULL;
	const char * const *authorlist;
	GList *list = NULL, *iter = NULL;

	if (!plugin)
		return;

	info = purple_plugin_get_info(plugin);
	authorlist = purple_plugin_info_get_authors(info);

	if (authorlist)
		authors = g_strjoinv(", ", (gchar **)authorlist);

	/* If the selected plugin was unseen before, mark it as seen. But save the list
	 * only when the plugin list is closed. So if the user enables a plugin, and it
	 * crashes, it won't get marked as seen so the user can fix the bug and still
	 * quickly find the plugin in the list.
	 * I probably mean 'plugin developers' by 'users' here. */
	list = g_object_get_data(G_OBJECT(widget), "seen-list");
	if (list)
		iter = g_list_find_custom(list, purple_plugin_get_filename(plugin),
					(GCompareFunc)strcmp);
	if (!iter) {
		list = g_list_prepend(list, g_strdup(purple_plugin_get_filename(plugin)));
		g_object_set_data(G_OBJECT(widget), "seen-list", list);
	}

	/* XXX: Use formatting and stuff */
	gnt_text_view_clear(GNT_TEXT_VIEW(plugins.aboot));
	text = g_strdup_printf((g_strv_length((gchar **)authorlist) > 1 ?
			_("Name: %s\nVersion: %s\nDescription: %s\nAuthors: %s\nWebsite: %s\nFilename: %s\n") :
			_("Name: %s\nVersion: %s\nDescription: %s\nAuthor: %s\nWebsite: %s\nFilename: %s\n")),
			SAFE(_(purple_plugin_info_get_name(info))),
			SAFE(_(purple_plugin_info_get_version(info))),
			SAFE(_(purple_plugin_info_get_description(info))),
			SAFE(authors),
			SAFE(_(purple_plugin_info_get_website(info))),
			SAFE(purple_plugin_get_filename(plugin)));

	gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(plugins.aboot),
			text, GNT_TEXT_FLAG_NORMAL);
	gnt_text_view_scroll(GNT_TEXT_VIEW(plugins.aboot), 0);

	g_free(text);
	g_free(authors);

	decide_conf_button(plugin);
}
Example #4
0
static void url_fetched(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, gpointer _data)
{
	CbInfo *data = (CbInfo *)_data;
	PurpleConversation *conv = data->conv;
	GList *convs = purple_conversations_get_all();
	const gchar *url;

	if (purple_http_response_is_successful(response)) {
		url = purple_http_response_get_data(response, NULL);
		g_hash_table_insert(tinyurl_cache, data->original_url, g_strdup(url));
	} else {
		url = _("Error while querying TinyURL");
		g_free(data->original_url);
	}

	/* ensure the conversation still exists */
	for (; convs; convs = convs->next) {
		if ((PurpleConversation *)(convs->data) == conv) {
			FinchConv *fconv = FINCH_CONV(conv);
			gchar *str = g_strdup_printf("[%d] %s", data->num, url);
			GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);
			gnt_text_view_tag_change(tv, data->tag, str, FALSE);
			g_free(str);
			g_free(data->tag);
			g_free(data);
			return;
		}
	}
	g_free(data->tag);
	g_free(data);
	purple_debug_info("TinyURL", "Conversation no longer exists... :(\n");
}
Example #5
0
static void
gnt_text_view_size_changed(GntWidget *widget, int w, int h)
{
	if (w != widget->priv.width && GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED)) {
		gnt_text_view_reflow(GNT_TEXT_VIEW(widget));
	}
}
Example #6
0
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;
}
Example #7
0
static void
roomlist_selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
{
	GList *iter, *field;
	PurpleRoomlistRoom *room = current;
	GntTextView *tv = GNT_TEXT_VIEW(froomlist.details);
	gboolean first = TRUE;

	gnt_text_view_clear(tv);

	if (!room)
		return;

	for (iter = purple_roomlist_room_get_fields(room),
			field = purple_roomlist_get_fields(froomlist.roomlist);
			iter && field;
			iter = iter->next, field = field->next) {
		PurpleRoomlistField *f = field->data;
		char *label = NULL;

		if (purple_roomlist_field_get_hidden(f)) {
			continue;
		}

		if (!first)
			gnt_text_view_append_text_with_flags(tv, "\n", GNT_TEXT_FLAG_NORMAL);

		gnt_text_view_append_text_with_flags(tv,
				purple_roomlist_field_get_label(f), GNT_TEXT_FLAG_BOLD);
		gnt_text_view_append_text_with_flags(tv, ": ", GNT_TEXT_FLAG_BOLD);

		switch (purple_roomlist_field_get_type(f)) {
			case PURPLE_ROOMLIST_FIELD_BOOL:
				label = g_strdup(iter->data ? "True" : "False");
				break;
			case PURPLE_ROOMLIST_FIELD_INT:
				label = g_strdup_printf("%d", (int)iter->data);
				break;
			case PURPLE_ROOMLIST_FIELD_STRING:
				label = g_strdup(iter->data);
				break;
		}
		gnt_text_view_append_text_with_flags(tv, label, GNT_TEXT_FLAG_NORMAL);
		g_free(label);
		first = FALSE;
	}

	if (purple_roomlist_room_get_type(room) == PURPLE_ROOMLIST_ROOMTYPE_CATEGORY) {
		if (!first)
			gnt_text_view_append_text_with_flags(tv, "\n", GNT_TEXT_FLAG_NORMAL);
		gnt_text_view_append_text_with_flags(tv,
				_("Hit 'Enter' to find more rooms of this category."),
				GNT_TEXT_FLAG_NORMAL);
	}
}
Example #8
0
static void
gnt_text_view_destroy(GntWidget *widget)
{
	GntTextView *view = GNT_TEXT_VIEW(widget);
	view->list = g_list_first(view->list);
	g_list_foreach(view->list, free_text_line, NULL);
	g_list_free(view->list);
	g_list_foreach(view->tags, free_tag, NULL);
	g_list_free(view->tags);
	g_string_free(view->string, TRUE);
}
Example #9
0
/* Frees 'urls' */
static void
process_urls(PurpleConversation *conv, GList *urls)
{
	GList *iter;
	int c;
	FinchConv *fconv = FINCH_CONV(conv);
	GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);

	for (iter = urls, c = 1; iter; iter = iter->next, c++) {
		int i;
		CbInfo *cbdata;
		gchar *url, *str;
		gchar *original_url;
		const gchar *tiny_url;

		i = gnt_text_view_get_lines_below(tv);

		original_url = purple_unescape_html((char *)iter->data);
		tiny_url = g_hash_table_lookup(tinyurl_cache, original_url);
		if (tiny_url) {
			gchar *str = g_strdup_printf("\n[%d] %s", c, tiny_url);

			g_free(original_url);
			gnt_text_view_append_text_with_flags(tv, str, GNT_TEXT_FLAG_DIM);
			if (i == 0)
				gnt_text_view_scroll(tv, 0);
			g_free(str);
			continue;
		}
		cbdata = g_new(CbInfo, 1);
		cbdata->num = c;
		cbdata->original_url = original_url;
		cbdata->tag = g_strdup_printf("%s%d", "tiny_", tag_num++);
		cbdata->conv = conv;
		if (g_ascii_strncasecmp(original_url, "http://", 7) && g_ascii_strncasecmp(original_url, "https://", 8)) {
			url = g_strdup_printf("%shttp%%3A%%2F%%2F%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url));
		} else {
			url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(original_url));
		}
		purple_http_get(NULL, url_fetched, cbdata, url);
		str = g_strdup_printf(_("\nFetching TinyURL..."));
		gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag);
		g_free(str);
		if (i == 0)
			gnt_text_view_scroll(tv, 0);
		g_free(iter->data);
		g_free(url);
	}
	g_list_free(urls);
}
Example #10
0
static void *
finch_notify_userinfo(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info)
{
	char *primary;
	char *info;
	void *ui_handle;
	char *key = userinfo_hash(purple_connection_get_account(gc), who);

	info = purple_notify_user_info_get_xhtml(user_info);

	ui_handle = g_hash_table_lookup(userinfo, key);
	if (ui_handle != NULL) {
		GntTextView *msg = GNT_TEXT_VIEW(g_object_get_data(G_OBJECT(ui_handle), "info-widget"));
		char *strip = purple_markup_strip_html(info);
		int tvw, tvh, width, height, ntvw, ntvh;

		while (GNT_WIDGET(ui_handle)->parent)
			ui_handle = GNT_WIDGET(ui_handle)->parent;
		gnt_widget_get_size(GNT_WIDGET(ui_handle), &width, &height);
		gnt_widget_get_size(GNT_WIDGET(msg), &tvw, &tvh);

		gnt_text_view_clear(msg);
		if (!gnt_util_parse_xhtml_to_textview(info, msg))
			gnt_text_view_append_text_with_flags(msg, strip, GNT_TEXT_FLAG_NORMAL);
		gnt_text_view_scroll(msg, 0);
		gnt_util_get_text_bound(strip, &ntvw, &ntvh);
		ntvw += 3;
		ntvh++;

		gnt_screen_resize_widget(GNT_WIDGET(ui_handle), width + MAX(0, ntvw - tvw), height + MAX(0, ntvh - tvh));
		g_free(strip);
		g_free(key);
	} else {
		primary = g_strdup_printf(_("Info for %s"), who);
		ui_handle = finch_notify_formatted(_("Buddy Information"), primary, NULL, info);
		g_hash_table_insert(userinfo, key, ui_handle);
		g_free(primary);
		g_signal_connect(G_OBJECT(ui_handle), "destroy", G_CALLBACK(remove_userinfo), key);
	}

	g_free(info);
	return ui_handle;
}
Example #11
0
static void
finch_debug_print(PurpleDebugLevel level, const char *category,
		const char *args)
{
	if (debug.window && !debug.paused && match_string(category, args))
	{
		int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview));
		GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;
		const char *mdate;
		time_t mtime = time(NULL);
		mdate = purple_utf8_strftime("%H:%M:%S ", localtime(&mtime));
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				mdate, flag);

		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				category, GNT_TEXT_FLAG_BOLD);
		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
				": ", GNT_TEXT_FLAG_BOLD);

		switch (level)
		{
			case PURPLE_DEBUG_WARNING:
				flag |= GNT_TEXT_FLAG_UNDERLINE;
			case PURPLE_DEBUG_ERROR:
			case PURPLE_DEBUG_FATAL:
				flag |= GNT_TEXT_FLAG_BOLD;
				break;
			default:
				break;
		}

		gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag);
		if (pos <= 1)
			gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0);
	}
}
Example #12
0
void finch_plugins_show_all(void)
{
	GntWidget *window, *tree, *box, *aboot, *button;
	GList *plugin_list, *iter;
	GList *seen;

	if (plugins.window) {
		gnt_window_present(plugins.window);
		return;
	}

	purple_plugins_refresh();

	plugins.window = window = gnt_vbox_new(FALSE);
	gnt_box_set_toplevel(GNT_BOX(window), TRUE);
	gnt_box_set_title(GNT_BOX(window), _("Plugins"));
	gnt_box_set_pad(GNT_BOX(window), 0);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);

	gnt_box_add_widget(GNT_BOX(window),
			gnt_label_new(_("You can (un)load plugins from the following list.")));
	gnt_box_add_widget(GNT_BOX(window), gnt_hline_new());

	box = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), box);
	gnt_box_add_widget(GNT_BOX(window), gnt_hline_new());

	gnt_box_set_pad(GNT_BOX(box), 0);
	plugins.tree = tree = gnt_tree_new();
	gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)plugin_compare);
	GNT_WIDGET_SET_FLAGS(tree, GNT_WIDGET_NO_BORDER);
	gnt_box_add_widget(GNT_BOX(box), tree);
	gnt_box_add_widget(GNT_BOX(box), gnt_vline_new());

	plugins.aboot = aboot = gnt_text_view_new();
	gnt_text_view_set_flag(GNT_TEXT_VIEW(aboot), GNT_TEXT_VIEW_TOP_ALIGN);
	gnt_widget_set_size(aboot, 40, 20);
	gnt_box_add_widget(GNT_BOX(box), aboot);

	seen = purple_prefs_get_path_list("/finch/plugins/seen");

	plugin_list = purple_plugins_find_all();
	for (iter = plugin_list; iter; iter = iter->next)
	{
		PurplePlugin *plug = PURPLE_PLUGIN(iter->data);

		if (purple_plugin_is_internal(plug))
			continue;

		gnt_tree_add_choice(GNT_TREE(tree), plug,
				gnt_tree_create_row(GNT_TREE(tree),
				purple_plugin_info_get_name(purple_plugin_get_info(plug))),
				NULL, NULL);
		gnt_tree_set_choice(GNT_TREE(tree), plug, purple_plugin_is_loaded(plug));
		if (!g_list_find_custom(seen, purple_plugin_get_filename(plug),
				(GCompareFunc)strcmp))
			gnt_tree_set_row_flags(GNT_TREE(tree), plug, GNT_TEXT_FLAG_BOLD);
	}
	g_list_free(plugin_list);

	gnt_tree_set_col_width(GNT_TREE(tree), 0, 30);
	g_signal_connect(G_OBJECT(tree), "toggled", G_CALLBACK(plugin_toggled_cb), NULL);
	g_signal_connect(G_OBJECT(tree), "selection_changed", G_CALLBACK(selection_changed), NULL);
	g_object_set_data(G_OBJECT(tree), "seen-list", seen);

	box = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), box);

#if 0
	button = gnt_button_new(_("Install Plugin..."));
	gnt_box_add_widget(GNT_BOX(box), button);
	gnt_util_set_trigger_widget(GNT_WIDGET(tree), GNT_KEY_INS, button);
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(install_plugin_cb), NULL);
#endif

	button = gnt_button_new(_("Close"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_signal_connect_swapped(G_OBJECT(button), "activate",
			G_CALLBACK(gnt_widget_destroy), window);

	plugins.conf = button = gnt_button_new(_("Configure Plugin"));
	gnt_box_add_widget(GNT_BOX(box), button);
	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(configure_plugin_cb), NULL);

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(reset_plugin_window), NULL);

	gnt_widget_show(window);

	decide_conf_button(gnt_tree_get_selection_data(GNT_TREE(tree)));
}
Example #13
0
void finch_debug_window_show()
{
	GntWidget *wid, *box, *label;

	debug.paused = FALSE;
	if (debug.window) {
		gnt_window_present(debug.window);
		return;
	}

	debug.window = gnt_vbox_new(FALSE);
	gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE);
	gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window"));
	gnt_box_set_pad(GNT_BOX(debug.window), 0);
	gnt_box_set_alignment(GNT_BOX(debug.window), GNT_ALIGN_MID);

	debug.tview = gnt_text_view_new();
	gnt_box_add_widget(GNT_BOX(debug.window), debug.tview);
	gnt_widget_set_size(debug.tview,
			purple_prefs_get_int(PREF_ROOT "/size/width"),
			purple_prefs_get_int(PREF_ROOT "/size/height"));
	g_signal_connect(G_OBJECT(debug.tview), "size_changed", G_CALLBACK(size_changed_cb), NULL);

	gnt_box_add_widget(GNT_BOX(debug.window), gnt_line_new(FALSE));

	box = gnt_hbox_new(FALSE);
	gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID);
	gnt_box_set_fill(GNT_BOX(box), FALSE);

	/* XXX: Setting the GROW_Y for the following widgets don't make sense. But right now
	 * it's necessary to make the width of the debug window resizable ... like I said,
	 * it doesn't make sense. The bug is likely in the packing in gntbox.c.
	 */
	wid = gnt_button_new(_("Clear"));
	g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(clear_debug_win), debug.tview);
	GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
	gnt_box_add_widget(GNT_BOX(box), wid);

	wid = gnt_button_new(_("Save"));
	g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(save_debug_win), debug.tview);
	GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
	gnt_box_add_widget(GNT_BOX(box), wid);

	debug.search = gnt_entry_new(purple_prefs_get_string(PREF_ROOT "/filter"));
	label = gnt_label_new(_("Filter:"));
	GNT_WIDGET_UNSET_FLAGS(label, GNT_WIDGET_GROW_X);
	gnt_box_add_widget(GNT_BOX(box), label);
	gnt_box_add_widget(GNT_BOX(box), debug.search);
	g_signal_connect(G_OBJECT(debug.search), "text_changed", G_CALLBACK(update_filter_string), NULL);

	wid = gnt_check_box_new(_("Pause"));
	g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL);
	GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
	gnt_box_add_widget(GNT_BOX(box), wid);

	gnt_box_add_widget(GNT_BOX(debug.window), box);
	GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_GROW_Y);

	gnt_widget_set_name(debug.window, "debug-window");

	g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL);
	gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(debug.tview), debug.window);
	gnt_text_view_attach_pager_widget(GNT_TEXT_VIEW(debug.tview), debug.window);

	gnt_widget_show(debug.window);
}
Example #14
0
	parent_class->destroy = gnt_text_view_destroy;
	parent_class->draw = gnt_text_view_draw;
	parent_class->map = gnt_text_view_map;
	parent_class->size_request = gnt_text_view_size_request;
	parent_class->key_pressed = gnt_text_view_key_pressed;
	parent_class->clicked = gnt_text_view_clicked;
	parent_class->size_changed = gnt_text_view_size_changed;

	GNTDEBUG;
}

static void
gnt_text_view_init(GTypeInstance *instance, gpointer class)
{
	GntWidget *widget = GNT_WIDGET(instance);
	GntTextView *view = GNT_TEXT_VIEW(widget);
	GntTextLine *line = g_new0(GntTextLine, 1);

	GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW |
            GNT_WIDGET_GROW_Y | GNT_WIDGET_GROW_X);
	widget->priv.minw = 5;
	widget->priv.minh = 2;
	view->string = g_string_new(NULL);
	view->list = g_list_append(view->list, line);

	GNTDEBUG;
}

/******************************************************************************
 * GntTextView API
 *****************************************************************************/
Example #15
0
static void
setup_roomlist(PurpleAccount *account)
{
	GntWidget *window, *tree, *hbox, *accounts;
	int iter;
	struct {
		const char *label;
		GCallback callback;
		GntWidget **widget;
	} buttons[] = {
		{_("Stop"), G_CALLBACK(fl_stop), &froomlist.stop},
		{_("Get"), G_CALLBACK(fl_get_list), &froomlist.getlist},
		{_("Add"), G_CALLBACK(fl_add_chat), &froomlist.add},
		{_("Close"), G_CALLBACK(fl_close), &froomlist.close},
		{NULL, NULL, NULL}
	};

	if (froomlist.window)
		return;

	froomlist.window = window = gnt_window_new();
	g_object_set(G_OBJECT(window), "vertical", TRUE, NULL);
	gnt_box_set_pad(GNT_BOX(window), 0);
	gnt_box_set_title(GNT_BOX(window), _("Room List"));
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);

	froomlist.accounts = accounts = gnt_combo_box_new();
	reset_account_list(account);
	gnt_box_add_widget(GNT_BOX(window), accounts);
	g_signal_connect(G_OBJECT(accounts), "selection-changed",
			G_CALLBACK(roomlist_account_changed), NULL);
	froomlist.account = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(accounts));

	froomlist.tree = tree = gnt_tree_new_with_columns(2);
	gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
	g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(roomlist_activated), NULL);
	gnt_tree_set_column_titles(GNT_TREE(tree), _("Name"), "");
	gnt_tree_set_show_separator(GNT_TREE(tree), FALSE);
	gnt_tree_set_col_width(GNT_TREE(tree), 1, 1);
	gnt_tree_set_column_resizable(GNT_TREE(tree), 1, FALSE);
	gnt_tree_set_search_column(GNT_TREE(tree), 0);

	gnt_box_add_widget(GNT_BOX(window), tree);

	froomlist.details = gnt_text_view_new();
	gnt_text_view_set_flag(GNT_TEXT_VIEW(froomlist.details), GNT_TEXT_VIEW_TOP_ALIGN);
	gnt_box_add_widget(GNT_BOX(window), froomlist.details);
	gnt_widget_set_size(froomlist.details, -1, 8);

	hbox = gnt_hbox_new(FALSE);
	gnt_box_add_widget(GNT_BOX(window), hbox);

	for (iter = 0; buttons[iter].label; iter++) {
		GntWidget *button = gnt_button_new(buttons[iter].label);
		gnt_box_add_widget(GNT_BOX(hbox), button);
		g_signal_connect(G_OBJECT(button), "activate", buttons[iter].callback, NULL);
		*buttons[iter].widget = button;
		gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(froomlist.details), button);
	}

	g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(roomlist_selection_changed), NULL);

	g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(unset_roomlist), NULL);
}
Example #16
0
static void *
finch_notify_common(PurpleNotifyType ntype, PurpleNotifyMsgType msgtype,
	const char *title, const char *primary, const char *secondary)
{
	GntWidget *window, *button;
	GntTextFormatFlags pf = 0, sf = 0;

	switch (msgtype)
	{
		case PURPLE_NOTIFY_MSG_ERROR:
			sf |= GNT_TEXT_FLAG_BOLD;
			/* fall through */
		case PURPLE_NOTIFY_MSG_WARNING:
			pf |= GNT_TEXT_FLAG_UNDERLINE;
			/* fall through */
		case PURPLE_NOTIFY_MSG_INFO:
			pf |= GNT_TEXT_FLAG_BOLD;
			break;
	}

	window = gnt_window_box_new(FALSE, TRUE);
	gnt_box_set_title(GNT_BOX(window), title);
	gnt_box_set_fill(GNT_BOX(window), FALSE);
	gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
	gnt_box_set_pad(GNT_BOX(window), 0);

	if (primary)
		gnt_box_add_widget(GNT_BOX(window),
				gnt_label_new_with_format(primary, pf));

	button = gnt_button_new(_("OK"));

	if (secondary) {
		GntWidget *msg;
		if (ntype == PURPLE_NOTIFY_FORMATTED) {
			int width = -1, height = -1;
			char *plain = (char*)secondary;
			msg = gnt_text_view_new();
			gnt_text_view_set_flag(GNT_TEXT_VIEW(msg), GNT_TEXT_VIEW_TOP_ALIGN | GNT_TEXT_VIEW_NO_SCROLL);

			plain = purple_markup_strip_html(secondary);
			if (!gnt_util_parse_xhtml_to_textview(secondary, GNT_TEXT_VIEW(msg)))
				gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(msg), plain, sf);

			gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(msg), button);
			gnt_util_get_text_bound(plain, &width, &height);
			gnt_widget_set_size(msg, width + 3, height + 1);
			if (plain != secondary)
				g_free(plain);
		} else {
			msg = gnt_label_new_with_format(secondary, sf);
		}
		gnt_box_add_widget(GNT_BOX(window), msg);
		g_object_set_data(G_OBJECT(window), "info-widget", msg);
	}

	gnt_box_add_widget(GNT_BOX(window), button);
	g_signal_connect_swapped(G_OBJECT(button), "activate",
			G_CALLBACK(gnt_widget_destroy), window);
	g_signal_connect(G_OBJECT(window), "destroy",
			G_CALLBACK(notify_msg_window_destroy_cb), GINT_TO_POINTER(ntype));

	gnt_widget_show(window);
	return window;
}
Example #17
0
static void
gnt_text_view_draw(GntWidget *widget)
{
	GntTextView *view = GNT_TEXT_VIEW(widget);
	int n;
	int i = 0;
	GList *lines;
	int rows, scrcol;
	int comp = 0;          /* Used for top-aligned text */
	gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL);

	wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL));
	werase(widget->window);

	n = g_list_length(view->list);
	if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) &&
			n < widget->priv.height) {
		GList *now = view->list;
		comp = widget->priv.height - n;
		view->list = g_list_nth_prev(view->list, comp);
		if (!view->list) {
			view->list = g_list_first(now);
			comp = widget->priv.height - g_list_length(view->list);
		} else {
			comp = 0;
		}
	}

	for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next)
	{
		GList *iter;
		GntTextLine *line = lines->data;

		wmove(widget->window, widget->priv.height - 1 - i - comp, 0);

		for (iter = line->segments; iter; iter = iter->next)
		{
			GntTextSegment *seg = iter->data;
			char *end = view->string->str + seg->end;
			char back = *end;
			chtype fl = seg->flags;
			*end = '\0';
			if (select_start && select_start < view->string->str + seg->start && select_end > view->string->str + seg->end) {
				fl |= A_REVERSE;
				wattrset(widget->window, fl);
				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
			} else if (select_start && select_end &&
				((select_start >= view->string->str + seg->start && select_start <= view->string->str + seg->end) ||
				(select_end <= view->string->str + seg->end && select_start <= view->string->str + seg->start))) {
				char *cur = view->string->str + seg->start;
				while (*cur != '\0') {
					gchar *last = g_utf8_next_char(cur);
					gchar *str;
					if (cur >= select_start && cur <= select_end)
						fl |= A_REVERSE;
					else
						fl = seg->flags;
					str = g_strndup(cur, last - cur);
					wattrset(widget->window, fl);
					waddstr(widget->window, C_(str));
					g_free(str);
					cur = g_utf8_next_char(cur);
				}
			} else {
				wattrset(widget->window, fl);
				wprintw(widget->window, "%s", C_(view->string->str + seg->start));
			}
			*end = back;
		}
		wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE);
		whline(widget->window, ' ', widget->priv.width - line->length - has_scroll);
	}

	scrcol = widget->priv.width - 1;
	rows = widget->priv.height - 2;
	if (has_scroll && rows > 0)
	{
		int total = g_list_length(g_list_first(view->list));
		int showing, position, up, down;

		showing = rows * rows / total + 1;
		showing = MIN(rows, showing);

		total -= rows;
		up = g_list_length(lines);
		down = total - up;

		position = (rows - showing) * up / MAX(1, up + down);
		position = MAX((lines != NULL), position);

		if (showing + position > rows)
			position = rows - showing;

		if (showing + position == rows && view->list && view->list->prev)
			position = MAX(1, rows - 1 - showing);
		else if (showing + position < rows && view->list && !view->list->prev)
			position = rows - showing;

		mvwvline(widget->window, position + 1, scrcol,
				ACS_CKBOARD | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D), showing);
	}

	if (has_scroll) {
		mvwaddch(widget->window, 0, scrcol,
				(lines ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
		mvwaddch(widget->window, widget->priv.height - 1, scrcol,
				((view->list && view->list->prev) ? ACS_DARROW : ' ') |
					gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
	}

	wmove(widget->window, 0, 0);
}