2008-03-17 17:29:55 +00:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2008-03-17 17:29:55 +00:00
|
|
|
* Copyright (C) Christian Kellner <gicmo@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-17 17:29:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2018-07-22 19:16:21 +00:00
|
|
|
#include <errno.h>
|
2008-03-17 17:29:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
#include "gtkmountoperationprivate.h"
|
2008-03-17 17:29:55 +00:00
|
|
|
#include "gtkbox.h"
|
2012-06-21 01:36:09 +00:00
|
|
|
#include "gtkdbusgenerated.h"
|
2008-03-17 17:29:55 +00:00
|
|
|
#include "gtkentry.h"
|
2011-08-28 05:54:55 +00:00
|
|
|
#include "gtkbox.h"
|
2008-03-17 17:29:55 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmessagedialog.h"
|
|
|
|
#include "gtkmountoperation.h"
|
|
|
|
#include "gtkprivate.h"
|
2020-08-30 21:51:21 +00:00
|
|
|
#include "gtkcheckbutton.h"
|
2011-08-28 04:39:44 +00:00
|
|
|
#include "gtkgrid.h"
|
2008-03-17 17:29:55 +00:00
|
|
|
#include "gtkwindow.h"
|
2009-07-01 03:46:02 +00:00
|
|
|
#include "gtktreeview.h"
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
#include "gtkmain.h"
|
2014-01-15 11:23:38 +00:00
|
|
|
#include "gtksettings.h"
|
2016-11-20 02:18:20 +00:00
|
|
|
#include "gtkdialogprivate.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2019-12-26 18:09:04 +00:00
|
|
|
#include "gtkmodelbuttonprivate.h"
|
|
|
|
#include "gtkpopover.h"
|
2020-02-06 16:10:13 +00:00
|
|
|
#include "gtksnapshot.h"
|
|
|
|
#include "gdktextureprivate.h"
|
2020-03-19 02:56:53 +00:00
|
|
|
#include "gtkshortcutcontroller.h"
|
|
|
|
#include "gtkshortcuttrigger.h"
|
|
|
|
#include "gtkshortcutaction.h"
|
|
|
|
#include "gtkshortcut.h"
|
2020-06-21 22:03:39 +00:00
|
|
|
#include "gtkliststore.h"
|
2012-06-21 01:36:09 +00:00
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* GtkMountOperation:
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* `GtkMountOperation` is an implementation of `GMountOperation`.
|
2021-02-18 18:17:56 +00:00
|
|
|
*
|
2020-09-12 16:01:04 +00:00
|
|
|
* The functions and objects described here make working with GTK and
|
2009-10-14 21:44:59 +00:00
|
|
|
* GIO more convenient.
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* `GtkMountOperation` is needed when mounting volumes:
|
|
|
|
* It is an implementation of `GMountOperation` that can be used with
|
2009-10-14 21:44:59 +00:00
|
|
|
* GIO functions for mounting volumes such as
|
2009-07-01 03:46:02 +00:00
|
|
|
* g_file_mount_enclosing_volume(), g_file_mount_mountable(),
|
2009-10-14 21:44:59 +00:00
|
|
|
* g_volume_mount(), g_mount_unmount_with_operation() and others.
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* When necessary, `GtkMountOperation` shows dialogs to let the user
|
|
|
|
* enter passwords, ask questions or show processes blocking unmount.
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-19 15:15:49 +00:00
|
|
|
static void gtk_mount_operation_finalize (GObject *object);
|
2008-03-17 17:29:55 +00:00
|
|
|
static void gtk_mount_operation_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_mount_operation_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gtk_mount_operation_ask_password (GMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
const char *default_user,
|
|
|
|
const char *default_domain,
|
|
|
|
GAskPasswordFlags flags);
|
|
|
|
|
|
|
|
static void gtk_mount_operation_ask_question (GMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
const char *choices[]);
|
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
static void gtk_mount_operation_show_processes (GMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
GArray *processes,
|
|
|
|
const char *choices[]);
|
|
|
|
|
2009-02-17 06:29:21 +00:00
|
|
|
static void gtk_mount_operation_aborted (GMountOperation *op);
|
|
|
|
|
2008-11-21 08:20:19 +00:00
|
|
|
struct _GtkMountOperationPrivate {
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkWindow *parent_window;
|
|
|
|
GtkDialog *dialog;
|
2017-10-31 06:51:15 +00:00
|
|
|
GdkDisplay *display;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
/* bus proxy */
|
2012-06-25 20:26:41 +00:00
|
|
|
_GtkMountOperationHandler *handler;
|
2012-06-21 01:36:09 +00:00
|
|
|
GCancellable *cancellable;
|
|
|
|
gboolean handler_showing;
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
/* for the ask-password dialog */
|
2012-08-23 16:04:23 +00:00
|
|
|
GtkWidget *grid;
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkWidget *username_entry;
|
|
|
|
GtkWidget *domain_entry;
|
|
|
|
GtkWidget *password_entry;
|
2018-07-22 19:16:21 +00:00
|
|
|
GtkWidget *pim_entry;
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkWidget *anonymous_toggle;
|
2018-07-22 19:16:21 +00:00
|
|
|
GtkWidget *tcrypt_hidden_toggle;
|
|
|
|
GtkWidget *tcrypt_system_toggle;
|
2012-08-23 16:04:23 +00:00
|
|
|
GList *user_widgets;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
GAskPasswordFlags ask_flags;
|
|
|
|
GPasswordSave password_save;
|
|
|
|
gboolean anonymous;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
/* for the show-processes dialog */
|
|
|
|
GtkWidget *process_tree_view;
|
|
|
|
GtkListStore *process_list_store;
|
2008-03-17 17:29:55 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_PARENT,
|
|
|
|
PROP_IS_SHOWING,
|
2017-10-31 06:51:15 +00:00
|
|
|
PROP_DISPLAY
|
2013-06-27 19:02:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkMountOperation, gtk_mount_operation, G_TYPE_MOUNT_OPERATION)
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
static void
|
|
|
|
gtk_mount_operation_class_init (GtkMountOperationClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2009-02-19 15:15:49 +00:00
|
|
|
GMountOperationClass *mount_op_class = G_MOUNT_OPERATION_CLASS (klass);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
object_class->finalize = gtk_mount_operation_finalize;
|
|
|
|
object_class->get_property = gtk_mount_operation_get_property;
|
|
|
|
object_class->set_property = gtk_mount_operation_set_property;
|
|
|
|
|
|
|
|
mount_op_class->ask_password = gtk_mount_operation_ask_password;
|
|
|
|
mount_op_class->ask_question = gtk_mount_operation_ask_question;
|
2009-07-01 03:46:02 +00:00
|
|
|
mount_op_class->show_processes = gtk_mount_operation_show_processes;
|
2009-02-17 06:29:21 +00:00
|
|
|
mount_op_class->aborted = gtk_mount_operation_aborted;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2021-03-02 03:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkMountOperation:parent: (attributes org.gtk.Property.get=gtk_mount_operation_get_parent org.gtk.Property.set=gtk_mount_operation_set_parent)
|
|
|
|
*
|
|
|
|
* The parent window.
|
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_PARENT,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("parent", NULL, NULL,
|
2008-03-17 17:29:55 +00:00
|
|
|
GTK_TYPE_WINDOW,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2021-03-02 03:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkMountOperation:is-showing: (attributes org.gtk.Property.get=gtk_mount_operation_is_showing)
|
|
|
|
*
|
|
|
|
* Whether a dialog is currently shown.
|
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_IS_SHOWING,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("is-showing", NULL, NULL,
|
2008-03-17 17:29:55 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READABLE));
|
|
|
|
|
2021-03-02 03:52:20 +00:00
|
|
|
/**
|
|
|
|
* GtkMountOperation:display: (attributes org.gtk.Property.get=gtk_mount_operation_get_display org.gtk.Property.set=gtk_mount_operation_set_display)
|
|
|
|
*
|
|
|
|
* The display where dialogs will be shown.
|
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_class_install_property (object_class,
|
2017-10-31 06:51:15 +00:00
|
|
|
PROP_DISPLAY,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("display", NULL, NULL,
|
2017-10-31 06:51:15 +00:00
|
|
|
GDK_TYPE_DISPLAY,
|
2008-03-17 17:29:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2009-02-19 15:15:49 +00:00
|
|
|
}
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2009-02-19 15:15:49 +00:00
|
|
|
static void
|
|
|
|
gtk_mount_operation_init (GtkMountOperation *operation)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *name_owner;
|
2012-06-21 01:36:09 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
operation->priv = gtk_mount_operation_get_instance_private (operation);
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
operation->priv->handler =
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
|
|
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
|
|
"org.gtk.MountOperationHandler",
|
|
|
|
"/org/gtk/MountOperationHandler",
|
|
|
|
NULL, NULL);
|
2019-12-30 20:24:51 +00:00
|
|
|
if (!operation->priv->handler)
|
|
|
|
return;
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (operation->priv->handler));
|
|
|
|
if (!name_owner)
|
|
|
|
g_clear_object (&operation->priv->handler);
|
|
|
|
g_free (name_owner);
|
2012-09-18 17:44:04 +00:00
|
|
|
|
2012-09-18 17:48:07 +00:00
|
|
|
if (operation->priv->handler)
|
|
|
|
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (operation->priv->handler), G_MAXINT);
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 16:03:11 +00:00
|
|
|
static void
|
|
|
|
parent_destroyed (GtkWidget *parent,
|
|
|
|
gpointer **pointer)
|
|
|
|
{
|
|
|
|
*pointer = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-19 15:15:49 +00:00
|
|
|
static void
|
|
|
|
gtk_mount_operation_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
if (priv->user_widgets)
|
|
|
|
g_list_free (priv->user_widgets);
|
|
|
|
|
2009-02-19 15:15:49 +00:00
|
|
|
if (priv->parent_window)
|
2014-02-04 02:00:17 +00:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->parent_window,
|
2020-05-09 16:03:11 +00:00
|
|
|
parent_destroyed,
|
2014-02-04 02:00:17 +00:00
|
|
|
&priv->parent_window);
|
|
|
|
g_object_unref (priv->parent_window);
|
|
|
|
}
|
2009-02-19 15:15:49 +00:00
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
if (priv->display)
|
|
|
|
g_object_unref (priv->display);
|
2009-02-19 15:15:49 +00:00
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
if (priv->handler)
|
|
|
|
g_object_unref (priv->handler);
|
|
|
|
|
2009-02-19 15:15:49 +00:00
|
|
|
G_OBJECT_CLASS (gtk_mount_operation_parent_class)->finalize (object);
|
|
|
|
}
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
static void
|
2008-05-26 04:05:17 +00:00
|
|
|
gtk_mount_operation_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
2009-02-19 15:15:49 +00:00
|
|
|
GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2009-02-19 15:15:49 +00:00
|
|
|
case PROP_PARENT:
|
|
|
|
gtk_mount_operation_set_parent (operation, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
gtk_mount_operation_set_display (operation, g_value_get_object (value));
|
2009-02-19 15:15:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_IS_SHOWING:
|
|
|
|
default:
|
2008-03-17 17:29:55 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-05-26 04:05:17 +00:00
|
|
|
gtk_mount_operation_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
2009-02-19 15:15:49 +00:00
|
|
|
GtkMountOperation *operation = GTK_MOUNT_OPERATION (object);
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PARENT:
|
|
|
|
g_value_set_object (value, priv->parent_window);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_IS_SHOWING:
|
2012-06-21 01:36:09 +00:00
|
|
|
g_value_set_boolean (value, priv->dialog != NULL || priv->handler_showing);
|
2008-03-17 17:29:55 +00:00
|
|
|
break;
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, priv->display);
|
2008-03-17 17:29:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
static void
|
|
|
|
gtk_mount_operation_proxy_finish (GtkMountOperation *op,
|
|
|
|
GMountOperationResult result)
|
|
|
|
{
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_call_close (op->priv->handler, NULL, NULL, NULL);
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
op->priv->handler_showing = FALSE;
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
|
|
|
|
|
|
|
g_mount_operation_reply (G_MOUNT_OPERATION (op), result);
|
|
|
|
|
|
|
|
/* drop the reference acquired when calling the proxy method */
|
|
|
|
g_object_unref (op);
|
|
|
|
}
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
static void
|
2020-08-30 21:51:21 +00:00
|
|
|
remember_button_toggled (GtkCheckButton *button,
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkMountOperation *operation)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
if (gtk_check_button_get_active (button))
|
2008-12-02 09:06:35 +00:00
|
|
|
{
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
data = g_object_get_data (G_OBJECT (button), "password-save");
|
|
|
|
priv->password_save = GPOINTER_TO_INT (data);
|
|
|
|
}
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pw_dialog_got_response (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response_id,
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkMountOperation *mount_op)
|
|
|
|
{
|
2009-02-19 15:15:49 +00:00
|
|
|
GtkMountOperationPrivate *priv = mount_op->priv;
|
|
|
|
GMountOperation *op = G_MOUNT_OPERATION (mount_op);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED)
|
|
|
|
g_mount_operation_set_anonymous (op, priv->anonymous);
|
|
|
|
|
|
|
|
if (priv->username_entry)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (priv->username_entry));
|
2008-03-17 17:29:55 +00:00
|
|
|
g_mount_operation_set_username (op, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->domain_entry)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (priv->domain_entry));
|
2008-03-17 17:29:55 +00:00
|
|
|
g_mount_operation_set_domain (op, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->password_entry)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (priv->password_entry));
|
2008-03-17 17:29:55 +00:00
|
|
|
g_mount_operation_set_password (op, text);
|
|
|
|
}
|
|
|
|
|
2018-07-22 19:16:21 +00:00
|
|
|
if (priv->pim_entry)
|
|
|
|
{
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (priv->pim_entry));
|
|
|
|
if (text && strlen (text) > 0)
|
|
|
|
{
|
|
|
|
guint64 pim;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *end = NULL;
|
2018-07-22 19:16:21 +00:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
pim = g_ascii_strtoull (text, &end, 10);
|
|
|
|
if (errno == 0 && pim <= G_MAXUINT && end != text)
|
|
|
|
g_mount_operation_set_pim (op, (guint) pim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
if (priv->tcrypt_hidden_toggle && gtk_check_button_get_active (GTK_CHECK_BUTTON (priv->tcrypt_hidden_toggle)))
|
2018-07-22 19:16:21 +00:00
|
|
|
g_mount_operation_set_is_tcrypt_hidden_volume (op, TRUE);
|
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
if (priv->tcrypt_system_toggle && gtk_check_button_get_active (GTK_CHECK_BUTTON (priv->tcrypt_system_toggle)))
|
2018-07-22 19:16:21 +00:00
|
|
|
g_mount_operation_set_is_tcrypt_system_volume (op, TRUE);
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
|
|
|
|
g_mount_operation_set_password_save (op, priv->password_save);
|
|
|
|
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
|
|
|
|
|
|
|
|
priv->dialog = NULL;
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_unref (op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
entry_has_input (GtkWidget *entry_widget)
|
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
|
|
|
|
if (entry_widget == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry_widget));
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
return text != NULL && text[0] != '\0';
|
|
|
|
}
|
|
|
|
|
2018-07-22 19:16:21 +00:00
|
|
|
static gboolean
|
|
|
|
pim_entry_is_valid (GtkWidget *entry_widget)
|
|
|
|
{
|
|
|
|
const char *text;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *end = NULL;
|
2018-07-22 19:16:21 +00:00
|
|
|
guint64 pim;
|
|
|
|
|
|
|
|
if (entry_widget == NULL)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (entry_widget));
|
|
|
|
/* An empty PIM entry is OK */
|
|
|
|
if (text == NULL || text[0] == '\0')
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
pim = g_ascii_strtoull (text, &end, 10);
|
|
|
|
if (errno || pim > G_MAXUINT || end == text)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
static gboolean
|
|
|
|
pw_dialog_input_is_valid (GtkMountOperation *operation)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
|
|
|
gboolean is_valid = TRUE;
|
|
|
|
|
2009-04-08 14:02:52 +00:00
|
|
|
/* We don't require password to be non-empty here
|
|
|
|
* since there are situations where it is not needed,
|
|
|
|
* see bug 578365.
|
|
|
|
* We may add a way for the backend to specify that it
|
|
|
|
* definitively needs a password.
|
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
is_valid = entry_has_input (priv->username_entry) &&
|
2018-07-22 19:16:21 +00:00
|
|
|
entry_has_input (priv->domain_entry) &&
|
|
|
|
pim_entry_is_valid (priv->pim_entry);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pw_dialog_verify_input (GtkEditable *editable,
|
|
|
|
GtkMountOperation *operation)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
|
|
|
gboolean is_valid;
|
|
|
|
|
|
|
|
is_valid = pw_dialog_input_is_valid (operation);
|
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
is_valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pw_dialog_anonymous_toggled (GtkWidget *widget,
|
|
|
|
GtkMountOperation *operation)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv = operation->priv;
|
|
|
|
gboolean is_valid;
|
2012-08-23 16:04:23 +00:00
|
|
|
GList *l;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
priv->anonymous = widget == priv->anonymous_toggle;
|
|
|
|
|
|
|
|
if (priv->anonymous)
|
|
|
|
is_valid = TRUE;
|
|
|
|
else
|
|
|
|
is_valid = pw_dialog_input_is_valid (operation);
|
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
for (l = priv->user_widgets; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (l->data), !priv->anonymous);
|
|
|
|
}
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
|
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
is_valid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
pw_dialog_cycle_focus (GtkWidget *widget,
|
|
|
|
GtkMountOperation *operation)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkWidget *next_widget = NULL;
|
|
|
|
|
|
|
|
priv = operation->priv;
|
|
|
|
|
|
|
|
if (widget == priv->username_entry)
|
|
|
|
{
|
|
|
|
if (priv->domain_entry != NULL)
|
|
|
|
next_widget = priv->domain_entry;
|
|
|
|
else if (priv->password_entry != NULL)
|
|
|
|
next_widget = priv->password_entry;
|
|
|
|
}
|
|
|
|
else if (widget == priv->domain_entry && priv->password_entry)
|
|
|
|
next_widget = priv->password_entry;
|
|
|
|
|
|
|
|
if (next_widget)
|
|
|
|
gtk_widget_grab_focus (next_widget);
|
|
|
|
else if (pw_dialog_input_is_valid (operation))
|
2019-04-28 17:34:20 +00:00
|
|
|
gtk_widget_activate_default (widget);
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2012-08-23 16:04:23 +00:00
|
|
|
table_add_entry (GtkMountOperation *operation,
|
|
|
|
int row,
|
|
|
|
const char *label_text,
|
|
|
|
const char *value,
|
|
|
|
gpointer user_data)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new_with_mnemonic (label_text);
|
2012-08-23 16:04:23 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
2011-05-21 18:08:51 +00:00
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2012-08-23 16:04:23 +00:00
|
|
|
gtk_widget_set_hexpand (label, FALSE);
|
|
|
|
operation->priv->user_widgets = g_list_prepend (operation->priv->user_widgets, label);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
2012-08-23 16:04:23 +00:00
|
|
|
gtk_widget_set_hexpand (entry, TRUE);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
if (value)
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (entry), value);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
gtk_grid_attach (GTK_GRID (operation->priv->grid), label, 0, row, 1, 1);
|
|
|
|
gtk_grid_attach (GTK_GRID (operation->priv->grid), entry, 1, row, 1, 1);
|
2008-03-17 17:29:55 +00:00
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
|
2012-08-23 16:04:23 +00:00
|
|
|
operation->priv->user_widgets = g_list_prepend (operation->priv->user_widgets, entry);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
g_signal_connect (entry, "changed",
|
|
|
|
G_CALLBACK (pw_dialog_verify_input), user_data);
|
|
|
|
|
|
|
|
g_signal_connect (entry, "activate",
|
|
|
|
G_CALLBACK (pw_dialog_cycle_focus), user_data);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-21 01:36:09 +00:00
|
|
|
gtk_mount_operation_ask_password_do_gtk (GtkMountOperation *operation,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *message,
|
|
|
|
const char *default_user,
|
|
|
|
const char *default_domain)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkDialog *dialog;
|
|
|
|
GtkWindow *window;
|
2012-08-23 16:04:23 +00:00
|
|
|
GtkWidget *hbox, *main_vbox, *icon;
|
|
|
|
GtkWidget *grid;
|
|
|
|
GtkWidget *label;
|
2021-04-16 23:05:14 +00:00
|
|
|
GtkWidget *content_area;
|
2008-03-17 17:29:55 +00:00
|
|
|
gboolean can_anonymous;
|
|
|
|
guint rows;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *primary;
|
2020-08-07 07:38:37 +00:00
|
|
|
const char *secondary = NULL;
|
2014-01-15 11:23:38 +00:00
|
|
|
gboolean use_header;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
priv = operation->priv;
|
|
|
|
|
2014-01-15 11:23:38 +00:00
|
|
|
g_object_get (gtk_settings_get_default (),
|
|
|
|
"gtk-dialogs-use-header", &use_header,
|
|
|
|
NULL);
|
|
|
|
widget = g_object_new (GTK_TYPE_DIALOG,
|
|
|
|
"use-header-bar", use_header,
|
|
|
|
NULL);
|
2008-03-17 17:29:55 +00:00
|
|
|
dialog = GTK_DIALOG (widget);
|
|
|
|
window = GTK_WINDOW (widget);
|
|
|
|
|
|
|
|
priv->dialog = dialog;
|
|
|
|
|
2010-06-03 07:36:39 +00:00
|
|
|
content_area = gtk_dialog_get_content_area (dialog);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
gtk_window_set_resizable (window, FALSE);
|
2008-12-13 03:55:04 +00:00
|
|
|
gtk_window_set_title (window, "");
|
2013-06-24 23:28:53 +00:00
|
|
|
gtk_window_set_icon_name (window, "dialog-password");
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
gtk_dialog_add_buttons (dialog,
|
2013-06-24 23:28:53 +00:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
2008-03-17 17:29:55 +00:00
|
|
|
_("Co_nnect"), GTK_RESPONSE_OK,
|
|
|
|
NULL);
|
|
|
|
gtk_dialog_set_default_response (dialog, GTK_RESPONSE_OK);
|
2014-01-15 11:23:38 +00:00
|
|
|
|
2008-03-18 09:21:15 +00:00
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
/* Build contents */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
|
2021-04-16 23:05:14 +00:00
|
|
|
g_object_set (hbox,
|
|
|
|
"margin-start", 12,
|
|
|
|
"margin-end", 12,
|
|
|
|
"margin-top", 12,
|
|
|
|
"margin-bottom", 12,
|
|
|
|
NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (content_area), hbox);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2017-11-15 00:43:13 +00:00
|
|
|
icon = gtk_image_new_from_icon_name ("dialog-password");
|
2017-11-15 02:14:47 +00:00
|
|
|
gtk_image_set_icon_size (GTK_IMAGE (icon), GTK_ICON_SIZE_LARGE);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2011-05-21 18:08:51 +00:00
|
|
|
gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (icon, GTK_ALIGN_START);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), icon);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), main_vbox);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2020-08-07 07:38:37 +00:00
|
|
|
primary = strstr (message, "\n");
|
|
|
|
if (primary)
|
2009-02-27 21:03:47 +00:00
|
|
|
{
|
2020-08-07 07:38:37 +00:00
|
|
|
secondary = primary + 1;
|
|
|
|
primary = g_strndup (message, primary - message);
|
2012-08-23 16:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 07:38:37 +00:00
|
|
|
label = gtk_label_new (primary != NULL ? primary : message);
|
2012-08-23 16:04:23 +00:00
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (main_vbox), GTK_WIDGET (label));
|
2012-08-23 16:04:23 +00:00
|
|
|
g_free (primary);
|
2021-04-16 23:05:14 +00:00
|
|
|
gtk_widget_add_css_class (label, "title-3");
|
2012-08-23 16:04:23 +00:00
|
|
|
|
|
|
|
if (secondary != NULL)
|
|
|
|
{
|
|
|
|
label = gtk_label_new (secondary);
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
2019-08-22 10:41:39 +00:00
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (main_vbox), GTK_WIDGET (label));
|
2009-02-27 21:03:47 +00:00
|
|
|
}
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
grid = gtk_grid_new ();
|
|
|
|
operation->priv->grid = grid;
|
|
|
|
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
|
|
|
|
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
|
|
|
|
gtk_widget_set_margin_bottom (grid, 12);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (main_vbox), grid);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
can_anonymous = priv->ask_flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
rows = 0;
|
|
|
|
|
2009-03-10 10:29:03 +00:00
|
|
|
priv->anonymous_toggle = NULL;
|
2008-03-17 17:29:55 +00:00
|
|
|
if (can_anonymous)
|
|
|
|
{
|
|
|
|
GtkWidget *anon_box;
|
|
|
|
GtkWidget *choice;
|
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
label = gtk_label_new (_("Connect As"));
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_hexpand (label, FALSE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, rows, 1, 1);
|
|
|
|
|
|
|
|
anon_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), anon_box, 1, rows++, 1, 1);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
choice = gtk_check_button_new_with_mnemonic (_("_Anonymous"));
|
|
|
|
gtk_box_append (GTK_BOX (anon_box), choice);
|
2008-03-17 17:29:55 +00:00
|
|
|
g_signal_connect (choice, "toggled",
|
|
|
|
G_CALLBACK (pw_dialog_anonymous_toggled), operation);
|
|
|
|
priv->anonymous_toggle = choice;
|
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
choice = gtk_check_button_new_with_mnemonic (_("Registered U_ser"));
|
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (choice), GTK_CHECK_BUTTON (priv->anonymous_toggle));
|
|
|
|
gtk_box_append (GTK_BOX (anon_box), choice);
|
2008-03-17 17:29:55 +00:00
|
|
|
g_signal_connect (choice, "toggled",
|
|
|
|
G_CALLBACK (pw_dialog_anonymous_toggled), operation);
|
|
|
|
}
|
|
|
|
|
2009-03-10 10:29:03 +00:00
|
|
|
priv->username_entry = NULL;
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_NEED_USERNAME)
|
2012-08-23 16:04:23 +00:00
|
|
|
priv->username_entry = table_add_entry (operation, rows++, _("_Username"),
|
2008-03-17 17:29:55 +00:00
|
|
|
default_user, operation);
|
|
|
|
|
2009-03-10 10:29:03 +00:00
|
|
|
priv->domain_entry = NULL;
|
2012-06-21 01:36:09 +00:00
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_NEED_DOMAIN)
|
2012-08-23 16:04:23 +00:00
|
|
|
priv->domain_entry = table_add_entry (operation, rows++, _("_Domain"),
|
2008-03-17 17:29:55 +00:00
|
|
|
default_domain, operation);
|
|
|
|
|
2018-07-22 19:16:21 +00:00
|
|
|
priv->pim_entry = NULL;
|
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_TCRYPT)
|
|
|
|
{
|
|
|
|
GtkWidget *volume_type_label;
|
|
|
|
GtkWidget *volume_type_box;
|
|
|
|
|
|
|
|
volume_type_label = gtk_label_new (_("Volume type"));
|
|
|
|
gtk_widget_set_halign (volume_type_label, GTK_ALIGN_END);
|
|
|
|
gtk_widget_set_hexpand (volume_type_label, FALSE);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), volume_type_label, 0, rows, 1, 1);
|
|
|
|
priv->user_widgets = g_list_prepend (priv->user_widgets, volume_type_label);
|
|
|
|
|
|
|
|
volume_type_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), volume_type_box, 1, rows++, 1, 1);
|
|
|
|
priv->user_widgets = g_list_prepend (priv->user_widgets, volume_type_box);
|
|
|
|
|
|
|
|
priv->tcrypt_hidden_toggle = gtk_check_button_new_with_mnemonic (_("_Hidden"));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (volume_type_box), priv->tcrypt_hidden_toggle);
|
2018-07-22 19:16:21 +00:00
|
|
|
|
|
|
|
priv->tcrypt_system_toggle = gtk_check_button_new_with_mnemonic (_("_Windows system"));
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (volume_type_box), priv->tcrypt_system_toggle);
|
2018-07-22 19:16:21 +00:00
|
|
|
|
|
|
|
priv->pim_entry = table_add_entry (operation, rows++, _("_PIM"), NULL, operation);
|
|
|
|
}
|
|
|
|
|
2009-03-10 10:29:03 +00:00
|
|
|
priv->password_entry = NULL;
|
2012-06-21 01:36:09 +00:00
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_NEED_PASSWORD)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
2012-08-23 16:04:23 +00:00
|
|
|
priv->password_entry = table_add_entry (operation, rows++, _("_Password"),
|
2008-03-17 17:29:55 +00:00
|
|
|
NULL, operation);
|
|
|
|
gtk_entry_set_visibility (GTK_ENTRY (priv->password_entry), FALSE);
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
if (priv->ask_flags & G_ASK_PASSWORD_SAVING_SUPPORTED)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
2008-12-02 09:06:35 +00:00
|
|
|
GtkWidget *remember_box;
|
2012-08-23 16:04:23 +00:00
|
|
|
GtkWidget *choice;
|
2020-08-30 21:51:21 +00:00
|
|
|
GtkWidget *group;
|
2008-12-02 09:06:35 +00:00
|
|
|
GPasswordSave password_save;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-08-23 16:04:23 +00:00
|
|
|
remember_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), remember_box, 0, rows++, 2, 1);
|
|
|
|
priv->user_widgets = g_list_prepend (priv->user_widgets, remember_box);
|
|
|
|
|
|
|
|
label = gtk_label_new ("");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (remember_box), label);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
password_save = g_mount_operation_get_password_save (G_MOUNT_OPERATION (operation));
|
2012-08-20 15:06:14 +00:00
|
|
|
priv->password_save = password_save;
|
2012-08-23 16:04:23 +00:00
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
choice = gtk_check_button_new_with_mnemonic (_("Forget password _immediately"));
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
|
|
|
|
password_save == G_PASSWORD_SAVE_NEVER);
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_set_data (G_OBJECT (choice), "password-save",
|
|
|
|
GINT_TO_POINTER (G_PASSWORD_SAVE_NEVER));
|
|
|
|
g_signal_connect (choice, "toggled",
|
|
|
|
G_CALLBACK (remember_button_toggled), operation);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (remember_box), choice);
|
2020-08-30 21:51:21 +00:00
|
|
|
group = choice;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
choice = gtk_check_button_new_with_mnemonic (_("Remember password until you _logout"));
|
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (choice), GTK_CHECK_BUTTON (group));
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
|
|
|
|
password_save == G_PASSWORD_SAVE_FOR_SESSION);
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_set_data (G_OBJECT (choice), "password-save",
|
|
|
|
GINT_TO_POINTER (G_PASSWORD_SAVE_FOR_SESSION));
|
|
|
|
g_signal_connect (choice, "toggled",
|
|
|
|
G_CALLBACK (remember_button_toggled), operation);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (remember_box), choice);
|
2020-08-30 21:51:21 +00:00
|
|
|
group = choice;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2020-08-30 21:51:21 +00:00
|
|
|
choice = gtk_check_button_new_with_mnemonic (_("Remember _forever"));
|
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (choice), GTK_CHECK_BUTTON (group));
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
|
|
|
|
password_save == G_PASSWORD_SAVE_PERMANENTLY);
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_set_data (G_OBJECT (choice), "password-save",
|
|
|
|
GINT_TO_POINTER (G_PASSWORD_SAVE_PERMANENTLY));
|
|
|
|
g_signal_connect (choice, "toggled",
|
|
|
|
G_CALLBACK (remember_button_toggled), operation);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (remember_box), choice);
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog), "response",
|
|
|
|
G_CALLBACK (pw_dialog_got_response), operation);
|
|
|
|
|
|
|
|
if (can_anonymous)
|
2008-05-27 00:12:33 +00:00
|
|
|
{
|
|
|
|
/* The anonymous option will be active by default,
|
|
|
|
* ensure the toggled signal is emitted for it.
|
|
|
|
*/
|
2020-08-30 21:51:21 +00:00
|
|
|
g_signal_emit_by_name (priv->anonymous_toggle, "toggled");
|
2008-05-27 00:12:33 +00:00
|
|
|
}
|
2008-03-17 17:29:55 +00:00
|
|
|
else if (! pw_dialog_input_is_valid (operation))
|
|
|
|
gtk_dialog_set_response_sensitive (dialog, GTK_RESPONSE_OK, FALSE);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
|
|
|
|
2008-05-27 00:08:00 +00:00
|
|
|
if (priv->parent_window)
|
|
|
|
{
|
|
|
|
gtk_window_set_transient_for (window, priv->parent_window);
|
|
|
|
gtk_window_set_modal (window, TRUE);
|
|
|
|
}
|
2017-10-31 06:51:15 +00:00
|
|
|
else if (priv->display)
|
|
|
|
gtk_window_set_display (GTK_WINDOW (dialog), priv->display);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (GTK_WIDGET (dialog));
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
g_object_ref (operation);
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
static void
|
|
|
|
call_password_proxy_cb (GObject *source,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-06-25 20:26:41 +00:00
|
|
|
_GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
|
2012-06-21 01:36:09 +00:00
|
|
|
GMountOperation *op = user_data;
|
|
|
|
GMountOperationResult result;
|
|
|
|
GVariant *result_details;
|
|
|
|
GVariantIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *key;
|
2012-06-21 01:36:09 +00:00
|
|
|
GVariant *value;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
if (!_gtk_mount_operation_handler_call_ask_password_finish (proxy,
|
|
|
|
&result,
|
|
|
|
&result_details,
|
|
|
|
res,
|
|
|
|
&error))
|
2012-06-21 01:36:09 +00:00
|
|
|
{
|
|
|
|
result = G_MOUNT_OPERATION_ABORTED;
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Shell mount operation error: %s", error->message);
|
2012-06-21 01:36:09 +00:00
|
|
|
g_error_free (error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, result_details);
|
|
|
|
while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
|
|
|
|
{
|
|
|
|
if (strcmp (key, "password") == 0)
|
|
|
|
g_mount_operation_set_password (op, g_variant_get_string (value, NULL));
|
|
|
|
else if (strcmp (key, "password_save") == 0)
|
|
|
|
g_mount_operation_set_password_save (op, g_variant_get_uint32 (value));
|
2018-07-09 19:13:50 +00:00
|
|
|
else if (strcmp (key, "hidden_volume") == 0)
|
|
|
|
g_mount_operation_set_is_tcrypt_hidden_volume (op, g_variant_get_boolean (value));
|
|
|
|
else if (strcmp (key, "system_volume") == 0)
|
|
|
|
g_mount_operation_set_is_tcrypt_system_volume (op, g_variant_get_boolean (value));
|
|
|
|
else if (strcmp (key, "pim") == 0)
|
|
|
|
g_mount_operation_set_pim (op, g_variant_get_uint32 (value));
|
2012-06-21 01:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_ask_password_do_proxy (GtkMountOperation *operation,
|
|
|
|
const char *message,
|
|
|
|
const char *default_user,
|
|
|
|
const char *default_domain)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char id[255];
|
2012-06-21 01:36:09 +00:00
|
|
|
g_sprintf(id, "GtkMountOperation%p", operation);
|
|
|
|
|
|
|
|
operation->priv->handler_showing = TRUE;
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
|
|
|
|
|
|
|
/* keep a ref to the operation while the handler is showing */
|
|
|
|
g_object_ref (operation);
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_call_ask_password (operation->priv->handler, id,
|
|
|
|
message, "drive-harddisk",
|
|
|
|
default_user, default_domain,
|
|
|
|
operation->priv->ask_flags, NULL,
|
|
|
|
call_password_proxy_cb, operation);
|
2012-06-21 01:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_ask_password (GMountOperation *mount_op,
|
|
|
|
const char *message,
|
|
|
|
const char *default_user,
|
|
|
|
const char *default_domain,
|
|
|
|
GAskPasswordFlags flags)
|
|
|
|
{
|
|
|
|
GtkMountOperation *operation;
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
gboolean use_gtk;
|
|
|
|
|
|
|
|
operation = GTK_MOUNT_OPERATION (mount_op);
|
|
|
|
priv = operation->priv;
|
|
|
|
priv->ask_flags = flags;
|
|
|
|
|
|
|
|
use_gtk = (operation->priv->handler == NULL) ||
|
|
|
|
(priv->ask_flags & G_ASK_PASSWORD_NEED_DOMAIN) ||
|
|
|
|
(priv->ask_flags & G_ASK_PASSWORD_NEED_USERNAME);
|
|
|
|
|
|
|
|
if (use_gtk)
|
|
|
|
gtk_mount_operation_ask_password_do_gtk (operation, message, default_user, default_domain);
|
|
|
|
else
|
|
|
|
gtk_mount_operation_ask_password_do_proxy (operation, message, default_user, default_domain);
|
|
|
|
}
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
static void
|
|
|
|
question_dialog_button_clicked (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int button_number,
|
2008-03-17 17:29:55 +00:00
|
|
|
GMountOperation *op)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkMountOperation *operation;
|
|
|
|
|
|
|
|
operation = GTK_MOUNT_OPERATION (op);
|
|
|
|
priv = operation->priv;
|
|
|
|
|
|
|
|
if (button_number >= 0)
|
|
|
|
{
|
|
|
|
g_mount_operation_set_choice (op, button_number);
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
|
2008-03-18 09:21:15 +00:00
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
priv->dialog = NULL;
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_unref (op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-21 01:36:09 +00:00
|
|
|
gtk_mount_operation_ask_question_do_gtk (GtkMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
const char *choices[])
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
const char *secondary = NULL;
|
|
|
|
char *primary;
|
|
|
|
int count, len = 0;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
|
|
|
|
g_return_if_fail (message != NULL);
|
|
|
|
g_return_if_fail (choices != NULL);
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
priv = op->priv;
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
primary = strstr (message, "\n");
|
|
|
|
if (primary)
|
|
|
|
{
|
|
|
|
secondary = primary + 1;
|
|
|
|
primary = g_strndup (message, primary - message);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog = gtk_message_dialog_new (priv->parent_window, 0,
|
|
|
|
GTK_MESSAGE_QUESTION,
|
|
|
|
GTK_BUTTONS_NONE, "%s",
|
|
|
|
primary != NULL ? primary : message);
|
|
|
|
g_free (primary);
|
|
|
|
|
|
|
|
if (secondary)
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
"%s", secondary);
|
|
|
|
|
|
|
|
/* First count the items in the list then
|
|
|
|
* add the buttons in reverse order */
|
|
|
|
|
|
|
|
while (choices[len] != NULL)
|
|
|
|
len++;
|
|
|
|
|
|
|
|
for (count = len - 1; count >= 0; count--)
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog), "response",
|
|
|
|
G_CALLBACK (question_dialog_button_clicked), op);
|
|
|
|
|
|
|
|
priv->dialog = GTK_DIALOG (dialog);
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
if (priv->parent_window == NULL && priv->display)
|
|
|
|
gtk_window_set_display (GTK_WINDOW (dialog), priv->display);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
g_object_ref (op);
|
|
|
|
}
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
static void
|
|
|
|
call_question_proxy_cb (GObject *source,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-06-25 20:26:41 +00:00
|
|
|
_GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
|
2012-06-21 01:36:09 +00:00
|
|
|
GMountOperation *op = user_data;
|
|
|
|
GMountOperationResult result;
|
|
|
|
GVariant *result_details;
|
|
|
|
GVariantIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *key;
|
2012-06-21 01:36:09 +00:00
|
|
|
GVariant *value;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
if (!_gtk_mount_operation_handler_call_ask_question_finish (proxy,
|
|
|
|
&result,
|
|
|
|
&result_details,
|
|
|
|
res,
|
|
|
|
&error))
|
2012-06-21 01:36:09 +00:00
|
|
|
{
|
|
|
|
result = G_MOUNT_OPERATION_ABORTED;
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Shell mount operation error: %s", error->message);
|
2012-06-21 01:36:09 +00:00
|
|
|
g_error_free (error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, result_details);
|
|
|
|
while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
|
|
|
|
{
|
|
|
|
if (strcmp (key, "choice") == 0)
|
|
|
|
g_mount_operation_set_choice (op, g_variant_get_int32 (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_ask_question_do_proxy (GtkMountOperation *operation,
|
|
|
|
const char *message,
|
|
|
|
const char *choices[])
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char id[255];
|
2012-06-21 01:36:09 +00:00
|
|
|
g_sprintf(id, "GtkMountOperation%p", operation);
|
|
|
|
|
|
|
|
operation->priv->handler_showing = TRUE;
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
|
|
|
|
|
|
|
/* keep a ref to the operation while the handler is showing */
|
|
|
|
g_object_ref (operation);
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_call_ask_question (operation->priv->handler, id,
|
|
|
|
message, "drive-harddisk",
|
|
|
|
choices, NULL,
|
|
|
|
call_question_proxy_cb, operation);
|
2012-06-21 01:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_ask_question (GMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
const char *choices[])
|
|
|
|
{
|
|
|
|
GtkMountOperation *operation;
|
|
|
|
gboolean use_gtk;
|
|
|
|
|
|
|
|
operation = GTK_MOUNT_OPERATION (op);
|
|
|
|
use_gtk = (operation->priv->handler == NULL);
|
|
|
|
|
|
|
|
if (use_gtk)
|
|
|
|
gtk_mount_operation_ask_question_do_gtk (operation, message, choices);
|
|
|
|
else
|
|
|
|
gtk_mount_operation_ask_question_do_proxy (operation, message, choices);
|
|
|
|
}
|
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
static void
|
|
|
|
show_processes_button_clicked (GtkDialog *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int button_number,
|
2009-07-01 03:46:02 +00:00
|
|
|
GMountOperation *op)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkMountOperation *operation;
|
|
|
|
|
|
|
|
operation = GTK_MOUNT_OPERATION (op);
|
|
|
|
priv = operation->priv;
|
|
|
|
|
|
|
|
if (button_number >= 0)
|
|
|
|
{
|
|
|
|
g_mount_operation_set_choice (op, button_number);
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED);
|
|
|
|
|
|
|
|
priv->dialog = NULL;
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2009-07-01 03:46:02 +00:00
|
|
|
g_object_unref (op);
|
|
|
|
}
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
static int
|
2009-07-01 03:46:02 +00:00
|
|
|
pid_equal (gconstpointer a,
|
|
|
|
gconstpointer b)
|
|
|
|
{
|
|
|
|
GPid pa, pb;
|
|
|
|
|
|
|
|
pa = *((GPid *) a);
|
|
|
|
pb = *((GPid *) b);
|
|
|
|
|
2009-07-12 16:00:40 +00:00
|
|
|
return GPOINTER_TO_INT(pb) - GPOINTER_TO_INT(pa);
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
diff_sorted_arrays (GArray *array1,
|
|
|
|
GArray *array2,
|
|
|
|
GCompareFunc compare,
|
|
|
|
GArray *added_indices,
|
|
|
|
GArray *removed_indices)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int order;
|
2009-07-01 03:46:02 +00:00
|
|
|
guint n1, n2;
|
|
|
|
guint elem_size;
|
|
|
|
|
|
|
|
n1 = n2 = 0;
|
|
|
|
|
|
|
|
elem_size = g_array_get_element_size (array1);
|
|
|
|
g_assert (elem_size == g_array_get_element_size (array2));
|
|
|
|
|
|
|
|
while (n1 < array1->len && n2 < array2->len)
|
|
|
|
{
|
2009-07-12 16:00:40 +00:00
|
|
|
order = (*compare) (((const char*) array1->data) + n1 * elem_size,
|
|
|
|
((const char*) array2->data) + n2 * elem_size);
|
2009-07-01 03:46:02 +00:00
|
|
|
if (order < 0)
|
|
|
|
{
|
|
|
|
g_array_append_val (removed_indices, n1);
|
|
|
|
n1++;
|
|
|
|
}
|
|
|
|
else if (order > 0)
|
|
|
|
{
|
|
|
|
g_array_append_val (added_indices, n2);
|
|
|
|
n2++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* same item */
|
|
|
|
n1++;
|
|
|
|
n2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (n1 < array1->len)
|
|
|
|
{
|
|
|
|
g_array_append_val (removed_indices, n1);
|
|
|
|
n1++;
|
|
|
|
}
|
|
|
|
while (n2 < array2->len)
|
|
|
|
{
|
|
|
|
g_array_append_val (added_indices, n2);
|
|
|
|
n2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-06 16:10:13 +00:00
|
|
|
static GdkTexture *
|
|
|
|
render_paintable_to_texture (GdkPaintable *paintable)
|
|
|
|
{
|
|
|
|
GtkSnapshot *snapshot;
|
|
|
|
GskRenderNode *node;
|
|
|
|
int width, height;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
GdkTexture *texture;
|
|
|
|
|
|
|
|
width = gdk_paintable_get_intrinsic_width (paintable);
|
|
|
|
height = gdk_paintable_get_intrinsic_height (paintable);
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
|
|
|
|
|
|
|
|
snapshot = gtk_snapshot_new ();
|
|
|
|
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
|
|
|
node = gtk_snapshot_free_to_node (snapshot);
|
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
gsk_render_node_draw (node, cr);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
|
|
|
texture = gdk_texture_new_for_surface (surface);
|
|
|
|
cairo_surface_destroy (surface);
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
add_pid_to_process_list_store (GtkMountOperation *mount_operation,
|
|
|
|
GtkMountOperationLookupContext *lookup_context,
|
|
|
|
GtkListStore *list_store,
|
|
|
|
GPid pid)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *command_line;
|
|
|
|
char *name;
|
2017-11-30 21:39:14 +00:00
|
|
|
GdkTexture *texture;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *markup;
|
2009-07-01 03:46:02 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
name = NULL;
|
2017-11-30 21:39:14 +00:00
|
|
|
texture = NULL;
|
2009-07-01 03:46:02 +00:00
|
|
|
command_line = NULL;
|
|
|
|
_gtk_mount_operation_lookup_info (lookup_context,
|
|
|
|
pid,
|
|
|
|
24,
|
|
|
|
&name,
|
|
|
|
&command_line,
|
2017-11-30 21:39:14 +00:00
|
|
|
&texture);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (name == NULL)
|
2016-02-06 02:58:39 +00:00
|
|
|
name = g_strdup_printf (_("Unknown Application (PID %d)"), (int) (gssize) pid);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (command_line == NULL)
|
|
|
|
command_line = g_strdup ("");
|
|
|
|
|
2017-11-30 21:39:14 +00:00
|
|
|
if (texture == NULL)
|
2009-07-01 03:46:02 +00:00
|
|
|
{
|
|
|
|
GtkIconTheme *theme;
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
2017-11-30 21:39:14 +00:00
|
|
|
|
2020-04-21 12:37:04 +00:00
|
|
|
theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (mount_operation->priv->dialog)));
|
2020-02-01 23:27:14 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (theme,
|
|
|
|
"application-x-executable",
|
2020-02-04 02:53:22 +00:00
|
|
|
NULL,
|
2020-02-01 23:27:14 +00:00
|
|
|
24, 1,
|
|
|
|
gtk_widget_get_direction (GTK_WIDGET (mount_operation->priv->dialog)),
|
|
|
|
0);
|
2020-02-06 16:10:13 +00:00
|
|
|
texture = render_paintable_to_texture (GDK_PAINTABLE (icon));
|
2020-01-30 09:52:09 +00:00
|
|
|
g_object_unref (icon);
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
markup = g_strdup_printf ("<b>%s</b>\n"
|
|
|
|
"<small>%s</small>",
|
|
|
|
name,
|
|
|
|
command_line);
|
|
|
|
|
|
|
|
gtk_list_store_append (list_store, &iter);
|
|
|
|
gtk_list_store_set (list_store, &iter,
|
2017-11-30 21:39:14 +00:00
|
|
|
0, texture,
|
2009-07-01 03:46:02 +00:00
|
|
|
1, markup,
|
|
|
|
2, pid,
|
|
|
|
-1);
|
|
|
|
|
2017-11-30 21:39:14 +00:00
|
|
|
if (texture != NULL)
|
|
|
|
g_object_unref (texture);
|
2009-07-01 03:46:02 +00:00
|
|
|
g_free (markup);
|
|
|
|
g_free (name);
|
|
|
|
g_free (command_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_pid_from_process_list_store (GtkMountOperation *mount_operation,
|
|
|
|
GtkListStore *list_store,
|
|
|
|
GPid pid)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GPid pid_of_item;
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (list_store),
|
|
|
|
&iter,
|
|
|
|
2, &pid_of_item,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (pid_of_item == pid)
|
|
|
|
{
|
|
|
|
gtk_list_store_remove (list_store, &iter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_process_list_store (GtkMountOperation *mount_operation,
|
|
|
|
GtkListStore *list_store,
|
|
|
|
GArray *processes)
|
|
|
|
{
|
|
|
|
guint n;
|
|
|
|
GtkMountOperationLookupContext *lookup_context;
|
|
|
|
GArray *current_pids;
|
|
|
|
GArray *pid_indices_to_add;
|
|
|
|
GArray *pid_indices_to_remove;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GPid pid;
|
|
|
|
|
|
|
|
/* Just removing all items and adding new ones will screw up the
|
|
|
|
* focus handling in the treeview - so compute the delta, and add/remove
|
|
|
|
* items as appropriate
|
|
|
|
*/
|
|
|
|
current_pids = g_array_new (FALSE, FALSE, sizeof (GPid));
|
2020-07-24 13:54:49 +00:00
|
|
|
pid_indices_to_add = g_array_new (FALSE, FALSE, sizeof (int));
|
|
|
|
pid_indices_to_remove = g_array_new (FALSE, FALSE, sizeof (int));
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (list_store),
|
|
|
|
&iter,
|
|
|
|
2, &pid,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_array_append_val (current_pids, pid);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (list_store), &iter));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_sort (current_pids, pid_equal);
|
|
|
|
g_array_sort (processes, pid_equal);
|
|
|
|
|
|
|
|
diff_sorted_arrays (current_pids, processes, pid_equal, pid_indices_to_add, pid_indices_to_remove);
|
|
|
|
|
|
|
|
for (n = 0; n < pid_indices_to_remove->len; n++)
|
|
|
|
{
|
|
|
|
pid = g_array_index (current_pids, GPid, n);
|
|
|
|
remove_pid_from_process_list_store (mount_operation, list_store, pid);
|
|
|
|
}
|
2009-10-20 02:08:00 +00:00
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
if (pid_indices_to_add->len > 0)
|
2009-10-20 02:08:00 +00:00
|
|
|
{
|
|
|
|
lookup_context = _gtk_mount_operation_lookup_context_get (gtk_widget_get_display (mount_operation->priv->process_tree_view));
|
|
|
|
for (n = 0; n < pid_indices_to_add->len; n++)
|
|
|
|
{
|
|
|
|
pid = g_array_index (processes, GPid, n);
|
|
|
|
add_pid_to_process_list_store (mount_operation, lookup_context, list_store, pid);
|
|
|
|
}
|
|
|
|
_gtk_mount_operation_lookup_context_free (lookup_context);
|
|
|
|
}
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
/* select the first item, if we went from a zero to a non-zero amount of processes */
|
|
|
|
if (current_pids->len == 0 && pid_indices_to_add->len > 0)
|
|
|
|
{
|
|
|
|
if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
|
|
|
|
{
|
|
|
|
GtkTreeSelection *tree_selection;
|
|
|
|
tree_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (mount_operation->priv->process_tree_view));
|
|
|
|
gtk_tree_selection_select_iter (tree_selection, &iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_unref (current_pids);
|
|
|
|
g_array_unref (pid_indices_to_add);
|
|
|
|
g_array_unref (pid_indices_to_remove);
|
|
|
|
}
|
|
|
|
|
2020-04-30 12:43:17 +00:00
|
|
|
static void
|
|
|
|
on_dialog_response (GtkDialog *dialog,
|
|
|
|
int response)
|
|
|
|
{
|
|
|
|
/* GTK_RESPONSE_NONE means the dialog were programmatically destroy, e.g. that
|
|
|
|
* GTK_DIALOG_DESTROY_WITH_PARENT kicked in - so it would trigger a warning to
|
|
|
|
* destroy the dialog in that case
|
|
|
|
*/
|
|
|
|
if (response != GTK_RESPONSE_NONE)
|
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
static void
|
2019-12-26 18:09:04 +00:00
|
|
|
on_end_process_activated (GtkModelButton *button,
|
2009-07-01 03:46:02 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GPid pid_to_kill;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
|
|
|
|
|
|
|
|
if (!gtk_tree_selection_get_selected (selection,
|
|
|
|
NULL,
|
|
|
|
&iter))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (op->priv->process_list_store),
|
|
|
|
&iter,
|
|
|
|
2, &pid_to_kill,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
/* TODO: We might want to either
|
|
|
|
*
|
|
|
|
* - Be smart about things and send SIGKILL rather than SIGTERM if
|
|
|
|
* this is the second time the user requests killing a process
|
|
|
|
*
|
|
|
|
* - Or, easier (but worse user experience), offer both "End Process"
|
|
|
|
* and "Terminate Process" options
|
|
|
|
*
|
|
|
|
* But that's not how things work right now....
|
|
|
|
*/
|
|
|
|
error = NULL;
|
|
|
|
if (!_gtk_mount_operation_kill_process (pid_to_kill, &error))
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
/* Use GTK_DIALOG_DESTROY_WITH_PARENT here since the parent dialog can be
|
|
|
|
* indeed be destroyed via the GMountOperation::abort signal... for example,
|
|
|
|
* this is triggered if the user yanks the device while we are showing
|
|
|
|
* the dialog...
|
|
|
|
*/
|
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (op->priv->dialog),
|
|
|
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_ERROR,
|
|
|
|
GTK_BUTTONS_CLOSE,
|
|
|
|
_("Unable to end process"));
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
"%s",
|
|
|
|
error->message);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (dialog);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2020-04-30 12:43:17 +00:00
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (on_dialog_response), NULL);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
do_popup_menu_for_process_tree_view (GtkWidget *widget,
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event,
|
2009-07-01 03:46:02 +00:00
|
|
|
GtkMountOperation *op)
|
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *item;
|
2019-12-26 18:09:04 +00:00
|
|
|
double x, y;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
menu = gtk_popover_new ();
|
|
|
|
gtk_widget_set_parent (menu, widget);
|
2020-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (menu, "context-menu");
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2019-12-26 18:09:04 +00:00
|
|
|
item = gtk_model_button_new ();
|
|
|
|
g_object_set (item, "text", _("_End Process"), NULL);
|
|
|
|
g_signal_connect (item, "clicked",
|
2009-07-01 03:46:02 +00:00
|
|
|
G_CALLBACK (on_end_process_activated),
|
|
|
|
op);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (menu), item);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
if (event && gdk_event_triggers_context_menu (event))
|
2009-07-01 03:46:02 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
gdk_event_get_position (event, &x, &y);
|
2009-07-01 03:46:02 +00:00
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (op->priv->process_tree_view),
|
2020-07-24 13:54:49 +00:00
|
|
|
(int) x,
|
|
|
|
(int) y,
|
2009-07-01 03:46:02 +00:00
|
|
|
&path,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (op->priv->process_tree_view));
|
|
|
|
gtk_tree_selection_select_path (selection, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* don't popup a menu if the user right-clicked in an area with no rows */
|
2016-07-12 18:08:36 +00:00
|
|
|
return FALSE;
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
2019-12-26 18:09:04 +00:00
|
|
|
|
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (menu), &(GdkRectangle){ x, y, 1, 1});
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 18:09:04 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (menu));
|
2016-07-12 18:08:36 +00:00
|
|
|
return TRUE;
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
on_popup_menu_for_process_tree_view (GtkWidget *widget,
|
2020-03-19 02:56:53 +00:00
|
|
|
GVariant *args,
|
2009-07-01 03:46:02 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
|
|
|
|
return do_popup_menu_for_process_tree_view (widget, NULL, op);
|
|
|
|
}
|
|
|
|
|
2018-01-15 21:43:54 +00:00
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
click_cb (GtkGesture *gesture,
|
2018-01-15 21:43:54 +00:00
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer user_data)
|
2009-07-01 03:46:02 +00:00
|
|
|
{
|
|
|
|
GtkMountOperation *op = GTK_MOUNT_OPERATION (user_data);
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event;
|
2018-01-15 21:43:54 +00:00
|
|
|
GdkEventSequence *sequence;
|
|
|
|
GtkWidget *widget;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2018-01-15 21:43:54 +00:00
|
|
|
sequence = gtk_gesture_get_last_updated_sequence (gesture);
|
|
|
|
event = gtk_gesture_get_last_event (gesture, sequence);
|
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
do_popup_menu_for_process_tree_view (widget, event, op);
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 18:09:56 +00:00
|
|
|
static GtkWidget *
|
2012-06-21 01:36:09 +00:00
|
|
|
create_show_processes_dialog (GtkMountOperation *op,
|
2009-07-01 03:46:02 +00:00
|
|
|
const char *message,
|
|
|
|
const char *choices[])
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
const char *secondary = NULL;
|
|
|
|
char *primary;
|
|
|
|
int count, len = 0;
|
|
|
|
GtkWidget *label;
|
|
|
|
GtkWidget *tree_view;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *content_area;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkListStore *list_store;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *s;
|
2014-01-15 11:23:38 +00:00
|
|
|
gboolean use_header;
|
2018-03-09 05:14:59 +00:00
|
|
|
GtkGesture *gesture;
|
2020-03-19 02:56:53 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
GtkShortcutTrigger *trigger;
|
|
|
|
GtkShortcutAction *action;
|
|
|
|
GtkShortcut *shortcut;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
priv = op->priv;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
primary = strstr (message, "\n");
|
|
|
|
if (primary)
|
|
|
|
{
|
|
|
|
secondary = primary + 1;
|
|
|
|
primary = g_strndup (message, primary - message);
|
|
|
|
}
|
|
|
|
|
2014-01-15 11:23:38 +00:00
|
|
|
g_object_get (gtk_settings_get_default (),
|
|
|
|
"gtk-dialogs-use-header", &use_header,
|
|
|
|
NULL);
|
|
|
|
dialog = g_object_new (GTK_TYPE_DIALOG,
|
|
|
|
"use-header-bar", use_header,
|
|
|
|
NULL);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (priv->parent_window != NULL)
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), priv->parent_window);
|
|
|
|
gtk_window_set_title (GTK_WINDOW (dialog), "");
|
|
|
|
|
|
|
|
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (content_area), vbox);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (secondary != NULL)
|
2015-03-22 15:45:19 +00:00
|
|
|
s = g_strdup_printf ("<big><b>%s</b></big>\n\n%s", primary, secondary);
|
2009-07-01 03:46:02 +00:00
|
|
|
else
|
2015-03-22 15:45:19 +00:00
|
|
|
s = g_strdup_printf ("%s", primary);
|
|
|
|
|
2009-07-01 03:46:02 +00:00
|
|
|
g_free (primary);
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_label_set_markup (GTK_LABEL (label), s);
|
|
|
|
g_free (s);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), label);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
/* First count the items in the list then
|
2017-11-30 21:39:14 +00:00
|
|
|
* add the buttons in reverse order
|
|
|
|
*/
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
while (choices[len] != NULL)
|
|
|
|
len++;
|
|
|
|
|
|
|
|
for (count = len - 1; count >= 0; count--)
|
|
|
|
gtk_dialog_add_button (GTK_DIALOG (dialog), choices[count], count);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (dialog), "response",
|
|
|
|
G_CALLBACK (show_processes_button_clicked), op);
|
|
|
|
|
|
|
|
priv->dialog = GTK_DIALOG (dialog);
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
if (priv->parent_window == NULL && priv->display)
|
|
|
|
gtk_window_set_display (GTK_WINDOW (dialog), priv->display);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
tree_view = gtk_tree_view_new ();
|
2017-11-30 21:39:14 +00:00
|
|
|
gtk_widget_set_size_request (tree_view, 300, 120);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
column = gtk_tree_view_column_new ();
|
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer, FALSE);
|
|
|
|
gtk_tree_view_column_set_attributes (column, renderer,
|
2017-11-30 21:39:14 +00:00
|
|
|
"texture", 0,
|
2009-07-01 03:46:02 +00:00
|
|
|
NULL);
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (renderer,
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_MIDDLE,
|
|
|
|
"ellipsize-set", TRUE,
|
|
|
|
NULL);
|
|
|
|
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
|
|
|
gtk_tree_view_column_set_attributes (column, renderer,
|
|
|
|
"markup", 1,
|
|
|
|
NULL);
|
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
|
|
|
|
|
|
|
|
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2009-07-01 03:46:02 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-04-17 03:25:06 +00:00
|
|
|
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (scrolled_window), TRUE);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), tree_view);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), scrolled_window);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
2020-03-19 02:56:53 +00:00
|
|
|
controller = gtk_shortcut_controller_new ();
|
|
|
|
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
|
|
|
|
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
|
|
|
|
action = gtk_callback_action_new (on_popup_menu_for_process_tree_view,
|
|
|
|
op,
|
|
|
|
NULL);
|
|
|
|
shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv");
|
|
|
|
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (tree_view), controller);
|
2018-01-15 21:43:54 +00:00
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY);
|
|
|
|
g_signal_connect (gesture, "pressed",
|
2019-05-29 17:10:46 +00:00
|
|
|
G_CALLBACK (click_cb), op);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (tree_view, GTK_EVENT_CONTROLLER (gesture));
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
list_store = gtk_list_store_new (3,
|
2017-11-30 21:39:14 +00:00
|
|
|
GDK_TYPE_TEXTURE,
|
2009-07-01 03:46:02 +00:00
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
|
|
gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), GTK_TREE_MODEL (list_store));
|
|
|
|
|
|
|
|
priv->process_list_store = list_store;
|
|
|
|
priv->process_tree_view = tree_view;
|
|
|
|
/* set pointers to NULL when dialog goes away */
|
2015-03-22 15:45:19 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (priv->process_list_store), (gpointer *) &priv->process_list_store);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (priv->process_tree_view), (gpointer *) &priv->process_tree_view);
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
g_object_unref (list_store);
|
|
|
|
g_object_ref (op);
|
2011-01-27 18:09:56 +00:00
|
|
|
|
|
|
|
return dialog;
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-21 01:36:09 +00:00
|
|
|
call_processes_proxy_cb (GObject *source,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-06-25 20:26:41 +00:00
|
|
|
_GtkMountOperationHandler *proxy = _GTK_MOUNT_OPERATION_HANDLER (source);
|
2012-06-21 01:36:09 +00:00
|
|
|
GMountOperation *op = user_data;
|
|
|
|
GMountOperationResult result;
|
|
|
|
GVariant *result_details;
|
|
|
|
GVariantIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *key;
|
2012-06-21 01:36:09 +00:00
|
|
|
GVariant *value;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
if (!_gtk_mount_operation_handler_call_show_processes_finish (proxy,
|
|
|
|
&result,
|
|
|
|
&result_details,
|
|
|
|
res,
|
|
|
|
&error))
|
2012-06-21 01:36:09 +00:00
|
|
|
{
|
|
|
|
result = G_MOUNT_OPERATION_ABORTED;
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Shell mount operation error: %s", error->message);
|
2012-06-21 01:36:09 +00:00
|
|
|
g_error_free (error);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the request was unhandled it means we called the method again;
|
|
|
|
* in this case, just return and wait for the next response.
|
|
|
|
*/
|
|
|
|
if (result == G_MOUNT_OPERATION_UNHANDLED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, result_details);
|
|
|
|
while (g_variant_iter_loop (&iter, "{&sv}", &key, &value))
|
|
|
|
{
|
|
|
|
if (strcmp (key, "choice") == 0)
|
|
|
|
g_mount_operation_set_choice (op, g_variant_get_int32 (value));
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
gtk_mount_operation_proxy_finish (GTK_MOUNT_OPERATION (op), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_show_processes_do_proxy (GtkMountOperation *operation,
|
|
|
|
const char *message,
|
|
|
|
GArray *processes,
|
|
|
|
const char *choices[])
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char id[255];
|
2012-06-21 01:36:09 +00:00
|
|
|
g_sprintf(id, "GtkMountOperation%p", operation);
|
|
|
|
|
|
|
|
operation->priv->handler_showing = TRUE;
|
|
|
|
g_object_notify (G_OBJECT (operation), "is-showing");
|
|
|
|
|
|
|
|
/* keep a ref to the operation while the handler is showing */
|
|
|
|
g_object_ref (operation);
|
|
|
|
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_call_show_processes (operation->priv->handler, id,
|
|
|
|
message, "drive-harddisk",
|
|
|
|
g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
|
|
|
|
processes->data, processes->len,
|
|
|
|
sizeof (GPid)),
|
|
|
|
choices, NULL,
|
|
|
|
call_processes_proxy_cb, operation);
|
2012-06-21 01:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_show_processes_do_gtk (GtkMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
GArray *processes,
|
|
|
|
const char *choices[])
|
2009-07-01 03:46:02 +00:00
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
2011-01-27 18:09:56 +00:00
|
|
|
GtkWidget *dialog = NULL;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
|
|
|
|
g_return_if_fail (message != NULL);
|
|
|
|
g_return_if_fail (processes != NULL);
|
|
|
|
g_return_if_fail (choices != NULL);
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
priv = op->priv;
|
2009-07-01 03:46:02 +00:00
|
|
|
|
|
|
|
if (priv->process_list_store == NULL)
|
|
|
|
{
|
|
|
|
/* need to create the dialog */
|
2011-01-27 18:09:56 +00:00
|
|
|
dialog = create_show_processes_dialog (op, message, choices);
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise, we're showing the dialog, assume messages+choices hasn't changed */
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
update_process_list_store (op,
|
2009-07-01 03:46:02 +00:00
|
|
|
priv->process_list_store,
|
|
|
|
processes);
|
2011-01-27 18:09:56 +00:00
|
|
|
|
|
|
|
if (dialog != NULL)
|
|
|
|
{
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (dialog);
|
2011-01-27 18:09:56 +00:00
|
|
|
}
|
2009-07-01 03:46:02 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_mount_operation_show_processes (GMountOperation *op,
|
|
|
|
const char *message,
|
|
|
|
GArray *processes,
|
|
|
|
const char *choices[])
|
|
|
|
{
|
|
|
|
|
|
|
|
GtkMountOperation *operation;
|
|
|
|
gboolean use_gtk;
|
|
|
|
|
|
|
|
operation = GTK_MOUNT_OPERATION (op);
|
|
|
|
use_gtk = (operation->priv->handler == NULL);
|
|
|
|
|
|
|
|
if (use_gtk)
|
|
|
|
gtk_mount_operation_show_processes_do_gtk (operation, message, processes, choices);
|
|
|
|
else
|
|
|
|
gtk_mount_operation_show_processes_do_proxy (operation, message, processes, choices);
|
|
|
|
}
|
|
|
|
|
2009-02-17 06:29:21 +00:00
|
|
|
static void
|
|
|
|
gtk_mount_operation_aborted (GMountOperation *op)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_MOUNT_OPERATION (op)->priv;
|
|
|
|
|
|
|
|
if (priv->dialog != NULL)
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (priv->dialog));
|
2009-02-17 06:29:21 +00:00
|
|
|
priv->dialog = NULL;
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
|
|
|
g_object_unref (op);
|
|
|
|
}
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
if (priv->handler != NULL)
|
|
|
|
{
|
2012-06-25 20:26:41 +00:00
|
|
|
_gtk_mount_operation_handler_call_close (priv->handler, NULL, NULL, NULL);
|
2012-06-21 01:36:09 +00:00
|
|
|
|
|
|
|
priv->handler_showing = FALSE;
|
|
|
|
g_object_notify (G_OBJECT (op), "is-showing");
|
|
|
|
}
|
2009-02-17 06:29:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
|
|
|
* gtk_mount_operation_new:
|
2021-05-21 00:45:06 +00:00
|
|
|
* @parent: (nullable): transient parent of the window
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Creates a new `GtkMountOperation`.
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Returns: a new `GtkMountOperation`
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
GMountOperation *
|
|
|
|
gtk_mount_operation_new (GtkWindow *parent)
|
|
|
|
{
|
|
|
|
GMountOperation *mount_operation;
|
|
|
|
|
|
|
|
mount_operation = g_object_new (GTK_TYPE_MOUNT_OPERATION,
|
|
|
|
"parent", parent, NULL);
|
|
|
|
|
|
|
|
return mount_operation;
|
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* gtk_mount_operation_is_showing: (attributes org.gtk.Method.get_property=is-showing)
|
|
|
|
* @op: a `GtkMountOperation`
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Returns whether the `GtkMountOperation` is currently displaying
|
2008-05-26 04:05:17 +00:00
|
|
|
* a window.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @op is currently displaying a window
|
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
gboolean
|
|
|
|
gtk_mount_operation_is_showing (GtkMountOperation *op)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), FALSE);
|
|
|
|
|
|
|
|
return op->priv->dialog != NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* gtk_mount_operation_set_parent: (attributes org.gtk.Method.set_property=parent)
|
|
|
|
* @op: a `GtkMountOperation`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @parent: (nullable): transient parent of the window
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
|
|
|
* Sets the transient parent for windows shown by the
|
2021-03-02 03:52:20 +00:00
|
|
|
* `GtkMountOperation`.
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
void
|
|
|
|
gtk_mount_operation_set_parent (GtkMountOperation *op,
|
|
|
|
GtkWindow *parent)
|
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
|
|
|
|
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
|
|
|
|
|
|
|
|
priv = op->priv;
|
|
|
|
|
|
|
|
if (priv->parent_window == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->parent_window)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->parent_window,
|
2020-05-09 16:03:11 +00:00
|
|
|
parent_destroyed,
|
2008-03-17 17:29:55 +00:00
|
|
|
&priv->parent_window);
|
2014-02-04 02:00:17 +00:00
|
|
|
g_object_unref (priv->parent_window);
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
2014-02-04 02:00:17 +00:00
|
|
|
priv->parent_window = parent;
|
|
|
|
if (priv->parent_window)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
2014-02-04 02:00:17 +00:00
|
|
|
g_object_ref (priv->parent_window);
|
|
|
|
g_signal_connect (priv->parent_window, "destroy",
|
2020-05-09 16:03:11 +00:00
|
|
|
G_CALLBACK (parent_destroyed), &priv->parent_window);
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-04 02:00:17 +00:00
|
|
|
if (priv->dialog)
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (priv->dialog), priv->parent_window);
|
|
|
|
|
2008-03-17 17:29:55 +00:00
|
|
|
g_object_notify (G_OBJECT (op), "parent");
|
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* gtk_mount_operation_get_parent: (attributes org.gtk.Method.get_property=parent)
|
|
|
|
* @op: a `GtkMountOperation`
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Gets the transient parent used by the `GtkMountOperation`.
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2022-01-01 18:05:33 +00:00
|
|
|
* Returns: (transfer none) (nullable): the transient parent for windows shown by @op
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
GtkWindow *
|
|
|
|
gtk_mount_operation_get_parent (GtkMountOperation *op)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
|
|
|
|
|
|
|
|
return op->priv->parent_window;
|
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* gtk_mount_operation_set_display: (attributes org.gtk.Method.set_property=display)
|
|
|
|
* @op: a `GtkMountOperation`
|
|
|
|
* @display: a `GdkDisplay`
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Sets the display to show windows of the `GtkMountOperation` on.
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
2008-03-17 17:29:55 +00:00
|
|
|
void
|
2017-10-31 06:51:15 +00:00
|
|
|
gtk_mount_operation_set_display (GtkMountOperation *op,
|
|
|
|
GdkDisplay *display)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MOUNT_OPERATION (op));
|
2017-10-31 06:51:15 +00:00
|
|
|
g_return_if_fail (GDK_IS_DISPLAY (display));
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
priv = op->priv;
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
if (priv->display == display)
|
2008-03-17 17:29:55 +00:00
|
|
|
return;
|
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
if (priv->display)
|
|
|
|
g_object_unref (priv->display);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
priv->display = g_object_ref (display);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
|
|
|
if (priv->dialog)
|
2017-10-31 06:51:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (priv->dialog), display);
|
2008-03-17 17:29:55 +00:00
|
|
|
|
2017-10-31 06:51:15 +00:00
|
|
|
g_object_notify (G_OBJECT (op), "display");
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|
|
|
|
|
2008-05-26 04:05:17 +00:00
|
|
|
/**
|
2021-03-02 03:52:20 +00:00
|
|
|
* gtk_mount_operation_get_display: (attributes org.gtk.Method.get_property=display)
|
|
|
|
* @op: a `GtkMountOperation`
|
2008-05-26 04:05:17 +00:00
|
|
|
*
|
2021-03-02 03:52:20 +00:00
|
|
|
* Gets the display on which windows of the `GtkMountOperation`
|
2008-05-26 04:05:17 +00:00
|
|
|
* will be shown.
|
|
|
|
*
|
2017-10-31 06:51:15 +00:00
|
|
|
* Returns: (transfer none): the display on which windows of @op are shown
|
2008-05-26 04:05:17 +00:00
|
|
|
*/
|
2017-10-31 06:51:15 +00:00
|
|
|
GdkDisplay *
|
|
|
|
gtk_mount_operation_get_display (GtkMountOperation *op)
|
2008-03-17 17:29:55 +00:00
|
|
|
{
|
|
|
|
GtkMountOperationPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MOUNT_OPERATION (op), NULL);
|
|
|
|
|
|
|
|
priv = op->priv;
|
|
|
|
|
|
|
|
if (priv->dialog)
|
2017-10-31 06:51:15 +00:00
|
|
|
return gtk_widget_get_display (GTK_WIDGET (priv->dialog));
|
2008-03-17 17:29:55 +00:00
|
|
|
else if (priv->parent_window)
|
2017-10-31 06:51:15 +00:00
|
|
|
return gtk_widget_get_display (GTK_WIDGET (priv->parent_window));
|
|
|
|
else if (priv->display)
|
|
|
|
return priv->display;
|
2008-03-17 17:29:55 +00:00
|
|
|
else
|
2017-10-31 06:51:15 +00:00
|
|
|
return gdk_display_get_default ();
|
2008-03-17 17:29:55 +00:00
|
|
|
}
|