]> Some of my projects - AniAddCLI.git/commitdiff
Add some basic LocalMyList integration
authorAPTX <marek321@gmail.com>
Wed, 13 Jun 2012 11:19:29 +0000 (13:19 +0200)
committerAPTX <marek321@gmail.com>
Wed, 13 Jun 2012 11:19:29 +0000 (13:19 +0200)
AniAddCLI.pro
config.pri [new file with mode: 0644]
main.cpp

index 17d02edfec3c81320d0a0b31102fe75ec0d92f01..d18e52c39d2ae548518653257e39ee8cf0bd7312 100644 (file)
@@ -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 (file)
index 0000000..e69de29
index c628028233275b5c939c2c4c5dad79c1d557a995..d19197762dbf6add2dcd48dad0219f2f288fa06b 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -4,6 +4,10 @@
 #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"
@@ -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);