WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. Zuble QML Types   |  Zuble C++ Classes   |  Zuble Overview
Zuble  0.1
Zuble Framework C++/QML extension API
ZblResource.cpp
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2014 Bob Dinitto
4  *
5  * Filename: ZblResource.cpp
6  * Created on: 12/25/2014
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #include "ZblResource.h"
26 #include <QCoreApplication>
27 #include <QFile>
28 #include <QStringList>
29 #include <QResource>
30 
31 namespace Zbl
32 {
33 
34 
36  const char* uri,
37  int versionMajor,
38  int versionMinor,
39  const char* fileName)
40 
41  :
42  m_uri(uri),
43  m_versionMajor(versionMajor),
44  m_versionMinor(versionMinor),
45  m_fileName(fileName),
46  m_loaded(false)
47 {
48 }
49 
51 {
52 
53 }
54 
56 {
57  QString nextPath;
58  QFile file;
59 
60  foreach (const QString &path,
61  QCoreApplication::libraryPaths())
62  {
63  nextPath = path + '/' + m_fileName;
64  file.setFileName(nextPath);
65  if(file.exists())
66  {
67  return true;
68  }
69  }
70  return false;
71 }
72 
74 {
75  if(m_loaded)
76  return true;
77 
78  //qApp->helpMe();
79 
80  QString resPath("/");
81  resPath += m_uri.replace('.','/');
82 
83  QFile f;
84 
85  foreach(const QString &libPath, qApp->libraryPaths())
86  {
87  QString filePath(libPath);
88 
89  filePath += "/" + m_fileName;
90 
91  f.setFileName(filePath);
92 
93  qDebug("ZblResource::load - testing resource file: %s",
94  filePath.toUtf8().constData());
95 
96 
97  if(f.exists())
98  {
99  qDebug("ZblResource::load - registering resource: %s at path %s",
100  filePath.toUtf8().constData(), resPath.toUtf8().constData());
101 
102  m_loaded = QResource::registerResource(filePath,resPath);
103 
104  return m_loaded;
105  }
106  }
107 
108  //TBD: print qWarning here file not found
109 
110  return m_loaded;
111 
112 
113 
114 }
115 
116 
117 } // Zbl
118 
QString m_uri
Resource uri.
Definition: ZblResource.h:103
ZblResource(const char *uri, int versionMajor, int versionMinor, const char *fileName)
Definition: ZblResource.cpp:35
virtual ~ZblResource()
Definition: ZblResource.cpp:50
Definition: ZAndGate.cpp:6
static int versionMinor
Definition: main.cpp:60
static int versionMajor
Definition: main.cpp:59
QString m_fileName
Resource file name.
Definition: ZblResource.h:118
bool m_loaded
true if the resource has been loaded, false otherwise
Definition: ZblResource.h:123