OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/gtk/options/passwords_exceptions_window_gtk.h" | |
6 | |
7 #include <gtk/gtk.h> | |
8 | |
9 #include <string> | |
10 | |
11 #include "base/message_loop.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/ui/gtk/gtk_util.h" | |
14 #include "chrome/browser/ui/gtk/options/passwords_exceptions_page_gtk.h" | |
15 #include "chrome/browser/ui/gtk/options/passwords_page_gtk.h" | |
16 #include "chrome/browser/ui/options/options_window.h" | |
17 #include "grit/chromium_strings.h" | |
18 #include "grit/generated_resources.h" | |
19 #include "grit/locale_settings.h" | |
20 #include "ui/base/l10n/l10n_util.h" | |
21 | |
22 /////////////////////////////////////////////////////////////////////////////// | |
23 // PasswordsExceptionsWindowGtk | |
24 // | |
25 // The contents of the Passwords and Exceptions dialog window. | |
26 | |
27 class PasswordsExceptionsWindowGtk { | |
28 public: | |
29 explicit PasswordsExceptionsWindowGtk(Profile* profile); | |
30 ~PasswordsExceptionsWindowGtk(); | |
31 | |
32 void Show(); | |
33 | |
34 private: | |
35 static void OnWindowDestroy(GtkWidget* widget, | |
36 PasswordsExceptionsWindowGtk* window); | |
37 | |
38 // The passwords and exceptions dialog. | |
39 GtkWidget *dialog_; | |
40 | |
41 // The container of the password and exception pages. | |
42 GtkWidget *notebook_; | |
43 | |
44 // The Profile associated with these passwords and exceptions. | |
45 Profile* profile_; | |
46 | |
47 // The passwords page. | |
48 PasswordsPageGtk passwords_page_; | |
49 | |
50 // The exceptions page. | |
51 PasswordsExceptionsPageGtk exceptions_page_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsWindowGtk); | |
54 }; | |
55 | |
56 // The singleton passwords and exceptions window object. | |
57 static PasswordsExceptionsWindowGtk* passwords_exceptions_window = NULL; | |
58 | |
59 /////////////////////////////////////////////////////////////////////////////// | |
60 // PasswordsExceptionsWindowGtk, public: | |
61 | |
62 PasswordsExceptionsWindowGtk::PasswordsExceptionsWindowGtk(Profile* profile) | |
63 : profile_(profile), | |
64 passwords_page_(profile_), | |
65 exceptions_page_(profile_) { | |
66 std::string dialog_name = l10n_util::GetStringUTF8( | |
67 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | |
68 dialog_ = gtk_dialog_new_with_buttons( | |
69 dialog_name.c_str(), | |
70 // Passwords and exceptions window is shared between all browser windows. | |
71 NULL, | |
72 // Non-modal. | |
73 GTK_DIALOG_NO_SEPARATOR, | |
74 GTK_STOCK_CLOSE, | |
75 GTK_RESPONSE_CLOSE, | |
76 NULL); | |
77 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | |
78 gtk_util::kContentAreaSpacing); | |
79 | |
80 notebook_ = gtk_notebook_new(); | |
81 | |
82 gtk_notebook_append_page( | |
83 GTK_NOTEBOOK(notebook_), | |
84 passwords_page_.get_page_widget(), | |
85 gtk_label_new(l10n_util::GetStringUTF8( | |
86 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE).c_str())); | |
87 | |
88 gtk_notebook_append_page( | |
89 GTK_NOTEBOOK(notebook_), | |
90 exceptions_page_.get_page_widget(), | |
91 gtk_label_new(l10n_util::GetStringUTF8( | |
92 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE).c_str())); | |
93 | |
94 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); | |
95 | |
96 // We only have one button and don't do any special handling, so just hook it | |
97 // directly to gtk_widget_destroy. | |
98 g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); | |
99 | |
100 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); | |
101 | |
102 gtk_util::ShowDialogWithLocalizedSize(dialog_, | |
103 IDS_PASSWORDS_DIALOG_WIDTH_CHARS, | |
104 IDS_PASSWORDS_DIALOG_HEIGHT_LINES, | |
105 true); | |
106 } | |
107 | |
108 PasswordsExceptionsWindowGtk::~PasswordsExceptionsWindowGtk() { | |
109 } | |
110 | |
111 void PasswordsExceptionsWindowGtk::Show() { | |
112 // Bring options window to front if it already existed and isn't already | |
113 // in front | |
114 gtk_util::PresentWindow(dialog_, 0); | |
115 } | |
116 | |
117 /////////////////////////////////////////////////////////////////////////////// | |
118 // PasswordsExceptionsWindowGtk, private: | |
119 | |
120 // static | |
121 void PasswordsExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget, | |
122 PasswordsExceptionsWindowGtk* window) { | |
123 passwords_exceptions_window = NULL; | |
124 MessageLoop::current()->DeleteSoon(FROM_HERE, window); | |
125 } | |
126 | |
127 /////////////////////////////////////////////////////////////////////////////// | |
128 // Factory/finder method: | |
129 | |
130 void ShowPasswordsExceptionsWindow(Profile* profile) { | |
131 DCHECK(profile); | |
132 // If there's already an existing passwords and exceptions window, use it. | |
133 if (!passwords_exceptions_window) { | |
134 passwords_exceptions_window = new PasswordsExceptionsWindowGtk(profile); | |
135 } | |
136 passwords_exceptions_window->Show(); | |
137 } | |
OLD | NEW |