• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
ksuserdb.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ksuserdb.cpp - K Desktop Planetarium
3  -------------------
4  begin : Wed May 2 2012
5  copyright : (C) 2012 by Rishab Arora
6  email : ra.rishab@gmail.com
7  ***************************************************************************/
8 
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "ksuserdb.h"
20 #include "kstarsdata.h"
21 #include "version.h"
22 #include <kdebug.h>
23 
24 /*
25  * TODO (spacetime):
26  * The database supports storing logs. But it needs to be implemented.
27  *
28  * One of the unresolved problems was the creation of a unique identifier
29  * for each object (DSO,planet,star etc) for use in the database.
30 */
31 
32 bool KSUserDB::Initialize() {
33  // Every logged in user has their own db.
34  userdb_ = QSqlDatabase::addDatabase("QSQLITE", "userdb");
35  QString dbfile = KStandardDirs::locateLocal("appdata", "userdb.sqlite");
36  QFile testdb(dbfile);
37  bool first_run = false;
38  if (!testdb.exists()) {
39  kDebug()<< i18n("User DB does not exist! New User DB will be "
40  "created.");
41  first_run = true;
42  }
43  userdb_.setDatabaseName(dbfile);
44  if (!userdb_.open()) {
45  kWarning() << i18n("Unable to open user database file!");
46  kWarning() << LastError();
47  } else {
48  kDebug() << i18n("Opened the User DB. Ready!");
49  if (first_run == true) {
50  FirstRun();
51  }
52  }
53  userdb_.close();
54  return true;
55 }
56 
57 KSUserDB::~KSUserDB() {
58  userdb_.close();
59 }
60 
61 QSqlError KSUserDB::LastError() {
62  // error description is in QSqlError::text()
63  return userdb_.lastError();
64 }
65 
66 bool KSUserDB::FirstRun() {
67  if (!RebuildDB())
68  return false;
69 
70  ImportFlags();
71  ImportUsers();
72  ImportEquipment();
73 
74  return true;
75 }
76 
77 
78 bool KSUserDB::RebuildDB() {
79  kWarning() << i18n("Rebuilding User Database");
80  QVector<QString> tables;
81  tables.append("CREATE TABLE Version ("
82  "Version CHAR DEFAULT NULL)");
83  tables.append("INSERT INTO Version VALUES (\"" KSTARS_VERSION "\")");
84  tables.append("CREATE TABLE user ( "
85  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
86  "Name TEXT NOT NULL DEFAULT 'NULL', "
87  "Surname TEXT NOT NULL DEFAULT 'NULL', "
88  "Contact TEXT DEFAULT NULL)");
89 
90  tables.append("CREATE TABLE telescope ( "
91  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
92  "Vendor TEXT DEFAULT NULL, "
93  "Aperture REAL NOT NULL DEFAULT NULL, "
94  "Model TEXT DEFAULT NULL, "
95  "Driver TEXT DEFAULT NULL, "
96  "Type TEXT DEFAULT NULL, "
97  "FocalLength REAL DEFAULT NULL)");
98 
99  tables.append("CREATE TABLE flags ( "
100  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
101  "RA TEXT NOT NULL DEFAULT NULL, "
102  "Dec TEXT NOT NULL DEFAULT NULL, "
103  "Icon TEXT NOT NULL DEFAULT 'NULL', "
104  "Label TEXT NOT NULL DEFAULT 'NULL', "
105  "Color TEXT DEFAULT NULL, "
106  "Epoch TEXT DEFAULT NULL)");
107 
108  tables.append("CREATE TABLE lens ( "
109  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
110  "Vendor TEXT NOT NULL DEFAULT 'NULL', "
111  "Model TEXT DEFAULT NULL, "
112  "Factor REAL NOT NULL DEFAULT NULL)");
113 
114  tables.append("CREATE TABLE eyepiece ( "
115  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
116  "Vendor TEXT DEFAULT NULL, "
117  "Model TEXT DEFAULT NULL, "
118  "FocalLength REAL NOT NULL DEFAULT NULL, "
119  "ApparentFOV REAL NOT NULL DEFAULT NULL, "
120  "FOVUnit TEXT NOT NULL DEFAULT NULL)");
121 
122  tables.append("CREATE TABLE filter ( "
123  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
124  "Vendor TEXT DEFAULT NULL, "
125  "Model TEXT DEFAULT NULL, "
126  "Type TEXT DEFAULT NULL, "
127  "Color TEXT DEFAULT NULL)");
128 
129  tables.append("CREATE TABLE wishlist ( "
130  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
131  "Date NUMERIC NOT NULL DEFAULT NULL, "
132  "Type TEXT DEFAULT NULL, "
133  "UIUD TEXT DEFAULT NULL)");
134 
135  tables.append("CREATE TABLE fov ( "
136  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
137  "name TEXT NOT NULL DEFAULT 'NULL', "
138  "color TEXT DEFAULT NULL, "
139  "sizeX NUMERIC DEFAULT NULL, "
140  "sizeY NUMERIC DEFAULT NULL, "
141  "shape TEXT DEFAULT NULL)");
142 
143  tables.append("CREATE TABLE logentry ( "
144  "id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
145  "content TEXT NOT NULL DEFAULT 'NULL', "
146  "UIUD TEXT DEFAULT NULL, "
147  "DateTime NUMERIC NOT NULL DEFAULT NULL, "
148  "User INTEGER DEFAULT NULL REFERENCES user (id), "
149  "Location TEXT DEFAULT NULL, "
150  "Telescope INTEGER DEFAULT NULL REFERENCES telescope (id),"
151  "Filter INTEGER DEFAULT NULL REFERENCES filter (id), "
152  "lens INTEGER DEFAULT NULL REFERENCES lens (id), "
153  "Eyepiece INTEGER DEFAULT NULL REFERENCES eyepiece (id), "
154  "FOV INTEGER DEFAULT NULL REFERENCES fov (id))");
155 
156  for (int i = 0; i < tables.count(); ++i) {
157  QSqlQuery query(userdb_);
158  if (!query.exec(tables[i])) {
159  kDebug() << query.lastError();
160  }
161  }
162  return true;
163 }
164 
165 /*
166  * Observer Section
167 */
168 void KSUserDB::AddObserver(const QString& name, const QString& surname,
169  const QString& contact) {
170  userdb_.open();
171  QSqlTableModel users(0, userdb_);
172  users.setTable("user");
173  users.setFilter("Name LIKE \'" + name + "\' AND Surname LIKE \'" +
174  surname + "\'");
175  users.select();
176 
177  if (users.rowCount() > 0) {
178  QSqlRecord record = users.record(0);
179  record.setValue("Name", name);
180  record.setValue("Surname", surname);
181  record.setValue("Contact", contact);
182  users.setRecord(0, record);
183  users.submitAll();
184  } else {
185  int row = 0;
186  users.insertRows(row, 1);
187  users.setData(users.index(row, 1), name); // row0 is autoincerement ID
188  users.setData(users.index(row, 2), surname);
189  users.setData(users.index(row, 3), contact);
190  users.submitAll();
191  }
192 
193  userdb_.close();
194 }
195 
196 int KSUserDB::FindObserver(const QString &name, const QString &surname) {
197  userdb_.open();
198  QSqlTableModel users(0, userdb_);
199  users.setTable("user");
200  users.setFilter("Name LIKE \'" + name + "\' AND Surname LIKE \'" +
201  surname + "\'");
202  users.select();
203 
204  int observer_count = users.rowCount();
205 
206  users.clear();
207  userdb_.close();
208  return (observer_count > 0);
209 }
210 
211 // TODO(spacetime): This method is currently unused.
212 bool KSUserDB::DeleteObserver(const QString &id) {
213  userdb_.open();
214  QSqlTableModel users(0, userdb_);
215  users.setTable("user");
216  users.setFilter("id = \'"+id+"\'");
217  users.select();
218 
219  users.removeRows(0, 1);
220  users.submitAll();
221 
222  int observer_count = users.rowCount();
223 
224  users.clear();
225  userdb_.close();
226  return (observer_count > 0);
227 }
228 
229 void KSUserDB::GetAllObservers(QList<Observer *> &observer_list) {
230  userdb_.open();
231  observer_list.clear();
232  QSqlTableModel users(0, userdb_);
233  users.setTable("user");
234  users.select();
235 
236  for (int i =0; i < users.rowCount(); ++i) {
237  QSqlRecord record = users.record(i);
238  QString id = record.value("id").toString();
239  QString name = record.value("Name").toString();
240  QString surname = record.value("Surname").toString();
241  QString contact = record.value("Contact").toString();
242  OAL::Observer *o= new OAL::Observer(id, name, surname, contact);
243  observer_list.append(o);
244  }
245 
246  users.clear();
247  userdb_.close();
248 }
249 
250 /*
251  * Flag Section
252 */
253 
254 void KSUserDB::EraseAllFlags() {
255  userdb_.open();
256  QSqlTableModel flags(0, userdb_);
257  flags.setTable("flags");
258  flags.select();
259 
260  flags.removeRows(0, flags.rowCount());
261  flags.submitAll();
262 
263  flags.clear();
264  userdb_.close();
265 }
266 
267 void KSUserDB::AddFlag(const QString &ra, const QString &dec,
268  const QString &epoch, const QString &image_name,
269  const QString &label, const QString &labelColor) {
270  userdb_.open();
271  QSqlTableModel flags(0, userdb_);
272  flags.setTable("flags");
273 
274  int row = 0;
275  flags.insertRows(row, 1);
276  flags.setData(flags.index(row, 1), ra); // row,0 is autoincerement ID
277  flags.setData(flags.index(row, 2), dec);
278  flags.setData(flags.index(row, 3), image_name);
279  flags.setData(flags.index(row, 4), label);
280  flags.setData(flags.index(row, 5), labelColor);
281  flags.setData(flags.index(row, 6), epoch);
282  flags.submitAll();
283 
284  flags.clear();
285  userdb_.close();
286 }
287 
288 QList<QStringList> KSUserDB::ReturnAllFlags() {
289  QList<QStringList> flagList;
290 
291  userdb_.open();
292  QSqlTableModel flags(0, userdb_);
293  flags.setTable("flags");
294  flags.select();
295 
296  for (int i =0; i < flags.rowCount(); ++i) {
297  QStringList flagEntry;
298  QSqlRecord record = flags.record(i);
299  /* flagEntry order description
300  * The variation in the order is due to variation
301  * in flag entry description order and flag database
302  * description order.
303  * flag (database): ra, dec, icon, label, color, epoch
304  * flag (object): ra, dec, epoch, icon, label, color
305  */
306  flagEntry.append(record.value(1).toString());
307  flagEntry.append(record.value(2).toString());
308  flagEntry.append(record.value(6).toString());
309  flagEntry.append(record.value(3).toString());
310  flagEntry.append(record.value(4).toString());
311  flagEntry.append(record.value(5).toString());
312  flagList.append(flagEntry);
313  }
314 
315  flags.clear();
316  userdb_.close();
317  return flagList;
318 }
319 
320 /*
321  * Generic Section
322  */
323 void KSUserDB::EraseEquipment(const QString &type, const int &id) {
324  userdb_.open();
325  QSqlTableModel equip(0, userdb_);
326  equip.setTable(type);
327  equip.setFilter("id = " + QString::number(id));
328  equip.select();
329 
330  equip.removeRows(0, equip.rowCount());
331  equip.submitAll();
332 
333  equip.clear();
334  userdb_.close();
335 }
336 
337 void KSUserDB::EraseAllEquipment(const QString &type) {
338  userdb_.open();
339  QSqlTableModel equip(0, userdb_);
340  equip.setTable(type);
341  equip.setFilter("id >= 1");
342  equip.select();
343  equip.removeRows(0, equip.rowCount());
344  equip.submitAll();
345 
346  equip.clear();
347  userdb_.close();
348 }
349 
350 /*
351  * Telescope section
352  */
353 void KSUserDB::AddScope(const QString &model, const QString &vendor,
354  const QString &driver, const QString &type,
355  const double & focalLength, const double &aperture) {
356  userdb_.open();
357  QSqlTableModel equip(0, userdb_);
358  equip.setTable("telescope");
359 
360  int row = 0;
361  equip.insertRows(row, 1);
362  equip.setData(equip.index(row, 1), vendor); // row,0 is autoincerement ID
363  equip.setData(equip.index(row, 2), aperture);
364  equip.setData(equip.index(row, 3), model);
365  equip.setData(equip.index(row, 4), driver);
366  equip.setData(equip.index(row, 5), type);
367  equip.setData(equip.index(row, 6), focalLength);
368  equip.submitAll();
369 
370  equip.clear(); //DB will not close if linked object not cleared
371  userdb_.close();
372 }
373 
374 void KSUserDB::AddScope(const QString &model, const QString &vendor,
375  const QString &driver, const QString &type,
376  const double &focalLength, const double &aperture,
377  const QString &id) {
378  userdb_.open();
379  QSqlTableModel equip(0, userdb_);
380  equip.setTable("telescope");
381  equip.setFilter("id = " + id);
382  equip.select();
383 
384  if (equip.rowCount() > 0) {
385  QSqlRecord record = equip.record(0);
386  record.setValue(1, vendor);
387  record.setValue(2, aperture);
388  record.setValue(3, model);
389  record.setValue(4, driver);
390  record.setValue(5, type);
391  record.setValue(6, focalLength);
392  equip.setRecord(0, record);
393  equip.submitAll();
394  }
395 
396  userdb_.close();
397 }
398 
399 void KSUserDB::GetAllScopes(QList<Scope *> &scope_list) {
400  scope_list.clear();
401 
402  userdb_.open();
403  QSqlTableModel equip(0, userdb_);
404  equip.setTable("telescope");
405  equip.select();
406 
407  for (int i =0; i < equip.rowCount(); ++i) {
408  QSqlRecord record = equip.record(i);
409  QString id = record.value("id").toString();
410  QString vendor = record.value("Vendor").toString();
411  double aperture = record.value("Aperture").toDouble();
412  QString model = record.value("Model").toString();
413  QString driver = record.value("Driver").toString();
414  QString type = record.value("Type").toString();
415  double focalLength = record.value("FocalLength").toDouble();
416  OAL::Scope *o= new OAL::Scope(id, model, vendor, type,
417  focalLength, aperture);
418  o->setINDIDriver(driver);
419  scope_list.append(o);
420  }
421 
422  equip.clear();
423  userdb_.close();
424 }
425 
426 /*
427  * Eyepiece section
428  */
429 void KSUserDB::AddEyepiece(const QString &vendor, const QString &model,
430  const double &focalLength, const double &fov,
431  const QString &fovunit) {
432  userdb_.open();
433  QSqlTableModel equip(0, userdb_);
434  equip.setTable("eyepiece");
435 
436  int row = 0;
437  equip.insertRows(row, 1);
438  equip.setData(equip.index(row, 1), vendor); // row,0 is autoincerement ID
439  equip.setData(equip.index(row, 2), model);
440  equip.setData(equip.index(row, 3), focalLength);
441  equip.setData(equip.index(row, 4), fov);
442  equip.setData(equip.index(row, 5), fovunit);
443  equip.submitAll();
444 
445  equip.clear();
446  userdb_.close();
447 }
448 
449 void KSUserDB::AddEyepiece(const QString &vendor, const QString &model,
450  const double &focalLength, const double &fov,
451  const QString &fovunit, const QString &id) {
452  userdb_.open();
453  QSqlTableModel equip(0, userdb_);
454  equip.setTable("eyepiece");
455  equip.setFilter("id = " + id);
456  equip.select();
457 
458  if (equip.rowCount()>0) {
459  QSqlRecord record = equip.record(0);
460  record.setValue(1, vendor);
461  record.setValue(2, model);
462  record.setValue(3, focalLength);
463  record.setValue(4, fov);
464  record.setValue(5, fovunit);
465  equip.setRecord(0, record);
466  equip.submitAll();
467  }
468 
469  userdb_.close();
470 }
471 
472 void KSUserDB::GetAllEyepieces(QList<OAL::Eyepiece *> &eyepiece_list) {
473  eyepiece_list.clear();
474 
475  userdb_.open();
476  QSqlTableModel equip(0, userdb_);
477  equip.setTable("eyepiece");
478  equip.select();
479 
480  for (int i =0; i < equip.rowCount(); ++i) {
481  QSqlRecord record = equip.record(i);
482  QString id = record.value("id").toString();
483  QString vendor = record.value("Vendor").toString();
484  QString model = record.value("Model").toString();
485  double focalLength = record.value("FocalLength").toDouble();
486  double fov = record.value("ApparentFOV").toDouble();
487  QString fovUnit = record.value("FOVUnit").toString();
488 
489  OAL::Eyepiece *o = new OAL::Eyepiece(id, model, vendor, fov,
490  fovUnit, focalLength);
491  eyepiece_list.append(o);
492  }
493 
494  equip.clear();
495  userdb_.close();
496 }
497 
498 /*
499  * lens section
500  */
501 void KSUserDB::AddLens(const QString &vendor, const QString &model,
502  const double &factor) {
503  userdb_.open();
504  QSqlTableModel equip(0, userdb_);
505  equip.setTable("lens");
506 
507  int row = 0;
508  equip.insertRows(row, 1);
509  equip.setData(equip.index(row, 1), vendor); // row,0 is autoincerement ID
510  equip.setData(equip.index(row, 2), model);
511  equip.setData(equip.index(row, 3), factor);
512  equip.submitAll();
513 
514  equip.clear();
515  userdb_.close();
516 }
517 
518 void KSUserDB::AddLens(const QString &vendor, const QString &model,
519  const double &factor, const QString &id) {
520  userdb_.open();
521  QSqlTableModel equip(0, userdb_);
522  equip.setTable("lens");
523  equip.setFilter("id = "+id);
524  equip.select();
525 
526  if (equip.rowCount()>0) {
527  QSqlRecord record = equip.record(0);
528  record.setValue(1, vendor);
529  record.setValue(2, model);
530  record.setValue(3, factor);
531  equip.submitAll();
532  }
533 
534  userdb_.close();
535 }
536 
537 void KSUserDB::GetAllLenses(QList<OAL::Lens *> &lens_list) {
538  lens_list.clear();
539 
540  userdb_.open();
541  QSqlTableModel equip(0, userdb_);
542  equip.setTable("lens");
543  equip.select();
544 
545  for (int i =0; i < equip.rowCount(); ++i) {
546  QSqlRecord record = equip.record(i);
547  QString id = record.value("id").toString();
548  QString vendor = record.value("Vendor").toString();
549  QString model = record.value("Model").toString();
550  double factor = record.value("Factor").toDouble();
551  OAL::Lens *o = new OAL::Lens(id, model, vendor, factor);
552  lens_list.append(o);
553  }
554 
555  equip.clear();
556  userdb_.close();
557 }
558 
559 /*
560  * filter section
561  */
562 void KSUserDB::AddFilter(const QString &vendor, const QString &model,
563  const QString &type, const QString &color) {
564  userdb_.open();
565  QSqlTableModel equip(0, userdb_);
566  equip.setTable("filter");
567 
568  int row = 0;
569  equip.insertRows(row, 1);
570  equip.setData(equip.index(row, 1), vendor); // row,0 is autoincerement ID
571  equip.setData(equip.index(row, 2), model);
572  equip.setData(equip.index(row, 3), type);
573  equip.setData(equip.index(row, 4), color);
574  equip.submitAll();
575 
576  equip.clear();
577  userdb_.close();
578 }
579 
580 void KSUserDB::AddFilter(const QString &vendor, const QString &model,
581  const QString &type, const QString &color,
582  const QString &id) {
583  userdb_.open();
584  QSqlTableModel equip(0, userdb_);
585  equip.setTable("filter");
586  equip.setFilter("id = " + id);
587  equip.select();
588 
589  if (equip.rowCount() > 0) {
590  QSqlRecord record = equip.record(0);
591  record.setValue(1, vendor);
592  record.setValue(2, model);
593  record.setValue(3, type);
594  record.setValue(4, color);
595  equip.submitAll();
596  }
597 
598  userdb_.close();
599 }
600 
601 void KSUserDB::GetAllFilters(QList<OAL::Filter *> &filter_list) {
602  userdb_.open();
603  filter_list.clear();
604  QSqlTableModel equip(0, userdb_);
605  equip.setTable("filter");
606  equip.select();
607 
608  for (int i =0; i < equip.rowCount(); ++i) {
609  QSqlRecord record = equip.record(i);
610  QString id = record.value("id").toString();
611  QString vendor = record.value("Vendor").toString();
612  QString model = record.value("Model").toString();
613  QString type = record.value("Type").toString();
614  QString color = record.value("Color").toString();
615  OAL::Filter *o= new OAL::Filter(id, model, vendor, type, color);
616  filter_list.append(o);
617  }
618 
619  equip.clear();
620  userdb_.close();
621  return;
622 }
623 
624 bool KSUserDB::ImportFlags() {
625  QString flagfilename = KStandardDirs::locateLocal("appdata", "flags.dat");
626  QFile flagsfile(flagfilename);
627  if (!flagsfile.exists()) {
628  return false; // No upgrade needed. Flags file doesn't exist.
629  }
630 
631  QList< QPair<QString, KSParser::DataTypes> > flag_file_sequence;
632  flag_file_sequence.append(qMakePair(QString("RA"), KSParser::D_QSTRING));
633  flag_file_sequence.append(qMakePair(QString("Dec"), KSParser::D_QSTRING));
634  flag_file_sequence.append(qMakePair(QString("epoch"), KSParser::D_QSTRING));
635  flag_file_sequence.append(qMakePair(QString("icon"), KSParser::D_QSTRING));
636  flag_file_sequence.append(qMakePair(QString("label"), KSParser::D_QSTRING));
637  flag_file_sequence.append(qMakePair(QString("color"), KSParser::D_QSTRING));
638  KSParser flagparser(flagfilename,'#',flag_file_sequence,' ');
639 
640  QHash<QString, QVariant> row_content;
641  while (flagparser.HasNextRow()){
642  row_content = flagparser.ReadNextRow();
643  QString ra = row_content["RA"].toString();
644  QString dec = row_content["Dec"].toString();
645  QString epoch = row_content["epoch"].toString();
646  QString icon = row_content["icon"].toString();
647  QString label = row_content["label"].toString();
648  QString color = row_content["color"].toString();
649 
650  AddFlag(ra,dec,epoch,icon,label,color);
651  }
652  return true;
653 }
654 
655 bool KSUserDB::ImportUsers() {
656  QString usersfilename = KStandardDirs::locateLocal("appdata", "observerlist.xml");
657  QFile usersfile(usersfilename);
658 
659  if (!usersfile.exists()) {
660  return false; // No upgrade needed. Users file doesn't exist.
661  }
662 
663  if( ! usersfile.open( QIODevice::ReadOnly ) )
664  return false;
665 
666  QXmlStreamReader *reader = new QXmlStreamReader(&usersfile);
667 
668  while( ! reader->atEnd() ) {
669  reader->readNext();
670 
671  if( reader->isEndElement() )
672  break;
673 
674  if( reader->isStartElement() ) {
675  if (reader->name() != "observers")
676  continue;
677 
678  //Read all observers
679  while( ! reader->atEnd() ) {
680  reader->readNext();
681 
682  if( reader->isEndElement() )
683  break;
684 
685  if( reader->isStartElement() ) {
686  // Read single observer
687  if( reader->name() == "observer" ) {
688  QString name, surname, contact;
689  while( ! reader->atEnd() ) {
690  reader->readNext();
691 
692  if( reader->isEndElement() )
693  break;
694 
695  if( reader->isStartElement() ) {
696  if( reader->name() == "name" ) {
697  name = reader->readElementText();
698  } else if( reader->name() == "surname" ) {
699  surname = reader->readElementText();
700  } else if( reader->name() == "contact" ) {
701  contact = reader->readElementText();
702  }
703  }
704  }
705  AddObserver(name, surname, contact);
706  }
707  }
708  }
709  }
710  }
711  delete reader_;
712  usersfile.close();
713  return true;
714 }
715 
716 bool KSUserDB::ImportEquipment() {
717  QString equipfilename = KStandardDirs::locateLocal("appdata", "equipmentlist.xml");
718  QFile equipfile(equipfilename);
719 
720  if (!equipfile.exists()) {
721  return false; // No upgrade needed. File doesn't exist.
722  }
723 
724  if( ! equipfile.open( QIODevice::ReadOnly ) )
725  return false;
726 
727  reader_ = new QXmlStreamReader(&equipfile);
728  while( ! reader_->atEnd() ) {
729  reader_->readNext();
730  if( reader_->isStartElement() ) {
731  while( ! reader_->atEnd() ) {
732  reader_->readNext();
733 
734  if( reader_->isEndElement() )
735  break;
736 
737  if( reader_->isStartElement() ) {
738  if( reader_->name() == "scopes" )
739  readScopes();
740  else if( reader_->name() == "eyepieces" )
741  readEyepieces();
742  else if( reader_->name() =="lenses" )
743  readLenses();
744  else if( reader_->name() =="filters" )
745  readFilters();
746  }
747  }
748  }
749  }
750  delete reader_;
751  equipfile.close();
752  return true;
753 }
754 
755 void KSUserDB::readScopes() {
756  while( ! reader_->atEnd() ) {
757  reader_->readNext();
758 
759  if( reader_->isEndElement() )
760  break;
761 
762  if( reader_->isStartElement() ) {
763  if( reader_->name() == "scope" )
764  readScope( reader_->attributes().value( "id" ).toString() );
765  }
766  }
767 }
768 
769 void KSUserDB::readEyepieces() {
770  while( ! reader_->atEnd() ) {
771  reader_->readNext();
772 
773  if( reader_->isEndElement() )
774  break;
775 
776  if( reader_->isStartElement() ) {
777  if( reader_->name() == "eyepiece" )
778  readEyepiece( reader_->attributes().value( "id" ).toString() );
779  }
780  }
781 }
782 
783 void KSUserDB::readLenses() {
784  while( ! reader_->atEnd() ) {
785  reader_->readNext();
786 
787  if( reader_->isEndElement() )
788  break;
789 
790  if( reader_->isStartElement() ) {
791  if( reader_->name() == "lens" )
792  readLens( reader_->attributes().value( "id" ).toString() );
793  }
794  }
795 }
796 
797 void KSUserDB::readFilters() {
798  while( ! reader_->atEnd() ) {
799  reader_->readNext();
800 
801  if( reader_->isEndElement() )
802  break;
803 
804  if( reader_->isStartElement() ) {
805  if( reader_->name() == "filter" )
806  readFilter( reader_->attributes().value( "id" ).toString() );
807  }
808  }
809 }
810 
811 void KSUserDB::readScope( QString id ) {
812  QString model, vendor, type, driver = i18n("None");
813  double aperture, focalLength;
814  while( ! reader_->atEnd() ) {
815  reader_->readNext();
816 
817  if( reader_->isEndElement() )
818  break;
819 
820  if( reader_->isStartElement() ) {
821  if( reader_->name() == "model" ) {
822  model = reader_->readElementText();
823  } else if( reader_->name() == "vendor" ) {
824  vendor = reader_->readElementText() ;
825  } else if( reader_->name() == "type" ) {
826  type = reader_->readElementText() ;
827  if( type == "N" ) type = "Newtonian";
828  if( type == "R" ) type = "Refractor";
829  if( type == "M" ) type = "Maksutov";
830  if( type == "S" ) type = "Schmidt-Cassegrain";
831  if( type == "K" ) type = "Kutter (Schiefspiegler)";
832  if( type == "C" ) type = "Cassegrain";
833  } else if( reader_->name() == "focalLength" ) {
834  focalLength = (reader_->readElementText()).toDouble() ;
835  } else if( reader_->name() == "aperture" )
836  aperture = (reader_->readElementText()).toDouble() ;
837  else if ( reader_->name() == "driver")
838  driver = reader_->readElementText();
839  }
840  }
841 
842  AddScope(model, vendor, driver, type, focalLength, aperture);
843 }
844 
845 void KSUserDB::readEyepiece( QString id ) {
846  QString model, focalLength, vendor, fov, fovUnit;
847  while( ! reader_->atEnd() ) {
848  reader_->readNext();
849 
850  if( reader_->isEndElement() )
851  break;
852 
853  if( reader_->isStartElement() ) {
854  if( reader_->name() == "model" ) {
855  model = reader_->readElementText();
856  } else if( reader_->name() == "vendor" ) {
857  vendor = reader_->readElementText() ;
858  } else if( reader_->name() == "apparentFOV" ) {
859  fov = reader_->readElementText();
860  fovUnit = reader_->attributes().value( "unit" ).toString();
861  } else if( reader_->name() == "focalLength" ) {
862  focalLength = reader_->readElementText() ;
863  }
864  }
865  }
866 
867  AddEyepiece(vendor, model, focalLength.toDouble(), fov.toDouble(), fovUnit);
868 }
869 
870 void KSUserDB::readLens( QString id ) {
871  QString model, factor, vendor;
872  while( ! reader_->atEnd() ) {
873  reader_->readNext();
874 
875  if( reader_->isEndElement() )
876  break;
877 
878  if( reader_->isStartElement() ) {
879  if( reader_->name() == "model" ) {
880  model = reader_->readElementText();
881  } else if( reader_->name() == "vendor" ) {
882  vendor = reader_->readElementText() ;
883  } else if( reader_->name() == "factor" ) {
884  factor = reader_->readElementText() ;
885  }
886  }
887  }
888 
889  AddLens(vendor, model, factor.toDouble());
890 }
891 
892 void KSUserDB::readFilter( QString id ) {
893  QString model, vendor, type, color;
894  while( ! reader_->atEnd() ) {
895  reader_->readNext();
896 
897  if( reader_->isEndElement() )
898  break;
899 
900  if( reader_->isStartElement() ) {
901  if( reader_->name() == "model" ) {
902  model = reader_->readElementText();
903  } else if( reader_->name() == "vendor" ) {
904  vendor = reader_->readElementText() ;
905  } else if( reader_->name() == "type" ) {
906  type = reader_->readElementText() ;
907  } else if( reader_->name() == "color" ) {
908  color = reader_->readElementText() ;
909  }
910  }
911  }
912  AddFilter(vendor, model, type, color );
913 }
KSUserDB::FindObserver
int FindObserver(const QString &name, const QString &surname)
Returns the unique id of the user with given name & surname.
Definition: ksuserdb.cpp:196
OAL::Eyepiece
Definition: eyepiece.h:25
KSUserDB::AddScope
void AddScope(const QString &model, const QString &vendor, const QString &driver, const QString &type, const double &focalLength, const double &aperture)
Appends the scope with given details in the database.
Definition: ksuserdb.cpp:353
KSUserDB::EraseAllEquipment
void EraseAllEquipment(const QString &type)
Erases the whole equipment table of given type.
Definition: ksuserdb.cpp:337
KSUserDB::~KSUserDB
~KSUserDB()
Definition: ksuserdb.cpp:57
KSUserDB::ReturnAllFlags
QList< QStringList > ReturnAllFlags()
Returns a QList populated with all stored flags Order: const QString &ra, const QString &dec...
Definition: ksuserdb.cpp:288
KSParser
Generic class for text file parsers used in KStars.
Definition: ksparser.h:49
OAL::Scope
Definition: scope.h:25
KSUserDB::GetAllObservers
void GetAllObservers(QList< OAL::Observer * > &observer_list)
Updates the passed reference of observer_list with all observers The original content of the list is ...
Definition: ksuserdb.cpp:229
KSUserDB::GetAllFilters
void GetAllFilters(QList< OAL::Filter * > &m_filterList)
Populate the reference passed with all filters.
Definition: ksuserdb.cpp:601
KSUserDB::Initialize
bool Initialize()
Initialize KStarsDB while running splash screen.
Definition: ksuserdb.cpp:32
KSUserDB::EraseAllFlags
void EraseAllFlags()
Erases all the flags from the database.
Definition: ksuserdb.cpp:254
KSUserDB::GetAllScopes
void GetAllScopes(QList< OAL::Scope * > &m_scopeList)
updates the scope list with all scopes from database List is cleared and then filled with content...
Definition: ksuserdb.cpp:399
KSUserDB::AddFilter
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &color)
Add a new filter to the database.
Definition: ksuserdb.cpp:562
KSUserDB::AddLens
void AddLens(const QString &vendor, const QString &model, const double &factor)
Add a new lens to the database.
Definition: ksuserdb.cpp:501
OAL::Filter
Definition: filter.h:25
KSUserDB::GetAllEyepieces
void GetAllEyepieces(QList< OAL::Eyepiece * > &m_eyepieceList)
Populate the reference passed with all eyepieces.
Definition: ksuserdb.cpp:472
OAL::Scope::setINDIDriver
void setINDIDriver(const QString &driver)
Definition: scope.h:37
KSUserDB::AddEyepiece
void AddEyepiece(const QString &vendor, const QString &model, const double &focalLength, const double &fov, const QString &fovunit)
Add new eyepiece to database.
Definition: ksuserdb.cpp:429
KSUserDB::GetAllLenses
void GetAllLenses(QList< OAL::Lens * > &m_lensList)
Populate the reference passed with all lenses.
Definition: ksuserdb.cpp:537
KSUserDB::DeleteObserver
bool DeleteObserver(const QString &id)
Removes the user with unique id as given by FindObserver Returns false if the user is not found...
Definition: ksuserdb.cpp:212
KSUserDB::AddObserver
void AddObserver(const QString &name, const QString &surname, const QString &contact)
Adds a new observer into the database.
Definition: ksuserdb.cpp:168
KSUserDB::EraseEquipment
void EraseEquipment(const QString &type, const int &id)
Erase the equipment with given type and unique id Valid equipment types: "telescope","lens","filter".
Definition: ksuserdb.cpp:323
kstarsdata.h
OAL::Observer
Definition: observer.h:25
KSUserDB::AddFlag
void AddFlag(const QString &ra, const QString &dec, const QString &epoch, const QString &image_name, const QString &label, const QString &labelColor)
Add a new Flag with given parameters.
Definition: ksuserdb.cpp:267
ksuserdb.h
KSParser::D_QSTRING
Definition: ksparser.h:68
OAL::Lens
Definition: lens.h:25
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal