root/src/library.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef LIBRARY_H
#define LIBRARY_H

#include <QObject>
#include <QFile>
#include <QDir>
#include <qhttprequest.h>
#include <qhttpresponse.h>
#include <QFileSystemWatcher>
#include "tvshow.h"
#include "malclient.h"
#include "malapidotcomclient.h"
#include "moebooruclient.h"
#include "gelbooruclient.h"
#include "metadataparser.h"
#include "libraryfilter.h"
#include "searchdirectory.h"
#include "franchise.h"
#include "onlinesync.h"

class BaseConfig;
class DirectoryScannerThread;

class Library : public QObject
{
    Q_OBJECT
public:

    enum searchStatus {
        notStarted,
        inProgress,
        done
    };

    explicit Library(QString path, QObject *parent = 0);
    virtual ~Library();
    bool initDirectory() const;
    void initWallpaperDownloaders();
    void watchFilesystem();
    void initOnlineSync(const BaseConfig& malConfigFilepath);

    bool handleApiRequest(QHttpRequest* req, QHttpResponse* resp);

    TvShow& tvShow(const QString name, bool setQParent = true);
    TvShow* existingTvShow(const QString name) const;
    const LibraryFilter& filter() const;

    //void xbmcLinkExport(QDir outputDir);
    void write();
    bool writeIndex();
    bool writeShow(TvShow *show);
    bool readAll(bool setQParent = true);

    QDir getDirectory() const;

    void startSearch();
    void startSearch(const QList<SearchDirectory> dirs);
    Library::searchStatus getSearchStatus() const;
    bool getWallpaperDownloadRunning() const;

    const QList<SearchDirectory>& getSearchDirectories() const;
    bool addSearchDirectory(SearchDirectory dir);
    void addWallpaperDownloader(WallpaperDownload::Client* client);
    SearchDirectory* getSearchDirectory(QString path);
    bool removeSearchDirectory(QString path);

    void addToFrenchise(const TvShow *show);

    MetaDataParser *getMetaDataParser() const;
    void setMetaDataParser(MetaDataParser *value);
signals:
    void initDone();
    void showAdded(TvShow* show);
    void searchFinished();
    void wallpaperDownloadersFinished();
    void wallpaperDownloaded(QString);
    void beforeWatchCountChanged(int newValue, int oldValue);
    
public slots:
    void importTvShowEpisode(QString episodePath);
    void startWallpaperDownloaders();
    void fetchMetaData();
    void generateFrenchises();
    void onInitDone();

    void fileChangedInSearchDirectory(QString);
    void onVideoPlaybackEndedNormally(TvShow* show);

private slots:
    void fetchingFinished();
    void wallpaperDownloaderFinished();

    void onBodyForRemoveFiles(QHttpResponse* resp, const QByteArray& body);
private:
    QDir directory;
    QList<TvShow*> tvShows;
    QList<Franchise*> franchises;
    QList<SearchDirectory> searchDirectories;

public:
// put this public, because the server needs, it.
// TODO better remove this from library and move it into main and pass it here as reference
    OnlineSync onlineSync;
private:
    bool didInit;
    LibraryFilter mFilter;
    MetaDataParser* metaDataParser;

    QList<WallpaperDownload::Client*> wallpaperDownloaders;
    QList<WallpaperDownload::FetchThread*> runningWallpaperDownloaders; // TODO only access the clients
    DirectoryScannerThread* searchThread;
    QFileSystemWatcher* fileSystemWatcher;
};

#endif // LIBRARY_H