1 // Copyright (c) 2013 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.
5 // This file implements common select dialog functionality between GTK and KDE.
7 #include "ui/shell_dialogs/gtk/select_file_dialog_impl.h"
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"
16 enum UseKdeFileDialogStatus
{
22 UseKdeFileDialogStatus use_kde_
= UNKNOWN
;
28 base::FilePath
* SelectFileDialogImpl::last_saved_path_
= NULL
;
29 base::FilePath
* SelectFileDialogImpl::last_opened_path_
= NULL
;
32 SelectFileDialog
* CreateLinuxSelectFileDialog(
33 SelectFileDialog::Listener
* listener
,
34 SelectFilePolicy
* policy
) {
35 if (use_kde_
== UNKNOWN
) {
36 // Start out assumimg we are not going to use KDE.
39 // Check to see if KDE is the desktop environment.
40 scoped_ptr
<base::Environment
> env(base::Environment::Create());
41 base::nix::DesktopEnvironment desktop
=
42 base::nix::GetDesktopEnvironment(env
.get());
43 if (desktop
== base::nix::DESKTOP_ENVIRONMENT_KDE3
||
44 desktop
== base::nix::DESKTOP_ENVIRONMENT_KDE4
) {
45 // Check to see if the user dislikes the KDE file dialog.
46 if (!env
->HasVar("NO_CHROME_KDE_FILE_DIALOG")) {
47 // Check to see if the KDE dialog works.
48 if (SelectFileDialogImpl::CheckKDEDialogWorksOnUIThread()) {
55 if (use_kde_
== NO_KDE
)
56 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener
, policy
);
58 scoped_ptr
<base::Environment
> env(base::Environment::Create());
59 base::nix::DesktopEnvironment desktop
=
60 base::nix::GetDesktopEnvironment(env
.get());
61 return SelectFileDialogImpl::NewSelectFileDialogImplKDE(
62 listener
, policy
, desktop
);
65 SelectFileDialogImpl::SelectFileDialogImpl(Listener
* listener
,
66 ui::SelectFilePolicy
* policy
)
67 : SelectFileDialog(listener
, policy
),
70 if (!last_saved_path_
) {
71 last_saved_path_
= new base::FilePath();
72 last_opened_path_
= new base::FilePath();
76 SelectFileDialogImpl::~SelectFileDialogImpl() { }
78 void SelectFileDialogImpl::ListenerDestroyed() {
82 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window
) const {
83 return parents_
.find(parent_window
) != parents_
.end();
86 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread(
87 const base::FilePath
& path
) {
88 base::ThreadRestrictions::ScopedAllowIO allow_io
;
89 return file_util::DirectoryExists(path
);