From 790cf176e441d2ad262b5c89a04b4f73a16a8e79 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 6 Jan 2014 18:42:27 -0600 Subject: [PATCH] Imported a new plug-in "selection" --- Makefile | 1 + src/plugins/Makefile | 14 ++++- src/plugins/project.conf | 9 ++- src/plugins/selection.c | 130 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 src/plugins/selection.c diff --git a/Makefile b/Makefile index 5d68a65..80f90b6 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,7 @@ dist: $(PACKAGE)-$(VERSION)/src/plugins/make.c \ $(PACKAGE)-$(VERSION)/src/plugins/preview.c \ $(PACKAGE)-$(VERSION)/src/plugins/properties.c \ + $(PACKAGE)-$(VERSION)/src/plugins/selection.c \ $(PACKAGE)-$(VERSION)/src/plugins/subversion.c \ $(PACKAGE)-$(VERSION)/src/plugins/template.c \ $(PACKAGE)-$(VERSION)/src/plugins/volumes.c \ diff --git a/src/plugins/Makefile b/src/plugins/Makefile index 24525ef..988a662 100644 --- a/src/plugins/Makefile +++ b/src/plugins/Makefile @@ -1,4 +1,4 @@ -TARGETS = cvs.so dirtree.so favorites.so git.so make.so preview.so properties.so subversion.so template.so volumes.so +TARGETS = cvs.so dirtree.so favorites.so git.so make.so preview.so properties.so selection.so subversion.so template.so volumes.so PREFIX = /usr/local DESTDIR = LIBDIR = $(PREFIX)/lib @@ -68,6 +68,13 @@ properties_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) properties.so: $(properties_OBJS) $(CCSHARED) -o properties.so $(properties_OBJS) $(properties_LDFLAGS) +selection_OBJS = selection.o +selection_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) +selection_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) + +selection.so: $(selection_OBJS) + $(CCSHARED) -o selection.so $(selection_OBJS) $(selection_LDFLAGS) + subversion_OBJS = subversion.o subversion_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) subversion_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) @@ -110,6 +117,9 @@ preview.o: preview.c ../../include/Browser.h properties.o: properties.c ../../include/Browser.h $(CC) $(properties_CFLAGS) -c properties.c +selection.o: selection.c ../../include/Browser.h + $(CC) $(selection_CFLAGS) -c selection.c + subversion.o: subversion.c common.c ../../include/Browser.h $(CC) $(subversion_CFLAGS) -c subversion.c @@ -120,7 +130,7 @@ volumes.o: volumes.c ../../include/Browser.h $(CC) $(volumes_CFLAGS) -c volumes.c clean: - $(RM) -- $(cvs_OBJS) $(dirtree_OBJS) $(favorites_OBJS) $(git_OBJS) $(make_OBJS) $(preview_OBJS) $(properties_OBJS) $(subversion_OBJS) $(template_OBJS) $(volumes_OBJS) + $(RM) -- $(cvs_OBJS) $(dirtree_OBJS) $(favorites_OBJS) $(git_OBJS) $(make_OBJS) $(preview_OBJS) $(properties_OBJS) $(selection_OBJS) $(subversion_OBJS) $(template_OBJS) $(volumes_OBJS) distclean: clean $(RM) -- $(TARGETS) diff --git a/src/plugins/project.conf b/src/plugins/project.conf index 3aaadb2..def0963 100644 --- a/src/plugins/project.conf +++ b/src/plugins/project.conf @@ -1,4 +1,4 @@ -targets=cvs,dirtree,favorites,git,make,preview,properties,subversion,template,volumes +targets=cvs,dirtree,favorites,git,make,preview,properties,selection,subversion,template,volumes cppflags_force=-I ../../include cppflags= cflags_force=-W `pkg-config --cflags libDesktop` @@ -62,6 +62,13 @@ install=$(LIBDIR)/Browser/plugins [properties.c] depends=../../include/Browser.h +[selection] +type=plugin +sources=selection.c + +[selection.c] +depends=../../include/Browser.h + [subversion] type=plugin sources=subversion.c diff --git a/src/plugins/selection.c b/src/plugins/selection.c new file mode 100644 index 0000000..f501dcb --- /dev/null +++ b/src/plugins/selection.c @@ -0,0 +1,130 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* 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 . */ +/* FIXME: + * - count the files and directories selected + * - count the total size */ + + + +#include +#include +#include "Browser.h" +#define _(string) gettext(string) +#define N_(string) (string) + + +/* Selection */ +/* private */ +/* types */ +typedef struct _BrowserPlugin +{ + BrowserPluginHelper * helper; + + GtkWidget * widget; + GtkWidget * view; + GtkListStore * store; +} Selection; + + +/* prototypes */ +static Selection * _selection_init(BrowserPluginHelper * helper); +static void _selection_destroy(Selection * selection); +static GtkWidget * _selection_get_widget(Selection * selection); +static void _selection_refresh(Selection * selection, GList * selected); + + +/* public */ +/* variables */ +BrowserPluginDefinition plugin = +{ + N_("Selection"), + "stock_select-all", + NULL, + _selection_init, + _selection_destroy, + _selection_get_widget, + _selection_refresh +}; + + +/* private */ +/* functions */ +/* selection_init */ +static Selection * _selection_init(BrowserPluginHelper * helper) +{ + Selection * selection; + GtkWidget * widget; + GtkCellRenderer * renderer; + GtkTreeViewColumn * column; + + if((selection = object_new(sizeof(*selection))) == NULL) + return NULL; + selection->helper = helper; +#if GTK_CHECK_VERSION(3, 0, 0) + selection->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); +#else + selection->widget = gtk_vbox_new(FALSE, 0); +#endif + widget = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + selection->store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); + selection->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL( + selection->store)); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(selection->view), + FALSE); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(_("Filename"), + renderer, "text", 1, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(selection->view), column); + gtk_container_add(GTK_CONTAINER(widget), selection->view); + gtk_box_pack_start(GTK_BOX(selection->widget), widget, TRUE, TRUE, 0); + gtk_widget_show_all(selection->widget); + return selection; +} + + +/* selection_destroy */ +static void _selection_destroy(Selection * selection) +{ + /* FIXME implement */ + object_delete(selection); +} + + +/* selection_get_widget */ +static GtkWidget * _selection_get_widget(Selection * selection) +{ + return selection->widget; +} + + +/* selection_refresh */ +static void _selection_refresh(Selection * selection, GList * selected) +{ + GList * l; + gchar * basename; + GtkTreeIter iter; + + gtk_list_store_clear(selection->store); + for(l = selected; l != NULL; l = l->next) + { + basename = g_path_get_basename(l->data); + gtk_list_store_append(selection->store, &iter); + gtk_list_store_set(selection->store, &iter, 0, l->data, + 1, basename, -1); + g_free(basename); + } +}