/* Copyright (C) 2006 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, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtk.h>

namespace Gtk
{

RecentInfo::operator bool() const
{
  return gobj() != 0;
}

Glib::StringArrayHandle RecentInfo::get_applications() const
{
  gsize length = 0;
  char** const applications =
    gtk_recent_info_get_applications(const_cast<GtkRecentInfo*>(gobj()), &length);

  return Glib::StringArrayHandle(applications, length, Glib::OWNERSHIP_DEEP);
}

bool RecentInfo::get_application_info(const Glib::ustring& app_name, std::string& app_exec,
                                      guint& count, time_t& time_) const
{
  const char* app_exec_cstr = 0;
  const int found = gtk_recent_info_get_application_info(
      const_cast<GtkRecentInfo*>(gobj()), app_name.c_str(), &app_exec_cstr, &count, &time_);

  if (app_exec_cstr)
    app_exec = app_exec_cstr;
  else
    app_exec.erase();

  return (found != 0);
}

Glib::StringArrayHandle RecentInfo::get_groups() const
{
  gsize length = 0;
  char** const groups = gtk_recent_info_get_groups(const_cast<GtkRecentInfo*>(gobj()), &length);

  return Glib::StringArrayHandle(groups, length, Glib::OWNERSHIP_DEEP);
}

RecentInfoTraits::CppType RecentInfoTraits::to_cpp_type(const CType& obj)
{
  return Glib::wrap(const_cast<CTypeNonConst>(obj), true);
}

} // namespace Gtk

namespace Glib
{

GType Value<RefPtr<Gtk::RecentInfo> >::value_type()
{
  return gtk_recent_info_get_type();
}

void Value<RefPtr<Gtk::RecentInfo> >::set(const CppType& data)
{
  set_boxed(data->gobj());
}

Value<RefPtr<Gtk::RecentInfo> >::CppType Value<RefPtr<Gtk::RecentInfo> >::get() const
{
  return Glib::wrap(static_cast<CType>(get_boxed()), true);
}

} // namespace Glib
