/* 
 * © 2008-2009 Sun Microsystems, Inc.
 *
 * 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 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _LF_UTILITIES_H_
#define _LF_UTILITIES_H_

#include <mforms/mforms.h>
#include "gtk_helpers.h"

#include "lf_mforms.h"

namespace mforms {
namespace gtk {

class UtilitiesImpl
{
  static sigc::slot<void,std::string> open_url_slot;
  
  static int show_message(const std::string &title, const std::string &text,
                          const std::string &ok, const std::string &cancel,
                          const std::string &other)
  {
    Gtk::MessageDialog dlg("<b>"+title+"</b>\n"+text, true,
                           Gtk::MESSAGE_INFO, Gtk::BUTTONS_NONE, true);
    
    dlg.add_button(ok, 1);
    if (!cancel.empty())
      dlg.add_button(cancel, 0);
    if (!other.empty())
      dlg.add_button(other, -1);
    
    dlg.set_transient_for(*get_mainwindow());
    return dlg.run();
  }

  
  static int show_error(const std::string &title, const std::string &text,
                        const std::string &ok, const std::string &cancel,
                        const std::string &other)
  {
    Gtk::MessageDialog dlg("<b>"+title+"</b>\n"+text, true,
                           Gtk::MESSAGE_ERROR, Gtk::BUTTONS_NONE, true);
    
    dlg.add_button(ok, 1);
    if (!cancel.empty())
      dlg.add_button(cancel, 0);
    if (!other.empty())
      dlg.add_button(other, -1);
    
    dlg.set_transient_for(*get_mainwindow());
    return dlg.run();
  }

  static int show_warning(const std::string &title, const std::string &text,
                        const std::string &ok, const std::string &cancel,
                        const std::string &other)
  {
    Gtk::MessageDialog dlg("<b>"+title+"</b>\n"+text, true,
                           Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE, true);
    
    dlg.add_button(ok, 1);
    if (!cancel.empty())
      dlg.add_button(cancel, 0);
    if (!other.empty())
      dlg.add_button(other, -1);
    
    dlg.set_transient_for(*get_mainwindow());
    return dlg.run();
  }

  static void set_clipboard_text(const std::string &text)
  {
    Gtk::Clipboard::get()->set_text(text);
  }

  static std::string get_clipboard_text()
  {
    return Gtk::Clipboard::get()->wait_for_text();
  }
  
  static void open_url(const std::string &url)
  {
    open_url_slot(url);
  }
  
  static std::string get_special_folder(mforms::FolderType type)
  {
    switch (type)
    {
    case mforms::Documents:
      return g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS);
    case mforms::Desktop:
      return g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
    }
    return "";
    
  }

public:
  static void init()
  {
    ::mforms::ControlFactory *f = ::mforms::ControlFactory::get_instance();

    f->_utilities_impl.show_message= &UtilitiesImpl::show_message;
    f->_utilities_impl.show_error= &UtilitiesImpl::show_error;
    f->_utilities_impl.show_warning= &UtilitiesImpl::show_warning;
    f->_utilities_impl.set_clipboard_text= &UtilitiesImpl::set_clipboard_text;
    f->_utilities_impl.get_clipboard_text= &UtilitiesImpl::get_clipboard_text;
    f->_utilities_impl.open_url= &UtilitiesImpl::open_url;
    f->_utilities_impl.get_special_folder= &UtilitiesImpl::get_special_folder;
  }
  
  static void set_open_url_slot(const sigc::slot<void,std::string> &slot)
  {
    open_url_slot= slot;
  }
};

};
};

#endif
