bloatpad: test inhibit

Add an inhibit for logout when there is context in the text buffer.
This commit is contained in:
Ryan Lortie 2013-12-14 21:36:27 -05:00
parent 8bdc3ab4c5
commit 2841c0ec54

View File

@ -1,6 +1,19 @@
#include <stdlib.h>
#include <gtk/gtk.h>
typedef struct
{
GtkApplication parent_instance;
guint quit_inhibit;
GMenu *time;
guint timeout;
} BloatPad;
typedef GtkApplicationClass BloatPadClass;
G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION)
static void
activate_toggle (GSimpleAction *action,
GVariant *parameter,
@ -126,10 +139,28 @@ activate_clear (GSimpleAction *action,
static void
text_buffer_changed_cb (GtkTextBuffer *buffer,
GApplication *app)
BloatPad *app)
{
gint old_n, n;
n = gtk_text_buffer_get_char_count (buffer);
if (n > 0)
{
if (!app->quit_inhibit)
app->quit_inhibit = gtk_application_inhibit (GTK_APPLICATION (app),
gtk_application_get_active_window (GTK_APPLICATION (app)),
GTK_APPLICATION_INHIBIT_LOGOUT,
"bloatpad can't save, so you can't logout; erase your text");
}
else
{
if (app->quit_inhibit)
{
gtk_application_uninhibit (GTK_APPLICATION (app), app->quit_inhibit);
app->quit_inhibit = 0;
}
}
old_n = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (buffer), "line-count"));
n = gtk_text_buffer_get_line_count (buffer);
g_object_set_data (G_OBJECT (buffer), "line-count", GINT_TO_POINTER (n));
@ -140,7 +171,7 @@ text_buffer_changed_cb (GtkTextBuffer *buffer,
n = g_notification_new ("Three lines of text");
g_notification_set_body (n, "Keep up the good work!");
g_notification_add_button (n, "Start over", "app.clear");
g_application_send_notification (app, "three-lines", n);
g_application_send_notification (G_APPLICATION (app), "three-lines", n);
g_object_unref (n);
}
}
@ -254,18 +285,6 @@ bloat_pad_open (GApplication *application,
new_window (application, files[i]);
}
typedef struct
{
GtkApplication parent_instance;
GMenu *time;
guint timeout;
} BloatPad;
typedef GtkApplicationClass BloatPadClass;
G_DEFINE_TYPE (BloatPad, bloat_pad, GTK_TYPE_APPLICATION)
static void
bloat_pad_finalize (GObject *object)
{