widget-factory: Add a lock button

This commit is contained in:
Matthias Clasen 2015-08-11 00:09:39 +02:00
parent aa9dd72e8f
commit cf237eccbe
2 changed files with 209 additions and 94 deletions

View File

@ -1271,6 +1271,108 @@ tab_close_cb (GtkWidget *page)
g_timeout_add (2500, show_page_again, page);
}
typedef struct _GTestPermission GTestPermission;
typedef struct _GTestPermissionClass GTestPermissionClass;
struct _GTestPermission
{
GPermission parent;
};
struct _GTestPermissionClass
{
GPermissionClass parent_class;
};
G_DEFINE_TYPE (GTestPermission, g_test_permission, G_TYPE_PERMISSION)
static void
g_test_permission_init (GTestPermission *test)
{
g_permission_impl_update (G_PERMISSION (test), TRUE, TRUE, TRUE);
}
static gboolean
update_allowed (GPermission *permission,
gboolean allowed)
{
g_permission_impl_update (permission, allowed, TRUE, TRUE);
return TRUE;
}
static gboolean
acquire (GPermission *permission,
GCancellable *cancellable,
GError **error)
{
return update_allowed (permission, TRUE);
}
static void
acquire_async (GPermission *permission,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
task = g_task_new ((GObject*)permission, NULL, callback, user_data);
g_task_return_boolean (task, update_allowed (permission, TRUE));
g_object_unref (task);
}
gboolean
acquire_finish (GPermission *permission,
GAsyncResult *res,
GError **error)
{
return g_task_propagate_boolean (G_TASK (res), error);
}
static gboolean
release (GPermission *permission,
GCancellable *cancellable,
GError **error)
{
return update_allowed (permission, FALSE);
}
static void
release_async (GPermission *permission,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
task = g_task_new ((GObject*)permission, NULL, callback, user_data);
g_task_return_boolean (task, update_allowed (permission, FALSE));
g_object_unref (task);
}
gboolean
release_finish (GPermission *permission,
GAsyncResult *result,
GError **error)
{
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
g_test_permission_class_init (GTestPermissionClass *class)
{
GPermissionClass *permission_class = G_PERMISSION_CLASS (class);
permission_class->acquire = acquire;
permission_class->acquire_async = acquire_async;
permission_class->acquire_finish = acquire_finish;
permission_class->release = release;
permission_class->release_async = release_async;
permission_class->release_finish = release_finish;
}
static void
activate (GApplication *app)
{
@ -1301,6 +1403,7 @@ activate (GApplication *app)
{ "win.delete", { "Delete", NULL } }
};
gint i;
GPermission *permission;
g_type_ensure (my_text_view_get_type ());
@ -1489,6 +1592,15 @@ activate (GApplication *app)
g_signal_connect (widget2, "notify::text", G_CALLBACK (open_popover_text_changed), widget3);
g_signal_connect_swapped (widget3, "clicked", G_CALLBACK (gtk_widget_hide), widget);
widget = (GtkWidget *)gtk_builder_get_object (builder, "lockbox");
widget2 = (GtkWidget *)gtk_builder_get_object (builder, "lockbutton");
permission = g_object_new (g_test_permission_get_type (), NULL);
g_object_bind_property (permission, "allowed",
widget, "sensitive",
G_BINDING_SYNC_CREATE);
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (widget2), permission);
g_object_unref (permission);
gtk_widget_show_all (GTK_WIDGET (window));
g_object_unref (builder);

View File

@ -2897,105 +2897,128 @@ microphone-sensitivity-medium-symbolic</property>
<property name="halign">start</property>
<property name="spacing">6</property>
<child>
<object class="GtkMenuButton">
<object class="GtkBox" id="lockbox">
<property name="visible">True</property>
<property name="halign">center</property>
<property name="popover">open_popover</property>
<style>
<class name="text-button"/>
<class name="image-button"/>
</style>
<property name="halign">start</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<object class="GtkMenuButton">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="halign">center</property>
<property name="popover">open_popover</property>
<style>
<class name="text-button"/>
<class name="image-button"/>
</style>
<child>
<object class="GtkLabel">
<object class="GtkBox">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="label">Open</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="icon_name">pan-down-symbolic</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="label">Open</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="icon_name">pan-down-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToggleButton" id="record_button">
<property name="visible">True</property>
<property name="halign">center</property>
<signal name="toggled" handler="on_record_button_toggled"/>
<style>
<class name="text-button"/>
<class name="image-button"/>
<class name="destructive-action"/>
</style>
<child>
<object class="GtkBox">
<object class="GtkToggleButton" id="record_button">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="halign">center</property>
<signal name="toggled" handler="on_record_button_toggled"/>
<style>
<class name="text-button"/>
<class name="image-button"/>
<class name="destructive-action"/>
</style>
<child>
<object class="GtkImage">
<object class="GtkBox">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="icon_name">media-record-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="label">Record</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="icon_name">media-record-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="valign">baseline</property>
<property name="label">Record</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkRadioButton" id="grid_button">
<object class="GtkBox">
<property name="visible">True</property>
<style>
<class name="linked"/>
</style>
<child>
<object class="GtkRadioButton" id="grid_button">
<property name="visible">True</property>
<property name="draw-indicator">False</property>
<property name="active">True</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">view-grid-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkRadioButton" id="list_button">
<property name="active">True</property>
<property name="visible">True</property>
<property name="draw-indicator">False</property>
<property name="group">grid_button</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">view-list-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="circular_button">
<property name="visible">True</property>
<property name="draw-indicator">False</property>
<property name="active">True</property>
<style>
<class name="image-button"/>
<class name="circular-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">view-grid-symbolic</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkRadioButton" id="list_button">
<property name="active">True</property>
<property name="visible">True</property>
<property name="draw-indicator">False</property>
<property name="group">grid_button</property>
<style>
<class name="image-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">view-list-symbolic</property>
<property name="icon-name">emblem-system-symbolic</property>
</object>
</child>
</object>
@ -3003,19 +3026,8 @@ microphone-sensitivity-medium-symbolic</property>
</object>
</child>
<child>
<object class="GtkButton" id="circular_button">
<object class="GtkLockButton" id="lockbutton">
<property name="visible">True</property>
<style>
<class name="image-button"/>
<class name="circular-button"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon-size">1</property>
<property name="icon-name">emblem-system-symbolic</property>
</object>
</child>
</object>
</child>
</object>
@ -3602,7 +3614,6 @@ microphone-sensitivity-medium-symbolic</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="halign">center</property>
<child>
<object class="GtkEntry">
@ -3610,11 +3621,6 @@ microphone-sensitivity-medium-symbolic</property>
<property name="can_focus">True</property>
<property name="placeholder_text" translatable="yes">Name…</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry">
@ -3623,8 +3629,6 @@ microphone-sensitivity-medium-symbolic</property>
<property name="placeholder_text" translatable="yes">Age…</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
@ -3928,7 +3932,6 @@ bad things might happen.</property>
<property name="visible">True</property>
<property name="shadow-type">in</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<property name="min-content-height">70</property>
<child>
<object class="GtkTextView" id="open_popover_textview">