Gracefully handle unset history and search engines
So app mode actually fails to search reliably and not by accident.
This commit is contained in:
parent
150082a6df
commit
fc8d0a1179
2 changed files with 24 additions and 22 deletions
|
@ -383,6 +383,8 @@ katze_array_find_token (KatzeArray* array,
|
|||
guint i;
|
||||
gpointer item;
|
||||
|
||||
g_return_val_if_fail (KATZE_IS_ARRAY (array), NULL);
|
||||
|
||||
i = 0;
|
||||
while ((item = g_list_nth_data (array->items, i++)))
|
||||
{
|
||||
|
|
|
@ -3511,14 +3511,10 @@ _action_location_submit_uri (GtkAction* action,
|
|||
gchar** parts;
|
||||
gchar* keywords = NULL;
|
||||
const gchar* search_uri = NULL;
|
||||
time_t now;
|
||||
gint64 day;
|
||||
sqlite3* db;
|
||||
static sqlite3_stmt* statement = NULL;
|
||||
|
||||
/* Do we have a keyword and a string? */
|
||||
parts = g_strsplit (stripped_uri, " ", 2);
|
||||
if (parts[0])
|
||||
if (parts[0] && browser->search_engines)
|
||||
{
|
||||
KatzeItem* item;
|
||||
if ((item = katze_array_find_token (browser->search_engines, parts[0])))
|
||||
|
@ -3538,26 +3534,30 @@ _action_location_submit_uri (GtkAction* action,
|
|||
}
|
||||
new_uri = sokoke_search_uri (search_uri, keywords);
|
||||
|
||||
now = time (NULL);
|
||||
day = sokoke_time_t_to_julian (&now);
|
||||
|
||||
db = g_object_get_data (G_OBJECT (browser->history), "db");
|
||||
if (!statement)
|
||||
if (browser->history != NULL)
|
||||
{
|
||||
const gchar* sqlcmd;
|
||||
sqlcmd = "INSERT INTO search (keywords, uri, day) VALUES (?,?,?)";
|
||||
sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &statement, NULL);
|
||||
}
|
||||
sqlite3_bind_text (statement, 1, keywords, -1, 0);
|
||||
sqlite3_bind_text (statement, 2, search_uri, -1, 0);
|
||||
sqlite3_bind_int64 (statement, 3, day);
|
||||
time_t now = time (NULL);
|
||||
gint64 day = sokoke_time_t_to_julian (&now);
|
||||
sqlite3* db = g_object_get_data (G_OBJECT (browser->history), "db");
|
||||
static sqlite3_stmt* statement = NULL;
|
||||
|
||||
if (sqlite3_step (statement) != SQLITE_DONE)
|
||||
g_printerr (_("Failed to insert new history item: %s\n"),
|
||||
if (!statement)
|
||||
{
|
||||
const gchar* sqlcmd;
|
||||
sqlcmd = "INSERT INTO search (keywords, uri, day) VALUES (?,?,?)";
|
||||
sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &statement, NULL);
|
||||
}
|
||||
sqlite3_bind_text (statement, 1, keywords, -1, 0);
|
||||
sqlite3_bind_text (statement, 2, search_uri, -1, 0);
|
||||
sqlite3_bind_int64 (statement, 3, day);
|
||||
|
||||
if (sqlite3_step (statement) != SQLITE_DONE)
|
||||
g_printerr (_("Failed to insert new history item: %s\n"),
|
||||
sqlite3_errmsg (db));
|
||||
sqlite3_reset (statement);
|
||||
if (sqlite3_step (statement) == SQLITE_DONE)
|
||||
sqlite3_clear_bindings (statement);
|
||||
sqlite3_reset (statement);
|
||||
if (sqlite3_step (statement) == SQLITE_DONE)
|
||||
sqlite3_clear_bindings (statement);
|
||||
}
|
||||
|
||||
g_free (keywords);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue