/* Copyright (C) 2003 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 <https://www.gnu.org/licenses/>.
 */

#include <glibmm/vectorutils.h>
#include <gtk/gtk.h>

using Action = Gtk::FileChooser::Action;

namespace
{
template <typename CppType, typename CType = typename CppType::BaseObjectType>
std::vector<Glib::RefPtr<CppType>> listmodel_to_vector(GListModel* listmodel)
{
  std::vector<Glib::RefPtr<CppType>> result;
  const guint n_items = g_list_model_get_n_items(listmodel);
  for (guint pos = 0; pos < n_items; ++pos)
    // g_list_model_get_object() gives us a reference.
    result.push_back(Glib::wrap((CType*)g_list_model_get_object(listmodel, pos)));
  // The caller had a reference that's no longer needed.
  g_object_unref(listmodel);
  return result;
}
} // anonymous namespace

namespace Gtk
{

void FileChooser::add_choice(const Glib::ustring& id, const Glib::ustring& label)
{
  gtk_file_chooser_add_choice(gobj(), id.c_str(), label.c_str(), nullptr, nullptr);
}

} // namespace Gtk
