menu: added new Keywords tag to .desktop files
[barry.git] / desktop / src / oextract.cc
blob11abf83f2a4d036eba412b3b667ce22dd5230fab
1 //
2 // This is just experimentation code to figure out the config API in 0.4x
3 //
4 // Compile with:
5 // g++ -Wall -o oextract oextract.cc $(pkg-config --cflags --libs libopensync1)
6 //
8 #include <iostream>
9 #include <stdexcept>
10 #include <opensync/opensync.h>
11 #include <opensync/opensync-plugin.h>
12 #include <opensync/opensync-group.h>
13 using namespace std;
15 #define NP(x) (x ? x : "(null)")
17 OSyncGroupEnv *genv;
18 OSyncPluginEnv *penv;
20 void get_advanced(OSyncPluginConfig *config, const char *name)
22 cout << "Advanced: " << name << ": "
23 << NP(osync_plugin_config_get_advancedoption_value_by_name(config, name))
24 << endl;
27 void add_advanced(OSyncPluginConfig *config,
28 const char *name,
29 const char *display,
30 const char *value)
32 OSyncError *ose = NULL;
33 OSyncPluginAdvancedOption *option = osync_plugin_advancedoption_new(&ose);
34 if( !option ) throw "bad option";
35 osync_plugin_advancedoption_set_displayname(option, "Test Display Name");
36 osync_plugin_advancedoption_set_name(option, "TestName");
37 osync_plugin_advancedoption_set_type(option, OSYNC_PLUGIN_ADVANCEDOPTION_TYPE_STRING);
38 osync_plugin_advancedoption_set_value(option, "Whippoorwill");
39 osync_plugin_config_add_advancedoption(config, option);
40 osync_plugin_advancedoption_unref(option);
43 void dump_resource(OSyncPluginResource *res)
45 cout << "Resource: "
46 << NP(osync_plugin_resource_get_name(res))
47 << ": "
48 << (osync_plugin_resource_is_enabled(res) ? "enabled" : "disabled");
49 if( osync_plugin_resource_get_preferred_format(res) )
50 cout << "\n pref format: "
51 << osync_plugin_resource_get_preferred_format(res);
53 if( osync_plugin_resource_get_mime(res) )
54 cout << "\n mime: "
55 << NP(osync_plugin_resource_get_mime(res));
57 if( osync_plugin_resource_get_objtype(res) )
58 cout << "\n objtype: "
59 << NP(osync_plugin_resource_get_objtype(res));
61 if( osync_plugin_resource_get_path(res) )
62 cout << "\n path: "
63 << NP(osync_plugin_resource_get_path(res));
65 if( osync_plugin_resource_get_url(res) )
66 cout << "\n url: "
67 << NP(osync_plugin_resource_get_url(res));
68 osync_plugin_resource_set_url(res, "http://whoopiecushion/");
70 cout << endl;
73 void dump_resources(OSyncPluginConfig *config)
75 OSyncList *resources = osync_plugin_config_get_resources(config);
76 for( OSyncList *o = resources; o; o = o->next ) {
77 OSyncPluginResource *res = (OSyncPluginResource*) o->data;
78 dump_resource(res);
82 void test_member(OSyncGroup *group, int member_id)
84 OSyncError *ose = NULL;
86 cout << "Testing member: " << member_id << endl;
88 OSyncMember *member = osync_group_find_member(group, member_id);
89 if( !member ) throw "bad member id";
90 OSyncPlugin *plugin = osync_plugin_env_find_plugin(penv, osync_member_get_pluginname(member));
91 if( !plugin ) throw "bad plugin";
92 OSyncPluginConfig *config = osync_member_get_config_or_default(member, &ose);
93 if( !config ) throw "bad config";
95 // extract advanced fields
96 get_advanced(config, "PinCode");
97 get_advanced(config, "Debug");
99 // test add
100 add_advanced(config, "TestName", "Test Display Name", "Whippoorwill");
101 get_advanced(config, "TestName");
103 // extract resources
104 dump_resources(config);
106 // save new config
107 if( !osync_member_save(member, &ose) )
108 throw "bad member save";
110 // due to leak in library, I don't think this is safe to call?
111 //osync_plugin_config_unref(config);
114 void test()
116 OSyncError *ose = NULL;
118 // create
119 genv = osync_group_env_new(&ose);
120 if( !genv ) throw "bad genv";
121 penv = osync_plugin_env_new(&ose);
122 if( !penv ) throw "bad penv";
124 // load
125 if( !osync_group_env_load_groups(genv, NULL, &ose) )
126 throw "bad group load";
127 if( !osync_plugin_env_load(penv, NULL, &ose) )
128 throw "bad plugin load";
130 // find config
131 OSyncGroup *group = osync_group_env_find_group(genv, "test");
132 if( !group ) throw "bad group";
133 test_member(group, 1);
134 test_member(group, 2);
136 // clean up
137 osync_plugin_env_unref(penv);
138 osync_group_env_unref(genv);
141 int main()
143 try { test(); }
144 catch( const char *msg ) {
145 cout << "Exception: " << msg << endl;
146 return 1;