void SelectStuForAddDetails::setClassList()
{
    QFile openConfigFile(filepath);
    if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
    {
        qDebug()<<"error";

    }
    else
    {
        QDomDocument document;

        document.setContent(&openConfigFile);
        QDomElement root= document.firstChildElement();

        QDomNodeList grades = root.elementsByTagName("Grade");


        for(int i=0;i<grades.count();i++)
        {

            QDomNode itemNode = grades.at(i);

            if(itemNode.isElement())
            {
                QTreeWidgetItem *grade= new QTreeWidgetItem(ui->tWSelectClass);
                grade->setText(0,itemNode.toElement().attribute("GradeName"));
                grade->setIcon(0,QIcon(":/binduTeacher/new/imgs/grade.png"));


                QDomNodeList classeList= itemNode.toElement().elementsByTagName("Class");

                    for(int j=0;j<classeList.count();j++)
                    {
                        QDomNode itemNodeClass = classeList.at(j);
                        QTreeWidgetItem *classItem= new QTreeWidgetItem(grade);
                        classItem->setText(0,itemNodeClass.toElement().attribute("ClassName"));
                        classItem->setIcon(0,QIcon(":/binduTeacher/new/imgs/class.png"));



                    }




              ui->tWSelectClass->addTopLevelItem(grade);


            }




       }


   }

}
Exemplo n.º 2
0
char *
afstest_BuildTestConfig(void) {
    char *dir = NULL;
    FILE *file;
    struct hostent *host;
    char hostname[255];
    struct in_addr iaddr;

    if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1)
	goto fail;

    if (mkdtemp(dir) == NULL)
	goto fail;

    /* Work out which IP address to use in our CellServDB. We figure this out
     * according to the IP address which ubik is most likely to pick for one of
     * our db servers */

    gethostname(hostname, sizeof(hostname));
    host = gethostbyname(hostname);
    if (!host)
	return NULL;

    memcpy(&iaddr, host->h_addr, 4);

    file = openConfigFile(dir, "CellServDB");
    fprintf(file, ">example.org # An example cell\n");
    fprintf(file, "%s #test.example.org\n", inet_ntoa(iaddr));
    fclose(file);

    /* Create a ThisCell file */
    file = openConfigFile(dir, "ThisCell");
    fprintf(file, "example.org");
    fclose(file);

    return dir;

fail:
    if (dir)
	free(dir);
    return NULL;
}
void SelectStuForAddDetails::on_tWSelectClass_clicked(const QModelIndex &index)
{
    ui->lWStudent->clear();

    if(ui->tWSelectClass->currentIndex().parent().isValid())
    {

        QFile openConfigFile(filepath);
        if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
        {
            qDebug()<<"error";

        }
        else
        {
            QDomDocument document;

            document.setContent(&openConfigFile);
            QDomElement root= document.firstChildElement();

            QDomNodeList grades = root.elementsByTagName("Grade");


            for(int i=0;i<grades.count();i++)
            {

                QDomNode itemNode = grades.at(i);

                if(itemNode.isElement())
                {
                    if(itemNode.toElement().attribute("GradeName")==ui->tWSelectClass->currentItem()->parent()->text(0))
                    {
                        QDomNodeList classeList= itemNode.toElement().elementsByTagName("Class");

                            for(int j=0;j<classeList.count();j++)
                            {
                                QDomNode itemNodeClass = classeList.at(j);
                                if(itemNodeClass.toElement().attribute("ClassName")==ui->tWSelectClass->currentItem()->text(0))
                                {
                                    QDomNodeList studentList=itemNodeClass.toElement().elementsByTagName("students");
                                    QDomNode students=studentList.at(0);
                                    QString studentNameList=students.firstChild().nodeValue();
                                    //qDebug()<<studentNameList<<"student NameList";
                                    QStringList studentNameSplitedList=studentNameList.split(",");
                                    foreach (QString studentName, studentNameSplitedList)
                                    {
                                        //QListWidgetItem
                                       //ui->lWStudent->addItem(studentName);
                                        ui->lWStudent->addItem(new QListWidgetItem(QIcon(":/binduTeacher/new/imgs/student.jpg"), studentName));

                                    }



                                    break;

                                }




                            }
                            break;

                    }


                  //ui->tWSelectClass->addTopLevelItem(grade);


                }
Exemplo n.º 4
0
void OpenHomeWork::on_tWSelectSubject_clicked(const QModelIndex &index)
{
    ui->lWHomeWorks->clear();
    //int x=0;
//    if(!ui->tWSelectSubject->currentIndex().isValid()||!ui->tWSelectSubject->currentIndex().parent().isValid())
//    {
//        QMessageBox::information(this,"Error","Select Subject");
//        x=1;

//    }
    if(ui->tWSelectSubject->currentIndex().parent().isValid())
    {
        QFile openConfigFile(filepath);
        if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
        {
            qDebug()<<"error";

        }
        else
        {
            QDomDocument document;

            document.setContent(&openConfigFile);
            QDomElement root= document.firstChildElement();

            QDomNodeList grades = root.elementsByTagName("Grade");


            for(int i=0;i<grades.count();i++)
            {

                QDomNode itemNode = grades.at(i);

                if(itemNode.isElement())
                {
                    if(itemNode.toElement().attribute("GradeName")==ui->tWSelectSubject->currentItem()->parent()->text(0))
                    {
                        QDomNodeList classList= itemNode.toElement().elementsByTagName("Subject");

                            for(int j=0;j<classList.count();j++)
                            {

                                QDomNode itemNodeClass = classList.at(j);

                                 if(itemNodeClass.toElement().attribute("SubjectName")==ui->tWSelectSubject->currentItem()->text(0))
                                 {
                                     if(itemNodeClass.isElement())
                                     {
                                         QDomNodeList paperNameList=itemNodeClass.toElement().elementsByTagName("HomeWork");
                                         for(int z=0;z<paperNameList.size();z++)
                                         {
                                             QDomNode paper=paperNameList.at(z);
                                            //ui->lWHomeWorks->addItem( paper.toElement().attribute("HomeWorkName"));
                                            ui->lWHomeWorks->addItem(new QListWidgetItem(QIcon(":/binduTeacher/new/imgs/paper.png"), paper.toElement().attribute("HomeWorkName")));

                                         }

                                     }


                                 }


                            }
                            //break;

                    }



                }




           }


       }

    }




}
Exemplo n.º 5
0
void OpenHomeWork::on_pBDeleteHomeWork_clicked()
{
    int x=0;
    if(!ui->tWSelectSubject->currentIndex().isValid()||!ui->tWSelectSubject->currentIndex().parent().isValid())
    {
        QMessageBox::warning(this,"Error","Select Subject");
       x=1;

    }
    if(!ui->lWHomeWorks->currentIndex().isValid())
    {
        QMessageBox::warning(this,"Error","Select Paper");
       x=1;

    }

    if(x==0)
    {QString creatingPaperPath=basicPath;
        creatingPaperPath.append("HomeWork/");
        creatingPaperPath.append(ui->tWSelectSubject->currentItem()->parent()->text(0));
        creatingPaperPath.append("/");
        creatingPaperPath.append(ui->tWSelectSubject->currentItem()->text(0));
        creatingPaperPath.append("/");
        creatingPaperPath.append(ui->lWHomeWorks->currentItem()->text());
        creatingPaperPath.append(".xml");




        QFile paperfile(creatingPaperPath);
        if(paperfile.exists())
        {

            paperfile.remove();
        }



        //delete in admin.xml
        QFile openConfigFile(filepath);
        if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
        {
            qDebug()<<"error";

        }
        else
        {
            QDomDocument document;

            document.setContent(&openConfigFile);
            QDomElement root= document.firstChildElement();

            QDomNodeList grades = root.elementsByTagName("Grade");


            for(int i=0;i<grades.count();i++)
            {

                QDomNode itemNode = grades.at(i);

                if(itemNode.isElement())
                {
                    if(itemNode.toElement().attribute("GradeName")==ui->tWSelectSubject->currentItem()->parent()->text(0))
                    {
                        QDomNodeList subjectList= itemNode.toElement().elementsByTagName("Subject");

                        for(int j=0;j<subjectList.count();j++)
                        {
                             QDomNode itemNodeSubject = subjectList.at(j);
                             if(itemNodeSubject.toElement().attribute("SubjectName")==ui->tWSelectSubject->currentItem()->text(0))
                             {
                                 QDomNodeList HomeWorkList=itemNodeSubject.toElement().elementsByTagName("HomeWork");

                                 for(int z=0;z<HomeWorkList.count();z++)
                                 {

                                     QDomNode itemNodeHomeWork= HomeWorkList.at(z);

                                     if(itemNodeHomeWork.toElement().attribute("HomeWorkName")==ui->lWHomeWorks->currentItem()->text())
                                     {
                                         itemNodeSubject.toElement().removeChild(HomeWorkList.at(z));
                                         QMessageBox::warning(this,"Error","Home Work removed");

                                     }



                                 }



                             }

                        }



                    }



                }




           }


            //root.appendChild(Activity);
            document.appendChild(root);

            openConfigFile.close();

            if(!openConfigFile.open(QFile::ReadWrite|QIODevice::Truncate | QIODevice::Text))
            {
                qDebug()<<"error";

            }
            else
            {
                QTextStream stream(&openConfigFile);
                stream <<document.toString();
                openConfigFile.close();



            }

            ui->tWSelectSubject->clear();
            ui->lWHomeWorks->clear();
            setSubjetToTree();



       }

    }

}
Exemplo n.º 6
0
void OpenHomeWork::setSubjetToTree()
{

    //QTreeWidgetItem *item= new QTreeWidgetItem(ui->tWSelectSubject);
    //item->setText(0,"dfdfdfdfdf");
    //ui->tWSelectSubject->addTopLevelItem(item);




    QFile openConfigFile(filepath);
    if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
    {
        qDebug()<<"error";

    }
    else
    {
        QDomDocument document;

        document.setContent(&openConfigFile);
        QDomElement root= document.firstChildElement();

        QDomNodeList grades = root.elementsByTagName("Grade");


        for(int i=0;i<grades.count();i++)
        {

            QDomNode itemNode = grades.at(i);

            if(itemNode.isElement())
            {
                QTreeWidgetItem *grade= new QTreeWidgetItem(ui->tWSelectSubject);
                grade->setText(0,itemNode.toElement().attribute("GradeName"));
                 grade->setIcon(0,QIcon(":/binduTeacher/new/imgs/grade.png"));


                QDomNodeList classList= itemNode.toElement().elementsByTagName("Subject");

                    for(int j=0;j<classList.count();j++)
                    {

                        QDomNode itemNodeClass = classList.at(j);
                        // ui->cBSelectClass->addItem(itemNodeClass.toElement().attribute("ClassName"));
                         QTreeWidgetItem *subjectItem= new QTreeWidgetItem(grade);
                         subjectItem->setText(0,itemNodeClass.toElement().attribute("SubjectName"));
                         subjectItem->setIcon(0,QIcon(":/binduTeacher/new/imgs/subject.png"));

                    }




              ui->tWSelectSubject->addTopLevelItem(grade);


            }




       }


   }


}
Exemplo n.º 7
0
void OpenHomeWork::on_pBOpen_clicked()
{
    int x=0;
    if(!ui->tWSelectSubject->currentIndex().isValid()||!ui->tWSelectSubject->currentIndex().parent().isValid())
    {
        QMessageBox::warning(this,"Error","Select Subject");
       x=1;

    }
    if(!ui->lWHomeWorks->currentIndex().isValid())
    {
        QMessageBox::warning(this,"Error","Select Paper");
       x=1;

    }
    if(ui->tWSelectSubject->currentIndex().parent().isValid()&&(ui->lWHomeWorks->currentIndex().isValid()))
    {
        QFile openConfigFile(filepath);
        if(!openConfigFile.open(QFile::ReadWrite| QIODevice::Text))
        {
            qDebug()<<"error";

        }
        else
        {
            QDomDocument document;

            document.setContent(&openConfigFile);
            QDomElement root= document.firstChildElement();

            QDomNodeList grades = root.elementsByTagName("Grade");


            for(int i=0;i<grades.count();i++)
            {

                QDomNode itemNode = grades.at(i);

                if(itemNode.isElement())
                {
                    if(itemNode.toElement().attribute("GradeName")==ui->tWSelectSubject->currentItem()->parent()->text(0))
                    {
                        QDomNodeList classList= itemNode.toElement().elementsByTagName("Subject");

                            for(int j=0;j<classList.count();j++)
                            {

                                QDomNode itemNodeClass = classList.at(j);

                                 if(itemNodeClass.toElement().attribute("SubjectName")==ui->tWSelectSubject->currentItem()->text(0))
                                 {
                                     if(itemNodeClass.isElement())
                                     {
                                         QDomNodeList paperNameList=itemNodeClass.toElement().elementsByTagName("HomeWork");
                                         for(int z=0;z<paperNameList.size();z++)
                                         {
                                             QDomNode paper=paperNameList.at(z);
                                             if(paper.toElement().attribute("HomeWorkName")==ui->lWHomeWorks->currentItem()->text())
                                             {
                                                 QString newfilepath=basicPath;
                                                 newfilepath.append("HomeWork/");
                                                 newfilepath.append(ui->tWSelectSubject->currentItem()->parent()->text(0));
                                                // QString newfilepath=qPaperSavefilepath.append(ui->tWSelectSubject->currentItem()->parent()->text(0));
                                                 newfilepath.append("/");
                                                 newfilepath.append(ui->tWSelectSubject->currentItem()->text(0));
                                                 newfilepath.append("/");
                                                 newfilepath.append(ui->lWHomeWorks->currentItem()->text());
                                                 newfilepath.append(".xml");

                                                 if(paper.toElement().attribute("Type")=="Mcq")
                                                 {
                                                     mewMcqPaper= new NewMcqPaper(0,newfilepath);
                                                     mewMcqPaper->setModal(false);
                                                     this->close();
                                                     mewMcqPaper->exec();


                                                 }
                                                 if(paper.toElement().attribute("Type")=="Essay")
                                                 {
                                                     newEssayPaper= new NewEssayPaper(0,newfilepath);
                                                     newEssayPaper->setModal(false);
                                                     this->close();
                                                     newEssayPaper->exec();

                                                 }
                                                 if(paper.toElement().attribute("Type")=="EssayMcq")
                                                 {
                                                     newMixPaper = new NewMixPaper(0,newfilepath);
                                                     newMixPaper->setModal(false);
                                                     this->close();
                                                     newMixPaper->exec();

                                                 }
                                                 break;

                                             }
                                            //ui->lWHomeWorks->addItem( paper.toElement().attribute("HomeWorkName"));

                                         }

                                     }


                                 }


                            }
                            //break;

                    }



                }




           }


       }

    }

}
Exemplo n.º 8
0
/**
*   Loads the configuration from file, and stores the config in 
*   respective holders...
*/                 
int loadConfig(char *configFile) {
    struct vifconfig  *tmpPtr;
    struct vifconfig  **currPtr = &vifconf;
    char *token;
    
    // Initialize common config
    initCommonConfig();

    // Test config file reader...
    if(!openConfigFile(configFile)) {
        log(LOG_ERR, 0, "Unable to open configfile from %s", configFile);
    }

    // Get first token...
    token = nextConfigToken();
    if(token == NULL) {
        log(LOG_ERR, 0, "Config file was empty.");
    }

    // Loop until all configuration is read.
    while ( token != NULL ) {
        // Check token...
        if(strcmp("phyint", token)==0) {
            // Got a phyint token... Call phyint parser
            IF_DEBUG log(LOG_DEBUG, 0, "Config: Got a phyint token.");
            tmpPtr = parsePhyintToken();
            if(tmpPtr == NULL) {
                // Unparsable token... Exit...
                closeConfigFile();
                log(LOG_WARNING, 0, "Unknown token '%s' in configfile", token);
                return 0;
            } else {

                IF_DEBUG log(LOG_DEBUG, 0, "IF name : %s", tmpPtr->name);
                IF_DEBUG log(LOG_DEBUG, 0, "Next ptr : %x", tmpPtr->next);
                IF_DEBUG log(LOG_DEBUG, 0, "Ratelimit : %d", tmpPtr->ratelimit);
                IF_DEBUG log(LOG_DEBUG, 0, "Threshold : %d", tmpPtr->threshold);
                IF_DEBUG log(LOG_DEBUG, 0, "State : %d", tmpPtr->state);
                IF_DEBUG log(LOG_DEBUG, 0, "Allowednet ptr : %x", tmpPtr->allowednets);

                // Insert config, and move temppointer to next location...
                *currPtr = tmpPtr;
                currPtr = &tmpPtr->next;
            }
        } 
        else if(strcmp("quickleave", token)==0) {
            // Got a quickleave token....
            IF_DEBUG log(LOG_DEBUG, 0, "Config: Quick leave mode enabled.");
            commonConfig.fastUpstreamLeave = 1;
            
            // Read next token...
            token = nextConfigToken();
            continue;
        } else {
            // Unparsable token... Exit...
            closeConfigFile();
            log(LOG_WARNING, 0, "Unknown token '%s' in configfile", token);
            return 0;
        }
        // Get token that was not recognized by phyint parser.
        token = getCurrentConfigToken();
    }

    // Close the configfile...
    closeConfigFile();

    return 1;
}
Exemplo n.º 9
0
// Save settings to screen.xml
void GfglFeatures::storeSelection(void* hparmConfig) const
{
    // Display what we have selected.
    dumpSelection();

    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Write new values.
    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                 isSelected(TextureCompression)
                 ? GFSCR_ATT_TEXTURECOMPRESSION_ENABLED : GFSCR_ATT_TEXTURECOMPRESSION_DISABLED);
    if (getSupported(TextureMaxSize) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE, pszNoUnit,
                     (tdble)getSelected(TextureMaxSize));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE);

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURING,
                 isSelected(MultiTexturing)
                 ? GFSCR_ATT_MULTITEXTURING_ENABLED : GFSCR_ATT_MULTITEXTURING_DISABLED);
    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                 isSelected(MultiSampling)
                 ? GFSCR_ATT_MULTISAMPLING_ENABLED : GFSCR_ATT_MULTISAMPLING_DISABLED);
    if (getSupported(MultiSamplingSamples) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES, pszNoUnit,
                     (tdble)getSelected(MultiSamplingSamples));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);


    // Force 'best possible' mode for video initialization when anti-aliasing selected
    if (isSelected(MultiSampling))
    {
        // Use the 'in-test' specs if present, and reset the test state
        // (force a new validation).
        if (GfParmExistsSection(hparm, GFSCR_SECT_INTESTPROPS))
        {
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
                         GFSCR_VAL_INPROGRESS);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
                         GFSCR_VAL_VINIT_BEST);
        }

        // Otherwise, use the 'validated' specs ... no new validation needed
        // (if we can en/disable multi-sampling, it means that we already checked
        //  that it was possible, and how much).
        else
        {
            GfParmSetStr(hparm, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VINIT,
                         GFSCR_VAL_VINIT_BEST);
        }
    }

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                 isSelected(StereoVision)
                 ? GFSCR_ATT_STEREOVISION_ENABLED : GFSCR_ATT_STEREOVISION_DISABLED);

    GfParmSetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING,
                 isSelected(BumpMapping)
                 ? GFSCR_ATT_BUMPMAPPING_ENABLED : GFSCR_ATT_BUMPMAPPING_DISABLED);

    if (getSupported(AnisotropicFiltering) != InvalidInt)
        GfParmSetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                     (tdble)getSelected(AnisotropicFiltering));
    else
        GfParmRemove(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);

    // Write new params to config file.
    GfParmWriteFile(NULL, hparm, "Screen");

    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);
}
Exemplo n.º 10
0
// Load the selected OpenGL features from the config file.
void GfglFeatures::loadSelection(void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Select the OpenGL features according to the user settings (when relevant)
    // or/and to the supported values (by default, select the max supported values).

    // 1) Double-buffer : not user-customizable.
    _mapSelectedBool[DoubleBuffer] = isSupported(DoubleBuffer);

    // 2) Color buffer depth : not user-customizable.
    _mapSelectedInt[ColorDepth] = getSupported(ColorDepth);

    // 3) Alpha-channel depth : not user-customizable.
    _mapSelectedInt[AlphaDepth] = getSupported(AlphaDepth);

    // 4) Max texture size : load from config file.
    _mapSelectedInt[TextureMaxSize] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MAXTEXTURESIZE,
                          pszNoUnit, (tdble)getSupported(TextureMaxSize));
    if (_mapSelectedInt[TextureMaxSize] > getSupported(TextureMaxSize))
        _mapSelectedInt[TextureMaxSize] = getSupported(TextureMaxSize);

    // 5) Texture compression : load from config file.
    _mapSelectedBool[TextureCompression] =
        isSupported(TextureCompression)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                                    GFSCR_ATT_TEXTURECOMPRESSION_ENABLED))
        == GFSCR_ATT_TEXTURECOMPRESSION_ENABLED;

    // 6) Multi-texturing : load from config file.
    _mapSelectedBool[MultiTexturing] =
        isSupported(MultiTexturing)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURING,
                                    GFSCR_ATT_MULTITEXTURING_ENABLED))
        == GFSCR_ATT_MULTITEXTURING_ENABLED;
    _mapSelectedInt[MultiTexturingUnits] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS,
                          pszNoUnit, (tdble)getSupported(TextureMaxSize));
    if (_mapSelectedInt[MultiTexturingUnits] > getSupported(MultiTexturingUnits))
        _mapSelectedInt[MultiTexturingUnits] = getSupported(MultiTexturingUnits);

    // 7) Rectangle textures : not user-customizable.
    _mapSelectedBool[TextureRectangle] = isSupported(TextureRectangle);

    // 8) Non-power-of-2 textures : not user-customizable.
    _mapSelectedBool[TextureNonPowerOf2] = isSupported(TextureNonPowerOf2);

    // 9) Multi-sampling : load from config file.
    const std::string strMultiSamp =
        GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                     GFSCR_ATT_MULTISAMPLING_ENABLED);
    _mapSelectedBool[MultiSampling] =
        isSupported(MultiSampling)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLING,
                                    GFSCR_ATT_MULTISAMPLING_ENABLED))
        == GFSCR_ATT_MULTISAMPLING_ENABLED;

    _mapSelectedInt[MultiSamplingSamples] =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES,
                          pszNoUnit, (tdble)8); // Good but reasonable value.
    if (_mapSelectedInt[MultiSamplingSamples] > getSupported(MultiSamplingSamples))
        _mapSelectedInt[MultiSamplingSamples] = getSupported(MultiSamplingSamples);

    // 10) Stereo Vision : load from config file.
    const std::string strStereoVision =
        GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                     GFSCR_ATT_STEREOVISION_ENABLED);
    _mapSelectedBool[StereoVision] =
        isSupported(StereoVision)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_STEREOVISION,
                                    GFSCR_ATT_STEREOVISION_ENABLED))
        == GFSCR_ATT_STEREOVISION_ENABLED;

    // 11) Bump Mapping : load from config file.
    _mapSelectedBool[BumpMapping] =
        isSupported(BumpMapping)
        && std::string(GfParmGetStr(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_BUMPMAPPING,
                                    GFSCR_ATT_BUMPMAPPING_ENABLED))
        == GFSCR_ATT_BUMPMAPPING_ENABLED;

    // 12) Anisotropic Filtering : load from config file.
    _mapSelectedInt[AnisotropicFiltering] = (int)GfParmGetNum(hparm, GFSCR_SECT_GLSELFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
                                            pszNoUnit, (tdble)getSupported(AnisotropicFiltering));
    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Display what we have really selected (after checking / fixing to supported values).
    dumpSelection();
}
Exemplo n.º 11
0
bool GfglFeatures::checkBestSupport(int nWidth, int nHeight, int nDepth,
                                    bool bAlpha, bool bFullScreen, bool bBump, bool bStereo,int nAniFilt, void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Get the frame buffer specs that are associated with the detected
    // Open GL features in the config file, if any.
    int nDetWidth, nDetHeight, nDetDepth, nDetAni;
    bool bDetFullScreen, bDetAlpha, bDetBump, bDetStereo;
    bool bPrevSupportFound =
        loadSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm);

    // Compare with the requested frame buffer specs
    // and run a new supported feature detection if any diffference.
    bool bSupportFound = true;
    if (!bPrevSupportFound || nWidth != nDetWidth || nHeight != nDetHeight || nDepth != nDetDepth
            || bAlpha != bDetAlpha || bFullScreen != bDetFullScreen || bStereo != bDetStereo || bBump != bDetBump || nAniFilt!= nDetAni)
    {
        nDetWidth = nWidth;
        nDetHeight = nHeight;
        nDetDepth = nDepth;
        bDetFullScreen = bFullScreen;
        bDetAlpha = bAlpha;
        bDetStereo = bStereo;
        bDetBump = bBump;
        nDetAni = nAniFilt;
        bSupportFound =
            detectBestSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo, nDetAni);

        // Store support data in any case.
        storeSupport(nDetWidth, nDetHeight, nDetDepth, bDetAlpha, bDetFullScreen, bDetBump, bDetStereo,nDetAni, hparm);

        // If frame buffer specs supported, update relevant user settings and restart.
        if (bSupportFound)
        {
            // Write new user settings about the frame buffer specs
            // (the detection process might have down-casted them ...).
            // Note: Sure the specs are in the 'in-test' state here,
            //       otherwise they would not have changed.
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_X, pszNoUnit,
                         (tdble)nDetWidth);
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_WIN_Y, pszNoUnit,
                         (tdble)nDetHeight);
            GfParmSetNum(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_BPP, pszNoUnit,
                         (tdble)nDetDepth);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_ALPHACHANNEL,
                         bDetAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_FSCR,
                         bDetFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);

            // But make sure they are not validated yet at restart (only next time if OK).
            GfParmSetStr(hparm, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_TESTSTATE,
                         GFSCR_VAL_TODO);

            // Write new params to config file.
            GfParmWriteFile(NULL, hparm, "Screen");

            // Close the config file ...
            closeConfigFile(hparm);

            // ... as we are restarting ...
            GfuiApp().restart();

            // Next time we pass in this function, loadSupport() will give
            // the right values for all features ...
        }
    }

    if (!hparmConfig)
        closeConfigFile(hparm);

    return bSupportFound;
}
Exemplo n.º 12
0
void GfglFeatures::storeSupport(int nWidth, int nHeight, int nDepth,
                                bool bAlpha, bool bFullScreen, bool bBump, bool bStereo, int nAniFilt, void* hparmConfig)
{
    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // If there's support for nothing, remove all.
    if (_mapSupportedBool.empty() && _mapSupportedInt.empty())
    {
        // Frame buffer specs.
        GfParmRemoveSection(hparm, GFSCR_SECT_GLDETSPECS);

        // Supported values.
        GfParmRemoveSection(hparm, GFSCR_SECT_GLDETFEATURES);
    }

    // If there's support for anything, store it.
    else
    {
        // Write new frame buffer specs for the stored supported features.
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_X, pszNoUnit,
                     (tdble)nWidth);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit,
                     (tdble)nHeight);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit,
                     (tdble)nDepth);
        GfParmSetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                     (tdble)nAniFilt);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL,
                     bAlpha ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR,
                     bFullScreen ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION,
                     bStereo ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        GfParmSetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING,
                     bBump ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // Write new values (remove the ones with no value supported).
        // 1) Double-buffer.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_DOUBLEBUFFER,
                     isSupported(DoubleBuffer) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 2) Color buffer depth.
        if (getSupported(ColorDepth) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH, pszNoUnit,
                         (tdble)getSupported(ColorDepth));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH);

        // 3) Alpha-channel depth.
        if (getSupported(AlphaDepth) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH, pszNoUnit,
                         (tdble)getSupported(AlphaDepth));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH);

        // 4) Max texture size.
        if (getSupported(TextureMaxSize) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE, pszNoUnit,
                         (tdble)getSupported(TextureMaxSize));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE);

        // 5) Texture compression.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_TEXTURECOMPRESSION,
                     isSupported(TextureCompression) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 6) Multi-texturing.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURING,
                     isSupported(MultiTexturing) ? GFSCR_VAL_YES : GFSCR_VAL_NO);
        if (getSupported(MultiTexturingUnits) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS, pszNoUnit,
                         (tdble)getSupported(MultiTexturingUnits));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS);

        // 7) Rectangle textures).
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_RECTANGLETEXTURES,
                     isSupported(TextureRectangle) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 8) Non-power-of-2 textures.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_NONPOTTEXTURES,
                     isSupported(TextureNonPowerOf2) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 9) Multi-sampling.
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLING,
                     isSupported(MultiSampling) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        if (getSupported(MultiSamplingSamples) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES, pszNoUnit,
                         (tdble)getSupported(MultiSamplingSamples));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES);

        // 10) Stereo Vision
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION,
                     isSupported(StereoVision) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 11) Bump Mapping
        GfParmSetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING,
                     isSupported(BumpMapping) ? GFSCR_VAL_YES : GFSCR_VAL_NO);

        // 12) Aniso Filtering
        if (getSupported(AnisotropicFiltering) != InvalidInt)
            GfParmSetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit,
                         (tdble)getSupported(AnisotropicFiltering));
        else
            GfParmRemove(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING);

    }

    // Write new params to config file.
    GfParmWriteFile(NULL, hparm, "Screen");

    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Trace resulting best supported features.
    dumpSupport();
}
Exemplo n.º 13
0
bool GfglFeatures::loadSupport(int &nWidth, int &nHeight, int &nDepth,
                               bool &bAlpha, bool &bFullScreen, bool &bBump, bool &bStereo, int &nAniFilt,void* hparmConfig)
{
    // Clear support data.
    _mapSupportedBool.clear();
    _mapSupportedInt.clear();

    // Open the config file if not already done.
    void* hparm = hparmConfig ? hparmConfig : openConfigFile();

    // Load the frame buffer specs for the stored supported features.
    nWidth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_X, pszNoUnit, 0);
    nHeight =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_WIN_Y, pszNoUnit, 0);
    nDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BPP, pszNoUnit, 0);
    nAniFilt =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ANISOTROPICFILTERING, pszNoUnit, 0);
    bAlpha =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_ALPHACHANNEL, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bFullScreen =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_FSCR, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bStereo =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_STEREOVISION, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;
    bBump =
        std::string(GfParmGetStr(hparm, GFSCR_SECT_GLDETSPECS, GFSCR_ATT_BUMPMAPPING, GFSCR_VAL_NO))
        == GFSCR_VAL_YES;

    // Check that we have something supported, and return if not.
    if (nWidth == 0 || nHeight == 0 || nDepth == 0)
    {
        GfLogTrace("No info found about best supported features for these specs ; "
                   "will need a detection pass.\n");

        // Close config file if we open it.
        if (!hparmConfig)
            closeConfigFile(hparm);

        return false;
    }


    // Here, we only update _mapSupportedXXX only if something relevant in the config file
    // If there's nothing or something not expected, it means no support.

    // 1) Double-buffer.
    const std::string strDoubleBuffer =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_DOUBLEBUFFER, "");
    if (strDoubleBuffer == GFSCR_VAL_YES)
        _mapSupportedBool[DoubleBuffer] = true;
    else if (strDoubleBuffer == GFSCR_VAL_NO)
        _mapSupportedBool[DoubleBuffer] = false;

    // 2) Color buffer depth.
    const int nColorDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_COLORDEPTH,
                          pszNoUnit, (tdble)0);
    if (nColorDepth > 0)
        _mapSupportedInt[ColorDepth] = nColorDepth;

    // 3) Alpha-channel depth.
    const int nAlphaDepth =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ALPHADEPTH,
                          pszNoUnit, (tdble)-1);
    if (nAlphaDepth >= 0)
        _mapSupportedInt[AlphaDepth] = nAlphaDepth;

    // 4) Max texture size.
    const int nMaxTexSize =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MAXTEXTURESIZE,
                          pszNoUnit, (tdble)0);
    if (nMaxTexSize > 0)
        _mapSupportedInt[TextureMaxSize] = nMaxTexSize;

    // 5) Texture compression.
    const std::string strTexComp =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_TEXTURECOMPRESSION, "");
    if (strTexComp == GFSCR_VAL_YES)
        _mapSupportedBool[TextureCompression] = true;
    else if (strTexComp == GFSCR_VAL_NO)
        _mapSupportedBool[TextureCompression] = false;

    // 6) Multi-texturing.
    const std::string strMultiTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURING, "");
    if (strMultiTex == GFSCR_VAL_YES)
        _mapSupportedBool[MultiTexturing] = true;
    else if (strMultiTex == GFSCR_VAL_NO)
        _mapSupportedBool[MultiTexturing] = false;

    const int nMultiTexUnits =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTITEXTURINGUNITS,
                          pszNoUnit, (tdble)0);
    if (nMultiTexUnits > 0)
        _mapSupportedInt[MultiTexturingUnits] = nMultiTexUnits;

    // 7) Rectangle textures).
    const std::string strRectTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_RECTANGLETEXTURES, "");
    if (strRectTex == GFSCR_VAL_YES)
        _mapSupportedBool[TextureRectangle] = true;
    else if (strRectTex == GFSCR_VAL_NO)
        _mapSupportedBool[TextureRectangle] = false;

    // 8) Non-power-of-2 textures.
    const std::string strNonPoTTex =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_NONPOTTEXTURES, "");
    if (strNonPoTTex == GFSCR_VAL_YES)
        _mapSupportedBool[TextureNonPowerOf2] = true;
    else if (strNonPoTTex == GFSCR_VAL_NO)
        _mapSupportedBool[TextureNonPowerOf2] = false;

    // 9) Multi-sampling.
    const std::string strMultiSamp =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLING, "");
    if (strMultiSamp == GFSCR_VAL_YES)
        _mapSupportedBool[MultiSampling] = true;
    else if (strMultiSamp == GFSCR_VAL_NO)
        _mapSupportedBool[MultiSampling] = false;

    const int nMultiSampSamples =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_MULTISAMPLINGSAMPLES,
                          pszNoUnit, (tdble)0);
    if (nMultiSampSamples > 0)
        _mapSupportedInt[MultiSamplingSamples] = nMultiSampSamples;

    // 10) Stereo Vision
    const std::string strStereoVision =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_STEREOVISION, "");
    if (strStereoVision == GFSCR_VAL_YES)
        _mapSupportedBool[StereoVision] = true;
    else if (strStereoVision == GFSCR_VAL_NO)
        _mapSupportedBool[StereoVision] = false;

    // 11) Bump Mapping.
    const std::string strBumpMapping =
        GfParmGetStr(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_BUMPMAPPING, "");
    if (strTexComp == GFSCR_VAL_YES) //strTexComp ? Bug ?
        _mapSupportedBool[BumpMapping] = true;
    else if (strTexComp == GFSCR_VAL_NO)
        _mapSupportedBool[BumpMapping] = false;

    // 11) Anisotropic Filtering.
    const int nAF =
        (int)GfParmGetNum(hparm, GFSCR_SECT_GLDETFEATURES, GFSCR_ATT_ANISOTROPICFILTERING,
                          pszNoUnit, (tdble)0);
    if (nMaxTexSize > 0)
        _mapSupportedInt[AnisotropicFiltering] =nAF;


    // Close config file if we open it.
    if (!hparmConfig)
        closeConfigFile(hparm);

    // Trace best supported features.
    dumpSupport();

    return true;
}