/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License.
 *
 *
 *                      ********************
 *
 *
 *  This program 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 Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **************************************************************************************/
#ifdef         __SAMBA_ENABLE

#include <gtk/gtk.h>

#include "Menu_Samba_Callbacks.h"
#include "Menu_Samba_Interface.h"
#include "../Debug.h"
#include "../Objet.h"
#include "../Objet_Liste.h"
#include "../Module_Samba.h"
#include "Root_Interface.h"

void on_rename_activate (GtkMenuItem * menuitem, gpointer user_data)
{
	GtkTreeViewColumn *column = NULL;
	GtkTreePath *path = NULL;
	GtkTreeModel *model = NULL;

	debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Renomme :  [%s]", Objet_Selectionner->Chaine_Attacher);
	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Modules));//Reseau_Selectionner->Liste_Module));
	gtk_tree_store_set (GTK_TREE_STORE (model), &Objet_Selectionner->ID_Arbre_Ligne, COLUMN_EDITABLE_LIST, TRUE, -1);
	column = gtk_tree_view_get_column (GTK_TREE_VIEW (treeview_Modules),0);
	path = gtk_tree_model_get_path (model, &Objet_Selectionner->ID_Arbre_Ligne);
	gtk_tree_view_set_cursor (GTK_TREE_VIEW (treeview_Modules), path, column, TRUE); 
	gtk_tree_path_free (path);
}


void on_delete_activate (GtkMenuItem * menuitem, gpointer user_data)
{
	struct Struct_Modele_Objet *Objet = NULL;
	GList    *Liste_Selection = NULL;
	GtkTreeModel *model = NULL;
	GtkTreeSelection *selection = NULL;
	GtkTreePath *path = NULL;
	GtkTreeIter iter;
	gint      i, Nb_Selection;

	model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview_Modules));//Reseau_Selectionner->Liste_Module));
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview_Modules));
	Liste_Selection = gtk_tree_selection_get_selected_rows (selection, &model);
	Nb_Selection = g_list_length (Liste_Selection);
	debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Selection suppression : %d", Nb_Selection);
	for (i = 0; i < Nb_Selection; i++) {
		path = g_list_nth_data (Liste_Selection, Nb_Selection - i - 1);
		if (gtk_tree_model_get_iter (model, &iter, path)) {
			gtk_tree_model_get (model, &iter, POINTER_LIST, &Objet, -1);
			debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Supprime(%d) :  [%s]", Nb_Selection - i - 1, Objet->Chaine_Attacher);
			switch (Objet->ID_Modele_Objet) {
			    case FICHIER_PARTAGER:
				    Destruction_Fichier_Samba (Objet);
				    break;
			    case PARTAGE_REPERTOIRE:
				    Destruction_Repertoire_Samba (Objet);
				    break;
			    default:
				    debug_printf (INTERFACE, D_WARN, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Type d'Objet a supprimer inconnu : %d", Objet->ID_Modele_Objet);
			}
		}
	}
}


void on_new_folder_activate (GtkMenuItem * menuitem, gpointer user_data)
{
	debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Nouveau repertoire :  [%s]", Objet_Selectionner->Chaine_Attacher);
	Creation_Repertoire_Samba ();
}


void on_newfile_activate (GtkMenuItem * menuitem, gpointer user_data)
{
	debug_printf (INTERFACE, D_INFO, __FILE__, __PRETTY_FUNCTION__, __LINE__, "Nouveau fichier :  [%s]", Objet_Selectionner->Chaine_Attacher);
	Creation_Fichier_Samba ();
}

#endif
