EphyHistoryHost * ephy_history_service_get_host_row_from_url (EphyHistoryService *self, const gchar *url) { GList *host_locations, *l; char *hostname; EphyHistoryHost *host = NULL; host_locations = get_hostname_and_locations (url, &hostname); for (l = host_locations; l != NULL; l = l->next) { host = ephy_history_service_get_host_row (self, l->data, NULL); if (host != NULL) break; } if (host == NULL) { host = ephy_history_host_new (host_locations->data, hostname, 0, 0.0); if (!self->read_only) ephy_history_service_add_host_row (self, host); } g_free (hostname); g_list_free_full (host_locations, (GDestroyNotify)g_free); return host; }
static void history_parse_end_element (GMarkupParseContext *context, const char *element_name, gpointer user_data, GError **error) { HistoryParseData *parse_data = user_data; if (g_str_equal (element_name, "node") && parse_data) { /* Add one item to History */ EphyHistoryPageVisit *visit = ephy_history_page_visit_new (parse_data->location ? parse_data->location : "", parse_data->last_visit, EPHY_PAGE_VISIT_TYPED); g_free (visit->url->title); visit->url->title = g_strdup (parse_data->title); if (parse_data->zoom_level != 1.0) { /* Zoom levels are only stored per host in the old history, so * creating a new host here is OK. */ g_assert (!visit->url->host); visit->url->host = ephy_history_host_new (parse_data->location, parse_data->title, parse_data->visit_count, parse_data->zoom_level); } parse_data->visits = g_list_append (parse_data->visits, visit); } }
static EphyHistoryHost * create_host_from_statement (EphySQLiteStatement *statement) { EphyHistoryHost *host = ephy_history_host_new (ephy_sqlite_statement_get_column_as_string (statement, 1), ephy_sqlite_statement_get_column_as_string (statement, 2), ephy_sqlite_statement_get_column_as_int (statement, 3), ephy_sqlite_statement_get_column_as_double (statement, 4)); host->id = ephy_sqlite_statement_get_column_as_int (statement, 0); return host; }
static EphyHistoryURL * create_url_from_statement (EphySQLiteStatement *statement) { EphyHistoryURL *url = ephy_history_url_new (ephy_sqlite_statement_get_column_as_string (statement, 1), ephy_sqlite_statement_get_column_as_string (statement, 2), ephy_sqlite_statement_get_column_as_int (statement, 3), ephy_sqlite_statement_get_column_as_int (statement, 4), ephy_sqlite_statement_get_column_as_int64 (statement, 5)); url->id = ephy_sqlite_statement_get_column_as_int (statement, 0); url->host = ephy_history_host_new (NULL, NULL, 0, 0.0); url->hidden = ephy_sqlite_statement_get_column_as_int (statement, 6); url->host->id = ephy_sqlite_statement_get_column_as_int (statement, 7); url->sync_id = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 8)); return url; }
EphyHistoryHost * ephy_hosts_store_get_host_from_path (EphyHostsStore *store, GtkTreePath *path) { GtkTreeIter iter; EphyHistoryHost *host = ephy_history_host_new (NULL, NULL, 0, 1.0); gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, EPHY_HOSTS_STORE_COLUMN_ID, &host->id, EPHY_HOSTS_STORE_COLUMN_TITLE, &host->title, EPHY_HOSTS_STORE_COLUMN_ADDRESS, &host->url, EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT, &host->visit_count, -1); return host; }
EphyHistoryHost * ephy_history_service_get_host_row (EphyHistoryService *self, const gchar *host_string, EphyHistoryHost *host) { EphySQLiteStatement *statement = NULL; GError *error = NULL; g_assert (self->history_thread == g_thread_self ()); g_assert (self->history_database != NULL); if (host_string == NULL && host != NULL) host_string = host->url; g_assert (host_string || (host != NULL && host->id != -1)); if (host != NULL && host->id != -1) { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, zoom_level FROM hosts " "WHERE id=?", &error); } else { statement = ephy_sqlite_connection_create_statement (self->history_database, "SELECT id, url, title, visit_count, zoom_level FROM hosts " "WHERE url=?", &error); } if (error) { g_warning ("Could not build hosts query statement: %s", error->message); g_error_free (error); return NULL; } if (host != NULL && host->id != -1) ephy_sqlite_statement_bind_int (statement, 0, host->id, &error); else ephy_sqlite_statement_bind_string (statement, 0, host_string, &error); if (error) { g_warning ("Could not build hosts table query statement: %s", error->message); g_error_free (error); g_object_unref (statement); return NULL; } if (ephy_sqlite_statement_step (statement, &error) == FALSE) { if (error) g_error_free (error); g_object_unref (statement); return NULL; } if (host == NULL) { host = ephy_history_host_new (NULL, NULL, 0, 0.0); } else { if (host->url) g_free (host->url); if (host->title) g_free (host->title); } host->id = ephy_sqlite_statement_get_column_as_int (statement, 0); host->url = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 1)); host->title = g_strdup (ephy_sqlite_statement_get_column_as_string (statement, 2)); host->visit_count = ephy_sqlite_statement_get_column_as_int (statement, 3); host->zoom_level = ephy_sqlite_statement_get_column_as_double (statement, 4); g_object_unref (statement); return host; }