summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/options/languages_page_gtk.h
blob: 81712bebcdb42da184457de89221ac87d1c0c270 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// The languages page of the Languages & languages options dialog, which
// contains accept-languages and spellchecker language options.
//
// Note that we intentionally do not implement the application locale setting,
// as it does not make sense on Linux, where locale is set through the LANG and
// LC_* environment variables.

#ifndef CHROME_BROWSER_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_
#define CHROME_BROWSER_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_
#pragma once

#include <gtk/gtk.h>

#include <string>

#include "app/gtk_signal.h"
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/gtk/gtk_tree.h"
#include "chrome/browser/options_page_base.h"
#include "chrome/browser/prefs/pref_member.h"

class LanguageComboboxModel;
class LanguageOrderTableModel;

class LanguagesPageGtk
    : public OptionsPageBase,
      public gtk_tree::TableAdapter::Delegate {
 public:
  explicit LanguagesPageGtk(Profile* profile);
  virtual ~LanguagesPageGtk();

  GtkWidget* get_page_widget() const { return page_; }

  // gtk_tree::TableAdapter::Delegate implementation.
  virtual void OnAnyModelUpdate();
  virtual void SetColumnValues(int row, GtkTreeIter* iter);

  // Callback from AddLanguageDialog.
  void OnAddLanguage(const std::string& new_language);

 private:
  // Column ids for |language_order_store_|.
  enum {
    COL_LANG,
    COL_COUNT,
  };

  void Init();

  // Enable buttons based on selection state.
  void EnableControls();

  // Get the row number of the first selected row or -1 if no row is selected.
  int FirstSelectedRowNum();

  // Overridden from OptionsPageBase.
  virtual void NotifyPrefChanged(const std::string* pref_name);

  // Callbacks for accept languages widgets.
  CHROMEG_CALLBACK_0(LanguagesPageGtk, void, OnSelectionChanged,
                     GtkTreeSelection*);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnAddButtonClicked);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnRemoveButtonClicked);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnMoveUpButtonClicked);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnMoveDownButtonClicked);

  // Callbacks for spellchecker option widgets.
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnEnableSpellCheckingToggled);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void,
                       OnEnableAutoSpellCheckingToggled);
  CHROMEGTK_CALLBACK_0(LanguagesPageGtk, void, OnDictionaryLanguageChanged);

  // The accept languages widgets.
  GtkListStore* language_order_store_;
  GtkWidget* language_order_tree_;
  GtkTreeSelection* language_order_selection_;
  GtkWidget* move_up_button_;
  GtkWidget* move_down_button_;
  GtkWidget* add_button_;
  GtkWidget* remove_button_;

  // The spell checking widgets.
  GtkWidget* dictionary_language_combobox_;
  GtkWidget* enable_autospellcorrect_checkbox_;
  GtkWidget* enable_spellchecking_checkbox_;

  // The widget containing the options for this page.
  GtkWidget* page_;

  // The model for |language_order_store_|.
  scoped_ptr<LanguageOrderTableModel> language_order_table_model_;
  scoped_ptr<gtk_tree::TableAdapter> language_order_table_adapter_;

  // Accept languages pref.
  StringPrefMember accept_languages_;

  // The spellchecker "dictionary language" pref and model.
  StringPrefMember dictionary_language_;
  scoped_ptr<LanguageComboboxModel> dictionary_language_model_;

  // If a language was auto-added to accept_languages_ due to being selected as
  // the dictionary language, it is saved in this string, so that it can be
  // removed if the dictionary language is changed again.
  std::string spellcheck_language_added_;

  // SpellChecker enable pref.
  BooleanPrefMember enable_spellcheck_;

  // Auto spell correction pref.
  BooleanPrefMember enable_autospellcorrect_;

  // Flag to ignore gtk callbacks while we are loading prefs, to avoid
  // then turning around and saving them again.
  bool initializing_;

  friend class LanguagesPageGtkTest;
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, RemoveAcceptLang);
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, RemoveMultipleAcceptLang);
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, MoveAcceptLang);
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, AddAcceptLang);
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, EnableSpellChecking);
  FRIEND_TEST_ALL_PREFIXES(LanguagesPageGtkTest, DictionaryLanguage);

  DISALLOW_COPY_AND_ASSIGN(LanguagesPageGtk);
};

#endif  // CHROME_BROWSER_GTK_OPTIONS_LANGUAGES_PAGE_GTK_H_