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 #include <gtk/gtk.h> | 5 #include <gtk/gtk.h> |
6 #include <map> | 6 #include <map> |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/mime_util.h" | 12 #include "base/nix/mime_util_xdg.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/ui/gtk/dialogs_common.h" | 17 #include "chrome/browser/ui/gtk/dialogs_common.h" |
18 #include "chrome/browser/ui/shell_dialogs.h" | 18 #include "chrome/browser/ui/shell_dialogs.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/gtk/gtk_signal.h" | 21 #include "ui/base/gtk/gtk_signal.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { | 221 void SelectFileDialogImplGTK::AddFilters(GtkFileChooser* chooser) { |
222 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 222 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
223 GtkFileFilter* filter = NULL; | 223 GtkFileFilter* filter = NULL; |
224 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { | 224 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { |
225 if (!file_types_.extensions[i][j].empty()) { | 225 if (!file_types_.extensions[i][j].empty()) { |
226 if (!filter) | 226 if (!filter) |
227 filter = gtk_file_filter_new(); | 227 filter = gtk_file_filter_new(); |
228 | 228 |
229 // Allow IO in the file dialog. http://crbug.com/72637 | 229 // Allow IO in the file dialog. http://crbug.com/72637 |
230 base::ThreadRestrictions::ScopedAllowIO allow_io; | 230 base::ThreadRestrictions::ScopedAllowIO allow_io; |
231 std::string mime_type = mime_util::GetFileMimeType( | 231 std::string mime_type = base::nix::GetFileMimeType( |
232 FilePath("name").ReplaceExtension(file_types_.extensions[i][j])); | 232 FilePath("name").ReplaceExtension(file_types_.extensions[i][j])); |
233 gtk_file_filter_add_mime_type(filter, mime_type.c_str()); | 233 gtk_file_filter_add_mime_type(filter, mime_type.c_str()); |
234 } | 234 } |
235 } | 235 } |
236 // We didn't find any non-empty extensions to filter on. | 236 // We didn't find any non-empty extensions to filter on. |
237 if (!filter) | 237 if (!filter) |
238 continue; | 238 continue; |
239 | 239 |
240 // The description vector may be blank, in which case we are supposed to | 240 // The description vector may be blank, in which case we are supposed to |
241 // use some sort of default description based on the filter. | 241 // use some sort of default description based on the filter. |
242 if (i < file_types_.extension_description_overrides.size()) { | 242 if (i < file_types_.extension_description_overrides.size()) { |
243 gtk_file_filter_set_name(filter, UTF16ToUTF8( | 243 gtk_file_filter_set_name(filter, UTF16ToUTF8( |
244 file_types_.extension_description_overrides[i]).c_str()); | 244 file_types_.extension_description_overrides[i]).c_str()); |
245 } else { | 245 } else { |
246 // Allow IO in the file dialog. http://crbug.com/72637 | 246 // Allow IO in the file dialog. http://crbug.com/72637 |
247 base::ThreadRestrictions::ScopedAllowIO allow_io; | 247 base::ThreadRestrictions::ScopedAllowIO allow_io; |
248 // There is no system default filter description so we use | 248 // There is no system default filter description so we use |
249 // the MIME type itself if the description is blank. | 249 // the MIME type itself if the description is blank. |
250 std::string mime_type = mime_util::GetFileMimeType( | 250 std::string mime_type = base::nix::GetFileMimeType( |
251 FilePath("name").ReplaceExtension(file_types_.extensions[i][0])); | 251 FilePath("name").ReplaceExtension(file_types_.extensions[i][0])); |
252 gtk_file_filter_set_name(filter, mime_type.c_str()); | 252 gtk_file_filter_set_name(filter, mime_type.c_str()); |
253 } | 253 } |
254 | 254 |
255 gtk_file_chooser_add_filter(chooser, filter); | 255 gtk_file_chooser_add_filter(chooser, filter); |
256 if (i == file_type_index_ - 1) | 256 if (i == file_type_index_ - 1) |
257 gtk_file_chooser_set_filter(chooser, filter); | 257 gtk_file_chooser_set_filter(chooser, filter); |
258 } | 258 } |
259 | 259 |
260 // Add the *.* filter, but only if we have added other filters (otherwise it | 260 // Add the *.* filter, but only if we have added other filters (otherwise it |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, | 538 GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file_at_size(filename, kPreviewWidth, |
539 kPreviewHeight, NULL); | 539 kPreviewHeight, NULL); |
540 g_free(filename); | 540 g_free(filename); |
541 if (pixbuf) { | 541 if (pixbuf) { |
542 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); | 542 gtk_image_set_from_pixbuf(GTK_IMAGE(preview_), pixbuf); |
543 g_object_unref(pixbuf); | 543 g_object_unref(pixbuf); |
544 } | 544 } |
545 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), | 545 gtk_file_chooser_set_preview_widget_active(GTK_FILE_CHOOSER(chooser), |
546 pixbuf ? TRUE : FALSE); | 546 pixbuf ? TRUE : FALSE); |
547 } | 547 } |
OLD | NEW |