Update tracking diff with patches from trunk
[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:13:21.000000000 +0100
4 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.cpp    2011-01-09 12:15:22.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,27 @@
107      m_widget->centerOn(m_currentPosition, true);
108  }
109  
110 +void CurrentLocationWidgetPrivate::saveTrack()
111 +{
112 +    static QString s_dirName = QDir::homePath();
113 +    QString fileName = QFileDialog::getSaveFileName(m_widget, QObject::tr("Save Track"), // krazy:exclude=qclasses
114 +                                                    s_dirName.append('/' + QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss") + ".kml"),
115 +                            QObject::tr("KML File (*.kml)"));
116 +    if ( fileName ) {
117 +        QFileInfo file( fileName );
118 +        s_dirName = file.absolutePath();
119 +        m_widget->model()->positionTracking()->saveTrack( fileName );
120 +    }
121 +}
122 +
123 +void CurrentLocationWidgetPrivate::clearTrack()
124 +{
125 +    m_widget->model()->positionTracking()->clearTrack();
126 +    m_widget->repaint();
127 +    m_currentLocationUi.saveTrackPushButton->setEnabled( false );
128 +    m_currentLocationUi.clearTrackPushButton->setEnabled( false );
129 +}
130 +
131  }
132  
133  #include "CurrentLocationWidget.moc"
134 Index: marble-0.95+svn1213143/src/lib/PositionTracking.cpp
135 ===================================================================
136 --- marble-0.95+svn1213143.orig/src/lib/PositionTracking.cpp    2011-01-09 12:13:21.000000000 +0100
137 +++ marble-0.95+svn1213143/src/lib/PositionTracking.cpp 2011-01-09 18:06:10.000000000 +0100
138 @@ -16,14 +16,19 @@
139  #include "GeoDataPlacemark.h"
140  #include "GeoDataStyle.h"
141  #include "GeoDataStyleMap.h"
142 +#include "GeoWriter.h"
143 +#include "KmlElementDictionary.h"
144  #include "AbstractProjection.h"
145  #include "FileManager.h"
146  #include "MarbleMath.h"
147  #include "MarbleDebug.h"
148 +#include "MarbleDirs.h"
149  #include "PositionProviderPlugin.h"
150  
151  #include "PositionTracking_p.h"
152  
153 +#include <QtCore/QFile>
154 +
155  using namespace Marble;
156  
157  void PositionTrackingPrivate::setPosition( GeoDataCoordinates position,
158 @@ -173,6 +178,41 @@
159      d->m_document->setVisible( visible );
160  }
161  
162 +bool PositionTracking::saveTrack(QString& fileName)
163 +{
164 +
165 +    if ( !fileName.isEmpty() )
166 +    {
167 +        if ( !fileName.endsWith(".kml", Qt::CaseInsensitive) )
168 +        {
169 +            fileName.append( ".kml" );
170 +        }
171 +
172 +        GeoWriter writer;
173 +        //FIXME: a better way to do this?
174 +        writer.setDocumentType( kml::kmlTag_nameSpace22 );
175 +
176 +        QFileInfo fileInfo( fileName );
177 +        QString name = fileInfo.baseName();
178 +        GeoDataDocument document;
179 +        document.setName( name );
180 +        foreach( GeoDataStyle style, d->m_document->styles() ) {
181 +            document.addStyle( style );
182 +        }
183 +        foreach( GeoDataStyleMap map, d->m_document->styleMaps() ) {
184 +            document.addStyleMap( map );
185 +        }
186 +        GeoDataFeature *track = new GeoDataFeature( d->m_document->last() );
187 +        track->setName( "Track " + name );
188 +        document.append( track );
189 +
190 +        QFile file( fileName );
191 +        file.open( QIODevice::ReadWrite );
192 +        return writer.write( &file, document );
193 +    }
194 +    return false;
195 +}
196 +
197  void PositionTracking::clearTrack()
198  {
199      GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(d->m_document->child(d->m_document->size()-1));
200 Index: marble-0.95+svn1213143/src/lib/PositionTracking.h
201 ===================================================================
202 --- marble-0.95+svn1213143.orig/src/lib/PositionTracking.h      2011-01-09 12:13:21.000000000 +0100
203 +++ marble-0.95+svn1213143/src/lib/PositionTracking.h   2011-01-09 12:13:35.000000000 +0100
204 @@ -84,6 +84,11 @@
205      void setTrackVisible ( bool visible );
206  
207      /**
208 +      * Saves the track document to file
209 +      */
210 +    bool saveTrack( QString& fileName );
211 +
212 +    /**
213        * Removes all track segments which were recorded
214        */
215      void clearTrack();
216 Index: marble-0.95+svn1213143/src/lib/CurrentLocationWidget.h
217 ===================================================================
218 --- marble-0.95+svn1213143.orig/src/lib/CurrentLocationWidget.h 2011-01-09 12:13:21.000000000 +0100
219 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.h      2011-01-09 12:13:35.000000000 +0100
220 @@ -72,6 +72,9 @@
221       Q_PRIVATE_SLOT( d, void updateAutoZoomCheckBox( bool autoZoom ) )
222  
223       Q_PRIVATE_SLOT( d, void updateActivePositionProvider( PositionProviderPlugin* ) )
224 +
225 +     Q_PRIVATE_SLOT( d, void saveTrack() )
226 +     Q_PRIVATE_SLOT( d, void clearTrack() )
227  };
228  
229  }
230 Index: marble-0.95+svn1213143/src/lib/CurrentLocationWidget.ui
231 ===================================================================
232 --- marble-0.95+svn1213143.orig/src/lib/CurrentLocationWidget.ui        2011-01-09 12:13:21.000000000 +0100
233 +++ marble-0.95+svn1213143/src/lib/CurrentLocationWidget.ui     2011-01-09 12:13:42.000000000 +0100
234 @@ -7,7 +7,7 @@
235      <x>0</x>
236      <y>0</y>
237      <width>137</width>
238 -    <height>190</height>
239 +    <height>237</height>
240     </rect>
241    </property>
242    <property name="windowTitle">
243 @@ -40,6 +40,36 @@
244      </widget>
245     </item>
246     <item>
247 +    <widget class="QCheckBox" name="showTrackCheckBox">
248 +     <property name="enabled">
249 +      <bool>false</bool>
250 +     </property>
251 +     <property name="text">
252 +      <string>Show Track</string>
253 +     </property>
254 +    </widget>
255 +   </item>
256 +   <item>
257 +    <widget class="QPushButton" name="saveTrackPushButton">
258 +     <property name="enabled">
259 +      <bool>false</bool>
260 +     </property>
261 +     <property name="text">
262 +      <string>Save Track</string>
263 +     </property>
264 +    </widget>
265 +   </item>
266 +   <item>
267 +    <widget class="QPushButton" name="clearTrackPushButton">
268 +     <property name="enabled">
269 +      <bool>false</bool>
270 +     </property>
271 +     <property name="text">
272 +      <string>Clear Track</string>
273 +     </property>
274 +    </widget>
275 +   </item>
276 +   <item>
277      <widget class="QLabel" name="locationLabel">
278       <property name="enabled">
279        <bool>false</bool>
280 @@ -65,6 +95,19 @@
281      </widget>
282     </item>
283     <item>
284 +    <spacer name="trackRecenterVerticalSpacer">
285 +     <property name="orientation">
286 +      <enum>Qt::Vertical</enum>
287 +     </property>
288 +     <property name="sizeHint" stdset="0">
289 +      <size>
290 +       <width>20</width>
291 +       <height>20</height>
292 +      </size>
293 +     </property>
294 +    </spacer>
295 +   </item>
296 +   <item>
297      <widget class="QLabel" name="recenterLabel">
298       <property name="enabled">
299        <bool>false</bool>
300 Index: marble-0.95+svn1213143/src/QtMainWindow.cpp
301 ===================================================================
302 --- marble-0.95+svn1213143.orig/src/QtMainWindow.cpp    2011-01-09 12:13:21.000000000 +0100
303 +++ marble-0.95+svn1213143/src/QtMainWindow.cpp 2011-01-09 12:13:42.000000000 +0100
304 @@ -41,6 +41,7 @@
305  #include <QtNetwork/QNetworkProxy>
306  
307  #include "BookmarkInfoDialog.h"
308 +#include "CurrentLocationWidget.h"
309  //#include "EditBookmarkDialog.h"
310  #include "MapViewWidget.h"
311  #include "MarbleDirs.h"
312 @@ -92,6 +93,7 @@
313          m_osmEditAction( 0 ),
314          m_mapViewDialog( 0 ),
315          m_routingDialog( 0 ),
316 +        m_trackingDialog( 0 ),
317          m_routingWidget( 0 )
318  {
319      setUpdatesEnabled( false );
320 @@ -298,6 +300,9 @@
321          m_toggleRoutingTabAction = menuBar()->addAction( tr( "Routing" ) );
322          connect( m_toggleRoutingTabAction, SIGNAL( triggered( bool ) ),
323                   this, SLOT( showRoutingDialog() ) );
324 +        m_showTrackingDialogAction = menuBar()->addAction( tr( "Tracking" ) );
325 +        connect( m_showTrackingDialogAction, SIGNAL( triggered()),
326 +                 this, SLOT( showTrackingDialog()) );
327  
328          m_controlView->marbleControl()->setNavigationTabShown( false );
329          m_controlView->marbleControl()->setLegendTabShown( false );
330 @@ -1268,6 +1273,28 @@
331      m_routingDialog->activateWindow();
332  }
333  
334 +void MainWindow::showTrackingDialog()
335 +{
336 +    if( !m_trackingDialog ) {
337 +        m_trackingDialog = new QDialog( this );
338 +        m_trackingDialog->setWindowTitle( tr( "Tracking - Marble" ) );
339 +        CurrentLocationWidget *trackingWidget = new CurrentLocationWidget( m_trackingDialog );
340 +        trackingWidget->setMarbleWidget( m_controlView->marbleWidget() );
341 +
342 +        QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok, Qt::Vertical, m_trackingDialog );
343 +        connect(buttonBox, SIGNAL( accepted() ), m_trackingDialog, SLOT( accept() ) );
344 +
345 +        QHBoxLayout* layout = new QHBoxLayout;
346 +        layout->addWidget( trackingWidget );
347 +        layout->addWidget( buttonBox );
348 +        m_trackingDialog->setLayout( layout );
349 +        m_trackingDialog->resize( 640, 420 );
350 +    }
351 +
352 +    m_trackingDialog->show();
353 +    m_trackingDialog->raise();
354 +    m_trackingDialog->activateWindow();
355 +}
356  
357  void MainWindow::updateMapEditButtonVisibility( const QString &mapTheme )
358  {
359 Index: marble-0.95+svn1213143/src/QtMainWindow.h
360 ===================================================================
361 --- marble-0.95+svn1213143.orig/src/QtMainWindow.h      2011-01-09 12:13:21.000000000 +0100
362 +++ marble-0.95+svn1213143/src/QtMainWindow.h   2011-01-09 12:13:42.000000000 +0100
363 @@ -120,6 +120,7 @@
364      void showMapViewDialog();
365      void showLegendTab( bool enabled );
366      void showRoutingDialog();
367 +    void showTrackingDialog();
368  
369   private:
370      void setupZoomButtons();
371 @@ -194,9 +195,11 @@
372      QAction *m_showMapViewDialogAction;
373      QAction *m_toggleLegendTabAction;
374      QAction *m_toggleRoutingTabAction;
375 +    QAction *m_showTrackingDialogAction;
376  
377      QDialog *m_mapViewDialog;
378      QDialog *m_routingDialog;
379 +    QDialog *m_trackingDialog;
380  
381      RoutingWidget *m_routingWidget;
382  };