74
Queue::currentTransfer() {
76
Queue::currentTransfer(const QString& appId) {
77
if(_current.contains(appId)) {
78
return _current[appId];
87
foreach(QStringList* list, _sortedPaths.values()) {
83
93
QHash<QString, Transfer*>
84
94
Queue::transfers() {
85
95
QHash<QString, Transfer*> transfers;
86
foreach(const QString& path, _sortedPaths) {
96
foreach(const QString& path, paths()) {
87
97
transfers[path] = _transfers[path];
101
111
// decide what to do with it
102
112
auto transfer = qobject_cast<Transfer*>(sender());
103
113
switch (transfer->state()) {
114
case Transfer::RESUME:
104
115
case Transfer::START:
105
// only start the transfer in the update method
106
if (_current.isEmpty())
107
updateCurrentTransfer();
116
if (!_current.contains(transfer->transferAppId())
117
|| (_current.contains(transfer->transferAppId())
118
&& _current[transfer->transferAppId()].isEmpty())) {
119
// only start or resume the transfer in the update method
120
updateCurrentTransfer(transfer->transferAppId());
109
123
case Transfer::PAUSE:
110
124
transfer->pauseTransfer();
111
if (!_current.isEmpty() && _current == transfer->path())
112
updateCurrentTransfer();
114
case Transfer::RESUME:
115
// only resume the transfer in the update method
116
if (_current.isEmpty()) {
117
updateCurrentTransfer();
125
updateCurrentTransfer(transfer->transferAppId());
120
127
case Transfer::CANCEL:
121
128
// cancel and remove the transfer
122
129
transfer->cancelTransfer();
123
if (!_current.isEmpty() && _current == transfer->path())
124
updateCurrentTransfer();
130
if (_current.contains(transfer->transferAppId()) && _current[transfer->transferAppId()] == transfer->path())
131
updateCurrentTransfer(transfer->transferAppId());
126
133
remove(transfer->path());
129
136
case Transfer::UNCOLLECTED:
130
137
// remove the registered object in dbus, remove the transfer
131
138
// and the adapter from the list
132
if (!_current.isEmpty() && _current == transfer->path())
133
updateCurrentTransfer();
139
if (_current.contains(transfer->transferAppId()) && _current[transfer->transferAppId()] == transfer->path())
140
updateCurrentTransfer(transfer->transferAppId());
135
142
case Transfer::FINISH:
136
if (!_current.isEmpty() && _current == transfer->path()) {
137
updateCurrentTransfer();
143
if (_current.contains(transfer->transferAppId()) && _current[transfer->transferAppId()] == transfer->path()) {
144
updateCurrentTransfer(transfer->transferAppId());
139
146
// Remove from the queue even if it wasn't the current transfer
140
147
// (finished signals can be received for downloads that completed
179
Queue::updateCurrentTransfer() {
186
Queue::updateCurrentTransfer(const QString& appIdToUpdate) {
181
if (!_current.isEmpty()) {
182
// check if it was canceled/finished
183
auto currentTransfer = _transfers[_current];
184
auto state = currentTransfer->state();
185
if (state == Transfer::CANCEL || state == Transfer::FINISH
186
|| state == Transfer::ERROR) {
187
LOG(INFO) << "State is CANCEL || FINISH || ERROR";
190
} else if (state == Transfer::UNCOLLECTED) {
191
LOG(INFO) << "State is UNCOLLECTED";
193
} else if (!currentTransfer->canTransfer()
194
|| state == Transfer::PAUSE) {
195
LOG(INFO) << "States is Cannot Transfer || PAUSE";
189
// If we don't get given a specific appId to update transfers for
190
// we update all the transfers
192
if (appIdToUpdate.isEmpty()) {
193
appIds = _sortedPaths.keys();
195
appIds.append(appIdToUpdate);
198
foreach(QString appId, appIds) {
199
if (_current.contains(appId)) {
200
// check if it was canceled/finished
201
auto currentTransfer = _transfers[_current[appId]];
202
auto state = currentTransfer->state();
203
if (state == Transfer::CANCEL || state == Transfer::FINISH
204
|| state == Transfer::ERROR) {
205
LOG(INFO) << "State is CANCEL || FINISH || ERROR";
206
remove(_current[appId]);
207
_current.remove(appId);
208
} else if (state == Transfer::UNCOLLECTED) {
209
LOG(INFO) << "State is UNCOLLECTED";
210
_current.remove(appId);
211
} else if (!currentTransfer->canTransfer()
212
|| state == Transfer::PAUSE) {
213
LOG(INFO) << "States is Cannot Transfer || PAUSE";
214
_current.remove(appId);
220
// loop via the transfers and choose the first that is
221
// started or resumed
222
foreach(const QString& path, *_sortedPaths[appId]) {
223
auto transfer = _transfers[path];
224
auto state = transfer->state();
225
if (transfer->canTransfer()
226
&& (state == Transfer::START
227
|| state == Transfer::RESUME)) {
228
_current[appId] = path;
229
if (state == Transfer::START) {
230
transfer->startTransfer();
232
transfer->resumeTransfer();
236
if (_current.contains(appId) && !_current[appId].isEmpty()) {
237
emit currentChanged(appId, _current[appId]);
202
// loop via the transfers and choose the first that is
203
// started or resumed
204
foreach(const QString& path, _sortedPaths) {
205
auto transfer = _transfers[path];
206
auto state = transfer->state();
207
if (transfer->canTransfer()
208
&& (state == Transfer::START
209
|| state == Transfer::RESUME)) {
211
if (state == Transfer::START)
212
transfer->startTransfer();
214
transfer->resumeTransfer();
219
emit currentChanged(_current);
239
emit currentChanged(appId, "");