; Module/File: System_DefIconThemeIconListDemo.pb ; Function: Demo to list icon names of default icon theme, sorted with icon, sizes, filenames, contextes - Linux gtk2.6up ; Author: Omi ; Date: Oct. 02, 2015 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.40 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ; Link to topic: http://www.purebasic.fr/english/viewtopic.php?f=15&t=63192 ;-------------------------------------------------------------- ;further codes for the use of icons from default icon theme (at the moment in /Misc/...) ; Get contextes : System_DefIconThemeContextList.pb ; Get pathes : System_DefIconThemePathes.pb ; Get an example name : System_DefIconThemeExampleName.pb ; Get iconnames : System_DefIconThemeIconList.pb ; Get filenames from iconnames: System_DefIconThemeGetFileFromName.pb ; Get sizes for iconnames : System_DefIconThemeSizes4Name.pb ; Get supported image types : System_SupportedImageFormatsList.pb (works for Decoder-free PixbufLoader too) EnableExplicit ;no Decoder needed! ImportC "" gtk_icon_theme_list_icons(*icon_theme.GtkIconTheme, context.p-utf8); gtk2.4 gtk_icon_theme_list_icons_p(*icon_theme.GtkIconTheme, *context) As "gtk_icon_theme_list_icons"; " gtk_icon_theme_get_icon_sizes(*icon_theme.GtkIconTheme, icon_name.p-utf8); gtk2.6 gtk_icon_theme_lookup_icon(*icon_theme.GtkIconTheme, icon_name.p-utf8, size, flags); gtk2.4 gtk_icon_theme_load_icon(*icon_theme.GtkIconTheme, icon_name.p-utf8, size, flags, *error.GError); gtk2.4 gtk_icon_theme_list_contexts(*icon_theme.GtkIconTheme); gtk2.12 ; gtk_icon_info_get_base_scale(*icon_info) EndImport Enumeration GtkIconLookupFlags #GTK_ICON_LOOKUP_ALL = 0; Not gtk-defined, own constant to clearify #GTK_ICON_LOOKUP_NO_SVG = 1 #GTK_ICON_LOOKUP_FORCE_SVG = 2 #GTK_ICON_LOOKUP_USE_BUILTIN = 4 #GTK_ICON_LOOKUP_GENERIC_FALLBACK = 8 #GTK_ICON_LOOKUP_FORCE_SIZE = 16 EndEnumeration #Win_Main = 0 #CBx = 0 #LIG = 1 #TG = 2 Global.i gEvent, gQuit Global.s WinTitle= "Default icon theme list w. example-icon, sizes & files, context for icon-names " Global NewList IconNames.s() ProcedureC Callback_SearchInTreeView(*model, column, *key, iter, *search_data) Protected.i I, Found= #True Protected.l Indices Protected path Protected.s Search= PeekS(*key, -1, #PB_UTF8) path = gtk_tree_model_get_path_(*model, iter) Indices= PeekL(gtk_tree_path_get_indices_(path)) If FindString(GetGadgetItemText(#LIG, Indices, column), Search, 1, #PB_String_NoCase); = 1 Found= #False EndIf gtk_tree_path_free_(path) ProcedureReturn Found; #False = Ok ! EndProcedure Procedure IconDefaultTheme_ListIconContext() Protected *gList.GList = gtk_icon_theme_list_contexts(gtk_icon_theme_get_default_()) Protected *gList0.GSList= *gList Protected *IconContext Protected n If *gList Repeat *IconContext= *gList\data AddGadgetItem(#CBx, -1, PeekS(*IconContext, -1, #PB_UTF8)) *gList= *gList\next n+ 1 Until *gList = 0 EndIf If *gList0 *gList= *gList0 Repeat g_free_(*gList\data); free context entries *gList= *gList\next Until *gList = 0 g_list_free_(*gList0); free context list EndIf SetGadgetState(#CBx, 0) EndProcedure ; search file from iconname in default icon theme and return pixbuf ... Procedure IconDefaultTheme_LoadIconFromName(icon_name.s, icon_size, flags) Protected *error.GError Protected *pixbuf= gtk_icon_theme_load_icon(gtk_icon_theme_get_default_(), icon_name, icon_size, flags, @*error) If *error : Debug icon_name + ": " + PeekS(*error\message, -1, #PB_UTF8) : EndIf ProcedureReturn *pixbuf EndProcedure Procedure IconDefaultTheme_ListIconNames(context.s) Protected *gList.GList Protected *icon_theme= gtk_icon_theme_get_default_() Protected *icon_info, *icon_name, *ptr, *pixbuf Protected.l I, n, icon_size, load_size, ItemIconIsSet Protected.s IconName, IconSizes, IconFiles If context = "" Or context = "All" *gList= gtk_icon_theme_list_icons_p(*icon_theme, #Null); set 'context 0-pointer' Else *gList= gtk_icon_theme_list_icons(*icon_theme, context); set 'context string' EndIf Protected *gList0.GSList = *gList; store 1. pointer If *gList ClearGadgetItems(#LIG) Repeat; read icon names for context or all (="") *icon_name= *gList\data AddElement(IconNames()) IconNames()= PeekS(*icon_name, -1, #PB_UTF8); icon names in linked list *gList= *gList\next Until *gList = 0 SortList(IconNames(), #PB_Sort_Ascending); sort icon names If *gList0; free pointers ... *gList= *gList0 Repeat g_free_(*gList\data); free entries of iconlist *gList= *gList\next Until *gList = 0 g_list_free_(*gList0); free iconlist EndIf ForEach IconNames() AddGadgetItem(#LIG, -1, IconNames()); icon names from LinkedList in ListIconGadget ItemIconIsSet= #False *ptr= gtk_icon_theme_get_icon_sizes(*icon_theme, IconNames()) I= 0 : IconSizes= "" While PeekL(*ptr+ I*SizeOf(I)); create sample-string with iconsizes for IconName IconSizes+ Str(PeekL(*ptr+ I*SizeOf(I))) + #LF$; add size I+ 1 Wend SetGadgetItemText(#LIG, n, RTrim(IconSizes, #LF$), 1); sizes with LF to ListIconGadget IconFiles= "" For I= 1 To CountString(IconSizes, #LF$); read filenames for iconsizes icon_size= Val(StringField(IconSizes, I, #LF$)) load_size= icon_size If load_size = -1 : load_size= 22 : EndIf; scalable? then set size 22 *icon_info= gtk_icon_theme_lookup_icon(*icon_theme, IconNames(), icon_size, #GTK_ICON_LOOKUP_ALL); search IconName with size, all types If *icon_info IconFiles+ PeekS(gtk_icon_info_get_filename_(*icon_info), -1, #PB_UTF8) + #LF$; add filenames for size to sample-string If Not ItemIconIsSet If load_size < 65 And gtk_icon_info_get_base_size_(*icon_info) < 65; set LIG-icon from 1. icon with size < 65 SetGadgetItemImage(#LIG, n, IconDefaultTheme_LoadIconFromName(IconNames(), load_size, #GTK_ICON_LOOKUP_ALL)) ItemIconIsSet= #True EndIf EndIf EndIf Next I If IconFiles : SetGadgetItemText(#LIG, n, RTrim(IconFiles, #LF$), 2) : EndIf; filename with LF to ListIconGadget n+ 1 Next IconNames() SetWindowTitle(#Win_Main, WinTitle + " [" + Str(ListSize(IconNames())) + "]") ClearList(IconNames()) Else MessageRequester("icon lister", "No icon names found for context '" + context + "'") EndIf EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 900, 400, WinTitle, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered) TextGadget(#TG, 360, 9, 300, 22, "Icons from Default-theme will be collected ...") TextGadget(#PB_Any, 5, 9, 150, 22, "Choose theme context:") ComboBoxGadget(#CBx, 155, 5, 200, 30) AddGadgetItem(#CBx, -1, "All") ListIconGadget(#LIG, 5, 40, 890, 355, "Icon Names", 360, #PB_ListIcon_GridLines) AddGadgetColumn(#LIG, 1, "...sizes", 60) AddGadgetColumn(#LIG, 2, "...files", 100) gtk_tree_view_set_search_column_(GadgetID(#LIG), 0); set column 0 for search gtk_tree_view_set_search_equal_func_(GadgetID(#LIG), @Callback_SearchInTreeView(), #Null, 0); set function for verification EndIf EndProcedure Create_WinMain() IconDefaultTheme_ListIconContext() IconDefaultTheme_ListIconNames("") SetGadgetText(#TG, "") Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True Case #PB_Event_SizeWindow ResizeGadget(#LIG, #PB_Ignore, #PB_Ignore, WindowWidth(0)-10, WindowHeight(0)-45) Case #PB_Event_Gadget If EventGadget() = #CBx IconDefaultTheme_ListIconNames(GetGadgetItemText(#CBx, GetGadgetState(#CBx))) EndIf EndSelect Until gQuit ; IDE Options = PureBasic 5.44 LTS (Linux - x86) ; CursorPosition = 7 ; Folding = - ; EnableUnicode ; EnableXP