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 system 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])) { is_desktop_file = TRUE; break; } /* user's data dir is also ok */ if (is_desktop_file == FALSE && g_str_has_prefix (path, g_get_user_data_dir ())) is_desktop_file = TRUE; /* cleanup */ g_free (path); } return is_desktop_file; }