1 /**************************************************************************
2 ** This file is part of LiteIDE
3 **
4 ** Copyright (c) 2011-2019 LiteIDE. All rights reserved.
5 **
6 ** This library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Lesser General Public
8 ** License as published by the Free Software Foundation; either
9 ** version 2.1 of the License, or (at your option) any later version.
10 **
11 ** This library 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 GNU
14 ** Lesser General Public License for more details.
15 **
16 ** In addition, as a special exception,  that plugins developed for LiteIDE,
17 ** are allowed to remain closed sourced and can be distributed under any license .
18 ** These rights are included in the file LGPL_EXCEPTION.txt in this package.
19 **
20 **************************************************************************/
21 // Module: buildmanager.cpp
22 // Creator: visualfc <visualfc@gmail.com>
23 
24 #include "buildmanager.h"
25 #include "build.h"
26 #include <QDir>
27 #include <QFileInfo>
28 #include <QFile>
29 #include <QDebug>
30 //lite_memory_check_begin
31 #if defined(WIN32) && defined(_MSC_VER) &&  defined(_DEBUG)
32      #define _CRTDBG_MAP_ALLOC
33      #include <stdlib.h>
34      #include <crtdbg.h>
35      #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
36      #define new DEBUG_NEW
37 #endif
38 //lite_memory_check_end
39 
40 
BuildManager(QObject * parent)41 BuildManager::BuildManager(QObject *parent)
42     : LiteApi::IBuildManager(parent)
43 {
44     m_build = 0;
45 }
46 
~BuildManager()47 BuildManager::~BuildManager()
48 {
49     qDeleteAll(m_buildList);
50 }
51 
addBuild(IBuild * build)52 void BuildManager::addBuild(IBuild *build)
53 {
54     m_buildList.append(build);
55 }
56 
removeBuild(IBuild * build)57 void BuildManager::removeBuild(IBuild *build)
58 {
59     m_buildList.removeAll(build);
60 }
61 
findBuild(const QString & mimeType)62 IBuild *BuildManager::findBuild(const QString &mimeType)
63 {
64     foreach(IBuild *build, m_buildList) {
65         if (build->mimeType() == mimeType) {
66             return build;
67         }
68     }
69     return 0;
70 }
71 
buildList() const72 QList<IBuild*> BuildManager::buildList() const
73 {
74     return m_buildList;
75 }
76 
setCurrentBuild(LiteApi::IBuild * build)77 void BuildManager::setCurrentBuild(LiteApi::IBuild *build)
78 {
79     if (m_build == build) {
80         return;
81     }
82     m_build = build;
83     emit buildChanged(m_build);
84 }
85 
currentBuild() const86 IBuild *BuildManager::currentBuild() const
87 {
88     return m_build;
89 }
90 
load(const QString & path)91 void BuildManager::load(const QString &path)
92 {
93     QDir dir = path;
94     m_liteApp->appendLog("BuildManager","Loading "+path);
95     dir.setFilter(QDir::Files | QDir::NoSymLinks);
96     dir.setNameFilters(QStringList("*.xml"));
97     foreach (QString fileName, dir.entryList()) {
98         Build::loadBuild(this,QFileInfo(dir,fileName).absoluteFilePath());
99     }
100 }
101