1 /***************************************************************************
2 **                                                                        **
3 **  Polyphone, a soundfont editor                                         **
4 **  Copyright (C) 2013-2019 Davy Triponney                                **
5 **                                                                        **
6 **  This program is free software: you can redistribute it and/or modify  **
7 **  it under the terms of the GNU General Public License as published by  **
8 **  the Free Software Foundation, either version 3 of the License, or     **
9 **  (at your option) any later version.                                   **
10 **                                                                        **
11 **  This program is distributed in the hope that it will be useful,       **
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the          **
14 **  GNU General Public License for more details.                          **
15 **                                                                        **
16 **  You should have received a copy of the GNU General Public License     **
17 **  along with this program. If not, see http://www.gnu.org/licenses/.    **
18 **                                                                        **
19 ****************************************************************************
20 **           Author: Davy Triponney                                       **
21 **  Website/Contact: https://www.polyphone-soundfonts.com                 **
22 **             Date: 01.01.2013                                           **
23 ***************************************************************************/
24 
25 #ifndef REPOSITORYMANAGER_H
26 #define REPOSITORYMANAGER_H
27 
mongo_sync_gridfs_stream_find(mongo_sync_gridfs * gfs,const bson * query)28 #include <QObject>
29 #include <QList>
30 #include <QMap>
31 #include "soundfontinformation.h"
32 #include "soundfontfilter.h"
33 class UrlReaderJson;
34 
35 class RepositoryManager: public QObject
36 {
37     Q_OBJECT
38 
39 public:
40     static const QString BASE_URL;
41 
42     // Singleton: get the instance of the object and finally kill it
43     static RepositoryManager * getInstance();
44     static void kill();
45 
46     // Initialize the soundfont list. The signal "ready()" is emitted when the initialization is complete
47     void initialize();
48 
49     // Get soundfont information
50     SoundfontInformation * getSoundfontInformation(int id);
51     QList<SoundfontInformation *> getSoundfontInformation(SoundfontFilter *filter);
52 
53     // Get the categories, properties, license and tags
54     QList<int> getCategories() { return _categoryNames.keys(); }
55     QString getCategoryName(int id);
56     QStringList getProperties(SoundfontInformation::Property property) { return _properties[property]; }
57     QString getLicenseLabel(QString licenseKey);
58     QMap<QString, QString> getLicenseLabels() { return _licenseLabels; }
59     QString getLicenseLink(QString licenseKey);
60     QStringList getTags() { return _tags; }
61 
62     // Ask for opening a soundfont
63     void openSoundfont(int soundfontId, bool daily);
64 
65 signals:
66     // Notify that the list is downloading
67     void initializing();
68 
69     // Emitted when the initialization is complete
70     // Possibly contains an error if the soundfont list cannot be downloaded
71     void ready(QString error);
72 
73     // Open a soundfont from the repository
74     void openSoundfont(int id);
75 
76 private slots:
77     void soundfontListAvailable(QString error);
78 
79 private:
80     RepositoryManager();
81     ~RepositoryManager();
82     void fillPropertyTranslation();
83     void fillLicenseLabelAndLink();
84     QString loadSoundfontInfo();
85     void loadProperty(SoundfontInformation * si, const QJsonValue &value, SoundfontInformation::Property property);
86     QString getPropertyTranslation(SoundfontInformation::Property property, QString value);
87 
88     static RepositoryManager * s_instance;
89     QMap<int, SoundfontInformation *> _soundfontInfos; // Classified by ID
90     UrlReaderJson * _urlReaderJsonList;
91     QMap<int, QString> _categoryNames;
92     QMap<SoundfontInformation::Property, QStringList> _properties;
93     QMap<SoundfontInformation::Property, QMap<QString, QString>> _propertyTranslations;
94     QMap<QString, QString> _licenseLabels;
95     QString _licenseUrl;
96     QStringList _tags;
97 };
98 
99 #endif // REPOSITORYMANAGER_H
100