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 */
28 #include <glade/glade.h>
34 #include "gui_support.h"
36 static GtkTreeStore
*log
;
38 /* The columns in the log list store */
43 /* Static prototypes */
44 static void log_dialog_response(GtkDialog
*dialog
, gint resp_id
,
47 /****************************************************************
48 * EXTERNAL INTERFACE *
49 ****************************************************************/
53 log
= gtk_tree_store_new(3, G_TYPE_STRING
, G_TYPE_STRING
, G_TYPE_STRING
);
55 log_info_paths(_("ROX-Filer started"), NULL
, NULL
);
60 paths
= g_list_prepend(paths
, "/first");
61 paths
= g_list_prepend(paths
, "/second");
63 log_info_paths("Test path", NULL
, "/the/path");
64 log_info_paths("Test paths", paths
, NULL
);
65 log_info_paths("Test both", paths
, "/other/path");
66 log_info_paths("Test one", paths
->next
, "/other/path");
67 log_info_paths("Test promote", paths
->next
, NULL
);
71 /* Record a message in the log.
72 * paths is the list of items being processed, if any
73 * path is a single path (if only one is being processed)
74 * paths and path may both be given (e.g. for copying or moving)
76 void log_info_paths(const gchar
*message
, GList
*paths
, const gchar
*path
)
82 char *actual_message
= NULL
;
86 message
= "(no log message!)";
91 if (now
== NULL
|| !strftime(timestamp
, sizeof(timestamp
), "%Y-%m-%d %H:%M", now
))
93 g_warning("Failed to generate timestamp!");
94 strcpy(timestamp
, "ERROR");
97 gtk_tree_store_append(log
, &iter
, NULL
);
99 n_paths
= g_list_length(paths
);
101 if (path
== NULL
&& n_paths
== 1)
103 /* Promote the single item to the main path */
110 actual_message
= g_strdup_printf(_("%s '%s'"), message
, g_basename((char *) paths
->data
));
111 else if (n_paths
> 1)
112 actual_message
= g_strdup_printf(_("%s on %d items"), message
, n_paths
);
114 gtk_tree_store_set(log
, &iter
,
115 TIMESTAMP
, timestamp
,
117 MESSAGE
, actual_message
? actual_message
: message
,
122 GtkTreeIter child_iter
;
123 gtk_tree_store_append(log
, &child_iter
, &iter
);
124 gtk_tree_store_set(log
, &child_iter
,
126 DIRECTORY
, paths
->data
,
131 g_free(actual_message
);
134 /* Open the log window. */
135 void log_show_window()
139 GtkTreeViewColumn
*column
;
140 GtkCellRenderer
*renderer
;
142 glade
= get_glade_xml("Log viewer");
144 tv
= GTK_TREE_VIEW(glade_xml_get_widget(glade
, "log_list"));
145 gtk_tree_view_set_model(tv
, GTK_TREE_MODEL(log
));
147 renderer
= gtk_cell_renderer_text_new();
149 column
= gtk_tree_view_column_new_with_attributes(_("Time"), renderer
,
152 gtk_tree_view_append_column(tv
, column
);
154 column
= gtk_tree_view_column_new_with_attributes(_("Action"), renderer
,
157 gtk_tree_view_column_set_resizable(column
, TRUE
);
158 gtk_tree_view_append_column(tv
, column
);
160 column
= gtk_tree_view_column_new_with_attributes(_("Path"), renderer
,
163 gtk_tree_view_append_column(tv
, column
);
165 g_signal_connect(G_OBJECT(glade_xml_get_widget(glade
, "Log viewer")),
166 "response", (GCallback
) log_dialog_response
, NULL
);
169 /****************************************************************
170 * INTERNAL FUNCTIONS *
171 ****************************************************************/
172 static void log_dialog_response(GtkDialog
*dialog
, gint resp_id
,
175 /* Only response we should get is CLOSE */
176 gtk_widget_hide(GTK_WIDGET(dialog
));
177 gtk_widget_destroy(GTK_WIDGET(dialog
));