Commit 3dfb1265 authored by Lukas Appelhans's avatar Lukas Appelhans

Updating databases yay!

parent dd4be7a4
......@@ -55,6 +55,14 @@ void SyncOperation::start(QList<APM::Operation> operations, QMultiHash<APM::Oper
connect(Akabei::Backend::instance(), SIGNAL(queryGroupsCompleted(QUuid,QList<Akabei::Group*>)),
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)));
}
AkabeiClient::Backend::instance()->updateDatabase();
}
}
......@@ -176,3 +184,47 @@ void SyncOperation::showGroup(QUuid uuid,QList<Akabei::Group*> groups)
out.flush();
}
void SyncOperation::databaseErrorTriggered(int error)
{
}
void SyncOperation::databaseProgressChanged(int progress)
{
QTextStream out(stdout);
out << static_cast<AkabeiClient::DatabaseHandler*>(QObject::sender())->name();
out << " [";
for (int i = 1; i != 11; i++) {
if (progress / i >= 10) {
out << "#";
} else {
out << "-";
}
}
out << "] " << progress << "%";
if (progress == 100) {
out << endl;
} else {
out << "\r";
}
out.flush();
}
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;
}
......@@ -14,6 +14,7 @@
#include <QObject>
#include <QUuid>
#include "apm.h"
#include <akabeiclient/akabeidatabasehandler.h>
class SyncOperation : public QObject
{
......@@ -29,6 +30,12 @@ private slots:
void listRepo(const QString &repo);
void showInformation(QUuid,QList<Akabei::Package*> packages);
void showGroup(QUuid,QList<Akabei::Group*>);
void databaseStatusChanged(AkabeiClient::DatabaseHandler::Status);
void databaseProgressChanged(int);
void databaseErrorTriggered(int);
private:
QMap<AkabeiClient::DatabaseHandler*, bool> m_databases;
};
#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