1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2017 UniPro <ugene@unipro.ru>
4  * http://ugene.unipro.ru
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 #include "ScanDashboardsDirTask.h"
23 
24 #include <QDir>
25 #include <QSettings>
26 
27 #include <U2Core/U2SafePoints.h>
28 
29 #include <U2Lang/WorkflowSettings.h>
30 
31 #include "Dashboard.h"
32 
33 namespace U2 {
34 
ScanDashboardsDirTask()35 ScanDashboardsDirTask::ScanDashboardsDirTask()
36     : Task(tr("Scan dashboards folder"), TaskFlag_None) {
37     tpm = Progress_Manual;
38 }
39 
getResult() const40 const QList<DashboardInfo> &ScanDashboardsDirTask::getResult() const {
41     return dashboardInfos;
42 }
43 
run()44 void ScanDashboardsDirTask::run() {
45     QDir outDir(WorkflowSettings::getWorkflowOutputDirectory());
46     CHECK(outDir.exists(), );
47 
48     QFileInfoList dirs = outDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
49     int counter = 0;
50     foreach (const QFileInfo &info, dirs) {
51         CHECK_OP(stateInfo, );
52         QString dirPath = info.absoluteFilePath() + "/";
53         if (isDashboardDir(dirPath)) {
54             dashboardInfos << readDashboardInfo(dirPath);
55         }
56         stateInfo.setProgress((100 * counter++) / dirs.count());
57     }
58 }
59 
isDashboardDir(const QString & dirPath)60 bool ScanDashboardsDirTask::isDashboardDir(const QString &dirPath) {
61     QDir dir(dirPath + Dashboard::REPORT_SUB_DIR);
62     CHECK(dir.exists(), false);
63     CHECK(dir.exists(Dashboard::DB_FILE_NAME), false);
64     CHECK(dir.exists(Dashboard::SETTINGS_FILE_NAME), false);
65     return true;
66 }
67 
readDashboardInfo(const QString & dirPath)68 DashboardInfo ScanDashboardsDirTask::readDashboardInfo(const QString &dirPath) {
69     DashboardInfo info(dirPath);
70     QSettings settings(dirPath + Dashboard::REPORT_SUB_DIR + Dashboard::SETTINGS_FILE_NAME, QSettings::IniFormat);
71     info.opened = settings.value(Dashboard::OPENED_SETTING).toBool();
72     info.name = settings.value(Dashboard::NAME_SETTING).toString();
73     return info;
74 }
75 
76 }  // namespace U2
77