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