summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/general_page_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/gtk/options/general_page_gtk.cc')
-rw-r--r--chrome/browser/gtk/options/general_page_gtk.cc163
1 files changed, 67 insertions, 96 deletions
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc
index cccdcad..16a0a05 100644
--- a/chrome/browser/gtk/options/general_page_gtk.cc
+++ b/chrome/browser/gtk/options/general_page_gtk.cc
@@ -4,14 +4,16 @@
#include "chrome/browser/gtk/options/general_page_gtk.h"
+#include <set>
+#include <vector>
+
#include "app/l10n_util.h"
#include "base/callback.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/browser_list.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/custom_home_pages_table_model.h"
#include "chrome/browser/gtk/accessible_widget_helper_gtk.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/gtk/keyword_editor_view.h"
-#include "chrome/browser/gtk/list_store_favicon_loader.h"
#include "chrome/browser/gtk/options/options_layout_gtk.h"
#include "chrome/browser/gtk/options/url_picker_dialog_gtk.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -19,10 +21,10 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/session_startup_pref.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "gfx/gtk_util.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
@@ -37,11 +39,11 @@ const char kDefaultBrowserLabelColor[] = "008700";
// Color of the default browser text when Chromium is not the default browser
const char kNotDefaultBrowserLabelColor[] = "870000";
-// Column ids for |startup_custom_pages_model_|.
+// Column ids for |startup_custom_pages_store_|.
enum {
- COL_FAVICON_HANDLE,
COL_FAVICON,
COL_URL,
+ COL_TOOLTIP,
COL_COUNT,
};
@@ -141,7 +143,7 @@ void GeneralPageGtk::NotifyPrefChanged(const std::wstring* pref_name) {
PrefService* prefs = profile()->GetPrefs();
const SessionStartupPref startup_pref =
SessionStartupPref::GetStartupPref(prefs);
- PopulateCustomUrlList(startup_pref.urls);
+ startup_custom_pages_table_model_->SetURLs(startup_pref.urls);
}
if (!pref_name || *pref_name == prefs::kHomePageIsNewTabPage) {
@@ -216,18 +218,20 @@ GtkWidget* GeneralPageGtk::InitStartupGroup() {
GTK_SHADOW_ETCHED_IN);
gtk_container_add(GTK_CONTAINER(url_list_container),
scroll_window);
- startup_custom_pages_model_ = gtk_list_store_new(COL_COUNT,
- G_TYPE_INT,
+ startup_custom_pages_store_ = gtk_list_store_new(COL_COUNT,
GDK_TYPE_PIXBUF,
+ G_TYPE_STRING,
G_TYPE_STRING);
startup_custom_pages_tree_ = gtk_tree_view_new_with_model(
- GTK_TREE_MODEL(startup_custom_pages_model_));
+ GTK_TREE_MODEL(startup_custom_pages_store_));
gtk_container_add(GTK_CONTAINER(scroll_window), startup_custom_pages_tree_);
- // Release |startup_custom_pages_model_| so that |startup_custom_pages_tree_|
+ // Release |startup_custom_pages_store_| so that |startup_custom_pages_tree_|
// owns the model.
- g_object_unref(startup_custom_pages_model_);
+ g_object_unref(startup_custom_pages_store_);
+ gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(startup_custom_pages_tree_),
+ COL_TOOLTIP);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(startup_custom_pages_tree_),
FALSE);
GtkTreeViewColumn* column = gtk_tree_view_column_new();
@@ -245,11 +249,12 @@ GtkWidget* GeneralPageGtk::InitStartupGroup() {
GTK_SELECTION_MULTIPLE);
g_signal_connect(startup_custom_pages_selection_, "changed",
G_CALLBACK(OnStartupPagesSelectionChangedThunk), this);
- favicon_loader_.reset(new ListStoreFavIconLoader(startup_custom_pages_model_,
- COL_FAVICON,
- COL_FAVICON_HANDLE,
- profile(),
- &fav_icon_consumer_));
+
+ startup_custom_pages_table_model_.reset(
+ new CustomHomePagesTableModel(profile()));
+ startup_custom_pages_table_adapter_.reset(
+ new gtk_tree::TableAdapter(this, startup_custom_pages_store_,
+ startup_custom_pages_table_model_.get()));
GtkWidget* url_list_buttons = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
gtk_box_pack_end(GTK_BOX(url_list_container), url_list_buttons,
@@ -497,106 +502,72 @@ void GeneralPageGtk::SaveStartupPref() {
pref.type = SessionStartupPref::URLS;
}
- pref.urls = GetCustomUrlList();
+ pref.urls = startup_custom_pages_table_model_->GetURLs();
SessionStartupPref::SetStartupPref(profile()->GetPrefs(), pref);
}
-void GeneralPageGtk::PopulateCustomUrlList(const std::vector<GURL>& urls) {
- gtk_list_store_clear(startup_custom_pages_model_);
- for (size_t i = 0; i < urls.size(); ++i) {
- GtkTreeIter iter;
- gtk_list_store_append(startup_custom_pages_model_, &iter);
- PopulateCustomUrlRow(urls[i], &iter);
- }
-}
-
-void GeneralPageGtk::PopulateCustomUrlRow(const GURL& url, GtkTreeIter* iter) {
- favicon_loader_->LoadFaviconForRow(url, iter);
- gtk_list_store_set(startup_custom_pages_model_, iter,
- COL_URL, url.spec().c_str(),
+void GeneralPageGtk::SetColumnValues(int row, GtkTreeIter* iter) {
+ SkBitmap bitmap = startup_custom_pages_table_model_->GetIcon(row);
+ GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap);
+ std::wstring text = startup_custom_pages_table_model_->GetText(row, 0);
+ std::string tooltip =
+ WideToUTF8(startup_custom_pages_table_model_->GetTooltip(row));
+ gchar* escaped_tooltip = g_markup_escape_text(tooltip.c_str(),
+ tooltip.size());
+ gtk_list_store_set(startup_custom_pages_store_, iter,
+ COL_FAVICON, pixbuf,
+ COL_URL, WideToUTF8(text).c_str(),
+ COL_TOOLTIP, escaped_tooltip,
-1);
+ g_object_unref(pixbuf);
+ g_free(escaped_tooltip);
}
void GeneralPageGtk::SetCustomUrlListFromCurrentPages() {
- std::vector<GURL> urls;
- for (BrowserList::const_iterator browser_i = BrowserList::begin();
- browser_i != BrowserList::end(); ++browser_i) {
- Browser* browser = *browser_i;
- if (browser->profile() != profile())
- continue; // Only want entries for open profile.
-
- for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) {
- TabContents* tab = browser->GetTabContentsAt(tab_index);
- if (tab->ShouldDisplayURL()) {
- const GURL url = browser->GetTabContentsAt(tab_index)->GetURL();
- if (!url.is_empty())
- urls.push_back(url);
- }
- }
- }
- PopulateCustomUrlList(urls);
+ startup_custom_pages_table_model_->SetToCurrentlyOpenPages();
+
SaveStartupPref();
}
void GeneralPageGtk::OnAddCustomUrl(const GURL& url) {
- GtkTreeIter iter;
- if (gtk_tree_selection_count_selected_rows(
- startup_custom_pages_selection_) == 1) {
- GList* list = gtk_tree_selection_get_selected_rows(
- startup_custom_pages_selection_, NULL);
- GtkTreeIter sibling;
- gtk_tree_model_get_iter(GTK_TREE_MODEL(startup_custom_pages_model_),
- &sibling, static_cast<GtkTreePath*>(list->data));
- g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(list);
-
- gtk_list_store_insert_before(startup_custom_pages_model_,
- &iter, &sibling);
- } else {
- gtk_list_store_append(startup_custom_pages_model_, &iter);
- }
- PopulateCustomUrlRow(url, &iter);
+ std::set<int> indices;
+ gtk_tree::GetSelectedIndicies(startup_custom_pages_selection_, &indices);
+ int index;
+ if (indices.empty())
+ index = startup_custom_pages_table_model_->RowCount();
+ else
+ index = *indices.begin() + 1;
+ startup_custom_pages_table_model_->Add(index, url);
+
SaveStartupPref();
+
+ gtk_tree::SelectAndFocusRowNum(index,
+ GTK_TREE_VIEW(startup_custom_pages_tree_));
}
void GeneralPageGtk::RemoveSelectedCustomUrls() {
- GList* list = gtk_tree_selection_get_selected_rows(
- startup_custom_pages_selection_, NULL);
- std::vector<GtkTreeIter> selected_iters(
- gtk_tree_selection_count_selected_rows(startup_custom_pages_selection_));
- GList* node;
- size_t i;
- for (i = 0, node = list; node != NULL; ++i, node = node->next) {
- gtk_tree_model_get_iter(GTK_TREE_MODEL(startup_custom_pages_model_),
- &selected_iters[i],
- static_cast<GtkTreePath*>(node->data));
+ std::set<int> indices;
+ gtk_tree::GetSelectedIndicies(startup_custom_pages_selection_, &indices);
+
+ int selected_row = 0;
+ for (std::set<int>::reverse_iterator i = indices.rbegin();
+ i != indices.rend(); ++i) {
+ startup_custom_pages_table_model_->Remove(*i);
+ selected_row = *i;
}
- g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL);
- g_list_free(list);
- for (i = 0; i < selected_iters.size(); ++i) {
- gtk_list_store_remove(startup_custom_pages_model_, &selected_iters[i]);
- }
SaveStartupPref();
-}
-std::vector<GURL> GeneralPageGtk::GetCustomUrlList() const {
- std::vector<GURL> urls;
- GtkTreeIter iter;
- gboolean valid = gtk_tree_model_get_iter_first(
- GTK_TREE_MODEL(startup_custom_pages_model_), &iter);
- while (valid) {
- gchar* url_data;
- gtk_tree_model_get(GTK_TREE_MODEL(startup_custom_pages_model_), &iter,
- COL_URL, &url_data,
- -1);
- urls.push_back(GURL(url_data));
- g_free(url_data);
- valid = gtk_tree_model_iter_next(
- GTK_TREE_MODEL(startup_custom_pages_model_), &iter);
+ // Select the next row after the last row deleted, or the above item if the
+ // latest item was deleted or nothing when the table doesn't have any items.
+ int row_count = startup_custom_pages_table_model_->RowCount();
+ if (selected_row >= row_count)
+ selected_row = row_count - 1;
+ if (selected_row >= 0) {
+ gtk_tree::SelectAndFocusRowNum(selected_row,
+ GTK_TREE_VIEW(startup_custom_pages_tree_));
}
- return urls;
}
void GeneralPageGtk::OnTemplateURLModelChanged() {