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