From: APTX Date: Wed, 13 Jun 2012 11:19:29 +0000 (+0200) Subject: Add some basic LocalMyList integration X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=fdd4926d4ec8a18d6bc0a4b6ef60456e32aa9aba;p=AniAddCLI.git Add some basic LocalMyList integration --- diff --git a/AniAddCLI.pro b/AniAddCLI.pro index 17d02ed..d18e52c 100644 --- a/AniAddCLI.pro +++ b/AniAddCLI.pro @@ -15,6 +15,16 @@ LIBS += -lanidbudpclient HEADERS += \ aniaddcli.h +include(config.pri) + +!nolocalmylist { + LIBS += -llocalmylist + QT += sql +} +nolocalmylist { + DEFINES += ANIADDCLI_NO_LOCALMYLIST +} + target.path = $${PREFIX}/bin INSTALLS += target diff --git a/config.pri b/config.pri new file mode 100644 index 0000000..e69de29 diff --git a/main.cpp b/main.cpp index c628028..d191977 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,10 @@ #include #include #include +#ifndef ANIADDCLI_NO_LOCALMYLIST +# include +# include +#endif #include #include #include "aniaddcli.h" @@ -90,6 +94,10 @@ int main(int argc, char *argv[]) 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); @@ -144,6 +152,10 @@ int main(int argc, char *argv[]) return -1; } +#ifndef ANIADDCLI_NO_LOCALMYLIST + bool useLocalMyList = false; +#endif + bool rename = true; bool add = true; bool setState = true; @@ -157,6 +169,9 @@ int main(int argc, char *argv[]) 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(); @@ -191,7 +206,12 @@ int main(int argc, char *argv[]) { 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")) @@ -257,6 +277,9 @@ int main(int argc, char *argv[]) { 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; @@ -288,6 +311,9 @@ int main(int argc, char *argv[]) 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); @@ -320,6 +346,54 @@ int main(int argc, char *argv[]) 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);