#include <QSettings>
#include <QStringList>
#include <AniDBUdpClient/MyListState>
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+# include <LocalMyList/MyList>
+# include <LocalMyList/AddFileTask>
+#endif
#include <QxtCommandOptions>
#include <QDebug>
#include "aniaddcli.h"
opts.alias("write-config", "w");
opts.addSection("Actions");
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ opts.add("localmylist", "Use LocalMyList. Note that AniAddCLI settings do not apply when using LocalMyList", QxtCommandOptions::NoValue, 6);
+ opts.add("no-localmylist", "Do not use LocalMyList", QxtCommandOptions::NoValue, 6);
+#endif
opts.add("add", "Add file to MyList", QxtCommandOptions::NoValue, 1);
opts.add("no-add", "Do not add file to MyList", QxtCommandOptions::NoValue, 1);
opts.add("rename", "Rename file", QxtCommandOptions::NoValue, 2);
return -1;
}
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ bool useLocalMyList = false;
+#endif
+
bool rename = true;
bool add = true;
bool setState = true;
bool ok;
QSettings s;
s.beginGroup("actions");
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ useLocalMyList = s.value("useLocalMyList", useLocalMyList).toBool();
+#endif
rename = s.value("rename", rename).toBool();
add = s.value("add", add).toBool();
setState = s.value("setState", setState).toBool();
{
AniDBUdpClient::Client *c = AniDBUdpClient::Client::instance();
bool ok;
-
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ if (opts.count("localmylist"))
+ useLocalMyList = true;
+ if (opts.count("no-localmylist"))
+ useLocalMyList = false;
+#endif
if (opts.count("add"))
add = true;
if (opts.count("no-add"))
{
AniDBUdpClient::Client *c = AniDBUdpClient::Client::instance();
cout << "Actions:" << endl;
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ cout << " LocalMyList: " << (useLocalMyList ? "Yes" : "No") << endl;
+#endif
cout << " Add: " << (add ? "Yes" : "No") << endl;
cout << " Rename: " << (rename ? "Yes" : "No") << endl;
cout << " Update State: " << (setState ? "Yes" : "No") << endl;
AniDBUdpClient::Client *c = AniDBUdpClient::Client::instance();
QSettings s;
s.beginGroup("actions");
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ s.setValue("useLocalMyList", useLocalMyList);
+#endif
s.setValue("rename", rename);
s.setValue("add", add);
s.setValue("setState", setState);
cout << "Try " << qApp->arguments()[0] << " -help for usage." << endl;
}
+#ifndef ANIADDCLI_NO_LOCALMYLIST
+ if (useLocalMyList)
+ {
+ cout << "Using LocalMyList" << endl;
+ using namespace LocalMyList;
+
+ MyList::instance()->loadLocalSettings();
+ if (!MyList::instance()->database()->connect())
+ {
+ cout << "Failed to connect to LocalMyList database." << endl;
+ return 1;
+ }
+
+ int addedFiles = 0;
+ foreach (const QString &fileName, opts.positional())
+ {
+ QFileInfo fileInfo(fileName);
+ if (fileName.startsWith("ed2k://"))
+ {
+ cout << "[FAIL] ed2k is not supported" << endl;
+ continue;
+ }
+ if (!fileInfo.exists())
+ {
+ cout << "[FAIL] File " << fileInfo.absoluteFilePath() << " does not exist" << endl;
+ continue;
+ }
+ if (!fileInfo.isFile())
+ {
+ cout << "[INFO] \"" << fileInfo.absoluteFilePath() << "\" is not a file, skipping" << endl;
+ continue;
+ }
+ cout << "[INFO] Adding \"" << fileInfo.absoluteFilePath() << "\" to LocalMyList" << endl;
+ MyList::instance()->addFile(fileInfo);
+ ++addedFiles;
+ }
+
+ if (!addedFiles)
+ {
+ cout << "No files to process." << endl;
+ return 1;
+ }
+ QObject::connect(MyList::instance(), SIGNAL(allTasksFinished()), qApp, SLOT(quit()));
+ return a.exec();
+ }
+#endif
+
+
AniAddCli t;
t.setState(state);