This repository has been archived on 2020-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
gnoemoe/gnoemoe/dialogs/gm-world-logs-dialog.c

154 lines
3.7 KiB
C
Raw Permalink Normal View History

2005-11-07 10:56:25 +01:00
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include <glade/glade.h>
2006-01-10 01:41:16 +01:00
#include "gm-world.h"
#include "gm-support.h"
2006-03-29 14:09:47 +02:00
#include "gm-debug.h"
2005-11-07 10:56:25 +01:00
2006-03-29 14:09:47 +02:00
#define GM_WORLD_LOGS_DIALOG_XML PACKAGE_DATA_DIR "/" PACKAGE "/ui/gm-world-logs.glade"
2005-11-07 10:56:25 +01:00
void
on_gm_world_logs_dialog_row_activated(GtkTreeView *treeview, GtkTreePath *arg1,
GtkTreeViewColumn *arg2, GtkDialog *dlg);
/* Public */
2005-11-15 12:55:06 +01:00
void
gm_world_logs_dialog_build_tree_view(GtkTreeView *tree_view) {
2005-11-07 10:56:25 +01:00
GtkTreeModel *model, *smodel;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
2005-11-15 12:55:06 +01:00
2005-11-07 10:56:25 +01:00
model = GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING));
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes(_("Logs"), renderer,
"text", 1, NULL);
2005-11-15 12:55:06 +01:00
gtk_tree_view_append_column(tree_view, column);
2005-11-07 10:56:25 +01:00
smodel = gtk_tree_model_sort_new_with_model(model);
* VERSION CHANGED TO 2.0.9 * po/POTFILES.in: added gnoemoe/dialogs/gm-world-paste-dialog.c and ui/gm-world-paste.glade * po/nl.po: added translations * ui/Makefile.am: * ui/gm-ui.xml: * ui/gm-world-paste.glade: new paste dialog * gnoemoe/mcp/Makefile.include: added gm-cell-renderer-text.[ch] * gnoemoe/mcp/gm-cell-renderer-text.[ch]: new cell renderer for rendering userlist * gnoemoe/mcp/gm-mcp-vmoo-client.c: update metrics in timeout so to reduce the number of updates when resizing * gnoemoe/mcp/gm-mcp-icecrew-serverinfo.c: max version set to 1.0 (1.0 does not actively request the info because it will be send on initialization). Set menu item invisible instead of insensitive when there is no info available * gnoemoe/mcp/gm-mcp-icecrew-userlist.c: fixed menu item substitution * gnoemoe/mcp/gm-mcp-vmoo-userlist.c: removed support for status because it doesn't really support it * gm-mcp-userlist-view.[ch]: moved column constants to header. Render items with new gm-cell-renderer-text. * gnoemoe/mcp/gm-mcp-icecrew-playerdb.[ch]: made gm_mcp_icecrew_playerdb_players public * gnoemoe/dialogs/Makefile.include: added gm-world-paste-dialog * gnoemoe/dialogs/gm-world-paste-dialog.[ch]: new paste dialog * gnoemoe/dialogs/gm-world-properties-dialog.c: * gnoemoe/dialogs/gm-world-logs-dialog.c: fixed leaking tree stores * gnoemoe/widgets/Makefile.include: added gm-commands.[ch] * gnoemoe/widgets/gm-commands.[ch]: new file for handling action activation (removed from gm-app-view) * gnoemoe/widgets/gm-world-view.c: fixed userlist size restore * gnoemoe/widgets/gm-app-view.c: removed action handlers * gnoemoe/gm-support.[ch]: added gm_find_child * gnoemoe/gm-world.c: removed debug message * gnoemoe/gm-ui.h: changed actions to gm-commands
2006-04-23 16:51:04 +02:00
g_object_unref(model);
2005-11-07 10:56:25 +01:00
gtk_tree_view_column_set_sort_column_id(column, 0);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(smodel), 0,
GTK_SORT_DESCENDING);
2005-11-15 12:55:06 +01:00
gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(smodel));
* VERSION CHANGED TO 2.0.9 * po/POTFILES.in: added gnoemoe/dialogs/gm-world-paste-dialog.c and ui/gm-world-paste.glade * po/nl.po: added translations * ui/Makefile.am: * ui/gm-ui.xml: * ui/gm-world-paste.glade: new paste dialog * gnoemoe/mcp/Makefile.include: added gm-cell-renderer-text.[ch] * gnoemoe/mcp/gm-cell-renderer-text.[ch]: new cell renderer for rendering userlist * gnoemoe/mcp/gm-mcp-vmoo-client.c: update metrics in timeout so to reduce the number of updates when resizing * gnoemoe/mcp/gm-mcp-icecrew-serverinfo.c: max version set to 1.0 (1.0 does not actively request the info because it will be send on initialization). Set menu item invisible instead of insensitive when there is no info available * gnoemoe/mcp/gm-mcp-icecrew-userlist.c: fixed menu item substitution * gnoemoe/mcp/gm-mcp-vmoo-userlist.c: removed support for status because it doesn't really support it * gm-mcp-userlist-view.[ch]: moved column constants to header. Render items with new gm-cell-renderer-text. * gnoemoe/mcp/gm-mcp-icecrew-playerdb.[ch]: made gm_mcp_icecrew_playerdb_players public * gnoemoe/dialogs/Makefile.include: added gm-world-paste-dialog * gnoemoe/dialogs/gm-world-paste-dialog.[ch]: new paste dialog * gnoemoe/dialogs/gm-world-properties-dialog.c: * gnoemoe/dialogs/gm-world-logs-dialog.c: fixed leaking tree stores * gnoemoe/widgets/Makefile.include: added gm-commands.[ch] * gnoemoe/widgets/gm-commands.[ch]: new file for handling action activation (removed from gm-app-view) * gnoemoe/widgets/gm-world-view.c: fixed userlist size restore * gnoemoe/widgets/gm-app-view.c: removed action handlers * gnoemoe/gm-support.[ch]: added gm_find_child * gnoemoe/gm-world.c: removed debug message * gnoemoe/gm-ui.h: changed actions to gm-commands
2006-04-23 16:51:04 +02:00
g_object_unref(smodel);
2005-11-15 12:55:06 +01:00
}
gint
gm_world_logs_dialog_fill(GmWorld *world, GtkTreeView *view,
GtkTreeModel *model, GError **err) {
gint res = 0;
gchar *path, *tmp, *tmp2;
gchar const *fname;
GDir *dir;
GtkTreeIter iter;
FILE *f;
long fsize;
2005-11-07 10:56:25 +01:00
/* Fill it in */
path = g_strdup_printf("%s/logs/", gm_world_path(world));
2005-11-15 12:55:06 +01:00
dir = g_dir_open(path, 0, err);
2005-11-07 10:56:25 +01:00
if (dir) {
while ((fname = g_dir_read_name(dir)) != NULL) {
2005-11-15 12:55:06 +01:00
++res;
2005-11-07 10:56:25 +01:00
tmp = g_strconcat(path, fname, NULL);
f = fopen(tmp, "r");
if (f) {
fseek(f, 0, SEEK_END);
fsize = ftell(f);
fclose(f);
g_free(tmp);
tmp = gnome_vfs_format_file_size_for_display(fsize);
tmp2 = g_strconcat(fname, " (", tmp, ")", NULL);
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, fname, 1,
tmp2, -1);
g_free(tmp2);
}
g_free(tmp);
}
g_dir_close(dir);
2005-11-15 12:55:06 +01:00
g_free(path);
return res;
2005-11-07 10:56:25 +01:00
} else {
2005-11-15 12:55:06 +01:00
g_free(path);
return -1;
}
}
GtkDialog *
gm_world_logs_dialog_new(GmWorld *world, GtkTreeView **view) {
2006-03-29 14:09:47 +02:00
GladeXML *xml;
2005-11-15 12:55:06 +01:00
GtkDialog *dlg;
2006-02-06 19:38:11 +01:00
GError *err = NULL;
2005-11-15 12:55:06 +01:00
gint res;
gchar *tmp;
2005-12-23 14:26:52 +01:00
GtkTreeModel *model, *smodel;
2005-11-15 12:55:06 +01:00
GtkTreeIter iter;
2006-03-29 14:09:47 +02:00
xml = glade_xml_new(GM_WORLD_LOGS_DIALOG_XML, "gm_world_logs_dialog", NULL);
if (xml == NULL) {
gm_debug_msg(DEBUG_ALWAYS, "Couldn't find glade file %s!",
GM_WORLD_LOGS_DIALOG_XML);
return NULL;
}
2005-11-15 12:55:06 +01:00
dlg = GTK_DIALOG(glade_xml_get_widget(xml, "gm_world_logs_dialog"));
*view = GTK_TREE_VIEW(glade_xml_get_widget(xml, "tree_view_files"));
gm_world_logs_dialog_build_tree_view(*view);
2005-12-23 14:26:52 +01:00
smodel = gtk_tree_view_get_model(*view);
model = gtk_tree_model_sort_get_model(GTK_TREE_MODEL_SORT(
smodel));
2005-11-15 12:55:06 +01:00
res = gm_world_logs_dialog_fill(world, *view, model, &err);
if (res == -1) {
tmp = g_strdup_printf(_("Couldn't open the log directory: %s"),
err->message);
2005-11-07 10:56:25 +01:00
gm_error_dialog(tmp, NULL);
g_error_free(err);
g_free(tmp);
gtk_widget_destroy(GTK_WIDGET(dlg));
dlg = NULL;
2005-11-15 12:55:06 +01:00
} else if (res == 0) {
gm_info_dialog(_("There are no log files for this world"), NULL);
gtk_widget_destroy(GTK_WIDGET(dlg));
dlg = NULL;
} else {
2005-12-23 14:26:52 +01:00
if (gtk_tree_model_get_iter_first(smodel, &iter)) {
gtk_tree_selection_select_iter(gtk_tree_view_get_selection(*view),
&iter);
}
2005-11-15 12:55:06 +01:00
glade_xml_signal_connect_data(xml, "on_tree_view_files_row_activated",
G_CALLBACK(on_gm_world_logs_dialog_row_activated), dlg);
2005-11-07 10:56:25 +01:00
}
g_object_unref(xml);
return dlg;
}
/* Callbacks */
void
on_gm_world_logs_dialog_row_activated(GtkTreeView *treeview, GtkTreePath *arg1,
GtkTreeViewColumn *arg2, GtkDialog *dlg) {
gtk_dialog_response(dlg, GTK_RESPONSE_OK);
}