[gtk+] bloatpad: test inhibit
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] bloatpad: test inhibit
- Date: Mon, 16 Dec 2013 18:51:32 +0000 (UTC)
commit 2841c0ec542262218fd805443aaa5ca3cca6d6a0
Author: Ryan Lortie <desrt desrt ca>
Date: Sat Dec 14 21:36:27 2013 -0500
bloatpad: test inhibit
Add an inhibit for logout when there is context in the text buffer.
examples/bloatpad.c | 47 +++++++++++++++++++++++++++++++++--------------
1 files changed, 33 insertions(+), 14 deletions(-)
---
diff --git a/examples/bloatpad.c b/examples/bloatpad.c
index 5ed5e7b..66ae90d 100644
--- a/examples/bloatpad.c
+++ b/examples/bloatpad.c
@@ -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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]