/* 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <vector>

#include <gdkmm/pixbuf.h>
#include <giomm/icon.h>
#include <giomm/appinfo.h>
#include <ctime>

_DEFS(gtkmm,gtk)

#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C"
{
typedef struct _GtkRecentInfo GtkRecentInfo;
void gtk_recent_info_unref(GtkRecentInfo* info);
}
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */

namespace Gtk
{

/** Contains information found when looking up an entry of the
 * recently used files list.
 *
 * @newin{2,10}
 *
 * @ingroup RecentFiles
 */
class RecentInfo final
{
  _CLASS_OPAQUE_REFCOUNTED(RecentInfo, GtkRecentInfo, NONE, gtk_recent_info_ref, gtk_recent_info_unref)
  _IGNORE(gtk_recent_info_ref, gtk_recent_info_unref)
public:

  _WRAP_METHOD(Glib::ustring get_uri() const, gtk_recent_info_get_uri)
  _WRAP_METHOD(Glib::ustring get_display_name() const, gtk_recent_info_get_display_name)
  _WRAP_METHOD(Glib::ustring get_description() const, gtk_recent_info_get_description)
  _WRAP_METHOD(Glib::ustring get_mime_type() const, gtk_recent_info_get_mime_type)

  _WRAP_METHOD(std::time_t get_added() const, gtk_recent_info_get_added)
  _WRAP_METHOD(std::time_t get_modified() const, gtk_recent_info_get_modified)
  _WRAP_METHOD(std::time_t get_visited() const, gtk_recent_info_get_visited)

  _WRAP_METHOD(bool get_private_hint() const, gtk_recent_info_get_private_hint)

  #m4 _CONVERSION(`GAppInfo*',`Glib::RefPtr<Gio::AppInfo>',`Glib::wrap($3)')
  _WRAP_METHOD(Glib::RefPtr<Gio::AppInfo> create_app_info(const Glib::ustring& app_name), gtk_recent_info_create_app_info, errthrow)

  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_application_info)
  bool get_application_info(const Glib::ustring& app_name, std::string& app_exec,
                            guint& count, std::time_t& time) const;

  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_applications)
  std::vector<Glib::ustring> get_applications() const;

  _WRAP_METHOD(Glib::ustring last_application() const, gtk_recent_info_last_application)
  _WRAP_METHOD(bool has_application(const Glib::ustring& app_name) const,
               gtk_recent_info_has_application)

  _WRAP_METHOD_DOCS_ONLY(gtk_recent_info_get_groups)
  std::vector<Glib::ustring> get_groups() const;

  _WRAP_METHOD(bool has_group(const Glib::ustring& group_name) const, gtk_recent_info_has_group)

  _WRAP_METHOD(Glib::RefPtr<Gdk::Pixbuf> get_icon(int size),
               gtk_recent_info_get_icon, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gdk::Pixbuf> get_icon(int size) const,
               gtk_recent_info_get_icon, refreturn, constversion)

  _WRAP_METHOD(Glib::RefPtr<Gio::Icon> get_gicon(),
               gtk_recent_info_get_gicon, refreturn)
  _WRAP_METHOD(Glib::RefPtr<const Gio::Icon> get_gicon() const,
               gtk_recent_info_get_gicon, refreturn, constversion)

  _WRAP_METHOD(Glib::ustring get_short_name() const, gtk_recent_info_get_short_name)
  _WRAP_METHOD(Glib::ustring get_uri_display() const, gtk_recent_info_get_uri_display)

  _WRAP_METHOD(int get_age() const, gtk_recent_info_get_age)
  _WRAP_METHOD(bool is_local() const, gtk_recent_info_is_local)
  _WRAP_METHOD(bool exists() const, gtk_recent_info_exists)
#m4begin
_CONVERSION(`const RecentInfo&',`GtkRecentInfo*', `const_cast<GtkRecentInfo*>(($3).gobj())')
#m4end
  _WRAP_METHOD(bool equal(const RecentInfo& info_b) const, gtk_recent_info_match)
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS

struct RecentInfoTraits
{
  typedef Glib::RefPtr<RecentInfo> CppType;
  typedef const GtkRecentInfo* CType;
  typedef GtkRecentInfo* CTypeNonConst;

  static inline CType to_c_type(const CppType& obj) { return Glib::unwrap(obj); }
  static inline CType to_c_type(const CType& obj) { return obj; }
  static CppType to_cpp_type(const CType& obj);
  static inline void release_c_type(const CType& obj)
    { gtk_recent_info_unref(const_cast<CTypeNonConst>(obj)); }
};
#endif /* !DOXYGEN_SHOULD_SKIP_THIS */

// TODO: These are almost impossible to use without RefPtr<>::operator*()

/** @relates Gtk::RecentInfo */
inline bool operator==(const RecentInfo& lhs, const RecentInfo& rhs)
  { return lhs.equal(rhs); }

/** @relates Gtk::RecentInfo */
inline bool operator!=(const RecentInfo& lhs, const RecentInfo& rhs)
  { return !lhs.equal(rhs); }

} // namespace Gtk

namespace Glib
{

// This is needed so Glib::RefPtr<Gtk::RecentInfo> can be used with
// Glib::Value and Gtk::TreeModelColumn:
template <>
class Value< Glib::RefPtr<Gtk::RecentInfo> > : public ValueBase_Boxed
{
public:
  typedef Glib::RefPtr<Gtk::RecentInfo> CppType;
  typedef GtkRecentInfo* CType;

  static GType value_type();

  void set(const CppType& data);
  CppType get() const;
};

} // namespace Glib
