Commit afa21fb4 authored by Ray Strode's avatar Ray Strode

shell: deduplicate shell signal logic

Anytime the shell sends us a signal about the end session dialog
we need to do the same things:

1) stop listening for new inhibitor updates
2) stop any queued operations for redisplaying the inhibitor dialog
3) emit the signal to on the gsm-shell object so other parts of the
code can listen for.

We currently have a separate signal handler for every signal, and
they all do they same thing.  Well, they're supposed to anyway, some
bits are erroneously missing from some of the handlers.

This commit consolidates all the code, so we don't have it reimplemently
badly in several places.
parent 3254e113
......@@ -328,27 +328,6 @@ debug_clients (GsmManager *manager)
manager);
}
static gboolean
_debug_inhibitor (const char *id,
GsmInhibitor *inhibitor,
GsmManager *manager)
{
g_debug ("GsmManager: Inhibitor app:%s client:%s bus-name:%s reason:%s",
gsm_inhibitor_peek_app_id (inhibitor),
gsm_inhibitor_peek_client_id (inhibitor),
gsm_inhibitor_peek_bus_name (inhibitor),
gsm_inhibitor_peek_reason (inhibitor));
return FALSE;
}
static void
debug_inhibitors (GsmManager *manager)
{
gsm_store_foreach (manager->priv->inhibitors,
(GsmStoreFunc)_debug_inhibitor,
manager);
}
static gboolean
_find_by_cookie (const char *id,
GsmInhibitor *inhibitor,
......@@ -3074,51 +3053,6 @@ on_session_connection_closed (GDBusConnection *connection,
remove_clients_for_connection (manager, NULL);
}
static gboolean
inhibitor_has_bus_name (gpointer key,
GsmInhibitor *inhibitor,
RemoveClientData *data)
{
gboolean matches;
const char *bus_name_b;
bus_name_b = gsm_inhibitor_peek_bus_name (inhibitor);
matches = FALSE;
if (! IS_STRING_EMPTY (data->service_name) && ! IS_STRING_EMPTY (bus_name_b)) {
matches = (strcmp (data->service_name, bus_name_b) == 0);
if (matches) {
g_debug ("GsmManager: removing inhibitor from %s for reason '%s' on connection %s",
gsm_inhibitor_peek_app_id (inhibitor),
gsm_inhibitor_peek_reason (inhibitor),
gsm_inhibitor_peek_bus_name (inhibitor));
}
}
return matches;
}
static void
remove_inhibitors_for_connection (GsmManager *manager,
const char *service_name)
{
RemoveClientData data;
guint count;
data.service_name = service_name;
data.manager = manager;
debug_inhibitors (manager);
count = gsm_store_foreach_remove (manager->priv->inhibitors,
(GsmStoreFunc)inhibitor_has_bus_name,
&data);
if (count > 0 &&
manager->priv->phase == GSM_MANAGER_PHASE_QUERY_END_SESSION) {
end_session_or_show_shell_dialog (manager);
}
}
static gboolean
register_manager (GsmManager *manager)
{
......
......@@ -328,23 +328,36 @@ on_open_finished (GObject *source,
}
static void
on_end_session_dialog_closed (GsmShell *shell)
on_end_session_dialog_dbus_signal (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
GsmShell *shell)
{
if (shell->priv->update_idle_id != 0) {
g_source_remove (shell->priv->update_idle_id);
shell->priv->update_idle_id = 0;
struct {
const char *name;
int index;
} signal_map[] = {
{ "Closed", END_SESSION_DIALOG_CLOSED },
{ "Canceled", END_SESSION_DIALOG_CANCELED },
{ "ConfirmedLogout", END_SESSION_DIALOG_CONFIRMED_LOGOUT },
{ "ConfirmedReboot", END_SESSION_DIALOG_CONFIRMED_REBOOT },
{ "ConfirmedShutdown", END_SESSION_DIALOG_CONFIRMED_SHUTDOWN },
{ NULL, -1 }
};
int signal_index = -1;
int i;
for (i = 0; signal_map[i].name != NULL; i++) {
if (g_strcmp0 (signal_map[i].name, signal_name) == 0) {
signal_index = signal_map[i].index;
break;
}
}
g_signal_handlers_disconnect_by_func (shell->priv->inhibitors,
G_CALLBACK (queue_end_session_dialog_update),
shell);
g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CLOSED], 0);
}
if (signal_index == -1)
return;
static void
on_end_session_dialog_canceled (GsmShell *shell)
{
if (shell->priv->update_idle_id != 0) {
g_source_remove (shell->priv->update_idle_id);
shell->priv->update_idle_id = 0;
......@@ -354,60 +367,7 @@ on_end_session_dialog_canceled (GsmShell *shell)
G_CALLBACK (queue_end_session_dialog_update),
shell);
g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CANCELED], 0);
}
static void
on_end_session_dialog_confirmed_logout (GsmShell *shell)
{
if (shell->priv->update_idle_id != 0) {
g_source_remove (shell->priv->update_idle_id);
shell->priv->update_idle_id = 0;
}
g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_LOGOUT], 0);
}
static void
on_end_session_dialog_confirmed_shutdown (GsmShell *shell)
{
if (shell->priv->update_idle_id != 0) {
g_source_remove (shell->priv->update_idle_id);
shell->priv->update_idle_id = 0;
}
g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_SHUTDOWN], 0);
}
static void
on_end_session_dialog_confirmed_reboot (GsmShell *shell)
{
if (shell->priv->update_idle_id != 0) {
g_source_remove (shell->priv->update_idle_id);
shell->priv->update_idle_id = 0;
}
g_signal_emit (G_OBJECT (shell), signals[END_SESSION_DIALOG_CONFIRMED_REBOOT], 0);
}
static void
on_end_session_dialog_dbus_signal (GDBusProxy *proxy,
gchar *sender_name,
gchar *signal_name,
GVariant *parameters,
GsmShell *shell)
{
if (g_strcmp0 (signal_name, "Closed") == 0) {
on_end_session_dialog_closed (shell);
} else if (g_strcmp0 (signal_name, "Canceled") == 0) {
on_end_session_dialog_canceled (shell);
} else if (g_strcmp0 (signal_name ,"ConfirmedLogout") == 0) {
on_end_session_dialog_confirmed_logout (shell);
} else if (g_strcmp0 (signal_name ,"ConfirmedReboot") == 0) {
on_end_session_dialog_confirmed_reboot (shell);
} else if (g_strcmp0 (signal_name ,"ConfirmedShutdown") == 0) {
on_end_session_dialog_confirmed_shutdown (shell);
}
g_signal_emit (G_OBJECT (shell), signals[signal_index], 0);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment