Exemplo n.º 1
0
      bool Configuration::write(bool const _force)
      {
         bool status = false;

         if (!inifile)
            {
               setErrorDescription(WRITE_ERROR + "internal error");
               return status;
            }

         if (!_force)
            {
               if (!opened)
                  {
                     setErrorDescription(WRITE_ERROR + "file not open");
                     // BTG_NOTICE("File not open.");
                     return status;
                  }
            }

         inifile->SetFileName(filename);
         status = inifile->Save();

         if (status)
            {
               inifile->Clear();
            }

         return status;
      }
Exemplo n.º 2
0
       bool Configuration::writeSwitch(std::string const& _key,
                                       std::string const& _section,
                                       std::string const& _description,
                                       std::string const& _switchOn,
                                       std::string const& _switchOff,
                                       bool const _value)
       {
           std::string switchStr;
           bool status = true;
           
           if (_value)
               {
                   switchStr = _switchOn;
               }
            else
               {
                  switchStr = _switchOff;
               }

            if (!inifile->SetValue(_key,
                                   switchStr,
                                   _description,
                                   _section))
               {
                  setErrorDescription("write", _section, _key);
                  status = false;
               }
            
            return status;
       }
Exemplo n.º 3
0
 void Configuration::setErrorDescription(std::string const& _operation, 
                                         std::string const& _section, 
                                         std::string const& _key)
 {
    std::string temp = 
       "Operation " + _operation + " on " + 
       _section + ":" + _key + " failed.";
    
    setErrorDescription(temp);
 }
Exemplo n.º 4
0
bool
CLuaVM::RunCommand(const char* param){

    int ret = luaL_loadstring( getVM(), param );
    if( ret != 0){
        setErrorDescription(ret);
        //_LOG_DEBUG << "TODO Lua could not load string";
        return false;
    }

    return execute();
}
Exemplo n.º 5
0
bool LensAutoFix::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    LensFunContainer prm;

    bool useMeta = settings()[QLatin1String("UseMetadata")].toBool();

    if (useMeta)
    {
        LensFunIface iface;
        DMetadata    meta(image().getMetadata());
        LensFunIface::MetadataMatch ret = iface.findFromMetadata(meta);
        prm                             = iface.settings();

        if (ret != LensFunIface::MetadataExactMatch)
        {
            setErrorDescription(i18n("Cannot find all lens information to process lens auto-corrections"));
            return false;
        }
    }
    else
    {
        prm.filterCCA       = settings()[QLatin1String("filterCCA")].toBool();
        prm.filterVIG       = settings()[QLatin1String("filterVIG")].toBool();
        prm.filterDST       = settings()[QLatin1String("filterDST")].toBool();
        prm.filterGEO       = settings()[QLatin1String("filterGEO")].toBool();

        prm.cropFactor      = settings()[QLatin1String("cropFactor")].toDouble();
        prm.focalLength     = settings()[QLatin1String("focalLength")].toDouble();
        prm.aperture        = settings()[QLatin1String("aperture")].toDouble();
        prm.subjectDistance = settings()[QLatin1String("subjectDistance")].toDouble();

        QString cameraMake  = settings()[QLatin1String("cameraMake")].toString();
        QString cameraModel = settings()[QLatin1String("cameraModel")].toString();
        QString lensModel   = settings()[QLatin1String("lensModel")].toString();
    }

    LensFunFilter filter(&image(), 0L, prm);
    applyFilter(&filter);

    MetaEngineData data = image().getMetadata();
    filter.registerSettingsToXmp(data);
    image().setMetadata(data);

    return savefromDImg();
}
Exemplo n.º 6
0
//int
bool
CLuaVM::loadChunkFromFile(const char* filename) {

    BOOST_ASSERT(filename);
    // TODO RunFunctionFromChunk
    //loadChunkFromGlobals
    int ret = luaL_loadfile( this->getVM(), filename);

    if(ret != 0){
        _LOG_ERROR << "Error while luaL_loadfile( " << filename << ")";
        //CLuaVM::getErrorDescription(ret);
        // _thread
        setErrorDescription(ret);
        //CLuaVM::handleError( getVM() );
        return false;
    }
    return true;
}
Exemplo n.º 7
0
bool
CLuaThread::execute(){

    int ret = resume();

    // script finished
    if(ret == 0){
//        _LOG_WARNING << "script finished !";
    }

    // LUA_YIELD = 1
    // Il y a une erreur !!
    else if( (ret != LUA_YIELD) ){
        setErrorDescription(ret);
        return false;
    }
    return true;

}
Exemplo n.º 8
0
bool
CLuaVM::execute(){
    /*
If errfunc is 0, then the error message returned on the stack is exactly the original error message. Otherwise, errfunc is the stack index of an error handler function. (In the current implementation, this index cannot be a pseudo-index.) In case of runtime errors, this function will be called with the error message and its return value will be the message returned on the stack by lua_pcall.
*/

// will push the error function  each time
    //int result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

    // Aller chercher la fct d'erreur dans detail::pcall
    int result = 0;
    //result = luabind::detail::pcall(getVM(), 0, LUA_MULTRET);

		pcall_callback_fun e = get_pcall_callback();
		int en = 0;
		if ( e )
		{
			int base = lua_gettop(_vm);
			lua_pushcfunction(_vm, e);
			lua_insert(_vm, base);  // push pcall_callback under chunk and args
			en = base;
  		}
  		//int lua_pcallk (lua_State *L, int nargs, int nresults, int errfunc,int ctx, lua_CFunction k);
		result = lua_pcallk(_vm, 0, 0, en,0,0);
        if ( en )
			lua_remove(_vm, en);  // remove pcall_callback


    // If we are here, it means there has been an error so we unwind stack
    if(result != 0){

        //_LOG_ERROR << "Error happened while executing";
        setErrorDescription(result);

        return false;
    }

    return true;
}
Exemplo n.º 9
0
ActionReply SddmAuthHelper::installtheme(const QVariantMap &args)
{
    const QString filePath = args["filePath"].toString();
    if (filePath.isEmpty()) {
        return ActionReply::HelperErrorReply();
    }

    const QString themesBaseDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "sddm/themes", QStandardPaths::LocateDirectory);
    QDir dir(themesBaseDir);
    if (!dir.exists()) {
        return ActionReply::HelperErrorReply();
    }

    qDebug() << "Installing " << filePath << " into " << themesBaseDir;

    if (!QFile::exists(filePath)) {
        return ActionReply::HelperErrorReply();
    }

    QMimeDatabase db;
    QMimeType mimeType = db.mimeTypeForFile(filePath);
    qWarning() << "Postinstallation: uncompress the file";

    QScopedPointer<KArchive> archive;

    //there must be a better way to do this? If not, make a static bool KZip::supportsMimeType(const QMimeType &type); ?
    //or even a factory class in KArchive

    if (mimeType.inherits(QStringLiteral("application/zip"))) {
        archive.reset(new KZip(filePath));
    } else if (mimeType.inherits(QStringLiteral("application/tar"))
                || mimeType.inherits(QStringLiteral("application/x-gzip"))
                || mimeType.inherits(QStringLiteral("application/x-bzip"))
                || mimeType.inherits(QStringLiteral("application/x-lzma"))
                || mimeType.inherits(QStringLiteral("application/x-xz"))
                || mimeType.inherits(QStringLiteral("application/x-bzip-compressed-tar"))
                || mimeType.inherits(QStringLiteral("application/x-compressed-tar"))) {
        archive.reset(new KTar(filePath));
    } else {
        auto e = ActionReply::HelperErrorReply();
        e.setErrorDescription(i18n("Invalid theme package"));
        return e;    }

    if (!archive->open(QIODevice::ReadOnly)) {
        auto e = ActionReply::HelperErrorReply();
        e.setErrorDescription("Could not open file");
        return e;
    }

    auto directory = archive->directory();

    QStringList installedPaths;

    //some basic validation
    //the top level should only have folders, and those folders should contain a valid metadata.desktop file
    //if we get anything else, abort everything before copying
    for(const QString &name: directory->entries()) {
        auto entry = directory->entry(name);
        if (!entry->isDirectory()) {
            auto e = ActionReply::HelperErrorReply();
            e.setErrorDescription(i18n("Invalid theme package"));
            return e;
        }
        auto subDirectory = static_cast<const KArchiveDirectory*>(entry);
        auto metadataFile = subDirectory->file("metadata.desktop");
        if(!metadataFile || !metadataFile->data().contains("[SddmGreeterTheme]")) {
            auto e = ActionReply::HelperErrorReply();
            e.setErrorDescription(i18n("Invalid theme package"));
            return e;
        }
        installedPaths.append(themesBaseDir + '/' + name);
    }

    if (!directory->copyTo(themesBaseDir)) {
        auto e = ActionReply::HelperErrorReply();
        e.setErrorDescription(i18n("Could not decompress archive"));
        return e;
    }

    auto rc = ActionReply::SuccessReply();
    rc.addData(QStringLiteral("installedPaths"), installedPaths);
    return rc;
}
Exemplo n.º 10
0
bool UserScript::toolOperations()
{
    QString script = settings()[QLatin1String("Script")].toString();

    if (script.isEmpty())
    {
        setErrorDescription(i18n("User Script: No script."));
        return false;
    }

    // Replace all occurences of $INPUT and $OUTPUT in script to file names. Case sensitive.
    script.replace(QLatin1String("$INPUT"),  QLatin1Char('"') + inputUrl().toLocalFile()  + QLatin1Char('"'));
    script.replace(QLatin1String("$OUTPUT"), QLatin1Char('"') + outputUrl().toLocalFile() + QLatin1Char('"'));

    QString shellScript;

#ifndef WIN32
    QString envCmd  = QLatin1String("export ");
#else
    QString envCmd  = QLatin1String("set ");
#endif // WIN32

    QString tagPath = TagsCache::instance()->tagPaths(imageInfo().tagIds(), TagsCache::NoLeadingSlash,
                                                      TagsCache::NoHiddenTags).join(QLatin1Char(';'));

    // Populate env variables from metadata
    shellScript.append(envCmd + QString::fromUtf8("COLORLABEL=\"%1\"\n").arg(imageInfo().colorLabel()));
    shellScript.append(envCmd + QString::fromUtf8("PICKLABEL=\"%1\"\n") .arg(imageInfo().pickLabel()));
    shellScript.append(envCmd + QString::fromUtf8("COMMENTS=\"%1\"\n")  .arg(imageInfo().comment()));
    shellScript.append(envCmd + QString::fromUtf8("RATING=\"%1\"\n")    .arg(imageInfo().rating()));
    shellScript.append(envCmd + QString::fromUtf8("TITLE=\"%1\"\n")     .arg(imageInfo().title()));
    shellScript.append(envCmd + QString::fromUtf8("TAGSPATH=\"%1\"\n")  .arg(tagPath));
    shellScript.append(script);

    // Empties d->image, not to pass it to the next tool in chain
    setImageData(DImg());

    QProcess process(this);

    // call the shell script
#ifndef WIN32
    int returncode = process.execute(QLatin1String("/bin/sh"), QStringList() << QLatin1String("-c") << shellScript);
#else
    int returncode = process.execute(QLatin1String("cmd.exe"), QStringList() << QLatin1String("/c") << shellScript);
#endif // WIN32

    if (returncode == -2)
    {
        setErrorDescription(i18n("User Script: Failed to start script."));
        return false;
    }

    if (returncode == -1)
    {
        setErrorDescription(i18n("User Script: Script process crashed."));
        return false;
    }

    if (returncode == 127)
    {
        setErrorDescription(i18n("User Script: Command not found."));
        return false;
    }

    return true;
}