Subversion Repositories public

Rev

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

Rev 137 Rev 143
Line 31... Line 31...
31
 
31
 
32
using std::cout;
32
using std::cout;
33
using std::endl;
33
using std::endl;
34
 
34
 
35
extern KApplication *mapp;
35
extern KApplication *mapp;
-
 
36
progressWidget *me;
36
 
37
 
37
progressWidget::progressWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
38
progressWidget::progressWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
38
		: progressWidgetBase ( parent,name, modal,fl )
39
		: progressWidgetBase ( parent,name, modal,fl )
39
{
40
{
-
 
41
	step = 0;
-
 
42
	psteps = 7;
-
 
43
	me = this;
40
}
44
}
41
 
45
 
42
progressWidget::~progressWidget()
46
progressWidget::~progressWidget()
43
{
47
{
-
 
48
	me = 0;
44
}
49
}
45
 
50
 
-
 
51
/*
-
 
52
 * This function is called from the Garmin library libgarmin.a during
-
 
53
 * reading data from a GPS device.
-
 
54
 */
46
void progressWidget::CallBack(char *str)
55
void progressWidget::CallBack(char *str)
47
{
56
{
-
 
57
	if (me)
-
 
58
	   me->IncrementBar();
-
 
59
}
-
 
60
 
-
 
61
void progressWidget::IncrementBar()
-
 
62
{
-
 
63
	step++;
-
 
64
 
-
 
65
	if (psteps <= step)
-
 
66
	{
-
 
67
	   psteps += 2;
48
cout << "I'm here :-) <" << str << ">" << endl;
68
	   barProgress->setTotalSteps(psteps);
-
 
69
	}
-
 
70
 
-
 
71
	barProgress->setProgress(step);
49
}
72
}
50
 
73
 
51
/*$SPECIALIZATION$*/
74
/*$SPECIALIZATION$*/
-
 
75
/*
-
 
76
 * The following function reads out all data from a GPS device. It uses
-
 
77
 * the library libgarmin.a, who is basicly the "garmintools-0.5", written by
-
 
78
 * Dave Bailey (thanks Dave!).
-
 
79
 */
52
bool progressWidget::Download()
80
bool progressWidget::Download()
53
{
81
{
54
QString Data, filepath, device;
82
QString Data, filepath, device;
55
int step, psteps = 4;
-
 
56
garmin_unit         garmin;
83
garmin_unit         garmin;
57
garmin_data *       data;
84
garmin_data *       data;
58
garmin_data *       data0;
85
garmin_data *       data0;
59
garmin_data *       data1;
86
garmin_data *       data1;
60
garmin_data *       data2;
87
garmin_data *       data2;
Line 90... Line 117...
90
	}
117
	}
91
 
118
 
92
	if (!isVisible())
119
	if (!isVisible())
93
	   setShown(true);
120
	   setShown(true);
94
 
121
 
-
 
122
	barProgress->setTotalSteps(psteps);
-
 
123
	step = 0;
95
	garmin_set_device(device.ascii());
124
	garmin_set_device(device.ascii());
96
	garmin_set_method(0);		// Setting to 1 doesn't work!!
125
	garmin_set_method(0);		// Setting to 1 doesn't work!! (reading over garmin_gps kernel module)
97
	// Initialize a callback function to have a real progress
126
	// Initialize a callback function to have a real progress bar
98
	garmin_set_hook(&progressWidget::CallBack);
127
	garmin_set_hook(&progressWidget::CallBack);
-
 
128
	lblInfo->setText(i18n("Looking for a Garmin GPS device..."));
99
 
129
 
100
	if (garmin_init(&garmin, 0) == 0)
130
	if (garmin_init(&garmin, 0) == 0)
101
	{
131
	{
102
	   garmin_close(&garmin);
132
	   garmin_close(&garmin);
103
	   garmin_clear_hook();
133
	   garmin_clear_hook();
104
//	   done(QDialog::Rejected);
-
 
105
	   return false;
134
	   return false;
106
	}
135
	}
107
 
136
 
108
	barProgress->setTotalSteps(5);
-
 
109
	step = 0;
-
 
110
	barProgress->setProgress(step++);
137
	barProgress->setProgress(++step);
111
	lblInfo->setText(i18n("Extracting data from Garmin <i>") + QString(garmin.product.product_description) + QString("</i>"));
138
	lblInfo->setText(i18n("Extracting data from Garmin <i>") + QString(garmin.product.product_description) + QString("</i>"));
112
	lblReading->setText(i18n("Please wait, this may take some time!"));
139
	lblReading->setText(i18n("Please wait, this may take some time!"));
113
 
140
 
114
	mapp->processEvents();
141
	mapp->processEvents();
115
 
142
 
Line 121... Line 148...
121
	    * 1) The runs (which identify the track and lap indices)
148
	    * 1) The runs (which identify the track and lap indices)
122
	    * 2) The laps (which are related to the runs)
149
	    * 2) The laps (which are related to the runs)
123
	    * 3) The tracks (which are related to the runs)
150
	    * 3) The tracks (which are related to the runs)
124
	    */
151
	    */
125
 
152
 
126
	   barProgress->setProgress(step++);
153
	   barProgress->setProgress(++step);
127
	   lblReading->setText(i18n("Sorting out runs ..."));
154
	   lblReading->setText(i18n("Sorting out runs ..."));
128
	   mapp->processEvents();
155
	   mapp->processEvents();
129
	   data0 = garmin_list_data(data, 0);
156
	   data0 = garmin_list_data(data, 0);
130
	   barProgress->setProgress(step++);
157
	   barProgress->setProgress(++step);
131
	   lblReading->setText(i18n("Sorting out laps ..."));
158
	   lblReading->setText(i18n("Sorting out laps ..."));
132
	   mapp->processEvents();
159
	   mapp->processEvents();
133
	   data1 = garmin_list_data(data, 1);
160
	   data1 = garmin_list_data(data, 1);
134
	   barProgress->setProgress(step++);
161
	   barProgress->setProgress(++step);
135
	   lblReading->setText(i18n("Sorting out tracks ..."));
162
	   lblReading->setText(i18n("Sorting out tracks ..."));
136
	   mapp->processEvents();
163
	   mapp->processEvents();
137
	   data2 = garmin_list_data(data, 2);
164
	   data2 = garmin_list_data(data, 2);
138
	   barProgress->setProgress(step++);
165
	   barProgress->setProgress(++step);
139
	   lblReading->setText(i18n("Sorting out data blocks done."));
166
	   lblReading->setText(i18n("Sorting out data blocks done."));
140
	   mapp->processEvents();
167
	   mapp->processEvents();
141
 
168
 
142
	   if ( data0 != NULL && (runs   = (garmin_list *)data0->data) != NULL &&
169
	   if ( data0 != NULL && (runs   = (garmin_list *)data0->data) != NULL &&
143
		data1 != NULL && (laps   = (garmin_list *)data1->data) != NULL &&
170
		data1 != NULL && (laps   = (garmin_list *)data1->data) != NULL &&
Line 152... Line 179...
152
	      barProgress->setTotalSteps(psteps);
179
	      barProgress->setTotalSteps(psteps);
153
	      mapp->processEvents();
180
	      mapp->processEvents();
154
 
181
 
155
	      for (n = runs->head; n != NULL; n = n->next)
182
	      for (n = runs->head; n != NULL; n = n->next)
156
	      {
183
	      {
157
		 barProgress->setProgress(step++);
184
		 barProgress->setProgress(++step);
158
		 mapp->processEvents();
185
		 mapp->processEvents();
159
 
186
 
160
		 if (get_run_track_lap_info(n->data, &trk, &f_lap, &l_lap) != 0)
187
		 if (get_run_track_lap_info(n->data, &trk, &f_lap, &l_lap) != 0)
161
		 {
188
		 {
162
		    lblReading->setText(i18n("Running: track ") + QString("%1, ").arg(trk) + i18n("laps ") + QString("%1:%1").arg(f_lap).arg(l_lap));
189
		    lblReading->setText(i18n("Running: track ") + QString("%1, ").arg(trk) + i18n("laps ") + QString("%1:%1").arg(f_lap).arg(l_lap));
Line 170... Line 197...
170
		    {
197
		    {
171
		       if (get_lap_index(m->data, &l_idx) != 0)
198
		       if (get_lap_index(m->data, &l_idx) != 0)
172
		       {
199
		       {
173
			  if ( l_idx >= f_lap && l_idx <= l_lap )
200
			  if ( l_idx >= f_lap && l_idx <= l_lap )
174
			  {
201
			  {
175
/*		             if ( garmin->verbose != 0 )
-
 
176
			     {
-
 
177
			        printf("[garmin] lap [%d] falls within laps [%d:%d]\n",
-
 
178
			        l_idx,f_lap,l_lap);
-
 
179
			     }
-
 
180
*/
-
 
181
			     garmin_list_append((garmin_list *)rlaps->data, m->data);
202
			     garmin_list_append((garmin_list *)rlaps->data, m->data);
182
 
203
 
183
			     if ( l_idx == f_lap )
204
			     if ( l_idx == f_lap )
184
			     {
-
 
185
			        get_lap_start_time(m->data, &start);
205
			        get_lap_start_time(m->data, &start);
186
 
-
 
187
/*			        if (garmin->verbose != 0)
-
 
188
				{
-
 
189
				   printf("[garmin] first lap [%d] has start time [%d]\n",
-
 
190
				   l_idx,(int)start);
-
 
191
				} */
-
 
192
			     }
-
 
193
			  }
206
			  }
194
		       }
207
		       }
195
		    }
208
		    }
196
 
209
 
197
		    /* Get the track points. */
210
		    /* Get the track points. */
Line 215... Line 228...
215
			  Data.ascii(), tbuf->tm_year+1900, tbuf->tm_mon + 1);
228
			  Data.ascii(), tbuf->tm_year+1900, tbuf->tm_mon + 1);
216
		       strftime(filename, sizeof(filename), "%Y%m%dT%H%M%S.gmn", tbuf);
229
		       strftime(filename, sizeof(filename), "%Y%m%dT%H%M%S.gmn", tbuf);
217
 
230
 
218
		       /* Save rlist to the file. */
231
		       /* Save rlist to the file. */
219
		       garmin_save(rlist, filename, filepath.ascii());
232
		       garmin_save(rlist, filename, filepath.ascii());
220
		       lblReading->setText(i18n("Saved file ") + QString(filename));
233
		       lblReading->setText(i18n("Saved file ") + QString(filename) + i18n(" successfully."));
221
		       mapp->processEvents();
234
		       mapp->processEvents();
222
		    }
235
		    }
223
/*	            else
236
	            else
224
		    {
-
 
225
		       printf("Start time of first lap not found!\n");
237
		       KMessageBox::error(this, i18n("Start time of first lap not found!"));
226
		    }
-
 
227
*/
238
 
228
		    /* Free the temporary lists we were using. */
239
		    /* Free the temporary lists we were using. */
229
 
240
 
230
		    if (rlaps != NULL)
241
		    if (rlaps != NULL)
231
		    {
242
		    {
232
		       garmin_free_list_only((garmin_list *)rlaps->data);
243
		       garmin_free_list_only((garmin_list *)rlaps->data);
Line 271... Line 282...
271
	   KMessageBox::error(this, i18n("Unable to extract any data!"));
282
	   KMessageBox::error(this, i18n("Unable to extract any data!"));
272
 
283
 
273
	mapp->processEvents();
284
	mapp->processEvents();
274
	garmin_close(&garmin);
285
	garmin_close(&garmin);
275
	garmin_clear_hook();
286
	garmin_clear_hook();
276
//	done(QDialog::Accepted);
-
 
277
 
287
 
278
	if (garmin_count_error() > 0)
288
	if (garmin_count_error() > 0)
279
	   return false;
289
	   return false;
280
 
290
 
281
	return true;
291
	return true;