Exemplo n.º 1
0
/** Gets the interface style key (e.g., "windows", "motif", etc.) */
QString
VidaliaSettings::getInterfaceStyle()
{
  return value(SETTING_STYLE).toString();
}
Exemplo n.º 2
0
AppInfo AppInfo::fromPath(const QString &path)
{
    AppInfo info(Bundle::fromPath(path));

    if (!static_cast<Bundle>(info).isValid()) {
        qCWarning(l) << "bundle" << path << "is not valid";
        return AppInfo();
    }

    QScopedPointer<QIODevice> appInfoJSON(info.openFile(AppInfo::INFO, QIODevice::Text));
    if (!appInfoJSON) {
        qCWarning(l) << "cannot find app" << path << "info json";
        return AppInfo();
    }

    QJsonParseError parseError;
    QJsonDocument doc = QJsonDocument::fromJson(appInfoJSON->readAll(), &parseError);
    if (parseError.error != QJsonParseError::NoError) {
        qCWarning(l) << "cannot parse app" << path << "info json" << parseError.errorString();
        return AppInfo();
    }
    appInfoJSON->close();

    const QJsonObject root = doc.object();
    info.d->uuid = QUuid(root["uuid"].toString());
    info.d->shortName = root["shortName"].toString();
    info.d->longName = root["longName"].toString();
    info.d->companyName = root["companyName"].toString();
    info.d->versionCode = root["versionCode"].toInt();
    info.d->versionLabel = root["versionLabel"].toString();

    const QJsonObject watchapp = root["watchapp"].toObject();
    info.d->watchface = watchapp["watchface"].toBool();

    info.d->jskit = info.fileExists(AppInfo::APPJS);

    if (root.contains("capabilities")) {
        const QJsonArray capabilities = root["capabilities"].toArray();
        AppInfo::Capabilities caps = 0;
        for (auto it = capabilities.constBegin(); it != capabilities.constEnd(); ++it) {
            QString cap = (*it).toString();
            if (cap == "location") caps |= AppInfo::Location;
            if (cap == "configurable") caps |= AppInfo::Configurable;
        }
        info.d->capabilities = caps;
    }

    if (root.contains("appKeys")) {
        const QJsonObject appkeys = root["appKeys"].toObject();
        for (auto it = appkeys.constBegin(); it != appkeys.constEnd(); ++it) {
            info.addAppKey(it.key(), it.value().toInt());
        }
    }

    if (root.contains("resources")) {
        const QJsonObject resources = root["resources"].toObject();
        const QJsonArray media = resources["media"].toArray();
        int index = 0;

        for (auto it = media.constBegin(); it != media.constEnd(); ++it) {
            const QJsonObject res = (*it).toObject();
            const QJsonValue menuIcon = res["menuIcon"];

            switch (menuIcon.type()) {
            case QJsonValue::Bool:
                info.d->menuIcon = menuIcon.toBool();
                info.d->menuIconResource = index;
                break;
            case QJsonValue::String:
                info.d->menuIcon = !menuIcon.toString().isEmpty();
                info.d->menuIconResource = index;
                break;
            default:
                break;
            }

            index++;
        }
    }

    if (info.uuid().isNull() || info.shortName().isEmpty()) {
        qCWarning(l) << "invalid or empty uuid/name in json of" << path;
        return AppInfo();
    }

    return info;
}
Exemplo n.º 3
0
bool
QMakeProperty::hasValue(QString v)
{
    return !value(v, true).isNull();
}
Exemplo n.º 4
0
bool JSString::getPrimitiveNumber(ExecState* exec, double& number, JSValue& result) const
{
    result = this;
    number = jsToNumber(value(exec));
    return false;
}
Exemplo n.º 5
0
UString JSString::toString(ExecState* exec) const
{
    return value(exec);
}
Exemplo n.º 6
0
/*
 * Mail a message on standard input to the people indicated
 * in the passed header.  (Internal interface).
 */
void
mail1(struct header *hp, int printheaders)
{
    char *cp;
    char *nbuf;
    int pid;
    char **namelist;
    struct name *to, *nsto;
    FILE *mtf;

    /*
     * Collect user's mail from standard input.
     * Get the result as mtf.
     */
    if ((mtf = collect(hp, printheaders)) == NULL)
        return;
    if (value("interactive") != NULL) {
        if (value("askcc") != NULL || value("askbcc") != NULL) {
            if (value("askcc") != NULL)
                grabh(hp, GCC);
            if (value("askbcc") != NULL)
                grabh(hp, GBCC);
        } else {
            printf("EOT\n");
            (void)fflush(stdout);
        }
    }
    if (fsize(mtf) == 0) {
        if (value("dontsendempty") != NULL)
            goto out;
        if (hp->h_subject == NULL)
            printf("No message, no subject; hope that's ok\n");
        else
            printf("Null message body; hope that's ok\n");
    }
    /*
     * Now, take the user names from the combined
     * to and cc lists and do all the alias
     * processing.
     */
    senderr = 0;
    to = usermap(cat(hp->h_bcc, cat(hp->h_to, hp->h_cc)));
    if (to == NULL) {
        printf("No recipients specified\n");
        senderr++;
    }
    /*
     * Look through the recipient list for names with /'s
     * in them which we write to as files directly.
     */
    to = outof(to, mtf, hp);
    if (senderr)
        savedeadletter(mtf);
    to = elide(to);
    if (count(to) == 0)
        goto out;
    if (value("recordrecip") != NULL) {
        /*
         * Before fixing the header, save old To:.
         * We do this because elide above has sorted To: list, and
         * we would like to save message in a file named by the first
         * recipient the user has entered, not the one being the first
         * after sorting happened.
         */
        if ((nsto = malloc(sizeof(struct name))) == NULL)
            err(1, "Out of memory");
        bcopy(hp->h_to, nsto, sizeof(struct name));
    }
    fixhead(hp, to);
    if ((mtf = infix(hp, mtf)) == NULL) {
        fprintf(stderr, ". . . message lost, sorry.\n");
        return;
    }
    namelist = unpack(cat(hp->h_smopts, to));
    if (debug) {
        char **t;

        printf("Sendmail arguments:");
        for (t = namelist; *t != NULL; t++)
            printf(" \"%s\"", *t);
        printf("\n");
        goto out;
    }
    if (value("recordrecip") != NULL) {
        /*
         * Extract first recipient username from saved To: and use it
         * as a filename.
         */
        if ((nbuf = malloc(strlen(detract(nsto, 0)) + 1)) == NULL)
            err(1, "Out of memory");
        if ((cp = yanklogin(detract(nsto, 0), nbuf)) != NULL)
            (void)savemail(expand(nbuf), mtf);
        free(nbuf);
        free(nsto);
    } else if ((cp = value("record")) != NULL)
        (void)savemail(expand(cp), mtf);
    /*
     * Fork, set up the temporary mail file as standard
     * input for "mail", and exec with the user list we generated
     * far above.
     */
    pid = fork();
    if (pid == -1) {
        warn("fork");
        savedeadletter(mtf);
        goto out;
    }
    if (pid == 0) {
        sigset_t nset;
        (void)sigemptyset(&nset);
        (void)sigaddset(&nset, SIGHUP);
        (void)sigaddset(&nset, SIGINT);
        (void)sigaddset(&nset, SIGQUIT);
        (void)sigaddset(&nset, SIGTSTP);
        (void)sigaddset(&nset, SIGTTIN);
        (void)sigaddset(&nset, SIGTTOU);
        prepare_child(&nset, fileno(mtf), -1);
        if ((cp = value("sendmail")) != NULL)
            cp = expand(cp);
        else
            cp = _PATH_SENDMAIL;
        execv(cp, namelist);
        warn("%s", cp);
        _exit(1);
    }
    if (value("verbose") != NULL)
        (void)wait_child(pid);
    else
        free_child(pid);
out:
    (void)Fclose(mtf);
}
Exemplo n.º 7
0
int AtIndicators::value( const QString& name ) const
{
    return value( indicator( name ) );
}
Exemplo n.º 8
0
/** Returns a fully-qualified path to the proxy server, including the
 * executable name. */
QString
VidaliaSettings::getProxyExecutable() const
{
  return QDir::convertSeparators(value(SETTING_PROXY_EXECUTABLE).toString());
}
Exemplo n.º 9
0
/** Returns a string containing additional command line arguments to be passed
 * to ProxyExecutable */
QString
VidaliaSettings::getProxyExecutableArguments() const
{
  return value(SETTING_PROXY_EXECUTABLE_ARGUMENTS).toString();
}
Exemplo n.º 10
0
/** Returns a fully-qualified path to the web browser directory */
QString
VidaliaSettings::getBrowserDirectory() const
{
  return QDir::convertSeparators(value(SETTING_BROWSER_DIRECTORY).toString());
}
Exemplo n.º 11
0
/** Returns true if Vidalia should start a proxy application when it
 * starts. */
bool
VidaliaSettings::runProxyAtStart()
{
  return value(SETTING_RUN_PROXY_AT_START).toBool();
}
Exemplo n.º 12
0
/** If browserDirectory is empty, returns a fully-qualified path to
 * the web browser, including the executable name. If browserDirectory
 * is set, then returns the basename of the configured web browser */
QString
VidaliaSettings::getBrowserExecutable() const
{
  return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
}
Exemplo n.º 13
0
/** Returns true if Vidalia's main window should be visible when the
 * application starts. */
bool
VidaliaSettings::showMainWindowAtStart()
{
  return value(SETTING_SHOW_MAINWINDOW_AT_START).toBool();
}
Exemplo n.º 14
0
/** Returns true if Tor is to be run when Vidalia starts. */
bool
VidaliaSettings::runTorAtStart()
{
  return value(SETTING_RUN_TOR_AT_START).toBool();
}
Exemplo n.º 15
0
QString
VidaliaSettings::getDefaultPluginsDirectory() const
{
  return QDir::convertSeparators(value(SETTING_DEFAULT_PLUGINS_DIRECTORY).toString());
}
Exemplo n.º 16
0
bool
VidaliaSettings::isAutoUpdateEnabled() const
{
  return value(SETTING_CHECK_FOR_UPDATES).toBool();
}
Exemplo n.º 17
0
  void medianCut( QVector<QRgb>& colorTable, int nColors, const QImage& inputImage )
  {
    QHash<QRgb, int> inputColors;
    imageColors( inputColors, inputImage );

    if ( inputColors.size() <= nColors ) //all the colors in the image can be mapped to one palette color
    {
      colorTable.resize( inputColors.size() );
      int index = 0;
      for ( auto inputColorIt = inputColors.constBegin(); inputColorIt != inputColors.constEnd(); ++inputColorIt )
      {
        colorTable[index] = inputColorIt.key();
        ++index;
      }
      return;
    }

    //create first box
    QgsColorBox firstBox; //QList< QPair<QRgb, int> >
    int firstBoxPixelSum = 0;
    for ( auto  inputColorIt = inputColors.constBegin(); inputColorIt != inputColors.constEnd(); ++inputColorIt )
    {
      firstBox.push_back( qMakePair( inputColorIt.key(), inputColorIt.value() ) );
      firstBoxPixelSum += inputColorIt.value();
    }

    QgsColorBoxMap colorBoxMap; //QMultiMap< int, ColorBox >
    colorBoxMap.insert( firstBoxPixelSum, firstBox );
    QMap<int, QgsColorBox>::iterator colorBoxMapIt = colorBoxMap.end();

    //split boxes until number of boxes == nColors or all the boxes have color count 1
    bool allColorsMapped = false;
    while ( colorBoxMap.size() < nColors )
    {
      //start at the end of colorBoxMap and pick the first entry with number of colors < 1
      colorBoxMapIt = colorBoxMap.end();
      while ( true )
      {
        --colorBoxMapIt;
        if ( colorBoxMapIt.value().size() > 1 )
        {
          splitColorBox( colorBoxMapIt.value(), colorBoxMap, colorBoxMapIt );
          break;
        }
        if ( colorBoxMapIt == colorBoxMap.begin() )
        {
          allColorsMapped = true;
          break;
        }
      }

      if ( allColorsMapped )
      {
        break;
      }
    }

    //get representative colors for the boxes
    int index = 0;
    colorTable.resize( colorBoxMap.size() );
    for ( auto colorBoxIt = colorBoxMap.constBegin(); colorBoxIt != colorBoxMap.constEnd(); ++colorBoxIt )
    {
      colorTable[index] = boxColor( colorBoxIt.value(), colorBoxIt.key() );
      ++index;
    }
  }
Exemplo n.º 18
0
QDateTime
VidaliaSettings::lastCheckedForUpdates() const
{
  return value(SETTING_LAST_UPDATE_CHECK).toDateTime();
}
Exemplo n.º 19
0
/**
 * Build a vehicle.
 * @param tile tile of depot where the vehicle is built
 * @param flags for command
 * @param p1 various bitstuffed data
 *  bits  0-15: vehicle type being built.
 *  bits 16-31: vehicle type specific bits passed on to the vehicle build functions.
 * @param p2 User
 * @param text unused
 * @return the cost of this operation or an error
 */
CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	/* Elementary check for valid location. */
	if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return CMD_ERROR;

	VehicleType type = GetDepotVehicleType(tile);

	/* Validate the engine type. */
	EngineID eid = GB(p1, 0, 16);
	if (!IsEngineBuildable(eid, type, _current_company)) return_cmd_error(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type);

	const Engine *e = Engine::Get(eid);
	CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost());

	/* Engines without valid cargo should not be available */
	if (e->GetDefaultCargoType() == CT_INVALID) return CMD_ERROR;

	/* Check whether the number of vehicles we need to build can be built according to pool space. */
	uint num_vehicles;
	switch (type) {
		case VEH_TRAIN:    num_vehicles = (e->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 2 : 1) + CountArticulatedParts(eid, false); break;
		case VEH_ROAD:     num_vehicles = 1 + CountArticulatedParts(eid, false); break;
		case VEH_SHIP:     num_vehicles = 1; break;
		case VEH_AIRCRAFT: num_vehicles = e->u.air.subtype & AIR_CTOL ? 2 : 3; break;
		default: NOT_REACHED(); // Safe due to IsDepotTile()
	}
	if (!Vehicle::CanAllocateItem(num_vehicles)) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);

	/* Check whether we can allocate a unit number. Autoreplace does not allocate
	 * an unit number as it will (always) reuse the one of the replaced vehicle
	 * and (train) wagons don't have an unit number in any scenario. */
	UnitID unit_num = (flags & DC_AUTOREPLACE || (type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type);
	if (unit_num == UINT16_MAX) return_cmd_error(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME);

	Vehicle *v;
	switch (type) {
		case VEH_TRAIN:    value.AddCost(CmdBuildRailVehicle(tile, flags, e, GB(p1, 16, 16), &v)); break;
		case VEH_ROAD:     value.AddCost(CmdBuildRoadVehicle(tile, flags, e, GB(p1, 16, 16), &v)); break;
		case VEH_SHIP:     value.AddCost(CmdBuildShip       (tile, flags, e, GB(p1, 16, 16), &v)); break;
		case VEH_AIRCRAFT: value.AddCost(CmdBuildAircraft   (tile, flags, e, GB(p1, 16, 16), &v)); break;
		default: NOT_REACHED(); // Safe due to IsDepotTile()
	}

	if (value.Succeeded() && flags & DC_EXEC) {
		v->unitnumber = unit_num;
		v->value      = value.GetCost();

		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
		InvalidateWindowClassesData(GetWindowClassForVehicleType(type), 0);
		SetWindowDirty(WC_COMPANY, _current_company);
		if (IsLocalCompany()) {
			InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the auto replace window (must be called before incrementing num_engines)
		}

		GroupStatistics::CountEngine(v, 1);
		GroupStatistics::UpdateAutoreplace(_current_company);

		if (v->IsPrimaryVehicle()) {
			GroupStatistics::CountVehicle(v, 1);
			OrderBackup::Restore(v, p2);
		}
	}

	return value;
}
Exemplo n.º 20
0
bool
VidaliaSettings::useLocalGeoIpDatabase() const
{
  return value(SETTING_USE_LOCAL_GEOIP_DATABASE).toBool();
}
Exemplo n.º 21
0
// PrintVarRecurse
//------------------------------------------------------------------------------
/*static*/ void FunctionPrint::PrintVarRecurse( const BFFVariable & var, uint32_t indent )
{
	AStackString<> indentStr;
	for ( uint32_t i=0; i<indent; ++i )
	{
		indentStr += "    ";
	}
	++indent;
	FLOG_BUILD( indentStr.Get() );

	switch ( var.GetType() )
	{
		case BFFVariable::VAR_ANY: ASSERT( false ); break; // Something is terribly wrong
		case BFFVariable::VAR_STRING:
		{
			AStackString<> value( var.GetString() );
			value.Replace( "'", "^'" ); // escape single quotes
			FLOG_BUILD( "%s = '%s'\n", var.GetName().Get(), value.Get() );
			break;
		}
		case BFFVariable::VAR_BOOL:
		{
			FLOG_BUILD( "%s = %s\n", var.GetName().Get(), var.GetBool() ? "true" : "false" );
			break;
		}
		case BFFVariable::VAR_ARRAY_OF_STRINGS:
		{
			const auto & strings = var.GetArrayOfStrings();
			FLOG_BUILD( "%s = // ArrayOfStrings, size: %u\n%s{\n", var.GetName().Get(), (uint32_t)strings.GetSize(), indentStr.Get() );
			for ( const AString & string : strings )
			{
				AStackString<> value( string );
				value.Replace( "'", "^'" ); // escape single quotes
				FLOG_BUILD( "%s    '%s'\n", indentStr.Get(), value.Get() );
			}
			FLOG_BUILD( "%s}\n", indentStr.Get() );
			break;
		}
		case BFFVariable::VAR_INT:
		{
			FLOG_BUILD( "%s = %i\n", var.GetName().Get(), var.GetInt() );
			break;
		}
		case BFFVariable::VAR_STRUCT:
		{
			FLOG_BUILD( "%s = // Struct\n%s[\n", var.GetName().Get(), indentStr.Get() );
			for ( const BFFVariable * subVar : var.GetStructMembers() )
			{
				PrintVarRecurse( *subVar, indent );
			}
			FLOG_BUILD( "%s]\n", indentStr.Get() );
			break;
		}
		case BFFVariable::VAR_ARRAY_OF_STRUCTS:
		{
			const auto & structs = var.GetArrayOfStructs();
			FLOG_BUILD( "%s = // ArrayOfStructs, size: %u\n%s{\n", var.GetName().Get(), (uint32_t)structs.GetSize(), indentStr.Get() );
			for ( const BFFVariable * subVar : structs )
			{
				PrintVarRecurse( *subVar, indent );
			}
			FLOG_BUILD( "%s}\n", indentStr.Get() );
			break;
		}
		case BFFVariable::MAX_VAR_TYPES: ASSERT( false ); break; // Something is terribly wrong
	}
}
Exemplo n.º 22
0
QString
VidaliaSettings::localGeoIpDatabase() const
{
  return QDir::convertSeparators(value(SETTING_LOCAL_GEOIP_DATABASE).toString());
}
Exemplo n.º 23
0
double JSString::toNumber(ExecState* exec) const
{
    return jsToNumber(value(exec));
}
Exemplo n.º 24
0
/** Get the icon preference */
VidaliaSettings::IconPosition
VidaliaSettings::getIconPref()
{
  return fromString(value(SETTING_ICON_PREF).toString());
}
Exemplo n.º 25
0
 void addProperty(std::string name, T min, T max, T def)
 {
     _properties[name] = make_unique<Property<T> >(name, min, max, def);
     Value<T> value(def);
     setProperty(name, value);
 }
Exemplo n.º 26
0
bool
VidaliaSettings::skipVersionCheck() const
{
  return value(SETTING_SKIP_VERSION_CHECK).toBool();
}
Exemplo n.º 27
0
 inline void put_new(context_type::key_type const& key, T const& val)
 {
     put_new(key,std::move(value(val)));
 }
Exemplo n.º 28
0
QString
VidaliaSettings::getProfileDirectory() const
{
  return QDir::convertSeparators(value(SETTING_PROFILE_DIRECTORY).toString());
}
Exemplo n.º 29
0
bool
QMakeProperty::exec()
{
    bool ret = true;
    if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY) {
        if(Option::prop::properties.isEmpty()) {
            initSettings();
            settings->beginGroup(keyBase(false));
            QStringList subs = settings->childGroups();
            settings->endGroup();
            subs.sort();
            for(int x = subs.count() - 1; x >= 0; x--) {
                QString s = subs[x];
                if(s.isEmpty())
                    continue;
                settings->beginGroup(keyBase(false) + s);
                QStringList keys = settings->childKeys();
                settings->endGroup();
                for(QStringList::ConstIterator it2 = keys.begin(); it2 != keys.end(); it2++) {
                    QString ret = settings->value(keyBase(false) + s + "/" + (*it2)).toString();
                    if(s != qmake_version())
                        fprintf(stdout, "%s/", s.toLatin1().constData());
                    fprintf(stdout, "%s:%s\n", (*it2).toLatin1().constData(), ret.toLatin1().constData());
                }
            }
            QStringList specialProps;
            specialProps.append("QT_INSTALL_PREFIX");
            specialProps.append("QT_INSTALL_DATA");
            specialProps.append("QT_INSTALL_DOCS");
            specialProps.append("QT_INSTALL_HEADERS");
            specialProps.append("QT_INSTALL_LIBS");
            specialProps.append("QT_INSTALL_BINS");
            specialProps.append("QT_INSTALL_PLUGINS");
            specialProps.append("QT_INSTALL_IMPORTS");
            specialProps.append("QT_INSTALL_TRANSLATIONS");
            specialProps.append("QT_INSTALL_CONFIGURATION");
            specialProps.append("QT_INSTALL_EXAMPLES");
            specialProps.append("QT_INSTALL_DEMOS");
            specialProps.append("QMAKE_MKSPECS");
            specialProps.append("QMAKE_VERSION");
#ifdef QT_VERSION_STR
            specialProps.append("QT_VERSION");
#endif
            foreach (QString prop, specialProps)
                fprintf(stdout, "%s:%s\n", prop.toLatin1().constData(), value(prop).toLatin1().constData());
            return true;
        }
        for(QStringList::ConstIterator it = Option::prop::properties.begin();
            it != Option::prop::properties.end(); it++) {
            if(Option::prop::properties.count() > 1)
                fprintf(stdout, "%s:", (*it).toLatin1().constData());
            if(!hasValue((*it))) {
                ret = false;
                fprintf(stdout, "**Unknown**\n");
            } else {
                fprintf(stdout, "%s\n", value((*it)).toLatin1().constData());
            }
        }
    } else if(Option::qmake_mode == Option::QMAKE_SET_PROPERTY) {
        for(QStringList::ConstIterator it = Option::prop::properties.begin();
            it != Option::prop::properties.end(); it++) {
            QString var = (*it);
            it++;
            if(it == Option::prop::properties.end()) {
                ret = false;
                break;
            }
            if(!var.startsWith("."))
                setValue(var, (*it));
        }
    }
    return ret;
}
Exemplo n.º 30
0
/** Gets the currently preferred language code for Vidalia. */
QString
VidaliaSettings::getLanguageCode()
{
  return value(SETTING_LANGUAGE).toString();
}