bool getAdmin1TranslationSubs(QString const &pathFile,
                              QList<QString> &listAdmin1Subs)
{
    QFile inputFile(pathFile);
    if(inputFile.open(QIODevice::ReadOnly))   {
        QString before = "\"";
        QString after = "";
        QTextStream in(&inputFile);
        while(!in.atEnd())   {
            QString line = in.readLine();

            // sometimes quotes are added in to
            // the translation substitutes file
            // so they should be removed
            line.replace(before,after);

            listAdmin1Subs.push_back(line);
        }

        listAdmin1Subs.removeFirst();   // should be 'BEGIN'
        listAdmin1Subs.removeLast();    // should be 'END'

        return true;
    }
    else   {
        return false;
    }
}
void AndroidRunnerWorker::logcatProcess(const QByteArray &text, QByteArray &buffer, bool onlyError)
{
    QList<QByteArray> lines = text.split('\n');
    // lines always contains at least one item
    lines[0].prepend(buffer);
    if (!lines.last().endsWith('\n')) {
        // incomplete line
        buffer = lines.last();
        lines.removeLast();
    } else {
        buffer.clear();
    }

    QString pidString = QString::number(m_processPID);
    foreach (const QByteArray &msg, lines) {
        const QString line = QString::fromUtf8(msg).trimmed() + QLatin1Char('\n');
        if (!line.contains(pidString))
            continue;
        if (m_useCppDebugger) {
            switch (m_jdbState) {
            case JDBState::Idle:
                if (msg.trimmed().endsWith("Sending WAIT chunk")) {
                    m_jdbState = JDBState::Waiting;
                    handleJdbWaiting();
                }
                break;
            case JDBState::Waiting:
                if (msg.indexOf("debugger has settled") > 0) {
                    m_jdbState = JDBState::Settled;
                    handleJdbSettled();
                }
                break;
            default:
                break;
            }
        }
        if (m_logCatRegExp.exactMatch(line)) {
            // Android M
            if (m_logCatRegExp.cap(1) == pidString) {
                const QString &messagetype = m_logCatRegExp.cap(2);
                QString output = line.mid(m_logCatRegExp.pos(2));

                if (onlyError
                        || messagetype == QLatin1String("F")
                        || messagetype == QLatin1String("E")
                        || messagetype == QLatin1String("W"))
                    emit remoteErrorOutput(output);
                else
                    emit remoteOutput(output);
            }
        } else {
            if (onlyError || line.startsWith("F/")
                    || line.startsWith("E/")
                    || line.startsWith("W/"))
                emit remoteErrorOutput(line);
            else
                emit remoteOutput(line);
        }
    }
}
void PanelPlot::parseMessage(QByteArray data)
{
    double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
    QString messages = data;
    messages.chop(1); // remove LF
    QList<QString> message = messages.split(',');
    if (message.last() == "")
        message.removeLast();
    if (message.size() == plotSize)
    {
        for (int index=0; index < plotSize; index++)
        {
            if (ui->plotNames->item(index)->checkState() == Qt::Checked)
            {
                double dataValue = message[index].toDouble();
                ui->plotWindow->graph(index)->addData(key, dataValue);
                ui->plotWindow->graph(index)->removeDataBefore(key-timeAxisLength);
            }
        }
        // make key axis range scroll with the data (at a constant range size of 10)
        ui->plotWindow->xAxis->setRange(key+0.25, timeAxisLength, Qt::AlignRight);
        ui->plotWindow->replot();
        ui->plotWindow->rescaleAxes(true);
    }
    else if (message.size() > plotSize)
        emit panelStatus("Plot count (" + QString::number(message.size()) +") does not match plot count in XML configuration file (" + QString::number(plotSize) +")");
}
void applistModel::Search()
{
    LS("applistModel::Search =>>");
    QList<AppEntry> results;
    QString s = m_searchString;

    if(m_appslist != NULL  || m_searchString.isEmpty())
        {
        int rank1results = 0;
        for(int i=0; i < m_appslist->count() ; i++)
            {
            QString appname = m_appslist->at(i).caption;
            if(appname.startsWith(s, Qt::CaseInsensitive))
                {
                AppEntry p = m_appslist->at(i);
                p.iscontact = false;
                if(rank1results <= APPSMODELQUOTA)
                    {
                    rank1results++;
                    p.rank = 1;
                    }
                else
                    {
                    p.rank = 2;
                    }

                results.prepend(p);
                }
            else if(appname.contains(s, Qt::CaseInsensitive))
                {
                AppEntry p = m_appslist->at(i);
                p.iscontact = false;
                p.rank = 3;
                results.append(p);
                }
            else
                {//ignore
                }
            }
        }

    //sort and trim the results before sending.
    qSort(results.begin(), results.end(), appentrylessthan2);

    while(results.count() > MAXRESULTS)
        results.removeLast();

//    for(int j=0;j<results.count();j++)
//        {
//        LS(results[j].caption);
//        LS(results[j].rank);
//        }

    emit HandleSearchResults(s, results, 0, false);
    LS("applistModel::Search << "<<QString::number(results.count()));
}
Example #5
0
void SchematicScene::clearAllItems() {
  clearSelection();
  m_highlightedLinks.clear();
  QList<SchematicWindowEditor *> editors;
  QList<SchematicNode *> nodes;
  QList<SchematicLink *> links;
  int i;
  QList<QGraphicsItem *> sceneItems = items();
  int size                          = sceneItems.size();
  // create nodes and links list
  for (i = 0; i < size; i++) {
    QGraphicsItem *item           = sceneItems.at(i);
    SchematicWindowEditor *editor = dynamic_cast<SchematicWindowEditor *>(item);
    SchematicNode *node           = dynamic_cast<SchematicNode *>(item);
    SchematicLink *link           = dynamic_cast<SchematicLink *>(item);
    if (editor) editors.append(editor);
    if (node) nodes.append(node);
    if (link) links.append(link);
  }
  while (links.size() > 0) {
    SchematicLink *link = links.back();
    removeItem(link);
    links.removeLast();
    SchematicPort *startPort = link->getStartPort();
    SchematicPort *endPort   = link->getEndPort();
    if (startPort) startPort->removeLink(link);
    if (endPort) endPort->removeLink(link);
    delete link;
  }
  while (editors.size() > 0) {
    SchematicWindowEditor *editor = editors.back();
    removeItem(editor);
    editors.removeLast();
    delete editor;
  }
  while (nodes.size() > 0) {
    SchematicNode *node = nodes.back();
    removeItem(node);
    nodes.removeLast();
    delete node;
  }
  assert(items().size() == 0);
}
Example #6
0
int BookViewPreview::GetSelectionOffset(const QMap<int, QString> &node_offsets,
                                        Searchable::Direction search_direction)
{
    QList<ViewEditor::ElementIndex> cl = GetCaretLocation();
    // remove final #text node if it exists
    if (cl.at(cl.count()-1).name == "#text") {
        cl.removeLast();
    }
    QString caret_node = ConvertHierarchyToQWebPath(cl);
    bool searching_down = search_direction == Searchable::Direction_Down ? true : false;
    int local_offset    = GetLocalSelectionOffset(!searching_down);
    int search_start    = node_offsets.key(caret_node) + local_offset;
    return search_start;
}
int BookViewPreview::GetSelectionOffset(const QMap<int, QString> &node_offsets,
                                        Searchable::Direction search_direction)
{
    QList<ViewEditor::ElementIndex> cl = GetCaretLocation();
    // remove final #text node if it exists
    // Some BookView tabs with only SVG images report a cl.count of 0
    // meaning there is no cursor, so test for that case
    if ((cl.count() > 0) && (cl.at(cl.count()-1).name == "#text")) {
        cl.removeLast();
    }
    QString caret_node = ConvertHierarchyToQWebPath(cl);
    bool searching_down = search_direction == Searchable::Direction_Down ? true : false;
    int local_offset    = GetLocalSelectionOffset(!searching_down);
    int search_start    = node_offsets.key(caret_node) + local_offset;
    return search_start;
}
Example #8
0
void VListCF::determineChildren()
{
	// Get the single items from the list of composite items.
	QList< Item* > items = extractSingleItems();

	// Inserts elements that are not yet visualized and adjusts the order to match that in 'nodes'.
	for (int i = 0; i < node()->size(); ++i)
	{
		if (i >= items.size() ) items.append( renderer()->render(this, node()->at<Node>(i)));	// This node is new
		else if ( items[i]->node() == node()->at<Node>(i) )	continue;	// This node is already there
		else
		{
			// This node might appear somewhere ahead, we should look for it
			bool found = false;
			for (int k = i + 1; k<items.size(); ++k)
			{
				if ( items[k]->node() == node()->at<Node>(i) )
				{
					// We found this node, swap the visualizations
					items.swap(i, k);
					found = true;
					break;
				}
			}

			// The node was not found, insert a visualization here
			if (!found ) items.insert(i, renderer()->render(this, node()->at<Node>(i)));
		}
	}

	// Remove excess items
	while (items.size() > node()->size()) items.removeLast();

	// Convert the single items list back to a list of composite items.
	buildCompositeItems(items);
}
Example #9
0
void MainWindow::readPendingDatagrams()
{
    QByteArray payload;
    QByteArray Type;
    QList<QByteArray> byte;

    while (udpSocket->hasPendingDatagrams()) {
        payload.resize(udpSocket->pendingDatagramSize());
        udpSocket->readDatagram(payload.data(), payload.size());
    }
    qDebug()<<payload<<endl;
    ui->ready_bar->setValue(80);

    if (QString::compare(payload.data(),"Invalid Option",Qt::CaseInsensitive)==0)
    {
        qDebug()<<"Invalid Option"<<endl;
    }
    else
    {
        byte=payload.split('+');
        byte.removeFirst();
        byte.removeLast();

        Type=byte.takeFirst();

        if(QString::compare(Type.data(),"OMR",Qt::CaseInsensitive)==0)
        {
            OP=byte.takeFirst();
            Read_Write=byte.takeFirst();
            Polarity=byte.takeFirst();
            PS=byte.takeFirst();
            Disc_CSM_SPM=byte.takeFirst();
            TP=byte.takeFirst();
            Count_L=byte.takeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            Equalization=byte.takeFirst();
            Colour_Mode=byte.takeFirst();
            Pixel_Mode=byte.takeFirst();
            byte.removeFirst();
            Gain_Mode=byte.takeFirst();
            byte.removeFirst();
            byte.removeFirst();
            byte.removeFirst();
            Time=byte.takeFirst();
            NImage=byte.takeFirst();
            Gap=byte.takeFirst();
            RCount=byte.takeFirst();

            ui->Aquire_Time_Input->setText(Time);
            ui->Gap_Input->setText(Gap);
            ui->NImages_Input->setText(NImage);
            ui->Read_Counter_Input->setCurrentIndex(RCount.toInt());
            ui->Polarity_Input->setCurrentIndex(Polarity.toInt());
            ui->Colour_Mode_Input->setCurrentIndex(Colour_Mode.toInt());
            ui->Read_Write_Input->setCurrentIndex(Read_Write.toInt());
            ui->Disc_CSM_SPM_Input->setCurrentIndex(Disc_CSM_SPM.toInt());
            ui->Output_Input->setCurrentIndex(PS.toInt());
            ui->Count_L_Input->setCurrentIndex(Count_L.toInt());
            ui->Gain_Mode_Input->setCurrentIndex(Gain_Mode.toInt());
            ui->Pixel_Mode_Input->setCurrentIndex(Pixel_Mode.toInt());
        }
        else if(QString::compare(Type.data(),"DAC",Qt::CaseInsensitive)==0)
        {
            th0=byte.takeFirst();
            th1=byte.takeFirst();
            th2=byte.takeFirst();
            th3=byte.takeFirst();
            th4=byte.takeFirst();
            th5=byte.takeFirst();
            th6=byte.takeFirst();
            th7=byte.takeFirst();
            preamp=byte.takeFirst();
            ikrum=byte.takeFirst();
            shaper=byte.takeFirst();
            disc=byte.takeFirst();
            discls=byte.takeFirst();
            shapertest=byte.takeFirst();
            dacdiscl=byte.takeFirst();
            dactest=byte.takeFirst();
            dacdisch=byte.takeFirst();
            delay=byte.takeFirst();
            tpbufferin=byte.takeFirst();
            tpbufferout=byte.takeFirst();
            rpz=byte.takeFirst();
            gnd=byte.takeFirst();
            tpref=byte.takeFirst();
            fbk=byte.takeFirst();
            cas=byte.takeFirst();
            tprefa=byte.takeFirst();
            tprefb=byte.takeFirst();

            ui->TH0_Input->setText(th0);
            ui->TH1_Input->setText(th1);
            ui->TH2_Input->setText(th2);
            ui->TH3_Input->setText(th3);
            ui->TH4_Input->setText(th4);
            ui->TH5_Input->setText(th5);
            ui->TH6_Input->setText(th6);
            ui->TH7_Input->setText(th7);
            ui->IPREAMP_Input->setText(preamp);
            ui->IKRUM_Input->setText(ikrum);
            ui->ISHAPER_Input->setText(shaper);
            ui->IDISC_Input->setText(disc);
            ui->IDISCLS_Input->setText(discls);
            ui->ISHAPERTEST_Input->setText(shapertest);
            ui->IDACDISCL_Input->setText(dacdiscl);
            ui->IDAC_Test_Input->setText(dactest);
            ui->IDACDISCH_Input->setText(dacdisch);
            ui->IDELAY_Input->setText(delay);
            ui->ITPBUFFERIN_Input->setText(tpbufferin);
            ui->ITPBUFFEROUT_Input->setText(tpbufferout);
            ui->VRPZ_Input->setText(rpz);
            ui->VGND_Input->setText(gnd);
            ui->VTPREF_Input->setText(tpref);
            ui->VFBK_Input->setText(fbk);
            ui->VCAS_Input->setText(cas);
            ui->VTPREFA_Input->setText(tprefa);
            ui->VTPREFB_Input->setText(tprefb);
        }
        else if(QString::compare(Type.data(),"SEND",Qt::CaseInsensitive)==0)
        {
            Send_Ip=byte.takeFirst();
            Send_Port=byte.takeFirst();
            Send_Mac=byte.takeFirst();
            byte.removeFirst();
            Host_Ip=byte.takeFirst();
            Host_Net=byte.takeFirst();

            ui->SENDIP_Input->setText(Send_Ip);
            ui->SENDPORT_Input->setText(Send_Port);
            ui->SENDMAC_Input->setText(Send_Mac);

            ui->HOSTIP_Input->setText(Host_Ip);
            ui->HOSTNETMASK_Input->setText(Host_Net);
        }
        ui->ready_bar->setValue(100);
    }
}
void Converter::convertSimpleType(const XSD::SimpleType *type, const XSD::SimpleType::List &simpleTypeList)
{
    const QString typeName(mTypeMap.localType(type->qualifiedName()));
    //qDebug() << "convertSimpleType:" << type->qualifiedName() << typeName;
    KODE::Class newClass;
    newClass.setNamespaceAndName(typeName);
    if (!Settings::self()->exportDeclaration().isEmpty()) {
        newClass.setExportDeclaration(Settings::self()->exportDeclaration());
    }
    newClass.setNameSpace(Settings::self()->nameSpace());

    QString classDocumentation;

    switch (type->subType()) {
    case XSD::SimpleType::TypeRestriction: {
        /**
          Use setter and getter method for enums as well.
         */
        if (type->facetType() & XSD::SimpleType::ENUM) {
            classDocumentation = "This class is a wrapper for an enumeration.\n";
            NameMapper nameMapper;
            QStringList enums = type->facetEnums();
            for (int i = 0; i < enums.count(); ++i) {
                enums[ i ] = nameMapper.escape(escapeEnum(enums[ i ]));
            }

            newClass.addEnum(KODE::Enum("Type", enums));

            classDocumentation += "Whenever you have to pass an object of type " + newClass.name() +
                                  " you can also pass the enum directly. Example:\n" +
                                  "someMethod(" + newClass.name() + "::" + enums.first() + ").";

            // member variables
            KODE::MemberVariable variable("type", "Type");
            variable.setInitializer("Type(0)");
            newClass.addMemberVariable(variable);

            // setter method
            KODE::Function setter("setType", "void");
            setter.addArgument("Type type");
            setter.setBody(variable.name() + " = type;");

            // getter method
            KODE::Function getter("type", newClass.qualifiedName() + "::Type");
            getter.setBody("return " + variable.name() + ';');
            getter.setConst(true);

            // convenience constructor
            KODE::Function conctor(newClass.name());
            conctor.addArgument("const Type &type");
            KODE::Code code;
            code += variable.name() + " = type;";
            conctor.setBody(code);

            // type operator
            KODE::Function op("operator Type");
            op.setBody("return " + variable.name() + ';');
            op.setConst(true);

            newClass.addFunction(conctor);
            newClass.addFunction(setter);
            newClass.addFunction(getter);
            newClass.addFunction(op);
        }

        /**
          A class can't derive from basic types (e.g. int or unsigned char), so
          we add setter and getter methods to set the value of this class.
         */
        if (type->baseTypeName() != XmlAnyType
                && !type->baseTypeName().isEmpty()
                && !(type->facetType() & XSD::SimpleType::ENUM)) {
            classDocumentation = "This class encapsulates a simple type.\n";

            const QName baseName = type->baseTypeName();
            const QString baseTypeName = mTypeMap.localType(baseName);
            Q_ASSERT(!baseTypeName.isEmpty());

            QList<QName> parentBasicTypes;
            parentBasicTypes.append(baseName);
            QName currentType = baseName;
            Q_FOREVER {
                const XSD::SimpleType simpleType = simpleTypeList.simpleType(currentType);
                if (!simpleType.isNull() && simpleType.isRestriction()) {
                    currentType = simpleType.baseTypeName();
                    parentBasicTypes.append(currentType);
                    continue;
                }
                break;
            }

            classDocumentation += "Whenever you have to pass an object of type " + newClass.name() +
                                  " you can also pass the value directly as a " + mTypeMap.localType(currentType) + '.';
            // include header
            newClass.addIncludes(QStringList(), mTypeMap.forwardDeclarations(baseName));
            newClass.addHeaderIncludes(mTypeMap.headerIncludes(baseName));

            // member variables
            KODE::MemberVariable variable("value", baseTypeName);
            addVariableInitializer(variable);
            newClass.addMemberVariable(variable);

            // setter method
            KODE::Function setter("setValue", "void");
            const QString inputType = mTypeMap.localInputType(baseName, QName());
            setter.addArgument(inputType + " value");
            KODE::Code setterBody;
            if (type->facetType() != XSD::SimpleType::NONE) {
                const XSD::SimpleType baseSimpleType = simpleTypeList.simpleType(baseName);
                setterBody += createRangeCheckCode(type, baseTypeName, "value", newClass, baseSimpleType);
                setterBody.newLine();
                setterBody += "if (!rangeOk)";
                setterBody.indent();
                setterBody += "qDebug( \"Invalid range in " + newClass.name() + "::" + setter.name() + "()\" );";
                setterBody.unindent();
                setterBody.newLine();
            }
            setterBody += variable.name() + " = value;"; // ### call setValue in base class?
            setter.setBody(setterBody);
            newClass.addFunction(setter);

            // getter method
            KODE::Function getter("value", baseTypeName);
            getter.setBody("return " + variable.name() + ';');
            getter.setConst(true);
            newClass.addFunction(getter);

            // convenience constructor
            KODE::Function conctor(newClass.name());
            conctor.addArgument(inputType + " value");
            conctor.addBodyLine("setValue(value);");
            newClass.addFunction(conctor);

            // even more convenient constructor, for the case of multiple-level simple-type restrictions
            //qDebug() << typeName << ": baseName=" << baseName << "further up:" << parentBasicTypes;
            if (parentBasicTypes.count() > 1) {
                parentBasicTypes.removeLast(); // the top-most one is in "currentType", so it's the input arg.
                KODE::Function baseCtor(conctor.name());
                baseCtor.addArgument(mTypeMap.localInputType(currentType, QName()) + " value");
                QString beginLine = "setValue(";
                QString endLine = ")";
                Q_FOREACH (const QName &base, parentBasicTypes) {
                    beginLine += mTypeMap.localType(base) + '(';
                    endLine += ')';
                }
                baseCtor.addBodyLine(beginLine + "value" + endLine + ';');
                newClass.addFunction(baseCtor);
            }

            // type operator
            KODE::Function op("operator " + baseTypeName);
            op.setBody("return " + variable.name() + ';');
            op.setConst(true);
            newClass.addFunction(op);
        }
bool SshEncryptionFacility::createAuthenticationKeyFromOpenSSL(const QByteArray &privKeyFileContents,
    QList<BigInt> &pubKeyParams, QList<BigInt> &allKeyParams, QString &error)
{
    try {
        bool syntaxOk = true;
        QList<QByteArray> lines = privKeyFileContents.split('\n');
        while (lines.last().isEmpty())
            lines.removeLast();
        if (lines.count() < 3) {
            syntaxOk = false;
        } else if (lines.first() == PrivKeyFileStartLineRsa) {
            if (lines.last() != PrivKeyFileEndLineRsa)
                syntaxOk = false;
            else
                m_authKeyAlgoName = SshCapabilities::PubKeyRsa;
        } else if (lines.first() == PrivKeyFileStartLineDsa) {
            if (lines.last() != PrivKeyFileEndLineDsa)
                syntaxOk = false;
            else
                m_authKeyAlgoName = SshCapabilities::PubKeyDss;
        } else {
            syntaxOk = false;
        }
        if (!syntaxOk) {
            error = SSH_TR("Unexpected format.");
            return false;
        }

        QByteArray privateKeyBlob;
        for (int i = 1; i < lines.size() - 1; ++i)
            privateKeyBlob += lines.at(i);
        privateKeyBlob = QByteArray::fromBase64(privateKeyBlob);

        BER_Decoder decoder(convertByteArray(privateKeyBlob), privateKeyBlob.size());
        BER_Decoder sequence = decoder.start_cons(SEQUENCE);
        size_t version;
        sequence.decode (version);
        if (version != 0) {
            error = SSH_TR("Key encoding has version %1, expected 0.").arg(version);
            return false;
        }

        if (m_authKeyAlgoName == SshCapabilities::PubKeyDss) {
            BigInt p, q, g, y, x;
            sequence.decode (p).decode (q).decode (g).decode (y).decode (x);
            DSA_PrivateKey * const dsaKey = new DSA_PrivateKey(m_rng, DL_Group(p, q, g), x);
            m_authKey.reset(dsaKey);
            pubKeyParams << p << q << g << y;
            allKeyParams << pubKeyParams << x;
        } else {
            BigInt p, q, e, d, n;
            sequence.decode(n).decode(e).decode(d).decode(p).decode(q);
            RSA_PrivateKey * const rsaKey = new RSA_PrivateKey(m_rng, p, q, e, d, n);
            m_authKey.reset(rsaKey);
            pubKeyParams << e << n;
            allKeyParams << pubKeyParams << p << q << d;
        }

        sequence.discard_remaining();
        sequence.verify_end();
    } catch (const Botan::Exception &ex) {
        error = QLatin1String(ex.what());
        return false;
    } catch (const Botan::Decoding_Error &ex) {
        error = QLatin1String(ex.what());
        return false;
    }
    return true;
}
//----------------------------------------
//--- Primary playback control methods ---
//----------------------------------------
void Playlist::playItemAt(int row, Model model)
{
    bool isQueue = (model == QueueModel);
    MediaItem nextMediaItem = isQueue ? m_queue->mediaItemAt(row) :
                                        m_currentPlaylist->mediaItemAt(row);
    if (!isQueue) {
        nextMediaItem.playlistIndex = row;
    }
    nextMediaItem.nowPlaying = true;
    
    //Update Queue Model
    if (!m_shuffle) {
        //Just build a new queue from the row of the item in the playlist
        buildQueueFrom(nextMediaItem.playlistIndex);
    } else {
        int rowInQueue = isQueue ? row : m_queue->rowOfUrl(nextMediaItem.url);

        //Add currently playing item to history
        if (rowInQueue > 0 && m_nowPlaying->rowCount() > 0) {
            if (m_nowPlaying->mediaItemAt(0).type == "Audio" || m_nowPlaying->mediaItemAt(0).type == "Video") {
                int nowPlayingIndex = m_nowPlaying->mediaItemAt(0).playlistIndex;
                m_playlistIndicesHistory.append(nowPlayingIndex);
                m_playlistUrlHistory.append(m_nowPlaying->mediaItemAt(0).url);
                if (m_queue->rowCount() > 1) {
                    m_queue->removeMediaItemAt(0);
                    rowInQueue--;
                }
            }
        }

        //Remove requested item from history
        bool inHistory = (m_playlistIndicesHistory.indexOf(nextMediaItem.playlistIndex) != -1);
        if ( inHistory ) { //remove from history
            int idx = m_playlistIndicesHistory.indexOf(row);
            m_playlistIndicesHistory.removeAt(idx);
            m_playlistUrlHistory.removeAt(idx);
        }

        //Place requested item at front of queue
        QList<MediaItem> queueMediaList = m_queue->mediaList();
        if ( rowInQueue > 0 ) { //in queue, but not at first place, so move it
            queueMediaList.move(rowInQueue, 0);
        } else if (rowInQueue < 0) { //not in queue, so add it at first place
            queueMediaList.insert(0, nextMediaItem);
            if (queueMediaList.count() > m_queueDepth) {
                queueMediaList.removeLast();
            }
        } //else it is already at first place in the queue
        m_queue->clearMediaListData();
        m_queue->loadMediaList(queueMediaList, true);

        //Fill out queue
        shuffle();
    }
    
    //Play media Item
    m_mediaObject->clearQueue();
    m_currentStream.clear();
    QString subType;
    if (nextMediaItem.type == "Audio") {
        subType = nextMediaItem.fields["audioType"].toString();
    } else if(nextMediaItem.type == "Video") {
        subType = nextMediaItem.fields["videoType"].toString();
    }
    m_currentUrl = nextMediaItem.url;
    bool isDiscTitle = Utilities::isDisc( nextMediaItem.url );
    if (isDiscTitle) {
        Solid::Device device = Solid::Device( Utilities::deviceUdiFromUrl(nextMediaItem.url) );
        if (!device.isValid()) {
            stop();
            return;
        }
        const Solid::Block* block = device.as<const Solid::Block>();
        Phonon::DiscType discType = (subType == "CD Track") ? Phonon::Cd : Phonon::Dvd;
        Phonon::MediaSource src = Phonon::MediaSource(discType, block->device());
        int title = nextMediaItem.fields["trackNumber"].toInt();
        if (m_mediaObject->currentSource().discType() != src.discType() ||
            m_mediaObject->currentSource().deviceName() != src.deviceName()) {
            m_mediaObject->setCurrentSource(src);
        }
        if (title != -1) {
            m_mediaController->setCurrentTitle(title);
            m_mediaController->setAutoplayTitles(true);
        }
        m_mediaObject->play();
    } else if (subType == "Audio Stream") {
        m_currentStream = nextMediaItem.url;
        m_streamListUrls.clear();
        if (Utilities::isPls(nextMediaItem.url) || Utilities::isM3u(nextMediaItem.url)) {
            QList<MediaItem> streamList = Utilities::mediaListFromSavedList(nextMediaItem);
            for (int i = 0; i < streamList.count(); i++) {
                m_streamListUrls << streamList.at(i).url;
                if (i == 0) {
                    m_currentUrl = streamList.at(i).url;
                } else {
                    m_mediaObject->enqueue(Phonon::MediaSource(QUrl::fromPercentEncoding(streamList.at(i).url.toUtf8())));
                }
            }
        } else {
            m_streamListUrls << nextMediaItem.url;
        }
        m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromPercentEncoding(m_currentUrl.toUtf8())));
        m_mediaObject->play();
    } else {
        m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(m_currentUrl.toUtf8())));
        m_mediaObject->play();
    }
    m_state = Playlist::Playing;
}
Example #13
0
bool noLimitsImporter::importAsNlTrack()
{
    fstream fin(fileName.toLocal8Bit().data(), ios::in | ios::binary);
    if(!fin)
    {
        return false;
    }

    inTrack->trackData->fHeart = 0.f;
    inTrack->trackWidgetItem->addSection(bezier);

    fin.seekg (0, ios::end);

    int length = fin.tellg();
    string temp;
    QList<bezier_t*> *bList = &inTrack->trackData->activeSection->bezList;

    QList<glm::vec3> *lineList = &inTrack->trackData->activeSection->supList;

    QList<glm::vec3> TubeNodes[3];

    int bezCount, fundCount, freeCount, tubeCount;
    glm::vec3 anchor;
    bool closeTrack = false;

    for(int i = 0; i < length; ++i)
    {
        fin.seekg(i);
        temp = readString(&fin, 4);
        if(temp == "SEGM")
        {
            readNulls(&fin, 4);
            int segCount = readInt(&fin);
            closeTrack = readBool(&fin);
            readNulls(&fin, 16);
            for(int i = 0; i < segCount; ++i)
            {
                int type = readInt(&fin);
                readNulls(&fin, 29);
                if(type == 0)
                {
                    readNulls(&fin, 4);
                    bList->at(i)->fVel = 0.f;
                }
                else if(type == 1)   // station
                {
                    readNulls(&fin, 54);
                    bList->at(i)->fVel = readFloat(&fin);
                    readNulls(&fin, 72);
                }
                else if(type == 2) // lift
                {
                    readNulls(&fin, 8);
                    bList->at(i)->fVel = readFloat(&fin);
                    readNulls(&fin, 28);
                }
                else if(type == 3) // transport
                {
                    readNulls(&fin, 4);
                    bList->at(i)->fVel = readFloat(&fin);
                    readNulls(&fin, 24);
                }
                else if(type == 4) // brake
                {
                    readNulls(&fin, 4);
                    bList->at(i)->fVel = readFloat(&fin);
                    readNulls(&fin, 46);
                }
                else
                {
                    qWarning("something wrong importing NL Track");
                }
                if(bList->at(i)->fVel != bList->at(i)->fVel)
                {
                    qWarning("read nan while importing NL Track");
                }

            }
        }
        if(temp == "BEZR")
        {
            readInt(&fin);  // size
            readNulls(&fin, 16);
            bezCount = readInt(&fin);
            for(int b = 0; b < bezCount; ++b)
            {
                bList->append(new bezier_t);
                bList->at(b)->P1.x = readFloat(&fin);
                bList->at(b)->P1.y = readFloat(&fin);
                bList->at(b)->P1.z = readFloat(&fin);
                bList->at(b)->Kp1.x = readFloat(&fin);
                bList->at(b)->Kp1.y = readFloat(&fin);
                bList->at(b)->Kp1.z = readFloat(&fin);
                bList->at(b)->Kp2.x = readFloat(&fin);
                bList->at(b)->Kp2.y = readFloat(&fin);
                bList->at(b)->Kp2.z = readFloat(&fin);
                bList->at(b)->roll = readFloat(&fin);
                bList->at(b)->contRoll = readBool(&fin);
                bList->at(b)->equalDist = readBool(&fin);
                bList->at(b)->relRoll = readBool(&fin);
                readNulls(&fin, 17);
                if(b == 0) anchor = bList->at(b)->P1;
                bList->at(b)->P1 -= anchor;
                bList->at(b)->Kp1 -= anchor;
                bList->at(b)->Kp2 -= anchor;

                bList->at(b)->ptf = 0.f;
                bList->at(b)->fvdRoll = 0.f;
                bList->at(b)->fVel = 0.f;
            }
        }
        if(temp == "FUND")
        {
            readInt(&fin);  //size
            readNulls(&fin, 16);
            fundCount = readInt(&fin);
            for(int b = 0; b < fundCount; ++b)
            {
                glm::vec3 temp;
                /*for(int i = 0; i < 4; ++i)
                {
                    temp.x = readFloat(&fin);
                }*/
                readNulls(&fin, 16);
                temp.x = readFloat(&fin);
                temp.y = readFloat(&fin);
                temp.z = readFloat(&fin);
                readNulls(&fin, 64);
                TubeNodes[0].append(temp);
                /*for(int i = 0; i < 12; ++i)
                {
                    temp.x = readFloat(&fin);
                }*/
            }
        }
        if(temp == "FREN")
        {
            readInt(&fin);  // size
            readNulls(&fin, 16);
            freeCount = readInt(&fin);
            for(int b = 0; b < freeCount; ++b)
            {
                glm::vec3 temp;
                temp.x = readFloat(&fin);
                temp.y = readFloat(&fin);
                temp.z = readFloat(&fin);
                TubeNodes[1].append(temp);
                readNulls(&fin, 16);
            }
        }
        if(temp == "TUBE")
        {
            int type, index;
            readInt(&fin);  // size
            readNulls(&fin, 16);
            tubeCount = readInt(&fin);
            for(int b = 0; b < tubeCount; ++b)
            {
                type = readInt(&fin);
                readInt(&fin);  // segment
                index = readInt(&fin);
                if(type != 3)
                {
                    lineList->append(TubeNodes[type-1][index] - anchor);
                }
                readNulls(&fin, 4);
                type = readInt(&fin);
                readInt(&fin);  // segment
                index = readInt(&fin);
                if(type != 3 && lineList->size()%2)
                {
                    lineList->append(TubeNodes[type-1][index] - anchor);
                }
                else if(type == 3 && lineList->size()%2)
                {
                    lineList->removeLast();
                }
                readNulls(&fin, 20);
            }
        }
    }

    if(closeTrack)
    {
        bList->append(new bezier_t);
        bList->last()->P1 = bList->at(0)->P1;
        bList->last()->Kp1 = bList->at(0)->Kp1;
        bList->last()->Kp2 = bList->at(0)->Kp2;
        bList->last()->roll = bList->at(0)->roll;
        bList->last()->contRoll = bList->at(0)->contRoll;
        bList->last()->equalDist = bList->at(0)->equalDist;
        bList->last()->relRoll = bList->at(0)->relRoll;
        bList->last()->ptf = 0.f;
        bList->last()->fvdRoll = 0.f;
    }

    inTrack->trackData->updateTrack(0, 0);
    fin.close();
    return true;
}
Example #14
0
// keys on even indexes, values on odd indexes. Reduces code expansion for the templated
// alternatives.
// If "ba" starts with empty content it will be removed from ba to simplify later calls
static QList<QByteArray> parseChallenge(QByteArray &ba, QByteArray *scheme, QByteArray* nextAuth = 0)
{
    QList<QByteArray> values;
    const char *b = ba.constData();
    int len = ba.count();
    int start = 0, end = 0, pos = 0;

    // parse scheme
    while (start < len && isWhiteSpaceOrComma(b[start])) {
        start++;
    }
    end = start;
    while (end < len && !isWhiteSpace(b[end])) {
        end++;
    }

    // drop empty stuff from the given string, it would have to be skipped over and over again
    if (start != 0) {
        ba = ba.mid(start);
        end -= start;
        len -= start;
        start = 0;
        b = ba.constData();
    }
    Q_ASSERT(scheme);
    *scheme = ba.left(end);

    while (end < len) {
        start = end;
        // parse key, skip empty fields
        while (start < len && isWhiteSpace(b[start])) {
            start++;
        }
        end = start;
        while (end < len && b[end] != '=') {
            end++;
        }
        pos = end; // save the end position
        while (end - 1 > start && isWhiteSpace(b[end - 1])) { // trim whitespace
            end--;
        }
        if (containsScheme(b, start, end) || (b[pos] != '=' && pos == len)) {
            if (nextAuth) {
                *nextAuth = QByteArray (b + start);
            }
            break;  // break on start of next scheme.
        }
        while (start < len && isWhiteSpaceOrComma(b[start])) {
            start++;
        }
        values.append(QByteArray (b + start, end - start));
        end = pos; // restore the end position
        if (end == len) {
            break;
        }

        // parse value
        start = end + 1;    //skip '='
        while (start < len && isWhiteSpace(b[start])) {
            start++;
        }

        if (b[start] == '"') {
            //quoted string
            bool hasBs = false;
            bool hasErr = false;
            end = ++start;
            while (end < len) {
                if (b[end] == '\\') {
                    end++;
                    if (end + 1 >= len) {
                        hasErr = true;
                        break;
                    } else {
                        hasBs = true;
                        end++;
                    }
                } else if (b[end] == '"') {
                    break;
                } else {
                    end++;
                }
            }
            if (hasErr || (end == len)) {
                // remove the key we already inserted
                kDebug(7113) << "error in quoted text for key" << values.last();
                values.removeLast();
                break;
             }
            QByteArray value = QByteArray(b + start, end - start);
            if (hasBs) {
                // skip over the next character, it might be an escaped backslash
                int i = -1;
                while ( (i = value.indexOf('\\', i + 1)) >= 0 ) {
                    value.remove(i, 1);
                }
            }
            values.append(value);
            end++;
        } else {
            //unquoted string
            end = start;
            while (end < len && b[end] != ',' && !isWhiteSpace(b[end])) {
                end++;
            }
            values.append(QByteArray(b + start, end - start));
        }

        //the quoted string has ended, but only a comma ends a key-value pair
        while (end < len && isWhiteSpace(b[end])) {
            end++;
        }

        // garbage, here should be end or field delimiter (comma)
        if (end < len && b[end] != ',') {
            kDebug(7113) << "unexpected character" << b[end] << "found in WWW-authentication header where token boundary (,) was expected";
            break;
        }
    }
    // ensure every key has a value
    // WARNING: Do not remove the > 1 check or parsing a Type 1 NTLM
    // authentication challenge will surely fail.
    if (values.count() > 1 && values.count() % 2) {
        values.removeLast();
    }
    return values;
}
Example #15
0
/*! parses .cty file, makes country list

      -  lat=latitude of station +=N
   -  lon=longitude of station +=W
   -  ZoneType: 0: read CQ zones/countries  1: read ITU zones/ARRL countries

 */
void Cty::initialize(double la, double lo, int ZoneType)
{
/*! CTY file format

   Column   Length      Description

   -    1           26  country Name
   -    27          5   CQ Zone
   -    32          5   ITU Zone
   -    37          5   2-letter continent abbreviation
   -    42          9   Latitude in degrees, + for North
   -    51          10  Longitude in degrees, + for West
   -    61          9   Local time offset from GMT
   -    70          6   Primary DXCC Prefix (A "*" preceding this prefix indicates
                        that the country is on the DARC WAEDC list, and counts in
                        CQ-sponsored contests, but not ARRL-sponsored contests).
 */
    double mylat=la;
    double mylon=lo;

    QFile file(dataDirectory()+"/"+settings.value(c_cty,c_cty_def).toString());
    int   indx;

    // sunrise/sunset times for station
    sunTimes(mylat, mylon, mySun);

    // sunrise/sunset times and bearings for CQ or ITU zones. These are used for
    // certain countries that span many zones
    QString zoneFileName;
    switch (ZoneType) {
    case 0:zoneFileName=dataDirectory()+"/cq_zone_latlong.dat";break;
    case 1:zoneFileName=dataDirectory()+"/itu_zone_latlong.dat";break;
    }
    QFile file2(zoneFileName);
    if (file2.open(QIODevice::ReadOnly | QIODevice::Text)) {
        // add blank for 0, zones start with 1
        zoneBearing.append(0);
        zoneSun.append("");
        while (!file2.atEnd()) {
            QString buffer;
            buffer=file2.readLine(80);
            if (buffer.contains('#')) continue; // #=comment line

            buffer=buffer.trimmed();
            QStringList field = buffer.split(" ", QString::SkipEmptyParts);
            double lat=field.at(1).toDouble();
            double lon=field.at(2).toDouble();
            QString sunTime;
            QString set;
            sunTimes(lat, -lon, sunTime);
            zoneSun.append(sunTime);

            double dist;
            double head;
            qrb(mylon * -1.0, mylat, lon , lat, &dist, &head);
            zoneBearing.append(qRound(head));
        }
        file2.close();
    } else {
        // file missing, just make these blank
        int nz=40;
        if (ZoneType==1) nz=80;
        for (int i=0;i<nz;i++) {
            zoneBearing.append(0);
            zoneSun.append("ERR");
        }
    }
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QString tmp = "ERROR: can't open file " + settings.value(c_cty,c_cty_def).toString();
        emit(ctyError(tmp));
        return;
    }
    nARRLCty = 0;
    nCQCty   = 0;
    indx     = 0;

    while (!file.atEnd()) {
        QByteArray buffer, tmp, tmp2, buffer_a, buffer_e;
        int        i0, i1, i2, i3, i4, cqz, ituz;

        // get one record
        // all records are at least one line
        buffer = file.readLine();
        tmp    = file.readLine();
        buffer_e.clear();

        // zone exceptions for main pfx
        while (tmp.contains("#")) {
            buffer_e.append(tmp);
            while (!tmp.contains(";")) {
                tmp = file.readLine();
                buffer_e.append(tmp);
            }
            tmp = file.readLine();
        }

        // alias pfx; may include zone exceptions as well
        buffer_a = tmp;
        while (!tmp.contains(";")) {
            tmp = file.readLine();
            buffer_a.append(tmp);
        }
        buffer   = buffer.trimmed();
        buffer_a = buffer_a.trimmed();
        buffer_e = buffer_e.trimmed();

        // now process parts
        // main line
        Country* new_country = new Country;
        new_country->multipleZones = false;
        new_country->indx          = indx;

        i1                = buffer.indexOf(":", 0);
        new_country->name = buffer.mid(0, i1);

        // insert some common abbrieviations (I=Island,...)
        // to save screen space
        if (new_country->name.contains("Island")) {
            new_country->name.replace("Island", "I");
        }
        i2 = buffer.indexOf(":", i1 + 1);
        int cqzone = buffer.mid(i1 + 1, i2 - i1 - 1).toInt();

        i1 = buffer.indexOf(":", i2 + 1);
        int ituzone = buffer.mid(i2 + 1, i1 - i2 - 1).toInt();
        if (ZoneType) {
            new_country->Zone = ituzone;
        } else {
            new_country->Zone = cqzone;
        }
        i2  = buffer.indexOf(":", i1 + 1);
        tmp = buffer.mid(i1 + 1, i2 - i1 - 1);

        tmp = tmp.trimmed();
        if (tmp == "NA") {
            new_country->Continent = NA;
        } else if (tmp == "SA") {
            new_country->Continent = SA;
        } else if (tmp == "EU") {
            new_country->Continent = EU;
        } else if (tmp == "AF") {
            new_country->Continent = AF;
        } else if (tmp == "AS") {
            new_country->Continent = AS;
        } else if (tmp == "OC") {
            new_country->Continent = OC;
        }
        i1 = buffer.indexOf(":", i2 + 1);
        double lat = buffer.mid(i2 + 1, i1 - i2 - 1).trimmed().toFloat();

        i2 = buffer.indexOf(":", i1 + 1);
        double lon = buffer.mid(i1 + 1, i2 - i1 - 1).trimmed().toFloat();

        double dist;
        double head;
        qrb(mylon * -1.0, mylat, lon * -1.0, lat, &dist, &head);
        new_country->bearing = qRound(head); // round azimuth to nearest degree
        sunTimes(lat, lon, new_country->sun);

        i1                   = buffer.indexOf(":", i2 + 1);
        new_country->delta_t = buffer.mid(i2 + 1, i1 - i2 - 1).trimmed().toFloat();

        i2                   = buffer.indexOf(":", i1 + 1);
        new_country->MainPfx = buffer.mid(i1 + 1, i2 - i1 - 1);
        new_country->MainPfx = new_country->MainPfx.trimmed();

        if (new_country->MainPfx.contains("*")) {
            if (ZoneType == 0) {
                // CQ country
                new_country->MainPfx.replace("*", "");
                nCQCty++;
            } else {
                // only keeping ARRL countries, skip this one
                delete new_country;
                continue;
            }
        } else {
            nARRLCty++;
        }

        // country has multiple zones?
        if (buffer_e != "") {
            new_country->multipleZones = true;
            QList<QByteArray> tmpl = buffer_e.split(';');
            tmpl.removeLast();  // for some reason get 1 too many here
            for (int i = 0; i < tmpl.size(); i++) {
                i1 = tmpl[i].indexOf("#");
                i2 = tmpl[i].indexOf(":");
                QByteArray pf = tmpl[i].mid(i1 + 1, i2 - i1 - 1);
                pf = pf.trimmed();

                // remove any final digit in the prefix
                if (isDigit(pf.at(pf.size() - 1))) {
                    pf.chop(1);
                }

                // remove initial pfx and final ;
                tmpl[i] = tmpl[i].mid(i2 + 1, tmpl[i].size() - 2);
                QList<QByteArray> tmpl2 = tmpl[i].split(',');  // separate
                for (int j = 0; j < tmpl2.size(); j++) {
                    tmpl2[j] = tmpl2[j].trimmed();
                    tmpl2[j].replace(pf, "");

                    // does it have a ITU zone exception?
                    ituz = 0;
                    if (tmpl2[j].contains("[")) {
                        i3 = tmpl2[j].indexOf("[");
                        i4 = tmpl2[j].indexOf("]");
                        if (i3 != -1 && i4 != -1) {
                            tmp2     = tmpl2[j].mid(i3 + 1, i4 - i3 - 1);
                            ituz     = tmp2.toInt();
                            tmp2     = tmpl2[j].mid(i3, i4 - i3 + 1);
                            tmpl2[j] = tmpl2[j].replace(tmp2, "");
                        }
                    }
                    cqz = 0;

                    // does it have a CQ zone exception?
                    if (tmpl2[j].contains("(")) {
                        i3 = tmpl2[j].indexOf("(");
                        i4 = tmpl2[j].indexOf(")");
                        if (i3 != -1 && i4 != -1) {
                            tmp2     = tmpl2[j].mid(i3 + 1, i4 - i3 - 1);
                            cqz      = tmp2.toInt();
                            tmp2     = tmpl2[j].mid(i3, i4 - i3 + 1);
                            tmpl2[j] = tmpl2[j].replace(tmp2, "");
                        }
                    }
                    new_country->zonePfx.append(tmpl2[j]);
                    if (ZoneType) {
                        if (ituz) {
                            new_country->zones.append(ituz);
                        } else {
                            new_country->zones.append(ituzone);
                        }
                    } else {
                        if (cqz) {
                            new_country->zones.append(cqz);
                        } else {
                            new_country->zones.append(cqzone);
                        }
                    }
                }
            }
        }

        // alias prefixes, may include zone exceptions
        i1 = 0;
        i2 = buffer_a.indexOf(",", i1 + 1);
        if (i2 == -1) i2 = buffer_a.size() - 1;
        int nalias = 0;
        while (i1 < (buffer_a.size() - 1)) {
            tmp = buffer_a.mid(i1, i2 - i1);
            tmp = tmp.trimmed();
            if (tmp.startsWith("=")) {
                i0 = 1; // call exception
            } else {
                i0 = 0; // alias prefix
                nalias++;
            }
            ituz = -1; // -1 is marker to use regular zone in pfx list
            cqz  = -1;

            // does it have a ITU zone exception?
            if (tmp.contains("[")) {
                i3 = tmp.indexOf("[");
                i4 = tmp.indexOf("]");
                if (i3 != -1 && i4 != -1) {
                    tmp2 = tmp.mid(i3 + 1, i4 - i3 - 1);
                    ituz = tmp2.toInt();
                    tmp2 = tmp.mid(i3, i4 - i3 + 1);
                    tmp  = tmp.replace(tmp2, "");
                }
            }

            // does it have a CQ zone exception?
            if (tmp.contains("(")) {
                i3 = tmp.indexOf("(");
                i4 = tmp.indexOf(")");
                if (i3 != -1 && i4 != -1) {
                    tmp2 = tmp.mid(i3 + 1, i4 - i3 - 1);
                    cqz  = tmp2.toInt();
                    tmp2 = tmp.mid(i3, i4 - i3 + 1);
                    tmp  = tmp.replace(tmp2, "");
                }
            }

            if (!i0) {
                // new alias prefix
                Pfx* new_pfx = new Pfx;
                new_pfx->CtyIndx      = indx;
                new_pfx->zoneOverride = true;
                if (ZoneType) {
                    new_pfx->Zone = ituz;
                } else {
                    new_pfx->Zone = cqz;
                }
                if (new_pfx->Zone == -1) {
                    new_pfx->Zone         = new_country->Zone;
                    new_pfx->zoneOverride = false;
                }

                new_pfx->prefix = tmp;
                pfxList.append(new_pfx);
            } else {
                // new exception call
                CtyCall* new_call = new CtyCall;
                new_call->call = tmp.right(tmp.size() - 1);
                if (ZoneType) {
                    if (ituz != -1) {
                        new_call->Zone = ituz;
                    } else {
                        new_call->Zone = new_country->Zone;
                    }
                } else {
                    if (cqz != -1) {
                        new_call->Zone = cqz;
                    } else {
                        new_call->Zone = new_country->Zone;
                    }
                }
                if (cqz == -1 && ituz == -1) {
                    // it NEITHER zone was defined, add call to exception list
                    // (with default zones set above). This is mostly for weird/unexpected calls
                    new_call->CtyIndx = indx;
                    new_call->sun=new_country->sun;
                    CallE.append(new_call);
                } else if ((!ZoneType && cqz == -1) || (ZoneType && ituz == -1)) {
                    // the exception doesn't have ONE of the zones defined, remove it
                    // (some entries in cty file only have CQ or ITU zones defined, but
                    // not both. In IARU contest for example, do not want CQ zone exceptions
                    // to be kept
                    delete new_call;
                } else {
                    new_call->CtyIndx = indx;
                    new_call->sun=zoneSun.at(new_call->Zone);
                    CallE.append(new_call);
                }
            }

            i1 = i2 + 1;
            i2 = buffer_a.indexOf(",", i1 + 1);
            if (i2 == -1) {
                i2 = buffer_a.size() - 1;
            }
        }
        countryList.append(new_country);

        // special case: some countries (4U1U, ...) have no alias prefixes listed, only exception calls.
        // make sure to add to main pfx list!
        if (nalias == 0) {
            Pfx* new_pfx = new Pfx;
            new_pfx->zoneOverride = false;
            new_pfx->CtyIndx      = indx;
            if (ZoneType) {
                new_pfx->Zone = ituz;
            } else {
                new_pfx->Zone = cqz;
            }
            if (new_pfx->Zone == -1) {
                new_pfx->Zone = new_country->Zone;
            }
            new_pfx->prefix = new_country->MainPfx;
            pfxList.append(new_pfx);
        }

        indx++;
    }

    /*!
       @todo define < operator so qsort can be used sort prefix and call exception lists
     */

    // prefix
    for (int i = 1; i < pfxList.size(); i++) {
        QByteArray tmp = pfxList[i]->prefix;
        int        i0  = pfxList[i]->Zone;
        int        i1  = pfxList[i]->CtyIndx;
        bool       i2  = pfxList[i]->zoneOverride;
        int        j   = i - 1;
        while (j >= 0 && pfxList[j]->prefix > tmp) {
            pfxList[j + 1]->prefix       = pfxList[j]->prefix;
            pfxList[j + 1]->Zone         = pfxList[j]->Zone;
            pfxList[j + 1]->CtyIndx      = pfxList[j]->CtyIndx;
            pfxList[j + 1]->zoneOverride = pfxList[j]->zoneOverride;
            j--;
        }
        pfxList[j + 1]->prefix       = tmp;
        pfxList[j + 1]->Zone         = i0;
        pfxList[j + 1]->CtyIndx      = i1;
        pfxList[j + 1]->zoneOverride = i2;
    }

    // exception
    for (int i = 1; i < CallE.size(); i++) {
        QByteArray tmp = CallE[i]->call;
        QString suntmp= CallE[i]->sun;
        int        i0  = CallE[i]->Zone;
        int        i1  = CallE[i]->CtyIndx;
        int        j   = i - 1;
        while (j >= 0 && CallE[j]->call > tmp) {
            CallE[j + 1]->call    = CallE[j]->call;
            CallE[j + 1]->sun    = CallE[j]->sun;
            CallE[j + 1]->Zone    = CallE[j]->Zone;
            CallE[j + 1]->CtyIndx = CallE[j]->CtyIndx;
            j--;
        }
        CallE[j + 1]->call    = tmp;
        CallE[j + 1]->sun    = suntmp;
        CallE[j + 1]->Zone    = i0;
        CallE[j + 1]->CtyIndx = i1;
    }

    // save index for US
    Qso  tmpqso;
    tmpqso.call = "W1AW";
    bool b;
    usaIndx = idPfx(&tmpqso, b);
}
Example #16
0
  ControlNet * CnetEditorWidget::filteredNetwork() const {
    ControlNet * filteredCnet = new ControlNet(*m_controlNet);

    QList<AbstractTreeItem *> networkItems = m_pointModel->getItems(0, -1,
        AbstractTreeModel::MeasureItems | AbstractTreeModel::PointItems, true);

    // Iterate through our copy of the cnet, deleting anything that doesn't
    //   exactly match our networkItems.
    for (int pointIndex = filteredCnet->GetNumPoints() - 1;
         pointIndex >= 0;
         pointIndex--) {
      if (networkItems.isEmpty()) {
        ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
        cp->SetEditLock(false);

        for (int measureIndex = 0;
             measureIndex < cp->GetNumMeasures();
             measureIndex++) {
          cp->GetMeasure(measureIndex)->SetEditLock(false);
        }

        filteredCnet->DeletePoint(cp);
      }
      else if (networkItems.last()->getPointerType() ==
               AbstractTreeItem::Point) {
        ControlPoint *networkItemsCp =
            (ControlPoint *)networkItems.last()->getPointer();
        ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
        if (cp->GetId() != networkItemsCp->GetId()) {
          cp->SetEditLock(false);

          for (int measureIndex = 0;
               measureIndex < cp->GetNumMeasures();
               measureIndex++) {
            cp->GetMeasure(measureIndex)->SetEditLock(false);
          }

          filteredCnet->DeletePoint(cp);
        }
        else {
          networkItems.removeLast();
        }
      }
      else if (networkItems.last()->getPointerType() ==
               AbstractTreeItem::Measure) {
        ControlPoint *cp = filteredCnet->GetPoint(pointIndex);
        ControlMeasure *networkItemsCm =
            (ControlMeasure *)networkItems.last()->getPointer();

        if (cp->GetId() != networkItemsCm->Parent()->GetId()) {
          cp->SetEditLock(false);

          for (int measureIndex = 0;
               measureIndex < cp->GetNumMeasures();
               measureIndex++) {
            cp->GetMeasure(measureIndex)->SetEditLock(false);
          }

          filteredCnet->DeletePoint(cp);
        }
        else {
          // Our CP stays, figure out which CMs stay.
          for (int measureIndex = cp->GetNumMeasures() - 1;
               networkItemsCm && measureIndex >= 0;
               measureIndex--) {
            ControlMeasure *cm = cp->GetMeasure(measureIndex);
            if (cm->GetCubeSerialNumber() !=
                networkItemsCm->GetCubeSerialNumber()) {
              cm->SetEditLock(false);
              cp->Delete(cm);
            }
            else {
              networkItems.removeLast();
              networkItemsCm = NULL;

              if (networkItems.last()->getPointerType() ==
                       AbstractTreeItem::Measure) {
                networkItemsCm =
                    (ControlMeasure *)networkItems.last()->getPointer();
              }
            }
          }

          // We still need to verify the copied CP at this index... although
          //   nothing should go wrong, we know things do go wrong so do
          //   the verify instead of just tossing the last networkItems item.
          pointIndex++;
        }
      }
    }

    return filteredCnet;
  }