8 #include <QCoreApplication>
10 QHash<QString,Journey *> Journeys::journeyHash;
11 bool Journeys::initialised = false;
25 bool Journeys::addJourney( Journey *journey )
29 saveJourney( journey );
31 if ( !journeyHash.contains( journey->label() ) ) {
32 qDebug() << "Adding journey" << journey->label();
33 journeyHash[ journey->label() ] = journey;
36 qDebug() << "FAILED to add journey" << journey->label();
42 void Journeys::restoreJourneys()
46 settings.beginGroup( "Journeys" );
47 QStringList labels = settings.childGroups();
49 for( int i=0; i<labels.size(); ++i ) {
50 QString label = labels[i];
51 settings.beginGroup( label );
52 QString from = settings.value( "from" ).toString();
53 QString to = settings.value( "to" ).toString();
56 qDebug() << "restoring" << label;
57 Journey *journey = new Journey();
58 journey->setJourney( from, to, label );
60 journeyHash[ label ] = journey;
66 void Journeys::saveJourney( Journey *journey )
68 qDebug() << "Saving journey" << journey->label();
70 settings.beginGroup( "Journeys" );
71 settings.beginGroup( journey->label() );
72 settings.setValue( "from", journey->from() );
73 settings.setValue( "to", journey->to() );
78 void Journeys::saveJourney()
80 Journey *journey = qobject_cast<Journey*>(sender());
82 saveJourney( journey );
85 Journey *Journeys::journey( const QString &label )
87 qDebug() << "requesting journey" << label;
90 if ( journeyHash.contains( label ) ) {
91 qDebug() << "found journey" << label;
92 retVal = journeyHash[ label ];
94 qDebug() << "didn't find journey" << label;