#include <iostream>
AniAddCli::AniAddCli(QObject *parent) :
- QObject(parent), printHash(false)
+ QObject(parent), printHash(false), cout(stdout, QIODevice::WriteOnly)
{
AniDBUdpClient::Client::instance()->setIdlePolicy(AniDBUdpClient::ImmediateLogoutIdlePolicy);;
connect(AniDBUdpClient::Client::instance(), SIGNAL(connectionError()), this, SLOT(handleError()));
file = AniDBUdpClient::File::fromEd2k(fileName);
if (file == 0)
{
- std::cout << "[FAIL] " << fileName.toUtf8().data() << " is not a valid ed2k uri" << std::endl;
+ cout << "[FAIL] " << fileName.toUtf8().data() << " is not a valid ed2k uri" << endl;
continue;
}
}
QFileInfo fileInfo(fileName);
if (!fileInfo.exists())
{
- std::cout << "[FAIL] File " << fileInfo.absoluteFilePath().toUtf8().data() << " does not exist" << std::endl;
+ cout << "[FAIL] File " << fileInfo.absoluteFilePath() << " does not exist" << endl;
continue;
}
file = new AniDBUdpClient::File(fileInfo);
if (m_files.isEmpty())
{
- std::cout << "No files to process" << std::endl;
+ cout << "No files to process" << endl;
emit finished(1);
return;
}
- std::cout << "Processing " << m_files.count() << " files" << std::endl;
+ cout << "Processing " << m_files.count() << " files" << endl;
}
void AniAddCli::handleStatusUpdate(AniDBUdpClient::File::Action action, AniDBUdpClient::File::ActionState state, int progress)
switch (state)
{
case AniDBUdpClient::File::Success:
- std::cout << "[WIN!] ";
+ cout << "[WIN!] ";
break;
case AniDBUdpClient::File::Failure:
- std::cout << "[FAIL] ";
+ cout << "[FAIL] ";
break;
case AniDBUdpClient::File::InProgress:
default:
- std::cout << "[INFO] ";
+ cout << "[INFO] ";
break;
}
switch (action)
{
case AniDBUdpClient::File::Hashing:
- std::cout << "Hashing ";
+ cout << "Hashing ";
break;
case AniDBUdpClient::File::Renaming:
- std::cout << "Renaming ";
+ cout << "Renaming ";
break;
case AniDBUdpClient::File::Adding:
- std::cout << "Adding ";
+ cout << "Adding ";
break;
case AniDBUdpClient::File::SettingState:
- std::cout << "Set State ";
+ cout << "Set State ";
break;
default:
- std::cout << "Unknown Operation ";
+ cout << "Unknown Operation ";
break;
}
- std::cout << "of file " << file->file().fileName().toUtf8().data();
+ cout << "of file " << file->file().fileName();
switch (state)
{
case AniDBUdpClient::File::Success:
case AniDBUdpClient::File::Finished:
- std::cout << " finished successfully!";
+ cout << " finished successfully!";
break;
case AniDBUdpClient::File::Failure:
- std::cout << " failed";
+ cout << " failed";
break;
case AniDBUdpClient::File::InProgress:
default:
- std::cout << " started";
+ cout << " started";
break;
}
- std::cout << std::endl;
+ cout << endl;
if (printHash && action == AniDBUdpClient::File::Hashing && state == AniDBUdpClient::File::Success)
- std::cout << "[HASH] " << file->file().fileName().toUtf8().constData() << " - " << file->ed2k().constData() << std::endl;
+ cout << "[HASH] " << file->file().fileName() << " - " << file->ed2k() << endl;
}
void AniAddCli::handleError()
{
- std::cout << "[FAIL] Connection error: " << AniDBUdpClient::Client::instance()->errorString().toUtf8().data()
- << std::endl;
+ cout << "[FAIL] Connection error: " << AniDBUdpClient::Client::instance()->errorString() << endl;
emit finished(1);
}
void AniAddCli::exit(int code)
{
if (!code)
- std::cout << "[INFO] Done" << std::endl;
+ cout << "[INFO] Done" << endl;
qApp->exit(code);
}