Skip to content

Commit

Permalink
Additional debug features
Browse files Browse the repository at this point in the history
-g:<regexp>, --grep:<regexp> filter debug output by regular expression
+w, --show-log-window        show log window
-o:<file>, --log-file:<file> save log data to file

Save geomtery and position of log window
Various buttons on log window
  • Loading branch information
caclark committed Jun 22, 2017
1 parent 9c47109 commit 3241294
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 19 deletions.
15 changes: 15 additions & 0 deletions doc/docbook/GuideReferenceCommandLine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@
<entry>--debug[=&lt;level&gt;]</entry>
<entry>Turn on debugging output (when compiled with Debug enabled). &lt;level&gt; is 0 to 4.</entry>
</row>
<row>
<entry>-g:&lt;regexp&gt;</entry>
<entry>--grep:&lt;regexp&gt;</entry>
<entry>Filter debug output with regular expression</entry>
</row>
<row>
<entry>+w</entry>
<entry>--show-log-window</entry>
<entry>Display log window</entry>
</row>
<row>
<entry>-o:&lt;file&gt;</entry>
<entry>--log-file:&lt;file&gt;</entry>
<entry>Save log data to file</entry>
</row>
<row>
<entry />
<entry>--alternate</entry>
Expand Down
49 changes: 44 additions & 5 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,22 @@
#include "ui_fileops.h"

#include <glib/gprintf.h>
#include <regex.h>

/*
* Logging functions
*/
static gchar *regexp = NULL;

void set_regexp(gchar *cmd_regexp)
{
regexp = g_strdup(cmd_regexp);
}

gchar *get_regexp()
{
return g_strdup(regexp);
}

static gboolean log_msg_cb(gpointer data)
{
Expand All @@ -50,17 +62,44 @@ void log_domain_printf(const gchar *domain, const gchar *format, ...)
{
va_list ap;
gchar *buf;
regex_t regex;
gint ret_comp, ret_exec;
gchar *filtered_buf;

va_start(ap, format);
buf = g_strdup_vprintf(format, ap);
va_end(ap);

print_term(buf);
if (strcmp(domain, DOMAIN_INFO) == 0)
g_idle_add(log_normal_cb, buf);
if (regexp && command_line && buf)
{
if (g_strcmp0(buf,"\n"))
{
ret_comp = regcomp(&regex, regexp, 0);
if (!ret_comp)
{
ret_exec = regexec(&regex, buf, 0, NULL, 0);

filtered_buf = g_strconcat(buf, "\n", NULL);
if (!ret_exec)
{
print_term(filtered_buf);
if (strcmp(domain, DOMAIN_INFO) == 0)
g_idle_add(log_normal_cb, filtered_buf);
else
g_idle_add(log_msg_cb, filtered_buf);
}
regfree(&regex);
}
}
}
else
g_idle_add(log_msg_cb, buf);

{
print_term(buf);
if (strcmp(domain, DOMAIN_INFO) == 0)
g_idle_add(log_normal_cb, buf);
else
g_idle_add(log_msg_cb, buf);
}
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRI
#define DEBUG_LEVEL_MIN 0
#define DEBUG_LEVEL_MAX 4

void set_regexp(gchar *regexp);
gchar *get_regexp();
gint get_debug_level(void);
void set_debug_level(gint new_level);
void debug_level_add(gint delta);
Expand Down
38 changes: 37 additions & 1 deletion src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "layout_config.h"
#include "layout_image.h"
#include "layout_util.h"
#include "logwindow.h"
#include "menu.h"
#include "pixbuf-renderer.h"
#include "pixbuf_util.h"
Expand Down Expand Up @@ -1343,6 +1344,26 @@ gboolean layout_geometry_get_tools(LayoutWindow *lw, gint *x, gint *y, gint *w,
return TRUE;
}

gboolean layout_geometry_get_log_window(LayoutWindow *lw, gint *x, gint *y,
gint *w, gint *h)
{
GdkWindow *window;

if (!layout_valid(&lw)) return FALSE;

if (!lw->log_window)
{
return FALSE;
}

window = gtk_widget_get_window(lw->log_window);
gdk_window_get_root_origin(window, x, y);
*w = gdk_window_get_width(window);
*h = gdk_window_get_height(window);

return TRUE;
}

static void layout_tools_geometry_sync(LayoutWindow *lw)
{
layout_geometry_get_tools(lw, &lw->options.float_window.x, &lw->options.float_window.y,
Expand Down Expand Up @@ -2166,6 +2187,10 @@ void layout_sync_options_with_current_state(LayoutWindow *lw)

g_free(lw->options.last_path);
lw->options.last_path = g_strdup(layout_get_path(lw));

layout_geometry_get_log_window(lw, &lw->options.log_window.x, &lw->options.log_window.y,
&lw->options.log_window.w, &lw->options.log_window.h);

}

void layout_apply_options(LayoutWindow *lw, LayoutOptions *lop)
Expand Down Expand Up @@ -2439,6 +2464,12 @@ void layout_write_attributes(LayoutOptions *layout, GString *outstr, gint indent
WRITE_NL(); WRITE_INT(*layout, image_overlay.histogram_channel);
WRITE_NL(); WRITE_INT(*layout, image_overlay.histogram_mode);

WRITE_NL(); WRITE_INT(*layout, log_window.x);
WRITE_NL(); WRITE_INT(*layout, log_window.y);
WRITE_NL(); WRITE_INT(*layout, log_window.w);
WRITE_NL(); WRITE_INT(*layout, log_window.h);
WRITE_SEPARATOR();

WRITE_NL(); WRITE_BOOL(*layout, animate);
}

Expand Down Expand Up @@ -2511,6 +2542,11 @@ void layout_load_attributes(LayoutOptions *layout, const gchar **attribute_names
if (READ_INT(*layout, image_overlay.histogram_channel)) continue;
if (READ_INT(*layout, image_overlay.histogram_mode)) continue;

if (READ_INT(*layout, log_window.x)) continue;
if (READ_INT(*layout, log_window.y)) continue;
if (READ_INT(*layout, log_window.w)) continue;
if (READ_INT(*layout, log_window.h)) continue;

if (READ_BOOL(*layout, animate)) continue;

log_printf("unknown attribute %s = %s\n", option, value);
Expand Down Expand Up @@ -2595,7 +2631,7 @@ LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar

if (use_commandline && command_line->startup_full_screen) layout_image_full_screen_start(lw);
if (use_commandline && command_line->startup_in_slideshow) layout_image_slideshow_start(lw);

if (use_commandline && command_line->log_window_show) log_window_new(lw);

g_free(path);
free_layout_options_content(&lop);
Expand Down
2 changes: 1 addition & 1 deletion src/layout_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ static void layout_menu_log_window_cb(GtkAction *action, gpointer data)
LayoutWindow *lw = data;

layout_exit_fullscreen(lw);
log_window_new();
log_window_new(lw);
}


Expand Down
107 changes: 97 additions & 10 deletions src/logwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "logwindow.h"

#include "misc.h"
#include "secure_save.h"
#include "ui_misc.h"
#include "window.h"

#include <gdk/gdkkeysyms.h>
Expand All @@ -38,6 +40,11 @@ struct _LogWindow
GdkColor colors[LOG_COUNT];

guint lines;
GtkWidget *regexp_box;
GtkWidget *bar;
GtkWidget *pause;
GtkWidget *wrap;
GtkWidget *debug_level;
};

typedef struct _LogDef LogDef;
Expand Down Expand Up @@ -70,19 +77,65 @@ static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
return FALSE;
}

static LogWindow *log_window_create(void)

static void log_window_pause_cb(GtkWidget *widget, gpointer data)
{
options->log_window.paused = !options->log_window.paused;
}

static void log_window_line_wrap_cb(GtkWidget *widget, gpointer data)
{
LogWindow *logwin = data;

options->log_window.line_wrap = !options->log_window.line_wrap;

if (options->log_window.line_wrap)
{
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(logwin->text), GTK_WRAP_WORD);
}
else
{
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(logwin->text), GTK_WRAP_NONE);
}
}

static void log_window_regexp_cb(GtkWidget *text_entry, gpointer data)
{
gchar *new_regexp;

new_regexp = g_strdup(gtk_entry_get_text(GTK_ENTRY(text_entry)));
set_regexp(new_regexp);
g_free(new_regexp);
}

static void log_window_debug_spin_cb(GtkSpinButton *debug_level, gpointer data)
{
set_debug_level(gtk_spin_button_get_value(debug_level));
}

static LogWindow *log_window_create(LayoutWindow *lw)
{
LogWindow *logwin;
GtkWidget *window;
GtkWidget *scrolledwin;
GtkWidget *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkWidget *button;
GtkWidget *win_vbox;
GtkWidget *textbox;
GtkWidget *hbox;

logwin = g_new0(LogWindow, 1);

window = window_new(GTK_WINDOW_TOPLEVEL, "log", NULL, NULL, _("Log"));
gtk_widget_set_size_request(window, 520, 400);
win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE);
gtk_container_add(GTK_CONTAINER(window), win_vbox);
gtk_widget_show(win_vbox);

gtk_widget_set_size_request(window, lw->options.log_window.w, lw->options.log_window.h);
gtk_window_move(GTK_WINDOW(window), lw->options.log_window.x, lw->options.log_window.y);

g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(gtk_widget_hide_on_delete), NULL);
g_signal_connect(G_OBJECT(window), "key_press_event",
Expand All @@ -96,9 +149,31 @@ static LogWindow *log_window_create(void)
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(window), scrolledwin);

gtk_container_add(GTK_CONTAINER(win_vbox), scrolledwin);
gtk_widget_show(scrolledwin);

hbox = pref_box_new(win_vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);

gtk_widget_show(hbox);
logwin->debug_level = pref_spin_new_mnemonic(hbox, _("Debug level:"), NULL,
0, 4, 1, 1, get_debug_level(),G_CALLBACK(log_window_debug_spin_cb),
logwin->debug_level );

logwin->pause = pref_button_new(hbox, NULL, "Pause", FALSE,
G_CALLBACK(log_window_pause_cb), NULL);

logwin->wrap = pref_button_new(hbox, NULL, "Line wrap", FALSE,
G_CALLBACK(log_window_line_wrap_cb), logwin);

pref_label_new(hbox, "Filter regexp");

textbox = gtk_entry_new();
gtk_container_add(GTK_CONTAINER(hbox), textbox);
gtk_widget_show(textbox);
g_signal_connect(G_OBJECT(textbox), "activate",
G_CALLBACK(log_window_regexp_cb), logwin);

text = gtk_text_view_new();
gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
Expand All @@ -112,7 +187,8 @@ static LogWindow *log_window_create(void)
logwin->scrolledwin = scrolledwin;
logwin->text = text;
logwin->lines = 1;

logwin->regexp_box = textbox;
lw->log_window = logwin->window;
return logwin;
}

Expand Down Expand Up @@ -168,6 +244,7 @@ static void log_window_show(LogWindow *logwin)
GtkTextView *text = GTK_TEXT_VIEW(logwin->text);
GtkTextBuffer *buffer;
GtkTextMark *mark;
gchar *regexp;

g_assert(logwin != NULL);

Expand All @@ -178,15 +255,22 @@ static void log_window_show(LogWindow *logwin)
gtk_window_present(GTK_WINDOW(logwin->window));

log_window_append("", LOG_NORMAL); // to flush memorized lines

regexp = g_strdup(get_regexp());
if (regexp != NULL)
{
gtk_entry_set_text(GTK_ENTRY(logwin->regexp_box), regexp);
g_free(regexp);
}
}

void log_window_new(void)
void log_window_new(LayoutWindow *lw)
{
if (logwindow == NULL)
{
LogWindow *logwin;

logwin = log_window_create();
logwin = log_window_create(lw);
log_window_init(logwin);
logwindow = logwin;
}
Expand Down Expand Up @@ -277,12 +361,15 @@ void log_window_append(const gchar *str, LogType type)

log_window_insert_text(buffer, &iter, str, logdefs[type].tag);

if (gtk_widget_get_visible(GTK_WIDGET(text)))
if (!options->log_window.paused)
{
GtkTextMark *mark;
if (gtk_widget_get_visible(GTK_WIDGET(text)))
{
GtkTextMark *mark;

mark = gtk_text_buffer_get_mark(buffer, "end");
gtk_text_view_scroll_mark_onscreen(text, mark);
mark = gtk_text_buffer_get_mark(buffer, "end");
gtk_text_view_scroll_mark_onscreen(text, mark);
}
}

logwindow->lines = gtk_text_buffer_get_line_count(buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/logwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef enum
LOG_COUNT
} LogType;

void log_window_new(void);
void log_window_new(LayoutWindow *lw);

void log_window_append(const gchar *str, LogType type);

Expand Down
Loading

0 comments on commit 3241294

Please sign in to comment.