/* Copyright (C) 2022 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

_CONFIGINCLUDE(gtkmmconfig.h)

_DEFS(gtkmm,gtk)
_PINCLUDE(glibmm/private/object_p.h)

#include <glibmm/object.h>
#include <giomm/asyncresult.h>
#include <giomm/cancellable.h>
#include <giomm/listmodel.h>
#include <giomm/file.h>
#include <gtkmm/filefilter.h>
#include <gtk/gtk.h>

namespace Gtk
{
class Window;

/** A %Gtk::FileDialog object collects the arguments that
 * are needed to present a file chooser dialog to the
 * user, such as a title for the dialog and whether it
 * should be modal.
 *
 * The dialog is shown with open(), save(), etc. These APIs follow the
 * GIO async pattern, and the result can be obtained by calling
 * the corresponding finish function, for example open_finish().
 *
 * @ingroup Dialogs
 * @newin{4,10}
 */
class GTKMM_API FileDialog : public Glib::Object
{
   _CLASS_GOBJECT(FileDialog, GtkFileDialog, GTK_FILE_DIALOG, Glib::Object, GObject, , , GTKMM_API)
  _DO_NOT_DERIVE_GTYPE dnl// GtkFileDialog is a final type
  _STRUCT_NOT_HIDDEN

protected:
  _CTOR_DEFAULT

public:
  _WRAP_CREATE()

  _WRAP_METHOD(Glib::ustring get_title() const, gtk_file_dialog_get_title)
  _WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_file_dialog_set_title)
  _WRAP_METHOD(bool get_modal() const, gtk_file_dialog_get_modal)
  _WRAP_METHOD(void set_modal(bool modal = true), gtk_file_dialog_set_modal)

  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_filters(), gtk_file_dialog_get_filters, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_filters() const, gtk_file_dialog_get_filters, refreturn, constversion)
  _WRAP_METHOD(void set_filters(const Glib::RefPtr<Gio::ListModel>& filters), gtk_file_dialog_set_filters)

  _WRAP_METHOD(Glib::RefPtr<FileFilter> get_current_filter(), gtk_file_dialog_get_current_filter, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const FileFilter> get_current_filter() const, gtk_file_dialog_get_current_filter, refreturn, constversion)
  _WRAP_METHOD(void set_current_filter(const Glib::RefPtr<FileFilter>& filter), gtk_file_dialog_set_current_filter)

  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> get_shortcut_folders(), gtk_file_dialog_get_shortcut_folders, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::ListModel> get_shortcut_folders() const, gtk_file_dialog_get_shortcut_folders, refreturn, constversion)
  _WRAP_METHOD(void set_shortcut_folders(const Glib::RefPtr<Gio::ListModel>& shortcut_folders), gtk_file_dialog_set_shortcut_folders)

  _WRAP_METHOD(Glib::RefPtr<Gio::File> get_current_folder(), gtk_file_dialog_get_current_folder, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::File> get_current_folder() const, gtk_file_dialog_get_current_folder, refreturn, constversion)
  _WRAP_METHOD(void set_current_folder(const Glib::RefPtr<Gio::File>& folder), gtk_file_dialog_set_current_folder)

  _WRAP_METHOD(void open(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::File>& current_file{.} = {},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_dialog_open, slot_name slot, slot_callback Gio::SignalProxy_async_callback)
  _WRAP_METHOD(Glib::RefPtr<Gio::File> open_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_dialog_open_finish, errthrow)

  _WRAP_METHOD(void select_folder(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::File>& current_folder{.} = {},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_dialog_select_folder, slot_name slot, slot_callback Gio::SignalProxy_async_callback)
  _WRAP_METHOD(Glib::RefPtr<Gio::File> select_folder_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_dialog_select_folder_finish, errthrow)

  _WRAP_METHOD(void save(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::File>& current_file{.} = {}, const std::string& current_name{. NULL} = {},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_dialog_save, slot_name slot, slot_callback Gio::SignalProxy_async_callback)
  _WRAP_METHOD(Glib::RefPtr<Gio::File> save_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_dialog_save_finish, errthrow)

  _WRAP_METHOD(void open_multiple(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_dialog_open_multiple, slot_name slot, slot_callback Gio::SignalProxy_async_callback)
  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> open_multiple_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_dialog_open_multiple_finish, errthrow)

  _WRAP_METHOD(void select_multiple_folders(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_dialog_select_multiple_folders, slot_name slot, slot_callback Gio::SignalProxy_async_callback)
  _WRAP_METHOD(Glib::RefPtr<Gio::ListModel> select_multiple_folders_finish(
    const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_dialog_select_multiple_folders_finish, errthrow)

  _WRAP_PROPERTY("title", Glib::ustring)
  _WRAP_PROPERTY("modal", bool)
  _WRAP_PROPERTY("filters", Glib::RefPtr<Gio::ListModel>)
  _WRAP_PROPERTY("shortcut-folders", Glib::RefPtr<Gio::ListModel>)
  _WRAP_PROPERTY("current-filter", Glib::RefPtr<FileFilter>)
  _WRAP_PROPERTY("current-folder", Glib::RefPtr<Gio::File>)
};

} // namespace Gtk
