~ubuntu-branches/ubuntu/trusty/ginkgocadx/trusty

« back to all changes in this revision

Viewing changes to src/cadxcore/main/controllers/configurationcontroller.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-07-21 11:58:53 UTC
  • mfrom: (7.2.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721115853-44e7n1xujqglu78e
Tags: 3.4.0.928.29+dfsg-1
* New upstream release [July 2013]
  + new B-D: "libjsoncpp-dev".
  + new patch "unbundle-libjsoncpp.patch" to avoid building bundled
    "libjsoncpp-dev".
  + new patch "fix-wx.patch" to avoid FTBFS due to missing
    "-lwx_gtk2u_html-2.8".
* Removed unnecessary versioned Build-Depends.
* Removed obsolete lintian override.
* Reference get-orig-source implementation for orig.tar clean-up and
  DFSG-repackaging.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
122
122
                        return writeString(TC_User, scope, key, value);
123
123
                }
124
124
 
125
 
      bool ConfigurationController::readStringUser(const std::string& scope, const std::string& key, std::string& value, const std::string& defaultValue)
 
125
                bool ConfigurationController::readStringUser(const std::string& scope, const std::string& key, std::string& value, const std::string& defaultValue)
126
126
                {
127
127
                        if (!readString(TC_General, scope, key, value, defaultValue)) {
128
 
                                return readString(TC_User, scope, key, value, defaultValue);
129
 
                        } else {
130
 
                                return true;
 
128
                                if (!readString(TC_Machine, scope, key, value, defaultValue)) { 
 
129
                                        return readString(TC_User, scope, key, value, defaultValue);
 
130
                                }
131
131
                        }
 
132
                        return true;                    
132
133
                }
133
134
 
134
135
                bool ConfigurationController::readBoolUser(const std::string& scope, const std::string& key, bool& value, bool defaultValue)
135
136
                {
136
137
                        if (!readBool(TC_General, scope, key, value, defaultValue)) {
137
 
                                return readBool(TC_User, scope, key, value, defaultValue);
138
 
                        } else {
139
 
                                return true;
140
 
                        }
 
138
                                if (!readBool(TC_Machine, scope, key, value, defaultValue)) {
 
139
                                        return readBool(TC_User, scope, key, value, defaultValue);
 
140
                                }
 
141
                        } 
 
142
                        return true;
141
143
                }
142
144
 
143
145
                bool ConfigurationController::writeBoolUser(const std::string& scope, const std::string& key, bool value)
148
150
                bool ConfigurationController::readIntUser(const std::string& scope, const std::string& key, int& value, int defaultValue)
149
151
                {
150
152
                        if (!readInt(TC_General, scope, key, value, defaultValue)) {
151
 
                                return readInt(TC_User, scope, key, value, defaultValue);
152
 
                        } else {
153
 
                                return true;
154
 
                        }
 
153
                                if (!readInt(TC_Machine, scope, key, value, defaultValue)) {
 
154
                                        return readInt(TC_User, scope, key, value, defaultValue);       
 
155
                                }
 
156
                        } 
 
157
                        return true;                    
155
158
                }
156
159
 
157
160
                bool ConfigurationController::writeIntUser(const std::string& scope, const std::string& key, int value)
162
165
                bool ConfigurationController::readDoubleUser(const std::string& scope, const std::string& key, double& value, double defaultValue)
163
166
                {
164
167
                        if (!readDouble(TC_General, scope, key, value, defaultValue)) {
165
 
                                return readDouble(TC_User, scope, key, value, defaultValue);
166
 
                        } else {
167
 
                                return true;
168
 
                        }
 
168
                                if (!readDouble(TC_Machine, scope, key, value, defaultValue)) {
 
169
                                        return readDouble(TC_User, scope, key, value, defaultValue);
 
170
                                }
 
171
                        } 
 
172
                        return true;
169
173
                }
170
174
 
171
175
                bool ConfigurationController::writeDoubleUser(const std::string& scope, const std::string& key, double value)
181
185
                bool ConfigurationController::readGroupUser(const std::string& scope, TListGroups& listOfGroups) 
182
186
                {
183
187
                        if (!readGroup(TC_General, scope, listOfGroups)) {
184
 
                                return readGroup(TC_User, scope, listOfGroups);
185
 
                        } else {
186
 
                                return true;
 
188
                                if (!readGroup(TC_Machine, scope, listOfGroups)) {
 
189
                                        return readGroup(TC_User, scope, listOfGroups);
 
190
                                }
187
191
                        }
 
192
                        return true;
188
193
                }
189
194
 
190
195
                bool ConfigurationController::saveGlobalConfigurationFile(const std::string& path)
230
235
                {
231
236
                        wxCriticalSectionLocker locker(m_criticalSection);
232
237
                        wxConfigBase * config;
233
 
                        if (type==TC_General) {
234
 
                                config = m_pGeneralConfig;
235
 
                        } else {
236
 
                                config = m_pUserConfig;
 
238
                        switch (type) {
 
239
                                case TC_User:
 
240
                                        config = m_pUserConfig;
 
241
                                        break;
 
242
                                case TC_Machine: 
 
243
                                        config = m_pMachineConfig;
 
244
                                        break;
 
245
                                case TC_General:
 
246
                                default:
 
247
                                        config = m_pGeneralConfig;
 
248
                        }
 
249
                        if (config == NULL) {
 
250
                                return false;
237
251
                        }
238
252
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
239
253
 
246
260
                {
247
261
                        wxCriticalSectionLocker locker(m_criticalSection);
248
262
                        wxConfigBase * config;
249
 
                        if (type==TC_General) {
250
 
                                config = m_pGeneralConfig;
251
 
                        } else {
252
 
                                config = m_pUserConfig;
 
263
                        switch (type) {
 
264
                                case TC_User:
 
265
                                        config = m_pUserConfig;
 
266
                                        break;
 
267
                                case TC_Machine: 
 
268
                                        config = m_pMachineConfig;
 
269
                                        break;
 
270
                                case TC_General:
 
271
                                default:
 
272
                                        config = m_pGeneralConfig;
 
273
                        }
 
274
                        if (config == NULL) {
 
275
                                return false;
253
276
                        }
254
277
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
255
278
                        wxString wxTmp;
262
285
                {
263
286
                        wxCriticalSectionLocker locker(m_criticalSection);
264
287
                        wxConfigBase * config;
265
 
                        if (type==TC_General) {
266
 
                                config = m_pGeneralConfig;
267
 
                        } else {
268
 
                                config = m_pUserConfig;
 
288
                        switch (type) {
 
289
                                case TC_User:
 
290
                                        config = m_pUserConfig;
 
291
                                        break;
 
292
                                case TC_Machine: 
 
293
                                        config = m_pMachineConfig;
 
294
                                        break;
 
295
                                case TC_General:
 
296
                                default:
 
297
                                        config = m_pGeneralConfig;
 
298
                        }
 
299
                        if (config == NULL) {
 
300
                                return false;
269
301
                        }
270
302
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
271
303
 
278
310
                {
279
311
                        wxCriticalSectionLocker locker(m_criticalSection);
280
312
                        wxConfigBase * config;
281
 
                        if (type==TC_General) {
282
 
                                config = m_pGeneralConfig;
283
 
                        } else {
284
 
                                config = m_pUserConfig;
 
313
                        switch (type) {
 
314
                                case TC_User:
 
315
                                        config = m_pUserConfig;
 
316
                                        break;
 
317
                                case TC_Machine: 
 
318
                                        config = m_pMachineConfig;
 
319
                                        break;
 
320
                                case TC_General:
 
321
                                default:
 
322
                                        config = m_pGeneralConfig;
 
323
                        }
 
324
                        if (config == NULL) {
 
325
                                return false;
285
326
                        }
286
327
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
287
328
                        
294
335
                {
295
336
                        wxCriticalSectionLocker locker(m_criticalSection);
296
337
                        wxConfigBase * config;
297
 
                        if (type==TC_General) {
298
 
                                config = m_pGeneralConfig;
299
 
                        } else {
300
 
                                config = m_pUserConfig;
 
338
                        switch (type) {
 
339
                                case TC_User:
 
340
                                        config = m_pUserConfig;
 
341
                                        break;
 
342
                                case TC_Machine: 
 
343
                                        config = m_pMachineConfig;
 
344
                                        break;
 
345
                                case TC_General:
 
346
                                default:
 
347
                                        config = m_pGeneralConfig;
 
348
                        }
 
349
                        if (config == NULL) {
 
350
                                return false;
301
351
                        }
302
352
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
303
353
                        
310
360
                {
311
361
                        wxCriticalSectionLocker locker(m_criticalSection);
312
362
                        wxConfigBase * config;
313
 
                        if (type==TC_General) {
314
 
                                config = m_pGeneralConfig;
315
 
                        } else {
316
 
                                config = m_pUserConfig;
 
363
                        switch (type) {
 
364
                                case TC_User:
 
365
                                        config = m_pUserConfig;
 
366
                                        break;
 
367
                                case TC_Machine: 
 
368
                                        config = m_pMachineConfig;
 
369
                                        break;
 
370
                                case TC_General:
 
371
                                default:
 
372
                                        config = m_pGeneralConfig;
 
373
                        }
 
374
                        if (config == NULL) {
 
375
                                return false;
317
376
                        }
318
377
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
319
378
 
326
385
                {
327
386
                        wxCriticalSectionLocker locker(m_criticalSection);
328
387
                        wxConfigBase * config;
329
 
                        if (type==TC_General) {
330
 
                                config = m_pGeneralConfig;
331
 
                        } else {
332
 
                                config = m_pUserConfig;
 
388
                        switch (type) {
 
389
                                case TC_User:
 
390
                                        config = m_pUserConfig;
 
391
                                        break;
 
392
                                case TC_Machine: 
 
393
                                        config = m_pMachineConfig;
 
394
                                        break;
 
395
                                case TC_General:
 
396
                                default:
 
397
                                        config = m_pGeneralConfig;
 
398
                        }
 
399
                        if (config == NULL) {
 
400
                                return false;
333
401
                        }
334
402
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
335
403
                        
342
410
                {
343
411
                        wxCriticalSectionLocker locker(m_criticalSection);
344
412
                        wxConfigBase * config;
345
 
                        if (type==TC_General) {
346
 
                                config = m_pGeneralConfig;
347
 
                        } else {
348
 
                                config = m_pUserConfig;
 
413
                        switch (type) {
 
414
                                case TC_User:
 
415
                                        config = m_pUserConfig;
 
416
                                        break;
 
417
                                case TC_Machine: 
 
418
                                        config = m_pMachineConfig;
 
419
                                        break;
 
420
                                case TC_General:
 
421
                                default:
 
422
                                        config = m_pGeneralConfig;
 
423
                        }
 
424
                        if (config == NULL) {
 
425
                                return false;
349
426
                        }
350
427
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
351
428
 
358
435
                {
359
436
                        wxCriticalSectionLocker locker(m_criticalSection);
360
437
                        wxConfigBase * config;
361
 
                        if (type==TC_General) {
362
 
                                config = m_pGeneralConfig;
363
 
                        } else {
364
 
                                config = m_pUserConfig;
 
438
                        switch (type) {
 
439
                                case TC_User:
 
440
                                        config = m_pUserConfig;
 
441
                                        break;
 
442
                                case TC_Machine: 
 
443
                                        config = m_pMachineConfig;
 
444
                                        break;
 
445
                                case TC_General:
 
446
                                default:
 
447
                                        config = m_pGeneralConfig;
 
448
                        }
 
449
                        if (config == NULL) {
 
450
                                return false;
365
451
                        }
366
452
                        config->DeleteGroup(wxString::FromUTF8(scope.c_str()));
367
453
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
382
468
                {
383
469
                        wxCriticalSectionLocker locker(m_criticalSection);
384
470
                        wxConfigBase * config;
385
 
                        if (type==TC_General) {
386
 
                                config = m_pGeneralConfig;
387
 
                        } else {
388
 
                                config = m_pUserConfig;
 
471
                        switch (type) {
 
472
                                case TC_User:
 
473
                                        config = m_pUserConfig;
 
474
                                        break;
 
475
                                case TC_Machine: 
 
476
                                        config = m_pMachineConfig;
 
477
                                        break;
 
478
                                case TC_General:
 
479
                                default:
 
480
                                        config = m_pGeneralConfig;
 
481
                        }
 
482
                        if (config == NULL) {
 
483
                                return false;
389
484
                        }
390
485
                        config->SetPath(wxString::FromUTF8(scope.c_str()));
391
486
 
407
502
                                config->SetPath(wxT(".."));
408
503
                                bCont = config->GetNextGroup(str, dummy);
409
504
                        }
410
 
                        return true;
 
505
                        return !listOfGroups.empty();
411
506
                }
412
507
 
413
508
                ConfigurationController::ConfigurationController() 
438
533
                                        }
439
534
                                }
440
535
                        }
 
536
 
 
537
                        wxString pathMachineConfig = fileName.GetPath(true) +  wxT("GinkgoMachine.ini");
 
538
                        if(wxFileExists(pathMachineConfig)) {
 
539
                                m_pMachineConfig = new wxFileConfig(wxEmptyString,wxEmptyString,pathMachineConfig,wxEmptyString,wxCONFIG_USE_LOCAL_FILE);
 
540
                        } else {
 
541
                                m_pMachineConfig = NULL;
 
542
                        }
441
543
                }
442
544
 
443
545
                ConfigurationController::~ConfigurationController() {
444
546
                        Flush();
445
547
                        delete m_pUserConfig;
446
548
                        delete m_pGeneralConfig;
 
549
                        if (m_pMachineConfig != NULL) {
 
550
                                delete m_pMachineConfig;
 
551
                        }
447
552
                }  
448
553
 
449
554
        }