Commit aaed1615 authored by Lisa's avatar Lisa Committed by Lukas Appelhans

Starting error handling

parent ad9b8a18
......@@ -33,6 +33,8 @@ OperationManager::OperationManager(APM::OperationType type, QList<APM::Operation
m_args(args)
{
connect(AkabeiClient::Backend::instance(), SIGNAL(statusChanged(Akabei::Backend::Status)), SLOT(statusChanged(Akabei::Backend::Status)), Qt::QueuedConnection);
Akabei::ErrorQueue::instance()->registerForAllErrors(this, "showError");
QString root;
QString cache;
QString dbs;
......@@ -63,6 +65,28 @@ OperationManager::~OperationManager()
{
}
void OperationManager::showErrors()
{
QTextStream err(stderr);
Akabei::Error error = Akabei::ErrorQueue::instance()->takeError();
switch (error.type()) {
case Akabei::Error::BackendInitializationError: {
err << Akabei::errorPrefix << i18n("The backend seems to be in a broken state. ");
err << i18n(error.description().toUtf8().data()) << endl;
err << Akabei::errorPrefix << i18n("This often means that you don't have enough permissions to perform this operation.");
break;
}
default:
err << Akabei::errorPrefix << i18n( error.description().toUtf8().data() );
break;
}
err << endl;
Akabei::Backend::instance()->deInit();
QCoreApplication::instance()->quit();
}
void OperationManager::statusChanged(Akabei::Backend::Status status)
{
......@@ -77,20 +101,7 @@ void OperationManager::statusChanged(Akabei::Backend::Status status)
out << i18n("Another instance of akabei is currently running. When it finishes, we will continue!") << endl;
break;
}
case Akabei::Backend::StatusBroken: {
QTextStream err(stderr);
err << Akabei::errorPrefix << i18n("The backend seems to be in a broken state. ");
if (Akabei::Backend::instance()->initError().type() == Akabei::Error::BackendInitializationError) {
QString description = Akabei::Backend::instance()->initError().description();
err << i18n(description.toUtf8().data()) << endl;
err << Akabei::errorPrefix << i18n("This often means that you don't have enough permissions to perform this operation.");
}
err << endl;
exit(1);
}
default:
break;
}
......
......@@ -27,6 +27,7 @@ public:
private slots:
void statusChanged(Akabei::Backend::Status);
void start();
void showErrors();
void quit();
private:
......
......@@ -126,8 +126,8 @@ void SyncOperation::updateDatabases()
out << i18n("Starting database update ...") << endl;
foreach (AkabeiClient::DatabaseHandler* db, AkabeiClient::Backend::instance()->databases()) {
if (db->name().length() > m_maxDbNameLenght)
m_maxDbNameLenght = db->name().length();
if (db->name().length() > m_maxDbNameLength)
m_maxDbNameLength = db->name().length();
}
currentDatabase = AkabeiClient::Backend::instance()->databases().constBegin();
lastDatabase = AkabeiClient::Backend::instance()->databases().constEnd();
......@@ -376,6 +376,29 @@ void SyncOperation::databaseProgressChanged(int progress)
out << m_bar.line();
}
void SyncOperation::updateError()
{
Akabei::ErrorQueue* queue = Akabei::ErrorQueue::instance();
Akabei::Error error = queue->takeError();
QTextStream out( stdout );
AkabeiClient::DatabaseHandler* db = *currentDatabase;
switch ( error.type() ) {
case Akabei::Error::NetworkOperationCanceledError: {
out << m_bar.replaceMessage( i18n("%1 already up to date!", db->name()) ) << endl;
break;
}
default:
out << Akabei::errorPrefix << m_bar.replaceMessage(i18n("%1 could not be updated!", db->name())) << endl;
out << Akabei::errorPrefix << m_bar.replaceMessage( i18n(error.description().toUtf8().data()) ) << endl;
break;
}
currentDatabase++;
updateNextDatabase();
}
void SyncOperation::databaseStatusChanged(AkabeiClient::DatabaseHandler::Status status)
{
if (status != AkabeiClient::DatabaseHandler::StatusFinished &&
......
......@@ -41,11 +41,12 @@ private slots:
public slots:
void updateNextDatabase();
void updateError();
private:
QList<AkabeiClient::DatabaseHandler*>::const_iterator currentDatabase;
QList<AkabeiClient::DatabaseHandler*>::const_iterator lastDatabase;
int m_maxDbNameLenght;
int m_maxDbNameLength;
void updateSystem();
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