<commit_before>/*
 *      This file is part of GPaste.
 *
 *      Copyright 2011-2012 <NAME> <<EMAIL>>
 *
 *      GPaste 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 3 of the License, or
 *      (at your option) any later version.
 *
 *      GPaste 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 GPaste.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "gpaste-history-private.h"

#include <glib/gi18n-lib.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlwriter.h>

#define G_PASTE_HISTORY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_PASTE_TYPE_HISTORY, GPasteHistoryPrivate))

G_DEFINE_TYPE (GPasteHistory, g_paste_history, G_TYPE_OBJECT)

struct _GPasteHistoryPrivate
{
    GPasteSettings *settings;
    GSList         *history;
};

enum
{
    CHANGED,
    SELECTED,

    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

enum
{
    C_CHANGED,
    C_LAST_SIGNAL
};

static gulong c_signals[C_LAST_SIGNAL] = { 0 };

static GSList *
_g_paste_history_remove (GPasteHistory *self,
                         GSList        *elem,
                         gboolean       remove_leftovers)
{
    GPasteItem *item = elem->data;

    if (remove_leftovers && G_PASTE_IS_IMAGE_ITEM (item))
    {
        GFile *image = g_file_new_for_path (g_paste_item_get_value (item));
        g_file_delete (image,
                       NULL, /* cancellable */
                       NULL); /* error */
        g_object_unref (image);
    }

    g_object_unref (item);
    return g_slist_delete_link (self->priv->history,
                                elem);
}

/**
 * g_paste_history_add:
 * @self: a #GPasteHistory instance
 * @item: (transfer none): the #GPasteItem to add
 *
 * Add a #GPasteItem to the #GPasteHistory
 *
 * Returns:
 */
G_PASTE_VISIBLE void
g_paste_history_add (GPasteHistory *self,
                     GPasteItem    *item)
{
    g_return_if_fail (G_PASTE_IS_HISTORY (self));
    g_return_if_fail (G_PASTE_IS_ITEM (item));

    GPasteHistoryPrivate *priv = self->priv;
    GSList *history = priv->history;

    if (history)
    {
        if (g_paste_item_equals (history->data, item))
            return;
        for (history = g_slist_next (history); history; history = g_slist_next (history))
        {
            if (g_paste_item_equals (history->data, item))
            {
                priv->history = _g_paste_history_remove (self, history, FALSE);
                break;
            }
        }
    }
    gboolean fifo = g_paste_settings_get_fifo (priv->settings);
    history = priv->history = fifo ?
        g_slist_append (priv->history, g_object_ref (item)) :
        g_slist_prepend (priv->history, g_object_ref (item));
<commit_msg>libgpaste-core: One item only is active at a time<commit_after>/*
 *      This file is part of GPaste.
 *
 *      Copyright 2011-2012 <NAME> <<EMAIL>>
 *
 *      GPaste 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 3 of the License, or
 *      (at your option) any later version.
 *
 *      GPaste 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 GPaste.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "gpaste-history-private.h"

#include <glib/gi18n-lib.h>
#include <libxml/xmlreader.h>
#include <libxml/xmlwriter.h>

#define G_PASTE_HISTORY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_PASTE_TYPE_HISTORY, GPasteHistoryPrivate))

G_DEFINE_TYPE (GPasteHistory, g_paste_history, G_TYPE_OBJECT)

struct _GPasteHistoryPrivate
{
    GPasteSettings *settings;
    GSList         *history;
};

enum
{
    CHANGED,
    SELECTED,

    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

enum
{
    C_CHANGED,
    C_LAST_SIGNAL
};

static gulong c_signals[C_LAST_SIGNAL] = { 0 };

static GSList *
_g_paste_history_remove (GPasteHistory *self,
                         GSList        *elem,
                         gboolean       remove_leftovers)
{
    GPasteItem *item = elem->data;

    if (remove_leftovers && G_PASTE_IS_IMAGE_ITEM (item))
    {
        GFile *image = g_file_new_for_path (g_paste_item_get_value (item));
        g_file_delete (image,
                       NULL, /* cancellable */
                       NULL); /* error */
        g_object_unref (image);
    }

    g_object_unref (item);
    return g_slist_delete_link (self->priv->history,
                                elem);
}

/**
 * g_paste_history_add:
 * @self: a #GPasteHistory instance
 * @item: (transfer none): the #GPasteItem to add
 *
 * Add a #GPasteItem to the #GPasteHistory
 *
 * Returns:
 */
G_PASTE_VISIBLE void
g_paste_history_add (GPasteHistory *self,
                     GPasteItem    *item)
{
    g_return_if_fail (G_PASTE_IS_HISTORY (self));
    g_return_if_fail (G_PASTE_IS_ITEM (item));

    GPasteHistoryPrivate *priv = self->priv;
    GSList *history = priv->history;

    if (history)
    {
        if (g_paste_item_equals (history->data, item))
            return;
        for (history = g_slist_next (history); history; history = g_slist_next (history))
        {
            if (g_paste_item_equals (history->data, item))
            {
                priv->history = _g_paste_history_remove (self, history, FALSE);
                break;
            }
        }
    }
    gboolean fifo = g_paste_settings_get_fifo (priv->settings);
    history = priv->history = fifo ?
        g_slist_append (priv->history, g_object_ref (item)) :
        g_slist_prepend (priv->history, g_object_ref (item));

    GSList *next = history->next;

    if (next)
        g_paste_item_set_state (next->data, G_PASTE_ITEM_STATE_IDLE);
    g_paste_item_set_state (item, G_PASTE_ITEM_STATE_ACTIVE);

{'fraction_non_alphanumeric': 0.09430164137503871, 'fraction_numerical': 0.004026014245896562, 'mean_word_length': 2.552805280528053, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489048', 'n_tokens_mistral': 2165, 'n_tokens_neox': 2056, 'n_words': 537}