Commit 256730a8 authored by Guido Gunther's avatar Guido Gunther
Browse files

Merge branch 'gmountoperation' into 'main'

Add initial PhoshMountOperation

Closes #573

See merge request World/Phosh/phosh!878
parents 518a977e 837c173c
......@@ -97,6 +97,8 @@ libphosh_tool_sources = files(
'mode-manager.h',
'mount-manager.c',
'mount-manager.h',
'mount-operation.c',
'mount-operation.h',
'overview.c',
'overview.h',
'osd-window.c',
......
......@@ -11,6 +11,7 @@
#include "config.h"
#include "feedback-manager.h"
#include "mount-manager.h"
#include "mount-operation.h"
#include "notifications/mount-notification.h"
#include "notifications/notify-manager.h"
#include "shell.h"
......@@ -101,8 +102,9 @@ static void
on_volume_added (PhoshMountManager *self, GVolume *vol, GVolumeMonitor *monitor)
{
gboolean automount;
gpointer ignore_lock;
gboolean mount_all;
GCancellable *cancellable;
g_autoptr (PhoshMountOperation) op = NULL;
g_autoptr (GMount) mount = NULL;
g_autofree gchar *name = NULL;
......@@ -116,8 +118,9 @@ on_volume_added (PhoshMountManager *self, GVolume *vol, GVolumeMonitor *monitor)
if (!phosh_shell_is_session_active (phosh_shell_get_default ()))
return;
ignore_lock = g_object_get_data (G_OBJECT (vol), "phosh-ignore-lock");
if (phosh_shell_get_locked (phosh_shell_get_default ()) && !ignore_lock)
mount_all = !!g_object_get_data (G_OBJECT (vol), "phosh-mount-all");
/* Initial mount-all is o.k. even when locked */
if (phosh_shell_get_locked (phosh_shell_get_default ()) && !mount_all)
return;
mount = g_volume_get_mount (vol);
......@@ -133,12 +136,16 @@ on_volume_added (PhoshMountManager *self, GVolume *vol, GVolumeMonitor *monitor)
return;
}
/* If this is not the intial 'mount-all' run allow UI interaction */
if (!mount_all)
op = phosh_mount_operation_new ();
cancellable = g_cancellable_new ();
g_object_set_data (G_OBJECT (vol), "phosh-cancel", cancellable);
g_ptr_array_add (self->cancellables, cancellable);
g_ptr_array_ref (self->cancellables);
g_debug ("Mounting '%s'", name);
g_volume_mount (g_object_ref (vol), G_MOUNT_MOUNT_NONE, NULL, cancellable,
g_volume_mount (g_object_ref (vol), G_MOUNT_MOUNT_NONE, G_MOUNT_OPERATION (op), cancellable,
(GAsyncReadyCallback)on_mount_finished, g_object_ref (self));
}
......@@ -243,7 +250,7 @@ on_session_active_changed (PhoshMountManager *self, GParamSpec *pspec, PhoshSess
for (GList *elem = volumes; elem != NULL; elem = elem->next) {
GVolume *vol = G_VOLUME (elem->data);
/* Ignore screen lock on initial startup */
g_object_set_data (G_OBJECT (vol), "phosh-ignore-lock", GINT_TO_POINTER (TRUE));
g_object_set_data (G_OBJECT (vol), "phosh-mount-all", GINT_TO_POINTER (TRUE));
on_volume_added (self, vol, self->monitor);
}
......
/*
* Copyright (C) 2021 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Author: Guido Günther <agx@sigxcpu.org>
*/
#define G_LOG_DOMAIN "phosh-mount-operation"
#include "config.h"
#include "gtk-mount-prompt.h"
#include "mount-operation.h"
#include "util.h"
/**
* SECTION:mount-operation
* @short_description: #GMountOperation using UI
* @Title: PhoshMountOperation
*
* A #GMountOperation that uses system modal dialogs for input.
*/
struct _PhoshMountOperation {
GMountOperation parent;
PhoshGtkMountPrompt *prompt;
};
G_DEFINE_TYPE (PhoshMountOperation, phosh_mount_operation, G_TYPE_MOUNT_OPERATION)
static void
on_prompt_done (PhoshMountOperation *self, PhoshGtkMountPrompt *prompt)
{
gboolean cancelled;
GMountOperationResult result = G_MOUNT_OPERATION_ABORTED;
g_return_if_fail (PHOSH_IS_MOUNT_OPERATION (self));
g_return_if_fail (PHOSH_IS_GTK_MOUNT_PROMPT (prompt));
cancelled = phosh_gtk_mount_prompt_get_cancelled (prompt);
g_debug ("Prompt done, cancelled: %d", cancelled);
if (!cancelled) {
GAskPasswordFlags flags = phosh_gtk_mount_prompt_get_ask_flags (prompt);
if (flags & G_ASK_PASSWORD_NEED_PASSWORD) {
const char *password;
password = phosh_gtk_mount_prompt_get_password (prompt);
g_mount_operation_set_password (G_MOUNT_OPERATION (self), password);
result = G_MOUNT_OPERATION_HANDLED;
}
}
g_mount_operation_reply (G_MOUNT_OPERATION (self), result);
g_clear_pointer (&self->prompt, phosh_cp_widget_destroy);
}
static void
new_prompt (PhoshMountOperation *self,
const char *message,
const char *icon_name,
const char *default_user,
const char *default_domain,
GVariant *pids,
const char *const *choices,
GAskPasswordFlags ask_flags)
{
g_debug ("New prompt for '%s'", message);
g_clear_pointer (&self->prompt, phosh_cp_widget_destroy);
self->prompt = PHOSH_GTK_MOUNT_PROMPT (phosh_gtk_mount_prompt_new (
message,
icon_name,
default_user,
default_domain,
pids,
choices,
ask_flags));
g_signal_connect_swapped (self->prompt,
"closed",
G_CALLBACK (on_prompt_done),
self);
gtk_widget_show (GTK_WIDGET (self->prompt));
}
static void
phosh_mount_operation_ask_password (GMountOperation *op,
const char *message,
const char *default_user,
const char *default_domain,
GAskPasswordFlags flags)
{
PhoshMountOperation *self = PHOSH_MOUNT_OPERATION (op);
new_prompt (self, message,
NULL, /* icon */
default_user,
default_domain,
NULL, /* default_user */
NULL, /* choices */
flags);
}
static void
phosh_mount_operation_dispose (GObject *object)
{
PhoshMountOperation *self = PHOSH_MOUNT_OPERATION (object);
g_clear_pointer (&self->prompt, phosh_cp_widget_destroy);
G_OBJECT_CLASS (phosh_mount_operation_parent_class)->dispose (object);
}
static void
phosh_mount_operation_class_init (PhoshMountOperationClass *klass)
{
GMountOperationClass *mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = phosh_mount_operation_dispose;
mount_op_class->ask_password = phosh_mount_operation_ask_password;
}
static void
phosh_mount_operation_init (PhoshMountOperation *self)
{
}
PhoshMountOperation *
phosh_mount_operation_new (void)
{
return PHOSH_MOUNT_OPERATION (g_object_new (PHOSH_TYPE_MOUNT_OPERATION, NULL));
}
/*
* Copyright (C) 2021 Purism SPC
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#pragma once
#include <gio/gio.h>
G_BEGIN_DECLS
#define PHOSH_TYPE_MOUNT_OPERATION (phosh_mount_operation_get_type ())
G_DECLARE_FINAL_TYPE (PhoshMountOperation, phosh_mount_operation, PHOSH, MOUNT_OPERATION, GMountOperation)
PhoshMountOperation *phosh_mount_operation_new (void);
G_END_DECLS
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