Subversion Repositories public

Rev

Rev 119 | Rev 137 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 119 Rev 132
Line 17... Line 17...
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
18
 ***************************************************************************/
19
 
19
 
20
 
20
 
21
#include "progresswidget.h"
21
#include "progresswidget.h"
-
 
22
#include <kapplication.h>
22
#include <kprogress.h>
23
#include <kprogress.h>
23
#include <kmessagebox.h>
24
#include <kmessagebox.h>
24
#include <ksimpleconfig.h>
25
#include <ksimpleconfig.h>
25
#include <klocale.h>
26
#include <klocale.h>
26
#include <qlabel.h>
27
#include <qlabel.h>
27
#include "garmin.h"
28
#include "garmin.h"
28
 
29
 
-
 
30
#include <iostream.h>
-
 
31
 
-
 
32
extern KApplication *mapp;
-
 
33
 
29
progressWidget::progressWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
34
progressWidget::progressWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
30
		: progressWidgetBase ( parent,name, modal,fl )
35
		: progressWidgetBase ( parent,name, modal,fl )
31
{
36
{
32
}
37
}
33
 
38
 
Line 75... Line 80...
75
	   done(QDialog::Rejected);
80
	   done(QDialog::Rejected);
76
	   return;
81
	   return;
77
	}
82
	}
78
 
83
 
79
	if (!isVisible())
84
	if (!isVisible())
80
	   QWidget::show();
85
	   setShown(true);
81
 
86
 
82
	garmin_set_device(device.ascii());
87
	garmin_set_device(device.ascii());
83
	garmin_set_method(0);		// read from a special device produced by "gamin_gps"
88
	garmin_set_method(0);		// read from a special device produced by "gamin_gps"
84
 
89
 
85
	if (garmin_init(&garmin, 0) == 0)
90
	if (garmin_init(&garmin, 0) == 0)
Line 91... Line 96...
91
	}
96
	}
92
 
97
 
93
	barProgress->setTotalSteps(5);
98
	barProgress->setTotalSteps(5);
94
	step = 0;
99
	step = 0;
95
	barProgress->setProgress(step++);
100
	barProgress->setProgress(step++);
96
	lblInfo->setText(i18n("Extracting data from Garmin <i>") + QString(garmin.product.product_description) + QString("</b>"));
101
	lblInfo->setText(i18n("Extracting data from Garmin <i>") + QString(garmin.product.product_description) + QString("</i>"));
-
 
102
	lblReading->setText(i18n("Please wait, this may take some time!"));
-
 
103
 
-
 
104
	mapp->processEvents();
97
 
105
 
98
	if ((data = garmin_get(&garmin, GET_RUNS)) != NULL )
106
	if ((data = garmin_get(&garmin, GET_RUNS)) != NULL )
99
	{
107
	{
100
	   /*
108
	   /*
101
	    * We should have a list with three elements:
109
	    * We should have a list with three elements:
Line 104... Line 112...
104
	    * 2) The laps (which are related to the runs)
112
	    * 2) The laps (which are related to the runs)
105
	    * 3) The tracks (which are related to the runs)
113
	    * 3) The tracks (which are related to the runs)
106
	    */
114
	    */
107
 
115
 
108
	   barProgress->setProgress(step++);
116
	   barProgress->setProgress(step++);
-
 
117
	   lblReading->setText(i18n("Sorting out runs ..."));
-
 
118
	   mapp->processEvents();
109
	   data0 = garmin_list_data(data, 0);
119
	   data0 = garmin_list_data(data, 0);
110
	   barProgress->setProgress(step++);
120
	   barProgress->setProgress(step++);
-
 
121
	   lblReading->setText(i18n("Sorting out laps ..."));
-
 
122
	   mapp->processEvents();
111
	   data1 = garmin_list_data(data, 1);
123
	   data1 = garmin_list_data(data, 1);
112
	   barProgress->setProgress(step++);
124
	   barProgress->setProgress(step++);
-
 
125
	   lblReading->setText(i18n("Sorting out tracks ..."));
-
 
126
	   mapp->processEvents();
113
	   data2 = garmin_list_data(data, 2);
127
	   data2 = garmin_list_data(data, 2);
114
	   barProgress->setProgress(step++);
128
	   barProgress->setProgress(step++);
-
 
129
	   lblReading->setText(i18n("Sorting out data blocks done."));
-
 
130
	   mapp->processEvents();
115
 
131
 
116
	   if ( data0 != NULL && (runs   = (garmin_list *)data0->data) != NULL &&
132
	   if ( data0 != NULL && (runs   = (garmin_list *)data0->data) != NULL &&
117
		data1 != NULL && (laps   = (garmin_list *)data1->data) != NULL &&
133
		data1 != NULL && (laps   = (garmin_list *)data1->data) != NULL &&
118
		data2 != NULL && (tracks = (garmin_list *)data2->data) != NULL )
134
		data2 != NULL && (tracks = (garmin_list *)data2->data) != NULL )
119
	   {
135
	   {
Line 122... Line 138...
122
	      /* But first see how much runs to set the progress bar */
138
	      /* But first see how much runs to set the progress bar */
123
	      for (n = runs->head; n != NULL; n = n->next)
139
	      for (n = runs->head; n != NULL; n = n->next)
124
		 psteps++;
140
		 psteps++;
125
	
141
	
126
	      barProgress->setTotalSteps(psteps);
142
	      barProgress->setTotalSteps(psteps);
-
 
143
	      mapp->processEvents();
127
 
144
 
128
	      for (n = runs->head; n != NULL; n = n->next)
145
	      for (n = runs->head; n != NULL; n = n->next)
129
	      {
146
	      {
130
		 barProgress->setProgress(step++);
147
		 barProgress->setProgress(step++);
-
 
148
		 mapp->processEvents();
131
 
149
 
132
		 if (get_run_track_lap_info(n->data, &trk, &f_lap, &l_lap) != 0)
150
		 if (get_run_track_lap_info(n->data, &trk, &f_lap, &l_lap) != 0)
133
		 {
151
		 {
134
		    lblReading->setText(i18n("Running: track ") + QString("%1, ").arg(trk) + i18n("laps ") + QString("%1:%1").arg(f_lap).arg(l_lap));
152
		    lblReading->setText(i18n("Running: track ") + QString("%1, ").arg(trk) + i18n("laps ") + QString("%1:%1").arg(f_lap).arg(l_lap));
135
 
-
 
-
 
153
		    mapp->processEvents();
136
		    start = 0;
154
		    start = 0;
137
 
155
 
138
		    /* Get the laps. */
156
		    /* Get the laps. */
139
		    rlaps = garmin_alloc_data(data_Dlist);
157
		    rlaps = garmin_alloc_data(data_Dlist);
140
 
158
 
Line 187... Line 205...
187
			  Data.ascii(), tbuf->tm_year+1900, tbuf->tm_mon + 1);
205
			  Data.ascii(), tbuf->tm_year+1900, tbuf->tm_mon + 1);
188
		       strftime(filename, sizeof(filename), "%Y%m%dT%H%M%S.gmn", tbuf);
206
		       strftime(filename, sizeof(filename), "%Y%m%dT%H%M%S.gmn", tbuf);
189
 
207
 
190
		       /* Save rlist to the file. */
208
		       /* Save rlist to the file. */
191
		       garmin_save(rlist, filename, filepath.ascii());
209
		       garmin_save(rlist, filename, filepath.ascii());
-
 
210
		       lblReading->setText(i18n("Saved file ") + QString(filename));
-
 
211
		       mapp->processEvents();
192
		    }
212
		    }
193
/*	            else
213
/*	            else
194
		    {
214
		    {
195
		       printf("Start time of first lap not found!\n");
215
		       printf("Start time of first lap not found!\n");
196
		    }
216
		    }
Line 238... Line 258...
238
	   garmin_free_data(data);
258
	   garmin_free_data(data);
239
	}
259
	}
240
	else
260
	else
241
	   KMessageBox::error(this, i18n("Unable to extract any data!"));
261
	   KMessageBox::error(this, i18n("Unable to extract any data!"));
242
 
262
 
-
 
263
	mapp->processEvents();
243
	garmin_close(&garmin);
264
	garmin_close(&garmin);
244
	done(QDialog::Accepted);
265
	done(QDialog::Accepted);
245
}
266
}
246
 
267
 
247
int progressWidget::get_run_track_lap_info ( garmin_data * run,
268
int progressWidget::get_run_track_lap_info ( garmin_data * run,
Line 273... Line 294...
273
    *track_index     = d1010->track_index;
294
    *track_index     = d1010->track_index;
274
    *first_lap_index = d1010->first_lap_index;
295
    *first_lap_index = d1010->first_lap_index;
275
    *last_lap_index  = d1010->last_lap_index;
296
    *last_lap_index  = d1010->last_lap_index;
276
    break;
297
    break;
277
  default:
298
  default:
278
    printf("get_run_track_lap_info: run type %d invalid!\n",run->type);
299
    fprintf(stderr, "get_run_track_lap_info: run type %d invalid!\n",run->type);
279
    ok = 0;
300
    ok = 0;
280
    break;
301
    break;
281
  }
302
  }
282
 
303
 
283
  return ok;
304
  return ok;
Line 334... Line 355...
334
  case data_D1015:
355
  case data_D1015:
335
    d1015       = (D1015 *)lap->data;
356
    d1015       = (D1015 *)lap->data;
336
    *start_time = d1015->start_time + TIME_OFFSET;
357
    *start_time = d1015->start_time + TIME_OFFSET;
337
    break;
358
    break;
338
  default:
359
  default:
339
    printf("get_lap_start_time: lap type %d invalid!\n",lap->type);
360
    fprintf(stderr, "get_lap_start_time: lap type %d invalid!\n",lap->type);
340
    ok = 0;
361
    ok = 0;
341
    break;
362
    break;
342
  }
363
  }
343
 
364
 
344
  return ok;
365
  return ok;
Line 377... Line 398...
377
	if ( track != NULL ) {
398
	if ( track != NULL ) {
378
	  garmin_list_append((garmin_list *)track->data,n->data);
399
	  garmin_list_append((garmin_list *)track->data,n->data);
379
	}
400
	}
380
	break;
401
	break;
381
      default:
402
      default:
382
	printf("get_track: point type %d invalid!\n",n->data->type);
403
	fprintf(stderr, "get_track: point type %d invalid!\n",n->data->type);
383
	break;
404
	break;
384
      }
405
      }
385
    }
406
    }
386
 
407
 
387
    if ( done != 0 ) break;
408
    if ( done != 0 ) break;