Skip to content
API Documentation
BastionGuard™
IconManager Class Reference
Inheritance diagram for IconManager:

Static Public Member Functions

static void init (string[] args, string app_name)
static void refresh_icon_theme ()
static Gdk.? Pixbuf lookup (string icon_name, int icon_size, bool symbolic=false, bool use_hardcoded=false, int scale=1)
static Gdk.? Pixbuf lookup_gicon (GLib.Icon gicon, int icon_size)
static Gtk.Image lookup_image (string icon_name, int icon_size, bool symbolic=false, bool use_hardcoded=false)
static Gtk.Button button_from_icon (string icon_name, int icon_size, string? tooltip=null)
static Cairo.? Surface lookup_surface (string icon_name, int icon_size, int scale=1, bool symbolic=false, bool use_hardcoded=false)
static Gdk.? Pixbuf add_emblem (Gdk.Pixbuf pixbuf, string icon_name, int emblem_size, bool emblem_symbolic, Gtk.CornerType corner_type)
static Gdk.? Pixbuf add_overlay (Gdk.Pixbuf pixbuf_base, Gdk.Pixbuf pixbuf_overlay)
static Gdk.? Pixbuf resize_icon (Gdk.Pixbuf pixbuf_image, int icon_size)
static Gdk.? Pixbuf add_transparency (Gdk.Pixbuf pixbuf, int opacity=130)
static Gdk.? Pixbuf load_pixbuf_from_file (string file_path, int icon_size)

Static Public Attributes

static Gtk.IconTheme theme
static Gee.ArrayList< string > search_paths = new Gee.ArrayList<string>()
static bool use_dark = false
const int SHIELD_ICON_SIZE = 64
const string GENERIC_ICON_IMAGE = "image-x-generic"
const string GENERIC_ICON_IMAGE_MISSING = "image-missing"
const string GENERIC_ICON_VIDEO = "video-x-generic"
const string GENERIC_ICON_FILE = "text-x-preview"
const string GENERIC_ICON_ARCHIVE_FILE = "package-x-generic"
const string GENERIC_ICON_DIRECTORY = "folder"
const string GENERIC_ICON_ISO = "media-cdrom"
const string GENERIC_ICON_PDF = "application-pdf"
const string ICON_HARDDRIVE = "drive-harddisk"
const string SHIELD_LIVE = "media-optical"
const string SHIELD_LOW = "bastionguard-backup-shield-low"
const string SHIELD_MED = "bastionguard-backup-shield-med"
const string SHIELD_HIGH = "bastionguard-backup-shield-high"

Detailed Description

Definition at line 37 of file IconManager.vala.

Member Function Documentation

◆ add_emblem()

Gdk.? Pixbuf IconManager.add_emblem ( Gdk.Pixbuf pixbuf,
string icon_name,
int emblem_size,
bool emblem_symbolic,
Gtk.CornerType corner_type )
inlinestatic

Definition at line 200 of file IconManager.vala.

200 {
201
202 if (icon_name.length == 0){ return pixbuf; }
203
204 Gdk.Pixbuf? emblem = null;
205
206 var SMALL_EMBLEM_COLOR = Gdk.RGBA();
207 SMALL_EMBLEM_COLOR.parse("#000000");
208 SMALL_EMBLEM_COLOR.alpha = 1.0f;
209
210 var EMBLEM_PADDING = 1;
211
212 emblem = lookup(icon_name, emblem_size, emblem_symbolic, true);
213 if (emblem == null) {
214 return pixbuf;
215 }
216
217 if (emblem == null)
218 return pixbuf;
219
220 var offset_x = EMBLEM_PADDING;
221
222 if ((corner_type == Gtk.CornerType.BOTTOM_RIGHT) || (corner_type == Gtk.CornerType.TOP_RIGHT)){
223 offset_x = pixbuf.width - emblem.width - EMBLEM_PADDING ;
224 }
225
226 var offset_y = EMBLEM_PADDING;
227
228 if ((corner_type == Gtk.CornerType.BOTTOM_LEFT) || (corner_type == Gtk.CornerType.BOTTOM_RIGHT)){
229 offset_y = pixbuf.height - emblem.height - EMBLEM_PADDING ;
230 }
231
232 var emblemed = pixbuf.copy();
233
234 emblem.composite(emblemed,
235 offset_x, offset_y,
236 emblem_size, emblem_size,
237 offset_x, offset_y,
238 1.0, 1.0,
239 Gdk.InterpType.BILINEAR, 255);
240
241 return emblemed;
242 }
static Gdk.? Pixbuf lookup(string icon_name, int icon_size, bool symbolic=false, bool use_hardcoded=false, int scale=1)

References lookup().

◆ add_overlay()

Gdk.? Pixbuf IconManager.add_overlay ( Gdk.Pixbuf pixbuf_base,
Gdk.Pixbuf pixbuf_overlay )
inlinestatic

Definition at line 244 of file IconManager.vala.

244 {
245
246 int offset_x = (pixbuf_base.width - pixbuf_overlay.width) / 2 ;
247
248 var offset_y = (pixbuf_base.height - pixbuf_overlay.height) / 2 ;
249
250 var emblemed = pixbuf_base.copy();
251
252 pixbuf_overlay.composite(emblemed,
253 offset_x, offset_y,
254 pixbuf_overlay.width, pixbuf_overlay.height,
255 offset_x, offset_y,
256 1.0, 1.0,
257 Gdk.InterpType.BILINEAR, 255);
258
259 return emblemed;
260 }

Referenced by resize_icon().

◆ add_transparency()

Gdk.? Pixbuf IconManager.add_transparency ( Gdk.Pixbuf pixbuf,
int opacity = 130 )
inlinestatic

Definition at line 280 of file IconManager.vala.

280 {
281
282 var trans = pixbuf.copy();
283 trans.fill((uint32) 0xFFFFFF00);
284
285 //log_debug("add_transparency");
286
287 int width = pixbuf.get_width();
288 int height = pixbuf.get_height();
289 pixbuf.composite(trans, 0, 0, width, height, 0, 0, 1.0, 1.0, Gdk.InterpType.BILINEAR, opacity);
290
291 return trans;
292 }

◆ button_from_icon()

Gtk.Button IconManager.button_from_icon ( string icon_name,
int icon_size,
string? tooltip = null )
inlinestatic

Definition at line 189 of file IconManager.vala.

189 {
190 var btn = new Gtk.Button();
191 btn.set_child(lookup_image(icon_name, icon_size));
192 if (tooltip != null) btn.tooltip_text = tooltip;
193 return btn;
194 }
static Gtk.Image lookup_image(string icon_name, int icon_size, bool symbolic=false, bool use_hardcoded=false)

References lookup_image().

Referenced by ExcludeBox.create_pattern_row().

◆ init()

void IconManager.init ( string[] args,
string app_name )
inlinestatic

Definition at line 65 of file IconManager.vala.

65 {
66
67 log_debug("IconManager: init()");
68
69 search_paths = new Gee.ArrayList<string>();
70
71 string[] extra_paths = {
72 "/usr/share/%s/images-dark".printf(app_name),
73 "/usr/share/%s/images-light".printf(app_name),
74 "/usr/local/share/%s/images-dark".printf(app_name),
75 "/usr/local/share/%s/images-light".printf(app_name),
76 "/usr/share/%s/images".printf(app_name),
77 "/usr/local/share/%s/images".printf(app_name),
78 "/usr/share/pixmaps",
79 "/usr/local/share/pixmaps",
80 GLib.Path.build_filename(GLib.Environment.get_user_data_dir(), app_name, "images-dark"),
81 GLib.Path.build_filename(GLib.Environment.get_user_data_dir(), app_name, "images-light"),
82 GLib.Path.build_filename(GLib.Environment.get_user_data_dir(), app_name, "images"),
83 GLib.Path.build_filename(GLib.Environment.get_current_dir(), "src", "share", app_name, "images-dark"),
84 GLib.Path.build_filename(GLib.Environment.get_current_dir(), "src", "share", app_name, "images-light"),
85 GLib.Path.build_filename(GLib.Environment.get_current_dir(), "src", "share", app_name, "images"),
86 GLib.Path.build_filename(GLib.Environment.get_current_dir(), "src", "share", "pixmaps"),
87 GLib.Path.build_filename(GLib.Environment.get_current_dir(), "icons")
88 };
89 foreach (var path in extra_paths) {
90 if (dir_exists(path) && !search_paths.contains(path)) {
91 search_paths.add(path);
92 log_debug("found images directory: %s".printf(path));
93 }
94 }
95
97 }
static void refresh_icon_theme()
static Gee.ArrayList< string > search_paths
bool dir_exists(string dir_path)
void log_debug(string message)

References TeeJee.FileSystem.dir_exists(), TeeJee.Logging.log_debug(), refresh_icon_theme(), and search_paths.

Referenced by Main.Main().

◆ load_pixbuf_from_file()

Gdk.? Pixbuf IconManager.load_pixbuf_from_file ( string file_path,
int icon_size )
inlinestatic

Definition at line 294 of file IconManager.vala.

294 {
295
296 Gdk.Pixbuf? pixbuf = null;
297
298 int width, height;
299 Gdk.Pixbuf.get_file_info(file_path, out width, out height);
300
301 if ((width <= icon_size) && (height <= icon_size)){
302 try{
303 // load without scaling
304 pixbuf = new Gdk.Pixbuf.from_file(file_path);
305 // pad to requested size
306 pixbuf = resize_icon(pixbuf, icon_size);
307 // return
308 if (pixbuf != null){ return pixbuf; }
309 }
310 catch (Error e){
311 // ignore
312 }
313 }
314 else {
315 try{
316 // load with scaling - scale down to requested box
317 pixbuf = new Gdk.Pixbuf.from_file_at_scale(file_path, icon_size, icon_size, true);
318 // pad to requested size
319 pixbuf = resize_icon(pixbuf, icon_size);
320 // return
321 if (pixbuf != null){ return pixbuf; }
322 }
323 catch (Error e){
324 // ignore
325 }
326 }
327
328 return null;
329 }
static Gdk.? Pixbuf resize_icon(Gdk.Pixbuf pixbuf_image, int icon_size)

References Error, and resize_icon().

Referenced by lookup().

◆ lookup()

Gdk.? Pixbuf IconManager.lookup ( string icon_name,
int icon_size,
bool symbolic = false,
bool use_hardcoded = false,
int scale = 1 )
inlinestatic

Definition at line 111 of file IconManager.vala.

111 {
112 // Pick the theme-specific subfolder first (images-dark/ or images-light/)
113 string theme_folder = use_dark ? "images-dark" : "images-light";
114 string[] resource_candidates = {
115 "images/" + theme_folder + "/" + icon_name + ".svg",
116 "images/" + theme_folder + "/" + icon_name + ".png",
117 "images/" + icon_name + ".png",
118 "images/" + icon_name + ".svg",
119 "images/" + icon_name,
120 "icons/" + icon_name + ".png",
121 "pixmaps/" + icon_name + ".png",
122 "icons/hicolor/128x128/apps/" + icon_name + ".png",
123 "icons/hicolor/96x96/apps/" + icon_name + ".png",
124 "icons/hicolor/64x64/apps/" + icon_name + ".png",
125 "icons/hicolor/48x48/apps/" + icon_name + ".png",
126 "icons/hicolor/32x32/apps/" + icon_name + ".png",
127 "icons/hicolor/24x24/apps/" + icon_name + ".png",
128 "icons/hicolor/22x22/apps/" + icon_name + ".png",
129 "icons/hicolor/16x16/apps/" + icon_name + ".png"
130 };
131
132 Gdk.Pixbuf? pixbuf = null;
133 if (icon_name.length == 0){ return null; }
134
135 foreach (var rel in resource_candidates) {
136 if (ResourceHelper.resource_exists(rel)) {
137 try {
138 pixbuf = new Gdk.Pixbuf.from_resource_at_scale(ResourceHelper.resource_prefix() + "/" + rel, icon_size, icon_size, true);
139 if (pixbuf != null) return pixbuf;
140 } catch (Error e) {
141 // ignore and continue with filesystem fallback
142 }
143 }
144 }
145
146 string? resolved = ResourceHelper.resolve_icon_file(icon_name);
147 if (resolved != null) {
148 pixbuf = load_pixbuf_from_file(resolved, icon_size);
149 if (pixbuf != null) return pixbuf;
150 }
151
152 foreach(string search_path in search_paths){
153 foreach(string ext in new string[] { ".svg", ".png", ".jpg", ".gif"}){
154 string img_file = path_combine(search_path, icon_name + ext);
155 if (file_exists(img_file)){
156 pixbuf = load_pixbuf_from_file(img_file, icon_size);
157 if (pixbuf != null){ return pixbuf; }
158 }
159 }
160 }
161
162 return null;
163 }
static bool use_dark
static Gdk.? Pixbuf load_pixbuf_from_file(string file_path, int icon_size)
bool file_exists(string file_path)
string path_combine(string path1, string path2)

References Error, TeeJee.FileSystem.file_exists(), load_pixbuf_from_file(), TeeJee.FileSystem.path_combine(), ResourceHelper.resolve_icon_file(), ResourceHelper.resource_exists(), ResourceHelper.resource_prefix(), search_paths, and use_dark.

Referenced by AboutWindow.AboutWindow(), add_emblem(), BackupWindow.build_sidebar(), RestoreWindow.build_sidebar(), SettingsWindow.build_sidebar(), SetupWizardWindow.build_sidebar(), FileItem.get_icon(), MainWindow.init_snapshots_page(), lookup_gicon(), lookup_image(), BackupWindow.reload_themed_icons(), DeleteWindow.reload_themed_icons(), MainWindow.reload_themed_icons(), RestoreWindow.reload_themed_icons(), SettingsWindow.reload_themed_icons(), SetupWizardWindow.reload_themed_icons(), ScheduleBox.ScheduleBox(), MainWindow.update_statusbar(), and ScheduleBox.update_statusbar().

◆ lookup_gicon()

Gdk.? Pixbuf IconManager.lookup_gicon ( GLib.Icon gicon,
int icon_size )
inlinestatic

Definition at line 166 of file IconManager.vala.

166 {
167 return lookup(GENERIC_ICON_FILE, icon_size, false);
168 }
const string GENERIC_ICON_FILE

References GENERIC_ICON_FILE, and lookup().

Referenced by FileItem.get_icon().

◆ lookup_image()

Gtk.Image IconManager.lookup_image ( string icon_name,
int icon_size,
bool symbolic = false,
bool use_hardcoded = false )
inlinestatic

Definition at line 171 of file IconManager.vala.

171 {
172
173 var image = new Gtk.Image();
174 image.set_pixel_size(icon_size);
175 if (icon_name.length == 0){
176 image.set_from_icon_name(GENERIC_ICON_IMAGE_MISSING);
177 return image;
178 }
179
180 Gdk.Pixbuf? pix = lookup(icon_name, icon_size, symbolic, use_hardcoded, image.get_scale_factor());
181 if (pix != null){
182 image.set_from_pixbuf(pix);
183 } else {
184 image.set_from_icon_name(icon_name);
185 }
186 return image;
187 }
const string GENERIC_ICON_IMAGE_MISSING

References GENERIC_ICON_IMAGE_MISSING, and lookup().

Referenced by AboutWindow.AboutWindow(), BackupDeviceBox.add_device_row(), BackupDeviceBox.add_smb_row(), ImportDialog.build_ui(), button_from_icon(), ExcludeListSummaryWindow.create_actions(), HeaderFactory.create_main_headerbar(), ExcludeBox.create_pattern_row(), ExcludeMessageWindow.exclude_list_add_item(), MainWindow.init_about_page(), MainWindow.init_sidebar(), CustomMessageDialog.init_window(), BackupWindow.themed_icon(), DeleteWindow.themed_icon(), MainWindow.themed_icon(), RestoreWindow.themed_icon(), SettingsWindow.themed_icon(), and SetupWizardWindow.themed_icon().

◆ lookup_surface()

Cairo.? Surface IconManager.lookup_surface ( string icon_name,
int icon_size,
int scale = 1,
bool symbolic = false,
bool use_hardcoded = false )
inlinestatic

Definition at line 196 of file IconManager.vala.

196 {
197 return null;
198 }

◆ refresh_icon_theme()

void IconManager.refresh_icon_theme ( )
inlinestatic

Definition at line 99 of file IconManager.vala.

99 {
100
101 if (!GTK_INITIALIZED) { return; }
102
103 var display = Gdk.Display.get_default();
104 if (display == null) { return; }
105 theme = Gtk.IconTheme.get_for_display(display);
106 foreach(string path in search_paths){
107 theme.add_search_path(path);
108 }
109 }
bool GTK_INITIALIZED
Definition Main.vala:37
static Gtk.IconTheme theme

References GTK_INITIALIZED, search_paths, and theme.

Referenced by init().

◆ resize_icon()

Gdk.? Pixbuf IconManager.resize_icon ( Gdk.Pixbuf pixbuf_image,
int icon_size )
inlinestatic

Definition at line 262 of file IconManager.vala.

262 {
263
264 //log_debug("resize_icon()");
265
266 var pixbuf_empty = new Gdk.Pixbuf(Gdk.Colorspace.RGB, true, 8, icon_size, icon_size);
267 pixbuf_empty.fill(0x00000000);
268
269 //log_debug("pixbuf_empty: %d, %d".printf(pixbuf_empty.width, pixbuf_empty.height));
270
271 var pixbuf_resized = add_overlay(pixbuf_empty, pixbuf_image);
272
273 //log_debug("pixbuf_resized: %d, %d".printf(pixbuf_resized.width, pixbuf_resized.height));
274
275 //copy_pixbuf_options(pixbuf_image, pixbuf_resized);
276
277 return pixbuf_resized;
278 }
static Gdk.? Pixbuf add_overlay(Gdk.Pixbuf pixbuf_base, Gdk.Pixbuf pixbuf_overlay)

References add_overlay().

Referenced by load_pixbuf_from_file().

Member Data Documentation

◆ GENERIC_ICON_ARCHIVE_FILE

const string IconManager.GENERIC_ICON_ARCHIVE_FILE = "package-x-generic"
static

Definition at line 53 of file IconManager.vala.

◆ GENERIC_ICON_DIRECTORY

const string IconManager.GENERIC_ICON_DIRECTORY = "folder"
static

Definition at line 54 of file IconManager.vala.

◆ GENERIC_ICON_FILE

const string IconManager.GENERIC_ICON_FILE = "text-x-preview"
static

Definition at line 52 of file IconManager.vala.

Referenced by lookup_gicon().

◆ GENERIC_ICON_IMAGE

const string IconManager.GENERIC_ICON_IMAGE = "image-x-generic"
static

Definition at line 49 of file IconManager.vala.

◆ GENERIC_ICON_IMAGE_MISSING

const string IconManager.GENERIC_ICON_IMAGE_MISSING = "image-missing"
static

Definition at line 50 of file IconManager.vala.

Referenced by lookup_image().

◆ GENERIC_ICON_ISO

const string IconManager.GENERIC_ICON_ISO = "media-cdrom"
static

Definition at line 55 of file IconManager.vala.

◆ GENERIC_ICON_PDF

const string IconManager.GENERIC_ICON_PDF = "application-pdf"
static

Definition at line 56 of file IconManager.vala.

◆ GENERIC_ICON_VIDEO

const string IconManager.GENERIC_ICON_VIDEO = "video-x-generic"
static

Definition at line 51 of file IconManager.vala.

◆ ICON_HARDDRIVE

const string IconManager.ICON_HARDDRIVE = "drive-harddisk"
static

Definition at line 58 of file IconManager.vala.

Referenced by BackupDeviceBox.add_device_row().

◆ search_paths

Gee.ArrayList<string> IconManager.search_paths = new Gee.ArrayList<string>()
static

Definition at line 41 of file IconManager.vala.

Referenced by init(), lookup(), and refresh_icon_theme().

◆ SHIELD_HIGH

const string IconManager.SHIELD_HIGH = "bastionguard-backup-shield-high"
static

◆ SHIELD_ICON_SIZE

const int IconManager.SHIELD_ICON_SIZE = 64
static

Definition at line 47 of file IconManager.vala.

Referenced by ScheduleBox.ScheduleBox(), and ScheduleBox.update_statusbar().

◆ SHIELD_LIVE

const string IconManager.SHIELD_LIVE = "media-optical"
static

Definition at line 60 of file IconManager.vala.

◆ SHIELD_LOW

const string IconManager.SHIELD_LOW = "bastionguard-backup-shield-low"
static

Definition at line 61 of file IconManager.vala.

Referenced by MainWindow.update_statusbar(), and ScheduleBox.update_statusbar().

◆ SHIELD_MED

const string IconManager.SHIELD_MED = "bastionguard-backup-shield-med"
static

Definition at line 62 of file IconManager.vala.

Referenced by MainWindow.update_statusbar().

◆ theme

Gtk.IconTheme IconManager.theme
static

Definition at line 39 of file IconManager.vala.

Referenced by refresh_icon_theme().

◆ use_dark

bool IconManager.use_dark = false
static

Definition at line 45 of file IconManager.vala.

Referenced by MainWindow.load_css(), lookup(), and MainWindow.MainWindow().


The documentation for this class was generated from the following file: