1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
|
/* Mission Control plugin API - Account Storage plugins.
*
* Copyright © 2010 Nokia Corporation
* Copyright © 2010 Collabora Ltd.
*
* 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.1 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
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* SECTION:account-storage
* @title: McpAccountStorage
* @short_description: Account Storage object, implemented by plugins
* @see_also:
* @include: mission-control-plugins/mission-control-plugins.h
*
* Plugins may implement #McpAccountStorage in order to provide account
* parameter storage backends to the AccountManager object.
*
* To do so, the plugin must implement a #GObject subclass that implements
* #McpAccountStorage, then return an instance of that subclass from
* mcp_plugin_ref_nth_object().
*
* Many methods take "the unique name of an account" as an argument.
* In this plugin, that means the unique "tail" of the account's
* object path, for instance "gabble/jabber/chris_40example_2ecom".
* The account's full object path is obtained by prepending
* %TP_ACCOUNT_OBJECT_PATH_BASE.
*
* A complete implementation of this interface with all methods would
* look something like this:
*
* <example><programlisting>
* G_DEFINE_TYPE_WITH_CODE (FooPlugin, foo_plugin,
* G_TYPE_OBJECT,
* G_IMPLEMENT_INTERFACE (...);
* G_IMPLEMENT_INTERFACE (MCP_TYPE_ACCOUNT_STORAGE,
* account_storage_iface_init));
* /<!-- -->* ... *<!-- -->/
* static void
* account_storage_iface_init (McpAccountStorageIface *iface)
* {
* iface->priority = 0;
* iface->name = "foo";
* iface->desc = "The FOO storage backend";
* iface->provider = "org.freedesktop.Telepathy.MissionControl5.FooStorage";
*
* iface->get = foo_plugin_get;
* iface->delete = foo_plugin_delete;
* iface->commit = foo_plugin_commit;
* iface->list = foo_plugin_list;
* iface->ready = foo_plugin_ready;
* iface->get_identifier = foo_plugin_get_identifier;
* iface->get_additional_info = foo_plugin_get_additional_info;
* iface->get_restrictions = foo_plugin_get_restrictions;
* iface->create = foo_plugin_create;
* iface->set_attribute = foo_plugin_set_attribute;
* iface->set_parameter = foo_plugin_set_parameter;
* }
* </programlisting></example>
*
* A single object can implement more than one interface; It is currently
* unlikely that you would find it useful to implement anything other than
* an account storage plugin in an account storage object, though.
*/
#include "config.h"
#include <mission-control-plugins/mission-control-plugins.h>
#include <mission-control-plugins/mcp-signals-marshal.h>
#include <mission-control-plugins/implementation.h>
#include <mission-control-plugins/debug-internal.h>
#include <glib.h>
#define MCP_DEBUG_TYPE MCP_DEBUG_ACCOUNT_STORAGE
#ifdef ENABLE_DEBUG
#define SDEBUG(_p, _format, ...) \
DEBUG("%s: " _format, \
(_p != NULL) ? mcp_account_storage_name (_p) : "NULL", ##__VA_ARGS__)
#else /* ENABLE_DEBUG */
#define SDEBUG(_p, _format, ...) do {} while (0);
#endif /* ENABLE_DEBUG */
enum
{
CREATED,
TOGGLED,
DELETED,
ALTERED_ONE,
RECONNECT,
NO_SIGNAL
};
static guint signals[NO_SIGNAL] = { 0 };
static gboolean
default_set_attribute (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account,
const gchar *attribute,
GVariant *value,
McpAttributeFlags flags)
{
return FALSE;
}
static gboolean
default_set_parameter (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account,
const gchar *parameter,
GVariant *value,
McpParameterFlags flags)
{
return FALSE;
}
static gchar *
default_create (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *manager,
const gchar *protocol,
const gchar *identification,
GError **error)
{
g_set_error (error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED,
"This storage does not implement create function");
return NULL;
}
static gboolean
default_delete (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *account,
const gchar *key)
{
return FALSE;
}
static gboolean
default_commit (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *account)
{
return FALSE;
}
static void
default_ready (const McpAccountStorage *storage,
const McpAccountManager *am)
{
}
static void
default_get_identifier (const McpAccountStorage *storage,
const gchar *account,
GValue *identifier)
{
g_value_init (identifier, G_TYPE_STRING);
g_value_set_string (identifier, account);
}
static GHashTable *
default_get_additional_info (const McpAccountStorage *storage,
const gchar *account)
{
return g_hash_table_new (g_str_hash, g_str_equal);
}
static TpStorageRestrictionFlags
default_get_restrictions (const McpAccountStorage *storage,
const gchar *account)
{
return 0;
}
static void
class_init (gpointer klass,
gpointer data)
{
GType type = G_TYPE_FROM_CLASS (klass);
McpAccountStorageIface *iface = klass;
iface->set_attribute = default_set_attribute;
iface->set_parameter = default_set_parameter;
iface->create = default_create;
iface->delete = default_delete;
iface->commit = default_commit;
iface->ready = default_ready;
iface->get_identifier = default_get_identifier;
iface->get_additional_info = default_get_additional_info;
iface->get_restrictions = default_get_restrictions;
if (signals[CREATED] != 0)
{
DEBUG ("already registered signals");
return;
}
/**
* McpAccountStorage::created
* @account: the unique name of the created account
*
* Emitted if an external entity creates an account
* in the backend the emitting plugin handles.
*
* Should not be fired until mcp_account_storage_ready() has been called
*
*/
signals[CREATED] = g_signal_new ("created",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING);
/**
* McpAccountStorage::altered-one
* @account: the unique name of the altered account
* @name: the name of the altered property (its key)
*
* Emitted if an external entity alters an account
* in the backend that the emitting plugin handles.
*
* Before emitting this signal, the plugin must call
* either mcp_account_manager_set_attribute(),
* either mcp_account_manager_set_parameter() or
* mcp_account_manager_set_value() to push the new value
* into the account manager.
*
* Note that mcp_account_manager_set_parameter() does not use the
* "param-" prefix, but this signal and mcp_account_manager_set_value()
* both do.
*
* Should not be fired until mcp_account_storage_ready() has been called
*/
signals[ALTERED_ONE] = g_signal_new ("altered-one",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
_mcp_marshal_VOID__STRING_STRING, G_TYPE_NONE,
2, G_TYPE_STRING, G_TYPE_STRING);
/**
* McpAccountStorage::deleted
* @account: the unique name of the deleted account
*
* Emitted if an external entity deletes an account
* in the backend the emitting plugin handles.
*
* Should not be fired until mcp_account_storage_ready() has been called.
*
* mcp_account_storage_commit() and mcp_account_storage_delete() won't be
* called for this account, it is assumed that the storage backend already
* deleted all the related information.
*/
signals[DELETED] = g_signal_new ("deleted",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING);
/**
* McpAccountStorage::toggled
* @account: the unique name of the toggled account
* @enabled: #gboolean indicating whether the account is enabled
*
* Emitted if an external entity enables/disables an account
* in the backend the emitting plugin handles. This is similar to
* emitting #McpAccountStorage::altered-one for the attribute
* "Enabled", except that the plugin is not required to call
* a function like mcp_account_manager_set_value() first.
*
* Should not be fired until mcp_account_storage_ready() has been called
*
*/
signals[TOGGLED] = g_signal_new ("toggled",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
_mcp_marshal_VOID__STRING_BOOLEAN, G_TYPE_NONE,
2, G_TYPE_STRING, G_TYPE_BOOLEAN);
/**
* McpAccountStorage::reconnect
* @account: the unique name of the account to reconnect
*
* emitted if an external entity modified important parameters of the
* account and a reconnection is required in order to apply them.
*
* Should not be fired until mcp_account_storage_ready() has been called
**/
signals[RECONNECT] = g_signal_new ("reconnect",
type, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
g_cclosure_marshal_VOID__STRING, G_TYPE_NONE,
1, G_TYPE_STRING);
}
GType
mcp_account_storage_get_type (void)
{
static gsize once = 0;
static GType type = 0;
if (g_once_init_enter (&once))
{
static const GTypeInfo info =
{
sizeof (McpAccountStorageIface),
NULL, /* base_init */
NULL, /* base_finalize */
class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
0, /* instance_size */
0, /* n_preallocs */
NULL, /* instance_init */
NULL /* value_table */
};
type = g_type_register_static (G_TYPE_INTERFACE,
"McpAccountStorage", &info, 0);
g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
g_once_init_leave (&once, 1);
}
return type;
}
/**
* McpAccountStorage:
*
* An object implementing the account storage plugin interface.
*/
/**
* McpAccountStorageIface:
* @parent: the standard fields for an interface
* @priority: returned by mcp_account_storage_priority()
* @name: returned by mcp_account_storage_name()
* @desc: returned by mcp_account_storage_description()
* @provider: returned by mcp_account_storage_provider()
* @set: implementation of mcp_account_storage_set()
* @get: implementation of mcp_account_storage_get()
* @delete: implementation of mcp_account_storage_delete()
* @list: implementation of mcp_account_storage_list()
* @ready: implementation of mcp_account_storage_ready()
* @commit: implementation of mcp_account_storage_commit()
* @get_identifier: implementation of mcp_account_storage_get_identifier()
* @get_additional_info: implementation of
* mcp_account_storage_get_additional_info()
* @get_restrictions: implementation of mcp_account_storage_get_restrictions()
* @create: implementation of mcp_account_storage_create()
*
* The interface vtable for an account storage plugin.
*/
/**
* mcp_account_storage_priority:
* @storage: an #McpAccountStorage instance
*
* Gets the priority for this plugin.
*
* Priorities currently run from MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_DEFAULT
* (the default storage plugin priority) upwards. More-positive numbers
* are higher priority.
*
* Plugins at a higher priority then MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_KEYRING
* used to have the opportunity to "steal" passwords from the gnome keyring.
* It is no longer significant.
*
* Plugins at a lower priority than the default plugin will never be asked to
* store any details, although they may still be asked to list them at startup
* time, and may asynchronously notify MC of accounts via the signals above.
*
* When loading accounts at startup, plugins are consulted in order from
* lowest to highest, so that higher priority plugins may overrule settings
* from lower priority plugins.
*
* Loading all the accounts is only done at startup, before the dbus name
* is claimed, and is therefore the only time plugins are allowed to indulge
* in blocking calls (indeed, they are expected to carry out this operation,
* and ONLY this operation, synchronously).
*
* When values are being set, the plugins are invoked from highest priority
* to lowest, with the first plugin that claims a setting being assigned
* ownership, and all lower priority plugins being asked to delete the
* setting in question.
*
* Returns: the priority of this plugin
**/
gint
mcp_account_storage_priority (const McpAccountStorage *storage)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_val_if_fail (iface != NULL, -1);
return iface->priority;
}
/**
* McpAccountStorageGetFunc:
* @storage: the account storage plugin
* @am: object used to call back into the account manager
* @account: the unique name of the account
* @key: the setting whose value we wish to fetch: either an attribute
* like "DisplayName", or "param-" plus a parameter like "account"
*
* An implementation of mcp_account_storage_get().
*
* Returns: %TRUE if @storage is responsible for @account
*/
/**
* mcp_account_storage_get:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: the unique name of the account
* @key: the setting whose value we wish to fetch: either an attribute
* like "DisplayName", or "param-" plus a parameter like "account"
*
* Get a value from the plugin's in-memory cache.
* Before emitting this signal, the plugin must call
* either mcp_account_manager_set_attribute(),
* mcp_account_manager_set_parameter(),
* or mcp_account_manager_set_value()
* before returning from this method call.
*
* Note that mcp_account_manager_set_parameter() does not use the
* "param-" prefix, even if called from this function.
*
* If @key is %NULL the plugin should iterate through all attributes and
* parameters, and push each of them into @am, as if this method had
* been called once for each attribute or parameter. It must then return
* %TRUE if any attributes or parameters were found, or %FALSE if it
* was not responsible for @account.
*
* Returns: %TRUE if @storage is responsible for @account
*/
gboolean
mcp_account_storage_get (const McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account,
const gchar *key)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->get != NULL, FALSE);
return iface->get (storage, am, account, key);
}
/**
* mcp_account_storage_set_attribute:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: the unique name of the account
* @attribute: the name of an attribute, e.g. "DisplayName"
* @value: a value to associate with @attribute
* @flags: flags influencing how the attribute is to be stored
*
* Store an attribute.
*
* The plugin is expected to either quickly and synchronously
* update its internal cache of values with @value, or to
* decline to store the attribute.
*
* The plugin is not expected to write to its long term storage
* at this point.
*
* There is a default implementation, which just returns %FALSE for read-only
* storage plugins.
*
* Returns: %TRUE if the attribute was claimed, %FALSE otherwise
*
* Since: 5.15.0
*/
gboolean
mcp_account_storage_set_attribute (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account,
const gchar *attribute,
GVariant *value,
McpAttributeFlags flags)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->set_attribute != NULL, FALSE);
return iface->set_attribute (storage, am, account, attribute, value, flags);
}
/**
* mcp_account_storage_set_parameter:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: the unique name of the account
* @parameter: the name of a parameter, e.g. "account" (note that there
* is no "param-" prefix here)
* @value: a value to associate with @parameter
* @flags: flags influencing how the parameter is to be stored
*
* Store a parameter.
*
* The plugin is expected to either quickly and synchronously
* update its internal cache of values with @value, or to
* decline to store the parameter.
*
* The plugin is not expected to write to its long term storage
* at this point.
*
* There is a default implementation, which just returns %FALSE for read-only
* storage plugins.
*
* Returns: %TRUE if the parameter was claimed, %FALSE otherwise
*
* Since: 5.15.0
*/
gboolean
mcp_account_storage_set_parameter (McpAccountStorage *storage,
McpAccountManager *am,
const gchar *account,
const gchar *parameter,
GVariant *value,
McpParameterFlags flags)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->set_parameter != NULL, FALSE);
return iface->set_parameter (storage, am, account, parameter, value, flags);
}
/**
* McpAccountStorageCreate:
* @storage: an #McpAccountStorage instance
* @am: an object which can be used to call back into the account manager
* @manager: the name of the manager
* @protocol: the name of the protocol
* @params: A gchar * / GValue * hash table of account parameters
* @error: a GError to fill
*
* An implementation of mcp_account_storage_create()
*
* Returns: (transfer full): the account name or %NULL
*/
/**
* mcp_account_storage_create:
* @storage: an #McpAccountStorage instance
* @am: an object which can be used to call back into the account manager
* @manager: the name of the manager
* @protocol: the name of the protocol
* @identification: a normalized form of the account name, or "account"
* if nothing is suitable (e.g. for telepathy-salut)
* @error: a GError to fill
*
* Inform the plugin that a new account is being created. @manager, @protocol
* and @identification are given to help determining the account's unique name,
* but does not need to be stored on the account yet, mcp_account_storage_set()
* and mcp_account_storage_commit() will be called later.
*
* It is recommended to use mcp_account_manager_get_unique_name() to create the
* unique name, but it's not mandatory. One could base the unique name on an
* internal storage identifier, prefixed with the provider's name
* (e.g. goa__1234).
*
* #McpAccountStorage::created signal should not be emitted for this account,
* not even when mcp_account_storage_commit() will be called.
*
* There is a default implementation, which just returns %NULL and raise an
* error.
*
* Returns: (transfer full): the newly allocated account name, which should
* be freed once the caller is done with it, or %NULL if that couldn't
* be done.
*/
gchar *
mcp_account_storage_create (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *manager,
const gchar *protocol,
const gchar *identification,
GError **error)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (iface->create != NULL, NULL);
return iface->create (storage, am, manager, protocol, identification, error);
}
/**
* McpAccountStorageDeleteFunc:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: the unique name of the account
* @key: (allow-none): the setting whose value we wish to store - either an
* attribute like "DisplayName", or "param-" plus a parameter like
* "account" - or %NULL to delete the entire account
*
* An implementation of mcp_account_storage_delete().
*
* Returns: %TRUE if the setting or settings are not
* the plugin's cache after this operation, %FALSE otherwise.
*/
/**
* mcp_account_storage_delete:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: the unique name of the account
* @key: (allow-none): the setting whose value we wish to store - either an
* attribute like "DisplayName", or "param-" plus a parameter like
* "account" - or %NULL to delete the entire account
*
* The plugin is expected to remove the setting for @key from its
* internal cache and to remember that its state has changed, so
* that it can delete said setting from its long term storage if
* its long term storage method makes this necessary.
*
* If @key is %NULL, the plugin should forget all its settings for
* @account,and remember to delete the entire account from its storage later.
*
* The plugin is not expected to update its long term storage at
* this point.
*
* There is a default implementation, which just returns %FALSE, for read-only
* plugins.
*
* Returns: %TRUE if the setting or settings are not
* the plugin's cache after this operation, %FALSE otherwise.
* This is very unlikely to ever be %FALSE, as a plugin is always
* expected to be able to manipulate its own cache.
*/
gboolean
mcp_account_storage_delete (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *account,
const gchar *key)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->delete != NULL, FALSE);
return iface->delete (storage, am, account, key);
}
/**
* McpAccountStorageCommitFunc:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: (allow-none): the unique suffix of an account's object path,
* or %NULL
*
* An implementation of mcp_account_storage_commit().
*
* Returns: %TRUE if the commit process was started successfully
*/
/**
* mcp_account_storage_commit:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
* @account: (allow-none): the unique suffix of an account's object path,
* or %NULL if all accounts are to be committed
*
* The plugin is expected to write its cache to long term storage,
* deleting, adding or updating entries in said storage as needed.
*
* This call is expected to return promptly, but the plugin is
* not required to have finished its commit operation when it returns,
* merely to have started the operation.
*
* If @account = %NULL it means that it should commit all accounts owned by the
* storage plugin.
*
* A default implementation that simply returns %FALSE is provided for read-only
* plugins.
*
* Returns: %TRUE if the commit process was started (but not necessarily
* completed) successfully; %FALSE if there was a problem that was immediately
* obvious.
*/
gboolean
mcp_account_storage_commit (const McpAccountStorage *storage,
const McpAccountManager *am,
const gchar *account)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "called for %s", account ? account : "<all accounts>");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->commit != NULL, FALSE);
return iface->commit (storage, am, account);
}
/**
* McpAccountStorageListFunc:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
*
* An implementation of mcp_account_storage_list().
*
* Returns: (transfer full): a list of account names
*/
/**
* mcp_account_storage_list:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
*
* Load details of every account stored by this plugin into an in-memory cache
* so that it can respond to requests promptly.
*
* This method is called only at initialisation time, before the dbus name
* has been claimed, and is the only one permitted to block.
*
* Returns: (element-type utf8) (transfer full): a list of account names that
* the plugin has settings for. The account names should be freed with
* g_free(), and the list with g_list_free(), when the caller is done with
* them.
*/
GList *
mcp_account_storage_list (const McpAccountStorage *storage,
const McpAccountManager *am)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, NULL);
g_return_val_if_fail (iface->list != NULL, NULL);
return iface->list (storage, am);
}
/**
* McpAccountStorageReadyFunc:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
*
* An implementation of mcp_account_storage_ready().
*/
/**
* mcp_account_storage_ready:
* @storage: an #McpAccountStorage instance
* @am: an #McpAccountManager instance
*
* Informs the plugin that it is now permitted to create new accounts,
* ie it can now fire its "created", "altered-one", "toggled" and "deleted"
* signals.
*
* There is a default implementation for plugins that can't create accounts from
* external sources, as they can never fire the async account change signals.
*/
void
mcp_account_storage_ready (const McpAccountStorage *storage,
const McpAccountManager *am)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_if_fail (iface != NULL);
g_return_if_fail (iface->ready != NULL);
iface->ready (storage, am);
}
/**
* McpAccountStorageGetIdentifierFunc:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
* @identifier: (out caller-allocates): a zero-filled #GValue whose type
* can be sent over D-Bus by dbus-glib, to hold the identifier.
*
* An implementation of mcp_account_storage_get_identifier().
*/
/**
* mcp_account_storage_get_identifier:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
* @identifier: (out caller-allocates): a zero-filled #GValue whose type
* can be sent over D-Bus by dbus-glib, to hold the identifier.
*
* Get the storage-specific identifier for this account. The type is variant,
* hence the GValue.
*
* This method will only be called for the storage plugin that "owns"
* the account.
*
* There is default implementation that sets @identifier to @account string.
*/
void
mcp_account_storage_get_identifier (const McpAccountStorage *storage,
const gchar *account,
GValue *identifier)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_if_fail (iface != NULL);
g_return_if_fail (iface->get_identifier != NULL);
g_return_if_fail (identifier != NULL);
g_return_if_fail (!G_IS_VALUE (identifier));
iface->get_identifier (storage, account, identifier);
}
/**
* McpAccountStorageGetAdditionalInfoFunc
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
*
* An implementation of mcp_account_storage_get_identifier().
*
* Returns: (transfer container) (element-type utf8 GObject.Value): additional
* storage-specific information
*/
/**
* mcp_account_storage_get_additional_info:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
*
* Return additional storage-specific information about this account, which is
* made available on D-Bus but not otherwise interpreted by Mission Control.
*
* This method will only be called for the storage plugin that "owns"
* the account.
*
* There is a default implementation that return an empty table.
*
* Returns: (transfer container) (element-type utf8 GObject.Value): additional
* storage-specific information
*/
GHashTable *
mcp_account_storage_get_additional_info (const McpAccountStorage *storage,
const gchar *account)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
SDEBUG (storage, "");
g_return_val_if_fail (iface != NULL, FALSE);
g_return_val_if_fail (iface->get_additional_info != NULL, FALSE);
return iface->get_additional_info (storage, account);
}
/**
* McpAccountStorageGetRestrictionsFunc
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
*
* An implementation of mcp_account_storage_get_restrictions().
*
* Returns: any restrictions that apply to this account.
*/
/**
* mcp_account_storage_get_restrictions:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
*
* This method will only be called for the storage plugin that "owns"
* the account.
*
* There is a default implementation that just return 0 (no restrictions).
*
* Returns: a bitmask of %TpStorageRestrictionFlags with the restrictions to
* account storage.
*/
TpStorageRestrictionFlags
mcp_account_storage_get_restrictions (const McpAccountStorage *storage,
const gchar *account)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_val_if_fail (iface != NULL, 0);
g_return_val_if_fail (iface->get_restrictions != NULL, 0);
return iface->get_restrictions (storage, account);
}
/**
* mcp_account_storage_name:
* @storage: an #McpAccountStorage instance
*
* <!-- nothing else to say -->
*
* Returns: the plugin's name (for logging etc)
*/
const gchar *
mcp_account_storage_name (const McpAccountStorage *storage)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_val_if_fail (iface != NULL, NULL);
return iface->name;
}
/**
* mcp_account_storage_description:
* @storage: an #McpAccountStorage instance
*
* <!-- nothing else to say -->
*
* Returns: the plugin's description (for logging etc)
*/
const gchar *
mcp_account_storage_description (const McpAccountStorage *storage)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_val_if_fail (iface != NULL, NULL);
return iface->desc;
}
/**
* mcp_account_storage_provider:
* @storage: an #McpAccountStorage instance
*
* <!-- nothing else to say -->
*
* Returns: a D-Bus namespaced name for this plugin, or "" if none
* was provided in #McpAccountStorageIface.provider.
*/
const gchar *
mcp_account_storage_provider (const McpAccountStorage *storage)
{
McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
g_return_val_if_fail (iface != NULL, NULL);
return iface->provider != NULL ? iface->provider : "";
}
/**
* mcp_account_storage_emit_created:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the created account
*
* Emits the #McpAccountStorage::created signal.
*/
void
mcp_account_storage_emit_created (McpAccountStorage *storage,
const gchar *account)
{
g_signal_emit (storage, signals[CREATED], 0, account);
}
/**
* mcp_account_storage_emit_altered_one:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the altered account
* @key: the key of the altered property: either an attribute name
* like "DisplayName", or "param-" plus a parameter name like "account"
*
* Emits the #McpAccountStorage::altered-one signal
*/
void
mcp_account_storage_emit_altered_one (McpAccountStorage *storage,
const gchar *account,
const gchar *key)
{
g_signal_emit (storage, signals[ALTERED_ONE], 0, account, key);
}
/**
* mcp_account_storage_emit_deleted:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the deleted account
*
* Emits the #McpAccountStorage::deleted signal
*/
void
mcp_account_storage_emit_deleted (McpAccountStorage *storage,
const gchar *account)
{
g_signal_emit (storage, signals[DELETED], 0, account);
}
/**
* mcp_account_storage_emit_toggled:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account
* @enabled: %TRUE if the account is now enabled
*
* Emits ::toggled signal
*/
void
mcp_account_storage_emit_toggled (McpAccountStorage *storage,
const gchar *account,
gboolean enabled)
{
g_signal_emit (storage, signals[TOGGLED], 0, account, enabled);
}
/**
* mcp_account_storage_emit_reconnect:
* @storage: an #McpAccountStorage instance
* @account: the unique name of the account to reconnect
*
* Emits ::reconnect signal
*/
void
mcp_account_storage_emit_reconnect (McpAccountStorage *storage,
const gchar *account)
{
g_signal_emit (storage, signals[RECONNECT], 0, account);
}
|