Commit 1f1aa38d authored by Lukas Appelhans's avatar Lukas Appelhans

A little hackish but works much better

parent 2eb0e315
......@@ -22,7 +22,8 @@
#include <kdebug.h>
SyncOperation::SyncOperation(QObject* parent)
: QObject(parent)
: QObject(parent),
maxDbNameLenght(0)
{
}
......@@ -56,13 +57,16 @@ void SyncOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Oper
SLOT(showGroup(QUuid,QList<Akabei::Group*>)));
Akabei::Backend::instance()->queryGroups("SELECT * FROM groups WHERE Name LIKE \"" + args.first() + "\"");
} else if (operations.contains(APM::UpdateDatabases)) {
foreach (AkabeiClient::DatabaseHandler * db, AkabeiClient::Backend::instance()->databases()) {
m_databases[db] = false;
connect(db, SIGNAL(statusChanged(AkabeiClient::DatabaseHandler::Status)), SLOT(databaseStatusChanged(AkabeiClient::DatabaseHandler::Status)));
connect(db, SIGNAL(progress(int)), SLOT(databaseProgressChanged(int)));
connect(db, SIGNAL(errorTriggered(int)), SLOT(databaseErrorTriggered(int)));
if (AkabeiClient::Backend::instance()->databases().isEmpty())
return;
QTextStream out(stdout);
out << tr("Starting database update") << endl;
foreach (AkabeiClient::DatabaseHandler* db, AkabeiClient::Backend::instance()->databases()) {
if (db->name().length() > maxDbNameLenght)
maxDbNameLenght = db->name().length();
}
AkabeiClient::Backend::instance()->updateDatabase();
currentDatabasePos = 0;
updateNextDatabase();
}
}
......@@ -184,6 +188,20 @@ void SyncOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
out.flush();
}
void SyncOperation::updateNextDatabase()
{
if (currentDatabasePos == AkabeiClient::Backend::instance()->databases().count()) {
QTextStream out(stdout);
out << tr("Updating all databases finished") << endl;
return;
}
AkabeiClient::DatabaseHandler* db = AkabeiClient::Backend::instance()->databases().at(currentDatabasePos);
connect(db, SIGNAL(statusChanged(AkabeiClient::DatabaseHandler::Status)), this, SLOT(databaseStatusChanged(AkabeiClient::DatabaseHandler::Status)));
connect(db, SIGNAL(progress(int)), this, SLOT(databaseProgressChanged(int)));
connect(db, SIGNAL(errorTriggered(int)), this, SLOT(databaseErrorTriggered(int)));
db->update();
}
void SyncOperation::databaseErrorTriggered(int error)
{
QTextStream out(stdout);
......@@ -194,7 +212,8 @@ void SyncOperation::databaseErrorTriggered(int error)
void SyncOperation::databaseProgressChanged(int progress)
{
QTextStream out(stdout);
out << static_cast<AkabeiClient::DatabaseHandler*>(QObject::sender())->name();
out.reset();
out << qSetFieldWidth(maxDbNameLenght) << static_cast<AkabeiClient::DatabaseHandler*>(QObject::sender())->name() << qSetFieldWidth(0);
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
......@@ -214,19 +233,14 @@ void SyncOperation::databaseProgressChanged(int progress)
void SyncOperation::databaseStatusChanged(AkabeiClient::DatabaseHandler::Status status)
{
if (status == AkabeiClient::DatabaseHandler::StatusFinished)
m_databases[static_cast<AkabeiClient::DatabaseHandler*>(QObject::sender())] = true;
foreach (bool done, m_databases.values()) {
if (!done)
return;
}
foreach (AkabeiClient::DatabaseHandler* db, AkabeiClient::Backend::instance()->databases()) {
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(int)), this, SLOT(databaseErrorTriggered(int)));
}
m_databases.clear();
QTextStream out(stdout);
out << tr("Updating all databases finished") << endl;
if (status != AkabeiClient::DatabaseHandler::StatusFinished)
return;
AkabeiClient::DatabaseHandler* db = AkabeiClient::Backend::instance()->databases().at(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(int)), this, SLOT(databaseErrorTriggered(int)));
currentDatabasePos++;
updateNextDatabase();
}
......@@ -35,7 +35,9 @@ private slots:
void databaseErrorTriggered(int);
private:
QMap<AkabeiClient::DatabaseHandler*, bool> m_databases;
int currentDatabasePos;
int maxDbNameLenght;
void updateNextDatabase();
};
#endif // SYNCOPERATION_H
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