@@ -148,12 +148,26 @@ QStringList BlockDevices::devicePaths(const QStringList &dbusObjectPaths) const
148
148
bool BlockDevices::createBlockDevice (const QString &dbusObjectPath, const InterfacePropertyMap &interfacePropertyMap)
149
149
{
150
150
if (!BlockDevices::isExternal (dbusObjectPath)) {
151
+ updatePopulatedCheck ();
151
152
return false ;
152
153
}
153
154
154
155
return doCreateBlockDevice (dbusObjectPath, interfacePropertyMap);
155
156
}
156
157
158
+ void BlockDevices::createBlockDevices (const QList<QDBusObjectPath> &devices)
159
+ {
160
+ m_blockCount = devices.count ();
161
+ if (m_blockCount == 0 ) {
162
+ m_populated = true ;
163
+ emit externalStoragesPopulated ();
164
+ }
165
+
166
+ for (const QDBusObjectPath &dbusObjectPath : devices) {
167
+ createBlockDevice (dbusObjectPath.path (), UDisks2::InterfacePropertyMap ());
168
+ }
169
+ }
170
+
157
171
void BlockDevices::lock (const QString &dbusObjectPath)
158
172
{
159
173
Block *deviceMapped = find ([dbusObjectPath](const Block *block) {
@@ -210,6 +224,11 @@ void BlockDevices::removeInterfaces(const QString &dbusObjectPath, const QString
210
224
}
211
225
}
212
226
227
+ bool BlockDevices::populated () const
228
+ {
229
+ return m_populated;
230
+ }
231
+
213
232
bool BlockDevices::isExternal (const QString &dbusObjectPath)
214
233
{
215
234
static const QRegularExpression externalBlockDevice (QStringLiteral (" ^/org/freedesktop/UDisks2/block_devices/%1$" ).arg (externalDevice));
@@ -223,15 +242,21 @@ void BlockDevices::blockCompleted()
223
242
(completedBlock->hasInterface (UDISKS2_BLOCK_INTERFACE) && completedBlock->interfaceCount () == 1 )) ){
224
243
qCInfo (lcMemoryCardLog) << " Start waiting for block" << completedBlock->device ();
225
244
waitPartition (completedBlock);
245
+ updatePopulatedCheck ();
226
246
return ;
227
247
}
228
248
229
249
clearPartitionWait (completedBlock->partitionTable (), true );
230
250
complete (completedBlock);
251
+
252
+ // Check only after complete has been called.
253
+ updatePopulatedCheck ();
231
254
}
232
255
233
256
BlockDevices::BlockDevices (QObject *parent)
234
257
: QObject(parent)
258
+ , m_blockCount(0 )
259
+ , m_populated(false )
235
260
{
236
261
Q_ASSERT (!sharedInstance);
237
262
@@ -333,6 +358,17 @@ void BlockDevices::timerEvent(QTimerEvent *e)
333
358
}
334
359
}
335
360
361
+ void BlockDevices::updatePopulatedCheck ()
362
+ {
363
+ if (!m_populated) {
364
+ --m_blockCount;
365
+ if (m_blockCount == 0 ) {
366
+ m_populated = true ;
367
+ emit externalStoragesPopulated ();
368
+ }
369
+ }
370
+ }
371
+
336
372
BlockDevices::PartitionWaiter::PartitionWaiter (int timer, Block *block)
337
373
: timer(timer)
338
374
, block(block)
0 commit comments