[telepathy-mission-control/master] McdAccount: add HasBeenOnline property
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Apr 9 07:09:35 PDT 2009
Recently merged to telepathy-spec, will be in 0.17.23
---
src/mcd-account-config.h | 1 +
src/mcd-account.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/mcd-account.h | 1 +
test/twisted/test-connect.py | 2 ++
xml/Account.xml | 16 ++++++++++++++++
5 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/src/mcd-account-config.h b/src/mcd-account-config.h
index b252000..1c99f8f 100644
--- a/src/mcd-account-config.h
+++ b/src/mcd-account-config.h
@@ -44,6 +44,7 @@
#define MC_ACCOUNTS_KEY_AUTO_PRESENCE_STATUS "AutomaticPresenceStatus"
#define MC_ACCOUNTS_KEY_AUTO_PRESENCE_MESSAGE "AutomaticPresenceMessage"
#define MC_ACCOUNTS_KEY_CONNECT_AUTOMATICALLY "ConnectAutomatically"
+#define MC_ACCOUNTS_KEY_HAS_BEEN_ONLINE "HasBeenOnline"
#define MC_ACCOUNTS_KEY_DATA_DIR "data_dir"
#define MC_ACCOUNTS_KEY_ALIAS "Nickname"
#define MC_ACCOUNTS_KEY_SECONDARY_VCARD_FIELDS "secondary_vcard_fields"
diff --git a/src/mcd-account.c b/src/mcd-account.c
index f7403c4..05cac2e 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -134,6 +134,7 @@ struct _McdAccountPrivate
guint enabled : 1;
guint valid : 1;
guint loaded : 1;
+ guint has_been_online : 1;
/* These fields are used to cache the changed properties */
GHashTable *changed_properties;
@@ -667,6 +668,17 @@ get_valid (TpSvcDBusProperties *self, const gchar *name, GValue *value)
}
static void
+get_has_been_online (TpSvcDBusProperties *self, const gchar *name,
+ GValue *value)
+{
+ McdAccount *account = MCD_ACCOUNT (self);
+ McdAccountPrivate *priv = account->priv;
+
+ g_value_init (value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (value, priv->has_been_online);
+}
+
+static void
set_enabled (TpSvcDBusProperties *self, const gchar *name, const GValue *value)
{
McdAccount *account = MCD_ACCOUNT (self);
@@ -1047,6 +1059,7 @@ static const McdDBusProp account_properties[] = {
{ "CurrentPresence", NULL, get_current_presence },
{ "RequestedPresence", set_requested_presence, get_requested_presence },
{ "NormalizedName", NULL, get_normalized_name },
+ { "HasBeenOnline", NULL, get_has_been_online },
{ 0 },
};
@@ -1388,6 +1401,10 @@ mcd_account_setup (McdAccount *account)
g_key_file_get_boolean (priv->keyfile, priv->unique_name,
MC_ACCOUNTS_KEY_CONNECT_AUTOMATICALLY, NULL);
+ priv->has_been_online =
+ g_key_file_get_boolean (priv->keyfile, priv->unique_name,
+ MC_ACCOUNTS_KEY_HAS_BEEN_ONLINE, NULL);
+
/* load the automatic presence */
priv->auto_presence_type =
g_key_file_get_integer (priv->keyfile, priv->unique_name,
@@ -2185,6 +2202,11 @@ mcd_account_set_connection_status (McdAccount *account,
McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
gboolean changed = FALSE;
+ if (status == TP_CONNECTION_STATUS_CONNECTED)
+ {
+ _mcd_account_set_has_been_online (account);
+ }
+
if (status != priv->conn_status)
{
GValue value = { 0 };
@@ -2393,3 +2415,22 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
}
}
+void
+_mcd_account_set_has_been_online (McdAccount *account)
+{
+ if (!account->priv->has_been_online)
+ {
+ GValue value = { 0 };
+
+ g_key_file_set_boolean (account->priv->keyfile,
+ account->priv->unique_name,
+ MC_ACCOUNTS_KEY_HAS_BEEN_ONLINE, TRUE);
+ account->priv->has_been_online = TRUE;
+ mcd_account_manager_write_conf (account->priv->account_manager);
+
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, TRUE);
+ mcd_account_changed_property (account, "HasBeenOnline", &value);
+ g_value_unset (&value);
+ }
+}
diff --git a/src/mcd-account.h b/src/mcd-account.h
index c1e3805..f1cecf5 100644
--- a/src/mcd-account.h
+++ b/src/mcd-account.h
@@ -119,6 +119,7 @@ void mcd_account_get_requested_presence (McdAccount *account,
const gchar **status,
const gchar **message);
+G_GNUC_INTERNAL void _mcd_account_set_has_been_online (McdAccount *account);
gboolean mcd_account_get_connect_automatically (McdAccount *account);
void mcd_account_get_automatic_presence (McdAccount *account,
TpConnectionPresenceType *presence,
diff --git a/test/twisted/test-connect.py b/test/twisted/test-connect.py
index 632da6b..7fddf88 100644
--- a/test/twisted/test-connect.py
+++ b/test/twisted/test-connect.py
@@ -71,6 +71,7 @@ def test(q, bus, mc):
assert properties.get('RequestedPresence') == \
dbus.Struct((dbus.UInt32(0L), dbus.String(u''), dbus.String(u''))), \
properties.get('RequestedPresence') # FIXME: we should expect 1
+ assert properties.get('HasBeenOnline') == False
# Go online
requested_presence = dbus.Struct((dbus.UInt32(2L), dbus.String(u'brb'),
@@ -122,6 +123,7 @@ def test(q, bus, mc):
properties = account.GetAll(cs.ACCOUNT,
dbus_interface=cs.PROPERTIES_IFACE)
assert properties is not None
+ assert properties.get('HasBeenOnline') == True
assert properties.get('RequestedPresence') == requested_presence, \
properties.get('RequestedPresence')
diff --git a/xml/Account.xml b/xml/Account.xml
index 9dc34ad..b6a2670 100644
--- a/xml/Account.xml
+++ b/xml/Account.xml
@@ -494,6 +494,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</tp:docstring>
</property>
+ <property name="HasBeenOnline" tp:name-for-bindings="Has_Been_Online"
+ type="b" access="read">
+ <tp:docstring>
+ If true, this account has successfully been put online at some point
+ in the past.
+
+ <tp:rationale>
+ UIs could apply a policy that the 'account' parameter can only be
+ edited in accounts that have never been online, or that
+ ConnectAutomatically cannot be set on such accounts. The account
+ manager should not enforce such policies, but it can expose enough
+ information to UIs that the UI can decide what to do.
+ </tp:rationale>
+ </tp:docstring>
+ </property>
+
</interface>
</node>
<!-- vim:set sw=2 sts=2 et ft=xml: -->
--
1.5.6.5
More information about the telepathy-commits
mailing list