7a86154b2def375eb5e66185b97cf0c9203e682a
[marble] / packaging / debian / patches / tracking-dialog.diff
1 Index: marble-0.95+svn1213143/src/lib/CurrentLocationWidget.cpp
2 ===================================================================
3 --- marble-0.95+svn1213143.orig/src/lib/CurrentLocationWidget.cpp       2011-01-09 12:28:00.000000000 +0100
4 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.cpp    2011-01-09 13:08:31.000000000 +0100
5 @@ -31,6 +31,9 @@
6  // Ui
7  #include "ui_CurrentLocationWidget.h"
8  
9 +#include <QtCore/QDateTime>
10 +#include <QtGui/QFileDialog>
11 +
12  namespace Marble
13  {
14  
15 @@ -52,6 +55,8 @@
16      void updateRecenterComboBox( int centerMode );
17      void updateAutoZoomCheckBox( bool autoZoom );
18      void updateActivePositionProvider( PositionProviderPlugin* );
19 +    void saveTrack();
20 +    void clearTrack();
21  };
22  
23  CurrentLocationWidget::CurrentLocationWidget( QWidget *parent, Qt::WindowFlags f )
24 @@ -62,11 +67,15 @@
25  
26      d->m_locale = MarbleGlobal::getInstance()->locale();
27  
28 -    connect( d->m_currentLocationUi.recenterComboBox, SIGNAL ( highlighted( int ) ),
29 +    connect( d->m_currentLocationUi.recenterComboBox, SIGNAL ( currentIndexChanged( int ) ),
30              this, SLOT( setRecenterMode( int ) ) );
31  
32      connect( d->m_currentLocationUi.autoZoomCheckBox, SIGNAL( clicked( bool ) ),
33               this, SLOT( setAutoZoom( bool ) ) );
34 +
35 +    bool const smallScreen = MarbleGlobal::getInstance()->profiles() & MarbleGlobal::SmallScreen;
36 +    d->m_currentLocationUi.positionTrackingComboBox->setVisible( !smallScreen );
37 +    d->m_currentLocationUi.locationLabel->setVisible( !smallScreen );
38  }
39  
40  CurrentLocationWidget::~CurrentLocationWidget()
41 @@ -91,6 +100,9 @@
42          QString html = "<p>No Position Tracking Plugin installed.</p>";
43          d->m_currentLocationUi.locationLabel->setText( html );
44          d->m_currentLocationUi.locationLabel->setEnabled ( true );
45 +        d->m_currentLocationUi.showTrackCheckBox->setEnabled( false );
46 +        d->m_currentLocationUi.saveTrackPushButton->setEnabled( false );
47 +        d->m_currentLocationUi.clearTrackPushButton->setEnabled( false );
48      }
49  
50      //disconnect CurrentLocation Signals
51 @@ -120,6 +132,7 @@
52      connect( d->m_widget->model()->positionTracking(),
53               SIGNAL( positionProviderPluginChanged( PositionProviderPlugin* ) ),
54               this, SLOT( updateActivePositionProvider( PositionProviderPlugin* ) ) );
55 +    d->updateActivePositionProvider( d->m_widget->model()->positionTracking()->positionProviderPlugin() );
56      connect( d->m_currentLocationUi.positionTrackingComboBox, SIGNAL( currentIndexChanged( QString ) ),
57               this, SLOT( changePositionProvider( QString ) ) );
58      connect( d->m_currentLocationUi.locationLabel, SIGNAL( linkActivated( QString ) ),
59 @@ -132,6 +145,17 @@
60               this, SLOT( updateRecenterComboBox( int ) ) );
61      connect( d->m_adjustNavigation, SIGNAL( autoZoomToggled( bool ) ),
62               this, SLOT( updateAutoZoomCheckBox( bool ) ) );
63 +    connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL( clicked(bool) ),
64 +             d->m_widget->model()->positionTracking(), SLOT( setTrackVisible(bool) ));
65 +    connect (d->m_currentLocationUi.showTrackCheckBox, SIGNAL( clicked(bool) ),
66 +             d->m_widget, SLOT(repaint()));
67 +    if ( d->m_widget->model()->positionTracking()->trackVisible() ) {
68 +        d->m_currentLocationUi.showTrackCheckBox->setCheckState(Qt::Checked);
69 +    }
70 +    connect ( d->m_currentLocationUi.saveTrackPushButton, SIGNAL( clicked(bool)),
71 +              this, SLOT(saveTrack()));
72 +    connect (d->m_currentLocationUi.clearTrackPushButton, SIGNAL( clicked(bool)),
73 +             this, SLOT(clearTrack()));
74  }
75  
76  void CurrentLocationWidgetPrivate::adjustPositionTrackingStatus( PositionProviderStatus status )
77 @@ -177,6 +201,10 @@
78          }
79      }
80      m_currentLocationUi.positionTrackingComboBox->blockSignals( false );
81 +    m_currentLocationUi.recenterLabel->setEnabled( plugin );
82 +    m_currentLocationUi.recenterComboBox->setEnabled( plugin );
83 +    m_currentLocationUi.autoZoomCheckBox->setEnabled( plugin );
84 +
85  }
86  
87  void CurrentLocationWidget::receiveGpsCoordinates( const GeoDataCoordinates &position, qreal speed )
88 @@ -222,14 +250,14 @@
89      html = html.arg( position.lonToString() ).arg( position.latToString() );
90      html = html.arg( distanceString ).arg( speedString + ' ' + unitString );
91      d->m_currentLocationUi.locationLabel->setText( html );
92 +    d->m_currentLocationUi.showTrackCheckBox->setEnabled( true );
93 +    d->m_currentLocationUi.saveTrackPushButton->setEnabled( true );
94 +    d->m_currentLocationUi.clearTrackPushButton->setEnabled( true );
95  }
96  
97  void CurrentLocationWidgetPrivate::changePositionProvider( const QString &provider )
98  {
99      bool hasProvider = ( provider != QObject::tr("Disabled") );
100 -    m_currentLocationUi.recenterLabel->setEnabled( hasProvider );
101 -    m_currentLocationUi.recenterComboBox->setEnabled( hasProvider );
102 -    m_currentLocationUi.autoZoomCheckBox->setEnabled( hasProvider );
103  
104      if ( hasProvider ) {
105          foreach( PositionProviderPlugin* plugin, m_positionProviderPlugins ) {
106 @@ -277,6 +305,28 @@
107      m_widget->centerOn(m_currentPosition, true);
108  }
109  
110 +void CurrentLocationWidgetPrivate::saveTrack()
111 +{
112 +    static QString s_dirName = QDir::homePath();
113 +    QString suggested = s_dirName;
114 +    QString fileName = QFileDialog::getSaveFileName(m_widget, QObject::tr("Save Track"), // krazy:exclude=qclasses
115 +                                                    suggested.append('/' + QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss") + ".kml"),
116 +                            QObject::tr("KML File (*.kml)"));
117 +    if ( !fileName.isEmpty() ) {
118 +        QFileInfo file( fileName );
119 +        s_dirName = file.absolutePath();
120 +        m_widget->model()->positionTracking()->saveTrack( fileName );
121 +    }
122 +}
123 +
124 +void CurrentLocationWidgetPrivate::clearTrack()
125 +{
126 +    m_widget->model()->positionTracking()->clearTrack();
127 +    m_widget->repaint();
128 +    m_currentLocationUi.saveTrackPushButton->setEnabled( false );
129 +    m_currentLocationUi.clearTrackPushButton->setEnabled( false );
130 +}
131 +
132  }
133  
134  #include "CurrentLocationWidget.moc"
135 Index: marble-0.95+svn1213143/src/lib/PositionTracking.cpp
136 ===================================================================
137 --- marble-0.95+svn1213143.orig/src/lib/PositionTracking.cpp    2011-01-09 12:28:00.000000000 +0100
138 +++ marble-0.95+svn1213143/src/lib/PositionTracking.cpp 2011-01-09 12:27:59.000000000 +0100
139 @@ -16,14 +16,19 @@
140  #include "GeoDataPlacemark.h"
141  #include "GeoDataStyle.h"
142  #include "GeoDataStyleMap.h"
143 +#include "GeoWriter.h"
144 +#include "KmlElementDictionary.h"
145  #include "AbstractProjection.h"
146  #include "FileManager.h"
147  #include "MarbleMath.h"
148  #include "MarbleDebug.h"
149 +#include "MarbleDirs.h"
150  #include "PositionProviderPlugin.h"
151  
152  #include "PositionTracking_p.h"
153  
154 +#include <QtCore/QFile>
155 +
156  using namespace Marble;
157  
158  void PositionTrackingPrivate::setPosition( GeoDataCoordinates position,
159 @@ -173,6 +178,34 @@
160      d->m_document->setVisible( visible );
161  }
162  
163 +bool PositionTracking::saveTrack(QString& fileName)
164 +{
165 +
166 +    if ( !fileName.isEmpty() )
167 +    {
168 +        if ( !fileName.endsWith(".kml", Qt::CaseInsensitive) )
169 +        {
170 +            fileName.append( ".kml" );
171 +        }
172 +
173 +        GeoWriter writer;
174 +        //FIXME: a better way to do this?
175 +        writer.setDocumentType( kml::kmlTag_nameSpace22 );
176 +
177 +        GeoDataDocument document( *d->m_document );
178 +        QFileInfo fileInfo( fileName );
179 +        QString name = fileInfo.baseName();
180 +        document.setName( name );
181 +        document.remove( 0 );
182 +        document.last().setName( "Track" );
183 +
184 +        QFile file( fileName );
185 +        file.open( QIODevice::ReadWrite );
186 +        return writer.write( &file, document );
187 +    }
188 +    return false;
189 +}
190 +
191  void PositionTracking::clearTrack()
192  {
193      GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(d->m_document->child(d->m_document->size()-1));
194 Index: marble-0.95+svn1213143/src/lib/PositionTracking.h
195 ===================================================================
196 --- marble-0.95+svn1213143.orig/src/lib/PositionTracking.h      2011-01-09 12:28:00.000000000 +0100
197 +++ marble-0.95+svn1213143/src/lib/PositionTracking.h   2011-01-09 12:27:59.000000000 +0100
198 @@ -84,6 +84,11 @@
199      void setTrackVisible ( bool visible );
200  
201      /**
202 +      * Saves the track document to file
203 +      */
204 +    bool saveTrack( QString& fileName );
205 +
206 +    /**
207        * Removes all track segments which were recorded
208        */
209      void clearTrack();
210 Index: marble-0.95+svn1213143/src/lib/CurrentLocationWidget.h
211 ===================================================================
212 --- marble-0.95+svn1213143.orig/src/lib/CurrentLocationWidget.h 2011-01-09 12:28:00.000000000 +0100
213 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.h      2011-01-09 12:27:59.000000000 +0100
214 @@ -72,6 +72,9 @@
215       Q_PRIVATE_SLOT( d, void updateAutoZoomCheckBox( bool autoZoom ) )
216  
217       Q_PRIVATE_SLOT( d, void updateActivePositionProvider( PositionProviderPlugin* ) )
218 +
219 +     Q_PRIVATE_SLOT( d, void saveTrack() )
220 +     Q_PRIVATE_SLOT( d, void clearTrack() )
221  };
222  
223  }
224 Index: marble-0.95+svn1213143/src/lib/CurrentLocationWidget.ui
225 ===================================================================
226 --- marble-0.95+svn1213143.orig/src/lib/CurrentLocationWidget.ui        2011-01-09 12:28:00.000000000 +0100
227 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.ui     2011-01-09 12:27:59.000000000 +0100
228 @@ -7,7 +7,7 @@
229      <x>0</x>
230      <y>0</y>
231      <width>137</width>
232 -    <height>190</height>
233 +    <height>237</height>
234     </rect>
235    </property>
236    <property name="windowTitle">
237 @@ -40,6 +40,36 @@
238      </widget>
239     </item>
240     <item>
241 +    <widget class="QCheckBox" name="showTrackCheckBox">
242 +     <property name="enabled">
243 +      <bool>false</bool>
244 +     </property>
245 +     <property name="text">
246 +      <string>Show Track</string>
247 +     </property>
248 +    </widget>
249 +   </item>
250 +   <item>
251 +    <widget class="QPushButton" name="saveTrackPushButton">
252 +     <property name="enabled">
253 +      <bool>false</bool>
254 +     </property>
255 +     <property name="text">
256 +      <string>Save Track</string>
257 +     </property>
258 +    </widget>
259 +   </item>
260 +   <item>
261 +    <widget class="QPushButton" name="clearTrackPushButton">
262 +     <property name="enabled">
263 +      <bool>false</bool>
264 +     </property>
265 +     <property name="text">
266 +      <string>Clear Track</string>
267 +     </property>
268 +    </widget>
269 +   </item>
270 +   <item>
271      <widget class="QLabel" name="locationLabel">
272       <property name="enabled">
273        <bool>false</bool>
274 @@ -65,6 +95,19 @@
275      </widget>
276     </item>
277     <item>
278 +    <spacer name="trackRecenterVerticalSpacer">
279 +     <property name="orientation">
280 +      <enum>Qt::Vertical</enum>
281 +     </property>
282 +     <property name="sizeHint" stdset="0">
283 +      <size>
284 +       <width>20</width>
285 +       <height>20</height>
286 +      </size>
287 +     </property>
288 +    </spacer>
289 +   </item>
290 +   <item>
291      <widget class="QLabel" name="recenterLabel">
292       <property name="enabled">
293        <bool>false</bool>
294 Index: marble-0.95+svn1213143/src/QtMainWindow.cpp
295 ===================================================================
296 --- marble-0.95+svn1213143.orig/src/QtMainWindow.cpp    2011-01-09 12:28:00.000000000 +0100
297 +++ marble-0.95+svn1213143/src/QtMainWindow.cpp 2011-01-09 12:27:59.000000000 +0100
298 @@ -41,6 +41,7 @@
299  #include <QtNetwork/QNetworkProxy>
300  
301  #include "BookmarkInfoDialog.h"
302 +#include "CurrentLocationWidget.h"
303  //#include "EditBookmarkDialog.h"
304  #include "MapViewWidget.h"
305  #include "MarbleDirs.h"
306 @@ -92,6 +93,7 @@
307          m_osmEditAction( 0 ),
308          m_mapViewDialog( 0 ),
309          m_routingDialog( 0 ),
310 +        m_trackingDialog( 0 ),
311          m_routingWidget( 0 )
312  {
313      setUpdatesEnabled( false );
314 @@ -298,6 +300,9 @@
315          m_toggleRoutingTabAction = menuBar()->addAction( tr( "Routing" ) );
316          connect( m_toggleRoutingTabAction, SIGNAL( triggered( bool ) ),
317                   this, SLOT( showRoutingDialog() ) );
318 +        m_showTrackingDialogAction = menuBar()->addAction( tr( "Tracking" ) );
319 +        connect( m_showTrackingDialogAction, SIGNAL( triggered()),
320 +                 this, SLOT( showTrackingDialog()) );
321  
322          m_controlView->marbleControl()->setNavigationTabShown( false );
323          m_controlView->marbleControl()->setLegendTabShown( false );
324 @@ -1268,6 +1273,28 @@
325      m_routingDialog->activateWindow();
326  }
327  
328 +void MainWindow::showTrackingDialog()
329 +{
330 +    if( !m_trackingDialog ) {
331 +        m_trackingDialog = new QDialog( this );
332 +        m_trackingDialog->setWindowTitle( tr( "Tracking - Marble" ) );
333 +        CurrentLocationWidget *trackingWidget = new CurrentLocationWidget( m_trackingDialog );
334 +        trackingWidget->setMarbleWidget( m_controlView->marbleWidget() );
335 +
336 +        QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok, Qt::Vertical, m_trackingDialog );
337 +        connect(buttonBox, SIGNAL( accepted() ), m_trackingDialog, SLOT( accept() ) );
338 +
339 +        QHBoxLayout* layout = new QHBoxLayout;
340 +        layout->addWidget( trackingWidget );
341 +        layout->addWidget( buttonBox );
342 +        m_trackingDialog->setLayout( layout );
343 +        m_trackingDialog->resize( 640, 420 );
344 +    }
345 +
346 +    m_trackingDialog->show();
347 +    m_trackingDialog->raise();
348 +    m_trackingDialog->activateWindow();
349 +}
350  
351  void MainWindow::updateMapEditButtonVisibility( const QString &mapTheme )
352  {
353 Index: marble-0.95+svn1213143/src/QtMainWindow.h
354 ===================================================================
355 --- marble-0.95+svn1213143.orig/src/QtMainWindow.h      2011-01-09 12:28:00.000000000 +0100
356 +++ marble-0.95+svn1213143/src/QtMainWindow.h   2011-01-09 12:27:59.000000000 +0100
357 @@ -120,6 +120,7 @@
358      void showMapViewDialog();
359      void showLegendTab( bool enabled );
360      void showRoutingDialog();
361 +    void showTrackingDialog();
362  
363   private:
364      void setupZoomButtons();
365 @@ -194,9 +195,11 @@
366      QAction *m_showMapViewDialogAction;
367      QAction *m_toggleLegendTabAction;
368      QAction *m_toggleRoutingTabAction;
369 +    QAction *m_showTrackingDialogAction;
370  
371      QDialog *m_mapViewDialog;
372      QDialog *m_routingDialog;
373 +    QDialog *m_trackingDialog;
374  
375      RoutingWidget *m_routingWidget;
376  };