~ubuntu-branches/ubuntu/precise/telepathy-mission-control-5/precise

« back to all changes in this revision

Viewing changes to src/mcd-account.c

ImportĀ upstreamĀ versionĀ 5.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
    guint loaded : 1;
143
143
    guint has_been_online : 1;
144
144
    guint removed : 1;
 
145
    guint always_on : 1;
145
146
 
146
147
    /* These fields are used to cache the changed properties */
147
148
    GHashTable *changed_properties;
154
155
    PROP_DBUS_DAEMON,
155
156
    PROP_ACCOUNT_MANAGER,
156
157
    PROP_NAME,
 
158
    PROP_ALWAYS_ON,
157
159
};
158
160
 
159
161
enum
952
954
 
953
955
    DEBUG ("called for %s", priv->unique_name);
954
956
 
955
 
    /* We can't raise an error in this API :-( */
956
957
    if (!G_VALUE_HOLDS_BOOLEAN (value))
957
958
    {
958
959
        g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
962
963
    }
963
964
 
964
965
    enabled = g_value_get_boolean (value);
 
966
 
 
967
    if (priv->always_on && !enabled)
 
968
    {
 
969
        g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
 
970
                     "Account %s cannot be disabled",
 
971
                     priv->unique_name);
 
972
        return FALSE;
 
973
    }
 
974
 
965
975
    if (priv->enabled != enabled)
966
976
    {
967
977
        if (!enabled)
1248
1258
    }
1249
1259
 
1250
1260
    connect_automatically = g_value_get_boolean (value);
 
1261
 
 
1262
    if (priv->always_on && !connect_automatically)
 
1263
    {
 
1264
        g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
 
1265
                     "Account %s always connects automatically",
 
1266
                     priv->unique_name);
 
1267
        return FALSE;
 
1268
    }
 
1269
 
1251
1270
    if (priv->connect_automatically != connect_automatically)
1252
1271
    {
1253
1272
        g_key_file_set_boolean (priv->keyfile, priv->unique_name,
1363
1382
    status = g_value_get_string (va->values + 1);
1364
1383
    message = g_value_get_string (va->values + 2);
1365
1384
 
 
1385
    if (priv->always_on && !_presence_type_is_online (type))
 
1386
    {
 
1387
        g_set_error (error, TP_ERRORS, TP_ERROR_PERMISSION_DENIED,
 
1388
                     "Account %s cannot be taken offline", priv->unique_name);
 
1389
        return FALSE;
 
1390
    }
 
1391
 
1366
1392
    if (!_presence_type_is_settable (type))
1367
1393
    {
1368
1394
        g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
1905
1931
    priv->object_path = g_strconcat (MC_ACCOUNT_DBUS_OBJECT_BASE,
1906
1932
                                     priv->unique_name, NULL);
1907
1933
 
1908
 
    priv->enabled =
1909
 
        g_key_file_get_boolean (priv->keyfile, priv->unique_name,
1910
 
                                MC_ACCOUNTS_KEY_ENABLED, NULL);
 
1934
    if (!priv->always_on)
 
1935
    {
 
1936
        priv->enabled =
 
1937
            g_key_file_get_boolean (priv->keyfile, priv->unique_name,
 
1938
                                    MC_ACCOUNTS_KEY_ENABLED, NULL);
1911
1939
 
1912
 
    priv->connect_automatically =
1913
 
        g_key_file_get_boolean (priv->keyfile, priv->unique_name,
1914
 
                                MC_ACCOUNTS_KEY_CONNECT_AUTOMATICALLY, NULL);
 
1940
        priv->connect_automatically =
 
1941
            g_key_file_get_boolean (priv->keyfile, priv->unique_name,
 
1942
                                    MC_ACCOUNTS_KEY_CONNECT_AUTOMATICALLY,
 
1943
                                    NULL);
 
1944
    }
1915
1945
 
1916
1946
    priv->has_been_online =
1917
1947
        g_key_file_get_boolean (priv->keyfile, priv->unique_name,
1968
1998
         * its lifetime is longer than the McdAccount's */
1969
1999
        priv->account_manager = g_value_get_object (val);
1970
2000
        break;
 
2001
 
1971
2002
    case PROP_NAME:
1972
2003
        g_assert (priv->unique_name == NULL);
1973
2004
        priv->unique_name = g_value_dup_string (val);
1974
2005
        break;
1975
2006
 
 
2007
    case PROP_ALWAYS_ON:
 
2008
        priv->always_on = g_value_get_boolean (val);
 
2009
 
 
2010
        if (priv->always_on)
 
2011
        {
 
2012
            priv->enabled = TRUE;
 
2013
            priv->connect_automatically = TRUE;
 
2014
            priv->req_presence_type = priv->auto_presence_type;
 
2015
            priv->req_presence_status = g_strdup (priv->auto_presence_status);
 
2016
            priv->req_presence_message = g_strdup (priv->auto_presence_message);
 
2017
        }
 
2018
 
 
2019
        break;
 
2020
 
1976
2021
    default:
1977
2022
        G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
1978
2023
        break;
2144
2189
                              NULL,
2145
2190
                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
2146
2191
 
 
2192
    g_object_class_install_property
 
2193
        (object_class, PROP_ALWAYS_ON,
 
2194
         g_param_spec_boolean ("always-on", "Always on?", "Always on?",
 
2195
                              FALSE,
 
2196
                              G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
 
2197
                              G_PARAM_STATIC_STRINGS));
 
2198
 
2147
2199
    /* Signals */
2148
2200
    _mcd_account_signals[CONNECTION_STATUS_CHANGED] =
2149
2201
        g_signal_new ("connection-status-changed",
2182
2234
    priv->req_presence_status = g_strdup ("offline");
2183
2235
    priv->req_presence_message = g_strdup ("");
2184
2236
 
 
2237
    priv->always_on = FALSE;
 
2238
    priv->enabled = FALSE;
 
2239
    priv->connect_automatically = FALSE;
 
2240
 
2185
2241
    priv->auto_presence_type = TP_CONNECTION_PRESENCE_TYPE_AVAILABLE;
2186
2242
    priv->auto_presence_status = g_strdup ("available");
2187
2243
    priv->auto_presence_message = g_strdup ("");
2536
2592
    data_dir = get_account_data_path (priv);
2537
2593
    filename = g_build_filename (data_dir, MC_AVATAR_FILENAME, NULL);
2538
2594
    if (!g_file_test (data_dir, G_FILE_TEST_EXISTS))
2539
 
        g_mkdir_with_parents (data_dir, 0777);
 
2595
        g_mkdir_with_parents (data_dir, 0700);
 
2596
    _mcd_chmod_private (data_dir);
2540
2597
    g_free (data_dir);
2541
2598
 
2542
2599
    if (G_LIKELY(avatar) && avatar->len > 0)
3164
3221
 
3165
3222
    self->priv->connection_context = c;
3166
3223
}
 
3224
 
 
3225
gboolean
 
3226
_mcd_account_get_always_on (McdAccount *self)
 
3227
{
 
3228
    g_return_val_if_fail (MCD_IS_ACCOUNT (self), FALSE);
 
3229
 
 
3230
    return self->priv->always_on;
 
3231
}