<?xml version="1.0"?>
<gcm>
  <item id="1">
    <type>text</type>
    <time>13:33:04</time>
    <from>Application</from>
    <data>/* * C o p y r i g h t *(also read COPYING)* * * * * * * * * * * * * * * * * * *
 *                                                                             *
 *  Copyright (C) 2002  &lt;Philip Van Hoof&gt;                                      *
 *                                                                             *
 *  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, or          *
 *  (at your option) any later version.                                        *
 *                                                                             *
 *  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 General Public License for more details.                               *
 *                                                                             *
 *  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  *
 *                                                                             *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include &lt;sys/time.h&gt;
#include &lt;time.h&gt;
#include &lt;string.h&gt;
#include &quot;mainwin.h&quot;
#include &quot;aboutwin.h&quot;
#include &quot;newitemwin.h&quot;
#include &quot;textitemwin.h&quot;
#include &quot;dataitemwin.h&quot;
#include &quot;gnomefilelist.h&quot;
#include &quot;prefswin.h&quot;
#include &lt;libxml/xmlmemory.h&gt;
#include &lt;libxml/parser.h&gt;
#include &lt;libxml/tree.h&gt;
#include &lt;libxml/xmlIO.h&gt;


static void mainwin_class_init(MainWinClass *klass);
static void mainwin_init(MainWin *mwin);
static void mainwin_destroy(GtkObject *object);

static GtkWindowClass *parent_class = NULL;

/* If you change a menu, also change it in the popmainwinmenu*/
/* And set the datapointer in the mainwin_new function to mwin !*/
static GnomeUIInfo mainwinmenu_file_menu_uiinfo[] =
{
#define MAINWINMENU_FILE_NEWITEM 0
  GNOMEUIINFO_MENU_NEW_ITEM (N_(&quot;_New item...&quot;), NULL, on_mainwinmenu_newitem_activate, NULL),
  {
#define MAINWINMENU_FILE_DELETEITEM 1
    GNOME_APP_UI_ITEM, N_(&quot;_Delete items&quot;),
    NULL,
    (gpointer) on_mainwinmenu_deleteitem_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_CLOSE,
    0, (GdkModifierType) 0, NULL
  },
#define MAINWINMENU_FILE_SAVEITEMTODISK 2
  {
    GNOME_APP_UI_ITEM, N_(&quot;_Save items to disk...&quot;),
    NULL,
    (gpointer) on_mainwinmenu_file_savetodisk_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE_AS,
    0, (GdkModifierType) 0, NULL
  },
#define MAINWINMENU_FILE_OPENITEMFROMDISK 3
  {
    GNOME_APP_UI_ITEM, N_(&quot;_Load items from disk...&quot;),
    NULL,
    (gpointer) on_mainwinmenu_file_openfromdisk_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
    0, (GdkModifierType) 0, NULL
  },
#define MAINWINMENU_FILE_SEPARATOR 4
  GNOMEUIINFO_SEPARATOR,
#define MAINWINMENU_FILE_EXIT 5
  GNOMEUIINFO_MENU_EXIT_ITEM (on_mainwinmenu_exit_activate, NULL),
#define MAINWINMENU_FILE_END 6
  GNOMEUIINFO_END
};

static GnomeUIInfo mainwinmenu_edit_menu_uiinfo[] =
{
#define MAINWINMENU_EDIT_CUT 0
  GNOMEUIINFO_MENU_CUT_ITEM (on_mainwinmenu_cut_activate, NULL),
#define MAINWINMENU_EDIT_COPY 1
  GNOMEUIINFO_MENU_COPY_ITEM (on_mainwinmenu_copy_activate, NULL),
#define MAINWINMENU_EDIT_PASTE 2
  GNOMEUIINFO_MENU_PASTE_ITEM (on_mainwinmenu_paste_activate, NULL),
#define MAINWINMENU_EDIT_CLEAR 3
  GNOMEUIINFO_MENU_CLEAR_ITEM (on_mainwinmenu_clear_activate, NULL),
#define MAINWINMENU_EDIT_SEPARATOR 4
  GNOMEUIINFO_SEPARATOR,
#define MAINWINMENU_EDIT_SELECT_ALL 5
  GNOMEUIINFO_MENU_SELECT_ALL_ITEM (on_mainwinmenu_selectall_activate, NULL),
{
#define MAINWINMENU_EDIT_SELECT_NONE 6
    GNOME_APP_UI_ITEM, N_(&quot;_Select none&quot;),
    NULL,
    (gpointer) on_mainwinmenu_selectnone_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_UNDO,
    0, (GdkModifierType) 0, NULL
  },	
#define MAINWINMENU_EDIT_END 7
  GNOMEUIINFO_END
};

static GnomeUIInfo mainwinmenu_settings_menu_uiinfo[] =
{
#define MAINWINMENU_SETTINGS_PREFERENCES 0
  GNOMEUIINFO_MENU_PREFERENCES_ITEM (on_mainwinmenu_preferences_activate, NULL),
#define MAINWINMENU_SETTINGS_END 1
  GNOMEUIINFO_END
};

static GnomeUIInfo mainwinmenu_help_menu_uiinfo[] =
{
#define MAINWINMENU_HELP_ABOUT 0
  GNOMEUIINFO_MENU_ABOUT_ITEM (on_mainwinmenu_about_activate, NULL),
#define MAINWINMENU_HELP_END 1
  GNOMEUIINFO_END
};

static GnomeUIInfo mainwinmenu_uiinfo[] =
{
#define MAINWINMENU_FILE 0
  GNOMEUIINFO_MENU_FILE_TREE (mainwinmenu_file_menu_uiinfo),
#define MAINWINMENU_EDIT 1
  GNOMEUIINFO_MENU_EDIT_TREE (mainwinmenu_edit_menu_uiinfo),
#define MAINWINMENU_SETTINGS 2
  GNOMEUIINFO_MENU_SETTINGS_TREE (mainwinmenu_settings_menu_uiinfo),
#define MAINWINMENU_HELP 3
  GNOMEUIINFO_MENU_HELP_TREE (mainwinmenu_help_menu_uiinfo),
#define MAINWINMENU_END 4
  GNOMEUIINFO_END
};

static GnomeUIInfo popmainwinmenu_file_menu_uiinfo[] =
{
#define POPMAINWINMENU_FILE_NEWITEM 0
  GNOMEUIINFO_MENU_NEW_ITEM (N_(&quot;_New item...&quot;), NULL, on_mainwinmenu_newitem_activate, NULL),
  {
#define POPMAINWINMENU_FILE_DELETEITEM 1
    GNOME_APP_UI_ITEM, N_(&quot;_Delete items&quot;),
    NULL,
    (gpointer) on_mainwinmenu_deleteitem_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_CLOSE,
    0, (GdkModifierType) 0, NULL
  },
#define POPMAINWINMENU_FILE_SAVEITEMTODISK 2
  {
    GNOME_APP_UI_ITEM, N_(&quot;_Save items to disk...&quot;),
    NULL,
    (gpointer) on_mainwinmenu_file_savetodisk_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE_AS,
    0, (GdkModifierType) 0, NULL
  },
#define POPMAINWINMENU_FILE_OPENITEMFROMDISK 3
  {
    GNOME_APP_UI_ITEM, N_(&quot;_Load items from disk...&quot;),
    NULL,
    (gpointer) on_mainwinmenu_file_openfromdisk_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_OPEN,
    0, (GdkModifierType) 0, NULL
  },

#define POPMAINWINMENU_FILE_SEPARATOR 4
  GNOMEUIINFO_SEPARATOR,
#define POPMAINWINMENU_FILE_EXIT 5
  GNOMEUIINFO_MENU_EXIT_ITEM (on_mainwinmenu_exit_activate, NULL),
#define POPMAINWINMENU_FILE_END 6
  GNOMEUIINFO_END
};

static GnomeUIInfo popmainwinmenu_edit_menu_uiinfo[] =
{
#define POPMAINWINMENU_EDIT_CUT 0
  GNOMEUIINFO_MENU_CUT_ITEM (on_mainwinmenu_cut_activate, NULL),
#define POPMAINWINMENU_EDIT_COPY 1
  GNOMEUIINFO_MENU_COPY_ITEM (on_mainwinmenu_copy_activate, NULL),
#define POPMAINWINMENU_EDIT_PASTE 2
  GNOMEUIINFO_MENU_PASTE_ITEM (on_mainwinmenu_paste_activate, NULL),
#define POPMAINWINMENU_EDIT_CLEAR 3
  GNOMEUIINFO_MENU_CLEAR_ITEM (on_mainwinmenu_clear_activate, NULL),
#define POPMAINWINMENU_EDIT_SEPARATOR 4
  GNOMEUIINFO_SEPARATOR,
#define POPMAINWINMENU_EDIT_SELECT_ALL 5
  GNOMEUIINFO_MENU_SELECT_ALL_ITEM (on_mainwinmenu_selectall_activate, NULL),
{
#define POPMAINWINMENU_EDIT_SELECT_NONE 6
    GNOME_APP_UI_ITEM, N_(&quot;_Select none&quot;),
    NULL,
    (gpointer) on_mainwinmenu_selectnone_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_UNDO,
    0, (GdkModifierType) 0, NULL
  },	
#define POPMAINWINMENU_EDIT_END 7
  GNOMEUIINFO_END
};

static GnomeUIInfo popmainwinmenu_settings_menu_uiinfo[] =
{
#define POPMAINWINMENU_SETTINGS_PREFERENCES 0
  GNOMEUIINFO_MENU_PREFERENCES_ITEM (on_mainwinmenu_preferences_activate, NULL),
#define POPMAINWINMENU_SETTINGS_END 1
  GNOMEUIINFO_END
};

static GnomeUIInfo popmainwinmenu_help_menu_uiinfo[] =
{
#define POPMAINWINMENU_HELP_ABOUT 0
  GNOMEUIINFO_MENU_ABOUT_ITEM (on_mainwinmenu_about_activate, NULL),
#define POPMAINWINMENU_HELP_END 1
  GNOMEUIINFO_END
};



static GnomeUIInfo popmainwinmenu_uiinfo[] =
{
#define POPMAINWINMENU_FILE 0
  GNOMEUIINFO_MENU_FILE_TREE (popmainwinmenu_file_menu_uiinfo),
#define POPMAINWINMENU_EDIT 1
  GNOMEUIINFO_MENU_EDIT_TREE (popmainwinmenu_edit_menu_uiinfo),
#define POPMAINWINMENU_SETTINGS 2
  GNOMEUIINFO_MENU_SETTINGS_TREE (popmainwinmenu_settings_menu_uiinfo),
#define POPMAINWINMENU_HELP 3
  GNOMEUIINFO_MENU_HELP_TREE (popmainwinmenu_help_menu_uiinfo),
#define POPMAINWINMENU_END 4
  GNOMEUIINFO_END
};

static GnomeUIInfo cliplistpopupmenu_uiinfo[] =
{
#define CLIPLISTPOPUPMENU_NEWITEM 0
  GNOMEUIINFO_MENU_NEW_ITEM (N_(&quot;_New&quot;), NULL, on_cliplistpopupmenu_new_activate, NULL),
#define CLIPLISTPOPUPMENU_CUTITEM 1
  GNOMEUIINFO_MENU_CUT_ITEM (on_cliplistpopupmenu_cut_activate, NULL),

#define CLIPLISTPOPUPMENU_COPYITEM 2
  GNOMEUIINFO_MENU_COPY_ITEM (on_cliplistpopupmenu_copy_activate, NULL),
#define CLIPLISTPOPUPMENU_PASTEITEM 3
  GNOMEUIINFO_MENU_PASTE_ITEM (on_cliplistpopupmenu_paste_activate, NULL),
  {
#define CLIPLISTPOPUPMENU_EDITITEM 4
    GNOME_APP_UI_ITEM, N_(&quot;_Edit item&quot;),
    NULL,
    (gpointer) on_cliplistpopupmenu_edit_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_SAVE_AS,
    0, (GdkModifierType) 0, NULL
  },
#define CLIPLISTPOPUPMENU_FILEMENU 5
  GNOMEUIINFO_SUBTREE (N_(&quot;_Menu&quot;), popmainwinmenu_uiinfo),
#define CLIPLISTPOPUPMENU_MOVE_UP 6
  {
    GNOME_APP_UI_ITEM, N_(&quot;Move item _up&quot;),
    NULL,
    (gpointer) on_mainwinmenu_moveup_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_UP,
    0, (GdkModifierType) 0, NULL
  },
#define CLIPLISTPOPUPMENU_MOVE_DOWN 7
  {
    GNOME_APP_UI_ITEM, N_(&quot;Move item _down&quot;),
    NULL,
    (gpointer) on_mainwinmenu_movedown_activate, NULL, NULL,
    GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_DOWN,
    0, (GdkModifierType) 0, NULL
  },
#define CLIPLISTPOPUPMENU_SEPARATOR 8
  GNOMEUIINFO_SEPARATOR,
#define CLIPLISTPOPUPMENU_END 9
  GNOMEUIINFO_END
};





GtkType mainwin_get_type(void)
{
	static GtkType mainwin_type = 0;
	if (!mainwin_type)
	{
		static const GtkTypeInfo mainwin_info =
		{	
			&quot;MainWin&quot;,
			sizeof (MainWin),
			sizeof (MainWinClass),
			(GtkClassInitFunc) mainwin_class_init,
			(GtkObjectInitFunc) mainwin_init,
			NULL,
			NULL,
			(GtkClassInitFunc) NULL,
		};
		mainwin_type = gtk_type_unique (GTK_TYPE_WINDOW, &mainwin_info);
	}
	return (mainwin_type);
}

static void mainwin_class_init(MainWinClass *klass)
{
	GtkObjectClass *object_class;
	object_class = (GtkObjectClass*)klass;
	object_class-&gt;destroy = mainwin_destroy;
	parent_class = gtk_type_class(GTK_TYPE_WINDOW);
}

static void mainwin_init(MainWin *mwin)
{

}

static void mainwin_destroy(GtkObject *object)
{
	GtkWidget *mwin;

	g_return_if_fail(object != NULL);
	g_return_if_fail(GNOME_IS_MAINWIN(object));
	mwin = GTK_WIDGET(object);
	gtk_widget_destroy(mwin);
	gtk_exit(0);
}




/* Saves the preferences (to GConf in our case) */
gboolean saveprefs_tofile (Prefs *prefs)
{
	GConfEngine *conf;
	GError *err=NULL;
	if (prefs != NULL) {
		if (gconf_is_initialized ()) {
			conf = gconf_engine_get_default ();
			gconf_engine_ref (conf);
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/notfirst_time&quot;, TRUE, &err)) return FALSE;
			if (!gconf_engine_set_int (conf, &quot;/app/gcm/prefs/selection_type&quot;, prefs-&gt;selection_type, &err)) return FALSE;
			if (!gconf_engine_set_string (conf, &quot;/app/gcm/prefs/custom_selection_type&quot;, prefs-&gt;custom_selection_type, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/beep_on_collect&quot;, prefs-&gt;beep_on_collect, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/auto_collect&quot;, prefs-&gt;auto_collect, &err)) return FALSE;
#ifdef DEVELOPMENT
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/debug&quot;, prefs-&gt;debug, &err)) return FALSE;
#endif
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_cliplist_titles&quot;, prefs-&gt;show_cliplist_titles, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_statusbar&quot;, prefs-&gt;show_statusbar, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_toolbar&quot;, prefs-&gt;show_toolbar, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_menu&quot;, prefs-&gt;show_menu, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_from&quot;, prefs-&gt;show_from, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_type&quot;, prefs-&gt;show_type, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_time&quot;, prefs-&gt;show_time, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/show_datap&quot;, prefs-&gt;show_datap, &err)) return FALSE;
			if (!gconf_engine_set_bool (conf, &quot;/app/gcm/prefs/multisel&quot;, prefs-&gt;multisel, &err)) return FALSE;
		} else {
			gnome_error_dialog(_(&quot;Unable to initialize GConf. Check your GConf package.&quot;)); 
			return FALSE;
		}
	} else {
		return FALSE;
	}
	return TRUE;
}


/* Loads the preferences from file (GConf in our case) */
Prefs* getprefs_fromfile (void)
{
	Prefs *prefs=NULL;
	GConfEngine *conf;
	GError *err=NULL;

	conf = gconf_engine_get_default ();
	gconf_engine_ref (conf);
	prefs = g_malloc0(sizeof(Prefs));

	/* Fetched from gconf */
	if (gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/notfirst_time&quot;, &err)) {
		prefs->selection_type = gconf_engine_get_int (conf, "/app/gcm/prefs/selection_type", &err);
		prefs-&gt;custom_selection_type = gconf_engine_get_string (conf, &quot;/app/gcm/prefs/custom_selection_type&quot;, &err);
		prefs-&gt;beep_on_collect = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/beep_on_collect&quot;, &err);
		prefs-&gt;auto_collect = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/auto_collect&quot;, &err);
#ifdef DEVELOPMENT
		prefs-&gt;debug = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/debug&quot;, &err);
#endif
		prefs-&gt;show_toolbar = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_toolbar&quot;, &err);
		prefs-&gt;show_menu = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_menu&quot;, &err);
		prefs-&gt;show_cliplist_titles = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_cliplist_titles&quot;, &err);
		prefs-&gt;show_statusbar = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_statusbar&quot;, &err);
		prefs-&gt;show_from = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_from&quot;, &err);
		prefs-&gt;show_type = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_type&quot;, &err);
		prefs-&gt;show_time = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_time&quot;, &err);
		prefs-&gt;show_datap = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/show_datap&quot;, &err);
		prefs-&gt;multisel = gconf_engine_get_bool (conf, &quot;/app/gcm/prefs/multisel&quot;, &err);
	} else {
		prefs-&gt;selection_type = PREFS_SELECTION_TYPE_CLIPBOARD;
		prefs-&gt;show_menu = TRUE;
		prefs-&gt;show_toolbar = TRUE;
#ifdef DEVELOPMENT
		prefs-&gt;debug = FALSE;
#endif
		prefs-&gt;auto_collect=TRUE;
		prefs-&gt;beep_on_collect=TRUE;
		prefs-&gt;show_toolbar=TRUE;
		prefs-&gt;show_menu=TRUE;
		prefs-&gt;show_cliplist_titles=TRUE;
		prefs-&gt;show_statusbar=TRUE;
		prefs-&gt;show_from=TRUE;
		prefs-&gt;show_type=TRUE;
		prefs-&gt;show_time=TRUE;
		prefs-&gt;show_datap=TRUE;
		prefs-&gt;multisel=TRUE;
		prefs-&gt;custom_selection_type = g_strdup(&quot;CLIPBOARD&quot;);
		saveprefs_tofile (prefs);
		/* Any firsttime messages could go here */
	}
	return prefs;
}


/* Reloads the preferences. Should be called each time a preference is changed */
void reload_prefs (MainWin *mwin)
{
  mwin-&gt;prefs = getprefs_fromfile ();
  switch (mwin-&gt;prefs-&gt;selection_type) {
	 case PREFS_SELECTION_TYPE_CLIPBOARD :
		  mwin-&gt;selection = gdk_atom_intern (&quot;CLIPBOARD&quot;, FALSE);
		  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecentry), 
		 _(PREFS_SELECTION_TYPE_CLIPBOARD_TEXT));
	 break;

	 case PREFS_SELECTION_TYPE_PRIMARY :
		  mwin-&gt;selection = GDK_SELECTION_PRIMARY;
		  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecentry), 
		 _(PREFS_SELECTION_TYPE_PRIMARY_TEXT));
	 break;

	 case PREFS_SELECTION_TYPE_SECONDARY :
		  mwin-&gt;selection = GDK_SELECTION_SECONDARY;
		  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecentry), 
		 _(PREFS_SELECTION_TYPE_SECONDARY_TEXT));
	 break;

	 case PREFS_SELECTION_TYPE_CUSTOM :
		  mwin-&gt;selection = gdk_atom_intern (mwin-&gt;prefs-&gt;custom_selection_type, FALSE);
		  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecentry), 
		 _(PREFS_SELECTION_TYPE_CUSTOM_TEXT));
	 break;

	 default :
		  mwin-&gt;selection = gdk_atom_intern (&quot;CLIPBOARD&quot;, FALSE);
		  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecentry), 
		 _(PREFS_SELECTION_TYPE_CLIPBOARD_TEXT));
	 break;
  }
  gtk_selection_add_target (GTK_WIDGET(mwin), mwin-&gt;selection, GDK_SELECTION_TYPE_STRING,1);
  gtk_entry_set_text (GTK_ENTRY (GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;seltypecustentry), mwin-&gt;prefs-&gt;custom_selection_type);
#ifdef DEVELOPMENT
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;devcheck), mwin-&gt;prefs-&gt;debug);
#endif
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;colbeep), mwin-&gt;prefs-&gt;beep_on_collect);  
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;colauto), mwin-&gt;prefs-&gt;auto_collect);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowtoolbar), mwin-&gt;prefs-&gt;show_toolbar);
  if (mwin-&gt;prefs-&gt;show_toolbar) {
	  gtk_widget_show(mwin-&gt;toolbar);
	  gtk_widget_show(mwin-&gt;toolbarhandlebox);
  } else {
	  gtk_widget_hide(mwin-&gt;toolbar);
	  gtk_widget_hide(mwin-&gt;toolbarhandlebox);
  }
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowmenu), mwin-&gt;prefs-&gt;show_menu);
  if (mwin-&gt;prefs-&gt;show_menu) {
	  gtk_widget_show(mwin-&gt;mainwinmenu);
	  gtk_widget_show(mwin-&gt;menuhandlebox);
  } else {
	  gtk_widget_hide(mwin-&gt;mainwinmenu);
	  gtk_widget_hide(mwin-&gt;menuhandlebox);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowtitles), mwin-&gt;prefs-&gt;show_cliplist_titles);  
  if (mwin-&gt;prefs-&gt;show_cliplist_titles) {
	  gtk_clist_column_titles_show (GTK_CLIST(mwin-&gt;cliplist));
  } else {
	  gtk_clist_column_titles_hide (GTK_CLIST(mwin-&gt;cliplist));
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowstatus), mwin-&gt;prefs-&gt;show_statusbar);  
  if (mwin-&gt;prefs-&gt;show_statusbar) {
	  gtk_widget_show(mwin-&gt;appbar);
  } else {
	  gtk_widget_hide(mwin-&gt;appbar);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowtime), mwin-&gt;prefs-&gt;show_time);
  if (mwin-&gt;prefs-&gt;show_time) {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_DATE_FIELD, TRUE);
  } else {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_DATE_FIELD, FALSE);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowtype), mwin-&gt;prefs-&gt;show_type);
  if (mwin-&gt;prefs-&gt;show_type) {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_TYPE_FIELD, TRUE);
  } else {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_TYPE_FIELD, FALSE);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowdatap), mwin-&gt;prefs-&gt;show_datap);
  if (mwin-&gt;prefs-&gt;show_datap) {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_DATA_FIELD, TRUE);
  } else {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_DATA_FIELD, FALSE);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guishowfrom), mwin-&gt;prefs-&gt;show_from);
  if (mwin-&gt;prefs-&gt;show_from) {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_FROM_FIELD, TRUE);
  } else {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_FROM_FIELD, FALSE);
  }

  if (!mwin-&gt;prefs-&gt;show_from & !mwin->prefs->show_time && !mwin->prefs->show_datap && !mwin->prefs->show_type) {
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin->cliplist), CLIST_DATA_FIELD, TRUE);
	  gtk_clist_set_column_visibility (GTK_CLIST(mwin-&gt;cliplist), CLIST_FROM_FIELD, FALSE);
  }

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(GNOME_PREFSWIN(mwin-&gt;prefswin)-&gt;guimultisel), mwin-&gt;prefs-&gt;multisel);
  if (mwin-&gt;prefs-&gt;multisel) {
	gtk_widget_show(mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_ALL].widget);
	gtk_widget_show(mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_NONE].widget);
	gtk_widget_show(popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_ALL].widget);
	gtk_widget_show(popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_NONE].widget);
	gtk_clist_set_selection_mode (GTK_CLIST(mwin-&gt;cliplist), GTK_SELECTION_MULTIPLE);  
  } else {
  	gtk_widget_hide(mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_ALL].widget);
	gtk_widget_hide(mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_NONE].widget);
  	gtk_widget_hide(popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_ALL].widget);
	gtk_widget_hide(popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_NONE].widget);
	gtk_clist_set_selection_mode (GTK_CLIST(mwin-&gt;cliplist), GTK_SELECTION_SINGLE);  
  }

  app_update_menus(mwin);
}


/* Create the mainwin */
GtkWidget* mainwin_new (GtkWidget *windowparent)
{
  MainWin *mwin;
	GtkAccelGroup *accel_group;

	accel_group = gtk_accel_group_new ();

  mwin = gtk_type_new(GNOME_TYPE_MAINWIN);
  gtk_signal_connect(GTK_OBJECT(mwin), &quot;show&quot;, GTK_SIGNAL_FUNC(mainwin_show), mwin);
  gtk_signal_connect(GTK_OBJECT(mwin), &quot;hide&quot;, GTK_SIGNAL_FUNC(mainwin_hide), mwin);
  mwin-&gt;windowparent = windowparent;
  gtk_widget_set_usize (GTK_WIDGET(mwin), 670, 400);
  gtk_window_set_title (GTK_WINDOW (mwin), _(&quot;Gnome Clipboard Manager&quot;));
  gtk_window_set_policy (GTK_WINDOW (mwin), TRUE, TRUE, FALSE);
  gtk_window_add_accel_group (GTK_WINDOW (mwin), accel_group);

  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_NEWITEM].user_data = mwin;
  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_DELETEITEM].user_data = mwin;
  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_SAVEITEMTODISK].user_data = mwin;
  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_OPENITEMFROMDISK].user_data = mwin;
  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_SEPARATOR].user_data = mwin;
  mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_EXIT].user_data = mwin;

  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_CUT].user_data = mwin;
  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_COPY].user_data = mwin;
  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_PASTE].user_data = mwin;
  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_CLEAR].user_data = mwin;
  /* Set visible/unvisible in reload_prefs() */
  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_ALL].user_data = mwin;
  mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_SELECT_NONE].user_data = mwin;
  
  mainwinmenu_settings_menu_uiinfo[MAINWINMENU_SETTINGS_PREFERENCES].user_data = mwin;

  mainwinmenu_help_menu_uiinfo[MAINWINMENU_HELP_ABOUT].user_data = mwin;

  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_NEWITEM].user_data = mwin;
  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_DELETEITEM].user_data = mwin;
  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_SAVEITEMTODISK].user_data = mwin;
  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_OPENITEMFROMDISK].user_data = mwin;
  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_SEPARATOR].user_data = mwin;
  popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_EXIT].user_data = mwin;

  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_CUT].user_data = mwin;
  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_COPY].user_data = mwin;
  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_PASTE].user_data = mwin;
  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_CLEAR].user_data = mwin;
  /* Set visible/unvisible in reload_prefs() */
  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_ALL].user_data = mwin;
  popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_SELECT_NONE].user_data = mwin;

  popmainwinmenu_settings_menu_uiinfo[POPMAINWINMENU_SETTINGS_PREFERENCES].user_data = mwin;

  popmainwinmenu_help_menu_uiinfo[POPMAINWINMENU_HELP_ABOUT].user_data = mwin;

  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_NEWITEM].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_CUTITEM].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_COPYITEM].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_PASTEITEM].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_EDITITEM].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_MOVE_UP].user_data = mwin;
  cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_MOVE_DOWN].user_data = mwin;
  /* GNOME 2.0 porting issue http://developer.gnome.org/doc/API/2.0/gtk/textwidget.html */
  mwin-&gt;clipboard = gtk_text_new(NULL, NULL);
  gtk_widget_show(mwin-&gt;clipboard);
  
  mwin-&gt;topvbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (mwin-&gt;topvbox);
  gtk_container_add (GTK_CONTAINER (mwin), mwin-&gt;topvbox);

  mwin-&gt;vbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (mwin-&gt;vbox);
  gtk_box_pack_start (GTK_BOX (mwin-&gt;topvbox), mwin-&gt;vbox, TRUE, TRUE, 0);

  mwin-&gt;mainwinmenu = gtk_menu_bar_new ();
  gtk_widget_show (mwin-&gt;mainwinmenu);

  mwin-&gt;menuhandlebox = gtk_handle_box_new ();
  gtk_widget_show (mwin-&gt;menuhandlebox);
  gtk_box_pack_start (GTK_BOX (mwin-&gt;vbox), mwin-&gt;menuhandlebox, FALSE, TRUE, 0);

  gtk_container_add (GTK_CONTAINER (mwin-&gt;menuhandlebox), mwin-&gt;mainwinmenu);

  gnome_app_fill_menu (GTK_MENU_SHELL (mwin-&gt;mainwinmenu), mainwinmenu_uiinfo,
                       NULL, FALSE, 0);

  mwin-&gt;cliplistpopupmenu = gtk_menu_new ();
  gnome_app_fill_menu (GTK_MENU_SHELL (mwin-&gt;cliplistpopupmenu), cliplistpopupmenu_uiinfo,
                       NULL, FALSE, 0);

  mwin-&gt;toolbarhandlebox = gtk_handle_box_new ();
  gtk_widget_show (mwin-&gt;toolbarhandlebox);
  gtk_box_pack_start (GTK_BOX (mwin-&gt;vbox), mwin-&gt;toolbarhandlebox, FALSE, TRUE, 0);


  mwin-&gt;toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
  gtk_widget_show (mwin-&gt;toolbar);
  gtk_container_add (GTK_CONTAINER (mwin-&gt;toolbarhandlebox), mwin-&gt;toolbar);

  gtk_container_set_border_width (GTK_CONTAINER (mwin-&gt;toolbar), 1);
 
  /* GNOME 2.0 Porting issue (these are removed?) */
  /*gtk_toolbar_set_space_size (GTK_TOOLBAR (mwin-&gt;toolbar), 16);
  gtk_toolbar_set_space_style (GTK_TOOLBAR (mwin-&gt;toolbar), GTK_TOOLBAR_SPACE_LINE);*/
  gtk_toolbar_set_button_relief (GTK_TOOLBAR (mwin-&gt;toolbar), GTK_RELIEF_NONE);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_NEW);
  mwin-&gt;toolbar_newitem = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;New item&quot;),
                                _(&quot;New File&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_newitem);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_CLOSE);
  mwin-&gt;toolbar_deleteitem = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Delete items&quot;),
                                _(&quot;Delete items&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_deleteitem);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_SAVE_AS);
  mwin-&gt;toolbar_edititem = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Edit item&quot;),
                                _(&quot;Edit item&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_edititem);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_CLEAR);
  mwin-&gt;toolbar_clear = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Clear list&quot;),
                                _(&quot;Clear list&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_clear);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_PREFERENCES);
  mwin-&gt;toolbar_preferences = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Preferences&quot;),
                                _(&quot;Preferences&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_preferences);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_REFRESH);
  mwin-&gt;toolbar_refresh = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Get current&quot;),
                                _(&quot;Get current selection from windowmanager&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_refresh);

  mwin-&gt;tmp_toolbar_icon = gnome_stock_pixmap_widget (GTK_WIDGET(mwin), GNOME_STOCK_PIXMAP_EXIT);
  mwin-&gt;toolbar_quit = gtk_toolbar_append_element (GTK_TOOLBAR (mwin-&gt;toolbar),
                                GTK_TOOLBAR_CHILD_BUTTON,
                                NULL,
                                _(&quot;Exit&quot;),
                                _(&quot;Quit application&quot;), NULL,
                                mwin-&gt;tmp_toolbar_icon, NULL, NULL);
  gtk_widget_show (mwin-&gt;toolbar_quit);

  mwin-&gt;scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
  gtk_widget_show (mwin-&gt;scrolledwindow);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mwin-&gt;scrolledwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_box_pack_start (GTK_BOX (mwin-&gt;vbox), mwin-&gt;scrolledwindow, TRUE, TRUE, 0);
  
  mwin-&gt;cliplist = gtk_clist_new (CLIST_FIELD_COUNT);
  gtk_widget_show (mwin-&gt;cliplist);
  
  gtk_clist_set_selection_mode (GTK_CLIST(mwin-&gt;cliplist), GTK_SELECTION_MULTIPLE);
  gtk_container_add (GTK_CONTAINER (mwin-&gt;scrolledwindow), mwin-&gt;cliplist);
  gtk_clist_set_column_width (GTK_CLIST (mwin-&gt;cliplist), CLIST_DATE_FIELD, 60);
  gtk_clist_set_column_width (GTK_CLIST (mwin-&gt;cliplist), CLIST_TYPE_FIELD, 48);
  gtk_clist_set_column_width (GTK_CLIST (mwin-&gt;cliplist), CLIST_FROM_FIELD, 43);
  gtk_clist_set_column_width (GTK_CLIST (mwin-&gt;cliplist), CLIST_DATA_FIELD, 80);
  gtk_clist_column_titles_show (GTK_CLIST (mwin-&gt;cliplist));

  mwin-&gt;cliplistlabel_time = gtk_label_new (_(&quot;Time&quot;));
  gtk_widget_show (mwin-&gt;cliplistlabel_time);
  gtk_clist_set_column_widget (GTK_CLIST (mwin-&gt;cliplist), CLIST_DATE_FIELD, mwin-&gt;cliplistlabel_time);

  mwin-&gt;cliplistlabel_type = gtk_label_new (_(&quot;Type&quot;));
  gtk_widget_show (mwin-&gt;cliplistlabel_type);
  gtk_clist_set_column_widget (GTK_CLIST (mwin-&gt;cliplist), CLIST_TYPE_FIELD, mwin-&gt;cliplistlabel_type);

  mwin-&gt;cliplistlabel_from = gtk_label_new (_(&quot;From&quot;));
  gtk_widget_show (mwin-&gt;cliplistlabel_from);
  gtk_clist_set_column_widget (GTK_CLIST (mwin-&gt;cliplist), CLIST_FROM_FIELD, mwin-&gt;cliplistlabel_from);

  mwin-&gt;cliplistlabel_data = gtk_label_new (_(&quot;Data preview&quot;));
  gtk_widget_show (mwin-&gt;cliplistlabel_data);
  gtk_clist_set_column_widget (GTK_CLIST (mwin-&gt;cliplist), CLIST_DATA_FIELD, mwin-&gt;cliplistlabel_data);
  
  mwin-&gt;appbar = gnome_appbar_new (TRUE, TRUE, GNOME_PREFERENCES_NEVER);
  gtk_widget_show (mwin-&gt;appbar);
  gtk_box_pack_start (GTK_BOX (mwin-&gt;topvbox), mwin-&gt;appbar, FALSE, TRUE, 0);
  gnome_appbar_push (GNOME_APPBAR(mwin-&gt;appbar), &quot;I don't own the selection&quot;);
 
  mwin-&gt;prefswin = prefswin_new(GTK_WIDGET(mwin));
  reload_prefs(mwin);
  
  gtk_signal_connect (GTK_OBJECT (mwin), &quot;destroy&quot;,
                      GTK_SIGNAL_FUNC (mainwin_destroy),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_newitem), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_newitem_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_deleteitem), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_deleteitem_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_edititem), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_edititem_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_clear), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_clear_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_preferences), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_preferences_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_refresh), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_refresh_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;toolbar_quit), &quot;clicked&quot;,
                      GTK_SIGNAL_FUNC (on_toolbar_quit_clicked),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;cliplist), &quot;click_column&quot;,
                      GTK_SIGNAL_FUNC (on_cliplist_click_column),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin-&gt;cliplist), &quot;event&quot;,
                      GTK_SIGNAL_FUNC (on_cliplist_event),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_event),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;topvbox), &quot;event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_event),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;vbox), &quot;event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_event),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;scrolledwindow), &quot;event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_event),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin-&gt;cliplist), &quot;select_row&quot;,
                      GTK_SIGNAL_FUNC (on_cliplist_select_row),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin-&gt;cliplist), &quot;unselect_row&quot;,
                      GTK_SIGNAL_FUNC (on_cliplist_unselect_row),
                      mwin);
  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_get&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_selection_get),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_clear_event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_selection_lost),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_notify_event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_in_selection_notify_event),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_request_event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_in_selection_request_event),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_clear_event&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_in_selection_clear_event),
                      mwin);

  gtk_signal_connect (GTK_OBJECT (mwin), &quot;selection_received&quot;,
                      GTK_SIGNAL_FUNC (on_mainwin_selection_received),
                      mwin);
  gtk_window_set_wmclass (GTK_WINDOW (mwin), &quot;mainwin&quot;, &quot;gcm&quot;);

	gtk_widget_add_accelerator (mwin-&gt;toolbar_deleteitem, &quot;clicked&quot;, accel_group, GDK_D, 0, 0);
	gtk_widget_add_accelerator (mwin-&gt;toolbar_newitem, &quot;clicked&quot;, accel_group, GDK_N, GDK_CONTROL_MASK, 0);
	gtk_widget_add_accelerator (mwin-&gt;toolbar_quit, &quot;clicked&quot;, accel_group, GDK_Q, GDK_CONTROL_MASK, 0);
	
  return GTK_WIDGET(mwin);
}



/* Mainwin functions */

/* This parses an item from an XML-doc */
Selection *parseSelection(xmlDocPtr doc, xmlNodePtr cur)
{
	Selection *item;

	item = (Selection*) malloc(sizeof(Selection));
	memset(item, 0, sizeof(Selection));
	item-&gt;type=NULL;
	item-&gt;time=NULL;
	item-&gt;from=NULL;
	item-&gt;data=NULL;
	cur = cur-&gt;xmlChildrenNode;
	while (cur != NULL) {
		if (!strcmp(cur-&gt;name, &quot;time&quot;))
			item-&gt;time = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
		if (!strcmp(cur-&gt;name, &quot;type&quot;))
			item-&gt;type = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
		if (!strcmp(cur-&gt;name, &quot;from&quot;))
			item-&gt;from = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
		if (!strcmp(cur-&gt;name, &quot;data&quot;))
			item-&gt;data = xmlNodeListGetString(doc, cur-&gt;xmlChildrenNode, 1);
		/* if &lt;tag/&gt; then we fill the item with emptyness */
		/* Else, for some reason, touching the struct will segfault */
		if (item-&gt;time == NULL) item-&gt;time = g_strdup(&quot;&quot;);
		if (item-&gt;type == NULL) item-&gt;type = g_strdup(&quot;&quot;);
		if (item-&gt;from == NULL) item-&gt;from = g_strdup(&quot;&quot;);
		if (item-&gt;data == NULL) item-&gt;data = g_strdup(&quot;&quot;);

		cur = cur-&gt;next;
	}
	return(item);
}



/* Saves selected items to an XML file */
gboolean app_save_items_to_disk(gchar *path, SaveAsData *sa)
{
	gint i=0;
	gchar *c;
	xmlDocPtr rootnode;

	rootnode = xmlNewDoc((xmlChar *) &quot;1.0&quot;);
	rootnode-&gt;root = xmlNewNode(NULL, (xmlChar *) &quot;gcm&quot;);
	xmlNewDtd(rootnode, &quot;gcm&quot;, &quot;http://gcm.sourceforge.net/DTD_gcmdoc_XML_V1.0//EN&quot;, &quot;gcmdoc.dtd&quot;);

	while (sa-&gt;items) {
		xmlNodePtr itemnode;
		Selection *item;
		
		i++; c=g_strdup_printf(&quot;%d&quot;, i);
		item = (Selection*) sa-&gt;items-&gt;data;
		itemnode = xmlNewNode(NULL, (xmlChar *) &quot;item&quot;);
			xmlNewProp (itemnode, &quot;id&quot;, c);
			xmlNewChild (itemnode,NULL,&quot;type&quot;, item-&gt;type);
			xmlNewChild (itemnode,NULL,&quot;time&quot;, item-&gt;time);
			xmlNewChild (itemnode,NULL,&quot;from&quot;, item-&gt;from);
			xmlNewChild (itemnode,NULL,&quot;data&quot;, item-&gt;data);
		xmlAddChild (rootnode-&gt;root, itemnode);
		sa-&gt;items = g_list_next(sa-&gt;items);
	}
	g_free(c);
	xmlSaveFile(path, rootnode);
}


/* Loads items from an XML file */
void app_load_items_from_disk(MainWin *mwin, gchar *path)
{
	xmlDocPtr doc;
	xmlNodePtr cur;

	doc = xmlParseFile(path);
	if (doc == NULL) return;
	cur = xmlDocGetRootElement(doc);
	if (cur == NULL) {
		gnome_error_dialog(_(&quot;Empty document!&quot;));
		xmlFreeDoc(doc);
		return;
	}
	if (xmlStrcmp(cur-&gt;name, (const xmlChar *) &quot;gcm&quot;)) {
		gnome_error_dialog(_(&quot;This is not a GCM XML file !&quot;));
		xmlFreeDoc(doc);
		return;
	}
	cur = cur-&gt;xmlChildrenNode;

	while (cur)
	{
		Selection *item=NULL;
		
		item = (Selection*) malloc(sizeof(Selection));
		memset(item, 0, sizeof(Selection));
		item = parseSelection(doc, cur);
		app_add_selection(mwin, item);
		cur = cur -&gt; next;
	}
	xmlFreeDoc(doc);

}




/* Creates and/or shows the preferences window */
void app_show_prefswin (MainWin *mwin, gpointer *user_data) {
	if (mwin-&gt;prefswin==NULL) {
		reload_prefs(mwin);
		mwin-&gt;prefswin = prefswin_new(GTK_WIDGET(mwin));
	}
	gtk_widget_show(mwin-&gt;prefswin);

}


/* Claims selection when more then one item can be selected */
void app_claim_multi_selection (MainWin *mwin)
{
		GList *selected;
		Selection *item, *ritem;
		gboolean first=TRUE;

		ritem=(Selection*) g_malloc0(sizeof(Selection));
		selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;   
		if (selected) {
			while (selected) {
				Selection *nitem;
				if (first) {
					item = gtk_clist_get_row_data(GTK_CLIST(mwin-&gt;cliplist),(gint) selected-&gt;data);
					ritem-&gt;time = g_strdup(item-&gt;time);
					ritem-&gt;type = g_strdup(item-&gt;type);
					ritem-&gt;from = g_strdup(item-&gt;from);
					ritem-&gt;data = g_strdup(item-&gt;data);
					ritem-&gt;row = item-&gt;row;
					first = FALSE;
				} else {
					nitem = gtk_clist_get_row_data(GTK_CLIST(mwin-&gt;cliplist),(gint) selected-&gt;data);
					ritem-&gt;data = g_strdup_printf(&quot;%s%s&quot;, ritem-&gt;data, nitem-&gt;data);
				}			
				selected = g_list_next(selected);
			}
		
			app_claim_text_selection (mwin, ritem);
			/* free buffers */
		} else {
			return;
		}
}

/* Claims selection for one item */
void app_claim_text_selection (MainWin *mwin, Selection *item)
{
	gchar *data=NULL;
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Claiming selection with data: %s\n&quot;, data);
#endif
	if (item) {
		data = g_strdup(item-&gt;data);
		/*GNOME 2.0 porting issue (GtkText is replaced) */
		gtk_editable_delete_text (GTK_EDITABLE(mwin-&gt;clipboard), 0, -1);
		gtk_text_insert (GTK_TEXT(mwin-&gt;clipboard), NULL, NULL, NULL, data, strlen(data));
		if (gtk_selection_owner_set (GTK_WIDGET(mwin), mwin-&gt;selection, GDK_CURRENT_TIME))
			gnome_appbar_push (GNOME_APPBAR(mwin-&gt;appbar), _(&quot;I own the selection&quot;));
		else
			gnome_appbar_push (GNOME_APPBAR(mwin-&gt;appbar), _(&quot;Claiming selection failed&quot;));
		g_free(data);
	} else {
		gnome_appbar_push (GNOME_APPBAR(mwin-&gt;appbar), _(&quot;Claiming selection failed&quot;));
#ifdef DEVELOPMENT
		if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GNOME Clipboard Manager ERROR: Item empty, not claiming selection\n&quot;);
#endif
	}
}


/* Gets a new item; The callback 'on_mainwin_selection_received' will recive it */
void app_get_new_item (MainWin *mwin, gpointer *user_data) 
{
  static GdkAtom targets_atom = GDK_NONE;
  mwin-&gt;lastnewrow = -1;
  mwin-&gt;lastnewitem = NULL;
  targets_atom = gdk_atom_intern (&quot;TEXT&quot;, FALSE); 
  gtk_selection_convert (GTK_WIDGET(mwin), mwin-&gt;selection, targets_atom, GDK_CURRENT_TIME);
}


/* Deletes the selected items (Warning: recursive function call) */
void app_delete_selected_items(MainWin *mwin, GtkCList *cliplist, gpointer *usr_data)
{
	GList *selected;
	gint row;

	selected = cliplist-&gt;selection;
	
	if (!(selected)){
		return;
	} else {
		selected = g_list_first(selected);
		row = (gint) selected-&gt;data;
		gtk_clist_remove(cliplist, row);
		/*recursive function call*/
		app_delete_selected_items(mwin, cliplist, usr_data);
		if (mwin-&gt;prefs-&gt;multisel==FALSE) gtk_clist_select_row(GTK_CLIST(mwin-&gt;cliplist), row, -1);
	}
}


/* Add a new item with &quot;From&quot; and &quot;Data&quot; */
gint app_add_text_selection (MainWin *mwin, gchar *from, gchar *data)
{
	Selection *item;
	time_t timeval=time(0);
	char *tim = malloc (32);	

	strftime(tim, 32, &quot;%H:%M:%S&quot;, localtime (&timeval));
	item = g_malloc0(sizeof(Selection));
	  item-&gt;time = tim;
	  item-&gt;from = g_strdup(from);
	  item-&gt;data = g_strdup(data);
	  item-&gt;type = g_strdup(&quot;text&quot;);
	return app_add_selection(mwin, item);
}


/* Add a new selection using a prefilled in item */
gint app_add_selection (MainWin *mwin, Selection *item)
{
	gchar *text[CLIST_FIELD_COUNT];
	gint row;
	if (item != NULL) {
		if (item-&gt;time != NULL) text[CLIST_DATE_FIELD] = g_strdup(item-&gt;time);
			else text[CLIST_DATE_FIELD] = g_strdup(&quot;&quot;);
		if (item-&gt;type != NULL) text[CLIST_TYPE_FIELD] = g_strdup(item-&gt;type);
			else text[CLIST_TYPE_FIELD] = g_strdup(&quot;&quot;);
		if (item-&gt;data != NULL) {
			if (strlen(item-&gt;data) &gt; CLIST_DATA_PREVIEW_LENGTH) {
				text[CLIST_DATA_FIELD] = g_strndup(item-&gt;data, CLIST_DATA_PREVIEW_LENGTH);
				text[CLIST_DATA_FIELD] = g_strdup_printf(&quot;%s...&quot;, text[CLIST_DATA_FIELD]);
			} else text[CLIST_DATA_FIELD] = g_strdup(item-&gt;data);
		} else text[CLIST_DATA_FIELD] = g_strdup(&quot;&quot;);
		if (item-&gt;from != NULL) text[CLIST_FROM_FIELD] = g_strdup(item-&gt;from);
			else text[CLIST_FROM_FIELD] = g_strdup(&quot;&quot;);
		row = gtk_clist_append(GTK_CLIST (mwin-&gt;cliplist), text);
		if (mwin-&gt;prefs-&gt;beep_on_collect) gdk_beep();
		gtk_clist_set_row_data (GTK_CLIST(mwin-&gt;cliplist), row, item);
		mwin-&gt;lastnewitem = item;
		/* Q: Make this a checkbox on the GUI or preferences ? */
		if (mwin-&gt;prefs-&gt;multisel) gtk_clist_unselect_all (GTK_CLIST(mwin-&gt;cliplist));
		gtk_clist_select_row(GTK_CLIST(mwin-&gt;cliplist), row, 1);
		/*free buffers*/
		return row;
	} else {
		g_print(&quot;GCM ERROR: Item containted no data!\n&quot;);
		return 0;
	}
}


/* Updates a row with &quot;From&quot; and &quot;Data&quot; */
void app_update_text_selection (MainWin *mwin, gint row, gchar *from, gchar *data)
{
	Selection *item;
	gchar *text[CLIST_FIELD_COUNT];
	time_t timeval=time(0);
	char *tim = malloc (32);	
	
    strftime(tim, 32, &quot;%H:%M:%S&quot;, localtime (&timeval));
	
	item = gtk_clist_get_row_data (GTK_CLIST(mwin-&gt;cliplist), row);
	  item-&gt;time = tim;
	  item-&gt;from = g_strdup(from);
	  item-&gt;data = g_strdup(data);
	  item-&gt;type = g_strdup(&quot;text&quot;);
	
	text[CLIST_DATE_FIELD] = g_strdup(item-&gt;time);
	text[CLIST_TYPE_FIELD] = g_strdup(item-&gt;type);
	if (strlen(data) &gt; CLIST_DATA_PREVIEW_LENGTH) {
		text[CLIST_DATA_FIELD] = g_strndup(item-&gt;data, CLIST_DATA_PREVIEW_LENGTH);
		text[CLIST_DATA_FIELD] = g_strdup_printf(&quot;%s...&quot;, text[CLIST_DATA_FIELD]);
	} else text[CLIST_DATA_FIELD] = g_strdup(item-&gt;data);
	text[CLIST_FROM_FIELD] = g_strdup(item-&gt;from);
	
	gtk_clist_set_text (GTK_CLIST (mwin-&gt;cliplist), row, CLIST_TYPE_FIELD, text[CLIST_TYPE_FIELD]);
	gtk_clist_set_text (GTK_CLIST (mwin-&gt;cliplist), row, CLIST_DATE_FIELD, text[CLIST_DATE_FIELD]);
	gtk_clist_set_text (GTK_CLIST (mwin-&gt;cliplist), row, CLIST_FROM_FIELD, text[CLIST_FROM_FIELD]);
	gtk_clist_set_text (GTK_CLIST (mwin-&gt;cliplist), row, CLIST_DATA_FIELD, text[CLIST_DATA_FIELD]);
	gtk_clist_set_row_data (GTK_CLIST(mwin-&gt;cliplist), row, item);
	gtk_clist_select_row(GTK_CLIST(mwin-&gt;cliplist), row, 1);
	/* free buffers */
}




/* Creates and/or shows a newitemwin */
GtkWidget* app_create_and_show_newitemwin (MainWin *mwin, gpointer *user_data)
{
	if (mwin-&gt;newitemwin==NULL) {
		mwin-&gt;newitemwin = newitemwin_new(GTK_WIDGET(mwin));
	}
	gtk_widget_show(mwin-&gt;newitemwin);
	return mwin-&gt;newitemwin;
}


/* Creates and/or shows a textitemwin */
GtkWidget* app_create_and_show_textitemwin (MainWin *mwin, gint row)
{
	GtkWidget *textitemwin;
	Selection *item;

	item = gtk_clist_get_row_data (GTK_CLIST(mwin-&gt;cliplist), row);
	textitemwin = textitemwin_new(GTK_WIDGET(mwin));
	textitemwin_load_item(textitemwin, row, item-&gt;time, item-&gt;type, item-&gt;from, item-&gt;data);
	gtk_widget_show(textitemwin);
	return textitemwin;
}


/* Creates and/or shows a dataitemwin (unused at this moment)*/
GtkWidget* app_create_and_show_dataitemwin (MainWin *mwin, gint row)
{
	GtkWidget *dataitemwin;
	dataitemwin = dataitemwin_new(GTK_WIDGET(mwin));
	gtk_widget_show(dataitemwin);
	return dataitemwin;
}



/* Creates and/or shows an aboutwin */
GtkWidget* app_create_and_show_aboutwin (MainWin *mwin, gpointer *user_data)
{
	GtkWidget *aboutwin;
	aboutwin = aboutwin_new(GTK_WIDGET(mwin));
	gtk_widget_show(aboutwin);
	return aboutwin;
}





/* Moves selected rows one up */
void app_move_selected_up(MainWin *mwin, GList *remaining, gint startrow)
{
	if (mwin-&gt;prefs-&gt;multisel) {
		remaining = g_list_first(remaining);
		/* FIXME: move all up */
		gtk_clist_row_move (GTK_CLIST(mwin-&gt;cliplist), (gint) remaining-&gt;data, (gint) remaining-&gt;data-1);
	} else {
		remaining = g_list_first(remaining);
		gtk_clist_row_move (GTK_CLIST(mwin-&gt;cliplist), (gint) remaining-&gt;data, (gint) remaining-&gt;data-1);
	}
	
}


/* Moves selected rows one down */
void app_move_selected_down(MainWin *mwin, GList *remaining, gint startrow)
{
	if (mwin-&gt;prefs-&gt;multisel) {
		remaining = g_list_first(remaining);
		/* FIXME: move all down */
		gtk_clist_row_move (GTK_CLIST(mwin-&gt;cliplist), (gint) remaining-&gt;data, (gint) remaining-&gt;data+1);
	} else {
		remaining = g_list_first(remaining);
		gtk_clist_row_move (GTK_CLIST(mwin-&gt;cliplist), (gint) remaining-&gt;data, (gint) remaining-&gt;data+1);
	}
	
}


/* Function that updates the status of the menuitems */
void app_update_menus(MainWin *mwin)
{
	GList *selected;

	if (mwin-&gt;prefs-&gt;show_menu == FALSE) { /* This needs documentation for users */
		gtk_widget_show (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_FILEMENU].widget));
	} else {
		gtk_widget_hide (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_FILEMENU].widget));
	}

	selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;   
	if (selected) {
		selected = g_list_first (selected);
		if (selected) {
			gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_SAVEITEMTODISK].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_CUT].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_COPY].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_SAVEITEMTODISK].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_CUT].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_COPY].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_CUTITEM].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_COPYITEM].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_EDITITEM].widget), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (mwin-&gt;toolbar_deleteitem), TRUE);
			gtk_widget_set_sensitive (GTK_WIDGET (mwin-&gt;toolbar_edititem), TRUE);
		} else goto deactivate;
	} else goto deactivate;
	return;

deactivate:
	gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_file_menu_uiinfo[POPMAINWINMENU_FILE_SAVEITEMTODISK].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_CUT].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (popmainwinmenu_edit_menu_uiinfo[POPMAINWINMENU_EDIT_COPY].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_file_menu_uiinfo[MAINWINMENU_FILE_SAVEITEMTODISK].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_CUT].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (mainwinmenu_edit_menu_uiinfo[MAINWINMENU_EDIT_COPY].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_CUTITEM].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_COPYITEM].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (cliplistpopupmenu_uiinfo[CLIPLISTPOPUPMENU_EDITITEM].widget), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (mwin-&gt;toolbar_deleteitem), FALSE);
	gtk_widget_set_sensitive (GTK_WIDGET (mwin-&gt;toolbar_edititem), FALSE);
	return;
}

/* Mainwin Callbacks */

void mainwin_show(GtkWidget *widget, MainWin *mwin)
{
}
void mainwin_hide(GtkWidget *widget, MainWin *mwin)
{
}



/* Any event on the mainwin */
int
on_mainwin_event                       (GtkWidget       *widget,
										GdkEvent        *event,
										MainWin         *mwin)
{
	GdkEventButton *button_event = (GdkEventButton *) event;
	app_update_menus(mwin);
	if (event-&gt;type == GDK_BUTTON_PRESS & button_event->button == 3) {
		gtk_menu_popup (GTK_MENU(mwin->cliplistpopupmenu), NULL, NULL, NULL, NULL, 3, 
						button_event->time);
		return TRUE;
	}
	return FALSE;
}


/* When the gcm recived a selection (after we asked for it of course) */
void
on_mainwin_selection_received          (GtkWidget       *widget,
										GtkSelectionData *data,
										guint            time,
										MainWin          *mwin)
{
	gchar *mydata;

#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection received\n&quot;);
#endif
	if (data-&gt;data) {
		mydata = g_strdup(data-&gt;data);
		mwin-&gt;lastnewrow = app_add_text_selection(mwin, &quot;Application&quot;, mydata);

		gtk_clist_select_row(GTK_CLIST(mwin-&gt;cliplist), mwin-&gt;lastnewrow, 1);
		g_free(mydata);
	}
}


/* Unused at this moment */
gboolean
on_mainwin_in_selection_clear_event    (GtkWidget       *widget,
                                        GdkEventSelection *event,
                                        MainWin         *mwin)
{
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection clear\n&quot;);
#endif
	return FALSE;
}



/* Unused at this moment */
gboolean
on_mainwin_in_selection_notify_event   (GtkWidget       *widget,
                                        GdkEventSelection *event,
                                        MainWin         *mwin)
{
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection notify\n&quot;);
#endif
	return FALSE;
}



/* Unused at this moment */
gboolean
on_mainwin_in_selection_request_event  (GtkWidget       *widget,
                                        GdkEventSelection *event,
                                        MainWin         *mwin)
{ 
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection request\n&quot;);
#endif
	return TRUE;
}


/* When gcm lost it's selection (somebody else took it) -we recollect if that option is set- */
gboolean
on_mainwin_selection_lost              (GtkWidget         *widget,
                                        GdkEventSelection *event,
                                        MainWin           *mwin)
{
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection lost\n&quot;);
#endif
	gnome_appbar_push (GNOME_APPBAR(mwin-&gt;appbar), _(&quot;I don't own the selection&quot;));
	if (mwin-&gt;prefs-&gt;auto_collect==TRUE )
		app_get_new_item (mwin, (gpointer*) widget);	
	return TRUE;
}


/* When an application asks for &quot;our&quot; selection. The selection that we are holding must be returned */
void on_mainwin_selection_get          (GtkWidget        *widget, 
                                        GtkSelectionData *selection_data,
                                        guint             info,
                                        guint             time_stamp,
                                        MainWin           *mwin)
{
	gchar *buffer;

#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;GCM: Selection get request\n&quot;);
#endif
	buffer = g_strdup(gtk_editable_get_chars (GTK_EDITABLE(mwin-&gt;clipboard), 0, -1));
#ifdef DEVELOPMENT
	if (mwin-&gt;prefs-&gt;debug) g_print(&quot;in buff: %s\n&quot;, buffer);
#endif
	gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING,
	                        8, buffer, strlen(buffer));
	/*free buffer*/
	g_free(buffer);
}


void
on_mainwinmenu_newitem_activate        (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	app_create_and_show_newitemwin(mwin, (gpointer*) menuitem);
}

void
on_mainwinmenu_deleteitem_activate     (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	app_delete_selected_items (mwin, GTK_CLIST(mwin-&gt;cliplist), (gpointer*) menuitem);
}







void
on_mainwinmenu_moveup_activate         (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *remaining;
	remaining = g_list_copy(GTK_CLIST(mwin-&gt;cliplist)-&gt;selection);
	app_move_selected_up (mwin, remaining, -1);
}

void
on_mainwinmenu_movedown_activate         (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *remaining;
	remaining = g_list_copy(GTK_CLIST(mwin-&gt;cliplist)-&gt;selection);
	app_move_selected_down (mwin, remaining, -1);
}

void on_mainwin_overwrite_yes_no (gint answer, SaveAsData *sa)
{
	if (answer == 0)
		if (!app_save_items_to_disk(sa-&gt;path, sa)) {
			gnome_error_dialog(_(&quot;IO error while trying to save file&quot;));
		}

}

void
on_mainwin_savefilelist_ok_button_clicked
                                       (GtkButton *button,
                                        MainWin *mwin)
{
	gchar *msg;
	gint row;
	GList *selected;
	GtkWidget *question;
	FILE *f;
	SaveAsData *sa;

	sa = g_malloc0(sizeof(SaveAsData));
	sa-&gt;items = NULL;

	selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;
	if (selected) {
		while (selected) {
			row = (gint) selected-&gt;data;
			sa-&gt;items = g_list_append(sa-&gt;items, gtk_clist_get_row_data (GTK_CLIST(mwin-&gt;cliplist), row));
			selected = g_list_next(selected);
		}
	} else { 
		gnome_error_dialog(_(&quot;No item selected&quot;));
		return;
	}
	sa-&gt;path = g_strdup(gnome_filelist_get_filename(GNOME_FILELIST(mwin-&gt;savefilelist)));
	gtk_widget_destroy(mwin-&gt;savefilelist);
	if (f=fopen(sa-&gt;path,&quot;r&quot;)) {
		fclose(f);
		msg = g_strdup_printf(&quot;A file named ''%s'' already exists.\n&quot;
							  &quot;Do you want to replace it with the &quot;
							  &quot;one you are saving?&quot;, sa-&gt;path);
		question = gnome_question_dialog_modal
				(_(msg), GTK_SIGNAL_FUNC (on_mainwin_overwrite_yes_no), sa);
		gtk_widget_show(question);
	} else {
		if (!app_save_items_to_disk(sa-&gt;path, sa)) {
			gnome_error_dialog(_(&quot;IO error while trying to save file&quot;));
		}
	}
}

void
on_mainwin_savefilelist_cancel_button_clicked
                                       (GtkButton *button,
                                        MainWin *mwin)
{
	gtk_widget_destroy(mwin-&gt;savefilelist);
}


void
on_mainwinmenu_file_savetodisk_activate
                                       (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *selected;
	GList *colist=NULL;
	GList *combolist=NULL;

	selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;
	if (selected) {
		selected = g_list_first (selected);
		if (selected == NULL) {
			gnome_error_dialog(_(&quot;No item selected&quot;));
			return;
		}
		mwin-&gt;savefilelist = gnome_filelist_new();
		mwin-&gt;savefilelist_ok_button = GNOME_FILELIST(mwin-&gt;savefilelist)-&gt;ok_button;
		mwin-&gt;savefilelist_cancel_button = GNOME_FILELIST(mwin-&gt;savefilelist)-&gt;cancel_button;
		colist = gnome_filelisttype_addtype_f(colist, _(&quot;XML file&quot;), &quot;.xml&quot;, NULL);
		colist = gnome_filelisttype_addtype(colist, _(&quot;All files&quot;), NULL);
		gnome_filelisttype_clearfiletypes(GNOME_FILELIST(mwin-&gt;savefilelist));
		GNOME_FILELIST(mwin-&gt;savefilelist)-&gt;filetypes = colist;
		combolist = gnome_filelisttype_getcombolist(GNOME_FILELIST(mwin-&gt;savefilelist)-&gt;filetypes);   
		gnome_filelist_set_combolist(GNOME_FILELIST(mwin-&gt;savefilelist), combolist);
		gtk_widget_show(mwin-&gt;savefilelist);
		gtk_signal_connect (GTK_OBJECT (mwin-&gt;savefilelist_ok_button), &quot;clicked&quot;,
						  GTK_SIGNAL_FUNC (on_mainwin_savefilelist_ok_button_clicked),
						  mwin);
		gtk_signal_connect (GTK_OBJECT (mwin-&gt;savefilelist_cancel_button), &quot;clicked&quot;,
						  GTK_SIGNAL_FUNC (on_mainwin_savefilelist_cancel_button_clicked),
						  mwin);
	} else {
		gnome_error_dialog(_(&quot;No item selected&quot;));
	}
}



void
on_mainwin_openfilelist_ok_button_clicked
                                       (GtkButton *button,
                                        MainWin *mwin)
{
	gchar *path;

	path = g_strdup(gnome_filelist_get_filename(GNOME_FILELIST(mwin-&gt;openfilelist)));
	gtk_widget_destroy(mwin-&gt;openfilelist);
	app_load_items_from_disk(mwin, path);
	g_free(path);
}

void
on_mainwin_openfilelist_cancel_button_clicked
                                       (GtkButton *button,
                                        MainWin *mwin)
{
	gtk_widget_destroy(mwin-&gt;openfilelist);
}


void
on_mainwinmenu_file_openfromdisk_activate
                                       (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *colist=NULL;
	GList *combolist=NULL;
	
	mwin-&gt;openfilelist = gnome_filelist_new();
	gtk_widget_show(mwin-&gt;openfilelist);
	mwin-&gt;openfilelist_ok_button = GNOME_FILELIST(mwin-&gt;openfilelist)-&gt;ok_button;
	mwin-&gt;openfilelist_cancel_button = GNOME_FILELIST(mwin-&gt;openfilelist)-&gt;cancel_button;
	colist = gnome_filelisttype_addtype_f(colist, _(&quot;XML file&quot;), &quot;.xml&quot;, NULL);
	colist = gnome_filelisttype_addtype(colist, _(&quot;All files&quot;), NULL);
	gnome_filelisttype_clearfiletypes(GNOME_FILELIST(mwin-&gt;openfilelist));
	GNOME_FILELIST(mwin-&gt;openfilelist)-&gt;filetypes = colist;
	combolist = gnome_filelisttype_getcombolist(GNOME_FILELIST(mwin-&gt;openfilelist)-&gt;filetypes);   
	gnome_filelist_set_combolist(GNOME_FILELIST(mwin-&gt;openfilelist), combolist);
	gtk_signal_connect (GTK_OBJECT (mwin-&gt;openfilelist_ok_button), &quot;clicked&quot;,
					  GTK_SIGNAL_FUNC (on_mainwin_openfilelist_ok_button_clicked),
					  mwin);
	gtk_signal_connect (GTK_OBJECT (mwin-&gt;openfilelist_cancel_button), &quot;clicked&quot;,
					  GTK_SIGNAL_FUNC (on_mainwin_openfilelist_cancel_button_clicked),
					  mwin);
}






void
on_mainwinmenu_exit_activate           (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	gtk_exit(0);
}


void
on_mainwinmenu_cut_activate            (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	on_mainwinmenu_copy_activate (menuitem, mwin);
	app_delete_selected_items(mwin, GTK_CLIST(mwin-&gt;cliplist), (gpointer*) menuitem);
}


void
on_mainwinmenu_copy_activate           (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	/* Function one : copypasteing in GCM */
	GList *selected;
	selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;
	mwin-&gt;copypaste = NULL;
	if (selected) {
		while (selected) {
			Selection *nitem, *mitem;
			nitem=(Selection*) g_malloc0(sizeof(Selection));
			mitem = gtk_clist_get_row_data(GTK_CLIST(mwin-&gt;cliplist),(gint) selected-&gt;data);
			nitem-&gt;time = g_strdup(mitem-&gt;time);
			nitem-&gt;type = g_strdup(mitem-&gt;type);
			nitem-&gt;from = g_strdup(mitem-&gt;from);
			nitem-&gt;data = g_strdup(mitem-&gt;data);
			nitem-&gt;row = mitem-&gt;row;
			mwin-&gt;copypaste = g_list_append(mwin-&gt;copypaste, nitem);
			selected = g_list_next(selected);
		}
	}
	/* Function two : refresh the selectionownership */
	if (mwin-&gt;prefs-&gt;multisel)
		app_claim_multi_selection (mwin);
	else {
		Selection *item;
		GList *selected;

		selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;   
		if (selected) {
			item = gtk_clist_get_row_data(GTK_CLIST(mwin-&gt;cliplist),(gint) selected-&gt;data);
		} else {
			gnome_error_dialog(&quot;No item selected&quot;);
			return;
		}
		app_claim_text_selection(mwin, item);
	}
}


void
on_mainwinmenu_paste_activate          (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *selected = g_list_copy(mwin-&gt;copypaste);

	if (selected) {
		while (selected) {
			Selection *nitem, *item;
			nitem=(Selection*) g_malloc0(sizeof(Selection));
			item = (Selection*) selected-&gt;data;
			nitem-&gt;time = g_strdup(item-&gt;time);
			nitem-&gt;type = g_strdup(item-&gt;type);
			nitem-&gt;from = g_strdup(item-&gt;from);
			nitem-&gt;data = g_strdup(item-&gt;data);
			nitem-&gt;row = item-&gt;row;
			app_add_selection(mwin, nitem);
			selected = g_list_next(selected);
		}
	}
}


void
on_mainwinmenu_clear_activate          (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	gtk_clist_clear (GTK_CLIST(mwin-&gt;cliplist));
}



void
on_mainwinmenu_selectall_activate     (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	gtk_clist_select_all (GTK_CLIST(mwin-&gt;cliplist));
}

void
on_mainwinmenu_selectnone_activate     (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	gtk_clist_unselect_all (GTK_CLIST(mwin-&gt;cliplist));
}

void
on_mainwinmenu_preferences_activate    (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	app_show_prefswin (mwin, (gpointer*) menuitem);
}


void
on_mainwinmenu_about_activate          (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	app_create_and_show_aboutwin (mwin, (gpointer*) menuitem);
}

void
on_cliplistpopupmenu_new_activate      (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	app_create_and_show_newitemwin (mwin, (gpointer*) menuitem);
}


void
on_cliplistpopupmenu_cut_activate      (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	on_mainwinmenu_cut_activate (NULL, mwin);
}

void
on_cliplistpopupmenu_copy_activate     (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	on_mainwinmenu_copy_activate (NULL, mwin);
}

void
on_cliplistpopupmenu_paste_activate    (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	on_mainwinmenu_paste_activate (NULL, mwin);
}

void
on_cliplistpopupmenu_edit_activate     (GtkMenuItem     *menuitem,
                                        MainWin         *mwin)
{
	GList *selected;
	gint row;

	selected = GTK_CLIST(mwin-&gt;cliplist)-&gt;selection;
	if (selected) {
		selected = g_list_first (selected);
		if (selected == NULL) {
			gnome_error_dialog(_(&quot;No item selected&quot;));
			return;
		}
	row = (gint) selected-&gt;data;

	app_create_and_show_textitemwin (mwin, row);
	} else gnome_error_dialog(_(&quot;No item selected&quot;));
}


void
on_toolbar_newitem_clicked             (GtkButton       *button,
                                        MainWin         *mwin)
{
	app_create_and_show_newitemwin (mwin, (gpointer*) button);
}


void
on_toolbar_clear_clicked              (GtkButton       *button,
                                        MainWin         *mwin)
{
	on_mainwinmenu_clear_activate(NULL, mwin);
}

void
on_toolbar_deleteitem_clicked          (GtkButton       *button,
                                        MainWin         *mwin)
{
	app_delete_selected_items(mwin, GTK_CLIST(mwin-&gt;cliplist), (gpointer*) button);
}

void
on_toolbar_edititem_clicked            (GtkButton       *button,
                                        MainWin         *mwin)
{
	on_cliplistpopupmenu_edit_activate (NULL, mwin);
}


void
on_toolbar_preferences_clicked         (GtkButton       *button,
                                        MainWin         *mwin)
{
	app_show_prefswin (mwin, (gpointer*) button);
}


void
on_toolbar_refresh_clicked             (GtkButton       *button,
                                        MainWin         *mwin)
{
	app_get_new_item (mwin, (gpointer*) button);
}


void
on_toolbar_quit_clicked                (GtkButton       *button,
                                        MainWin         *mwin)
{
	gtk_exit(0);
}


void
on_cliplist_click_column               (GtkCList        *clist,
                                        gint             column,
                                        MainWin         *mwin)

{

}


void
on_cliplist_select_row                 (GtkCList        *clist,
                                        gint             row,
                                        gint             column,
                                        GdkEvent        *event,
                                        MainWin         *mwin)

{
	
		Selection *item;
		app_update_menus(mwin);
		item = gtk_clist_get_row_data (clist, row);
		if (!strcmp(item-&gt;type, &quot;text&quot;)) {
			if ((event)&(event->button.type == GDK_2BUTTON_PRESS)) {
				app_create_and_show_textitemwin (mwin, row);
				return;
			} else {
				if (mwin-&gt;prefs-&gt;multisel) {
					app_claim_multi_selection (mwin);
				} else {
					app_claim_text_selection (mwin, item);					
				}
				return;
			}
		}
		
	
	
}


void
on_cliplist_unselect_row               (GtkCList        *clist,
                                        gint             row,
                                        gint             column,
                                        GdkEvent        *event,
                                        MainWin         *mwin)
{
	app_update_menus(mwin);
	if (mwin-&gt;prefs-&gt;multisel) {
		app_claim_multi_selection (mwin);
	}

}

int
on_cliplist_event                      (GtkCList        *clist,
                                        GdkEvent        *event,
                                        MainWin         *mwin)
{
	GdkEventButton *button_event = (GdkEventButton *) event;
	app_update_menus(mwin);
	if (event-&gt;type == GDK_BUTTON_PRESS & button_event->button == 3) {
		gtk_menu_popup (GTK_MENU(mwin->cliplistpopupmenu), NULL, NULL, NULL, NULL, 3, 
						button_event->time);
		return TRUE;
	}
	return FALSE;
}
</data>
  </item>
</gcm>

