Home | History | Annotate | Download | only in libgtk2ui
      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
      3 // found in the LICENSE file.
      4 //
      5 // This file implements common select dialog functionality between GTK and KDE.
      6 
      7 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
      8 #define CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
      9 
     10 #include <set>
     11 
     12 #include "base/compiler_specific.h"
     13 #include "base/nix/xdg_util.h"
     14 #include "ui/aura/window.h"
     15 #include "ui/shell_dialogs/select_file_dialog.h"
     16 #include "ui/shell_dialogs/select_file_policy.h"
     17 
     18 namespace libgtk2ui {
     19 
     20 // Shared implementation SelectFileDialog used by SelectFileDialogImplGTK
     21 class SelectFileDialogImpl : public ui::SelectFileDialog {
     22  public:
     23   // Main factory method which returns correct type.
     24   static ui::SelectFileDialog* Create(Listener* listener,
     25                                       ui::SelectFilePolicy* policy);
     26 
     27   // Factory method for creating a GTK-styled SelectFileDialogImpl
     28   static SelectFileDialogImpl* NewSelectFileDialogImplGTK(
     29       Listener* listener,
     30       ui::SelectFilePolicy* policy);
     31   // Factory method for creating a KDE-styled SelectFileDialogImpl
     32   static SelectFileDialogImpl* NewSelectFileDialogImplKDE(
     33       Listener* listener,
     34       ui::SelectFilePolicy* policy,
     35       base::nix::DesktopEnvironment desktop);
     36 
     37   // Returns true if the SelectFileDialog class returned by
     38   // NewSelectFileDialogImplKDE will actually work.
     39   static bool CheckKDEDialogWorksOnUIThread();
     40 
     41   // BaseShellDialog implementation.
     42   virtual void ListenerDestroyed() OVERRIDE;
     43 
     44  protected:
     45   explicit SelectFileDialogImpl(Listener* listener,
     46                                 ui::SelectFilePolicy* policy);
     47   virtual ~SelectFileDialogImpl();
     48 
     49   // SelectFileDialog implementation.
     50   // |params| is user data we pass back via the Listener interface.
     51   virtual void SelectFileImpl(
     52       Type type,
     53       const base::string16& title,
     54       const base::FilePath& default_path,
     55       const FileTypeInfo* file_types,
     56       int file_type_index,
     57       const base::FilePath::StringType& default_extension,
     58       gfx::NativeWindow owning_window,
     59       void* params) = 0;
     60 
     61   // Wrapper for base::DirectoryExists() that allow access on the UI
     62   // thread. Use this only in the file dialog functions, where it's ok
     63   // because the file dialog has to do many stats anyway. One more won't
     64   // hurt too badly and it's likely already cached.
     65   bool CallDirectoryExistsOnUIThread(const base::FilePath& path);
     66 
     67   // The file filters.
     68   FileTypeInfo file_types_;
     69 
     70   // The index of the default selected file filter.
     71   // Note: This starts from 1, not 0.
     72   size_t file_type_index_;
     73 
     74   // The type of dialog we are showing the user.
     75   Type type_;
     76 
     77   // These two variables track where the user last saved a file or opened a
     78   // file so that we can display future dialogs with the same starting path.
     79   static base::FilePath* last_saved_path_;
     80   static base::FilePath* last_opened_path_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(SelectFileDialogImpl);
     83 };
     84 
     85 }  // namespace libgtk2ui
     86 
     87 #endif  // CHROME_BROWSER_UI_LIBGTK2UI_SELECT_FILE_DIALOG_IMPL_H_
     88