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

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • runner
  • monav
MonavConfigWidget.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "MonavConfigWidget.h"
12 
13 #include "MonavMapsModel.h"
14 #include "MonavPlugin.h"
15 #include "MarbleDirs.h"
16 #include "MarbleDebug.h"
17 
18 #include <QFile>
19 #include <QProcess>
20 #include <QSignalMapper>
21 #include <QStringListModel>
22 #include <QComboBox>
23 #include <QPushButton>
24 #include <QShowEvent>
25 #include <QSortFilterProxyModel>
26 #include <QMessageBox>
27 #include <QNetworkAccessManager>
28 #include <QNetworkReply>
29 #include <QDomDocument>
30 
31 namespace Marble
32 {
33 
34 class MonavStuffEntry
35 {
36 public:
37  void setPayload( const QString &payload );
38 
39  QString payload() const;
40 
41  void setName( const QString &name );
42 
43  QString name() const;
44 
45  bool isValid() const;
46 
47  QString continent() const;
48 
49  QString state() const;
50 
51  QString region() const;
52 
53  QString transport() const;
54 
55 private:
56  QString m_payload;
57 
58  QString m_name;
59 
60  QString m_continent;
61 
62  QString m_state;
63 
64  QString m_region;
65 
66  QString m_transport;
67 };
68 
69 class MonavConfigWidgetPrivate
70 {
71 public:
72  MonavConfigWidget* m_parent;
73 
74  MonavPlugin* m_plugin;
75 
76  QNetworkAccessManager m_networkAccessManager;
77 
78  QNetworkReply* m_currentReply;
79 
80  QProcess* m_unpackProcess;
81 
82  QSortFilterProxyModel* m_filteredModel;
83 
84  MonavMapsModel* m_mapsModel;
85 
86  bool m_initialized;
87 
88  QSignalMapper m_removeMapSignalMapper;
89 
90  QSignalMapper m_upgradeMapSignalMapper;
91 
92  QVector<MonavStuffEntry> m_remoteMaps;
93 
94  QMap<QString, QString> m_remoteVersions;
95 
96  QString m_currentDownload;
97 
98  QFile m_currentFile;
99 
100  QString m_transport;
101 
102  MonavConfigWidgetPrivate( MonavConfigWidget* parent, MonavPlugin* plugin );
103 
104  void parseNewStuff( const QByteArray &data );
105 
106  bool updateContinents( QComboBox* comboBox );
107 
108  bool updateStates( const QString &continent, QComboBox* comboBox );
109 
110  bool updateRegions( const QString &continent, const QString &state, QComboBox* comboBox );
111 
112  MonavStuffEntry map( const QString &continent, const QString &state, const QString &region ) const;
113 
114  void install();
115 
116  void installMap();
117 
118  void updateInstalledMapsView();
119 
120  void updateInstalledMapsViewButtons();
121 
122  void updateTransportPreference();
123 
124  bool canExecute( const QString &executable ) const;
125 
126  void setBusy( bool busy, const QString &message = QString() ) const;
127 
128 private:
129  bool fillComboBox( QStringList items, QComboBox* comboBox ) const;
130 };
131 
132 void MonavStuffEntry::setPayload( const QString &payload )
133 {
134  m_payload = payload;
135 }
136 
137 QString MonavStuffEntry::payload() const
138 {
139  return m_payload;
140 }
141 
142 void MonavStuffEntry::setName( const QString &name )
143 {
144  m_name = name;
145  QStringList parsed = name.split( QLatin1Char( '/' ) );
146  int size = parsed.size();
147  m_continent = size > 0 ? parsed.at( 0 ).trimmed() : QString();
148  m_state = size > 1 ? parsed.at( 1 ).trimmed() : QString();
149  m_region = size > 2 ? parsed.at( 2 ).trimmed() : QString();
150  m_transport = "Motorcar"; // No i18n
151 
152  if ( size > 1 ) {
153  QString last = parsed.last().trimmed();
154  QRegExp regexp("([^(]+)\\(([^)]+)\\)");
155  if ( regexp.indexIn( last ) >= 0 ) {
156  QStringList matches = regexp.capturedTexts();
157  if ( matches.size() == 3 ) {
158  m_transport = matches.at( 2 ).trimmed();
159  if ( size > 2 ) {
160  m_region = matches.at( 1 ).trimmed();
161  } else {
162  m_state = matches.at( 1 ).trimmed();
163  }
164  }
165  }
166  }
167 }
168 
169 QString MonavStuffEntry::name() const
170 {
171  return m_name;
172 }
173 
174 QString MonavStuffEntry::continent() const
175 {
176  return m_continent;
177 }
178 
179 QString MonavStuffEntry::state() const
180 {
181  return m_state;
182 }
183 
184 QString MonavStuffEntry::region() const
185 {
186  return m_region;
187 }
188 
189 QString MonavStuffEntry::transport() const
190 {
191  return m_transport;
192 }
193 
194 bool MonavStuffEntry::isValid() const
195 {
196  return !m_continent.isEmpty() && !m_state.isEmpty() && m_payload.startsWith( QLatin1String( "http://" ) );
197 }
198 
199 MonavConfigWidgetPrivate::MonavConfigWidgetPrivate( MonavConfigWidget* parent, MonavPlugin* plugin ) :
200  m_parent( parent ), m_plugin( plugin ), m_networkAccessManager( 0 ),
201  m_currentReply( 0 ), m_unpackProcess( 0 ), m_filteredModel( new QSortFilterProxyModel( parent) ),
202  m_mapsModel( 0 ), m_initialized( false )
203 {
204  m_filteredModel->setFilterKeyColumn( 1 );
205 }
206 
207 void MonavConfigWidgetPrivate::parseNewStuff( const QByteArray &data )
208 {
209  QDomDocument xml;
210  if ( !xml.setContent( data ) ) {
211  mDebug() << "Cannot parse xml file " << data;
212  return;
213  }
214 
215  QDomElement root = xml.documentElement();
216  QDomNodeList items = root.elementsByTagName( "stuff" );
217  for ( unsigned int i = 0; i < items.length(); ++i ) {
218  MonavStuffEntry item;
219  QDomNode node = items.item( i );
220 
221  QDomNodeList names = node.toElement().elementsByTagName( "name" );
222  if ( names.size() == 1 ) {
223  item.setName( names.at( 0 ).toElement().text() );
224  }
225 
226  QString releaseDate;
227  QDomNodeList dates = node.toElement().elementsByTagName( "releasedate" );
228  if ( dates.size() == 1 ) {
229  releaseDate = dates.at( 0 ).toElement().text();
230  }
231 
232  QString filename;
233  QDomNodeList payloads = node.toElement().elementsByTagName( "payload" );
234  if ( payloads.size() == 1 ) {
235  QString payload = payloads.at( 0 ).toElement().text();
236  filename = payload.mid( 1 + payload.lastIndexOf( "/" ) );
237  item.setPayload( payload );
238  }
239 
240  if ( item.isValid() ) {
241  m_remoteMaps.push_back( item );
242  if ( !filename.isEmpty() && !releaseDate.isEmpty() ) {
243  m_remoteVersions[filename] = releaseDate;
244  }
245  }
246  }
247 
248  m_mapsModel->setInstallableVersions( m_remoteVersions );
249  updateInstalledMapsViewButtons();
250 }
251 
252 bool MonavConfigWidgetPrivate::fillComboBox( QStringList items, QComboBox* comboBox ) const
253 {
254  comboBox->clear();
255  qSort( items );
256  comboBox->addItems( items );
257  return !items.isEmpty();
258 }
259 
260 bool MonavConfigWidgetPrivate::updateContinents( QComboBox* comboBox )
261 {
262  QSet<QString> continents;
263  foreach( const MonavStuffEntry &map, m_remoteMaps ) {
264  Q_ASSERT( map.isValid() );
265  continents << map.continent();
266  }
267 
268  return fillComboBox( continents.toList(), comboBox );
269 }
270 
271 bool MonavConfigWidgetPrivate::updateStates( const QString &continent, QComboBox* comboBox )
272 {
273  QSet<QString> states;
274  foreach( const MonavStuffEntry &map, m_remoteMaps ) {
275  Q_ASSERT( map.isValid() );
276  if ( map.continent() == continent ) {
277  states << map.state();
278  }
279  }
280 
281  return fillComboBox( states.toList(), comboBox );
282 }
283 
284 bool MonavConfigWidgetPrivate::updateRegions( const QString &continent, const QString &state, QComboBox* comboBox )
285 {
286  comboBox->clear();
287  QMap<QString,QString> regions;
288  foreach( const MonavStuffEntry &map, m_remoteMaps ) {
289  Q_ASSERT( map.isValid() );
290  if ( map.continent() == continent && map.state() == state ) {
291  QString item = "%1 - %2";
292  if ( map.region().isEmpty() ) {
293  item = item.arg( map.state() );
294  comboBox->addItem( item.arg( map.transport() ), map.payload() );
295  } else {
296  item = item.arg( map.region(), map.transport() );
297  regions.insert( item, map.payload() );
298  }
299  }
300  }
301 
302  QMapIterator<QString, QString> iter( regions );
303  while ( iter.hasNext() ) {
304  iter.next();
305  comboBox->addItem( iter.key(), iter.value() );
306  }
307 
308  return true;
309 }
310 
311 MonavStuffEntry MonavConfigWidgetPrivate::map( const QString &continent, const QString &state, const QString &region ) const
312 {
313  foreach( const MonavStuffEntry &entry, m_remoteMaps ) {
314  if ( continent == entry.continent() && state == entry.state() && region == entry.region() ) {
315  return entry;
316  }
317  }
318 
319  return MonavStuffEntry();
320 }
321 
322 MonavConfigWidget::MonavConfigWidget( MonavPlugin* plugin ) :
323  d( new MonavConfigWidgetPrivate( this, plugin ) )
324 {
325  setupUi( this );
326  m_statusLabel->setText( plugin->statusMessage() );
327  m_statusLabel->setHidden( m_statusLabel->text().isEmpty() );
328  d->setBusy( false );
329  m_installedMapsListView->setModel( d->m_mapsModel );
330  m_configureMapsListView->setModel( d->m_filteredModel );
331  m_configureMapsListView->resizeColumnsToContents();
332 
333  updateComboBoxes();
334 
335  connect( m_continentComboBox, SIGNAL(currentIndexChanged(int)),
336  this, SLOT(updateStates()) );
337  connect( m_transportTypeComboBox, SIGNAL(currentIndexChanged(QString)),
338  this, SLOT(updateTransportTypeFilter(QString)) );
339  connect( m_stateComboBox, SIGNAL(currentIndexChanged(int)),
340  this, SLOT(updateRegions()) );
341  connect( m_installButton, SIGNAL(clicked()), this, SLOT(downloadMap()) );
342  connect( m_cancelButton, SIGNAL(clicked()), this, SLOT(cancelOperation()) );
343  connect( &d->m_removeMapSignalMapper, SIGNAL(mapped(int)),
344  this, SLOT(removeMap(int)) );
345  connect( &d->m_upgradeMapSignalMapper, SIGNAL(mapped(int)),
346  this, SLOT(upgradeMap(int)) );
347  connect( &d->m_networkAccessManager, SIGNAL(finished(QNetworkReply*)),
348  this, SLOT(retrieveMapList(QNetworkReply*)) );
349 }
350 
351 MonavConfigWidget::~MonavConfigWidget()
352 {
353  delete d;
354 }
355 
356 void MonavConfigWidget::loadSettings( const QHash<QString, QVariant> &settings )
357 {
358  d->m_transport = settings["transport"].toString();
359  d->updateTransportPreference();
360 }
361 
362 void MonavConfigWidgetPrivate::updateTransportPreference()
363 {
364  if ( m_parent->m_transportTypeComboBox && m_mapsModel ) {
365  m_parent->m_transportTypeComboBox->blockSignals( true );
366  m_parent->m_transportTypeComboBox->clear();
367  QSet<QString> transportTypes;
368  for( int i=0; i<m_mapsModel->rowCount(); ++i ) {
369  QModelIndex index = m_mapsModel->index( i, 1 );
370  transportTypes << m_mapsModel->data( index ).toString();
371  }
372  m_parent->m_transportTypeComboBox->addItems( transportTypes.toList() );
373  m_parent->m_transportTypeComboBox->blockSignals( false );
374 
375  if ( !m_transport.isEmpty() && m_parent->m_transportTypeComboBox ) {
376  for ( int i=1; i<m_parent->m_transportTypeComboBox->count(); ++i ) {
377  if ( m_parent->m_transportTypeComboBox->itemText( i ) == m_transport ) {
378  m_parent->m_transportTypeComboBox->setCurrentIndex( i );
379  return;
380  }
381  }
382  }
383  }
384 }
385 
386 QHash<QString, QVariant> MonavConfigWidget::settings() const
387 {
388  QHash<QString, QVariant> settings;
389  settings["transport"] = d->m_transport;
390  return settings;
391 }
392 
393 void MonavConfigWidget::retrieveMapList( QNetworkReply *reply )
394 {
395  if ( reply->isReadable() && d->m_currentDownload.isEmpty() ) {
396  // check if we are redirected
397  QVariant const redirectionAttribute = reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
398  if ( !redirectionAttribute.isNull() ) {
399  d->m_networkAccessManager.get( QNetworkRequest( redirectionAttribute.toUrl() ) );
400  } else {
401  disconnect( &d->m_networkAccessManager, SIGNAL(finished(QNetworkReply*)),
402  this, SLOT(retrieveMapList(QNetworkReply*)) );
403  d->parseNewStuff( reply->readAll() );
404  updateComboBoxes();
405  }
406  }
407 }
408 
409 void MonavConfigWidget::retrieveData()
410 {
411  if ( d->m_currentReply && d->m_currentReply->isReadable() && !d->m_currentDownload.isEmpty() ) {
412  // check if we are redirected
413  QVariant const redirectionAttribute = d->m_currentReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
414  if ( !redirectionAttribute.isNull() ) {
415  d->m_currentReply = d->m_networkAccessManager.get( QNetworkRequest( redirectionAttribute.toUrl() ) );
416  connect( d->m_currentReply, SIGNAL(readyRead()),
417  this, SLOT(retrieveData()) );
418  connect( d->m_currentReply, SIGNAL(readChannelFinished()),
419  this, SLOT(retrieveData()) );
420  connect( d->m_currentReply, SIGNAL(downloadProgress(qint64,qint64)),
421  this, SLOT(updateProgressBar(qint64,qint64)) );
422  } else {
423  d->m_currentFile.write( d->m_currentReply->readAll() );
424  if ( d->m_currentReply->isFinished() ) {
425  d->m_currentReply->deleteLater();
426  d->m_currentReply = 0;
427  d->m_currentFile.close();
428  d->installMap();
429  d->m_currentDownload.clear();
430  }
431  }
432  }
433 }
434 
435 void MonavConfigWidget::updateComboBoxes()
436 {
437  d->updateContinents( m_continentComboBox );
438  updateStates();
439  updateRegions();
440 }
441 
442 void MonavConfigWidget::updateStates()
443 {
444  bool const haveContinents = m_continentComboBox->currentIndex() >= 0;
445  if ( haveContinents ) {
446  QString const continent = m_continentComboBox->currentText();
447  if ( d->updateStates( continent, m_stateComboBox ) ) {
448  updateRegions();
449  }
450  }
451 }
452 
453 void MonavConfigWidget::updateRegions()
454 {
455  bool haveRegions = false;
456  if ( m_continentComboBox->currentIndex() >= 0 ) {
457  if ( m_stateComboBox->currentIndex() >= 0 ) {
458  QString const continent = m_continentComboBox->currentText();
459  QString const state = m_stateComboBox->currentText();
460  haveRegions = d->updateRegions( continent, state, m_regionComboBox );
461  }
462  }
463 
464  m_regionLabel->setVisible( haveRegions );
465  m_regionComboBox->setVisible( haveRegions );
466 }
467 
468 void MonavConfigWidget::downloadMap()
469 {
470  if ( d->m_currentDownload.isEmpty() && !d->m_currentFile.isOpen() ) {
471  d->m_currentDownload = m_regionComboBox->itemData( m_regionComboBox->currentIndex() ).toString();
472  d->install();
473  }
474 }
475 
476 void MonavConfigWidget::cancelOperation()
477 {
478  if ( !d->m_currentDownload.isEmpty() || d->m_currentFile.isOpen() ) {
479  d->m_currentReply->abort();
480  d->m_currentReply->deleteLater();
481  d->m_currentReply = 0;
482  d->m_currentDownload.clear();
483  d->setBusy( false );
484  d->m_currentFile.close();
485  }
486 }
487 
488 void MonavConfigWidgetPrivate::install()
489 {
490  if ( !m_currentDownload.isEmpty() ) {
491  int const index = m_currentDownload.lastIndexOf( "/");
492  QString localFile = MarbleDirs::localPath() + "/maps" + m_currentDownload.mid( index );
493  m_currentFile.setFileName( localFile );
494  if ( m_currentFile.open( QFile::WriteOnly ) ) {
495  QFileInfo file( m_currentFile );
496  QString message = QObject::tr( "Downloading %1" ).arg( file.fileName() );
497  setBusy( true, message );
498  m_currentReply = m_networkAccessManager.get( QNetworkRequest( m_currentDownload ) );
499  QObject::connect( m_currentReply, SIGNAL(readyRead()),
500  m_parent, SLOT(retrieveData()) );
501  QObject::connect( m_currentReply, SIGNAL(readChannelFinished()),
502  m_parent, SLOT(retrieveData()) );
503  QObject::connect( m_currentReply, SIGNAL(downloadProgress(qint64,qint64)),
504  m_parent, SLOT(updateProgressBar(qint64,qint64)) );
505  } else {
506  mDebug() << "Failed to write to " << localFile;
507  }
508  }
509 }
510 
511 void MonavConfigWidgetPrivate::installMap()
512 {
513  if ( m_unpackProcess ) {
514  m_unpackProcess->close();
515  delete m_unpackProcess;
516  m_unpackProcess = 0;
517  m_parent->m_installButton->setEnabled( true );
518  } else if ( m_currentFile.fileName().endsWith( QLatin1String( "tar.gz" ) ) && canExecute( "tar" ) ) {
519  QFileInfo file( m_currentFile );
520  QString message = QObject::tr( "Installing %1" ).arg( file.fileName() );
521  setBusy( true, message );
522  m_parent->m_progressBar->setMaximum( 0 );
523  if ( file.exists() && file.isReadable() ) {
524  m_unpackProcess = new QProcess;
525  QObject::connect( m_unpackProcess, SIGNAL(finished(int)),
526  m_parent, SLOT(mapInstalled(int)) );
527  QStringList arguments = QStringList() << "-x" << "-z" << "-f" << file.fileName();
528  m_unpackProcess->setWorkingDirectory( file.dir().absolutePath() );
529  m_unpackProcess->start( "tar", arguments );
530  }
531  } else {
532  if ( !m_currentFile.fileName().endsWith( QLatin1String( "tar.gz" ) ) ) {
533  mDebug() << "Can only handle tar.gz files";
534  } else {
535  mDebug() << "Cannot extract archive: tar executable not found in PATH.";
536  }
537  }
538 }
539 
540 void MonavConfigWidget::updateProgressBar( qint64 bytesReceived, qint64 bytesTotal )
541 {
542  // Coarse MB resolution for the text to get it short,
543  // finer Kb resolution for the progress values to see changes easily
544  m_progressBar->setMaximum( bytesTotal / 1024 );
545  m_progressBar->setValue( bytesReceived / 1024 );
546  QString progress = "%1/%2 MB";
547  m_progressBar->setFormat( progress.arg( bytesReceived / 1024 / 1024 ).arg( bytesTotal / 1024 / 1024 ) );
548 }
549 
550 bool MonavConfigWidgetPrivate::canExecute( const QString &executable ) const
551 {
552  QString path = QProcessEnvironment::systemEnvironment().value( "PATH", "/usr/local/bin:/usr/bin:/bin" );
553  foreach( const QString &dir, path.split( QLatin1Char( ':' ) ) ) {
554  QFileInfo application( QDir( dir ), executable );
555  if ( application.exists() ) {
556  return true;
557  }
558  }
559 
560  return false;
561 }
562 
563 void MonavConfigWidget::mapInstalled( int exitStatus )
564 {
565  d->m_unpackProcess = 0;
566  d->m_currentFile.remove();
567  d->setBusy( false );
568 
569  if ( exitStatus == 0 ) {
570  d->m_plugin->reloadMaps();
571  d->updateInstalledMapsView();
572  monavTabWidget->setCurrentIndex( 0 );
573  } else {
574  mDebug() << "Error when unpacking archive, process exited with status code " << exitStatus;
575  }
576 }
577 
578 void MonavConfigWidget::showEvent ( QShowEvent * event )
579 {
580  // Lazy initialization
581  RoutingRunnerPlugin::ConfigWidget::showEvent( event );
582  if ( !event->spontaneous() && !d->m_initialized ) {
583  d->m_initialized = true;
584  d->updateInstalledMapsView();
585  QUrl url = QUrl( "http://files.kde.org/marble/newstuff/maps-monav.xml" );
586  d->m_networkAccessManager.get( QNetworkRequest( url ) );
587  }
588 }
589 
590 void MonavConfigWidgetPrivate::updateInstalledMapsView()
591 {
592  m_mapsModel = m_plugin->installedMapsModel();
593  m_mapsModel->setInstallableVersions( m_remoteVersions );
594  m_filteredModel->setSourceModel( m_mapsModel );
595  m_parent->m_installedMapsListView->setModel( m_mapsModel );
596 
597  m_parent->m_configureMapsListView->setColumnHidden( 1, true );
598  m_parent->m_installedMapsListView->setColumnHidden( 2, true );
599  m_parent->m_configureMapsListView->setColumnHidden( 3, true );
600  m_parent->m_configureMapsListView->setColumnHidden( 4, true );
601  m_parent->m_installedMapsListView->setColumnHidden( 5, true );
602 
603  m_parent->m_configureMapsListView->horizontalHeader()->setVisible( true );
604  m_parent->m_installedMapsListView->horizontalHeader()->setVisible( true );
605  m_parent->m_configureMapsListView->resizeColumnsToContents();
606  m_parent->m_installedMapsListView->resizeColumnsToContents();
607 
608  updateTransportPreference();
609  updateInstalledMapsViewButtons();
610 }
611 
612 void MonavConfigWidgetPrivate::updateInstalledMapsViewButtons()
613 {
614  m_removeMapSignalMapper.removeMappings( m_parent );
615  m_upgradeMapSignalMapper.removeMappings( m_parent );
616  for( int i=0; i<m_mapsModel->rowCount(); ++i ) {
617  {
618  QPushButton* button = new QPushButton( QIcon( ":/system-software-update.png" ), "" );
619  button->setAutoFillBackground( true );
620  QModelIndex index = m_mapsModel->index( i, 3 );
621  m_parent->m_installedMapsListView->setIndexWidget( index, button );
622  m_upgradeMapSignalMapper.setMapping( button, index.row() );
623  QObject::connect( button, SIGNAL(clicked()), &m_upgradeMapSignalMapper, SLOT(map()) );
624  bool upgradable = m_mapsModel->data( index ).toBool();
625  QString canUpgradeText = QObject::tr( "An update is available. Click to install it." );
626  QString isLatestText = QObject::tr( "No update available. You are running the latest version." );
627  button->setToolTip( upgradable ? canUpgradeText : isLatestText );
628  button->setEnabled( upgradable );
629  }
630  {
631  QPushButton* button = new QPushButton( QIcon( ":/edit-delete.png" ), "" );
632  button->setAutoFillBackground( true );
633  QModelIndex index = m_mapsModel->index( i, 4 );
634  m_parent->m_installedMapsListView->setIndexWidget( index, button );
635  m_removeMapSignalMapper.setMapping( button, index.row() );
636  QObject::connect( button, SIGNAL(clicked()), &m_removeMapSignalMapper, SLOT(map()) );
637  bool const writable = m_mapsModel->data( index ).toBool();
638  button->setEnabled( writable );
639  }
640  }
641  m_parent->m_installedMapsListView->resizeColumnsToContents();
642 }
643 
644 void MonavConfigWidget::updateTransportTypeFilter( const QString &filter )
645 {
646  d->m_filteredModel->setFilterFixedString( filter );
647  d->m_transport = filter;
648  m_configureMapsListView->resizeColumnsToContents();
649 }
650 
651 void MonavConfigWidget::removeMap( int index )
652 {
653  QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel;
654  QString text = tr( "Are you sure you want to delete this map from the system?" );
655  if ( QMessageBox::question( this, tr( "Remove Map" ), text, buttons, QMessageBox::No ) == QMessageBox::Yes ) {
656  d->m_mapsModel->deleteMapFiles( index );
657  d->m_plugin->reloadMaps();
658  d->updateInstalledMapsView();
659  }
660 }
661 
662 void MonavConfigWidget::upgradeMap( int index )
663 {
664  QString payload = d->m_mapsModel->payload( index );
665  if ( !payload.isEmpty() ) {
666  foreach( const MonavStuffEntry &entry, d->m_remoteMaps ) {
667  if ( entry.payload().endsWith( '/' + payload ) ) {
668  d->m_currentDownload = entry.payload();
669  d->install();
670  return;
671  }
672  }
673  }
674 }
675 
676 void MonavConfigWidgetPrivate::setBusy( bool busy, const QString &message ) const
677 {
678  if ( busy ) {
679  m_parent->m_stackedWidget->removeWidget( m_parent->m_settingsPage );
680  m_parent->m_stackedWidget->addWidget( m_parent->m_progressPage );
681  } else {
682  m_parent->m_stackedWidget->removeWidget( m_parent->m_progressPage );
683  m_parent->m_stackedWidget->addWidget( m_parent->m_settingsPage );
684  }
685 
686  QString const defaultMessage = QObject::tr( "Nothing to do." );
687  m_parent->m_progressLabel->setText( message.isEmpty() ? defaultMessage : message );
688 }
689 
690 }
691 
692 #include "MonavConfigWidget.moc"
Marble::MonavPlugin
Definition: MonavPlugin.h:23
Marble::MarbleDirs::localPath
static QString localPath()
Definition: MarbleDirs.cpp:217
Marble::MonavConfigWidget::loadSettings
virtual void loadSettings(const QHash< QString, QVariant > &settings)
Definition: MonavConfigWidget.cpp:356
Marble::MonavConfigWidget::MonavConfigWidget
MonavConfigWidget(MonavPlugin *plugin)
Definition: MonavConfigWidget.cpp:322
MonavPlugin.h
MarbleDebug.h
Marble::MonavConfigWidget::settings
virtual QHash< QString, QVariant > settings() const
Definition: MonavConfigWidget.cpp:386
MonavMapsModel.h
Marble::MonavConfigWidget::~MonavConfigWidget
~MonavConfigWidget()
Definition: MonavConfigWidget.cpp:351
MarbleDirs.h
Marble::RoutingRunnerPlugin::statusMessage
QString statusMessage() const
A status message showing whether the plugin will be able to deliver results.
Definition: RoutingRunnerPlugin.cpp:96
Marble::MonavConfigWidget::showEvent
virtual void showEvent(QShowEvent *event)
Definition: MonavConfigWidget.cpp:578
MonavConfigWidget.h
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • 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