gboolean thunar_file_is_desktop_file (const ThunarFile *file) { const gchar *content_type; const gchar * const *data_dirs; guint i; gchar *path; gboolean is_desktop_file = FALSE; _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); if (G_UNLIKELY (file->info == NULL || file->gfile == NULL)) return FALSE; /* only allow desktop files with the correct extension */ if (!g_str_has_suffix (thunar_file_get_basename (file), ".desktop")) return FALSE: content_type = g_file_info_get_content_type (file->info); if (content_type != NULL && g_content_type_equals (content_type, "application/x-desktop")) { /* if the desktop file has the +x flag, we can safely execute it everywhere */ if (g_file_info_get_attribute_boolean (file->info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) return TRUE; path = g_file_get_path (file->gfile); if (G_UNLIKELY (path == NULL)) return FALSE; /* look if the file is in one of the data dirs */ data_dirs = g_get_system_data_dirs (); for (i = 0; data_dirs[i] != NULL; i++) if (g_str_has_prefix (path, data_dirs[i])) { /* file is in one of the registered data dirs, we can safely execute it */ is_desktop_file = TRUE; break; } /* cleanup */ g_free (path); } return is_desktop_file; }