MCPcopy Create free account
hub / github.com/Martchus/syncthingtray / processFetchQueue

Method processFetchQueue

syncthingmodel/syncthingfilemodel.cpp:1066–1173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1064}
1065
1066void SyncthingFileModel::processFetchQueue(const QString &lastItemPath)
1067{
1068 if (!lastItemPath.isNull()) {
1069 m_fetchQueue.removeAll(lastItemPath);
1070 }
1071 if (m_fetchQueue.isEmpty()) {
1072 emit fetchQueueEmpty();
1073 return;
1074 }
1075 const auto &path = m_fetchQueue.front();
1076 const auto rootIndex = index(path);
1077 if (!rootIndex.isValid()) {
1078 processFetchQueue(path);
1079 return;
1080 }
1081
1082 // add/update loading item
1083 auto *rootItem = reinterpret_cast<SyncthingItem *>(rootIndex.internalPointer());
1084 const auto populated = rootItem->childrenPopulated;
1085 if (!rootItem->childrenPopulated) {
1086 rootItem->childrenPopulated = true;
1087 switch (rootItem->children.size()) {
1088 case 0:
1089 beginInsertRows(rootIndex, 0, 0);
1090 addLoadingItem(rootItem->children);
1091 endInsertRows();
1092 break;
1093 case 1:
1094 setLoadingItem(rootItem->children.front().get());
1095 const auto affectedIndex = index(0, 0, rootIndex);
1096 emit dataChanged(affectedIndex, affectedIndex, QVector<int>{ Qt::DisplayRole, Qt::DecorationRole });
1097 break;
1098 }
1099 }
1100
1101 // query directory entries from Syncthing database
1102 if (rootItem->existsInDb.value_or(false)) {
1103 m_pendingRequest = m_connection.browse(
1104 m_dirId, path, 1, [this, populated](std::vector<std::unique_ptr<SyncthingItem>> &&items, QString &&errorMessage) mutable {
1105 m_pendingRequest.reply = nullptr;
1106 addErrorItem(items, std::move(errorMessage));
1107 const auto refreshedIndex = index(m_pendingRequest.forPath);
1108
1109 if (!refreshedIndex.isValid()) {
1110 processFetchQueue(m_pendingRequest.forPath);
1111 return;
1112 }
1113 auto *const refreshedItem = reinterpret_cast<SyncthingItem *>(refreshedIndex.internalPointer());
1114 const auto previousChildCount = refreshedItem->children.size();
1115 if (previousChildCount) {
1116 beginRemoveRows(refreshedIndex, 0, static_cast<int>(refreshedItem->children.size() - 1));
1117 refreshedItem->children.clear();
1118 endRemoveRows();
1119 }
1120 if (!items.empty()) {
1121 const auto last = items.size() - 1;
1122 for (auto &item : items) {
1123 item->parent = refreshedItem;

Callers

nothing calls this directly

Calls 11

addLoadingItemFunction · 0.85
setLoadingItemFunction · 0.85
addErrorItemFunction · 0.85
populatePathFunction · 0.85
forEachItemFunction · 0.85
setChildrenCheckedFunction · 0.85
browseMethod · 0.80
clearMethod · 0.80
QueryResultClass · 0.70
isNullMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected