Project Documentation Manager BRIGADOON-0002
Project Documentation Manager
Loading...
Searching...
No Matches
licencemanager.cpp
Go to the documentation of this file.
1#include <QSqlDatabase>
2#include <QSqlQuery>
3
4#include "licencemanager.h"
5
6LicenceManager::LicenceManager::LicenceManager(Ui::MainWindow* UI_Window)
7{
8 ui = UI_Window;
9
10
11 QObject::connect(ui->UpdateQtLicence, SIGNAL(pressed()), this, SLOT(SaveQtLicence()));
12 QObject::connect(ui->SoftwareLicenceList, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSoftwareLicence(int)));
13 QObject::connect(ui->HardwareLicenceList, SIGNAL(currentIndexChanged(int)), this, SLOT(SetHardwareLicence(int)));
14 QObject::connect(ui->DocumentationLicenceList, SIGNAL(currentIndexChanged(int)), this, SLOT(SetDocumentationLicence(int)));
15}
16
18{
19 QSqlDatabase db = QSqlDatabase::database();
20
21 // Clear the Licence List
22 ui->SoftwareLicenceList->clear();
23
24 // Get a List of the Development Families from Database
25 QSqlQuery soft_licence_query( "select licence_index, short_name from licence where licence_type = 1 or licence_type = 3 order by short_name" );
26
27 // Step through the Results
28 int row_index = 0;
29 while ( soft_licence_query.next() )
30 {
31 int licence_index = soft_licence_query.value(0).toInt();
32 QString software_entry = soft_licence_query.value(1).toString();
33 ui->SoftwareLicenceList->addItem( software_entry, licence_index );
34 row_index++;
35 }
36 SendStatusMessage("Software Licence", row_index);
37
38 // Clear the Licence List
39 ui->DocumentationLicenceList->clear();
40
41 // Get a List of the Development Families from Database
42 QSqlQuery doc_licence_query( "select licence_index, short_name from licence where licence_type = 1 or licence_type = 2 order by short_name" );
43
44 // Step through the Results
45 row_index = 0;
46 while ( doc_licence_query.next() )
47 {
48 int licence_index = doc_licence_query.value(0).toInt();
49 QString doc_licence_entry = doc_licence_query.value(1).toString();
50 ui->DocumentationLicenceList->addItem( doc_licence_entry, licence_index );
51 row_index++;
52 }
53 SendStatusMessage("Documentation Licence", row_index);
54
55 // Clear the Licence List
56 ui->HardwareLicenceList->clear();
57
58 // Get a List of the Development Families from Database
59 QSqlQuery hardware_licence_query( "select licence_index, short_name from licence where licence_type = 1 or licence_type = 4 order by short_name" );
60
61 // Step through the Results
62 row_index = 0;
63 while ( hardware_licence_query.next() )
64 {
65 int licence_index = hardware_licence_query.value(0).toInt();
66 QString hardware_entry = hardware_licence_query.value(1).toString();
67 ui->HardwareLicenceList->addItem( hardware_entry, licence_index );
68 row_index++;
69 }
70 SendStatusMessage("Hardware Licence", row_index);
71
72 // Initialise the Qt Licence List
73 ui->QtLicenceList->clear();
74 ui->QtLicenceList->addItems({QString("Community"), QString("Professional"), QString("Enterprise")});
75 SendStatusMessage("Qt Licence List", 3);
76
78}
79
80void LicenceManager::SendStatusMessage(QString Type, int Counter)
81{
82 if (Counter > 0)
83 {
84 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("%1 Loaded with %2 entries.").arg(Type, QString::number(Counter)));
85 }
86 else
87 {
88 LogAdd(LOG_ERROR, MODE_DATABASE, QString("%1 FAILED to load any entries.").arg(Type, Counter));
89 }
90}
91
93{
94 // Open the Settings Data
95 QSettings settings( "brigadoon/netprojectmanager" );
96 ui->QtLicenceList->setCurrentText(settings.value( "Qt/Licence", "Community").toString());
97 LogAdd(LOG_DEBUG, MODE_CONFIG, QString("Qt Licence for Site loaded as %1.").arg(ui->QtLicenceList->currentText()));
98}
99
101{
102 // Open the Settings Data
103 QSettings settings( "brigadoon/netprojectmanager" );
104 settings.setValue( "Qt/Licence", ui->QtLicenceList->currentText());
105 LogAdd(LOG_INFO, MODE_CONFIG, QString("Qt Licence for Site saved as %1.").arg(ui->QtLicenceList->currentText()));
106}
107
108void LicenceManager::LogAdd(LOGGING_SEVERITY Severity, LOGGING_MODE Mode, const QString Message)
109{
110 REMOTE_LOG_ENTRY log_entry;
111 log_entry.Severity = Severity;
112 log_entry.Mode = Mode;
113 log_entry.Message = Message;
114 emit SendLogEntry(log_entry);
115}
116
118{
119 // Assume No Restrictions will be found
120 ui->SoftwareLicenceList->setEnabled(true);
121 ui->DocumentationLicenceList->setEnabled(true);
122 ui->HardwareLicenceList->setEnabled(true);
123
124 QSqlDatabase db = QSqlDatabase::database();
125
126 // See if there is a Licence Restriction for this Tool from Database
127 QSqlQuery tool_restriction_query( QString("select software_licence_restriction, documentation_licence_restriction, hardware_licence_restriction from compiler_instance where compiler_instance_index = %1").arg(QString::number(ToolIndex+1)));
128
129 // Find Any Licence Restrictions for the Primary Tool
130 int row_index = 0;
131 int software_restriction; int documentation_restriction; int hardware_restriction;
132 while ( tool_restriction_query.next() )
133 {
134 software_restriction = tool_restriction_query.value(0).toInt();
135 documentation_restriction = tool_restriction_query.value(1).toInt();
136 hardware_restriction = tool_restriction_query.value(2).toInt();
137 row_index++;
138 }
139
140 // If Entries were found for the Primary Tool, Process Them
141 if (row_index != 0)
142 {
143 // Process Software Licemce Exceptions (if any)
144 bool do_software_restriction = true;
145
146 // Apply Special Exceptions (if any)
147 if ((ToolIndex == 2) &&(ui->QtLicenceList->currentIndex() != 0)) do_software_restriction = false;
148
149 // Process the Software Restrictions
150 if (do_software_restriction) ProcessSoftwareRestriction(software_restriction);
151
152 // Process Software Licemce Exceptions (if any)
153 bool do_documentation_restriction = false;
154
155 // Apply Special Exceptions (if any)
156
157
158 // Process the Documenttaion Restrictions
159 if (do_documentation_restriction) ProcessDocumentationRestriction(documentation_restriction);
160
161 // Process Software Licemce Exceptions (if any)
162 bool do_hardware_restriction = false;
163
164 // Apply Special Exceptions (if any)
165
166
167 // Process the Software Restrictions
168 if (do_hardware_restriction) ProcessHardwareRestriction(hardware_restriction);
169 }
170}
171
173{
174 QString licence_name;
175 bool licence_enabled = true;
176
177 // Check if there is No Software ERestriction
178 if (SoftwareRestriction != 0)
179 {
180 QSqlDatabase db = QSqlDatabase::database();
181 int row_index = 0;
182 QSqlQuery licence_restriction_query(QString("select short_name from licence where licence_index = %1").arg(QString::number(SoftwareRestriction)));
183 while ( licence_restriction_query.next() )
184 {
185 licence_name = licence_restriction_query.value(0).toString();
186 row_index++;
187 }
188
189 if (row_index != 0)
190 {
191 ui->SoftwareLicenceList->setCurrentText(licence_name);
192 licence_enabled = false;
193 }
194 }
195 ui->SoftwareLicenceList->setEnabled(licence_enabled);
196}
197
198void LicenceManager::ProcessDocumentationRestriction(int DocumentationRestriction)
199{
200 bool licence_enabled = true;
201
202 // Check if there is No Documentation ERestriction
203 if (DocumentationRestriction != 0)
204 {
205 QString licence_name;
206 QSqlDatabase db = QSqlDatabase::database();
207 int row_index = 0;
208 QSqlQuery licence_restriction_query(QString("select short_name from licence where licence_index = %1").arg(QString::number(DocumentationRestriction)));
209 while ( licence_restriction_query.next() )
210 {
211 licence_name = licence_restriction_query.value(0).toString();
212 row_index++;
213 }
214
215 if (row_index != 0)
216 {
217 ui->DocumentationLicenceList->setCurrentText(licence_name);
218 }
219 }
220 ui->DocumentationLicenceList->setEnabled(licence_enabled);
221}
222
224{
225 bool licence_enabled = true;
226
227 // Check if there is No Documentation Restriction
228 if (HardwareRestriction != 0)
229 {
230 QString licence_name;
231 QSqlDatabase db = QSqlDatabase::database();
232 int row_index = 0;
233 QSqlQuery licence_restriction_query(QString("select short_name from licence where licence_index = %1").arg(QString::number(HardwareRestriction)));
234 while ( licence_restriction_query.next() )
235 {
236 licence_name = licence_restriction_query.value(0).toString();
237 row_index++;
238 }
239
240 if (row_index != 0)
241 {
242 ui->HardwareLicenceList->setCurrentText(licence_name);
243 }
244 }
245 ui->HardwareLicenceList->setEnabled(licence_enabled);
246}
247
254
256{
257 LICENCE_STATE project_licences;
258 project_licences.SoftwareLicence = GetLicenceIndex(ui->SoftwareLicence->text());
259 project_licences.DocumentationLicence = GetLicenceIndex(ui->SoftwareLicence->text());
260 project_licences.HardwareLicence = GetLicenceIndex(ui->HardwareLicence->text());
261 emit SendLicenceState(project_licences);
262}
263
264uint LicenceManager::GetLicenceIndex(QString LicenceText)
265{
266 uint licence_index = 0;
267 QSqlQuery licence_index_query( QString("select licence_index from licence where short_name = '%1'").arg(LicenceText));
268 while ( licence_index_query.next() )
269 {
270 licence_index = licence_index_query.value(0).toInt();
271 }
272 return(licence_index);
273}
274
276{
277 LogAdd(LOG_DEBUG, MODE_QT, "Request to Send Licences Received.");
279}
280
282{
283 LoadLicences();
284}
285
287{
288 QString LicenceName = ui->SoftwareLicenceList->itemText(LicenceIndex);
289 emit UpdateSoftwareLicence(LicenceName);
290}
291
293{
294 QString LicenceName = ui->HardwareLicenceList->itemText(LicenceIndex);
295 emit UpdateHardwareLicence(LicenceName);
296}
297
299{
300 QString LicenceName = ui->DocumentationLicenceList->itemText(LicenceIndex);
301 emit UpdateDocumentationLicence(LicenceName);
302}
303
void SetSoftwareLicence(int LicenceIndex)
Set the Software Licence.
void SendLogEntry(REMOTE_LOG_ENTRY LogEntry)
Send Log Entry to the Log \LogEntry Structure holding Log information.
void ReadPrimaryTool(int ToolIndex)
read Primary Tool & Apply any licence Restrictions
void LoadLicences(void)
Load the Licence Data from the Database.
Ui::MainWindow * ui
Pointer to the Main Window.
void LogAdd(LOGGING_SEVERITY Severity, LOGGING_MODE Mode, const QString Message)
Add a Log Entry.
void SaveQtLicence(void)
Save the Default Qt Licence to settings.
void UpdateHardwareLicence(QString LicenceName)
Emits the Text Name of the Hardware Lidence.
void UpdateDocumentationLicence(QString LicenceName)
Emits the Text Name of the Documentation Lidence.
void TriggerSendLicence(void)
Trigger to send out the Licence states.
uint GetLicenceIndex(QString LicenceText)
Find the Licence Index from the Licence text.
void SendStatusMessage(QString Type, int Counter)
Send the Type of Licence and the number licences loaded.
void UpdateSoftwareLicence(QString LicenceName)
Emits the Text Name of the Software Lidence.
void SetHardwareLicence(int LicenceIndex)
Set the Hardware Licence.
void WriteLicenceState(void)
Read the Current Lilcence Stae on Display & Send out.
void ProcessSoftwareRestriction(int DocumentationRestriction)
Use the Soft Restrictions to limit the possible licence selections.
void SetDocumentationLicence(int LicenceIndex)
Set the Documentation Licence.
void ProcessDocumentationRestriction(int DocumentationRestriction)
Use the Documenrtation Restrictions to limit the possible licence selections.
void LoadQtLicence(void)
Load the Qt Licence from settings.
void ProcessHardwareRestriction(int HardwareRestriction)
Use the Hardware Restrictions to limit the possible licence selections.
void DoClear(void)
Resest the Licences fro the Database.
void ReadLicenceState(LICENCE_STATE LicenceState)
process the Licence state including any restrictions
void SendLicenceState(LICENCE_STATE LicenceState)
Send the State of the Licences.
Class Controlling the project's Licences.
LOGGING_SEVERITY
Log Severity allow the selection of logging events based on Severity.
Definition logger.h:48
@ LOG_ERROR
Definition logger.h:52
@ LOG_INFO
Definition logger.h:55
@ LOG_DEBUG
Definition logger.h:56
LOGGING_MODE
Log Severity allow the selection of logging events based on the mode.
Definition logger.h:21
@ MODE_QT
Definition logger.h:23
@ MODE_CONFIG
Definition logger.h:26
@ MODE_DATABASE
Definition logger.h:35
Assigned Software, Hardware and COgumenttaion Licences.
Definition logger.h:60
LOGGING_MODE Mode
Definition logger.h:61
QString Message
Definition logger.h:63
LOGGING_SEVERITY Severity
Definition logger.h:62