Browse Source

Previous four commits fixed #19 and yeah im ocd when it comes to code style/formatting 😬

sisyphus
Dustin Falgout 9 years ago
parent
commit
22c75d042e
  1. 97
      src/lightdm-webkit2-greeter-ext.c

97
src/lightdm-webkit2-greeter-ext.c

@ -47,6 +47,7 @@
G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension); G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension);
guint64 page_id = -1; guint64 page_id = -1;
GKeyFile *keyfile;
#define USER ((LightDMUser *) JSObjectGetPrivate (thisObject)) #define USER ((LightDMUser *) JSObjectGetPrivate (thisObject))
#define LAYOUT ((LightDMLayout *) JSObjectGetPrivate (thisObject)) #define LAYOUT ((LightDMLayout *) JSObjectGetPrivate (thisObject))
@ -61,9 +62,8 @@ static JSClassRef
lightdm_language_class, lightdm_language_class,
lightdm_layout_class, lightdm_layout_class,
lightdm_session_class, lightdm_session_class,
conffile_class; config_file_class;
GKeyFile *keyfile;
/* /*
* Returns either a string or null. * Returns either a string or null.
@ -1017,16 +1017,21 @@ ngettext_cb(JSContextRef context,
return result; return result;
} }
/*
* Gets a key's value from config file.
*
* Returns config key's value as string.
*/
static JSValueRef static JSValueRef
get_conf_str_cb(JSContextRef context, get_conf_str_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *section, *key, *value; gchar *section, *key, *value;
GError *err = NULL; GError *err = NULL;
JSValueRef result; JSValueRef result;
if (argumentCount != 2) { if (argumentCount != 2) {
@ -1040,14 +1045,9 @@ get_conf_str_cb(JSContextRef context,
} }
key = arg_to_string(context, arguments[1], exception); key = arg_to_string(context, arguments[1], exception);
if (!section) {
return JSValueMakeNull(context);
}
value = g_key_file_get_string(keyfile, section, key, &err); value = g_key_file_get_string(keyfile, section, key, &err);
if (err) { if (err) {
_mkexception(context, exception, err->message); _mkexception(context, exception, err->message);
g_error_free(err); g_error_free(err);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -1060,17 +1060,23 @@ get_conf_str_cb(JSContextRef context,
return result; return result;
} }
/*
* Gets a key's value from config file.
*
* Returns config key's value as number.
*/
static JSValueRef static JSValueRef
get_conf_num_cb(JSContextRef context, get_conf_num_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *section, *key; gchar *section, *key;
gint value; gint value;
GError *err = NULL; GError *err = NULL;
if (argumentCount != 2) { if (argumentCount != 2) {
return mkexception(context, exception, "Needs 2 arguments"); return mkexception(context, exception, "Needs 2 arguments");
@ -1083,14 +1089,9 @@ get_conf_num_cb(JSContextRef context,
} }
key = arg_to_string(context, arguments[1], exception); key = arg_to_string(context, arguments[1], exception);
if (!section) {
return JSValueMakeNull(context);
}
value = g_key_file_get_integer(keyfile, section, key, &err); value = g_key_file_get_integer(keyfile, section, key, &err);
if (err) { if (err) {
_mkexception(context, exception, err->message); _mkexception(context, exception, err->message);
g_error_free(err); g_error_free(err);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -1099,17 +1100,23 @@ get_conf_num_cb(JSContextRef context,
return JSValueMakeNumber(context, value); return JSValueMakeNumber(context, value);
} }
/*
* Gets a key's value from config file.
*
* Returns config key's value as bool.
*/
static JSValueRef static JSValueRef
get_conf_bool_cb(JSContextRef context, get_conf_bool_cb(JSContextRef context,
JSObjectRef function, JSObjectRef function,
JSObjectRef thisObject, JSObjectRef thisObject,
size_t argumentCount, size_t argumentCount,
const JSValueRef arguments[], const JSValueRef arguments[],
JSValueRef *exception) { JSValueRef *exception) {
gchar *section, *key; gchar *section, *key;
gboolean value; gboolean value;
GError *err = NULL; GError *err = NULL;
if (argumentCount != 2) { if (argumentCount != 2) {
return mkexception(context, exception, "Needs 2 arguments"); return mkexception(context, exception, "Needs 2 arguments");
@ -1122,14 +1129,9 @@ get_conf_bool_cb(JSContextRef context,
} }
key = arg_to_string(context, arguments[1], exception); key = arg_to_string(context, arguments[1], exception);
if (!section) {
return JSValueMakeNull(context);
}
value = g_key_file_get_boolean(keyfile, section, key, &err); value = g_key_file_get_boolean(keyfile, section, key, &err);
if (err) { if (err) {
_mkexception(context, exception, err->message); _mkexception(context, exception, err->message);
g_error_free(err); g_error_free(err);
return JSValueMakeNull(context); return JSValueMakeNull(context);
@ -1138,15 +1140,6 @@ get_conf_bool_cb(JSContextRef context,
return JSValueMakeBoolean(context, value); return JSValueMakeBoolean(context, value);
} }
static JSValueRef
get_iconsdir_cb(JSContextRef context,
JSObjectRef thisObject,
JSStringRef propertyName,
JSValueRef *exception) {
return string_or_null(context, ICONS_DIR);
}
static const JSStaticValue lightdm_user_values[] = { static const JSStaticValue lightdm_user_values[] = {
{"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, {"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly},
@ -1292,13 +1285,13 @@ static const JSClassDefinition gettext_definition = {
gettext_functions, /* Static functions */ gettext_functions, /* Static functions */
}; };
static const JSClassDefinition conffile_definition = { static const JSClassDefinition config_file_definition = {
0, /* Version */ 0, /* Version */
kJSClassAttributeNone, /* Attributes */ kJSClassAttributeNone, /* Attributes */
"Branding", /* Class name */ "ConfigFile", /* Class name */
NULL, /* Parent class */ NULL, /* Parent class */
NULL, /* Static values */ NULL, /* Static values */
conffile_functions, /* Static functions */ config_file_functions, /* Static functions */
}; };
/*static void /*static void
@ -1335,7 +1328,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
lightdm_language_class = JSClassCreate(&lightdm_language_definition); lightdm_language_class = JSClassCreate(&lightdm_language_definition);
lightdm_layout_class = JSClassCreate(&lightdm_layout_definition); lightdm_layout_class = JSClassCreate(&lightdm_layout_definition);
lightdm_session_class = JSClassCreate(&lightdm_session_definition); lightdm_session_class = JSClassCreate(&lightdm_session_definition);
conffile_class = JSClassCreate(&conffile_definition); config_file_class = JSClassCreate(&config_file_definition);
gettext_object = JSObjectMake(jsContext, gettext_class, NULL); gettext_object = JSObjectMake(jsContext, gettext_class, NULL);
@ -1360,7 +1353,7 @@ window_object_cleared_callback(WebKitScriptWorld *world,
JSObjectSetProperty(jsContext, JSObjectSetProperty(jsContext,
globalObject, globalObject,
JSStringCreateWithUTF8CString("config"), JSStringCreateWithUTF8CString("config"),
conffile_object, config_file_object,
kJSPropertyAttributeNone, kJSPropertyAttributeNone,
NULL); NULL);

Loading…
Cancel
Save