| OLD | NEW |
| (Empty) |
| 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. | |
| 4 // | |
| 5 // This file implements common select dialog functionality between GTK and KDE. | |
| 6 | |
| 7 #include "ui/shell_dialogs/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 | |
| 14 namespace { | |
| 15 | |
| 16 enum UseKdeFileDialogStatus { | |
| 17 UNKNOWN, | |
| 18 NO_KDE, | |
| 19 YES_KDE | |
| 20 }; | |
| 21 | |
| 22 UseKdeFileDialogStatus use_kde_ = UNKNOWN; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 namespace ui { | |
| 27 | |
| 28 base::FilePath* SelectFileDialogImpl::last_saved_path_ = NULL; | |
| 29 base::FilePath* SelectFileDialogImpl::last_opened_path_ = NULL; | |
| 30 | |
| 31 // static | |
| 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. | |
| 37 use_kde_ = NO_KDE; | |
| 38 | |
| 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()) { | |
| 49 use_kde_ = YES_KDE; | |
| 50 } | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 if (use_kde_ == NO_KDE) | |
| 56 return SelectFileDialogImpl::NewSelectFileDialogImplGTK(listener, policy); | |
| 57 | |
| 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); | |
| 63 } | |
| 64 | |
| 65 SelectFileDialogImpl::SelectFileDialogImpl(Listener* listener, | |
| 66 ui::SelectFilePolicy* policy) | |
| 67 : SelectFileDialog(listener, policy), | |
| 68 file_type_index_(0), | |
| 69 type_(SELECT_NONE) { | |
| 70 if (!last_saved_path_) { | |
| 71 last_saved_path_ = new base::FilePath(); | |
| 72 last_opened_path_ = new base::FilePath(); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 SelectFileDialogImpl::~SelectFileDialogImpl() { } | |
| 77 | |
| 78 void SelectFileDialogImpl::ListenerDestroyed() { | |
| 79 listener_ = NULL; | |
| 80 } | |
| 81 | |
| 82 bool SelectFileDialogImpl::IsRunning(gfx::NativeWindow parent_window) const { | |
| 83 return parents_.find(parent_window) != parents_.end(); | |
| 84 } | |
| 85 | |
| 86 bool SelectFileDialogImpl::CallDirectoryExistsOnUIThread( | |
| 87 const base::FilePath& path) { | |
| 88 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 89 return base::DirectoryExists(path); | |
| 90 } | |
| 91 | |
| 92 } // namespace ui | |
| OLD | NEW |