Example #1
0
void nsgtk_history_init_list(void)
{
	GtkTreeIter iter;
	
	gtk_list_store_clear(history->history_list);
	gtk_list_store_clear(history->domain_list);
	
	gtk_list_store_append(history->domain_list, &iter);
	gtk_list_store_set(history->domain_list, &iter,
			DOM_DOMAIN, domainAll,
			DOM_LASTVISIT, -2,
			DOM_TOTALVISITS, -2,
			DOM_HAS_SITES, TRUE,
			-1);
	
	urldb_iterate_entries(nsgtk_history_add_internal);
}
Example #2
0
bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key)
{
	wimp_w			parent;
	wimp_window_state	state;
	char			*match_url;
	const char		*url;
	int			old_selection;
	int			height;
	os_error		*error;
	bool			currently_open;

	assert(toolbar != NULL);
	parent = ro_toolbar_get_parent_window(toolbar);

	/* we must have a toolbar/url bar */
	if (!ro_toolbar_get_display_url(toolbar) ||
	    (!nsoption_bool(url_suggestion))) {
		ro_gui_url_complete_close();
		return false;
	}

	/* if we are currently active elsewhere, remove the previous window */
	currently_open = ((parent == url_complete_parent) &&
			(url_complete_matches_available > 0));
	if (parent != url_complete_parent)
		ro_gui_url_complete_close();

	/* forcibly open on down keys */
	if ((!currently_open) && (url_complete_matched_string)) {
		switch (key) {
			case IS_WIMP_KEY | wimp_KEY_DOWN:
			case IS_WIMP_KEY | wimp_KEY_PAGE_DOWN:
			case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_DOWN:
				free(url_complete_matched_string);
				url_complete_matched_string = NULL;
		}
	}


	/* get the text to match */
	url_complete_parent = parent;
	url = ro_toolbar_get_url(toolbar);
	match_url = (url != NULL) ? strdup(url) : NULL;
	if (match_url == NULL) {
		ro_gui_url_complete_close();
		return false;
	}

	/* if the text to match has changed then update it */
	if ((!url_complete_matched_string) ||
			(strcmp(match_url, url_complete_matched_string))) {

		/* memorize the current matches */
		int i;
		int lines = MAXIMUM_VISIBLE_LINES;
		if (lines > url_complete_matches_available)
			lines = url_complete_matches_available;
		if (url_complete_matches) {
			for (i = 0; i < MAXIMUM_VISIBLE_LINES; i++) {
				if (i < lines) {
					url_complete_redraw[i] =
						url_complete_matches[i];
				} else {
					url_complete_redraw[i] = NULL;
				}
			}
		}

		/* our selection gets wiped */
		error = xwimp_force_redraw(dialog_url_complete,
				0,
				-(url_complete_matches_selection + 1) * 44,
				65536, -url_complete_matches_selection * 44);
		if (error) {
			LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
			ro_warn_user("WimpError", error->errmess);
		}

		/* clear our state */
		free(url_complete_original_url);
		free(url_complete_matched_string);
		url_complete_matched_string = match_url;
		url_complete_original_url = NULL;
		url_complete_matches_available = 0;
		url_complete_matches_selection = -1;
		url_complete_keypress_selection = -1;

		/* get some initial memory */
		if (!url_complete_matches) {
			url_complete_matches = malloc(64 * sizeof(char *));
			if (!url_complete_matches) {
				ro_gui_url_complete_close();
				return false;
			}
			url_complete_matches_allocated = 64;
		}

		/* find matches */
		url_complete_memory_exhausted = false;
		if (strlen(match_url) == 0)
			urldb_iterate_entries(url_complete_callback);
		else
			urldb_iterate_partial(match_url, url_complete_callback);
		if ((url_complete_memory_exhausted) ||
				(url_complete_matches_available == 0)) {
			ro_gui_url_complete_close();
			return false;
		}

		/* update the window */
		state.w = parent;
		error = xwimp_get_window_state(&state);
		if (error) {
			LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
			ro_warn_user("WimpError", error->errmess);
			return false;
		}
		url_complete_matches_reset = true;
		ro_gui_url_complete_resize(toolbar, PTR_WIMP_OPEN(&state));
		url_complete_matches_reset = false;

		/* redraw the relevant bits of the window */
		lines = MAXIMUM_VISIBLE_LINES;
		if (lines > url_complete_matches_available)
			lines = url_complete_matches_available;
		for (i = 0; i < lines; i++) {
			if (url_complete_redraw[i] !=
					url_complete_matches[i]) {
				error = xwimp_force_redraw(dialog_url_complete,
					0, -(i + 1) * 44, 65536, -i * 44);
				if (error) {
					LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
					ro_warn_user("WimpError",
							error->errmess);
				}
			}
		}
	} else {
		free(match_url);
	}

	/* handle keypresses */
	if (!currently_open)
		return false;

	old_selection = url_complete_matches_selection;

	switch (key) {
		case IS_WIMP_KEY | wimp_KEY_UP:
			url_complete_matches_selection--;
			break;
		case IS_WIMP_KEY | wimp_KEY_DOWN:
			url_complete_matches_selection++;
			break;
		case IS_WIMP_KEY | wimp_KEY_PAGE_UP:
			url_complete_matches_selection -=
					MAXIMUM_VISIBLE_LINES;
			break;
		case IS_WIMP_KEY | wimp_KEY_PAGE_DOWN:
			url_complete_matches_selection +=
					MAXIMUM_VISIBLE_LINES;
			break;
		case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_UP:
			url_complete_matches_selection = 0;
			break;
		case IS_WIMP_KEY | wimp_KEY_CONTROL | wimp_KEY_DOWN:
			url_complete_matches_selection = 65536;
			break;
	}

	if (url_complete_matches_selection >
			url_complete_matches_available - 1)
		url_complete_matches_selection =
				url_complete_matches_available - 1;
	else if (url_complete_matches_selection < -1)
		url_complete_matches_selection = -1;

	if (old_selection == url_complete_matches_selection)
		return false;

	error = xwimp_force_redraw(dialog_url_complete,
			0, -(old_selection + 1) * 44,
			65536, -old_selection * 44);
	if (error) {
		LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
	}

	error = xwimp_force_redraw(dialog_url_complete,
			0, -(url_complete_matches_selection + 1) * 44,
			65536, -url_complete_matches_selection * 44);
	if (error) {
		LOG("xwimp_force_redraw: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
	}

	if (old_selection == -1) {
		free(url_complete_original_url);
		url_complete_original_url = malloc(strlen(url) + 1);
		if (!url_complete_original_url)
			return false;
		strcpy(url_complete_original_url, url);
	}

	if (url_complete_matches_selection == -1) {
		ro_toolbar_set_url(toolbar,
				url_complete_original_url, true, false);
	} else {
		ro_toolbar_set_url(toolbar,
				nsurl_access(url_complete_matches[
					url_complete_matches_selection]),
				true, false);
		free(url_complete_matched_string);
		url_complete_matched_string = strdup(nsurl_access(
					url_complete_matches[
					url_complete_matches_selection]));
	}
	url_complete_keypress_selection = url_complete_matches_selection;

	/* auto-scroll */
	state.w = dialog_url_complete;
	error = xwimp_get_window_state(&state);
	if (error) {
		LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
		return true;
	}

	if (state.yscroll < -(url_complete_matches_selection * 44))
		state.yscroll = -(url_complete_matches_selection * 44);
	height = state.visible.y1 - state.visible.y0;
	if (state.yscroll - height >
			-((url_complete_matches_selection + 1) * 44))
		state.yscroll =
			-((url_complete_matches_selection + 1) * 44) + height;

	error = xwimp_open_window(PTR_WIMP_OPEN(&state));
	if (error) {
		LOG("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess);
		ro_warn_user("WimpError", error->errmess);
		return true;
	}

	return true;
}
/**
 * Initialise global history tree
 */
void ro_gui_global_history_initialise(void)
{
	char s[MAXIMUM_URL_LENGTH];
	FILE *fp;

	/* create our window */
	global_history_window = ro_gui_dialog_create("tree");
	ro_gui_set_window_title(global_history_window,
			messages_get("GlobalHistory"));
	ro_gui_wimp_event_register_redraw_window(global_history_window,
			ro_gui_tree_redraw);
	ro_gui_wimp_event_register_open_window(global_history_window,
			ro_gui_tree_open);
	ro_gui_wimp_event_register_mouse_click(global_history_window,
			ro_gui_global_history_click);

	/* Create an empty tree */
	global_history_tree = calloc(sizeof(struct tree), 1);
	if (!global_history_tree) {
		warn_user("NoMemory", 0);
		return;
	}
	global_history_tree->root = tree_create_folder_node(NULL, "Root");
	if (!global_history_tree->root) {
		warn_user("NoMemory", 0);
		free(global_history_tree);
		global_history_tree = NULL;
		return;
	}
	global_history_tree->root->expanded = true;
	ro_gui_global_history_initialise_nodes();
	global_history_tree->handle = (int)global_history_window;
	global_history_tree->movable = false;
	ro_gui_wimp_event_set_user_data(global_history_window,
			global_history_tree);
	ro_gui_wimp_event_register_keypress(global_history_window,
			ro_gui_tree_keypress);

	/* Create our toolbar */
	global_history_tree->toolbar = ro_gui_theme_create_toolbar(NULL,
			THEME_HISTORY_TOOLBAR);
	if (global_history_tree->toolbar)
		ro_gui_theme_attach_toolbar(global_history_tree->toolbar,
				global_history_window);

	/* load recent URLs */
	fp = fopen(option_recent_path, "r");
	if (!fp)
		LOG(("Failed to open file '%s' for reading",
				option_recent_path));
	else {
		while (fgets(s, MAXIMUM_URL_LENGTH, fp)) {
			if (s[strlen(s) - 1] == '\n')
				s[strlen(s) - 1] = '\0';
			global_history_add_recent(s);
		}
		fclose(fp);
	}

	global_history_init = true;
	urldb_iterate_entries(global_history_add_internal);
	global_history_init = false;
	tree_initialise(global_history_tree);
}
Example #4
0
/* Exported interface, documented in global_history.h */
nserror global_history_init(struct core_window_callback_table *cw_t,
		void *core_window_handle)
{
	nserror err;

	LOG("Loading global history");

	/* Init. global history treeview time */
	err = global_history_initialise_time();
	if (err != NSERROR_OK) {
		gh_ctx.tree = NULL;
		return err;
	}

	/* Init. global history treeview entry fields */
	err = global_history_initialise_entry_fields();
	if (err != NSERROR_OK) {
		gh_ctx.tree = NULL;
		return err;
	}

	/* Load the entries */
	urldb_iterate_entries(global_history_add_entry);

	/* Create the global history treeview */
	err = treeview_create(&gh_ctx.tree, &gh_tree_cb_t,
			N_FIELDS, gh_ctx.fields,
			cw_t, core_window_handle,
			TREEVIEW_NO_MOVES | TREEVIEW_DEL_EMPTY_DIRS);
	if (err != NSERROR_OK) {
		gh_ctx.tree = NULL;
		return err;
	}

	/* Ensure there is a folder for today */
	err = global_history_create_dir(GH_TODAY);
	if (err != NSERROR_OK) {
		return err;
	}

	/* Add the history to the treeview */
	err = global_history_init_entries();
	if (err != NSERROR_OK) {
		return err;
	}

	/* Expand the "Today" folder node */
	err = treeview_node_expand(gh_ctx.tree,
			gh_ctx.folders[GH_TODAY].folder);
	if (err != NSERROR_OK) {
		return err;
	}

	/* History tree is built
	 * We suppress the treeview height callback on entry insertion before
	 * the treeview is built. */
	gh_ctx.built = true;

	/* Inform client of window height */
	treeview_get_height(gh_ctx.tree);

	LOG("Loaded global history");

	return NSERROR_OK;
}