Updating branch refs/heads/thunarx-2 to 2cf5cf3a3bea075b4ff2db4218925874183d28e0 (commit) from 4ec787eadf9705d7b66af44f83aaf78df17f4383 (commit)
commit 2cf5cf3a3bea075b4ff2db4218925874183d28e0 Author: Peter de Ridder <pe...@xfce.org> Date: Fri Oct 23 15:26:33 2009 +0200 * tvp-git-helper/tgh-add.c tvp-git-helper/tgh-common.[ch] tvp-git-helper/tgh-notify-dialog.[ch]: Added notify dialog to make add more verbose. * tvp-git-helper/tgh-common.c tvp-git-helper/tgh-file-selection-dialog.c: Improved status output parsing. tvp-git-helper/Makefile.am | 2 + tvp-git-helper/tgh-add.c | 56 ++++-------- tvp-git-helper/tgh-common.c | 72 ++++++++++++-- tvp-git-helper/tgh-common.h | 2 + tvp-git-helper/tgh-file-selection-dialog.c | 26 +++--- .../{tgh-status-dialog.c => tgh-notify-dialog.c} | 102 +++++++------------- tvp-git-helper/tgh-notify-dialog.h | 50 ++++++++++ 7 files changed, 182 insertions(+), 128 deletions(-) diff --git a/tvp-git-helper/Makefile.am b/tvp-git-helper/Makefile.am index 96717b6..b3b56a9 100644 --- a/tvp-git-helper/Makefile.am +++ b/tvp-git-helper/Makefile.am @@ -36,6 +36,8 @@ tvp_git_helper_SOURCES = \ tgh-file-selection-dialog.c \ tgh-log-dialog.h \ tgh-log-dialog.c \ + tgh-notify-dialog.h \ + tgh-notify-dialog.c \ tgh-status-dialog.h \ tgh-status-dialog.c \ tgh-transfer-dialog.h \ diff --git a/tvp-git-helper/tgh-add.c b/tvp-git-helper/tgh-add.c index 4b57046..f55816d 100644 --- a/tvp-git-helper/tgh-add.c +++ b/tvp-git-helper/tgh-add.c @@ -38,57 +38,36 @@ #include "tgh-common.h" #include "tgh-dialog-common.h" #include "tgh-file-selection-dialog.h" +#include "tgh-notify-dialog.h" #include "tgh-add.h" -struct exit_args -{ - TghOutputParser *parser; - GtkWidget *dialog; -}; - -static void child_exit(GPid pid, gint status, gpointer user_data) -{ - struct exit_args *args = user_data; - - gtk_widget_destroy(args->dialog); - - if(WEXITSTATUS(status) <= 1) - { - GtkWidget *dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_OTHER, GTK_BUTTONS_CLOSE, _("Add finished")); - tgh_dialog_start(GTK_DIALOG(dialog), TRUE); - } - - tgh_child_exit(pid, status, args->parser); - - g_free(args); -} - static gboolean add_spawn (GtkWidget *dialog, gchar **files, GPid *pid) { GError *error = NULL; - gint fd_err; - GIOChannel *chan_err; + gint fd_out, fd_err; + GIOChannel *chan_out, *chan_err; TghOutputParser *parser; gsize length; gint i; gchar **argv; - struct exit_args *args = g_new(struct exit_args, 1); - length = 3; + length = 5; length += g_strv_length(files); argv = g_new(gchar*, length); argv[0] = "git"; argv[1] = "add"; + argv[2] = "-v"; + argv[3] = "--"; argv[length-1] = NULL; - i = 2; + i = 4; while(*files) argv[i++] = *files++; - if(!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, NULL, &fd_err, &error)) + if(!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH, NULL, NULL, pid, NULL, &fd_out, &fd_err, &error)) { g_free (argv); return FALSE; @@ -97,12 +76,11 @@ static gboolean add_spawn (GtkWidget *dialog, gchar **files, GPid *pid) parser = tgh_error_parser_new(GTK_WIDGET(dialog)); - args->parser = parser; - args->dialog = dialog; - - g_child_watch_add(*pid, (GChildWatchFunc)child_exit, args); + g_child_watch_add(*pid, (GChildWatchFunc)tgh_child_exit, parser); + chan_out = g_io_channel_unix_new(fd_out); chan_err = g_io_channel_unix_new(fd_err); + g_io_add_watch(chan_out, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, tgh_notify_parser_new(GTK_WIDGET(dialog))); g_io_add_watch(chan_err, G_IO_IN|G_IO_HUP, (GIOFunc)tgh_parse_output_func, parser); return TRUE; @@ -125,7 +103,7 @@ gboolean tgh_add (gchar **files, GPid *pid) } dialog = tgh_file_selection_dialog_new (_("Add"), NULL, 0, TGH_FILE_SELECTION_FLAG_MODIFIED|TGH_FILE_SELECTION_FLAG_UNTRACKED); - if(gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) { gtk_widget_destroy (dialog); return FALSE; @@ -134,13 +112,13 @@ gboolean tgh_add (gchar **files, GPid *pid) files = tgh_file_selection_dialog_get_files (TGH_FILE_SELECTION_DIALOG (dialog)); gtk_widget_destroy (dialog); - if(!files) + if (!files) return FALSE; - dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_OTHER, GTK_BUTTONS_CANCEL, _("Adding ...")); - g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (tgh_cancel), NULL); - tgh_dialog_start(GTK_DIALOG(dialog), TRUE); + dialog = tgh_notify_dialog_new (_("Add"), NULL, 0); + g_signal_connect (dialog, "cancel-clicked", tgh_cancel, NULL); + tgh_dialog_start (GTK_DIALOG(dialog), TRUE); - return add_spawn(dialog, files, pid); + return add_spawn (dialog, files, pid); } diff --git a/tvp-git-helper/tgh-common.c b/tvp-git-helper/tgh-common.c index a5facf8..f4fc10d 100644 --- a/tvp-git-helper/tgh-common.c +++ b/tvp-git-helper/tgh-common.c @@ -36,6 +36,7 @@ #include <thunar-vfs/thunar-vfs.h> #include "tgh-dialog-common.h" +#include "tgh-notify-dialog.h" #include "tgh-status-dialog.h" #include "tgh-log-dialog.h" #include "tgh-branch-dialog.h" @@ -105,7 +106,54 @@ tgh_error_parser_new(GtkWidget *dialog) typedef struct { TghOutputParser parent; GtkWidget *dialog; - gboolean commit; +} TghNotifyParser; + +static void +notify_parser_func(TghNotifyParser *parser, gchar *line) +{ + TghNotifyDialog *dialog = TGH_NOTIFY_DIALOG(parser->dialog); + if(line) + { + gchar *action, *file; + + file = strchr(line, '\''); + if(file) + { + *file++ = '\0'; + *strrchr(file, '\'') = '\0'; + + action = g_strstrip(line); + + tgh_notify_dialog_add(dialog, action, file); + } + } + else + { + tgh_notify_dialog_done(dialog); + g_free(parser); + } +} + +TghOutputParser* +tgh_notify_parser_new (GtkWidget *dialog) +{ + TghNotifyParser *parser = g_new(TghNotifyParser,1); + + TGH_OUTPUT_PARSER(parser)->parse = TGH_OUTPUT_PARSER_FUNC(notify_parser_func); + + parser->dialog = dialog; + + return TGH_OUTPUT_PARSER(parser); +} + +typedef struct { + TghOutputParser parent; + GtkWidget *dialog; + enum { + STATUS_COMMIT, + STATUS_MODIFIED, + STATUS_UNTRACKED + } state; } TghStatusParser; static void @@ -114,25 +162,31 @@ status_parser_func(TghStatusParser *parser, gchar *line) TghStatusDialog *dialog = TGH_STATUS_DIALOG(parser->dialog); if(line) { - if(strstr(line, "git reset")) - parser->commit = TRUE; - else if(strstr(line, "git add")) - parser->commit = FALSE; if(line[0] == '#' && line[1] == '\t') { gchar *file = strchr(line, ':'); gchar *state = _("untracked"); - if(file) + if(file && parser->state != STATUS_UNTRACKED) { *file = '\0'; state = line+2; - file = g_strstrip(file+1); + file = line+14; } else - file = g_strstrip(line+2); + file = line+2; + file[strlen(file)-1] = '\0'; + file = g_shell_unquote(file, NULL); - tgh_status_dialog_add(dialog, file, state, parser->commit); + tgh_status_dialog_add(dialog, file, state, parser->state == STATUS_COMMIT); + + g_free(file); } + else if(strstr(line, "git reset")) + parser->state = STATUS_COMMIT; + else if(strstr(line, "git add")) + parser->state = STATUS_UNTRACKED; + else if(strstr(line, "git checkout")) + parser->state = STATUS_MODIFIED; } else { diff --git a/tvp-git-helper/tgh-common.h b/tvp-git-helper/tgh-common.h index 1f62d25..72d7522 100644 --- a/tvp-git-helper/tgh-common.h +++ b/tvp-git-helper/tgh-common.h @@ -36,6 +36,8 @@ struct _TghOutputParser { TghOutputParser* tgh_error_parser_new (GtkWidget *); +TghOutputParser* tgh_notify_parser_new (GtkWidget *); + TghOutputParser* tgh_status_parser_new (GtkWidget *); TghOutputParser* tgh_log_parser_new (GtkWidget *); diff --git a/tvp-git-helper/tgh-file-selection-dialog.c b/tvp-git-helper/tgh-file-selection-dialog.c index 387708c..caa2150 100644 --- a/tvp-git-helper/tgh-file-selection-dialog.c +++ b/tvp-git-helper/tgh-file-selection-dialog.c @@ -30,7 +30,7 @@ typedef struct { TghOutputParser parent; GtkWidget *dialog; - enum {STATE_ADDED, STATE_MODIFIED, STATE_UNTRACKED} state; + enum {STATUS_ADDED, STATUS_MODIFIED, STATUS_UNTRACKED} state; } StatusParser; static void status_parser_func(StatusParser *, gchar *); @@ -249,29 +249,31 @@ status_parser_func(StatusParser *parser, gchar *line) { gchar *file = strchr(line, ':'); gchar *state = _("untracked"); - if(file) + if(file && parser->state != STATUS_UNTRACKED) { *file = '\0'; state = line+2; - file = g_strstrip(file+1); + file = line+14; } else - file = g_strstrip(line+2); + file = line+2; + file[strlen(file)-1] = '\0'; + file = g_shell_unquote(file, NULL); switch(parser->state) { - case STATE_ADDED: + case STATUS_ADDED: if(dialog->flags & TGH_FILE_SELECTION_FLAG_ADDED) add = TRUE; select_ = TRUE; break; - case STATE_MODIFIED: + case STATUS_MODIFIED: if(dialog->flags & TGH_FILE_SELECTION_FLAG_MODIFIED) add = TRUE; if(!(dialog->flags & TGH_FILE_SELECTION_FLAG_ADDED)) select_ = TRUE; break; - case STATE_UNTRACKED: + case STATUS_UNTRACKED: if(dialog->flags & TGH_FILE_SELECTION_FLAG_UNTRACKED) add = TRUE; if(!(dialog->flags & (TGH_FILE_SELECTION_FLAG_ADDED|TGH_FILE_SELECTION_FLAG_MODIFIED))) @@ -279,8 +281,6 @@ status_parser_func(StatusParser *parser, gchar *line) break; } - g_debug ("%s, %d", line, add); - if (add) { GtkTreeModel *model; @@ -295,13 +295,15 @@ status_parser_func(StatusParser *parser, gchar *line) COLUMN_SELECTION, select_, -1); } + + g_free(file); } else if(strstr(line, "git reset")) - parser->state = STATE_ADDED; + parser->state = STATUS_ADDED; else if(strstr(line, "git add")) - parser->state = STATE_UNTRACKED; + parser->state = STATUS_UNTRACKED; else if(strstr(line, "git checkout")) - parser->state = STATE_MODIFIED; + parser->state = STATUS_MODIFIED; } else { diff --git a/tvp-git-helper/tgh-status-dialog.c b/tvp-git-helper/tgh-notify-dialog.c similarity index 60% copy from tvp-git-helper/tgh-status-dialog.c copy to tvp-git-helper/tgh-notify-dialog.c index 6f7f426..d964321 100644 --- a/tvp-git-helper/tgh-status-dialog.c +++ b/tvp-git-helper/tgh-notify-dialog.c @@ -24,39 +24,35 @@ #include <thunar-vfs/thunar-vfs.h> #include <gtk/gtk.h> -#include "tgh-common.h" -#include "tgh-status-dialog.h" +#include "tgh-notify-dialog.h" static void cancel_clicked (GtkButton*, gpointer); -static void refresh_clicked (GtkButton*, gpointer); -struct _TghStatusDialog +struct _TghNotifyDialog { GtkDialog dialog; GtkWidget *tree_view; GtkWidget *close; GtkWidget *cancel; - GtkWidget *refresh; }; -struct _TghStatusDialogClass +struct _TghNotifyDialogClass { GtkDialogClass dialog_class; }; -G_DEFINE_TYPE (TghStatusDialog, tgh_status_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE (TghNotifyDialog, tgh_notify_dialog, GTK_TYPE_DIALOG) enum { SIGNAL_CANCEL = 0, - SIGNAL_REFRESH, SIGNAL_COUNT }; static guint signals[SIGNAL_COUNT]; static void -tgh_status_dialog_class_init (TghStatusDialogClass *klass) +tgh_notify_dialog_class_init (TghNotifyDialogClass *klass) { signals[SIGNAL_CANCEL] = g_signal_new("cancel-clicked", G_OBJECT_CLASS_TYPE (klass), @@ -64,23 +60,16 @@ tgh_status_dialog_class_init (TghStatusDialogClass *klass) 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - signals[SIGNAL_REFRESH] = g_signal_new("refresh-clicked", - G_OBJECT_CLASS_TYPE (klass), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); } enum { - COLUMN_PATH = 0, - COLUMN_STAT, - COLUMN_ADDED, + COLUMN_ACTION = 0, + COLUMN_PATH, COLUMN_COUNT }; static void -tgh_status_dialog_init (TghStatusDialog *dialog) +tgh_notify_dialog_init (TghNotifyDialog *dialog) { GtkWidget *button; GtkWidget *tree_view; @@ -93,25 +82,19 @@ tgh_status_dialog_init (TghStatusDialog *dialog) dialog->tree_view = tree_view = gtk_tree_view_new (); - renderer = gtk_cell_renderer_toggle_new (); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), - -1, ("Commit"), - renderer, "active", - COLUMN_ADDED, NULL); - renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), - -1, _("Path"), + -1, _("Action"), renderer, "text", - COLUMN_PATH, NULL); + COLUMN_ACTION, NULL); renderer = gtk_cell_renderer_text_new (); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view), - -1, ("State"), + -1, _("Path"), renderer, "text", - COLUMN_STAT, NULL); + COLUMN_PATH, NULL); - model = GTK_TREE_MODEL (gtk_list_store_new (COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN)); + model = GTK_TREE_MODEL (gtk_list_store_new (COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING)); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); @@ -122,30 +105,23 @@ tgh_status_dialog_init (TghStatusDialog *dialog) gtk_widget_show (tree_view); gtk_widget_show (scroll_window); - gtk_window_set_title (GTK_WINDOW (dialog), _("Status")); + gtk_window_set_title (GTK_WINDOW (dialog), _("Notify")); - gtk_button_box_set_layout(GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), GTK_BUTTONBOX_EDGE); + dialog->close = button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); + gtk_widget_hide (button); dialog->cancel = button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, FALSE, TRUE, 0); + gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, FALSE, TRUE, 0); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cancel_clicked), dialog); gtk_widget_show (button); - dialog->refresh = button = gtk_button_new_from_stock(GTK_STOCK_REFRESH); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, FALSE, TRUE, 0); - g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (refresh_clicked), dialog); - gtk_widget_hide (button); - - dialog->close = button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE); - gtk_widget_show (button); - gtk_window_set_default_size (GTK_WINDOW (dialog), 500, 400); } GtkWidget* -tgh_status_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags) +tgh_notify_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags flags) { - TghStatusDialog *dialog = g_object_new (TGH_TYPE_STATUS_DIALOG, NULL); + TghNotifyDialog *dialog = g_object_new (TGH_TYPE_NOTIFY_DIALOG, NULL); if(title) gtk_window_set_title (GTK_WINDOW(dialog), title); @@ -166,55 +142,45 @@ tgh_status_dialog_new (const gchar *title, GtkWindow *parent, GtkDialogFlags fla } void -tgh_status_dialog_add (TghStatusDialog *dialog, const gchar *file, const gchar *state, gboolean commit) +tgh_notify_dialog_add (TghNotifyDialog *dialog, const gchar *action, const gchar *file) { GtkTreeModel *model; GtkTreeIter iter; + GtkTreePath *path; - g_return_if_fail (TGH_IS_STATUS_DIALOG (dialog)); + g_return_if_fail (TGH_IS_NOTIFY_DIALOG (dialog)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tree_view)); gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, + COLUMN_ACTION, action, COLUMN_PATH, file, - COLUMN_STAT, state, - COLUMN_ADDED, commit, -1); + + path = gtk_tree_model_get_path (model, &iter); + gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (dialog->tree_view), path, NULL, FALSE, 0, 0); + + gtk_tree_path_free (path); } void -tgh_status_dialog_done (TghStatusDialog *dialog) +tgh_notify_dialog_done (TghNotifyDialog *dialog) { - g_return_if_fail (TGH_IS_STATUS_DIALOG (dialog)); + g_return_if_fail (TGH_IS_NOTIFY_DIALOG (dialog)); gtk_widget_hide (dialog->cancel); - gtk_widget_show (dialog->refresh); + gtk_widget_show (dialog->close); } static void cancel_clicked (GtkButton *button, gpointer user_data) { - TghStatusDialog *dialog = TGH_STATUS_DIALOG (user_data); - + TghNotifyDialog *dialog = TGH_NOTIFY_DIALOG (user_data); + gtk_widget_hide (dialog->cancel); - gtk_widget_show (dialog->refresh); + gtk_widget_show (dialog->close); g_signal_emit (dialog, signals[SIGNAL_CANCEL], 0); } -static void -refresh_clicked (GtkButton *button, gpointer user_data) -{ - GtkTreeModel *model; - TghStatusDialog *dialog = TGH_STATUS_DIALOG (user_data); - - gtk_widget_hide (dialog->refresh); - gtk_widget_show (dialog->cancel); - - g_signal_emit (dialog, signals[SIGNAL_REFRESH], 0); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->tree_view)); - gtk_list_store_clear (GTK_LIST_STORE (model)); -} - diff --git a/tvp-git-helper/tgh-notify-dialog.h b/tvp-git-helper/tgh-notify-dialog.h new file mode 100644 index 0000000..a05c488 --- /dev/null +++ b/tvp-git-helper/tgh-notify-dialog.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2006 Peter de Ridder <pe...@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __TGH_NOTIFY_DIALOG_H__ +#define __TGH_NOTIFY_DIALOG_H__ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS; + +typedef struct _TghNotifyDialogClass TghNotifyDialogClass; +typedef struct _TghNotifyDialog TghNotifyDialog; + +#define TGH_TYPE_NOTIFY_DIALOG (tgh_notify_dialog_get_type ()) +#define TGH_NOTIFY_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TGH_TYPE_NOTIFY_DIALOG, TghNotifyDialog)) +#define TGH_NOTIFY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TGH_TYPE_NOTIFY_DIALOG, TghNotifyDialogClass)) +#define TGH_IS_NOTIFY_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TGH_TYPE_NOTIFY_DIALOG)) +#define TGH_IS_NOTIFY_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TGH_TYPE_NOTIFY_DIALOG)) +#define TGH_NOTIFY_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TGH_TYPE_NOTIFY_DIALOG, TghNotifyDialogClass)) + +GType tgh_notify_dialog_get_type (void) G_GNUC_CONST G_GNUC_INTERNAL; + +GtkWidget* tgh_notify_dialog_new (const gchar *title, + GtkWindow *parent, + GtkDialogFlags flags) G_GNUC_MALLOC G_GNUC_INTERNAL; + +void tgh_notify_dialog_add (TghNotifyDialog *dialog, + const gchar *action, + const gchar *path); +void tgh_notify_dialog_done (TghNotifyDialog *dialog); + +G_END_DECLS; + +#endif /* !__TGH_NOTIFY_DIALOG_H__ */ _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits