Salome HOME
Second integration of Salome On Demand
[modules/gui.git] / src / SalomeApprc_utils / SalomeApprc_utils.cxx
1 #include "SalomeApprc_utils.h"
2
3 void AddComponents_from_salomeappdir(const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr)
4 {
5         QFileInfoList salomexd_list = salomeappdir.entryInfoList(QStringList() << "*.salomexd",QDir::Files);
6         foreach(QFileInfo filename, salomexd_list)
7     {
8                 QFile file( filename.filePath() );
9         if ( !file.open( QFile::ReadOnly ) )
10         {
11             qWarning() << "file " << filename.fileName() << " is not accessible";
12             continue;
13         }
14
15         QJsonDocument document = QJsonDocument::fromJson( file.readAll() );
16         if ( document.isNull() )
17         {
18             qWarning() << "invalid json file. Filename: " << filename.fileName();
19             continue;
20         }
21         QJsonObject salomexd_dict = document.object();
22         QJsonValue components = salomexd_dict.value( "components");
23
24                 QString root(salomeappdir.path() + "/__SALOME_EXT__");
25                 if ( components.isArray() )
26                 {
27                         // In the case that we have a list of components. We consider that all of them are GUI module
28                         foreach ( auto comp, components.toArray())
29                         {
30                                 AddGuiComponent(comp.toString(), root, ResMgr);
31                         }
32                 }
33                 else
34                 {
35                         // In the case that we have a dict of several component group
36                         QJsonObject compObj = components.toObject();
37                         foreach ( QString key, compObj.keys() )
38                     {
39                                 if ( QString::compare(key, ITERACTIVE_EXTCOMPONENT_KEY) == 0 )
40                                 {
41                                         foreach (auto comp, compObj.value(key).toArray() )
42                                                 AddGuiComponent(comp.toString(), root, ResMgr);
43                                 }
44                         }
45                 }
46     }
47 }
48
49 void AddComponents_from_salomemodules(const QString& salomemodules, const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr)
50 {
51         QRegularExpression sep(":|,");
52         QStringList components_list = salomemodules.split(sep,QString::SkipEmptyParts);
53         foreach (QString comp, components_list)
54         {
55                 QString comp_root_dir = Qtx::getenv(comp + "_ROOT_DIR");
56
57                 qWarning() << comp;
58                 qWarning() << comp_root_dir;
59                 if (comp_root_dir.isEmpty())
60                         comp_root_dir = salomeappdir.path() + "/__SALOME_EXT__";
61                 AddGuiComponent(comp, comp_root_dir, ResMgr);
62         }
63
64
65 }
66 void AddGuiComponent(const QString& comp, const QString& CompRoot, SUIT_ResourceMgr* ResMgr)
67 {
68         QStringList CompsResMgr = ResMgr->stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts);
69         ResMgr->setValue( "user_modules", comp, CompRoot );
70
71         CompsResMgr << comp;
72         CompsResMgr.removeDuplicates();
73     ResMgr->setValue( "launch", "user_modules", CompsResMgr.join( ";" ) );
74 }