/* 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/file.h>
#include <gtk/gtk.h>

namespace Gtk
{
class Window;

/** A %Gtk::FileLauncher object collects the arguments that are needed 
 * to open a uri with an application.
 *
 * Depending on system configuration, user preferences and available APIs, this
 * may or may not show an app chooser dialog or launch the default application
 * right away.
 *
 * The operation is started with the launch() method. This API follows the GIO
 * async pattern, and the result can be obtained by calling launch_finish().
 *
 * To launch uris that don't represent files, use Gtk::UriLauncher.
 *
 * @newin{4,10}
 */
class GTKMM_API FileLauncher : public Glib::Object
{
   _CLASS_GOBJECT(FileLauncher, GtkFileLauncher, GTK_FILE_LAUNCHER, Glib::Object, GObject, , , GTKMM_API)
  _DO_NOT_DERIVE_GTYPE dnl// GtkFileLauncher is a final type
  _STRUCT_NOT_HIDDEN

protected:
  _WRAP_CTOR(FileLauncher(const Glib::RefPtr<Gio::File>& file), gtk_file_launcher_new)

public:
  _WRAP_CREATE(const Glib::RefPtr<Gio::File>& file = {})

  _WRAP_METHOD(Glib::RefPtr<Gio::File> get_file(), gtk_file_launcher_get_file, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::File> get_file() const, gtk_file_launcher_get_file, refreturn, constversion)
  _WRAP_METHOD(void set_file(const Glib::RefPtr<Gio::File>& file), gtk_file_launcher_set_file)

  _WRAP_METHOD(bool get_always_ask() const, gtk_file_launcher_get_always_ask)
  _WRAP_METHOD(void set_always_ask(bool always_ask = true), gtk_file_launcher_set_always_ask)

  _WRAP_METHOD(bool get_writable() const, gtk_file_launcher_get_writable)
  _WRAP_METHOD(void set_writable(bool writable = true), gtk_file_launcher_set_writable)

  _WRAP_METHOD(void launch(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_launcher_launch, slot_name slot, slot_callback Gdk::gdkmm_SignalProxy_async_callback)
  _WRAP_METHOD(bool launch_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_launcher_launch_finish, errthrow "Gtk::DialogError, Gio::Error")

  _WRAP_METHOD(void open_containing_folder(Window& parent{?}, const Gio::SlotAsyncReady& slot{callback},
    const Glib::RefPtr<Gio::Cancellable>& cancellable{.} = {}) const,
    gtk_file_launcher_open_containing_folder, slot_name slot, slot_callback Gdk::gdkmm_SignalProxy_async_callback)
  _WRAP_METHOD(bool open_containing_folder_finish(const Glib::RefPtr<Gio::AsyncResult>& result) const,
    gtk_file_launcher_open_containing_folder_finish, errthrow "Gtk::DialogError, Gio::Error")

  _WRAP_PROPERTY("file", Glib::RefPtr<Gio::File>)
  _WRAP_PROPERTY("always-ask", bool)
  _WRAP_PROPERTY("writable", bool)
};

} // namespace Gtk
