Exemple #1
0
QT_BEGIN_NAMESPACE

/*
    This function looks at two file names and returns the name of the
    infile with a path relative to outfile.

    Examples:

        /tmp/abc, /tmp/bcd -> abc
        xyz/a/bc, xyz/b/ac -> ../a/bc
        /tmp/abc, xyz/klm -> /tmp/abc
 */

static QByteArray combinePath(const QString &infile, const QString &outfile)
{
    QFileInfo inFileInfo(QDir::current(), infile);
    QFileInfo outFileInfo(QDir::current(), outfile);
    const QByteArray relativePath = QFile::encodeName(outFileInfo.dir().relativeFilePath(inFileInfo.filePath()));
#ifdef Q_OS_WIN
    // It's a system limitation.
    // It depends on the Win API function which is used by the program to open files.
    // cl apparently uses the functions that have the MAX_PATH limitation.
    if (outFileInfo.dir().absolutePath().length() + relativePath.length() + 1 >= 260)
        return QFile::encodeName(inFileInfo.absoluteFilePath());
#endif
    return relativePath;
}
Exemple #2
0
QByteArray combinePath(const char *infile, const char *outfile)
{
    QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile));
    QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile));
    int numCommonComponents = 0;

    QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/'));
    QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/'));

    while (!inSplitted.isEmpty() && !outSplitted.isEmpty() &&
            inSplitted.first() == outSplitted.first()) {
        inSplitted.erase(inSplitted.begin());
        outSplitted.erase(outSplitted.begin());
        numCommonComponents++;
    }

    if (numCommonComponents < 2) {
        /*
          The paths don't have the same drive, or they don't have the
          same root directory. Use an absolute path.
        */
        return QFile::encodeName(inFileInfo.absoluteFilePath());
    } else {
        /*
          The paths have something in common. Use a path relative to
          the output file.
        */
        while (!outSplitted.isEmpty()) {
            outSplitted.erase(outSplitted.begin());
            inSplitted.prepend(QLatin1String(".."));
        }
        inSplitted.append(inFileInfo.fileName());
        return QFile::encodeName(inSplitted.join(QLatin1String("/")));
    }
}
Exemple #3
0
QT_BEGIN_NAMESPACE

/*
    This function looks at two file names and returns the name of the
    infile with a path relative to outfile.

    Examples:

        /tmp/abc, /tmp/bcd -> abc
        xyz/a/bc, xyz/b/ac -> ../a/bc
        /tmp/abc, xyz/klm -> /tmp/abc
 */

static QByteArray combinePath(const char *infile, const char *outfile)
{
    QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile));
    QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile));
    int numCommonComponents = 0;

    QStringList inSplitted = inFileInfo.dir().canonicalPath().split(QLatin1Char('/'));
    QStringList outSplitted = outFileInfo.dir().canonicalPath().split(QLatin1Char('/'));

    while (!inSplitted.isEmpty() && !outSplitted.isEmpty() &&
            inSplitted.first() == outSplitted.first()) {
        inSplitted.removeFirst();
        outSplitted.removeFirst();
        numCommonComponents++;
    }

    if (numCommonComponents < 2)
        /*
          The paths don't have the same drive, or they don't have the
          same root directory. Use an absolute path.
        */
        return QFile::encodeName(inFileInfo.absoluteFilePath());
    /*
       The paths have something in common. Use a path relative to
       the output file.
     */
    while (!outSplitted.isEmpty()) {
        outSplitted.removeFirst();
        inSplitted.prepend(QLatin1String(".."));
    }
    inSplitted.append(inFileInfo.fileName());
    return QFile::encodeName(inSplitted.join(QLatin1String("/")));
}
Exemple #4
0
QT_BEGIN_NAMESPACE

/*
    This function looks at two file names and returns the name of the
    infile with a path relative to outfile.

    Examples:

        /tmp/abc, /tmp/bcd -> abc
        xyz/a/bc, xyz/b/ac -> ../a/bc
        /tmp/abc, xyz/klm -> /tmp/abc
 */

static QByteArray combinePath(const char *infile, const char *outfile)
{
    QFileInfo inFileInfo(QDir::current(), QFile::decodeName(infile));
    QFileInfo outFileInfo(QDir::current(), QFile::decodeName(outfile));
    return QFile::encodeName(outFileInfo.dir().relativeFilePath(inFileInfo.filePath()));
}
void Professional::OpenProfessionalSourceFile(){
    QString tempElement, tempText;
    QString fileName = QFileDialog::getOpenFileName(0, QWidget::tr("Open Category Text File"),QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).at(0), "Text files (*.txt)");
    QByteArray line = NULL;
    QFile inFile(fileName);
    QFileInfo inFileInfo(inFile);
    categoriesPath  = inFileInfo.dir().path();
    if (!inFile.open(QIODevice::ReadOnly)) {
        qDebug() << inFile.errorString();
        QMessageBox msgBox;
        msgBox.setText("Δεν έχετε επιλέξει αρχείο\nή το αρχείο είναι κατεστραμμένο!");
        msgBox.exec();
    }else{
        QFile outFile(categoriesPath + "/epaggelmatikos_source_sample.xml");
        outFile.open(QIODevice::WriteOnly);
        QXmlStreamWriter xmlWriter(&outFile);
        xmlWriter.setAutoFormatting(false);
        xmlWriter.writeStartDocument("1.0", true);
        xmlWriter.writeStartElement("ROOT");
        xmlWriter.writeStartElement("categories");
        int counter = 0;
        while (!inFile.atEnd()) {
            line = inFile.readLine();
            tempText = line;
            tempElement = line.remove(0,1);
            tempElement = tempElement.remove(QRegExp("=.*"));
            tempText = tempText.remove(QRegExp("@.*="));
            if(tempElement == "KATHG" && counter > 0){
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
                xmlWriter.writeCharacters("\n");
                xmlWriter.writeStartElement("category");
                xmlWriter.writeTextElement(tempElement,tempText.simplified());
                xmlWriter.writeStartElement("entries");
            }
            else if (tempElement == "KATHG") {
                xmlWriter.writeStartElement("category");
                xmlWriter.writeTextElement(tempElement,tempText.simplified());
                xmlWriter.writeStartElement("entries");
            }
            else if(tempElement == "ONOMA"
                    || tempElement == "ONOMA-B"
                    || tempElement == "ONOMA-S" ) {
                xmlWriter.writeEndElement();
                xmlWriter.writeStartElement("entry");
                xmlWriter.writeTextElement(tempElement,tempText.simplified());
            }
            else if(tempElement == "KIMENO-B" || tempElement == "KIMENO-S"){
                xmlWriter.writeTextElement(tempElement,tempText.simplified() );
            }
            else if(tempElement == "TEL-B" || tempElement == "TEL-S"){
                xmlWriter.writeTextElement(tempElement,tempText.simplified());
            }
            else if(tempElement == "DIEYT1"
                    || tempElement == "DIEYT1-B"
                    || tempElement == "DIEYT1-S"){
                xmlWriter.writeTextElement(tempElement,tempText.simplified().replace(" <9>","\t").replace("<9>","\t"));
            }
            else if(tempElement == "DIEYT2"
                    || tempElement == "DIEYT2-B"
                    || tempElement == "DIEYT2-S"){
                xmlWriter.writeTextElement(tempElement,tempText.simplified().replace(" <9>","\t").replace("<9>","\t"));
            }
            counter ++;
        }
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        xmlWriter.writeEndElement();
        inFile.close();
        outFile.close();
        CreateProfessionalXML(categoriesPath);
    }
}