#include <QFileInfo>
AniAddCli::AniAddCli(QObject *parent) :
- QObject(parent), printHash(false), cout(stdout, QIODevice::WriteOnly), showNewVersionInfo(false), closing(false), errorPrinted(false)
+ QObject(parent), printHash(false), printEd2k(false), cout(stdout, QIODevice::WriteOnly), showNewVersionInfo(false), closing(false), errorPrinted(false)
{
AniDBUdpClient::Client::instance()->setIdlePolicy(AniDBUdpClient::ImmediateLogoutIdlePolicy);;
connect(AniDBUdpClient::Client::instance(), SIGNAL(connectionError()), this, SLOT(handleError()));
m_state = state;
}
-void AniAddCli::process(const QStringList &files, bool rename, bool add, bool setState, bool hash)
+void AniAddCli::process(const QStringList &files, bool rename, bool add, bool setState, bool hash, bool ed2k)
{
foreach(const QString &fileName, files)
{
file->setState(m_state);
- if (hash)
+ if (hash || ed2k)
{
file->hash();
- printHash = true;
+ printHash = hash;
+ printEd2k = ed2k;
}
if (rename)
file->rename();
if (printHash && action == AniDBUdpClient::File::Hashing && state == AniDBUdpClient::File::Success)
cout << "[HASH] " << file->file().fileName() << " - " << file->ed2k() << endl;
+
+ if (printEd2k && action == AniDBUdpClient::File::Adding && state == AniDBUdpClient::File::Failure && !file->ed2k().isEmpty())
+ cout << "[ED2K] ed2k://|file|" << file->file().fileName() << "|" << file->file().size() << "|" << file->ed2k() << "|/" << endl;
}
void AniAddCli::handleError()
AniDBUdpClient::MyListState state() const;
void setState(const AniDBUdpClient::MyListState &state);
- void process(const QStringList &files, bool rename = true, bool add = true, bool setState = true, bool hash = false);
+ void process(const QStringList &files, bool rename = true, bool add = true, bool setState = true, bool hash = false, bool ed2k = false);
AniDBUdpClient::MyListState m_state;
bool printHash;
+ bool printEd2k;
bool showNewVersionInfo;
bool closing;
bool errorPrinted;
opts.add("no-update-state", "Do not update state", QxtCommandOptions::NoValue, 3);
opts.add("hash", "Print hash", QxtCommandOptions::NoValue, 4);
opts.add("no-hash", "Do not print hash", QxtCommandOptions::NoValue, 4);
+ opts.add("ed2k", "Print ed2k URIs for files which failed to be added", QxtCommandOptions::NoValue, 5);
+ opts.add("no-ed2k", "Do not print ed2k URIs", QxtCommandOptions::NoValue, 5);
opts.addSection("Account settings");
opts.add("user", "AniDB user name", QxtCommandOptions::ValueRequired);
bool add = true;
bool setState = true;
bool hash = false;
+ bool ed2k = false;
// Read settings from config
if (!opts.count("no-config"))
add = s.value("add", add).toBool();
setState = s.value("setState", setState).toBool();
hash = s.value("hash", hash).toBool();
+ ed2k = s.value("ed2k", ed2k).toBool();
s.endGroup();
s.beginGroup("account");
c->setUser(s.value("user", "").toString());
hash = true;
if (opts.count("no-hash"))
hash = false;
+ if (opts.count("ed2k"))
+ ed2k = true;
+ if (opts.count("no-ed2k"))
+ ed2k = false;
if (opts.count("user"))
c->setUser(opts.value("user").toString());
cout << " Add: " << (add ? "Yes" : "No") << endl;
cout << " Rename: " << (rename ? "Yes" : "No") << endl;
cout << " Update State: " << (setState ? "Yes" : "No") << endl;
- cout << " Print Hash: " << (hash ? "Yes" : "No") << endl << endl;
+ cout << " Print Hash: " << (hash ? "Yes" : "No") << endl;
+ cout << " Print ed2k: " << (ed2k ? "Yes" : "No") << endl << endl;
cout << "Account settings:" << endl;
cout << " User: " << c->user() << endl;
s.setValue("add", add);
s.setValue("setState", setState);
s.setValue("hash", hash);
+ s.setValue("ed2k", ed2k);
s.endGroup();
s.beginGroup("account");
s.setValue("user", c->user());
AniAddCli t;
t.setState(state);
- t.process(opts.positional(), rename, add, setState, hash);
+ t.process(opts.positional(), rename, add, setState, hash, ed2k);
return a.exec();
}