2
* Copyright (C) 2010 Robert Ancell.
3
* Author: Robert Ancell <robert.ancell@canonical.com>
5
* This program is free software: you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License as published by the Free Software
7
* Foundation, either version 3 of the License, or (at your option) any later
8
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
14
#include <webkit/webkit.h>
15
#include <JavaScriptCore/JavaScript.h>
16
#include <glib/gi18n.h>
20
static JSClassRef gettext_class, ldm_greeter_class, ldm_user_class, ldm_language_class, ldm_layout_class, ldm_session_class;
22
static GtkWidget *window;
25
show_prompt_cb (LdmGreeter *greeter, const gchar *text, WebKitWebView *view)
29
command = g_strdup_printf ("show_prompt('%s')", text); // FIXME: Escape text
30
webkit_web_view_execute_script (view, command);
35
show_message_cb (LdmGreeter *greeter, const gchar *text, WebKitWebView *view)
39
command = g_strdup_printf ("show_message('%s')", text); // FIXME: Escape text
40
webkit_web_view_execute_script (view, command);
45
authentication_complete_cb (LdmGreeter *greeter, WebKitWebView *view)
47
webkit_web_view_execute_script (view, "authentication_complete()");
51
timed_login_cb (LdmGreeter *greeter, const gchar *username, WebKitWebView *view)
55
command = g_strdup_printf ("timed_login('%s')", username); // FIXME: Escape text
56
webkit_web_view_execute_script (view, command);
61
fade_timer_cb (gpointer data)
65
opacity = gtk_window_get_opacity (GTK_WINDOW (window));
72
gtk_window_set_opacity (GTK_WINDOW (window), opacity);
78
quit_cb (LdmGreeter *greeter, const gchar *username)
80
/* Fade out the greeter */
81
g_timeout_add (40, (GSourceFunc) fade_timer_cb, NULL);
85
get_user_name_cb (JSContextRef context,
86
JSObjectRef thisObject,
87
JSStringRef propertyName,
88
JSValueRef *exception)
90
LdmUser *user = JSObjectGetPrivate (thisObject);
93
string = JSStringCreateWithUTF8CString (ldm_user_get_name (user));
94
return JSValueMakeString (context, string);
98
get_user_real_name_cb (JSContextRef context,
99
JSObjectRef thisObject,
100
JSStringRef propertyName,
101
JSValueRef *exception)
103
LdmUser *user = JSObjectGetPrivate (thisObject);
106
string = JSStringCreateWithUTF8CString (ldm_user_get_real_name (user));
107
return JSValueMakeString (context, string);
111
get_user_display_name_cb (JSContextRef context,
112
JSObjectRef thisObject,
113
JSStringRef propertyName,
114
JSValueRef *exception)
116
LdmUser *user = JSObjectGetPrivate (thisObject);
119
string = JSStringCreateWithUTF8CString (ldm_user_get_display_name (user));
120
return JSValueMakeString (context, string);
124
get_user_image_cb (JSContextRef context,
125
JSObjectRef thisObject,
126
JSStringRef propertyName,
127
JSValueRef *exception)
129
LdmUser *user = JSObjectGetPrivate (thisObject);
132
string = JSStringCreateWithUTF8CString (ldm_user_get_image (user));
133
return JSValueMakeString (context, string);
137
get_user_language_cb (JSContextRef context,
138
JSObjectRef thisObject,
139
JSStringRef propertyName,
140
JSValueRef *exception)
142
LdmUser *user = JSObjectGetPrivate (thisObject);
143
const gchar *language = ldm_user_get_language (user);
147
return JSValueMakeNull (context);
149
string = JSStringCreateWithUTF8CString (language);
150
return JSValueMakeString (context, string);
154
get_user_layout_cb (JSContextRef context,
155
JSObjectRef thisObject,
156
JSStringRef propertyName,
157
JSValueRef *exception)
159
LdmUser *user = JSObjectGetPrivate (thisObject);
160
const gchar *layout = ldm_user_get_layout (user);
164
return JSValueMakeNull (context);
166
string = JSStringCreateWithUTF8CString (layout);
167
return JSValueMakeString (context, string);
171
get_user_session_cb (JSContextRef context,
172
JSObjectRef thisObject,
173
JSStringRef propertyName,
174
JSValueRef *exception)
176
LdmUser *user = JSObjectGetPrivate (thisObject);
177
const gchar *session = ldm_user_get_session (user);
181
return JSValueMakeNull (context);
183
string = JSStringCreateWithUTF8CString (session);
184
return JSValueMakeString (context, string);
188
get_user_logged_in_cb (JSContextRef context,
189
JSObjectRef thisObject,
190
JSStringRef propertyName,
191
JSValueRef *exception)
193
LdmUser *user = JSObjectGetPrivate (thisObject);
194
return JSValueMakeBoolean (context, ldm_user_get_logged_in (user));
198
get_language_code_cb (JSContextRef context,
199
JSObjectRef thisObject,
200
JSStringRef propertyName,
201
JSValueRef *exception)
203
LdmLanguage *language = JSObjectGetPrivate (thisObject);
206
string = JSStringCreateWithUTF8CString (ldm_language_get_code (language));
207
return JSValueMakeString (context, string);
211
get_language_name_cb (JSContextRef context,
212
JSObjectRef thisObject,
213
JSStringRef propertyName,
214
JSValueRef *exception)
216
LdmLanguage *language = JSObjectGetPrivate (thisObject);
219
string = JSStringCreateWithUTF8CString (ldm_language_get_name (language));
220
return JSValueMakeString (context, string);
224
get_language_territory_cb (JSContextRef context,
225
JSObjectRef thisObject,
226
JSStringRef propertyName,
227
JSValueRef *exception)
229
LdmLanguage *language = JSObjectGetPrivate (thisObject);
232
string = JSStringCreateWithUTF8CString (ldm_language_get_territory (language));
233
return JSValueMakeString (context, string);
237
get_layout_name_cb (JSContextRef context,
238
JSObjectRef thisObject,
239
JSStringRef propertyName,
240
JSValueRef *exception)
242
LdmLayout *layout = JSObjectGetPrivate (thisObject);
245
string = JSStringCreateWithUTF8CString (ldm_layout_get_name (layout));
246
return JSValueMakeString (context, string);
250
get_layout_short_description_cb (JSContextRef context,
251
JSObjectRef thisObject,
252
JSStringRef propertyName,
253
JSValueRef *exception)
255
LdmLayout *layout = JSObjectGetPrivate (thisObject);
258
string = JSStringCreateWithUTF8CString (ldm_layout_get_short_description (layout));
259
return JSValueMakeString (context, string);
263
get_layout_description_cb (JSContextRef context,
264
JSObjectRef thisObject,
265
JSStringRef propertyName,
266
JSValueRef *exception)
268
LdmLayout *layout = JSObjectGetPrivate (thisObject);
271
string = JSStringCreateWithUTF8CString (ldm_layout_get_description (layout));
272
return JSValueMakeString (context, string);
276
get_session_key_cb (JSContextRef context,
277
JSObjectRef thisObject,
278
JSStringRef propertyName,
279
JSValueRef *exception)
281
LdmSession *session = JSObjectGetPrivate (thisObject);
284
string = JSStringCreateWithUTF8CString (ldm_session_get_key (session));
285
return JSValueMakeString (context, string);
289
get_session_name_cb (JSContextRef context,
290
JSObjectRef thisObject,
291
JSStringRef propertyName,
292
JSValueRef *exception)
294
LdmSession *session = JSObjectGetPrivate (thisObject);
297
string = JSStringCreateWithUTF8CString (ldm_session_get_name (session));
298
return JSValueMakeString (context, string);
302
get_session_comment_cb (JSContextRef context,
303
JSObjectRef thisObject,
304
JSStringRef propertyName,
305
JSValueRef *exception)
307
LdmSession *session = JSObjectGetPrivate (thisObject);
310
string = JSStringCreateWithUTF8CString (ldm_session_get_comment (session));
311
return JSValueMakeString (context, string);
315
get_hostname_cb (JSContextRef context,
316
JSObjectRef thisObject,
317
JSStringRef propertyName,
318
JSValueRef *exception)
320
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
323
string = JSStringCreateWithUTF8CString (ldm_greeter_get_hostname (greeter));
325
return JSValueMakeString (context, string);
329
get_num_users_cb (JSContextRef context,
330
JSObjectRef thisObject,
331
JSStringRef propertyName,
332
JSValueRef *exception)
334
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
337
num_users = ldm_greeter_get_num_users (greeter);
338
return JSValueMakeNumber (context, num_users);
342
get_users_cb (JSContextRef context,
343
JSObjectRef thisObject,
344
JSStringRef propertyName,
345
JSValueRef *exception)
347
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
349
const GList *users, *link;
350
guint i, n_users = 0;
353
users = ldm_greeter_get_users (greeter);
354
n_users = g_list_length ((GList *)users);
355
args = g_malloc (sizeof (JSValueRef) * (n_users + 1));
356
for (i = 0, link = users; link; i++, link = link->next)
358
LdmUser *user = link->data;
360
args[i] = JSObjectMake (context, ldm_user_class, user);
363
array = JSObjectMakeArray (context, n_users, args, NULL);
369
get_languages_cb (JSContextRef context,
370
JSObjectRef thisObject,
371
JSStringRef propertyName,
372
JSValueRef *exception)
374
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
376
const GList *languages, *link;
377
guint i, n_languages = 0;
380
languages = ldm_greeter_get_languages (greeter);
381
n_languages = g_list_length ((GList *)languages);
382
args = g_malloc (sizeof (JSValueRef) * (n_languages + 1));
383
for (i = 0, link = languages; link; i++, link = link->next)
385
LdmLanguage *language = link->data;
386
g_object_ref (language);
387
args[i] = JSObjectMake (context, ldm_language_class, language);
390
array = JSObjectMakeArray (context, n_languages, args, NULL);
396
get_default_language_cb (JSContextRef context,
397
JSObjectRef thisObject,
398
JSStringRef propertyName,
399
JSValueRef *exception)
401
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
404
string = JSStringCreateWithUTF8CString (ldm_greeter_get_default_language (greeter));
406
return JSValueMakeString (context, string);
410
get_default_layout_cb (JSContextRef context,
411
JSObjectRef thisObject,
412
JSStringRef propertyName,
413
JSValueRef *exception)
415
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
418
string = JSStringCreateWithUTF8CString (ldm_greeter_get_default_layout (greeter));
420
return JSValueMakeString (context, string);
424
get_layouts_cb (JSContextRef context,
425
JSObjectRef thisObject,
426
JSStringRef propertyName,
427
JSValueRef *exception)
429
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
431
const GList *layouts, *link;
432
guint i, n_layouts = 0;
435
layouts = ldm_greeter_get_layouts (greeter);
436
n_layouts = g_list_length ((GList *)layouts);
437
args = g_malloc (sizeof (JSValueRef) * (n_layouts + 1));
438
for (i = 0, link = layouts; link; i++, link = link->next)
440
LdmLayout *layout = link->data;
441
g_object_ref (layout);
442
args[i] = JSObjectMake (context, ldm_layout_class, layout);
445
array = JSObjectMakeArray (context, n_layouts, args, NULL);
451
get_layout_cb (JSContextRef context,
452
JSObjectRef thisObject,
453
JSStringRef propertyName,
454
JSValueRef *exception)
456
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
459
string = JSStringCreateWithUTF8CString (ldm_greeter_get_layout (greeter));
461
return JSValueMakeString (context, string);
465
set_layout_cb (JSContextRef context,
466
JSObjectRef thisObject,
467
JSStringRef propertyName,
469
JSValueRef *exception)
471
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
472
JSStringRef layout_arg;
475
// FIXME: Throw exception
476
if (JSValueGetType (context, value) != kJSTypeString)
479
layout_arg = JSValueToStringCopy (context, value, NULL);
480
JSStringGetUTF8CString (layout_arg, layout, 1024);
481
JSStringRelease (layout_arg);
483
ldm_greeter_set_layout (greeter, layout);
489
get_sessions_cb (JSContextRef context,
490
JSObjectRef thisObject,
491
JSStringRef propertyName,
492
JSValueRef *exception)
494
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
496
const GList *sessions, *link;
497
guint i, n_sessions = 0;
500
sessions = ldm_greeter_get_sessions (greeter);
501
n_sessions = g_list_length ((GList *)sessions);
502
args = g_malloc (sizeof (JSValueRef) * (n_sessions + 1));
503
for (i = 0, link = sessions; link; i++, link = link->next)
505
LdmSession *session = link->data;
506
g_object_ref (session);
507
args[i] = JSObjectMake (context, ldm_session_class, session);
510
array = JSObjectMakeArray (context, n_sessions, args, NULL);
516
get_default_session_cb (JSContextRef context,
517
JSObjectRef thisObject,
518
JSStringRef propertyName,
519
JSValueRef *exception)
521
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
524
string = JSStringCreateWithUTF8CString (ldm_greeter_get_default_session (greeter));
526
return JSValueMakeString (context, string);
530
get_timed_login_user_cb (JSContextRef context,
531
JSObjectRef thisObject,
532
JSStringRef propertyName,
533
JSValueRef *exception)
535
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
538
string = JSStringCreateWithUTF8CString (ldm_greeter_get_timed_login_user (greeter));
540
return JSValueMakeString (context, string);
544
get_timed_login_delay_cb (JSContextRef context,
545
JSObjectRef thisObject,
546
JSStringRef propertyName,
547
JSValueRef *exception)
549
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
552
delay = ldm_greeter_get_timed_login_delay (greeter);
553
return JSValueMakeNumber (context, delay);
557
get_string_property_cb (JSContextRef context,
558
JSObjectRef function,
559
JSObjectRef thisObject,
560
size_t argumentCount,
561
const JSValueRef arguments[],
562
JSValueRef *exception)
564
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
565
JSStringRef name_arg;
570
// FIXME: Throw exception
571
if (argumentCount != 1)
572
return JSValueMakeNull (context);
574
name_arg = JSValueToStringCopy (context, arguments[0], NULL);
575
JSStringGetUTF8CString (name_arg, name, 1024);
576
JSStringRelease (name_arg);
578
value = ldm_greeter_get_string_property (greeter, name);
581
return JSValueMakeNull (context);
583
string = JSStringCreateWithUTF8CString (value);
585
return JSValueMakeString (context, string);
589
get_integer_property_cb (JSContextRef context,
590
JSObjectRef function,
591
JSObjectRef thisObject,
592
size_t argumentCount,
593
const JSValueRef arguments[],
594
JSValueRef *exception)
596
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
597
JSStringRef name_arg;
600
// FIXME: Throw exception
601
if (argumentCount != 1)
602
return JSValueMakeNull (context);
604
name_arg = JSValueToStringCopy (context, arguments[0], NULL);
605
JSStringGetUTF8CString (name_arg, name, 1024);
606
JSStringRelease (name_arg);
608
return JSValueMakeNumber (context, ldm_greeter_get_integer_property (greeter, name));
612
get_boolean_property_cb (JSContextRef context,
613
JSObjectRef function,
614
JSObjectRef thisObject,
615
size_t argumentCount,
616
const JSValueRef arguments[],
617
JSValueRef *exception)
619
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
620
JSStringRef name_arg;
623
// FIXME: Throw exception
624
if (argumentCount != 1)
625
return JSValueMakeNull (context);
627
name_arg = JSValueToStringCopy (context, arguments[0], NULL);
628
JSStringGetUTF8CString (name_arg, name, 1024);
629
JSStringRelease (name_arg);
631
return JSValueMakeBoolean (context, ldm_greeter_get_boolean_property (greeter, name));
635
cancel_timed_login_cb (JSContextRef context,
636
JSObjectRef function,
637
JSObjectRef thisObject,
638
size_t argumentCount,
639
const JSValueRef arguments[],
640
JSValueRef *exception)
642
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
644
// FIXME: Throw exception
645
if (argumentCount != 0)
646
return JSValueMakeNull (context);
648
ldm_greeter_cancel_timed_login (greeter);
649
return JSValueMakeNull (context);
653
start_authentication_cb (JSContextRef context,
654
JSObjectRef function,
655
JSObjectRef thisObject,
656
size_t argumentCount,
657
const JSValueRef arguments[],
658
JSValueRef *exception)
660
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
661
JSStringRef name_arg;
664
// FIXME: Throw exception
665
if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString))
666
return JSValueMakeNull (context);
668
name_arg = JSValueToStringCopy (context, arguments[0], NULL);
669
JSStringGetUTF8CString (name_arg, name, 1024);
670
JSStringRelease (name_arg);
672
ldm_greeter_start_authentication (greeter, name);
673
return JSValueMakeNull (context);
677
provide_secret_cb (JSContextRef context,
678
JSObjectRef function,
679
JSObjectRef thisObject,
680
size_t argumentCount,
681
const JSValueRef arguments[],
682
JSValueRef *exception)
684
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
685
JSStringRef secret_arg;
688
// FIXME: Throw exception
689
if (!(argumentCount == 1 && JSValueGetType (context, arguments[0]) == kJSTypeString))
690
return JSValueMakeNull (context);
692
secret_arg = JSValueToStringCopy (context, arguments[0], NULL);
693
JSStringGetUTF8CString (secret_arg, secret, 1024);
694
JSStringRelease (secret_arg);
696
ldm_greeter_provide_secret (greeter, secret);
697
return JSValueMakeNull (context);
701
cancel_authentication_cb (JSContextRef context,
702
JSObjectRef function,
703
JSObjectRef thisObject,
704
size_t argumentCount,
705
const JSValueRef arguments[],
706
JSValueRef *exception)
708
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
710
// FIXME: Throw exception
711
if (argumentCount != 0)
712
return JSValueMakeNull (context);
714
ldm_greeter_cancel_authentication (greeter);
715
return JSValueMakeNull (context);
719
get_authentication_user_cb (JSContextRef context,
720
JSObjectRef thisObject,
721
JSStringRef propertyName,
722
JSValueRef *exception)
724
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
725
return JSValueMakeString (context, JSStringCreateWithUTF8CString (ldm_greeter_get_authentication_user (greeter)));
729
get_is_authenticated_cb (JSContextRef context,
730
JSObjectRef thisObject,
731
JSStringRef propertyName,
732
JSValueRef *exception)
734
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
735
return JSValueMakeBoolean (context, ldm_greeter_get_is_authenticated (greeter));
739
get_can_suspend_cb (JSContextRef context,
740
JSObjectRef thisObject,
741
JSStringRef propertyName,
742
JSValueRef *exception)
744
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
745
return JSValueMakeBoolean (context, ldm_greeter_get_can_suspend (greeter));
749
suspend_cb (JSContextRef context,
750
JSObjectRef function,
751
JSObjectRef thisObject,
752
size_t argumentCount,
753
const JSValueRef arguments[],
754
JSValueRef *exception)
756
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
758
// FIXME: Throw exception
759
if (argumentCount != 0)
760
return JSValueMakeNull (context);
762
ldm_greeter_suspend (greeter);
763
return JSValueMakeNull (context);
767
get_can_hibernate_cb (JSContextRef context,
768
JSObjectRef thisObject,
769
JSStringRef propertyName,
770
JSValueRef *exception)
772
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
773
return JSValueMakeBoolean (context, ldm_greeter_get_can_hibernate (greeter));
777
hibernate_cb (JSContextRef context,
778
JSObjectRef function,
779
JSObjectRef thisObject,
780
size_t argumentCount,
781
const JSValueRef arguments[],
782
JSValueRef *exception)
784
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
786
// FIXME: Throw exception
787
if (argumentCount != 0)
788
return JSValueMakeNull (context);
790
ldm_greeter_hibernate (greeter);
791
return JSValueMakeNull (context);
795
get_can_restart_cb (JSContextRef context,
796
JSObjectRef thisObject,
797
JSStringRef propertyName,
798
JSValueRef *exception)
800
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
801
return JSValueMakeBoolean (context, ldm_greeter_get_can_restart (greeter));
805
restart_cb (JSContextRef context,
806
JSObjectRef function,
807
JSObjectRef thisObject,
808
size_t argumentCount,
809
const JSValueRef arguments[],
810
JSValueRef *exception)
812
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
814
// FIXME: Throw exception
815
if (argumentCount != 0)
816
return JSValueMakeNull (context);
818
ldm_greeter_restart (greeter);
819
return JSValueMakeNull (context);
823
get_can_shutdown_cb (JSContextRef context,
824
JSObjectRef thisObject,
825
JSStringRef propertyName,
826
JSValueRef *exception)
828
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
829
return JSValueMakeBoolean (context, ldm_greeter_get_can_shutdown (greeter));
833
shutdown_cb (JSContextRef context,
834
JSObjectRef function,
835
JSObjectRef thisObject,
836
size_t argumentCount,
837
const JSValueRef arguments[],
838
JSValueRef *exception)
840
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
842
// FIXME: Throw exception
843
if (argumentCount != 0)
844
return JSValueMakeNull (context);
846
ldm_greeter_shutdown (greeter);
847
return JSValueMakeNull (context);
851
login_cb (JSContextRef context,
852
JSObjectRef function,
853
JSObjectRef thisObject,
854
size_t argumentCount,
855
const JSValueRef arguments[],
856
JSValueRef *exception)
858
LdmGreeter *greeter = JSObjectGetPrivate (thisObject);
860
char username[1024], *session = NULL, *language = NULL;
862
// FIXME: Throw exception
863
if (argumentCount < 1 || argumentCount > 3)
864
return JSValueMakeNull (context);
866
arg = JSValueToStringCopy (context, arguments[0], NULL);
867
JSStringGetUTF8CString (arg, username, 1024);
868
JSStringRelease (arg);
870
if (argumentCount > 1)
872
arg = JSValueToStringCopy (context, arguments[1], NULL);
873
session = g_malloc (sizeof (char) * 1024);
874
JSStringGetUTF8CString (arg, session, 1024);
875
JSStringRelease (arg);
878
if (argumentCount > 2)
880
arg = JSValueToStringCopy (context, arguments[1], NULL);
881
language = g_malloc (sizeof (char) * 1024);
882
JSStringGetUTF8CString (arg, language, 1024);
883
JSStringRelease (arg);
886
ldm_greeter_login (greeter, username, session, language);
890
return JSValueMakeNull (context);
894
gettext_cb (JSContextRef context,
895
JSObjectRef function,
896
JSObjectRef thisObject,
897
size_t argumentCount,
898
const JSValueRef arguments[],
899
JSValueRef *exception)
901
JSStringRef string_arg, result;
904
// FIXME: Throw exception
905
if (argumentCount != 1)
906
return JSValueMakeNull (context);
908
string_arg = JSValueToStringCopy (context, arguments[0], NULL);
909
JSStringGetUTF8CString (string_arg, string, 1024);
910
JSStringRelease (string_arg);
912
result = JSStringCreateWithUTF8CString (gettext (string));
913
return JSValueMakeString (context, result);
917
ngettext_cb (JSContextRef context,
918
JSObjectRef function,
919
JSObjectRef thisObject,
920
size_t argumentCount,
921
const JSValueRef arguments[],
922
JSValueRef *exception)
924
JSStringRef string_arg, plural_string_arg, result;
925
char string[1024], plural_string[1024];
928
// FIXME: Throw exception
929
if (argumentCount != 3)
930
return JSValueMakeNull (context);
932
string_arg = JSValueToStringCopy (context, arguments[0], NULL);
933
JSStringGetUTF8CString (string_arg, string, 1024);
934
JSStringRelease (string_arg);
936
plural_string_arg = JSValueToStringCopy (context, arguments[1], NULL);
937
JSStringGetUTF8CString (plural_string_arg, string, 1024);
938
JSStringRelease (plural_string_arg);
940
n = JSValueToNumber (context, arguments[2], NULL);
942
result = JSStringCreateWithUTF8CString (ngettext (string, plural_string, n));
943
return JSValueMakeString (context, result);
946
static const JSStaticValue ldm_user_values[] =
948
{ "name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly },
949
{ "real_name", get_user_real_name_cb, NULL, kJSPropertyAttributeReadOnly },
950
{ "display_name", get_user_display_name_cb, NULL, kJSPropertyAttributeReadOnly },
951
{ "image", get_user_image_cb, NULL, kJSPropertyAttributeReadOnly },
952
{ "language", get_user_language_cb, NULL, kJSPropertyAttributeReadOnly },
953
{ "layout", get_user_layout_cb, NULL, kJSPropertyAttributeReadOnly },
954
{ "session", get_user_session_cb, NULL, kJSPropertyAttributeReadOnly },
955
{ "logged_in", get_user_logged_in_cb, NULL, kJSPropertyAttributeReadOnly },
956
{ NULL, NULL, NULL, 0 }
959
static const JSStaticValue ldm_language_values[] =
961
{ "code", get_language_code_cb, NULL, kJSPropertyAttributeReadOnly },
962
{ "name", get_language_name_cb, NULL, kJSPropertyAttributeReadOnly },
963
{ "territory", get_language_territory_cb, NULL, kJSPropertyAttributeReadOnly },
964
{ NULL, NULL, NULL, 0 }
967
static const JSStaticValue ldm_layout_values[] =
969
{ "name", get_layout_name_cb, NULL, kJSPropertyAttributeReadOnly },
970
{ "short_description", get_layout_short_description_cb, NULL, kJSPropertyAttributeReadOnly },
971
{ "description", get_layout_description_cb, NULL, kJSPropertyAttributeReadOnly },
972
{ NULL, NULL, NULL, 0 }
975
static const JSStaticValue ldm_session_values[] =
977
{ "key", get_session_key_cb, NULL, kJSPropertyAttributeReadOnly },
978
{ "name", get_session_name_cb, NULL, kJSPropertyAttributeReadOnly },
979
{ "comment", get_session_comment_cb, NULL, kJSPropertyAttributeReadOnly },
980
{ NULL, NULL, NULL, 0 }
983
static const JSStaticValue ldm_greeter_values[] =
985
{ "hostname", get_hostname_cb, NULL, kJSPropertyAttributeReadOnly },
986
{ "users", get_users_cb, NULL, kJSPropertyAttributeReadOnly },
987
{ "default_language", get_default_language_cb, NULL, kJSPropertyAttributeReadOnly },
988
{ "languages", get_languages_cb, NULL, kJSPropertyAttributeReadOnly },
989
{ "default_layout", get_default_layout_cb, NULL, kJSPropertyAttributeReadOnly },
990
{ "layouts", get_layouts_cb, NULL, kJSPropertyAttributeReadOnly },
991
{ "layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeReadOnly },
992
{ "sessions", get_sessions_cb, NULL, kJSPropertyAttributeReadOnly },
993
{ "num_users", get_num_users_cb, NULL, kJSPropertyAttributeReadOnly },
994
{ "default_session", get_default_session_cb, NULL, kJSPropertyAttributeNone },
995
{ "timed_login_user", get_timed_login_user_cb, NULL, kJSPropertyAttributeReadOnly },
996
{ "timed_login_delay", get_timed_login_delay_cb, NULL, kJSPropertyAttributeReadOnly },
997
{ "authentication_user", get_authentication_user_cb, NULL, kJSPropertyAttributeReadOnly },
998
{ "is_authenticated", get_is_authenticated_cb, NULL, kJSPropertyAttributeReadOnly },
999
{ "can_suspend", get_can_suspend_cb, NULL, kJSPropertyAttributeReadOnly },
1000
{ "can_hibernate", get_can_hibernate_cb, NULL, kJSPropertyAttributeReadOnly },
1001
{ "can_restart", get_can_restart_cb, NULL, kJSPropertyAttributeReadOnly },
1002
{ "can_shutdown", get_can_shutdown_cb, NULL, kJSPropertyAttributeReadOnly },
1003
{ NULL, NULL, NULL, 0 }
1006
static const JSStaticFunction ldm_greeter_functions[] =
1008
{ "get_string_property", get_string_property_cb, kJSPropertyAttributeReadOnly },
1009
{ "get_integer_property", get_integer_property_cb, kJSPropertyAttributeReadOnly },
1010
{ "get_boolean_property", get_boolean_property_cb, kJSPropertyAttributeReadOnly },
1011
{ "cancel_timed_login", cancel_timed_login_cb, kJSPropertyAttributeReadOnly },
1012
{ "start_authentication", start_authentication_cb, kJSPropertyAttributeReadOnly },
1013
{ "provide_secret", provide_secret_cb, kJSPropertyAttributeReadOnly },
1014
{ "cancel_authentication", cancel_authentication_cb, kJSPropertyAttributeReadOnly },
1015
{ "suspend", suspend_cb, kJSPropertyAttributeReadOnly },
1016
{ "hibernate", hibernate_cb, kJSPropertyAttributeReadOnly },
1017
{ "restart", restart_cb, kJSPropertyAttributeReadOnly },
1018
{ "shutdown", shutdown_cb, kJSPropertyAttributeReadOnly },
1019
{ "login", login_cb, kJSPropertyAttributeReadOnly },
1023
static const JSStaticFunction gettext_functions[] =
1025
{ "gettext", gettext_cb, kJSPropertyAttributeReadOnly },
1026
{ "ngettext", ngettext_cb, kJSPropertyAttributeReadOnly },
1030
static const JSClassDefinition ldm_user_definition =
1033
kJSClassAttributeNone, /* Attributes */
1034
"LdmUser", /* Class name */
1035
NULL, /* Parent class */
1036
ldm_user_values, /* Static values */
1039
static const JSClassDefinition ldm_language_definition =
1042
kJSClassAttributeNone, /* Attributes */
1043
"LdmLanguage", /* Class name */
1044
NULL, /* Parent class */
1045
ldm_language_values, /* Static values */
1048
static const JSClassDefinition ldm_layout_definition =
1051
kJSClassAttributeNone, /* Attributes */
1052
"LdmLayout", /* Class name */
1053
NULL, /* Parent class */
1054
ldm_layout_values, /* Static values */
1057
static const JSClassDefinition ldm_session_definition =
1060
kJSClassAttributeNone, /* Attributes */
1061
"LdmSession", /* Class name */
1062
NULL, /* Parent class */
1063
ldm_session_values, /* Static values */
1066
static const JSClassDefinition ldm_greeter_definition =
1069
kJSClassAttributeNone, /* Attributes */
1070
"LdmGreeter", /* Class name */
1071
NULL, /* Parent class */
1072
ldm_greeter_values, /* Static values */
1073
ldm_greeter_functions, /* Static functions */
1076
static const JSClassDefinition gettext_definition =
1079
kJSClassAttributeNone, /* Attributes */
1080
"GettextClass", /* Class name */
1081
NULL, /* Parent class */
1083
gettext_functions, /* Static functions */
1087
window_object_cleared_cb (WebKitWebView *web_view,
1088
WebKitWebFrame *frame,
1089
JSGlobalContextRef context,
1090
JSObjectRef window_object,
1091
LdmGreeter *greeter)
1093
JSObjectRef gettext_object, ldm_greeter_object;
1095
gettext_class = JSClassCreate (&gettext_definition);
1096
ldm_greeter_class = JSClassCreate (&ldm_greeter_definition);
1097
ldm_user_class = JSClassCreate (&ldm_user_definition);
1098
ldm_language_class = JSClassCreate (&ldm_language_definition);
1099
ldm_layout_class = JSClassCreate (&ldm_layout_definition);
1100
ldm_session_class = JSClassCreate (&ldm_session_definition);
1102
gettext_object = JSObjectMake (context, gettext_class, NULL);
1103
JSObjectSetProperty (context,
1104
JSContextGetGlobalObject (context),
1105
JSStringCreateWithUTF8CString ("gettext"),
1106
gettext_object, kJSPropertyAttributeNone, NULL);
1108
ldm_greeter_object = JSObjectMake (context, ldm_greeter_class, greeter);
1109
JSObjectSetProperty (context,
1110
JSContextGetGlobalObject (context),
1111
JSStringCreateWithUTF8CString ("lightdm"),
1112
ldm_greeter_object, kJSPropertyAttributeNone, NULL);
1116
sigterm_cb (int signum)
1122
main(int argc, char **argv)
1124
LdmGreeter *greeter;
1125
GdkDisplay *display;
1127
gint screen_width, screen_height;
1128
GtkWidget *web_view;
1131
signal (SIGTERM, sigterm_cb);
1133
gtk_init (&argc, &argv);
1136
g_printerr ("Usage: %s <url>\n", argv[0]);
1141
greeter = ldm_greeter_new ();
1143
display = gdk_display_get_default ();
1144
screen = gdk_display_get_default_screen (display);
1145
screen_width = gdk_screen_get_width (screen);
1146
screen_height = gdk_screen_get_height (screen);
1148
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1149
gtk_window_set_default_size (GTK_WINDOW (window), screen_width, screen_height);
1150
gtk_window_fullscreen (GTK_WINDOW (window));
1152
web_view = webkit_web_view_new ();
1153
g_signal_connect (G_OBJECT (web_view), "window-object-cleared", G_CALLBACK (window_object_cleared_cb), greeter);
1154
gtk_container_add (GTK_CONTAINER (window), web_view);
1156
g_signal_connect (G_OBJECT (greeter), "show-prompt", G_CALLBACK (show_prompt_cb), web_view);
1157
g_signal_connect (G_OBJECT (greeter), "show-message", G_CALLBACK (show_message_cb), web_view);
1158
g_signal_connect (G_OBJECT (greeter), "show-error", G_CALLBACK (show_message_cb), web_view);
1159
g_signal_connect (G_OBJECT (greeter), "authentication-complete", G_CALLBACK (authentication_complete_cb), web_view);
1160
g_signal_connect (G_OBJECT (greeter), "timed-login", G_CALLBACK (timed_login_cb), web_view);
1161
g_signal_connect (G_OBJECT (greeter), "quit", G_CALLBACK (quit_cb), web_view);
1163
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), url);
1164
ldm_greeter_connect (greeter);
1166
gtk_widget_show_all (window);