<commit_before>/* $Id$ */
/* Copyright (c) 2012-2015 <NAME> <<EMAIL>> */
/* This file is part of DeforaOS Desktop Browser */
/* 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, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
/* TODO:
 * - parse git's meta-data */



#include <System.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <errno.h>
#define COMMON_PROMPT
#include "common.c"


/* Git */
/* private */
/* types */
typedef struct _CommonTask GitTask;

typedef struct _BrowserPlugin
{
	BrowserPluginHelper * helper;

	char * filename;

	guint source;

	/* widgets */
	GtkWidget * widget;
	GtkWidget * name;
	GtkWidget * status;
	/* init */
	GtkWidget * init;
	/* directory */
	GtkWidget * directory;
	/* file */
	GtkWidget * file;
	/* additional actions */
	GtkWidget * add;

	/* tasks */
	GitTask ** tasks;
	size_t tasks_cnt;
} Git;


/* prototypes */
static Git * _git_init(BrowserPluginHelper * helper);
static void _git_destroy(Git * git);
static GtkWidget * _git_get_widget(Git * git);
static void _git_refresh(Git * git, GList * selection);

/* accessors */
static gboolean _git_is_managed(char const * filename);

/* useful */
static int _git_add_task(Git * git, char const * title,
		char const * directory, char * argv[],
		CommonTaskCallback callback);

/* callbacks */
static void _git_on_add(gpointer data);
static void _git_on_blame(gpointer data);
static void _git_on_clone(gpointer data);
static void _git_on_commit(gpointer data);
static void _git_on_diff(gpointer data);
static void _git_on_init(gpointer data);
static void _git_on_log(gpointer data);
static void _git_on_pull(gpointer data);
static void _git_on_push(gpointer data);
static void _git_on_status(gpointer data);


/* public */
/* variables */
/* plug-in */
BrowserPluginDefinition plugin =
{
	N_("Git"),
	"applications-development",
	NULL,
	_git_init,
	_git_destroy,
	_git_get_widget,
	_git_refresh
};


/* private */
/* functions */
/* git_init */
static GtkWidget * _init_button(GtkSizeGroup * group, char const * icon,
		char const * label, GCallback callback, gpointer data);

static Git * _git_init(BrowserPluginHelper * helper)
{
	Git * git;
	PangoFontDescription * font;
	GtkSizeGroup * group;
	GtkWidget * widget;

	if((git = object_new(sizeof(*git))) == NULL)
		return NULL;
	git->helper = helper;
	git->filename = NULL;
	git->source = 0;
	/* widgets */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->widget = gtk_vbox_new(FALSE, 4);
#endif
	font = pango_font_description_new();
	pango_font_description_set_weight(font, PANGO_WEIGHT_BOLD);
	group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	/* label */
	git->name = gtk_label_new("");
	gtk_label_set_ellipsize(GTK_LABEL(git->name), PANGO_ELLIPSIZE_MIDDLE);
	gtk_misc_set_alignment(GTK_MISC(git->name), 0.0, 0.0);
	gtk_widget_modify_font(git->name, font);
	gtk_box_pack_start(GTK_BOX(git->widget), git->name, FALSE, TRUE, 0);
	git->status = gtk_label_new("");
	gtk_label_set_ellipsize(GTK_LABEL(git->status), PANGO_ELLIPSIZE_END);
	gtk_misc_set_alignment(GTK_MISC(git->status), 0.0, 0.0);
	gtk_box_pack_start(GTK_BOX(git->widget), git->status, FALSE, TRUE, 0);
	/* init */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->init = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->init = gtk_vbox_new(FALSE, 4);
#endif
	widget = _init_button(group, GTK_STOCK_OK, _("Initialize"), G_CALLBACK(
				_git_on_init), git);
	gtk_box_pack_start(GTK_BOX(git->init), widget, FALSE, TRUE, 0);
	widget = _init_button(group, GTK_STOCK_OK, _("Clone..."), G_CALLBACK(
				_git_on_clone), git);
	gtk_box_pack_start(GTK_BOX(git->init), widget, FALSE, TRUE, 0);
	gtk_widget_show_all(git->init);
	gtk_widget_set_no_show_all(git->init, TRUE);
	gtk_box_pack_start(GTK_BOX(git->widget), git->init, FALSE, TRUE, 0);
	/* directory */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->directory = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->directory = gtk_vbox_new(FALSE, 4);
#endif
	widget = _init_button(group, GTK_STOCK_FIND_AND_REPLACE,<commit_msg>Update the stock icon for cloning<commit_after>/* $Id$ */
/* Copyright (c) 2012-2015 <NAME> <<EMAIL>> */
/* This file is part of DeforaOS Desktop Browser */
/* 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, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
/* TODO:
 * - parse git's meta-data */



#include <System.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <errno.h>
#define COMMON_PROMPT
#include "common.c"


/* Git */
/* private */
/* types */
typedef struct _CommonTask GitTask;

typedef struct _BrowserPlugin
{
	BrowserPluginHelper * helper;

	char * filename;

	guint source;

	/* widgets */
	GtkWidget * widget;
	GtkWidget * name;
	GtkWidget * status;
	/* init */
	GtkWidget * init;
	/* directory */
	GtkWidget * directory;
	/* file */
	GtkWidget * file;
	/* additional actions */
	GtkWidget * add;

	/* tasks */
	GitTask ** tasks;
	size_t tasks_cnt;
} Git;


/* prototypes */
static Git * _git_init(BrowserPluginHelper * helper);
static void _git_destroy(Git * git);
static GtkWidget * _git_get_widget(Git * git);
static void _git_refresh(Git * git, GList * selection);

/* accessors */
static gboolean _git_is_managed(char const * filename);

/* useful */
static int _git_add_task(Git * git, char const * title,
		char const * directory, char * argv[],
		CommonTaskCallback callback);

/* callbacks */
static void _git_on_add(gpointer data);
static void _git_on_blame(gpointer data);
static void _git_on_clone(gpointer data);
static void _git_on_commit(gpointer data);
static void _git_on_diff(gpointer data);
static void _git_on_init(gpointer data);
static void _git_on_log(gpointer data);
static void _git_on_pull(gpointer data);
static void _git_on_push(gpointer data);
static void _git_on_status(gpointer data);


/* public */
/* variables */
/* plug-in */
BrowserPluginDefinition plugin =
{
	N_("Git"),
	"applications-development",
	NULL,
	_git_init,
	_git_destroy,
	_git_get_widget,
	_git_refresh
};


/* private */
/* functions */
/* git_init */
static GtkWidget * _init_button(GtkSizeGroup * group, char const * icon,
		char const * label, GCallback callback, gpointer data);

static Git * _git_init(BrowserPluginHelper * helper)
{
	Git * git;
	PangoFontDescription * font;
	GtkSizeGroup * group;
	GtkWidget * widget;

	if((git = object_new(sizeof(*git))) == NULL)
		return NULL;
	git->helper = helper;
	git->filename = NULL;
	git->source = 0;
	/* widgets */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->widget = gtk_vbox_new(FALSE, 4);
#endif
	font = pango_font_description_new();
	pango_font_description_set_weight(font, PANGO_WEIGHT_BOLD);
	group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	/* label */
	git->name = gtk_label_new("");
	gtk_label_set_ellipsize(GTK_LABEL(git->name), PANGO_ELLIPSIZE_MIDDLE);
	gtk_misc_set_alignment(GTK_MISC(git->name), 0.0, 0.0);
	gtk_widget_modify_font(git->name, font);
	gtk_box_pack_start(GTK_BOX(git->widget), git->name, FALSE, TRUE, 0);
	git->status = gtk_label_new("");
	gtk_label_set_ellipsize(GTK_LABEL(git->status), PANGO_ELLIPSIZE_END);
	gtk_misc_set_alignment(GTK_MISC(git->status), 0.0, 0.0);
	gtk_box_pack_start(GTK_BOX(git->widget), git->status, FALSE, TRUE, 0);
	/* init */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->init = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->init = gtk_vbox_new(FALSE, 4);
#endif
	widget = _init_button(group, GTK_STOCK_OK, _("Initialize"), G_CALLBACK(
				_git_on_init), git);
	gtk_box_pack_start(GTK_BOX(git->init), widget, FALSE, TRUE, 0);
	widget = _init_button(group, GTK_STOCK_SAVE_AS, _("Clone..."),
			G_CALLBACK(_git_on_clone), git);
	gtk_box_pack_start(GTK_BOX(git->init), widget, FALSE, TRUE, 0);
	gtk_widget_show_all(git->init);
	gtk_widget_set_no_show_all(git->init, TRUE);
	gtk_box_pack_start(GTK_BOX(git->widget), git->init, FALSE, TRUE, 0);
	/* directory */
#if GTK_CHECK_VERSION(3, 0, 0)
	git->directory = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
#else
	git->directory = gtk_vbox_new(FALSE, 4);
#endif
	widget = _init_button(group, GTK_STOCK_FIND_AND_REPLACE,
{'fraction_non_alphanumeric': 0.13023154690727254, 'fraction_numerical': 0.008261767583432982, 'mean_word_length': 5.028833551769331, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '870932', 'n_tokens_mistral': 3494, 'n_tokens_neox': 3329, 'n_words': 823}