OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 // This file implements common select dialog functionality between GTK and KDE. | |
6 | |
7 #include "chrome/browser/ui/gtk/select_file_dialog_impl.h" | |
8 | |
9 #include "base/environment.h" | |
10 #include "base/file_util.h" | |
11 #include "base/nix/xdg_util.h" | |
12 #include "base/threading/thread_restrictions.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 | |
15 using content::BrowserThread; | |
16 | |
17 namespace { | |
18 | |
19 enum UseKdeFileDialogStatus { | |
20 UNKNOWN, | |
21 NO_KDE, | |
22 YES_KDE | |
23 }; | |
24 | |
25 UseKdeFileDialogStatus use_kde_ = UNKNOWN; | |
26 | |
27 } // namespace | |
28 | |
29 FilePath* SelectFileDialogImpl::last_saved_path_ = NULL; | |
30 FilePath* SelectFileDialogImpl::last_opened_path_ = NULL; | |
31 | |
32 // static | |
33 SelectFileDialog* SelectFileDialog::Create(Listener* listener, | |
34 ui::SelectFilePolicy* policy) { | |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
36 if (use_kde_ == UNKNOWN) { | |
37 // Start out assumimg we are not going to use KDE. | |
38 use_kde_ = NO_KDE; | |
39 | |
40 // Check to see if KDE is the desktop environment. | |
41 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
42 base::nix::DesktopEnvironment desktop = | |
43 base::nix::GetDesktopEnvironment(env.get()); | |
44 if (desktop == base::nix::DESKTOP_ENVIRONMENT_KDE3 || | |
45 desktop == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | |
46 // Check to see if the user dislikes the KDE file dialog. | |
47 if (!env->HasVar("NO_CHROME_KDE_FILE_DIALOG")) { | |
48 // Check to see if the KDE dialog works. | |
49 if (SelectFileDialogImpl::CheckKDEDialogWorksOnUIThread()) { | |
50 use_kde_ = YES_KDE; | |
51 } | |
52 } | |
53 } | |
54 } | |
55 | |
56 if (use_kde_ == NO_KDE) | |
57 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener, policy); | |
58 | |
59 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
60 base::nix::DesktopEnvironment desktop = | |
61 base::nix::GetDesktopEnvironment(env.get()); | |
62 return SelectFileDialogImpl::NewSelectFileDialogImplKDE( | |
63 listener, policy, desktop); | |
64 } | |
65 | |
66 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, | |
67 ui::SelectFilePolicy* policy) | |
68 : SelectFileDialog(listener, policy), | |
69 file_type_index_(0), | |
70 type_(SELECT_NONE) { | |
71 if (!last_saved_path_) { | |
72 last_saved_path_ = new FilePath(); | |
73 last_opened_path_ = new FilePath(); | |
74 } | |
75 } | |
76 | |
77 SelectFileDialogImpl::~SelectFileDialogImpl() { } | |
78 | |
79 void SelectFileDialogImpl::ListenerDestroyed() { | |
80 listener_ = NULL; | |
81 } | |
82 | |
83 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const { | |
84 return parents_.find(parent_window) != parents_.end(); | |
85 } | |
86 | |
87 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(const FilePath& path) { | |
88 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
89 return file_util::DirectoryExists(path); | |
90 } | |
OLD | NEW |