Compare commits

...

4 Commits

Author SHA1 Message Date
Zeeshan Ali (Khattak)
64e11c38b4 privacy: Per-app location access control 2016-02-18 18:01:58 +00:00
Zeeshan Ali (Khattak)
2d3ea8b388 privacy: Indicate location service being used
As per the new mockup, we should indicate when location service is in
use:

https://dl.dropboxusercontent.com/u/5031519/privacy/privacy-3.20.png
2016-02-17 15:56:21 +00:00
Zeeshan Ali (Khattak)
ca2d1d7c88 privacy: Move "Location Services" into a dialog
We are about to add per-application settings for geolocation access and
they won't really fit well in the main view. This is as per design
mockup:

https://dl.dropboxusercontent.com/u/5031519/privacy/privacy-3.20.png
2016-02-17 13:31:49 +00:00
Zeeshan Ali (Khattak)
9b7c1749a9 Move get_smart_date() to common utils
And rename it to cc_util_get_smart_date().

In a following patch, we'll need to use it from privacy panel.
2016-02-17 13:31:29 +00:00
8 changed files with 425 additions and 82 deletions

View File

@@ -20,6 +20,7 @@
#include "config.h"
#include <string.h>
#include <glib/gi18n.h>
#include "cc-util.h"
@@ -103,3 +104,41 @@ cc_util_normalize_casefold_and_unaccent (const char *str)
return tmp;
}
gchar *
cc_util_get_smart_date (GDateTime *date)
{
gchar *label;
GDateTime *today, *local;
GTimeSpan span;
/* Set today date */
local = g_date_time_new_now_local ();
today = g_date_time_new_local (g_date_time_get_year (local),
g_date_time_get_month (local),
g_date_time_get_day_of_month (local),
0, 0, 0);
span = g_date_time_difference (today, date);
if (span <= 0) {
label = g_strdup (_("Today"));
}
else if (span <= G_TIME_SPAN_DAY) {
label = g_strdup (_("Yesterday"));
}
else {
if (g_date_time_get_year (date) == g_date_time_get_year (today)) {
/* Translators: This is a date format string in the style of "Feb 24". */
label = g_date_time_format (date, _("%b %e"));
}
else {
/* Translators: This is a date format string in the style of "Feb 24, 2013". */
label = g_date_time_format (date, _("%b %e, %Y"));
}
}
g_date_time_unref (local);
g_date_time_unref (today);
return label;
}

View File

@@ -23,6 +23,7 @@
#include <glib.h>
char *cc_util_normalize_casefold_and_unaccent (const char *str);
char * cc_util_normalize_casefold_and_unaccent (const char *str);
gchar *cc_util_get_smart_date (GDateTime *date);
#endif

View File

@@ -21,6 +21,7 @@
#include "shell/list-box-helper.h"
#include "cc-privacy-panel.h"
#include "cc-privacy-resources.h"
#include "cc-util.h"
#include <gio/gdesktopappinfo.h>
#include <glib/gi18n.h>
@@ -38,14 +39,22 @@ CC_PANEL_REGISTER (CcPrivacyPanel, cc_privacy_panel)
#define REPORT_TECHNICAL_PROBLEMS "report-technical-problems"
#define LOCATION_ENABLED "enabled"
#define APP_PERMISSIONS_TABLE "desktop"
#define APP_PERMISSIONS_ID "geolocation"
struct _CcPrivacyPanelPrivate
{
GtkBuilder *builder;
GtkWidget *recent_dialog;
GtkWidget *screen_lock_dialog;
GtkWidget *location_dialog;
GtkWidget *location_label;
GtkWidget *trash_dialog;
GtkWidget *software_dialog;
GtkWidget *list_box;
GtkWidget *location_apps_list_box;
GtkWidget *location_apps_label;
GtkWidget *location_apps_frame;
GSettings *lockdown_settings;
GSettings *lock_settings;
@@ -56,6 +65,11 @@ struct _CcPrivacyPanelPrivate
GtkWidget *abrt_dialog;
GtkWidget *abrt_row;
guint abrt_watch_id;
GDBusProxy *gclue_manager;
GDBusProxy *perm_store;
GtkSizeGroup *location_icon_size_group;
};
static char *
@@ -379,6 +393,271 @@ add_screen_lock (CcPrivacyPanel *self)
G_SETTINGS_BIND_DEFAULT);
}
static void
update_location_label (CcPrivacyPanel *self)
{
CcPrivacyPanelPrivate *priv = self->priv;
gboolean in_use = FALSE, on;
if (priv->gclue_manager != NULL)
{
GVariant *variant;
variant = g_dbus_proxy_get_cached_property (priv->gclue_manager, "InUse");
if (variant != NULL)
{
in_use = g_variant_get_boolean (variant);
g_variant_unref (variant);
}
}
if (in_use) {
gtk_label_set_label (GTK_LABEL (priv->location_label), _("In use"));
return;
}
on = g_settings_get_boolean (priv->location_settings, LOCATION_ENABLED);
gtk_label_set_label (GTK_LABEL (priv->location_label),
on ? _("On") : _("Off"));
}
static void
on_location_setting_changed (GSettings *settings,
gchar *key,
gpointer user_data)
{
update_location_label (CC_PRIVACY_PANEL (user_data));
}
static void
on_gclue_manager_props_changed (GDBusProxy *manager,
GVariant *changed_properties,
GStrv invalidated_properties,
gpointer user_data)
{
update_location_label (CC_PRIVACY_PANEL (user_data));
}
static void
on_gclue_manager_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
CcPrivacyPanel *self = CC_PRIVACY_PANEL (user_data);
GError *error = NULL;
self->priv->gclue_manager = g_dbus_proxy_new_for_bus_finish (res, &error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
g_signal_connect (self->priv->gclue_manager,
"g-properties-changed",
G_CALLBACK (on_gclue_manager_props_changed),
self);
update_location_label (self);
}
static void
add_location_app (CcPrivacyPanel *self,
const gchar *app_id,
gboolean enabled,
gint64 last_used)
{
GDesktopAppInfo *app_info;
char *desktop_id;
GtkWidget *box, *row, *w;
GIcon *icon;
GDateTime *t;
char *last_used_str;
desktop_id = g_strjoin (".", app_id, "desktop", NULL);
app_info = g_desktop_app_info_new (desktop_id);
if (app_info == NULL)
return;
row = gtk_list_box_row_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_widget_set_margin_top (box, 6);
gtk_widget_set_margin_bottom (box, 6);
gtk_container_add (GTK_CONTAINER (row), box);
gtk_widget_set_hexpand (box, TRUE);
gtk_container_add (GTK_CONTAINER (self->priv->location_apps_list_box), row);
icon = g_app_info_get_icon (G_APP_INFO (app_info));
w = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_widget_set_margin_start (w, 12);
gtk_widget_set_halign (w, GTK_ALIGN_CENTER);
gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
gtk_size_group_add_widget (self->priv->location_icon_size_group, w);
gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
w = gtk_label_new (g_app_info_get_name (G_APP_INFO (app_info)));
gtk_widget_set_margin_start (w, 12);
gtk_widget_set_margin_end (w, 12);
gtk_widget_set_halign (w, GTK_ALIGN_START);
gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
gtk_label_set_xalign (GTK_LABEL (w), 0);
gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
t = g_date_time_new_from_unix_utc (last_used);
last_used_str = cc_util_get_smart_date (t);
w = gtk_label_new (last_used_str);
g_free (last_used_str);
gtk_style_context_add_class (gtk_widget_get_style_context (w), "dim-label");
gtk_widget_set_margin_start (w, 12);
gtk_widget_set_margin_end (w, 12);
gtk_widget_set_halign (w, GTK_ALIGN_END);
gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
w = gtk_switch_new ();
gtk_switch_set_active (GTK_SWITCH (w), enabled);
gtk_widget_set_margin_end (w, 12);
gtk_widget_set_halign (w, GTK_ALIGN_END);
gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
gtk_widget_show_all (row);
}
static void
on_perm_store_lookup_done(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
CcPrivacyPanel *self = CC_PRIVACY_PANEL (user_data);
GVariant *results, *dict;
GVariantIter iter;
gchar *key;
gchar **value;
GList *children;
GError *error = NULL;
results = g_dbus_proxy_call_finish (self->priv->perm_store,
res,
&error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
dict = g_variant_get_child_value (results, 0);
g_variant_iter_init (&iter, dict);
while (g_variant_iter_loop (&iter, "{s^as}", &key, &value))
{
gboolean enabled;
gint64 last_used;
if (g_strv_length (value) < 3)
continue;
enabled = (g_strcmp0 (value[0], "NONE") != 0);
last_used = g_ascii_strtoll (value[2], NULL, 10);
add_location_app (self,
key,
enabled,
last_used);
}
children = gtk_container_get_children (GTK_CONTAINER (self->priv->location_apps_list_box));
if (g_list_length (children) > 0)
{
gtk_widget_set_visible (self->priv->location_apps_label, TRUE);
gtk_widget_set_visible (self->priv->location_apps_frame, TRUE);
}
g_list_free (children);
}
static void
on_perm_store_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
CcPrivacyPanel *self = CC_PRIVACY_PANEL (user_data);
GVariant *params;
GError *error = NULL;
self->priv->perm_store = g_dbus_proxy_new_for_bus_finish (res, &error);
if (error != NULL)
{
g_warning ("%s", error->message);
g_error_free (error);
return;
}
params = g_variant_new ("(ss)",
APP_PERMISSIONS_TABLE,
APP_PERMISSIONS_ID);
g_dbus_proxy_call (self->priv->perm_store,
"Lookup",
params,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
on_perm_store_lookup_done,
self);
}
static void
add_location (CcPrivacyPanel *self)
{
CcPrivacyPanelPrivate *priv = self->priv;
GtkWidget *w;
GtkWidget *dialog;
priv->location_label = gtk_label_new ("");
g_signal_connect (priv->location_settings,
"changed::" LOCATION_ENABLED,
G_CALLBACK (on_location_setting_changed),
self);
update_location_label (self);
add_row (self,
_("Location Services"),
"location_dialog",
priv->location_label);
dialog = priv->location_dialog;
g_signal_connect (dialog, "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), NULL);
w = GTK_WIDGET (gtk_builder_get_object (priv->builder, "location_services_switch"));
g_settings_bind (priv->location_settings, LOCATION_ENABLED,
w, "active",
G_SETTINGS_BIND_DEFAULT);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.GeoClue2",
"/org/freedesktop/GeoClue2/Manager",
"org.freedesktop.GeoClue2.Manager",
NULL,
on_gclue_manager_ready,
self);
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.freedesktop.XdgApp",
"/org/freedesktop/XdgApp/PermissionStore",
"org.freedesktop.XdgApp.PermissionStore",
NULL,
on_perm_store_ready,
self);
}
static void
retain_history_combo_changed_cb (GtkWidget *widget,
CcPrivacyPanel *self)
@@ -767,6 +1046,7 @@ cc_privacy_panel_finalize (GObject *object)
g_clear_pointer (&priv->recent_dialog, gtk_widget_destroy);
g_clear_pointer (&priv->screen_lock_dialog, gtk_widget_destroy);
g_clear_pointer (&priv->location_dialog, gtk_widget_destroy);
g_clear_pointer (&priv->trash_dialog, gtk_widget_destroy);
g_clear_pointer (&priv->software_dialog, gtk_widget_destroy);
g_clear_pointer (&priv->abrt_dialog, gtk_widget_destroy);
@@ -776,6 +1056,9 @@ cc_privacy_panel_finalize (GObject *object)
g_clear_object (&priv->privacy_settings);
g_clear_object (&priv->notification_settings);
g_clear_object (&priv->location_settings);
g_clear_object (&priv->gclue_manager);
g_clear_object (&priv->perm_store);
g_clear_object (&priv->location_icon_size_group);
G_OBJECT_CLASS (cc_privacy_panel_parent_class)->finalize (object);
}
@@ -836,6 +1119,7 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
self->priv->recent_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "recent_dialog"));
self->priv->screen_lock_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "screen_lock_dialog"));
self->priv->location_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "location_dialog"));
self->priv->trash_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "trash_dialog"));
self->priv->software_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "software_dialog"));
self->priv->abrt_dialog = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "abrt_dialog"));
@@ -846,6 +1130,13 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
gtk_container_add (GTK_CONTAINER (frame), widget);
self->priv->list_box = widget;
gtk_widget_show (widget);
self->priv->location_apps_list_box = WID ("location_apps_list_box");
gtk_list_box_set_header_func (GTK_LIST_BOX (self->priv->location_apps_list_box),
cc_list_box_update_header_func,
NULL, NULL);
self->priv->location_apps_frame = WID ("location_apps_frame");
self->priv->location_apps_label = WID ("location_apps_label");
self->priv->location_icon_size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
g_signal_connect_swapped (widget, "row-activated",
G_CALLBACK (activate_row), self);
@@ -861,6 +1152,7 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
self->priv->location_settings = g_settings_new ("org.gnome.system.location");
add_screen_lock (self);
add_location (self);
add_usage_history (self);
add_trash_temp (self);
add_software (self);
@@ -870,15 +1162,6 @@ cc_privacy_panel_init (CcPrivacyPanel *self)
G_CALLBACK (on_lockdown_settings_changed), self);
update_lock_screen_sensitivity (self);
widget = WID ("location_services_switch");
gtk_switch_set_active (GTK_SWITCH (widget),
g_settings_get_boolean (self->priv->location_settings,
LOCATION_ENABLED));
g_settings_bind (self->priv->location_settings,
LOCATION_ENABLED,
widget, "active",
G_SETTINGS_BIND_DEFAULT);
widget = WID ("privacy_vbox");
gtk_container_add (GTK_CONTAINER (self), widget);
}

View File

@@ -714,19 +714,30 @@ All the information we collect is made anonymous, and we will never share your d
</object>
</child>
</object>
<object class="GtkBox" id="privacy_vbox">
<property name="visible">True</property>
<object class="GtkDialog" id="location_dialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Location Services</property>
<property name="resizable">False</property>
<property name="type_hint">dialog</property>
<property name="use_header_bar">1</property>
<child internal-child="vbox">
<object class="GtkBox" id="location-vbox">
<property name="can_focus">False</property>
<property name="margin_start">134</property>
<property name="margin_end">134</property>
<property name="margin_top">22</property>
<property name="margin_bottom">22</property>
<property name="orientation">vertical</property>
<property name="margin_start">12</property>
<property name="margin_end">12</property>
<property name="spacing">2</property>
<child>
<object class="GtkFrame" id="frame">
<object class="GtkLabel" id="location_description_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="shadow_type">in</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<property name="label" translatable="yes">Location services allow applications to determine your geographical position. Accuracy is increased by enabling WiFi and GPS.</property>
<property name="wrap">True</property>
<property name="max_width_chars">50</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="expand">False</property>
@@ -740,8 +751,6 @@ All the information we collect is made anonymous, and we will never share your d
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="shadow_type">in</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkListBox" id="location_listbox">
@@ -771,7 +780,6 @@ All the information we collect is made anonymous, and we will never share your d
<property name="xalign">0</property>
<property name="label" translatable="yes">_Location Services</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">location_services_switch</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -781,24 +789,6 @@ All the information we collect is made anonymous, and we will never share your d
</packing>
</child>
<child>
<object class="GtkLabel" id="location_description_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Used to determine your geographical location</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="location_services_switch">
<property name="visible">True</property>
@@ -819,6 +809,27 @@ All the information we collect is made anonymous, and we will never share your d
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="location_apps_label">
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="margin_top">24</property>
<property name="margin_bottom">12</property>
<property name="halign">start</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Applications</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
@@ -826,6 +837,53 @@ All the information we collect is made anonymous, and we will never share your d
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="location_apps_frame">
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="shadow_type">in</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkListBox" id="location_apps_list_box">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="selection_mode">none</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkBox" id="privacy_vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_start">134</property>
<property name="margin_end">134</property>
<property name="margin_top">22</property>
<property name="margin_bottom">22</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="frame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="shadow_type">in</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<object class="GtkDialog" id="abrt_dialog">

View File

@@ -30,6 +30,8 @@
#include <gtk/gtk.h>
#include <act/act.h>
#include "cc-util.h"
#include "um-history-dialog.h"
#include "um-utils.h"
@@ -169,7 +171,7 @@ add_record (GtkWidget *box, GDateTime *datetime, gchar *record_string, gint line
gchar *date, *time, *str;
GtkWidget *label, *row;
date = get_smart_date (datetime);
date = cc_util_get_smart_date (datetime);
/* Translators: This is a time format string in the style of "22:58".
It indicates a login time which follows a date. */
time = g_date_time_format (datetime, C_("login date-time", "%k:%M"));

View File

@@ -60,6 +60,7 @@
#include "um-history-dialog.h"
#include "cc-common-language.h"
#include "cc-util.h"
#include "um-realm-manager.h"
@@ -838,7 +839,7 @@ get_login_time_text (ActUser *user)
}
else if (time > 0) {
date_time = g_date_time_new_from_unix_local (time);
date_str = get_smart_date (date_time);
date_str = cc_util_get_smart_date (date_time);
/* Translators: This is a time format string in the style of "22:58".
It indicates a login time which follows a date. */
time_str = g_date_time_format (date_time, C_("login date-time", "%k:%M"));

View File

@@ -796,45 +796,6 @@ generate_username_choices (const gchar *name,
g_string_free (item4, TRUE);
}
gchar *
get_smart_date (GDateTime *date)
{
gchar *label;
GDateTime *today, *local;
GTimeSpan span;
/* Set today date */
local = g_date_time_new_now_local ();
today = g_date_time_new_local (g_date_time_get_year (local),
g_date_time_get_month (local),
g_date_time_get_day_of_month (local),
0, 0, 0);
span = g_date_time_difference (today, date);
if (span <= 0) {
label = g_strdup (_("Today"));
}
else if (span <= G_TIME_SPAN_DAY) {
label = g_strdup (_("Yesterday"));
}
else {
if (g_date_time_get_year (date) == g_date_time_get_year (today)) {
/* Translators: This is a date format string in the style of "Feb 24". */
label = g_date_time_format (date, _("%b %e"));
}
else {
/* Translators: This is a date format string in the style of "Feb 24, 2013". */
label = g_date_time_format (date, _("%b %e, %Y"));
}
}
g_date_time_unref (local);
g_date_time_unref (today);
return label;
}
static gboolean
check_user_file (const char *filename,
gssize max_file_size)

View File

@@ -73,8 +73,6 @@ gboolean is_valid_username (const gchar *name,
void generate_username_choices (const gchar *name,
GtkListStore *store);
gchar * get_smart_date (GDateTime *date);
cairo_surface_t *render_user_icon (ActUser *user,
UmIconStyle style,
gint icon_size,