OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/platform_util.h" | 5 #include "chrome/common/platform_util.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 | 13 |
| 14 namespace { |
| 15 |
| 16 void XDGOpen(const FilePath& path) { |
| 17 std::vector<std::string> argv; |
| 18 argv.push_back("xdg-open"); |
| 19 argv.push_back(path.value()); |
| 20 base::file_handle_mapping_vector no_files; |
| 21 base::LaunchApp(argv, no_files, false, NULL); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
14 namespace platform_util { | 26 namespace platform_util { |
15 | 27 |
16 // TODO(estade): It would be nice to be able to select the file in the file | 28 // TODO(estade): It would be nice to be able to select the file in the file |
17 // manager, but that probably requires extending xdg-open. For now just | 29 // manager, but that probably requires extending xdg-open. For now just |
18 // show the folder. | 30 // show the folder. |
19 void ShowItemInFolder(const FilePath& full_path) { | 31 void ShowItemInFolder(const FilePath& full_path) { |
20 FilePath dir = full_path.DirName(); | 32 FilePath dir = full_path.DirName(); |
21 if (!file_util::DirectoryExists(dir)) | 33 if (!file_util::DirectoryExists(dir)) |
22 return; | 34 return; |
23 | 35 |
24 std::vector<std::string> argv; | 36 XDGOpen(dir); |
25 argv.push_back("xdg-open"); | 37 } |
26 argv.push_back(dir.value()); | 38 |
27 base::file_handle_mapping_vector no_files; | 39 void OpenItem(const FilePath& full_path) { |
28 base::LaunchApp(argv, no_files, false, NULL); | 40 XDGOpen(full_path); |
29 } | 41 } |
30 | 42 |
31 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { | 43 gfx::NativeWindow GetTopLevel(gfx::NativeView view) { |
32 // A detached widget won't have a toplevel window as an ancestor, so we can't | 44 // A detached widget won't have a toplevel window as an ancestor, so we can't |
33 // assume that the query for toplevel will return a window. | 45 // assume that the query for toplevel will return a window. |
34 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW); | 46 GtkWidget* toplevel = gtk_widget_get_ancestor(view, GTK_TYPE_WINDOW); |
35 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; | 47 return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; |
36 } | 48 } |
37 | 49 |
38 string16 GetWindowTitle(gfx::NativeWindow window) { | 50 string16 GetWindowTitle(gfx::NativeWindow window) { |
39 const gchar* title = gtk_window_get_title(window); | 51 const gchar* title = gtk_window_get_title(window); |
40 return UTF8ToUTF16(title); | 52 return UTF8ToUTF16(title); |
41 } | 53 } |
42 | 54 |
43 bool IsWindowActive(gfx::NativeWindow window) { | 55 bool IsWindowActive(gfx::NativeWindow window) { |
44 return gtk_window_is_active(window); | 56 return gtk_window_is_active(window); |
45 } | 57 } |
46 | 58 |
47 bool IsVisible(gfx::NativeView view) { | 59 bool IsVisible(gfx::NativeView view) { |
48 return GTK_WIDGET_VISIBLE(view); | 60 return GTK_WIDGET_VISIBLE(view); |
49 } | 61 } |
50 | 62 |
51 } // namespace platform_util | 63 } // namespace platform_util |
OLD | NEW |