Skip to content

Commit ad44137

Browse files
committed
nemo-action.c: Fix loading of absolute icon paths.
This is allowed via the layout editor but absolute paths were not being detected and handled correctly in Nemo.
1 parent e21b284 commit ad44137

2 files changed

Lines changed: 47 additions & 8 deletions

File tree

action-layout-editor/nemo_action_layout_editor.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def __init__(self, label, accel_string):
4747
self.label = _(label)
4848

4949
class Row():
50-
def __init__(self, row_meta=None, keyfile=None, path=None, enabled=True):
50+
def __init__(self, row_meta=None, keyfile=None, path=None, enabled=True, scale_factor=1):
5151
self.keyfile = keyfile
5252
self.row_meta = row_meta
5353
self.enabled = enabled
54+
self.scale_factor = scale_factor
5455
self.path = path # PosixPath
5556

5657
def get_icon_string(self, original=False):
@@ -81,7 +82,7 @@ def get_icon_type_and_data(self, original=False):
8182

8283
if icon_string.startswith("/"):
8384
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icon_string, 16, 16)
84-
surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, self.main_window.get_scale_factor(), None)
85+
surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, self.scale_factor, None)
8586
return ("surface", surface)
8687

8788
return ("icon-name", icon_string)
@@ -501,6 +502,7 @@ def load_installed_actions(self):
501502

502503
def fill_model(self, model, parent, items, installed_actions):
503504
disabled_actions = self.nemo_plugin_settings.get_strv("disabled-actions")
505+
scale_factor = self.main_window.get_scale_factor()
504506

505507
for item in items:
506508
row_type = item.get("type")
@@ -514,7 +516,7 @@ def fill_model(self, model, parent, items, installed_actions):
514516
print("Ignoring missing installed action %s" % uuid)
515517
continue
516518

517-
iter = model.append(parent, [new_hash(), uuid, row_type, Row(item, kf, path, path.name not in disabled_actions)])
519+
iter = model.append(parent, [new_hash(), uuid, row_type, Row(item, kf, path, path.name not in disabled_actions, scale_factor)])
518520

519521
del installed_actions[uuid]
520522
elif row_type == ROW_TYPE_SEPARATOR:
@@ -537,7 +539,7 @@ def push_disabled(key):
537539

538540
for uuid, (path, kf) in sorted_actions.items():
539541
enabled = path.name not in disabled_actions
540-
model.append(parent, [new_hash(), uuid, ROW_TYPE_ACTION, Row(None, kf, path, enabled)])
542+
model.append(parent, [new_hash(), uuid, ROW_TYPE_ACTION, Row(None, kf, path, enabled, scale_factor)])
541543

542544
def save_disabled_list(self):
543545
disabled = []

libnemo-private/nemo-action.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ nemo_action_constructed (GObject *object)
642642
{
643643
NemoAction *action = NEMO_ACTION (object);
644644
NemoActionPrivate *priv = nemo_action_get_instance_private (action);
645+
GIcon *gicon;
645646

646647
G_OBJECT_CLASS (nemo_action_parent_class)->constructed (object);
647648

@@ -666,6 +667,23 @@ nemo_action_constructed (GObject *object)
666667
KEY_ICON_NAME,
667668
NULL);
668669

670+
gicon = NULL;
671+
672+
if (icon_name != NULL) {
673+
if (g_path_is_absolute (icon_name)) {
674+
GFile *icon_file = g_file_new_for_path (icon_name);
675+
if (g_file_is_native (icon_file)) {
676+
gicon = g_file_icon_new (icon_file);
677+
}
678+
g_object_unref (icon_file);
679+
}
680+
681+
if (gicon == NULL) {
682+
gicon = g_themed_icon_new (icon_name);
683+
}
684+
}
685+
g_free (icon_name);
686+
669687
gchar *stock_id = g_key_file_get_string (key_file,
670688
ACTION_FILE_GROUP,
671689
KEY_STOCK_ID,
@@ -851,7 +869,7 @@ nemo_action_constructed (GObject *object)
851869
g_object_set (action,
852870
"label", orig_label,
853871
"tooltip", orig_tt,
854-
"icon-name", icon_name,
872+
"gicon", gicon,
855873
"stock-id", stock_id,
856874
NULL);
857875

@@ -877,7 +895,7 @@ nemo_action_constructed (GObject *object)
877895
queue_recalc_gsettings_conditions (action);
878896
DEBUG ("Initial action gsettings and dbus complete (%s)", action->key_file_path);
879897

880-
g_free (icon_name);
898+
g_clear_object (&gicon);
881899
g_free (stock_id);
882900
g_free (quote_type_string);
883901
g_key_file_free (key_file);
@@ -1505,9 +1523,28 @@ nemo_action_override_label (NemoAction *action,
15051523

15061524
void
15071525
nemo_action_override_icon (NemoAction *action,
1508-
const gchar *icon)
1526+
const gchar *icon_name)
15091527
{
1510-
gtk_action_set_icon_name (GTK_ACTION (action), icon);
1528+
GIcon *gicon = NULL;
1529+
1530+
if (icon_name != NULL && *icon_name != '\0') {
1531+
if (g_path_is_absolute (icon_name)) {
1532+
GFile *icon_file = g_file_new_for_path (icon_name);
1533+
if (g_file_is_native (icon_file)) {
1534+
gicon = g_file_icon_new (icon_file);
1535+
}
1536+
g_object_unref (icon_file);
1537+
}
1538+
1539+
if (gicon == NULL) {
1540+
gicon = g_themed_icon_new (icon_name);
1541+
}
1542+
1543+
gtk_action_set_gicon (GTK_ACTION (action), gicon);
1544+
g_clear_object (&gicon);
1545+
} else {
1546+
gtk_action_set_gicon(GTK_ACTION (action), NULL);
1547+
}
15111548
}
15121549

15131550
const gchar *

0 commit comments

Comments
 (0)