Commit f148d413 authored by Lukas Appelhans's avatar Lukas Appelhans

Fix crashes and all, support forced db update

parent 8980f2e8
......@@ -127,6 +127,7 @@ void initAkabeiOperations(CommandLineParser *parser)
clean.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation sync(APM::SyncOperationType, APM::UpdateDatabases, "", "sync", ki18n("Refresh databases"), false);
sync.addConnectionWithOption(APM::Force);
AkabeiOperation update(APM::SyncOperationType, APM::UpdateSystem, "", "update", ki18n("Update system"), false);
update.addConnectionWithOption(APM::DownloadOnly);
......@@ -270,6 +271,7 @@ void initPakabeiOperations(CommandLineParser *parser)
repo.addConnectionWithOption(APM::IgnoreGroup);
AkabeiOperation refresh(APM::SyncOperationType, APM::UpdateDatabases, "y", "refresh", ki18n("Refresh database"), false);
refresh.addConnectionWithOption(APM::Force);
AkabeiOperation sysupgrade(APM::SyncOperationType, APM::UpdateSystem, "u", "sysupgrade", ki18n("Update system"), false);
sysupgrade.addConnectionWithOption(APM::DownloadOnly);
......
......@@ -126,7 +126,9 @@ void SyncOperation::updateDatabases()
if (db->name().length() > m_maxDbNameLenght)
m_maxDbNameLenght = db->name().length();
}
m_currentDatabasePos = 0;
currentDatabase = AkabeiClient::Backend::instance()->databases().constBegin();
lastDatabase = AkabeiClient::Backend::instance()->databases().constEnd();
updateNextDatabase();
}
......@@ -321,13 +323,13 @@ void SyncOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
void SyncOperation::updateNextDatabase()
{
if (m_currentDatabasePos == AkabeiClient::Backend::instance()->databases().count()) {
if (currentDatabase == lastDatabase) {
QTextStream out(stdout);
out << i18n("Updating all databases finished") << endl;
nextOperation();
return;
}
AkabeiClient::DatabaseHandler* db = AkabeiClient::Backend::instance()->databases().at(m_currentDatabasePos);
AkabeiClient::DatabaseHandler* db = *currentDatabase;
connect(db, SIGNAL(statusChanged(AkabeiClient::DatabaseHandler::Status)), this, SLOT(databaseStatusChanged(AkabeiClient::DatabaseHandler::Status)), Qt::QueuedConnection);
connect(db, SIGNAL(progress(int)), this, SLOT(databaseProgressChanged(int)), Qt::QueuedConnection);
connect(db, SIGNAL(errorTriggered(Akabei::Error::List)), this, SLOT(databaseErrorTriggered(Akabei::Error::List)), Qt::QueuedConnection);
......@@ -346,11 +348,13 @@ void SyncOperation::databaseErrorTriggered(Akabei::Error::List errors)
void SyncOperation::databaseProgressChanged(int progress)
{
if (currentDatabase == lastDatabase)
return;
QTextStream out(stdout);
out.reset();
m_bar.setColumns(ProgressBar::Progress);
m_bar.setProgressDescription(AkabeiClient::Backend::instance()->databases().at(m_currentDatabasePos)->name());
m_bar.setProgressDescription((*currentDatabase)->name());
m_bar.setProgress(progress);
out << m_bar.line();
......@@ -364,10 +368,8 @@ void SyncOperation::databaseStatusChanged(AkabeiClient::DatabaseHandler::Status
return;
}
AkabeiClient::DatabaseHandler* db = AkabeiClient::Backend::instance()->databases().at(m_currentDatabasePos);
disconnect(db, SIGNAL(statusChanged(AkabeiClient::DatabaseHandler::Status)), this, SLOT(databaseStatusChanged(AkabeiClient::DatabaseHandler::Status)));
disconnect(db, SIGNAL(progress(int)), this, SLOT(databaseProgressChanged(int)));
disconnect(db, SIGNAL(errorTriggered(Akabei::Error::List)), this, SLOT(databaseErrorTriggered(Akabei::Error::List)));
AkabeiClient::DatabaseHandler* db = *currentDatabase;
db->disconnect(this);
QTextStream out(stdout);
if (status == AkabeiClient::DatabaseHandler::StatusUpToDate) {
......@@ -378,7 +380,7 @@ void SyncOperation::databaseStatusChanged(AkabeiClient::DatabaseHandler::Status
out << m_bar.replaceMessage(i18n("%1 updated!", db->name())) << endl;
}
m_currentDatabasePos++;
currentDatabase++;
updateNextDatabase();
}
......
......@@ -40,7 +40,8 @@ private slots:
void nextOperation();
private:
int m_currentDatabasePos;
QList<AkabeiClient::DatabaseHandler*>::const_iterator currentDatabase;
QList<AkabeiClient::DatabaseHandler*>::const_iterator lastDatabase;
int m_maxDbNameLenght;
void updateDatabases();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment