~bartbes/luomg/trunk

« back to all changes in this revision

Viewing changes to luomg.vala

  • Committer: Bart van Strien
  • Date: 2011-04-02 14:57:51 UTC
  • Revision ID: bart.bes@gmail.com-20110402145751-c64rwdf3pm0ydiar
Update to match cheers upstream updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2010 Bart van Strien <bart.bes@gmail.com>
 
1
/* Copyright (c) 2010-2011 Bart van Strien <bart.bes@gmail.com>
2
2
*
3
3
* Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
* of this software and associated documentation files (the "Software"), to deal
33
33
        return vm.to_string(n);
34
34
}
35
35
 
36
 
static int description_to_table(LuaVM vm, string[,] t)
 
36
static int multilang_table(LuaVM vm, multilang[] t)
37
37
{
38
38
        vm.new_table();
39
 
        for (int i = 0; i < t.length[0]; i++)
 
39
        for (int i = 0; i < t.length; i++)
40
40
        {
41
41
                vm.push_number(i+1);
42
42
                vm.new_table();
43
43
                vm.push_string("Language");
44
 
                vm.push_string(t[i,0]);
 
44
                vm.push_string(t[i].language);
45
45
                vm.set_table(-3);
46
46
                vm.push_string("Text");
47
 
                vm.push_string(t[i,1]);
 
47
                vm.push_string(t[i].text);
48
48
                vm.set_table(-3);
49
49
                vm.set_table(-3);
50
50
        }
58
58
        vm.push_string(t.id);
59
59
        vm.set_table(-3);
60
60
        vm.push_string("Title");
61
 
        vm.push_string(t.title);
 
61
        multilang_table(vm, t.title);
62
62
        vm.set_table(-3);
63
63
        vm.push_string("Description");
64
 
        description_to_table(vm, t.description);
65
 
        vm.set_table(-3);
66
 
        vm.push_string("IconPath");
67
 
        vm.push_string(t.icon_path);
 
64
        multilang_table(vm, t.description);
68
65
        vm.set_table(-3);
69
66
        vm.push_string("SetName");
70
67
        vm.push_string(t.set_name);
72
69
        vm.push_string("Application");
73
70
        vm.push_string(t.application);
74
71
        vm.set_table(-3);
75
 
        vm.push_string("ApplicationFriendlyName");
76
 
        vm.push_string(t.application_friendly_name);
77
 
        vm.set_table(-3);
78
 
        vm.push_string("Priority");
79
 
        vm.push_number(t.priority);
80
 
        vm.set_table(-3);
81
 
        vm.push_string("SetIcon");
82
 
        vm.push_string(t.set_icon);
 
72
        vm.push_string("Icon");
 
73
        vm.push_string(t.icon);
83
74
        vm.set_table(-3);
84
75
        vm.push_string("Unlocked");
85
76
        vm.push_boolean(t.unlocked ? 1 : 0);
86
77
        vm.set_table(-3);
87
 
        vm.push_string("Timestamp");
88
 
        vm.push_number(t.timestamp);
89
 
        vm.set_table(-3);
90
78
        vm.push_string("StockIcon");
91
79
        vm.push_string(t.stock_icon);
92
80
        vm.set_table(-3);
99
87
                string id = checkstring(vm, 1);
100
88
                omg.delete_trophy(id);
101
89
                return 0;
102
 
        } catch (DBus.Error e) {
 
90
        } catch (IOError e) {
103
91
                vm.push_nil();
104
92
                vm.push_string(e.message);
105
93
                return 2;
112
100
                string id = checkstring(vm, 1);
113
101
                omg.award_trophy(id);
114
102
                return 0;
115
 
        } catch (DBus.Error e) {
 
103
        } catch (IOError e) {
116
104
                vm.push_nil();
117
105
                vm.push_string(e.message);
118
106
                return 2;
125
113
                string id = checkstring(vm, 1);
126
114
                omg.un_award_trophy(id);
127
115
                return 0;
128
 
        } catch (DBus.Error e) {
 
116
        } catch (IOError e) {
129
117
                vm.push_nil();
130
118
                vm.push_string(e.message);
131
119
                return 2;
144
132
                        vm.set_table(-3);
145
133
                }
146
134
                return 1;
147
 
        } catch (DBus.Error e) {
 
135
        } catch (IOError e) {
148
136
                vm.push_nil();
149
137
                vm.push_string(e.message);
150
138
                return 2;
164
152
                        return 2;
165
153
                }
166
154
                return trophy_to_table(vm, t);
167
 
        } catch (DBus.Error e) {
 
155
        } catch (IOError e) {
168
156
                vm.push_nil();
169
157
                vm.push_string(e.message);
170
158
                return 2;
184
172
                        vm.set_table(-3);
185
173
                }
186
174
                return 1;
187
 
        } catch (DBus.Error e) {
 
175
        } catch (IOError e) {
188
176
                vm.push_nil();
189
177
                vm.push_string(e.message);
190
178
                return 2;
204
192
                        vm.set_table(-3);
205
193
                }
206
194
                return 1;
207
 
        } catch (DBus.Error e) {
 
195
        } catch (IOError e) {
208
196
                vm.push_nil();
209
197
                vm.push_string(e.message);
210
198
                return 2;
211
199
        }
212
200
}
213
201
 
214
 
static int get_all_set_names(LuaVM vm)
 
202
static int get_sets(LuaVM vm)
215
203
{
216
204
        try {
217
 
                string[] names = omg.get_all_set_names();
 
205
                string[] names = omg.get_sets();
218
206
                vm.new_table();
219
207
                for (int i = 0; i < names.length; i++)
220
208
                {
223
211
                        vm.set_table(-3);
224
212
                }
225
213
                return 1;
226
 
        } catch (DBus.Error e) {
 
214
        } catch (IOError e) {
227
215
                vm.push_nil();
228
216
                vm.push_string(e.message);
229
217
                return 2;
235
223
        try {
236
224
                omg.quit();
237
225
                return 0;
238
 
        } catch (DBus.Error e) {
 
226
        } catch (IOError e) {
 
227
                vm.push_nil();
 
228
                vm.push_string(e.message);
 
229
                return 2;
 
230
        }
 
231
}
 
232
 
 
233
static int get_awarded_trophies(LuaVM vm)
 
234
{
 
235
        try {
 
236
                trophy[] t = omg.get_awarded_trophies();
 
237
                vm.new_table();
 
238
                for (int i = 0; i < t.length; i++)
 
239
                {
 
240
                        vm.push_number(i+1);
 
241
                        trophy_to_table(vm, t[i]);
 
242
                        vm.set_table(-3);
 
243
                }
 
244
                return 1;
 
245
        } catch (IOError e) {
239
246
                vm.push_nil();
240
247
                vm.push_string(e.message);
241
248
                return 2;
245
252
static int real_luaopen_luomg(LuaVM vm)
246
253
{
247
254
        try {
248
 
                var conn = DBus.Bus.get(DBus.BusType.SESSION);
249
 
                omg = (omg_trophies) conn.get_object("org.gnome.cheers", "/org/gnome/cheers/trophies");
 
255
                omg = Bus.get_proxy_sync(BusType.SESSION, "com.cheersproject.cheers", "/com/cheersproject/cheers/trophies");
250
256
                vm.new_table();
251
257
                vm.push_string("DeleteTrophy");
252
258
                vm.push_cfunction(delete_trophy);
269
275
                vm.push_string("GetTrophyByApp");
270
276
                vm.push_cfunction(get_trophy_by_app);
271
277
                vm.set_table(-3);
272
 
                vm.push_string("GetAllSetNames");
273
 
                vm.push_cfunction(get_all_set_names);
 
278
                vm.push_string("GetSets");
 
279
                vm.push_cfunction(get_sets);
274
280
                vm.set_table(-3);
275
281
                vm.push_string("Quit");
276
282
                vm.push_cfunction(quit);
277
283
                vm.set_table(-3);
 
284
                vm.push_string("GetAwardedTrophies");
 
285
                vm.push_cfunction(get_awarded_trophies);
 
286
                vm.set_table(-3);
278
287
                vm.push_value(-1);
279
288
                vm.set_global("luomg");
280
289
                return 1;
281
 
        } catch (DBus.Error e) {
 
290
        } catch (IOError e) {
282
291
                stderr.printf("Failed\n");
283
292
        }
284
293
        return 0;