Commit 3272a35e authored by Rishab Arora's avatar Rishab Arora

Flags imported from flags.dat to database

parent eb31b13b
......@@ -20,6 +20,13 @@
#include "kstarsdata.h"
#include <kdebug.h>
/*
* TODO (spacetime):
* The database supports storing logs. But it needs to be implemented.
*
* One of the unresolved problems was the creation of a unique identifier
* for each object (DSO,planet,star etc) for use in the database.
*/
bool KSUserDB::Initialize() {
// Every logged in user has their own db.
......@@ -56,6 +63,16 @@ QSqlError KSUserDB::LastError() {
}
bool KSUserDB::FirstRun() {
if (!RebuildDB())
return false;
ImportFlags();
return true;
}
bool KSUserDB::RebuildDB() {
kWarning() << i18n("Rebuilding User Database");
QVector<QString> tables;
tables.append("CREATE TABLE user ( "
......@@ -597,3 +614,34 @@ void KSUserDB::GetAllFilters(QList<OAL::Filter *> &filter_list) {
userdb_.close();
return;
}
bool KSUserDB::ImportFlags() {
QString flagfilename = KStandardDirs::locateLocal("appdata", "flags.dat");
QFile flagsfile(flagfilename);
if (!flagsfile.exists()) {
return false; // No upgrade needed. Flags file doesn't exist.
}
QList< QPair<QString, KSParser::DataTypes> > flag_file_sequence;
flag_file_sequence.append(qMakePair(QString("RA"), KSParser::D_QSTRING));
flag_file_sequence.append(qMakePair(QString("Dec"), KSParser::D_QSTRING));
flag_file_sequence.append(qMakePair(QString("epoch"), KSParser::D_QSTRING));
flag_file_sequence.append(qMakePair(QString("icon"), KSParser::D_QSTRING));
flag_file_sequence.append(qMakePair(QString("label"), KSParser::D_QSTRING));
flag_file_sequence.append(qMakePair(QString("color"), KSParser::D_QSTRING));
KSParser flagparser(flagfilename,'#',flag_file_sequence,' ');
QHash<QString, QVariant> row_content;
while (flagparser.HasNextRow()){
row_content = flagparser.ReadNextRow();
QString ra = row_content["RA"].toString();
QString dec = row_content["Dec"].toString();
QString epoch = row_content["epoch"].toString();
QString icon = row_content["icon"].toString();
QString label = row_content["label"].toString();
QString color = row_content["color"].toString();
AddFlag(ra,dec,epoch,icon,label,color);
}
return true;
}
......@@ -214,7 +214,20 @@ class KSUserDB {
*
* @return bool
**/
bool RebuildDB();
/**
* @brief Rebuilds the User DB from scratch using RebuildDB.
* Also, loads any previous user data into the DB.
*
* @return bool
**/
bool FirstRun();
/**
* @brief Imports flags data from previous format
*
* @return bool
**/
bool ImportFlags();
/**
* @brief Linked to the user database _once_.
**/
......
......@@ -92,9 +92,6 @@ void AsteroidsComponent::loadData() {
m_ObjectList.clear();
objectNames( SkyObject::ASTEROID ).clear();
// TODO(spacetime): Am I complicating things? ~~spacetime
// Providing a list of the columns in advance will help check
// for valid rows.
QList< QPair<QString, KSParser::DataTypes> > sequence;
sequence.append(qMakePair(QString("full name"), KSParser::D_QSTRING));
sequence.append(qMakePair(QString("epoch_mjd"), KSParser::D_INT));
......
......@@ -90,7 +90,6 @@ void CometsComponent::loadData() {
emitProgressText(i18n("Loading comets"));
objectNames(SkyObject::COMET).clear();
QList<QString> newList;
QList< QPair<QString, KSParser::DataTypes> > sequence;
sequence.append(qMakePair(QString("full name"), KSParser::D_QSTRING));
sequence.append(qMakePair(QString("epoch_mjd"), KSParser::D_INT));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment