@@ -31,7 +31,13 @@ QVariant FileActionsModel::data(const QModelIndex &index, int role) const
3131 case FileActionMethodRole:
3232 return _fileActions.at (row).method ; // GET
3333 case FileActionParamsRole:
34- return QVariant::fromValue<QList<QueryItem>>(_fileActions.at (row).params );
34+ return QVariant::fromValue<QueryList>(_fileActions.at (row).params );
35+ case FileActionResponseLabelRole:
36+ return _response.label ;
37+ case FileActionResponseUrlRole:
38+ return _response.url ;
39+ default :
40+ return QVariant ();
3541 }
3642
3743 return {};
@@ -54,6 +60,8 @@ QHash<int, QByteArray> FileActionsModel::roleNames() const
5460 roles[FileActionUrlRole] = " url" ;
5561 roles[FileActionMethodRole] = " method" ;
5662 roles[FileActionParamsRole] = " params" ;
63+ roles[FileActionResponseLabelRole] = " responseLabel" ;
64+ roles[FileActionResponseUrlRole] = " responseUrl" ;
5765
5866 return roles;
5967}
@@ -83,7 +91,6 @@ QString FileActionsModel::localPath() const
8391 return _localPath;
8492}
8593
86-
8794void FileActionsModel::setLocalPath (const QString &localPath)
8895{
8996 if (localPath.isEmpty ()) {
@@ -168,33 +175,41 @@ void FileActionsModel::setResponse(const Response &response)
168175void FileActionsModel::parseEndpoints ()
169176{
170177 if (!_accountState->isConnected ()) {
171- qCWarning (lcFileActions) << " The account is not connected" << _accountUrl;
172- setResponse ({ tr (" Your account is offline %1." , " account url" ).arg (_accountUrl), _accountUrl });
178+ qCWarning (lcFileActions) << " The account is not connected"
179+ << _accountUrl;
180+ setResponse ({ tr (" Your account is offline %1." , " account url" ).arg (_accountUrl),
181+ _accountUrl });
173182 return ;
174183 }
175184
176185 if (_fileId.isEmpty ()) {
177- qCWarning (lcFileActions) << " The file id is empty, not initialized" << _localPath;
178- setResponse ({ tr (" The file id is empty for %1." , " file name" ).arg (_localPath), _accountUrl });
186+ qCWarning (lcFileActions) << " The file id is empty, not initialized"
187+ << _localPath;
188+ setResponse ({ tr (" The file id is empty for %1." , " file name" ).arg (_localPath),
189+ _accountUrl });
179190 return ;
180191 }
181192
182193 if (!_mimeType.isValid ()) {
183- qCWarning (lcFileActions) << " The mime type found for the file is not valid" << _localPath;
184- setResponse ({ tr (" The file type for %1 is not valid." , " file name" ).arg (_localPath), _accountUrl });
194+ qCWarning (lcFileActions) << " The mime type found for the file is not valid"
195+ << _localPath;
196+ setResponse ({ tr (" The file type for %1 is not valid." , " file name" ).arg (_localPath),
197+ _accountUrl });
185198 return ;
186199 }
187200
188- const auto contextMenuList = _accountState->account ()->capabilities ().contextMenuByMimeType (_mimeType);
189- // const QList<QVariantMap> contextMenuList;
201+ const auto contextMenuList = _accountState->account ()->capabilities ().fileActionsByMimeType (_mimeType);
190202 if (contextMenuList.isEmpty ()) {
191- qCWarning (lcFileActions) << " contextMenuByMimeType is empty, nothing was returned by capabilities" << _localPath;
192- setResponse ({ tr (" No file actions were returned by the server for %1 files." , " file mymetype" ).arg (_mimeType.filterString ()), _accountUrl });
203+ qCWarning (lcFileActions) << " contextMenuByMimeType is empty, nothing was returned by capabilities"
204+ << _localPath;
205+ setResponse ({ tr (" No file actions were returned by the server for %1 files." , " file mymetype" )
206+ .arg (_mimeType.filterString ()),
207+ _accountUrl });
193208 return ;
194209 }
195210
196211 for (const auto &contextMenu : contextMenuList) {
197- ParamsList queryParams ;
212+ QueryList queryList ;
198213 const auto paramsMap = contextMenu.value (" params" ).toMap ();
199214 for (auto param = paramsMap.cbegin (), end = paramsMap.cend (); param != end; ++param) {
200215 const auto name = param.key ();
@@ -208,18 +223,20 @@ void FileActionsModel::parseEndpoints()
208223 }
209224
210225 if (!value.isEmpty ()) {
211- queryParams .append ( QueryItem{ name, value } );
226+ queryList .append ( QueryItem{ name, value } );
212227 }
213228 }
214229
215230 _fileActions.append ({ parseIcon (contextMenu.value (" icon" ).toString ()),
216231 contextMenu.value (" name" ).toString (),
217232 contextMenu.value (" url" ).toString (),
218233 contextMenu.value (" method" ).toString (),
219- queryParams });
234+ queryList });
220235 }
221236
222- qCDebug (lcFileActions) << " File" << _localPath << " has" << _fileActions.size () << " actions available." ;
237+ qCDebug (lcFileActions) << " File" << _localPath << " has"
238+ << _fileActions.size ()
239+ << " actions available." ;
223240 Q_EMIT fileActionModelChanged ();
224241}
225242
@@ -242,7 +259,8 @@ QString FileActionsModel::parseIcon(const QString &icon) const
242259void FileActionsModel::createRequest (const int row)
243260{
244261 if (!_accountState) {
245- qCWarning (lcFileActions) << " No account state for" << _localPath;
262+ qCWarning (lcFileActions) << " No account state for"
263+ << _localPath;
246264 return ;
247265 }
248266
@@ -252,7 +270,7 @@ void FileActionsModel::createRequest(const int row)
252270 this );
253271 connect (job, &JsonApiJob::jsonReceived,
254272 this , &FileActionsModel::processRequest);
255- for (const auto ¶m : _fileActions.at (row).params ) {
273+ for (const auto ¶m : std::as_const ( _fileActions.at (row).params ) ) {
256274 QUrlQuery query;
257275 query.addQueryItem (param.name , param.value );
258276 job->addQueryParams (query);
0 commit comments