~ubuntu-branches/debian/sid/stellarium/sid

« back to all changes in this revision

Viewing changes to plugins/Supernovae/src/Supernovae.cpp

  • Committer: Package Import Robot
  • Author(s): Tomasz Buchert
  • Date: 2013-08-04 15:06:55 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20130804150655-iji0vb5navh3lk13
Tags: 0.12.2-1
* Imported Upstream version 0.12.2
* Added dependency to phonon (to enable video/sound)
* Fixed VCS links
* Removed unused lintian tag (embedded-library glee)
* Dropped obsolete patch
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
#include <QStringList>
51
51
#include <QVariant>
52
52
#include <QVariantMap>
 
53
#include <QDir>
53
54
 
54
55
#define CATALOG_FORMAT_VERSION 1 /* Version of format of catalog */
55
56
 
167
168
        }
168
169
        else
169
170
        {
170
 
                qDebug() << "Supernovae::init supernovae.json does not exist - copying default file to " << sneJsonPath;
 
171
                qDebug() << "Supernovae::init supernovae.json does not exist - copying default file to " << QDir::toNativeSeparators(sneJsonPath);
171
172
                restoreDefaultJsonFile();
172
173
        }
173
174
 
174
 
        qDebug() << "Supernovae::init using supernovae.json file: " << sneJsonPath;
 
175
        qDebug() << "Supernovae::init using file: " << QDir::toNativeSeparators(sneJsonPath);
175
176
 
176
177
        readJsonFile();
177
178
 
265
266
 
266
267
StelObjectP Supernovae::searchByName(const QString& englishName) const
267
268
{
268
 
        QString objw = englishName.toUpper();
269
269
        foreach(const SupernovaP& sn, snstar)
270
270
        {
271
 
                if (sn->getEnglishName().toUpper() == englishName)
 
271
                if (sn->getEnglishName().toUpper() == englishName.toUpper())
272
272
                        return qSharedPointerCast<StelObject>(sn);
273
273
        }
274
274
 
277
277
 
278
278
StelObjectP Supernovae::searchByNameI18n(const QString& nameI18n) const
279
279
{
280
 
        QString objw = nameI18n.toUpper();
281
 
 
282
280
        foreach(const SupernovaP& sn, snstar)
283
281
        {
284
 
                if (sn->getNameI18n().toUpper() == nameI18n)
 
282
                if (sn->getNameI18n().toUpper() == nameI18n.toUpper())
285
283
                        return qSharedPointerCast<StelObject>(sn);
286
284
        }
287
285
 
291
289
QStringList Supernovae::listMatchingObjectsI18n(const QString& objPrefix, int maxNbItem) const
292
290
{
293
291
        QStringList result;
294
 
        if (maxNbItem==0) return result;
295
 
 
296
 
        QString objw = objPrefix.toUpper();
297
 
 
 
292
        if (maxNbItem==0)
 
293
                return result;
 
294
 
 
295
        QString snn;
298
296
        foreach(const SupernovaP& sn, snstar)
299
297
        {
300
 
                if (sn->getNameI18n().toUpper().left(objw.length()) == objw)
 
298
                snn = sn->getNameI18n();
 
299
                if (snn.contains(objPrefix, Qt::CaseInsensitive))
301
300
                {
302
 
                                result << sn->getNameI18n().toUpper();
 
301
                                result << snn;
303
302
                }
304
303
        }
305
304
 
306
305
        result.sort();
307
 
        if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, result.end());
 
306
        if (result.size()>maxNbItem)
 
307
                result.erase(result.begin()+maxNbItem, result.end());
308
308
 
309
309
        return result;
310
310
}
312
312
QStringList Supernovae::listMatchingObjects(const QString& objPrefix, int maxNbItem) const
313
313
{
314
314
        QStringList result;
315
 
        if (maxNbItem==0) return result;
316
 
 
317
 
        QString objw = objPrefix.toUpper();
318
 
 
 
315
        if (maxNbItem==0)
 
316
                return result;
 
317
 
 
318
        QString snn;
319
319
        foreach(const SupernovaP& sn, snstar)
320
320
        {
321
 
                if (sn->getEnglishName().toUpper().left(objw.length()) == objw)
 
321
                snn = sn->getEnglishName();
 
322
                if (snn.contains(objPrefix, Qt::CaseInsensitive))
322
323
                {
323
 
                                result << sn->getEnglishName().toUpper();
 
324
                                result << snn;
324
325
                }
325
326
        }
326
327
 
327
328
        result.sort();
328
 
        if (result.size()>maxNbItem) result.erase(result.begin()+maxNbItem, result.end());
 
329
        if (result.size()>maxNbItem)
 
330
                result.erase(result.begin()+maxNbItem, result.end());
329
331
 
330
332
        return result;
331
333
}
361
363
        QFile src(":/Supernovae/supernovae.json");
362
364
        if (!src.copy(sneJsonPath))
363
365
        {
364
 
                qWarning() << "Supernovae::restoreDefaultJsonFile cannot copy json resource to " + sneJsonPath;
 
366
                qWarning() << "Supernovae::restoreDefaultJsonFile cannot copy json resource to " + QDir::toNativeSeparators(sneJsonPath);
365
367
        }
366
368
        else
367
369
        {
368
 
                qDebug() << "Supernovae::init copied default supernovae.json to " << sneJsonPath;
 
370
                qDebug() << "Supernovae::init copied default supernovae.json to " << QDir::toNativeSeparators(sneJsonPath);
369
371
                // The resource is read only, and the new file inherits this...  make sure the new file
370
372
                // is writable by the Stellarium process so that updates can be done.
371
373
                QFile dest(sneJsonPath);
434
436
        QVariantMap map;
435
437
        QFile jsonFile(path);
436
438
        if (!jsonFile.open(QIODevice::ReadOnly))
437
 
            qWarning() << "Supernovae::loadSNeMap cannot open " << path;
 
439
            qWarning() << "Supernovae::loadSNeMap cannot open " << QDir::toNativeSeparators(path);
438
440
        else
439
441
            map = StelJsonParser::parse(jsonFile.readAll()).toMap();
440
442
 
470
472
        QFile sneJsonFile(sneJsonPath);
471
473
        if (!sneJsonFile.open(QIODevice::ReadOnly))
472
474
        {
473
 
                qWarning() << "Supernovae::init cannot open " << sneJsonPath;
 
475
                qWarning() << "Supernovae::init cannot open " << QDir::toNativeSeparators(sneJsonPath);
474
476
                return jsonVersion;
475
477
        }
476
478
 
578
580
        lastUpdate = QDateTime::currentDateTime();
579
581
        conf->setValue("Supernovae/last_update", lastUpdate.toString(Qt::ISODate));
580
582
 
581
 
        emit(jsonUpdateComplete());
582
 
 
583
583
        updateState = Supernovae::Updating;
584
 
 
585
584
        emit(updateStateChanged(updateState));
586
 
        updateFile.clear();
587
585
 
588
586
        if (progressBar==NULL)
589
587
                progressBar = StelApp::getInstance().getGui()->addProgressBar();
590
588
 
591
589
        progressBar->setValue(0);
592
 
        progressBar->setMaximum(updateUrl.size());
 
590
        progressBar->setMaximum(100);
 
591
        progressBar->setFormat("Update historical supernovae");
593
592
        progressBar->setVisible(true);
594
 
        progressBar->setFormat("Update historical supernovae");
595
593
 
596
594
        QNetworkRequest request;
597
595
        request.setUrl(QUrl(updateUrl));
598
596
        request.setRawHeader("User-Agent", QString("Mozilla/5.0 (Stellarium Historical Supernovae Plugin %1; http://stellarium.org/)").arg(SUPERNOVAE_PLUGIN_VERSION).toUtf8());
599
597
        downloadMgr->get(request);
600
598
 
601
 
        progressBar->setValue(100);
602
 
        delete progressBar;
603
 
        progressBar = NULL;
604
 
 
605
 
        updateState = CompleteUpdates;
606
 
 
 
599
        updateState = Supernovae::CompleteUpdates;
607
600
        emit(updateStateChanged(updateState));
608
601
        emit(jsonUpdateComplete());
609
602
}
637
630
        }
638
631
 
639
632
        if (progressBar)
 
633
        {
640
634
                progressBar->setValue(100);
 
635
                delete progressBar;
 
636
                progressBar = NULL;
 
637
        }
641
638
}
642
639
 
643
640
void Supernovae::displayMessage(const QString& message, const QString hexColor)