Ejemplo n.º 1
0
void Radio::openLink()
{
	QListWidgetItem *lWI = lW->currentItem();
	if (lWI)
	{
		if (lWI == nowaStacjaLWI)
		{
			const QString newStation = tr("Adding a new radio station");
			QString nazwa, adres;
			bool ok;
			nazwa = QInputDialog::getText(this, newStation, tr("Name"), QLineEdit::Normal, QString(), &ok);
			if (ok && !nazwa.isEmpty())
			{
				adres = QInputDialog::getText(this, newStation, tr("Address"), QLineEdit::Normal, "http://", &ok);
				if (ok && !adres.isEmpty() && adres != "http://")
					addStation(nazwa, adres, wlasneStacje);
			}
		}
		else
		{
			const QString url = lWI->data(Qt::UserRole).toString();
			if (!url.isEmpty())
				emit QMPlay2Core.processParam("open", url);
		}
	}
}
Ejemplo n.º 2
0
void Radio::finished()
{
	QNetworkReply *netReply = (QNetworkReply *)sender();
	bool err = false;
	if (!netReply->error())
	{
		progressB->deleteLater();
		progressB = NULL;
		QByteArray RadioList = netReply->readAll();
		if (RadioList.left(4) != "NXRL")
			err = true;
		else
		{
			int separators = 0;
			QString GroupName;
			while (RadioList.size())
			{
				if (RadioList.left(4) == "NXRL")
				{
					RadioList.remove(0, 4);
					GroupName = RadioList.data();
					RadioList.remove(0, GroupName.toUtf8().length() + 1);
					addGroup(GroupName);
					++separators;
				}

				QString nazwa = RadioList.data();
				RadioList.remove(0, nazwa.toUtf8().length() + 1);
				QString URL = RadioList.data();
				RadioList.remove(0, URL.toUtf8().length() + 1);
				int imgSize = *(const int *)RadioList.constData();
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
				quint8 *imgSizeArr = (quint8 *)&imgSize;
				imgSize = imgSizeArr[0] << 24 | imgSizeArr[1] << 16 | imgSizeArr[2] << 8 | imgSizeArr[3];
#endif
				RadioList.remove(0, sizeof(int));
				QByteArray img = RadioList.mid(0, imgSize);
				RadioList.remove(0, imgSize);
				addStation(nazwa, URL, GroupName, img);
			}

			infoL->setText(tr("Number of radio stations") + ": " + QString::number(lW->count() - separators));
		}
	}
	else
		err = true;
	if (err)
	{
		infoL->setText(tr("Error while downloading list"));
		progressB->hide();
		once = false;
	}
	netReply->deleteLater();
	net->deleteLater();
	net = NULL;
}
Ejemplo n.º 3
0
Radio::Radio(Module &module) :
	once(false), net(NULL),
	qmp2Icon(QMPlay2Core.getQMPlay2Pixmap()),
	wlasneStacje(tr("Own radio stations"))
{
	SetModule(module);

	setContextMenuPolicy(Qt::CustomContextMenu);
	popupMenu.addAction(tr("Remove the radio station"), this, SLOT(removeStation()));

	dw = new DockWidget;
	dw->setWindowTitle(tr("Internet radios"));
	dw->setObjectName(RadioName);
	dw->setWidget(this);

	lW = new QListWidget;
	connect(lW, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(openLink()));
	lW->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
	lW->setResizeMode(QListView::Adjust);
	lW->setWrapping(true);
	lW->setIconSize(QSize(32, 32));

	QAction *act = new QAction(lW);
	act->setShortcuts(QList<QKeySequence>() << QKeySequence("Return") << QKeySequence("Enter"));
	connect(act, SIGNAL(triggered()), this, SLOT(openLink()));
	act->setShortcutContext(Qt::WidgetWithChildrenShortcut);
	lW->addAction(act);

	infoL = new QLabel;

	progressB = new QProgressBar;

	QVBoxLayout *layout = new QVBoxLayout(this);
	layout->addWidget(lW);
	layout->addWidget(infoL);
	layout->addWidget(progressB);

	progressB->hide();

	connect(dw, SIGNAL(visibilityChanged(bool)), this, SLOT(visibilityChanged(bool)));
	connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(popup(const QPoint &)));

	addGroup(wlasneStacje);
	nowaStacjaLWI = new QListWidgetItem("-- " + tr("Add new radio station") + " --", lW);
	nowaStacjaLWI->setData(Qt::TextAlignmentRole, Qt::AlignCenter);

	Settings sets("Radio");
	foreach (const QString &entry, sets.get("Radia").toStringList())
	{
		const QStringList nazwa_i_adres = entry.split('\n');
		if (nazwa_i_adres.count() == 2)
			addStation(nazwa_i_adres[0], nazwa_i_adres[1], wlasneStacje);
	}
}
Ejemplo n.º 4
0
int transect_readParams(int* count, char* tok[], int ntoks)
//
//  Input:   count = transect index
//           tok[] = array of string tokens
//           ntoks = number of tokens
//  Output:  updated value of count,
//           returns an error code
//  Purpose: read parameters of a transect from a tokenized line of input data.
//
//  Format of transect data follows that used for HEC-2 program:
//    NC  nLeft  nRight  nChannel
//    X1  name  nSta  xLeftBank  xRightBank  0  0  0  xFactor  yFactor
//    GR  Elevation  Station  ... 
//
{
    int    i, k;
    int    index = *count;             // transect index
    int    errcode;                    // error code
    double x[10];                      // parameter values
    char*  id;                         // transect ID name

    // --- match first token to a transect keyword
    k = findmatch(tok[0], TransectKeyWords);
    if ( k < 0 ) return error_setInpError(ERR_KEYWORD, tok[0]);

    // --- read parameters associated with keyword
    switch ( k )
    {
      // --- NC line: Manning n values
      case 0:

        // --- finish processing the previous transect
        transect_validate(index - 1);

        // --- read Manning's n values
        if ( ntoks < 4 ) return error_setInpError(ERR_ITEMS, "");
        for (i = 1; i <= 3; i++)
        {
            if ( ! getDouble(tok[i], &x[i]) )
                return error_setInpError(ERR_NUMBER, tok[i]);
        }
        return setManning(x);

      // --- X1 line: identifies start of next transect
      case 1:

        // --- check that transect was already added to project
        //     (by input_countObjects)
        if ( ntoks < 10 ) return error_setInpError(ERR_ITEMS, "");
        id = project_findID(TRANSECT, tok[1]);
        if ( id == NULL ) return error_setInpError(ERR_NAME, tok[1]);

        // --- read in rest of numerical values on data line
        for ( i = 2; i < 10; i++ )
        {
            if ( ! getDouble(tok[i], &x[i]) )
                return error_setInpError(ERR_NUMBER, tok[i]);
        }

        // --- update total transect count
        *count = index + 1;

        // --- transfer parameter values to transect's properties
        return setParams(index, id, x);

      // --- GR line: station elevation & location data
      case 2:

        // --- check that line contains pairs of data values
        if ( (ntoks - 1) % 2 > 0 ) return error_setInpError(ERR_ITEMS, "");

        // --- parse each pair of Elevation-Station values
        i = 1;
        while ( i < ntoks )
        {
            if ( ! getDouble(tok[i], &x[1]) )
                return error_setInpError(ERR_NUMBER, tok[i]);
            if ( ! getDouble(tok[i+1], &x[2]) )
                return error_setInpError(ERR_NUMBER, tok[i+1]);
            errcode = addStation(x[1], x[2]);
            if ( errcode ) return errcode;
            i += 2;
        }
        return 0;
    }
    return 0;
}
Ejemplo n.º 5
0
void IOPolly::obsFromTextFile (std::string filePath, int angle_unit_type)
{
  // The input file
  std::ifstream data_file (filePath.c_str());

  // testa a abertura do ficheiro
  if (!data_file.is_open()) 
    {
      std::cerr << "Error: Could not open " << filePath << "\n";
      exit (8); //faz parte da cstdlib
    }

  std::string current_line; // alberga cada linha do ficheiro
  
  double horizontal_dir, vertical_dir; // alberga os valores angulares convertidos para rad
  SIUnits *ang_conv = new SIUnits(); // responsavel pelas conversoes


  while(!data_file.eof())
    {
      std::getline(data_file, current_line); // recolhe a linha
      
      if (!current_line.empty()) // se n leu uma linha em branco
	{

	  std::vector<std::string> elements;  // linha nos seus elementos
	  
	  // faz o split ah string para elements
	  std::istringstream iss(current_line);	  
	  std::copy(std::istream_iterator<std::string>(iss),
		    std::istream_iterator<std::string>(),
		    std::back_inserter<std::vector<std::string> >(elements));


	  if(elements.size() == 2)
	    {
	      //cria uma estacao
	      addStation(TCStations->getEnzPoint(elements[0]), 
			 std::atof(elements[1].c_str()));
	    }
	  else if(elements.size() == 5)
	    {
	      //cria um reading
	      
	      switch(angle_unit_type) // conversao dos angulos
		{
		case 1:
		  horizontal_dir = std::atof(elements[1].c_str()); 
		  vertical_dir = std::atof(elements[2].c_str());
		  break;
		case 2:
		  horizontal_dir = ang_conv->degree2rad (std::atof(elements[1].c_str())); 
		  vertical_dir = ang_conv->degree2rad (std::atof(elements[2].c_str()));
		  break;
		case 3:
		  horizontal_dir = ang_conv->gon2rad (std::atof(elements[1].c_str())); 
		  vertical_dir = ang_conv->gon2rad (std::atof(elements[2].c_str()));
		  break;
		}
	      
	      addReading((*(--(obs->end()))).from,
			 TCStations->getEnzPoint(elements[0]), horizontal_dir, 
			 vertical_dir, std::atof(elements[3].c_str()),
			 std::atof(elements[4].c_str()));
	    
	      
	    }

	}       
    }

  delete ang_conv;

  data_file.close();
}