Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ui / shell_dialogs / gtk / select_file_dialog_impl.h
blobb0206e0661135aa037a8c6c397f2134e65595ed4
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.
7 #ifndef UI_SHELL_DIALOGS_GTK_SELECT_FILE_DIALOG_IMPL_H_
8 #define UI_SHELL_DIALOGS_GTK_SELECT_FILE_DIALOG_IMPL_H_
10 #include <set>
12 #include "base/compiler_specific.h"
13 #include "base/nix/xdg_util.h"
14 #include "ui/shell_dialogs/select_file_dialog.h"
16 namespace ui {
18 // Shared implementation SelectFileDialog used by SelectFileDialogImplGTK
19 class SelectFileDialogImpl : public SelectFileDialog {
20 public:
21 // Factory method for creating a GTK-styled SelectFileDialogImpl
22 static SelectFileDialogImpl* NewSelectFileDialogImplGTK(
23 Listener* listener,
24 ui::SelectFilePolicy* policy);
25 // Factory method for creating a KDE-styled SelectFileDialogImpl
26 static SelectFileDialogImpl* NewSelectFileDialogImplKDE(
27 Listener* listener,
28 ui::SelectFilePolicy* policy,
29 base::nix::DesktopEnvironment desktop);
31 // Returns true if the SelectFileDialog class returned by
32 // NewSelectFileDialogImplKDE will actually work.
33 static bool CheckKDEDialogWorksOnUIThread();
35 // BaseShellDialog implementation.
36 virtual bool IsRunning(gfx::NativeWindow parent_window) const OVERRIDE;
37 virtual void ListenerDestroyed() OVERRIDE;
39 protected:
40 explicit SelectFileDialogImpl(Listener* listener,
41 ui::SelectFilePolicy* policy);
42 virtual ~SelectFileDialogImpl();
44 // SelectFileDialog implementation.
45 // |params| is user data we pass back via the Listener interface.
46 virtual void SelectFileImpl(
47 Type type,
48 const string16& title,
49 const base::FilePath& default_path,
50 const FileTypeInfo* file_types,
51 int file_type_index,
52 const base::FilePath::StringType& default_extension,
53 gfx::NativeWindow owning_window,
54 void* params) = 0;
56 // Wrapper for file_util::DirectoryExists() that allow access on the UI
57 // thread. Use this only in the file dialog functions, where it's ok
58 // because the file dialog has to do many stats anyway. One more won't
59 // hurt too badly and it's likely already cached.
60 bool CallDirectoryExistsOnUIThread(const base::FilePath& path);
62 // The file filters.
63 FileTypeInfo file_types_;
65 // The index of the default selected file filter.
66 // Note: This starts from 1, not 0.
67 size_t file_type_index_;
69 // The set of all parent windows for which we are currently running dialogs.
70 std::set<GtkWindow*> parents_;
72 // The type of dialog we are showing the user.
73 Type type_;
75 // These two variables track where the user last saved a file or opened a
76 // file so that we can display future dialogs with the same starting path.
77 static base::FilePath* last_saved_path_;
78 static base::FilePath* last_opened_path_;
80 DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
83 SelectFileDialog* CreateLinuxSelectFileDialog(
84 SelectFileDialog::Listener* listener,
85 SelectFilePolicy* policy);
87 } // namespace ui
89 #endif // UI_SHELL_DIALOGS_GTK_SELECT_FILE_DIALOG_IMPL_H_