Commit 30862b94 authored by Akarsh Simha's avatar Akarsh Simha

Avoid truncating the wishlist if there's a crash while saving it.

There is a bug which induces a crash when writing the observing wish
list, and ends up truncating the wish list. This can be very
frustrating because of the loss of the wishlist.

Although the bug still needs to be found and fixed, this change in
code at least prevents the wishlist from being truncated upon crash.
parent 24f6b350
......@@ -888,13 +888,10 @@ void ObservingList::slotSaveList() {
QFile f;
// FIXME: Move wishlist into a database.
// TODO: Support multiple wishlists.
f.setFileName( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "wishlist.obslist" ) ;
if ( ! f.open( QIODevice::WriteOnly ) ) {
qDebug() << "Cannot write list to file"; // TODO: This should be presented as a message box to the user
return;
}
QTextStream ostream( &f );
foreach ( SkyObject* o, obsList() ) {
QString fileContents;
QTextStream ostream( &fileContents ); // We first write to a QString to prevent truncating the file in case there is a crash.
foreach ( const SkyObject* o, obsList() ) {
if ( !o ) {
qWarning() << "Null entry in observing wishlist! Skipping!";
continue;
......@@ -903,7 +900,8 @@ void ObservingList::slotSaveList() {
//ostream << o->name() << " " << o->ra0().Hours() << " " << o->dec0().Degrees() << endl;
ostream << getObjectName(o, false) << endl;
} else if ( o->type() == SkyObject::STAR ) {
StarObject *s = (StarObject*)o;
Q_ASSERT( dynamic_cast<const StarObject *>( o ) );
const StarObject *s = static_cast<const StarObject *>( o );
if ( s->name() == s->gname() )
ostream << s->name2() << endl;
else
......@@ -912,6 +910,13 @@ void ObservingList::slotSaveList() {
ostream << o->name() << endl;
}
}
f.setFileName( KSPaths::writableLocation(QStandardPaths::GenericDataLocation) + "wishlist.obslist" ) ;
if ( ! f.open( QIODevice::WriteOnly ) ) {
qWarning() << "Cannot save wish list to file!"; // TODO: This should be presented as a message box to the user
return;
}
QTextStream writeemall( &f );
writeemall << fileContents;
f.close();
}
......
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