OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Currently this file is only used for the uninstall prompt. The install prompt | 5 // Currently this file is only used for the uninstall prompt. The install prompt |
6 // code is in extension_install_prompt2_gtk.cc. | 6 // code is in extension_install_prompt2_gtk.cc. |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
13 #include "chrome/browser/browser_window.h" | 13 #include "chrome/browser/browser_window.h" |
14 #include "chrome/browser/extensions/extension_install_dialog.h" | 14 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
16 #include "chrome/browser/ui/gtk/gtk_util.h" | 16 #include "chrome/browser/ui/gtk/gtk_util.h" |
17 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/gfx/gtk_util.h" | 20 #include "ui/gfx/gtk_util.h" |
21 | 21 |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 // Left or right margin. | 26 // Left or right margin. |
27 const int kPanelHorizMargin = 13; | 27 const int kPanelHorizMargin = 13; |
28 | 28 |
29 void OnResponse(GtkWidget* dialog, int response_id, | 29 void OnResponse(GtkWidget* dialog, int response_id, |
30 ExtensionInstallUI::Delegate* delegate) { | 30 ExtensionUninstallDialog::Delegate* delegate) { |
31 if (response_id == GTK_RESPONSE_ACCEPT) { | 31 if (response_id == GTK_RESPONSE_ACCEPT) |
32 delegate->InstallUIProceed(); | 32 delegate->ExtensionDialogAccepted(); |
33 } else { | 33 else |
34 delegate->InstallUIAbort(); | 34 delegate->ExtensionDialogCanceled(); |
35 } | |
36 | 35 |
37 gtk_widget_destroy(dialog); | 36 gtk_widget_destroy(dialog); |
38 } | 37 } |
39 | 38 |
40 void ShowInstallPromptDialog(GtkWindow* parent, | 39 void ShowUninstallDialogGtk(GtkWindow* parent, |
41 SkBitmap* skia_icon, | 40 SkBitmap* skia_icon, |
42 const Extension* extension, | 41 const Extension* extension, |
43 ExtensionInstallUI::Delegate *delegate, | 42 ExtensionUninstallDialog::Delegate *delegate) { |
44 ExtensionInstallUI::PromptType type) { | |
45 // Build the dialog. | 43 // Build the dialog. |
46 int title_id = ExtensionInstallUI::kTitleIds[type]; | |
47 int button_id = ExtensionInstallUI::kButtonIds[type]; | |
48 GtkWidget* dialog = gtk_dialog_new_with_buttons( | 44 GtkWidget* dialog = gtk_dialog_new_with_buttons( |
49 l10n_util::GetStringUTF8(title_id).c_str(), | 45 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(), |
50 parent, | 46 parent, |
51 GTK_DIALOG_MODAL, | 47 GTK_DIALOG_MODAL, |
52 GTK_STOCK_CANCEL, | 48 GTK_STOCK_CANCEL, |
53 GTK_RESPONSE_CLOSE, | 49 GTK_RESPONSE_CLOSE, |
54 l10n_util::GetStringUTF8(button_id).c_str(), | 50 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(), |
55 GTK_RESPONSE_ACCEPT, | 51 GTK_RESPONSE_ACCEPT, |
56 NULL); | 52 NULL); |
57 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | 53 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); |
58 | 54 |
59 // Create a two column layout. | 55 // Create a two column layout. |
60 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; | 56 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; |
61 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); | 57 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); |
62 | 58 |
63 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing); | 59 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing); |
64 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); | 60 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); |
65 | 61 |
66 // Put Icon in the left column. | 62 // Put Icon in the left column. |
67 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon); | 63 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon); |
68 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); | 64 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); |
69 g_object_unref(pixbuf); | 65 g_object_unref(pixbuf); |
70 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); | 66 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); |
71 | 67 |
72 // Create a new vbox for the right column. | 68 // Create a new vbox for the right column. |
73 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); | 69 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); |
74 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); | 70 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); |
75 | 71 |
76 int heading_id = ExtensionInstallUI::kHeadingIds[type]; | |
77 std::string heading_text = l10n_util::GetStringFUTF8( | 72 std::string heading_text = l10n_util::GetStringFUTF8( |
78 heading_id, UTF8ToUTF16(extension->name())); | 73 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name())); |
79 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); | 74 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); |
80 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 75 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
81 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); | 76 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); |
82 | 77 |
83 g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), delegate); | 78 g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), delegate); |
84 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | 79 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); |
85 gtk_widget_show_all(dialog); | 80 gtk_widget_show_all(dialog); |
86 } | 81 } |
87 | 82 |
88 } // namespace | 83 } // namespace |
89 | 84 |
90 void ShowExtensionInstallDialog(Profile* profile, | 85 // static |
91 ExtensionInstallUI::Delegate* delegate, | 86 void ExtensionUninstallDialog::Show( |
92 const Extension* extension, | 87 Profile* profile, |
93 SkBitmap* icon, | 88 ExtensionUninstallDialog::Delegate* delegate, |
94 ExtensionInstallUI::PromptType type) { | 89 const Extension* extension, |
| 90 SkBitmap* icon) { |
95 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 91 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
96 if (!browser) { | 92 if (!browser) { |
97 delegate->InstallUIAbort(); | 93 delegate->ExtensionDialogCanceled(); |
98 return; | 94 return; |
99 } | 95 } |
100 | 96 |
101 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( | 97 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
102 browser->window()); | 98 browser->window()); |
103 if (!browser_window) { | 99 if (!browser_window) { |
104 delegate->InstallUIAbort(); | 100 delegate->ExtensionDialogCanceled(); |
105 return; | 101 return; |
106 } | 102 } |
107 | 103 |
108 ShowInstallPromptDialog(browser_window->window(), icon, extension, delegate, | 104 ShowUninstallDialogGtk(browser_window->window(), icon, extension, delegate); |
109 type); | |
110 } | 105 } |
OLD | NEW |