<commit_before>/*
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 *
 *
 * The Totem project hereby grant permission for non-gpl compatible GStreamer
 * plugins to be used and distributed together with GStreamer and Totem. This
 * permission are above and beyond the permissions granted by the GPL license
 * Totem is covered by.
 */

#include "config.h"

#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
#include <gmodule.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include <gdk/gdkkeysyms.h>
#include <unistd.h>
#include <math.h>

#include "bacon-video-widget.h"
#include "totem-plugin.h"
#include "totem-dirs.h"
#include "totem-interface.h"
#include "totem.h"
#include "totem-cmml-parser.h"
#include "totem-chapters-utils.h"
#include "totem-edit-chapter.h"

#define TOTEM_TYPE_CHAPTERS_PLUGIN		(totem_chapters_plugin_get_type ())
#define TOTEM_CHAPTERS_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPlugin))
#define TOTEM_CHAPTERS_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginClass))
#define TOTEM_IS_CHAPTERS_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_CHAPTERS_PLUGIN))
#define TOTEM_IS_CHAPTERS_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_CHAPTERS_PLUGIN))
#define TOTEM_CHAPTERS_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginClass))

#define TOTEM_CHAPTERS_PLUGIN_GET_PRIVATE(obj)	(G_TYPE_INSTANCE_GET_PRIVATE ((obj), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginPrivate))

#define CHAPTER_TOOLTIP(title, start) g_strdup_printf	( _("<b>Title: </b>%s\n<b>Start time: </b>%s"),	\
							 ( title ), ( start ) )

#define CHAPTER_TITLE(title, start) g_strdup_printf	("<big>%s</big>\n"				\
							 "<small><span foreground='grey'>%s"		\
							 "</span></small>",				\
							 ( title ), ( start ) )
#define ICON_SCALE_RATIO 2

typedef struct {
	GtkWidget	*tree;
	GtkWidget	*add_button,
			*remove_button,
			*save_button,
			*load_button,
			*goto_button,
			*continue_button,
			*list_box,
			*load_box;
	GtkActionGroup	*action_group;
	GtkUIManager	*ui_manager;
	gboolean	was_played;
	GdkPixbuf	*last_frame;
	gint64		last_time;
	gchar		*cmml_mrl;
	gboolean	autoload;
	GCancellable	*cancellable[2];
	GSettings	*settings;
	guint		autoload_handle_id;
} TotemChaptersPluginPrivate;

typedef struct {
	PeasExtensionBase		parent;
	TotemObject			*totem;
	TotemEditChapter		*edit_chapter;
	TotemChaptersPluginPrivate	*priv;
} TotemChaptersPlugin;

typedef struct {
	PeasExtensionBaseClass		parent_class;
} TotemChaptersPluginClass;

enum {
	CHAPTERS_PIXBUF_COLUMN = 0,
	CHAPTERS_TITLE_COLUMN,
	CHAPTERS_TOOLTIP_COLUMN,
	CHAPTERS_TITLE_PRIV_COLUMN,
	CHAPTERS_TIME_PRIV_COLUMN,
	CHAPTERS_N_COLUMNS
};

G_MODULE_EXPORT GType register_totem_plugin (GTypeModule *module);
GType totem_chapters_plugin_get_type (void) G_GNUC_CONST;
static void totem_chapters_plugin_finalize (GObject *object);
static void totem_file_opened_async_cb (TotemObject *totem, const gchar *uri, TotemChaptersPlugin *plugin);
static void totem_file_opened_result_cb (gpointer data, gpointer user_data);
static void totem_file_closed_cb (TotemObject *totem, TotemChaptersPlugin *plugin);
static void add_chapter_to_the_list (gpointer data, gpointer user_data);
static void add_chapter_to_the_list_new (TotemChaptersPlugin *plugin, const gchar *title, gint64 time);
static gboolean check_available_time (TotemChaptersPlugin *plugin, gint64 time);
static GdkPixbuf * get_chapter_pixbuf (GdkPixbuf *src);
static void chapter_edit_dialog_response_cb (GtkDialog *dialog, gint response, TotemChaptersPlugin *plugin);
static void prepare_chapter_edit (GtkCellRenderer *renderer, GtkCellEditable *editable, gchar *path, gpointer user_data);
static void finish_chapter_edit (GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data);
static void chapter_selection_changed_cb (GtkTreeSelection *tree_selection, TotemChaptersPlugin *plugin);
static void show_chapter_edit_dialog (TotemChaptersPlugin *plugin);
static void save_chapters_result_cb (gpointer data, gpointer user_data);
static GList * get_chapters_list (TotemChaptersPlugin *plugin);
static gboolean show_popup_menu (TotemChaptersPlugin *plugin, GdkEventButton *event);
static void autoload_changed_cb (GSettings *settigs, const gchar *key, TotemChaptersPlugin *plugin);
static void load_chapters_from_file (const gchar *uri, gboolean from_dialog, TotemChaptersPlugin *plugin);
static void set_no_data_visible (gboolean visible, gboolean show_buttons, TotemChaptersPlugin *plugin);

/* GtkBuilder callbacks */
void add_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void remove_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void save_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void goto_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void tree_view_row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, TotemChaptersPlugin *plugin);
gboolean tree_view_button_press_cb (GtkTreeView *tree_view, GdkEventButton *event, TotemChaptersPlugin *plugin);
gboolean tree_view_key_press_cb (GtkTreeView *tree_view, GdkEventKey *event, TotemChaptersPlugin *plugin);
gboolean tree_view_popup_menu_cb (GtkTreeView *tree_view, TotemChaptersPlugin *plugin);
void popup_remove_action_cb (GtkAction *action, TotemChaptersPlugin *plugin);
void popup_goto_action_cb (GtkAction *action, TotemChaptersPlugin *plugin);
void load_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void continue_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);

TOTEM_PLUGIN_REGISTER (TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPlugin, totem_chapters_plugin)

static void
totem_chapters_plugin_class_init (TotemChaptersPluginClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	g_type_class_add_private (klass, sizeof (TotemChaptersPluginPrivate));

	object_class->set_property = set_property;
	object_class->get_property = get_property;
	object_class->finalize = totem_chapters_plugin_finalize;

	g_object_class_override_property (object_class, PROP_OBJECT, "object");
}

static void
totem_chapters_plugin_init (TotemChaptersPlugin *plugin)
{
	plugin->priv = TOTEM_CHAPTERS_PLUGIN_GET_PRIVATE (plugin);
}

static void
totem_chapters_plugin_finalize (GObject *object)
{
	G_OBJECT_CLASS (totem_chapters_plugin_parent_class)->finalize (object);
}
<commit_msg>Remove a redundant finalize method from the chapters plugin<commit_after>/*
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 *
 *
 * The Totem project hereby grant permission for non-gpl compatible GStreamer
 * plugins to be used and distributed together with GStreamer and Totem. This
 * permission are above and beyond the permissions granted by the GPL license
 * Totem is covered by.
 */

#include "config.h"

#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <glib/gprintf.h>
#include <gio/gio.h>
#include <gmodule.h>
#include <gdk-pixbuf/gdk-pixdata.h>
#include <gdk/gdkkeysyms.h>
#include <unistd.h>
#include <math.h>

#include "bacon-video-widget.h"
#include "totem-plugin.h"
#include "totem-dirs.h"
#include "totem-interface.h"
#include "totem.h"
#include "totem-cmml-parser.h"
#include "totem-chapters-utils.h"
#include "totem-edit-chapter.h"

#define TOTEM_TYPE_CHAPTERS_PLUGIN		(totem_chapters_plugin_get_type ())
#define TOTEM_CHAPTERS_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPlugin))
#define TOTEM_CHAPTERS_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginClass))
#define TOTEM_IS_CHAPTERS_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_CHAPTERS_PLUGIN))
#define TOTEM_IS_CHAPTERS_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_CHAPTERS_PLUGIN))
#define TOTEM_CHAPTERS_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginClass))

#define TOTEM_CHAPTERS_PLUGIN_GET_PRIVATE(obj)	(G_TYPE_INSTANCE_GET_PRIVATE ((obj), TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPluginPrivate))

#define CHAPTER_TOOLTIP(title, start) g_strdup_printf	( _("<b>Title: </b>%s\n<b>Start time: </b>%s"),	\
							 ( title ), ( start ) )

#define CHAPTER_TITLE(title, start) g_strdup_printf	("<big>%s</big>\n"				\
							 "<small><span foreground='grey'>%s"		\
							 "</span></small>",				\
							 ( title ), ( start ) )
#define ICON_SCALE_RATIO 2

typedef struct {
	GtkWidget	*tree;
	GtkWidget	*add_button,
			*remove_button,
			*save_button,
			*load_button,
			*goto_button,
			*continue_button,
			*list_box,
			*load_box;
	GtkActionGroup	*action_group;
	GtkUIManager	*ui_manager;
	gboolean	was_played;
	GdkPixbuf	*last_frame;
	gint64		last_time;
	gchar		*cmml_mrl;
	gboolean	autoload;
	GCancellable	*cancellable[2];
	GSettings	*settings;
	guint		autoload_handle_id;
} TotemChaptersPluginPrivate;

typedef struct {
	PeasExtensionBase		parent;
	TotemObject			*totem;
	TotemEditChapter		*edit_chapter;
	TotemChaptersPluginPrivate	*priv;
} TotemChaptersPlugin;

typedef struct {
	PeasExtensionBaseClass		parent_class;
} TotemChaptersPluginClass;

enum {
	CHAPTERS_PIXBUF_COLUMN = 0,
	CHAPTERS_TITLE_COLUMN,
	CHAPTERS_TOOLTIP_COLUMN,
	CHAPTERS_TITLE_PRIV_COLUMN,
	CHAPTERS_TIME_PRIV_COLUMN,
	CHAPTERS_N_COLUMNS
};

G_MODULE_EXPORT GType register_totem_plugin (GTypeModule *module);
GType totem_chapters_plugin_get_type (void) G_GNUC_CONST;
static void totem_file_opened_async_cb (TotemObject *totem, const gchar *uri, TotemChaptersPlugin *plugin);
static void totem_file_opened_result_cb (gpointer data, gpointer user_data);
static void totem_file_closed_cb (TotemObject *totem, TotemChaptersPlugin *plugin);
static void add_chapter_to_the_list (gpointer data, gpointer user_data);
static void add_chapter_to_the_list_new (TotemChaptersPlugin *plugin, const gchar *title, gint64 time);
static gboolean check_available_time (TotemChaptersPlugin *plugin, gint64 time);
static GdkPixbuf * get_chapter_pixbuf (GdkPixbuf *src);
static void chapter_edit_dialog_response_cb (GtkDialog *dialog, gint response, TotemChaptersPlugin *plugin);
static void prepare_chapter_edit (GtkCellRenderer *renderer, GtkCellEditable *editable, gchar *path, gpointer user_data);
static void finish_chapter_edit (GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data);
static void chapter_selection_changed_cb (GtkTreeSelection *tree_selection, TotemChaptersPlugin *plugin);
static void show_chapter_edit_dialog (TotemChaptersPlugin *plugin);
static void save_chapters_result_cb (gpointer data, gpointer user_data);
static GList * get_chapters_list (TotemChaptersPlugin *plugin);
static gboolean show_popup_menu (TotemChaptersPlugin *plugin, GdkEventButton *event);
static void autoload_changed_cb (GSettings *settigs, const gchar *key, TotemChaptersPlugin *plugin);
static void load_chapters_from_file (const gchar *uri, gboolean from_dialog, TotemChaptersPlugin *plugin);
static void set_no_data_visible (gboolean visible, gboolean show_buttons, TotemChaptersPlugin *plugin);

/* GtkBuilder callbacks */
void add_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void remove_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void save_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void goto_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void tree_view_row_activated_cb (GtkTreeView *tree_view, GtkTreePath *path, GtkTreeViewColumn *column, TotemChaptersPlugin *plugin);
gboolean tree_view_button_press_cb (GtkTreeView *tree_view, GdkEventButton *event, TotemChaptersPlugin *plugin);
gboolean tree_view_key_press_cb (GtkTreeView *tree_view, GdkEventKey *event, TotemChaptersPlugin *plugin);
gboolean tree_view_popup_menu_cb (GtkTreeView *tree_view, TotemChaptersPlugin *plugin);
void popup_remove_action_cb (GtkAction *action, TotemChaptersPlugin *plugin);
void popup_goto_action_cb (GtkAction *action, TotemChaptersPlugin *plugin);
void load_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);
void continue_button_clicked_cb (GtkButton *button, TotemChaptersPlugin *plugin);

TOTEM_PLUGIN_REGISTER (TOTEM_TYPE_CHAPTERS_PLUGIN, TotemChaptersPlugin, totem_chapters_plugin)

static void
totem_chapters_plugin_class_init (TotemChaptersPluginClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

	g_type_class_add_private (klass, sizeof (TotemChaptersPluginPrivate));

	object_class->set_property = set_property;
	object_class->get_property = get_property;

	g_object_class_override_property (object_class, PROP_OBJECT, "object");
}

static void
totem_chapters_plugin_init (TotemChaptersPlugin *plugin)
{
	plugin->priv = TOTEM_CHAPTERS_PLUGIN_GET_PRIVATE (plugin);
}

{'fraction_non_alphanumeric': 0.0863018473335657, 'fraction_numerical': 0.0037643778319972118, 'mean_word_length': 7.2829099307159355, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1442085', 'n_tokens_mistral': 5293, 'n_tokens_neox': 4978, 'n_words': 1183}