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