1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (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, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_DATA_PATH_REGISTRY_H
23 #define _U2_DATA_PATH_REGISTRY_H
24 
25 #include <QDir>
26 #include <QMap>
27 
28 #include <U2Core/global.h>
29 
30 namespace U2 {
31 
32 /**
33  * class to access data that different tools might need e.g. data bases, samples, test files, ...
34  * registers data name and path to data
35  * it will analyze the path storing all the data in the map data_file_name -> data_full_path where data_file_name is a name of a file
36  */
37 class U2CORE_EXPORT U2DataPath : public QObject {
38     Q_OBJECT
39 public:
40     enum Option {
41         None = 0,
42         AddOnlyFolders = 1 << 0,
43         AddRecursively = 1 << 1,
44         CutFileExtension = 1 << 2,
45         AddTopLevelFolder = 1 << 3
46     };
47     Q_DECLARE_FLAGS(Options, Option)
48 
49     U2DataPath(const QString &name, const QString &path, const QString &descr = "", Options options = None);
50 
51     const QString &getName() const;
52     const QString &getPath() const;
53     const QString &getDescription() const;
54 
55     const QMap<QString, QString> &getDataItems() const;
56     QList<QString> getDataNames() const;
57 
58     bool isValid() const;
59     bool isFolders() const;
60 
61     QVariantMap getDataItemsVariantMap() const;
62     QString getPathByName(const QString &name) const;  // first name found is returned. if your items have similar names use getDataItems()
63 
64     bool operator==(const U2DataPath &other) const;
65     bool operator!=(const U2DataPath &other) const;
66 
67 private:
68     void init();
69     void fillDataItems(const QDir &dir, bool recursive);
70     QString chopExtention(QString name);
71 
72     QString name;
73     QString path;
74     QString description;
75     QMap<QString, QString> dataItems;  // data_file_name -> data_full_path
76     Options options;
77     bool valid;
78 };
79 
80 class U2CORE_EXPORT U2DataPathRegistry : public QObject {
81     Q_OBJECT
82 public:
83     ~U2DataPathRegistry();
84 
85     U2DataPath *getDataPathByName(const QString &name);
86 
87     bool registerEntry(U2DataPath *dp);
88     void unregisterEntry(const QString &name);
89 
90     QList<U2DataPath *> getAllEntries() const;
91 
92 private:
93     QMap<QString, U2DataPath *> registry;
94 };
95 
96 }  // namespace U2
97 
98 Q_DECLARE_OPERATORS_FOR_FLAGS(U2::U2DataPath::Options)
99 
100 #endif  // _U2_DATA_PATH_REGISTRY_H
101