/** set info */ void ui_info_hardware_set( NiftyconfHardware * hardware) { LedHardware *h = hardware_niftyled(hardware); gtk_link_button_set_uri(GTK_LINK_BUTTON(UI("linkbutton_family")), led_hardware_plugin_get_url(h)); gtk_button_set_label(GTK_BUTTON(UI("linkbutton_family")), led_hardware_plugin_get_family(h)); gtk_label_set_text(GTK_LABEL(UI("label_description")), led_hardware_plugin_get_description(h)); gtk_label_set_text(GTK_LABEL(UI("label_author")), led_hardware_plugin_get_author(h)); gtk_label_set_text(GTK_LABEL(UI("label_license")), led_hardware_plugin_get_license(h)); gchar version[64]; g_snprintf(version, sizeof(version), "v%d.%d.%d", led_hardware_plugin_get_version_major(h), led_hardware_plugin_get_version_minor(h), led_hardware_plugin_get_version_micro(h)); gtk_label_set_text(GTK_LABEL(UI("label_version")), version); }
/** * Object-to-Config function. * Creates a config-node (and subnodes) from a LedHardware model * @param c the current preferences context * @param n a freshly created prefs node that this function should fill with properties of obj * @param obj object of this class where preferences should be generated from * @result NFT_SUCCESS if everything went fine, NFT_FAILURE otherwise * @note you shouldn't call this function directly * It's used by nft_prefs_obj_to_node() etc. */ static NftResult _prefs_from_hardware(NftPrefs * p, NftPrefsNode * n, void *obj, void *userptr) { if(!p || !n || !obj) NFT_LOG_NULL(NFT_FAILURE); /* hardware "object" */ LedHardware *h = obj; /* name of hardware */ if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_NAME, (char *) led_hardware_get_name(h))) return NFT_FAILURE; /* plugin family of hardware */ if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_PLUGIN, (char *) led_hardware_plugin_get_family (h))) return NFT_FAILURE; /* id of hardware */ if(!nft_prefs_node_prop_string_set(n, LED_HARDWARE_PROP_ID, (char *) led_hardware_get_id(h))) return NFT_FAILURE; /* LED stride */ if(!nft_prefs_node_prop_int_set(n, LED_HARDWARE_PROP_STRIDE, led_hardware_get_stride(h))) return NFT_FAILURE; /* handle custom plugin properties */ int i, a = led_hardware_plugin_prop_get_count(h); for(i = 0; i < a; i++) { LedPluginCustomProp *prop; if(!(prop = led_hardware_plugin_prop_get_nth(h, i))) { NFT_LOG(L_ERROR, "Could not get property %d (but %d registered). This is a bug!", i, a); break; } /* create new node for property */ NftPrefsNode *pnode; if(! (pnode = nft_prefs_node_alloc(LED_HARDWARE_PROPERTY_NAME))) { NFT_LOG(L_ERROR, "Failed to create new node."); return NFT_FAILURE; } /* name of property */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_NAME, (char *) led_hardware_plugin_prop_get_name(prop))) return NFT_FAILURE; /* handle various types of properties */ switch (led_hardware_plugin_prop_get_type(prop)) { case LED_HW_CUSTOM_PROP_STRING: { /* save type */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE, "string")) return NFT_FAILURE; /* get string */ char *string; if(!led_hardware_plugin_prop_get_string(h, led_hardware_plugin_prop_get_name (prop), &string)) return NFT_FAILURE; /* save value */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE, string)) return NFT_FAILURE; break; } case LED_HW_CUSTOM_PROP_INT: { /* save type */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE, "int")) return NFT_FAILURE; /* get integer */ int integer; if(!led_hardware_plugin_prop_get_int(h, led_hardware_plugin_prop_get_name (prop), &integer)) return NFT_FAILURE; /* convert to string */ char *string; if(!(string = alloca(64))) { NFT_LOG_PERROR("alloca"); return NFT_FAILURE; } snprintf(string, 64, "%d", integer); /* save value */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE, string)) return NFT_FAILURE; break; } case LED_HW_CUSTOM_PROP_FLOAT: { /* save type */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_TYPE, "float")) return NFT_FAILURE; /* get float */ float fp; if(!led_hardware_plugin_prop_get_float(h, led_hardware_plugin_prop_get_name (prop), &fp)) return NFT_FAILURE; /* convert to string */ char *string; if(!(string = alloca(64))) { NFT_LOG_PERROR("alloca"); return NFT_FAILURE; } snprintf(string, 64, "%f", fp); /* save value */ if(!nft_prefs_node_prop_string_set (pnode, LED_HARDWARE_PROPERTY_PROP_VALUE, string)) return NFT_FAILURE; break; } /* unsupported type */ default: { NFT_LOG(L_WARNING, "Property \"%s\" is of unsupported type. Ignoring", led_hardware_plugin_prop_get_name (prop)); continue; } } /* add node as child of this node */ nft_prefs_node_add_child(n, pnode); } /* chain of this hardware */ LedChain *c; if((c = led_hardware_get_chain(h))) { /* generate prefs node from chain */ NftPrefsNode *node; if(!(node = led_prefs_chain_to_node(p, c))) return NFT_FAILURE; /* add node as child of this node */ nft_prefs_node_add_child(n, node); } /* tiles of this hardware */ LedTile *t; for(t = led_hardware_get_tile(h); t; t = led_tile_list_get_next(t)) { NftPrefsNode *node; if(!(node = led_prefs_tile_to_node(p, t))) return NFT_FAILURE; /* add node as child of this node */ nft_prefs_node_add_child(n, node); } /* all OK */ return NFT_SUCCESS; }