Esempio n. 1
0
void
ephy_hosts_store_add_hosts (EphyHostsStore *store,
                            GList *hosts)
{
  EphyHistoryHost *host;
  GtkTreeIter treeiter;
  GtkTreePath *path;
  GList *iter;
#ifdef HAVE_WEBKIT2
  /* TODO: Favicons */
#else
  GdkPixbuf *favicon;
  IconLoadData *data;
  WebKitFaviconDatabase *database = webkit_get_favicon_database ();
#endif

  for (iter = hosts; iter != NULL; iter = iter->next) {
    host = (EphyHistoryHost *)iter->data;
#ifdef HAVE_WEBKIT2
    /* TODO: Favicons */
#else
    favicon = webkit_favicon_database_try_get_favicon_pixbuf (database, host->url,
                                                              FAVICON_SIZE, FAVICON_SIZE);
#endif
    gtk_list_store_insert_with_values (GTK_LIST_STORE (store),
                                       &treeiter, G_MAXINT,
                                       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,
#ifdef HAVE_WEBKIT2
                                       /* TODO: Favicons */
#else
                                       EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon,
#endif
                                       -1);
#ifdef HAVE_WEBKIT2
    /* TODO: Favicons */
#else
    if (favicon)
      g_object_unref (favicon);
    else {
      data = g_slice_new (IconLoadData);
      data->model = GTK_LIST_STORE (g_object_ref (store));
      path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &treeiter);
      data->row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
      gtk_tree_path_free (path);

      webkit_favicon_database_get_favicon_pixbuf (database, host->url,
                                                  FAVICON_SIZE, FAVICON_SIZE, NULL,
                                                  async_get_favicon_cb, data);
    }
#endif
  }
}
static void
set_row_in_model (EphyCompletionModel *model, int position, PotentialRow *row)
{
  GtkTreeIter iter;
  GtkTreePath *path;
  IconLoadData *data;
  WebKitFaviconDatabase* database;

#ifndef HAVE_WEBKIT2
  GdkPixbuf *favicon;
  database = webkit_get_favicon_database ();
#else
  database = webkit_web_context_get_favicon_database (webkit_web_context_get_default ());
#endif

  gtk_list_store_insert_with_values (GTK_LIST_STORE (model), &iter, position,
                                     EPHY_COMPLETION_TEXT_COL, row->title ? row->title : "",
                                     EPHY_COMPLETION_URL_COL, row->location,
                                     EPHY_COMPLETION_ACTION_COL, row->location,
                                     EPHY_COMPLETION_KEYWORDS_COL, row->keywords ? row->keywords : "",
                                     EPHY_COMPLETION_EXTRA_COL, row->is_bookmark,
                                     EPHY_COMPLETION_RELEVANCE_COL, row->relevance,
                                     -1);

#ifndef HAVE_WEBKIT2
  /* We try first with the try_get_favicon_pixbuf() because if the icon
     is in the DB it's faster than the async version. */
  favicon = webkit_favicon_database_try_get_favicon_pixbuf (database, row->location,
                                                            FAVICON_SIZE, FAVICON_SIZE);
  if (favicon) {
    gtk_list_store_set (GTK_LIST_STORE (model), &iter, EPHY_COMPLETION_FAVICON_COL, favicon, -1);
    g_object_unref (favicon);
    return;
  }
#endif

  data = g_slice_new (IconLoadData);
  data->model = GTK_LIST_STORE (g_object_ref(model));
  path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
  data->row_reference = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), path);
  gtk_tree_path_free (path);

#ifdef HAVE_WEBKIT2
  webkit_favicon_database_get_favicon (database, row->location,
                                       NULL, icon_loaded_cb, data);
#else
  webkit_favicon_database_get_favicon_pixbuf (database, row->location,
                                              FAVICON_SIZE, FAVICON_SIZE,
                                              NULL, icon_loaded_cb, data);
#endif
}
Esempio n. 3
0
static void
icon_loaded_cb (WebKitFaviconDatabase *database,
                const char *address,
                GtkTreeModel *model)
{
  GtkTreeIter iter;
  GdkPixbuf *favicon;
  int cmp;
  char *host_address;
  gboolean done, valid;
  SoupURI *uri;

  valid = gtk_tree_model_get_iter_first (model, &iter);

  /* If the address has a path, this icon is not for a host, so it can
     be skipped. */
  uri = soup_uri_new (address);
  done = strcmp (soup_uri_get_path (uri), "/") != 0;
  soup_uri_free (uri);

  while (valid && !done) {
    gtk_tree_model_get (model, &iter,
                        EPHY_HOSTS_STORE_COLUMN_ADDRESS, &host_address, -1);
    cmp = g_strcmp0 (host_address, address);
    g_free (host_address);

    if (cmp == 0) {
      favicon = webkit_favicon_database_try_get_favicon_pixbuf (database,
                                                                address,
                                                                FAVICON_SIZE,
                                                                FAVICON_SIZE);
      if (favicon) {
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                            EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon,
                            -1);
        g_object_unref (favicon);
      }
    }
    valid = gtk_tree_model_iter_next (model, &iter);

    /* Since the list is sorted alphanumerically, if the result of the
       comparison is > 0, there is no point in searching any
       further. */
    done = cmp >= 0;
  }
}
Esempio n. 4
0
static void
icon_changed_cb (WebKitFaviconDatabase *database,
                 const char *page_uri,
#ifdef HAVE_WEBKIT2
                 const char *favicon_uri,
#endif
                 GtkTreeModel *model)
{
  GtkTreeIter iter;
  int cmp;
  char *host_address;
  gboolean done, valid;
  SoupURI *uri;

  valid = gtk_tree_model_get_iter_first (model, &iter);

  /* If the page_uri has a path, this icon is not for a host, so it
     can be skipped. */
  uri = soup_uri_new (page_uri);
  done = strcmp (soup_uri_get_path (uri), "/") != 0;
  soup_uri_free (uri);

  while (valid && !done) {
    gtk_tree_model_get (model, &iter,
                        EPHY_HOSTS_STORE_COLUMN_ADDRESS, &host_address, -1);
    cmp = g_strcmp0 (host_address, page_uri);
    g_free (host_address);

    if (cmp == 0) {
#ifdef HAVE_WEBKIT2
      IconLoadData *data;
      GtkTreePath *path;

      data = g_slice_new (IconLoadData);
      data->model = GTK_LIST_STORE (g_object_ref (model));
      path = gtk_tree_model_get_path (model, &iter);
      data->row_reference = gtk_tree_row_reference_new (model, path);
      gtk_tree_path_free (path);

      webkit_favicon_database_get_favicon (database,
                                           page_uri,
                                           0,
                                           async_update_favicon_icon,
                                           data);
#else
      GdkPixbuf *favicon = webkit_favicon_database_try_get_favicon_pixbuf (database,
                                                                           page_uri,
                                                                           FAVICON_SIZE,
                                                                           FAVICON_SIZE);
      if (favicon) {
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                            EPHY_HOSTS_STORE_COLUMN_FAVICON, favicon,
                            -1);
        g_object_unref (favicon);
      }

#endif
    }
    valid = gtk_tree_model_iter_next (model, &iter);

    /* Since the list is sorted alphanumerically, if the result of the
       comparison is > 0, there is no point in searching any
       further. */
    done = cmp >= 0;
  }
}