- if(!storage->init(dbSettings)) {
- if(!setup || !(storage->setup(dbSettings) && storage->init(dbSettings))) {
- qCritical() << "Could not init storage!";
- storage = 0;
- return configured = false;
+
+ Storage::State storageState = storage->init(dbSettings);
+ switch(storageState) {
+ case Storage::NeedsSetup:
+ if(!setup)
+ return false; // trigger setup process
+ if(storage->setup(dbSettings))
+ return initStorage(dbSettings, false);
+ // if setup wasn't successfull we mark the backend as unavailable
+ case Storage::NotAvailable:
+ qCritical() << "Selected storage backend is not available:" << backend;
+ storage->deleteLater();
+ _storageBackends.remove(backend);
+ storage = 0;
+ return false;
+ case Storage::IsReady:
+ // delete all other backends
+ foreach(Storage *s, _storageBackends.values()) {
+ if(s != storage) s->deleteLater();