| 1098 | // DBusMessage_Guard). |
| 1099 | template <bool Multiple, bool Directory> |
| 1100 | nfdresult_t NFD_DBus_OpenFile(DBusMessage*& outMsg, |
| 1101 | const nfdnfilteritem_t* filterList, |
| 1102 | nfdfiltersize_t filterCount) { |
| 1103 | const char* handle_token_ptr; |
| 1104 | char* handle_obj_path = MakeUniqueObjectPath(&handle_token_ptr); |
| 1105 | Free_Guard<char> handle_obj_path_guard(handle_obj_path); |
| 1106 | |
| 1107 | DBusError err; // need a separate error object because we don't want to mess with the old one |
| 1108 | // if it's stil set |
| 1109 | dbus_error_init(&err); |
| 1110 | |
| 1111 | // Subscribe to the signal using the handle_obj_path |
| 1112 | DBusSignalSubscriptionHandler signal_sub; |
| 1113 | nfdresult_t res = signal_sub.Subscribe(handle_obj_path); |
| 1114 | if (res != NFD_OKAY) return res; |
| 1115 | |
| 1116 | // TODO: use XOpenDisplay()/XGetInputFocus() to find xid of window... but what should one do on |
| 1117 | // Wayland? |
| 1118 | |
| 1119 | DBusMessage* query = dbus_message_new_method_call("org.freedesktop.portal.Desktop", |
| 1120 | "/org/freedesktop/portal/desktop", |
| 1121 | "org.freedesktop.portal.FileChooser", |
| 1122 | "OpenFile"); |
| 1123 | DBusMessage_Guard query_guard(query); |
| 1124 | AppendOpenFileQueryParams<Multiple, Directory>( |
| 1125 | query, handle_token_ptr, filterList, filterCount); |
| 1126 | |
| 1127 | DBusMessage* reply = |
| 1128 | dbus_connection_send_with_reply_and_block(dbus_conn, query, DBUS_TIMEOUT_INFINITE, &err); |
| 1129 | if (!reply) { |
| 1130 | dbus_error_free(&dbus_err); |
| 1131 | dbus_move_error(&err, &dbus_err); |
| 1132 | NFDi_SetError(dbus_err.message); |
| 1133 | return NFD_ERROR; |
| 1134 | } |
| 1135 | DBusMessage_Guard reply_guard(reply); |
| 1136 | |
| 1137 | // Check the reply and update our signal subscription if necessary |
| 1138 | { |
| 1139 | DBusMessageIter iter; |
| 1140 | if (!dbus_message_iter_init(reply, &iter)) { |
| 1141 | NFDi_SetError("D-Bus reply is missing an argument."); |
| 1142 | return NFD_ERROR; |
| 1143 | } |
| 1144 | if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) { |
| 1145 | NFDi_SetError("D-Bus reply is not an object path."); |
| 1146 | return NFD_ERROR; |
| 1147 | } |
| 1148 | |
| 1149 | const char* path; |
| 1150 | dbus_message_iter_get_basic(&iter, &path); |
| 1151 | if (strcmp(path, handle_obj_path) != 0) { |
| 1152 | // needs to change our signal subscription |
| 1153 | signal_sub.Subscribe(path); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | // Wait and read the response |
nothing calls this directly
no test coverage detected