2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2007, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* logging.c - the action logger */
27 #include <glade/glade.h>
33 #include "gui_support.h"
35 static GtkTreeStore
*log
;
37 /* The columns in the log list store */
42 /* Static prototypes */
43 static void log_dialog_response(GtkDialog
*dialog
, gint resp_id
,
46 /****************************************************************
47 * EXTERNAL INTERFACE *
48 ****************************************************************/
52 log
= gtk_tree_store_new(3, G_TYPE_STRING
, G_TYPE_STRING
, G_TYPE_STRING
);
54 log_info_paths(_("ROX-Filer started"), NULL
, NULL
);
59 paths
= g_list_prepend(paths
, "/first");
60 paths
= g_list_prepend(paths
, "/second");
62 log_info_paths("Test path", NULL
, "/the/path");
63 log_info_paths("Test paths", paths
, NULL
);
64 log_info_paths("Test both", paths
, "/other/path");
65 log_info_paths("Test one", paths
->next
, "/other/path");
66 log_info_paths("Test promote", paths
->next
, NULL
);
70 /* Record a message in the log.
71 * paths is the list of items being processed, if any
72 * path is a single path (if only one is being processed)
73 * paths and path may both be given (e.g. for copying or moving)
75 void log_info_paths(const gchar
*message
, GList
*paths
, const gchar
*path
)
81 char *actual_message
= NULL
;
85 message
= "(no log message!)";
90 if (now
== NULL
|| !strftime(timestamp
, sizeof(timestamp
), "%Y-%m-%d %H:%M", now
))
92 g_warning("Failed to generate timestamp!");
93 strcpy(timestamp
, "ERROR");
96 gtk_tree_store_append(log
, &iter
, NULL
);
98 n_paths
= g_list_length(paths
);
100 if (path
== NULL
&& n_paths
== 1)
102 /* Promote the single item to the main path */
109 actual_message
= g_strdup_printf(_("%s '%s'"), message
, g_basename((char *) paths
->data
));
110 else if (n_paths
> 1)
111 actual_message
= g_strdup_printf(_("%s on %d items"), message
, n_paths
);
113 gtk_tree_store_set(log
, &iter
,
114 TIMESTAMP
, timestamp
,
116 MESSAGE
, actual_message
? actual_message
: message
,
121 GtkTreeIter child_iter
;
122 gtk_tree_store_append(log
, &child_iter
, &iter
);
123 gtk_tree_store_set(log
, &child_iter
,
125 DIRECTORY
, paths
->data
,
130 g_free(actual_message
);
133 /* Open the log window. */
134 void log_show_window()
138 GtkTreeViewColumn
*column
;
139 GtkCellRenderer
*renderer
;
141 glade
= get_glade_xml("Log viewer");
143 tv
= GTK_TREE_VIEW(glade_xml_get_widget(glade
, "log_list"));
144 gtk_tree_view_set_model(tv
, GTK_TREE_MODEL(log
));
146 renderer
= gtk_cell_renderer_text_new();
148 column
= gtk_tree_view_column_new_with_attributes("Time", renderer
,
151 gtk_tree_view_append_column(tv
, column
);
153 column
= gtk_tree_view_column_new_with_attributes("Action", renderer
,
156 gtk_tree_view_column_set_resizable(column
, TRUE
);
157 gtk_tree_view_append_column(tv
, column
);
159 column
= gtk_tree_view_column_new_with_attributes("Path", renderer
,
162 gtk_tree_view_append_column(tv
, column
);
164 g_signal_connect(G_OBJECT(glade_xml_get_widget(glade
, "Log viewer")),
165 "response", log_dialog_response
, NULL
);
168 /****************************************************************
169 * INTERNAL FUNCTIONS *
170 ****************************************************************/
171 static void log_dialog_response(GtkDialog
*dialog
, gint resp_id
,
174 /* Only response we should get is CLOSE */
175 gtk_widget_hide(GTK_WIDGET(dialog
));
176 gtk_widget_destroy(GTK_WIDGET(dialog
));