blob: 20ad001988831afca73315c577f90c824a36e282 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2022 The Chromium Authors
Tom Anderson16cc9722022-02-14 06:59:402// 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#ifndef UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LINUX_H_
8#define UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LINUX_H_
9
10#include <stddef.h>
11
12#include <memory>
13#include <set>
14
15#include "base/nix/xdg_util.h"
16#include "ui/aura/window.h"
17#include "ui/shell_dialogs/select_file_dialog.h"
18#include "ui/shell_dialogs/select_file_policy.h"
19#include "ui/shell_dialogs/shell_dialogs_export.h"
20
21namespace ui {
22
23// Shared implementation SelectFileDialog used on Linux
24class SHELL_DIALOGS_EXPORT SelectFileDialogLinux : public SelectFileDialog {
25 public:
26 SelectFileDialogLinux(const SelectFileDialogLinux&) = delete;
27 SelectFileDialogLinux& operator=(const SelectFileDialogLinux&) = delete;
28
29 // Returns true if the SelectFileDialog class returned by
30 // NewSelectFileDialogImplKDE will actually work.
31 static bool CheckKDEDialogWorksOnUIThread(std::string& kdialog_version);
32
33 // BaseShellDialog implementation.
34 void ListenerDestroyed() override;
35
36 protected:
37 explicit SelectFileDialogLinux(Listener* listener,
38 std::unique_ptr<ui::SelectFilePolicy> policy);
39 ~SelectFileDialogLinux() override;
40
41 // SelectFileDialog implementation.
42 // |params| is user data we pass back via the Listener interface.
43 void SelectFileImpl(Type type,
44 const std::u16string& title,
45 const base::FilePath& default_path,
46 const FileTypeInfo* file_types,
47 int file_type_index,
48 const base::FilePath::StringType& default_extension,
49 gfx::NativeWindow owning_window,
Aida Zolica03ba4ca2022-09-29 13:50:0950 void* params,
51 const GURL* caller) override = 0;
Tom Anderson16cc9722022-02-14 06:59:4052
53 // Wrapper for base::DirectoryExists() that allow access on the UI
54 // thread. Use this only in the file dialog functions, where it's ok
55 // because the file dialog has to do many stats anyway. One more won't
56 // hurt too badly and it's likely already cached.
57 bool CallDirectoryExistsOnUIThread(const base::FilePath& path);
58
59 const FileTypeInfo& file_types() const { return file_types_; }
60 void set_file_types(const FileTypeInfo& file_types) {
61 file_types_ = file_types;
62 }
63
64 size_t file_type_index() const { return file_type_index_; }
65 void set_file_type_index(size_t file_type_index) {
66 file_type_index_ = file_type_index;
67 }
68
69 Type type() const { return type_; }
70 void set_type(Type type) { type_ = type; }
71
72 static const base::FilePath* last_saved_path() { return last_saved_path_; }
73 static void set_last_saved_path(const base::FilePath& last_saved_path) {
74 *last_saved_path_ = last_saved_path;
75 }
76
77 static const base::FilePath* last_opened_path() { return last_opened_path_; }
78 static void set_last_opened_path(const base::FilePath& last_opened_path) {
79 *last_opened_path_ = last_opened_path;
80 }
81
82 private:
83 // The file filters.
84 FileTypeInfo file_types_;
85
86 // The index of the default selected file filter.
87 // Note: This starts from 1, not 0.
88 size_t file_type_index_ = 0;
89
90 // The type of dialog we are showing the user.
91 Type type_ = SELECT_NONE;
92
93 // These two variables track where the user last saved a file or opened a
94 // file so that we can display future dialogs with the same starting path.
95 static base::FilePath* last_saved_path_;
96 static base::FilePath* last_opened_path_;
97};
98
99} // namespace ui
100
101#endif // UI_SHELL_DIALOGS_SELECT_FILE_DIALOG_LINUX_H_