コード例 #1
0
void CWintec::parseWayPoints(QByteArray data) {

	for(int pos = 0; pos < data.size(); pos += TrackPoint::size()) {
		//fwrite(data.mid(pos, TrackPoint::size()).data(), data.mid(pos, TrackPoint::size()).size(), 1, fd);
		TrackPoint* tp = dataToWayPoint(data.mid(pos, TrackPoint::size()));
		if(tp == 0) {
			continue;
		}

		if(tp->isLogPoint()) {
			emit newLogPoint(tp);
		}
		else {
			if(tp->isBeginOfTrack()) {
				if(m_tmp_track != 0) {
					m_tmp_track->commit();
					emit newTrack(m_tmp_track);
					qDebug() << QString("End of Track (%1 - %2 , %3 - %4)").arg(m_tmp_track->getMinLong()).arg(m_tmp_track->getMaxLong()).arg(m_tmp_track->getMinLat()).arg(m_tmp_track->getMaxLat());
				}
				m_tmp_track = new Track();
				//m_tmp_track->setIndex(trackindex);
				// trackindex++;
				//m_track_collection->append(track);
			}
			m_tmp_track->append(tp);
		}

	}
//	m_tmp_track->commit();
//	emit newTrack(m_tmp_track);

}
コード例 #2
0
void CWintec::createTrackpoints() {
	FILE* fd;
	Track* track = 0;
	fd = fopen("outfile2.tkraw", "wb");
    qDebug() << QString("createTrackpoints()");
    int trackindex = 0;

    // m_track_collection->clear();

	for(int pos = 0; pos < m_log_buf.size(); pos += TrackPoint::size()) {
		fwrite(m_log_buf.mid(pos, TrackPoint::size()).data(), m_log_buf.mid(pos, TrackPoint::size()).size(), 1, fd);
		TrackPoint* tp = new TrackPoint(m_log_buf.mid(pos, TrackPoint::size()));


		if(tp->isLogPoint()) {
			emit newLogPoint(tp);
		}
		else {
			if(tp->isBeginOfTrack()) {
				if(track != 0) {
					track->commit();
					emit newTrack(track);
					qDebug() << QString("End of Track (%1 - %2 , %3 - %4)").arg(track->getMinLong()).arg(track->getMaxLong()).arg(track->getMinLat()).arg(track->getMaxLat());
				}
				track = new Track();
				track->setIndex(trackindex);
				trackindex++;
				//m_track_collection->append(track);
			}
			track->append(tp);
		}

	}
	track->commit();
	emit newTrack(track);
//	m_track_view->setTrackColletcion(m_track_collection);
//	m_track_collection->commit();

//	ui.treeView->resizeColumnToContents(0);
//	ui.treeView->resizeColumnToContents(1);
//	ui.treeView->resizeColumnToContents(2);
//	ui.treeView->resizeColumnToContents(3);
//	fclose(fd);

//	m_track_view->update();
}
コード例 #3
0
ファイル: parser.cpp プロジェクト: maxvanceffer/pulsar
void Parser::libraryReply(QNetworkReply *reply)
{
    QString content;
    QTextCodec * codec = QTextCodec::codecForName("windows-1251");
    content = codec->toUnicode(reply->readAll());

    // Parsing AddHash(need for adding songs to your library)
    QString addHash;
    QRegExp rx("\"add_hash\":\"(.*)\"");
    rx.setMinimal(true);
    rx.indexIn(content);
    addHash = rx.capturedTexts()[1];

    // DeleteHash
    QString delHash;
    rx.setPattern("\"delete_hash\":\"(.*)\"");
    rx.indexIn(content);
    delHash = rx.capturedTexts()[1];

    // Tracks json
    QString data;
    rx.setPattern("\\{\"all\":(.*)\\}<!>");
    rx.indexIn(content);
    data = rx.capturedTexts()[1];

    if(data != "")
    {
        QScriptEngine engine;
        QScriptValue values;
        values = engine.evaluate(data);
        QScriptValue item;

        int i = 0;
        while(values.property(i).toString() != "") {
            item = values.property(i);

            Track *track = new Track(this);

            track->setArtist(trimXlam(item.property(5).toString()));
            track->setTitle(trimXlam(item.property(6).toString()));
            track->setDuration(item.property(4).toString());
            track->setUrl(item.property(2).toString());

            track->setAid(item.property(1).toString());
            track->setOid(item.property(0).toString());
            track->setHash(addHash);
            track->setDelHash(delHash);

            Q_EMIT newTrack(track);

            i++;
        }
    }
    Q_EMIT free();

    content.clear();
}
コード例 #4
0
ファイル: parser.cpp プロジェクト: maxvanceffer/pulsar
void Parser::suggestionsReply(QNetworkReply *reply)
{
    QString content;
    QTextCodec * codec = QTextCodec::codecForName("windows-1251");
    content = codec->toUnicode(reply->readAll());


    // Parsing AddHash(need for adding songs to your library)
    QString addHash;
    QRegExp rx("onclick=\"Audio\\.addShareAudio\\(this, [\\d]+, [\\d]+, '(.*)', 0\\)\\;\"");
    rx.setMinimal(true);
    rx.indexIn(content);
    addHash = rx.capturedTexts()[1];

    QString data;

    //QRegExp rx("\\{\"all\":(.*)\\}<!>");
    rx.setPattern("\\{\"all\":(.*)\\}<!>");
    rx.indexIn(content);
    data = rx.capturedTexts()[1];

    if(data != "")
    {
        QScriptEngine engine;
        QScriptValue values;
        values = engine.evaluate(data);
        QScriptValue item;

        int i = 0;
        while(values.property(i).toString() != "") {
            item = values.property(i);

            Track *track = new Track(this);

            track->setArtist(trimXlam(item.property(5).toString()));
            track->setTitle(trimXlam(item.property(6).toString()));
            track->setDuration(item.property(4).toString());
            track->setUrl(item.property(2).toString());

            track->setAid(item.property(1).toString());
            track->setOid(item.property(0).toString());
            track->setHash(addHash);

            Q_EMIT newTrack(track);

            i++;
        }
    }
    if(m_iOffset > 0)
        loadMoreResults();
    else
        Q_EMIT free();
}
コード例 #5
0
void CWintec::parseAL(QString line) {

    // expect the responses from the set to command mode state machine.
	// wait for LoginOK. If received, switchng to command mode was successful
	// and we can continue reading out data.

    QString expectstr("@AL,02,01");
    //qDebug() << QString("expecting line %1: %2").arg(m_command_response_step).arg(expectstr);
    if (expectstr.compare(line) == 0) {
			m_timer->stop();
            qDebug() << QString("got %1 proceeding... ").arg(expectstr);
            m_command_mode_step = 2;
            m_step_complete = true;
            return;
    }

    expectstr = QString("@AL,LoginOK");
    //qDebug() << QString("expecting line %1: %2").arg(m_command_response_step).arg(expectstr);
    if (expectstr.compare(line) == 0) {
			m_timer->stop();
            qDebug("got LoginOK, proceeding... ");
            m_command_mode_step = 3;
            m_step_complete = true;
            return;
    }


    // get device name (usually WBT201)
    expectstr = QString("@AL,07,01,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
		QString model = line.section(',', 3, 3);
        qDebug() << QString("model = %1").arg(model);
        m_dev_data->setDeviceName(model);
        m_command_mode_step = 4;
        m_step_complete = true;
        return;
    }

    // get device info
    expectstr = QString("@AL,07,02,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString info = line.section(',', 3, 3);
        qDebug() << QString("device info = %1.").arg(info);
        m_dev_data->setDeviceInfo(info);
        m_command_mode_step = 5;
        m_step_complete = true;
        return;
    }

    // get device serial No
    expectstr = QString("@AL,07,03,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString serial = line.section(',', 3, 3);
        qDebug() << QString("device serial No = %1.").arg(serial);
        m_dev_data->setDeviceSerial(serial);
        m_command_mode_step = 6;
        m_step_complete = true;
        return;
    }

    // get log start address
    expectstr = QString("@AL,05,01,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString log_start_str = line.section(',', 3, 3);
        long logstart = log_start_str.toLong();
        qDebug() << QString("Log start = %1. As int %2").arg(log_start_str).arg(logstart);
        m_dev_data->setLogStart(logstart);
        m_command_mode_step = 7;
        m_step_complete = true;
        if(m_dev_data->complete()) {
        	readLogMode();
        }
        return;
    }

    // get log end address
    expectstr = QString("@AL,05,02,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString log_end_str = line.section(',', 3, 3);
        long logend = log_end_str.toLong();
        qDebug() << QString("Log end = %1. As int %2").arg(log_end_str).arg(logend);
        m_dev_data->setLogEnd(logend);
        m_command_mode_step = 8;
        m_step_complete = true;
        if(m_dev_data->complete()) {
        	readLogMode();
        }
        return;
    }

    // get log area start address
    expectstr = QString("@AL,05,09,");
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString log_area_start_str = line.section(',', 3, 3);
        long logareastart = log_area_start_str.toLong();
        qDebug() << QString("Log area start = %1. As int %2").arg(log_area_start_str).arg(logareastart);
        m_dev_data->setLogAreaStart(logareastart);
        m_command_mode_step = 9;
        m_step_complete = true;
        if(m_dev_data->complete()) {
        	readLogMode();
        }
        return;
    }

    // get log area end address
    expectstr = QString("@AL,05,10,");
    //qDebug() << QString("expecting line %1: %2").arg(m_command_response_step).arg(expectstr);
    if (line.startsWith(expectstr)) {
		m_timer->stop();
        QString log_area_end_str = line.section(',', 3, 3);
        long logareaend = log_area_end_str.toLong();
        qDebug() << QString("Log area end = %1. As int %2").arg(log_area_end_str).arg(logareaend);
        m_dev_data->setLogAreaEnd(logareaend);
        m_command_mode_step = 10;
        m_step_complete = true;
        if(m_dev_data->complete()) {
        	readLogMode();
        }
        return;
    }

    // get checksum over received binary data
    expectstr = QString("@AL,CS,");
    //qDebug() << QString("expecting line %1: %2").arg(m_command_response_step).arg(expectstr);
    if (line.startsWith(expectstr)) {
        QString checksum_str = line.section(',', 2, 2);
        qDebug() << QString("checksum string = %1.").arg(checksum_str);
		m_timer->stop();
        if(!checksumCorrect(m_tmp_buf, checksum_str)) {
        	qDebug() << QString("Checksum error! Retrying %1").arg(m_retry_count);
        	m_retry_count--;
        	readLogData();
        	return;
        }
        m_log_buf.append(m_tmp_buf);
        m_retry_count = 5;

        parseWayPoints(m_tmp_buf);

        // make TrackPoints from m_tmp_buf here.
        //

        if(m_lastsection == 1 || m_tmp_buf.size() == 0) {
        	//createTrackpoints();
        	if(m_tmp_track != 0) {
        		m_tmp_track->commit();
        		emit newTrack(m_tmp_track);
        	}
        	emit readLogFinished();
        	leaveCommandMode();
            return;
        }

        int percent_done = m_read_start * 100
							/ (m_dev_data->getLogEnd() - m_dev_data->getLogStart());

        emit progress(percent_done);
        m_read_start += m_tmp_buf.size();

        readLogData();
        return;
    }

}
コード例 #6
0
ファイル: parser.cpp プロジェクト: maxvanceffer/pulsar
void Parser::searchReply(QNetworkReply *reply)
{
    QString content;
    QTextCodec * codec = QTextCodec::codecForName("windows-1251");
    content = codec->toUnicode(reply->readAll());

    content = trimXlam(content);

    int nextOffset = m_iOffset + 100;

    if(nextOffset < 1000) {
        QRegExp rx3("\"section\":\"audio\",\"has_more\":(true)");
        rx3.indexIn(content);
        if(rx3.capturedTexts()[1] != "") {
            m_morePossible = true;
        } else {
            m_morePossible = false;
        }
    } else {
        m_morePossible = false;
    }

    QRegExp rx("<div class=\"audio\" id=\"audio[\\d_]+\"([\\s\\S]*)?<div class=\"audio_add\"></div>");
    rx.setMinimal(true);
    int pos = 0;

    while (pos >= 0) {
        pos = rx.indexIn(content, pos);
        if (pos >= 0) {
            Track *track = new Track(this);

            // Artist
            QRegExp rx2("<b onclick=\"event.cancelBubble = true;\"><a href=.*>(.*)</a></b>");
            rx2.setMinimal(true);
            rx2.indexIn(rx.capturedTexts()[0]);

            track->setArtist(QString(rx2.capturedTexts()[1]).replace("<span class=\"match\">", "").replace("</span>",""));

            rx2.setPattern("<span class=\"title\".*>(.*)<span class=\"user\"");
            if(rx2.indexIn(rx.capturedTexts()[0]) > 0)
                track->setTitle(QString(rx2.capturedTexts()[1]).remove(QRegExp("<span class=\"match\">")).remove(QRegExp("</span>")).remove(QRegExp("<a href.*;\">")).remove(QRegExp("</a>")));

            // Duration
            rx2.setPattern("<input type=\"hidden\" id=\"audio_info[\\d_]+\" value=\".*,([\\d]*)\" />");
            rx2.indexIn(rx.capturedTexts()[0]);
            {
                    int t = QString(rx2.capturedTexts()[1]).toInt();
                    track->setDuration((t/60<10?"":"") + QString::number(t/60)+":"+((t%60)<10?"0":"")+QString::number(t%60));
                    track->setLenght(t);
  	    }

            // Link etc.
            rx2.setPattern("<input type=\"hidden\" id=\"audio_info[\\d_]+\" value=\"(.*),[\\d]*\" />");
            rx2.indexIn(rx.capturedTexts()[0]);

            track->setUrl(rx2.capturedTexts()[1]);

            // Opts for 'Add to library'
            rx2.setPattern("<a class=\"addAudioLink\" href=\"\" onclick=\"addAudio\\(this, \\{act:'a_add',add:1,gid:0,aid:(.*),oid:(.*),album_id:0,hash:'(.*)'\\}\\);return false;\">");
            rx2.indexIn(rx.capturedTexts()[0]);

            track->setAid(rx2.capturedTexts()[1]);
            track->setOid(rx2.capturedTexts()[2]);
            track->setHash(rx2.capturedTexts()[3]);

            pos += rx.matchedLength();

            QString tStr = track->artist() + track->title() + track->lenght();
            tStr.remove(QRegExp("[ ?!:_+]+", Qt::CaseInsensitive));

            // Don't send duplicates to playlist
            if(!m_TrackStrings.contains(tStr, Qt::CaseInsensitive)) {
                Q_EMIT newTrack(track);
                m_TrackStrings.append(tStr);
            } else {
                track->deleteLater();
            }
        }
    }
    content.clear();
    reply->deleteLater();

    if(m_iOffset > 0)
        loadMoreResults();
    else
        Q_EMIT free();

}
コード例 #7
0
ファイル: editor.cpp プロジェクト: CruzR/stk-editor
// ----------------------------------------------------------------------------
bool Editor::importantButtonClicked(int ID)
{
    stringc s;
    switch (ID)
    {
        // ToolBar buttons
    case ToolBar::TBI_EXIT:
        m_msg_wndw->showMsg(_(L"Do you really want to quit?\n"
                            L"Any unsaved progress will be lost!"), true, true);
        return true;
    case ToolBar::TBI_NEW:
        if (m_viewport) m_viewport->lock();
        m_new_dialog_wndw->show();
        return true;
    case WelcomeScreen::FBTN_ID + 1:
        m_welcome_screen->hide();
    case ToolBar::TBI_OPEN:
        m_new_dialog_wndw->hide();
        m_gui_env->addFileOpenDialog(L"Open track:", true, 0, -1, true, m_maps_path);
        if (m_viewport) m_viewport->lock();
        return true;
        // WELCOME SCREEN
    case WelcomeScreen::FBTN_ID:
        s = m_welcome_screen->getActiveText();
        if (s != "")
        {
            if (open(path(m_maps_path) + "/" + m_welcome_screen->getActiveText()))
                m_welcome_screen->hide();
        }
        return true;
    case WelcomeScreen::FBTN_ID + 2:
        m_welcome_screen->hide();
        m_new_dialog_wndw->show();
        return true;
    case NewDialogWndw::BTN_ID:
        newTrack();
    case NewDialogWndw::BTN_ID+1:
        m_new_dialog_wndw->hide();
        return true;
    case MsgWndw::OK_BTN_ID:
        m_msg_wndw->buttonClicked();
        return true;
    case MsgWndw::CA_BTN_ID:
        m_msg_wndw->buttonClicked(true);
        return true;
    case RoadCrossSectionWndw::OK:
        m_viewport->switchRoadCrossSectionMode(true);
        return true;
    case RoadCrossSectionWndw::CANCEL:
        m_viewport->switchRoadCrossSectionMode(false);
        return true;
    case RoadCrossSectionWndw::POINT_M:
    case RoadCrossSectionWndw::POINT_P:
        m_viewport->clearSelection();
    case RoadCrossSectionWndw::GRID_ON_OFF:
    case RoadCrossSectionWndw::GRID_M:
    case RoadCrossSectionWndw::GRID_P:
    case RoadCrossSectionWndw::SYM_ON_OFF:
        m_rcs->buttonClicked(ID);
        return true;
    }
    return false;
} // importantButtonClicked
コード例 #8
0
AssemblyMainWindow::AssemblyMainWindow(QWidget *parent) :
	QMainWindow( parent )
,	mpTrack( 0 )
,	mCurrentTerrainBrush( 0 )
,	ui( new Ui::AssemblyMainWindow )
,	trackView( new TrackView() )
{	
	trackView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
	trackView->setMinimumSize( 100, 100 );

	ui->setupUi(this);
	QGridLayout* container_layout = new QGridLayout( ui->viewContainer );
	//((QGridLayout*) ui->CentralFrame->layout())->addWidget( trackView, 1, 1 );

	container_layout->setContentsMargins( 0, 0, 0, 0 );
	container_layout->setSpacing( 0 );

	container_layout->addWidget( trackView, 0, 0 );

	// konfiguruje suwaki:
	ui->horizontalScrollBar->setSingleStep( 5 );
	ui->horizontalScrollBar->setPageStep( 20 );
	ui->horizontalScrollBar->setMinimum( 0 );


	ui->verticalScrollBar->setSingleStep( 5 );
	ui->verticalScrollBar->setPageStep( 20 );
	ui->verticalScrollBar->setMinimum( 0 );

	// status bar:
	connect( trackView, SIGNAL(showTip(QString)), ui->statusBar, SLOT(showMessage(QString)) );
	connect( trackView, SIGNAL(removeTip()), ui->statusBar, SLOT(clearMessage()) );

	// zakresy:
	connect( trackView, SIGNAL(horizontalSliderRangeChanged(int)), this, SLOT(setHorizontalSliderMaximum(int)) );
	connect( trackView, SIGNAL(verticalSliderRangeChanged(int)), this, SLOT(setVerticalSliderMaximum(int)) );

	// wlaczanie i wylaczanie scrollbarow:
	connect( trackView, SIGNAL(horizontalSliderEnabled(bool)), ui->horizontalScrollBar, SLOT(setEnabled(bool)));
	connect( trackView, SIGNAL(verticalSliderEnabled(bool)), ui->verticalScrollBar, SLOT(setEnabled(bool)));

	// sprzezenie zwrotne scrollbarow do TrackView:
	connect( ui->horizontalScrollBar, SIGNAL(valueChanged(int)), trackView, SLOT(setHorizontalPosition(int)) );
	connect( ui->verticalScrollBar, SIGNAL(valueChanged(int)), trackView, SLOT(setVerticalPosition(int)) );

	// guzik wczytywania obrazkow:
	connect( ui->loadImageButton, SIGNAL(clicked()), this, SLOT(loadImage()) );

	// taby:
	connect( ui->tabWidget, SIGNAL(currentChanged(int)), trackView, SLOT(setMode(int)) );
	connect( ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(prepareTab(int)) );

	// siatka:
	connect( ui->gridSlider, SIGNAL(valueChanged(int)), this, SLOT(setGridDensity(int)) );

	// menu:
	connect( ui->actionNewTrack, SIGNAL(triggered()), this, SLOT(newTrack()) );
	connect( ui->actionOpen, SIGNAL(triggered()), this, SLOT(openTrack()) );
	connect( ui->actionSave, SIGNAL(triggered()), this, SLOT(saveTrack()) );
	connect( ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(saveTrackAs()) );
	connect( ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) );
	connect( ui->actionDrawGrid, SIGNAL(toggled(bool)), trackView, SLOT(drawGrid(bool)) );

	// zakladka terenu:
	connect( ui->comboTerrainBrushType, SIGNAL(currentIndexChanged(int)), this, SLOT(terrainChangeBrush(int)) );
	connect( ui->comboTerrainBrushType, SIGNAL(currentIndexChanged(int)), trackView, SLOT(setBrushId(int)) );
	connect( ui->sliderTerrainBrushSize, SIGNAL(valueChanged(int)), trackView, SLOT(setBrushSize(int)) );
	connect( ui->sliderTerrainIntensity, SIGNAL(valueChanged(int)), trackView, SLOT(setBrushIntensity(int)) );
	connect( ui->sliderTerrainBrushSize, SIGNAL(valueChanged(int)),ui->lineTerrainBrushSize,SLOT(setValue(int)) );
	connect( ui->sliderTerrainIntensity, SIGNAL(valueChanged(int)),ui->lineTerrainIntensity,SLOT(setValue(int)) );

	// koncowa inicjalizacja...
	disableMenus();
}