Author: locilka Date: Mon Dec 3 17:14:03 2007 New Revision: 42623 URL: http://svn.opensuse.org/viewcvs/yast?rev=42623&view=rev Log: Er ehm, addded new module as advertised before :))))))))) Added: trunk/yast2/library/modules/Icon.ycp Added: trunk/yast2/library/modules/Icon.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/yast2/library/modules/Icon.ycp?re... ============================================================================== --- trunk/yast2/library/modules/Icon.ycp (added) +++ trunk/yast2/library/modules/Icon.ycp Mon Dec 3 17:14:03 2007 @@ -0,0 +1,120 @@ +/** + * File: modules/Icon.ycp + * Package: YaST2 + * Authors: Lukas Ocilka <lukas.ocilka@suse.cz> + * Summary: Transparent access to Icons + * Flags: Stable + * + * $Id:$ + */ +{ + module "Icon"; + + textdomain "base"; + + import "Directory"; + + boolean has_image_support = nil; + map <string, string> icons_map = $[]; + string icon_32x32_path = nil; + + void LazyInit () { + if (has_image_support != nil) + return; + + map display_info = UI::GetDisplayInfo(); + has_image_support = display_info["HasImageSupport"]:false; + + icon_32x32_path = Directory::themedir + "/current/icons/32x32/apps/"; + + icons_map = $[ + "warning" : "msg_warning.png", + "info" : "msg_info.png", + "error" : "msg_error.png", + ]; + } + + /** + * Returns path to an image + * + * @param string icon_type + * + * @see Icon::Image() for details + */ + global string IconPath (string icon_type) { + string icon_path = nil; + + if (icons_map[icon_type]:nil != nil) { + icon_path = icon_32x32_path + icons_map[icon_type]:""; + } else { + icon_path = icon_32x32_path + icon_type + ".png"; + y2milestone ("Image '%1' is not defined, using '%2'", icon_type, icon_path); + } + + return icon_path; + } + + /** + * Returns `Image() term defined by parameters. Returns `Empty() if the current + * UI doesn't support images. + * + * @param string icon_type (one of known types or just an image name without a 'png' suffix) + * Known icon types are "warning", "info", and "error" + * + * @param map <string, any> options + * + * @struct options = $[ + * "id" : any_icon_id, + * "label" : (string) icon_label, // (used if icon is missing) + * "margin_left" : 0, // HSpacing on the left + * "margin_right" : 5, // HSpacing on the right + * ] + * + * @example Icon::Image ("warning", $["id":`my_warning, "label":_("My Warning")]) + * -> + */ + global term Image (string icon_type, map <string, any> options) { + LazyInit(); + + if (! has_image_support) + return `Empty(); + + any icon_id = options["id"]:sformat ("icon_id_%1", icon_type); + string icon_label = options["label"]:icon_type; + + term ret = nil; + + term this_image = `Image ( + `id (icon_id), + IconPath (icon_type), + icon_label + ); + + // left and/or right margin defined + if (options["margin_left"]:0 != 0 || options["margin_right"]:0 != 0) { + ret = `HBox ( + `HSpacing (options["margin_left"]:0), + this_image, + `HSpacing (options["margin_right"]:0) + ); + + return ret; + // no margin defined + } else { + return this_image; + } + } + + /** + * Function calls Icon::Image with default options + * + * @param string icon_type + * + * @see Icon for more information + */ + global term Simple (string icon_type) { + return Image (icon_type, $[]); + } + +/* EOF */ +} -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org