/* 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 <glibmm/vectorutils.h>

#include <gtk/gtk.h>

namespace Gtk
{

bool RecentManager::add_item(const Glib::ustring& uri, const Data& data)
{
  GtkRecentData c_data;
  gboolean result;

  // I wonder whether these should be const in the GTK+ API. armin.
  c_data.display_name = data.display_name.empty() ? NULL : const_cast<gchar*>(data.display_name.c_str());
  c_data.description = const_cast<gchar*>(data.description.c_str());
  c_data.mime_type = const_cast<gchar*>(data.mime_type.c_str());
  c_data.app_name = const_cast<gchar*>(data.app_name.c_str());
  c_data.app_exec = const_cast<gchar*>(data.app_exec.c_str());
  
  c_data.groups = static_cast<gchar**>(g_malloc((data.groups.size() + 1) * sizeof(gchar*)));
  for(unsigned int i = 0; i < data.groups.size(); ++ i)
    c_data.groups[i] = const_cast<gchar*>(data.groups[i].c_str());
  c_data.groups[data.groups.size()] = NULL;
  
  c_data.is_private = data.is_private;

  result = gtk_recent_manager_add_full(gobj(), uri.c_str(), &c_data);
  g_free(c_data.groups);
  return result == TRUE;
}

} //namespace Gtk
