Esempio n. 1
0
bool TrackNode::toGPX(QXmlStreamWriter& stream, QProgressDialog * progress, QString element, bool forExport)
{
    bool OK = true;

    if (isVirtual())
        return OK;

    if (!tagValue("_waypoint_","").isEmpty() ||!sizeParents())
        stream.writeStartElement("wpt");
    else
        stream.writeStartElement(element);

    if (!forExport)
        stream.writeAttribute("xml:id", xmlId());
    stream.writeAttribute("lon",COORD2STRING(BBox.topRight().x()));
    stream.writeAttribute("lat", COORD2STRING(BBox.topRight().y()));

    stream.writeTextElement("time", time().toString(Qt::ISODate)+"Z");

    QString s = tagValue("name","");
    if (!s.isEmpty()) {
        stream.writeTextElement("name", s);
    }
    if (elevation()) {
        stream.writeTextElement("ele", QString::number(elevation(),'f',6));
    }
    if (speed()) {
        stream.writeTextElement("speed", QString::number(speed(),'f',6));
    }
    s = tagValue("_comment_","");
    if (!s.isEmpty()) {
        stream.writeTextElement("cmt", s);
    }
    s = tagValue("_description_","");
    if (!s.isEmpty()) {
        stream.writeTextElement("desc", s);
    }

    // OpenStreetBug
    s = tagValue("_special_","");
    if (!s.isEmpty() && id().type & IFeature::Special) {
        stream.writeStartElement("extensions");
        QString sid = stripToOSMId(id());
        stream.writeTextElement("id", sid);
        stream.writeEndElement();
    }
    stream.writeEndElement();

    if (progress)
        progress->setValue(progress->value()+1);

    return OK;
}
Esempio n. 2
0
static JSBool
rpmhdr_getprop(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    Header h = ptr;
    jsval idval;
    JS_IdToValue(cx, id, &idval);
    jsint tiny = JSVAL_TO_INT(idval);

_PROP_DEBUG_ENTRY(_debug < 0);

    /* XXX the class has ptr == NULL, instances have ptr != NULL. */
    if (ptr == NULL)
	return JS_TRUE;

    switch (tiny) {
    case _DEBUG:
	*vp = INT_TO_JSVAL(_debug);
	break;
    default: {
	char * s = NULL;
	rpmTag tag = JSVAL_IS_INT(id)
		? (rpmTag) JSVAL_TO_INT(id)
		: tagValue((s = JS_EncodeString(cx, (JS_ValueToString(cx, id)))));
	if (s)
	    JS_free(cx, s);
	if (rpmhdrLoadTag(cx, obj, h, tag, vp) == NULL)
	    break;
      } break;
    }

    return JS_TRUE;
}
Esempio n. 3
0
static JSBool
rpmts_mi(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL);
    rpmts ts = ptr;
    jsval tagid = JSVAL_VOID;
    jsval kv = JSVAL_VOID;
    rpmTag tag = RPMDBI_PACKAGES;
    JSObject *mio;
    JSBool ok = JS_FALSE;

_METHOD_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/vv", &tagid, &kv)))
        goto exit;

    if (!JSVAL_IS_VOID(tagid)) {
	/* XXX TODO: make sure both tag and key were specified. */
	tag = JSVAL_IS_INT(tagid)
		? (rpmTag) JSVAL_TO_INT(tagid)
		: tagValue(JS_GetStringBytes(JS_ValueToString(cx, tagid)));
    }

    if ((mio = rpmjs_NewMiObject(cx, ts, tag, kv)) == NULL)
	goto exit;

    *rval = OBJECT_TO_JSVAL(mio);
    ok = JS_TRUE;

exit:
    return ok;
}
Esempio n. 4
0
QStringList KExiv2::getIptcTagsStringList(const char* iptcTagName, bool escapeCR) const
{
    try
    {
        if (!d->iptcMetadata().empty())
        {
            QStringList values;
            Exiv2::IptcData iptcData(d->iptcMetadata());

            for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it)
            {
                QString key = QString::fromLocal8Bit(it->key().c_str());

                if (key == QString(iptcTagName))
                {
                    QString tagValue(it->toString().c_str());

                    if (escapeCR)
                        tagValue.replace('\n', ' ');

                    values.append(tagValue);
                }
            }

            return values;
        }
    }
    catch( Exiv2::Error& e )
    {
        d->printExiv2ExceptionError(QString("Cannot find Iptc key '%1' into image using Exiv2 ")
                                    .arg(iptcTagName), e);
    }

    return QStringList();
}
Esempio n. 5
0
QString KExiv2::getIptcTagString(const char* iptcTagName, bool escapeCR) const
{
    try
    {
        Exiv2::IptcKey iptcKey(iptcTagName);
        Exiv2::IptcData iptcData(d->iptcMetadata());
        Exiv2::IptcData::iterator it = iptcData.findKey(iptcKey);
        if (it != iptcData.end())
        {
            std::ostringstream os;
            os << *it;
            QString tagValue(os.str().c_str());

            if (escapeCR)
                tagValue.replace('\n', ' ');

            return tagValue;
        }
    }
    catch( Exiv2::Error& e )
    {
        d->printExiv2ExceptionError(QString("Cannot find Iptc key '%1' into image using Exiv2 ")
                                    .arg(iptcTagName), e);
    }

    return QString();
}
Esempio n. 6
0
QString Node::description() const
{
    QString s(tagValue("name",""));
    if (!s.isEmpty())
        return QString("%1 (%2)").arg(s).arg(id().numId);
    return
        QString("%1").arg(id().numId);
}
Esempio n. 7
0
/**
 * Return rpmdb match iterator with filters (if any) set.
 * @param gi		generalized iterator
 * @returns		RPMRC_OK on success
 */
static rpmRC rpmgiInitFilter(rpmgi gi)
	/*@globals rpmGlobalMacroContext, h_errno, internalState @*/
	/*@modifies gi, rpmGlobalMacroContext, h_errno, internalState @*/
{
    rpmRC rpmrc = RPMRC_OK;
    ARGV_t av;
    int got = 0;

    gi->mi = rpmtsInitIterator(gi->ts, gi->tag, gi->keyp, gi->keylen);

if (_rpmgi_debug < 0)
fprintf(stderr, "*** gi %p key %p[%d]\tmi %p\n", gi, gi->keyp, (int)gi->keylen, gi->mi);

    if (gi->argv != NULL)
    for (av = (const char **) gi->argv; *av != NULL; av++) {
	if (gi->tag == RPMDBI_PACKAGES) {
	    int tag = RPMTAG_NAME;
	    const char * pat;
	    char * a, * ae;

	    pat = a = xstrdup(*av);
	    tag = RPMTAG_NAME;

	    /* Parse for "tag=pattern" args. */
	    if ((ae = strchr(a, '=')) != NULL) {
		*ae++ = '\0';
		if (*a != '\0') {	/* XXX HACK: permit '=foo' */
		    tag = tagValue(a);
#ifdef	DYING	/* XXX arbitrary tags always have a return value */
		    if (tag < 0) {
			rpmlog(RPMLOG_NOTICE, _("unknown tag: \"%s\"\n"), a);
			got = -1;
		    }
#endif
		}
		pat = ae;
		got++;
	    }
	    if (got) {
if (_rpmgi_debug  < 0)
fprintf(stderr, "\tav %p[%d]: \"%s\" -> %s ~= \"%s\"\n", gi->argv, (int)(av - gi->argv), *av, tagName(tag), pat);
		got = rpmmiAddPattern(gi->mi, tag, RPMMIRE_DEFAULT, pat);
	    }
	    a = _free(a);
	}

	if (got >= 0)
	    continue;

	gi->mi = rpmmiFree(gi->mi);	/* XXX odd side effect? */
	rpmrc = RPMRC_FAIL;
	break;
    }

    return rpmrc;
}
Esempio n. 8
0
static VALUE
rpmhdrLoadTag(Header h, const char * name)
{
    HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    VALUE v = Qfalse;
    int i;

if (_debug)
fprintf(stderr, "==> %s(%p,%s)\n", __FUNCTION__, h, name);

    he->tag = tagValue(name);
    if (headerGet(h, he, 0)) {
if (_debug < 0)
fprintf(stderr, "\t%s(%u) %u %p[%u]\n", name, (unsigned)he->tag, (unsigned)he->t, he->p.ptr, (unsigned)he->c);
	switch (he->t) {
	default:
	    goto exit;
	    /*@notreached@*/ break;
	case RPM_BIN_TYPE:	/* XXX return as array of octets for now. */
	case RPM_UINT8_TYPE:
	    v = rb_ary_new();
	    for (i = 0; i < (int)he->c; i++)
		rb_ary_push(v, INT2FIX(he->p.ui8p[i]));
	    break;
	case RPM_UINT16_TYPE:
	    v = rb_ary_new();
	    for (i = 0; i < (int)he->c; i++)
		rb_ary_push(v, INT2FIX(he->p.ui16p[i]));
	    break;
	case RPM_UINT32_TYPE:
	    v = rb_ary_new();
	    for (i = 0; i < (int)he->c; i++)
		rb_ary_push(v, INT2FIX(he->p.ui32p[i]));
	    break;
	case RPM_UINT64_TYPE:
	    v = rb_ary_new();
	    for (i = 0; i < (int)he->c; i++)
		rb_ary_push(v, INT2FIX(he->p.ui64p[i]));
	    break;
	case RPM_STRING_ARRAY_TYPE:
	    v = rb_ary_new();
	    for (i = 0; i < (int)he->c; i++)
		rb_ary_push(v, rb_str_new2(he->p.argv[i]));
	    break;
	case RPM_I18NSTRING_TYPE:	/* XXX FIXME: is this ever seen? */
	case RPM_STRING_TYPE:
	    v = rb_str_new2(he->p.str);
	    break;
	}
    }

exit:
    he->p.ptr = _free(he->p.ptr);
    return v;
}
Esempio n. 9
0
/**
 * Add expanded build scriptlets to srpm header.
 * @param spec		spec file control structure
 * @return		0 always
 */
static int initSourceHeaderScriptlets(Spec spec)
	/*@modifies spec->sourceHeader @*/
{
    int xx;

    if (spec->prep != NULL)
	xx = initSourceHeaderScriptlet(spec->sourceHeader,
	    tagValue("Buildprepprog"), tagValue("Buildprep"), spec->prep);
    if (spec->build != NULL)
	xx = initSourceHeaderScriptlet(spec->sourceHeader,
	    tagValue("Buildbuildprog"), tagValue("Buildbuild"), spec->build);
    if (spec->install != NULL)
	xx = initSourceHeaderScriptlet(spec->sourceHeader,
	    tagValue("Buildinstallprog"), tagValue("Buildinstall"), spec->install);
    if (spec->check != NULL)
	xx = initSourceHeaderScriptlet(spec->sourceHeader,
	    tagValue("Buildcheckprog"), tagValue("Buildcheck"), spec->check);
    if (spec->clean != NULL)
	xx = initSourceHeaderScriptlet(spec->sourceHeader,
	    tagValue("Buildcleanprog"), tagValue("Buildclean"), spec->clean);

   return 0;
}
Esempio n. 10
0
QString Node::toHtml()
{
    QString D;
    int i;


    if ((i = findKey("_waypoint_")) != -1)
        D += "<p><b>"+QApplication::translate("MapFeature", "Waypoint")+"</b><br/>";
    D += "<i>"+QApplication::translate("MapFeature", "coord")+": </i>" + COORD2STRING(position().y()) + " (" + Coord2Sexa(position().y()) + ") / " + COORD2STRING(position().x()) + " (" + Coord2Sexa(position().x()) + ")";

    if ((i = findKey("_description_")) != -1)
        D += "<br/><i>"+QApplication::translate("MapFeature", "description")+": </i>" + tagValue(i);
    if ((i = findKey("_comment_")) != -1)
        D += "<br/><i>"+QApplication::translate("MapFeature", "comment")+": </i>" + tagValue(i);

    return Feature::toMainHtml(QApplication::translate("MapFeature", "Node"), "node").arg(D);
}
Esempio n. 11
0
// Minimalistic logging function for internal JS
static Handle<Value> krollLog(const Arguments& args)
{
	HandleScope scope;
	uint32_t len = args.Length();

	if (len < 2) {
		return JSException::Error("log: missing required tag and message arguments");
	}

	Handle<String> tag = args[0]->ToString();
	Handle<String> message = args[1]->ToString();
	for (uint32_t i = 2; i < len; ++i) {
		message = String::Concat(String::Concat(message, String::New(" ")), args[i]->ToString());
	}

	String::Utf8Value tagValue(tag);
	String::Utf8Value messageValue(message);
	__android_log_print(ANDROID_LOG_DEBUG, *tagValue, *messageValue);

	return Undefined();
}
Esempio n. 12
0
// Minimalistic logging function for internal JS
static void krollLog(const FunctionCallbackInfo<Value>& args)
{
	Isolate* isolate = args.GetIsolate();
	HandleScope scope(isolate);
	uint32_t len = args.Length();

	if (len < 2) {
		JSException::Error(isolate, "log: missing required tag and message arguments");
		return;
	}

	Local<String> tag = args[0].As<String>();
	Local<String> message = args[1].As<String>();
	Local<String> space = STRING_NEW(isolate, " ");
	for (uint32_t i = 2; i < len; ++i) {
		message = String::Concat(String::Concat(message, space), args[i].As<String>());
	}

	v8::String::Utf8Value tagValue(tag);
	v8::String::Utf8Value messageValue(message);
	__android_log_print(ANDROID_LOG_DEBUG, *tagValue, *messageValue);
}
Esempio n. 13
0
static JSBool
rpmhdr_resolve(JSContext *cx, JSObject *obj, jsval id, uintN flags,
	JSObject **objp)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmhdrClass, NULL);
    Header h = ptr;
    JSBool ok = JS_FALSE;

_RESOLVE_DEBUG_ENTRY(_debug);

    if ((flags & JSRESOLVE_ASSIGNING)
     || (h == NULL)) {	/* don't resolve to parent prototypes objects. */
	*objp = NULL;
	ok = JS_TRUE;
	goto exit;
    }

    if (JSVAL_IS_INT(id) || JSVAL_IS_STRING(id)) {
	char * s = NULL;
	rpmTag tag = JSVAL_IS_INT(id)
		? (rpmTag) JSVAL_TO_INT(id)
		: tagValue(JS_EncodeString(cx, JS_ValueToString(cx, id)));
	JSObject * arr = rpmhdrLoadTag(cx, obj, h, tag, NULL);

	if (s)
	    JS_free(cx, s);
	if (!JS_DefineElement(cx, obj, tag, OBJECT_TO_JSVAL(arr),
			NULL, NULL, JSPROP_ENUMERATE)) {
	    *objp = NULL;
	    goto exit;
	}
	*objp = obj;
    } else
	*objp = NULL;
    ok = JS_TRUE;
exit:
    return ok;
}
Esempio n. 14
0
File: tbf.c Progetto: avokhmin/RPM5
int main(int argc, char *argv[])
{
    HE_t he = (HE_t)memset(alloca(sizeof(*he)), 0, sizeof(*he));
    poptContext optCon;
    rpmts ts = NULL;
    rpmgi gi = NULL;
    size_t n = 4096;
    static double e = 1.0e-4;
    size_t m = 0;
    size_t k = 0;
    rpmTag gitag = RPMDBI_PACKAGES;
    rpmTag hetag = RPMTAG_DIRNAMES;
    ARGV_t av;
    rpmRC rc;
    int ec = EXIT_FAILURE;
FD_t fd;
struct stat sb;
static const char fn_dirs[] = "/tmp/dirs.xz";
size_t ndirs = 0;
size_t ndirb = 0;
size_t ndirxz = 0;
static const char fn_bf[] = "/tmp/bf.xz";
static const char fmode_w[] = "w9.xzdio";
rpmbf * bfa = NULL;
size_t npkgs = 0;
size_t nb = 0;
size_t nover = 0;
int ix = 0;
int jx;
int xx;

    optCon = rpmcliInit(argc, argv, optionsTable);
    if (optCon == NULL)
	goto exit;

    if (rpmioFtsOpts == 0)
	rpmioFtsOpts = (FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT);

    if (gitagstr != NULL)
	gitag = tagValue(gitagstr);

    av = poptGetArgs(optCon);

    ts = rpmtsCreate();
    (void) rpmtsSetFlags(ts, transFlags);
    (void) rpmtsSetDFlags(ts, depFlags);
    (void) rpmtsSetVSFlags(ts, vsFlags);

    gi = rpmgiNew(ts, gitag, gikeystr, 0);
    (void) rpmgiSetArgs(gi, av, rpmioFtsOpts, giFlags);

    npkgs = 0;
    while ((rc = rpmgiNext(gi)) == RPMRC_OK)
	npkgs++;
    bfa = xcalloc(npkgs, sizeof(*bfa));
    rpmbfParams(n, e, &m, &k);

    fd = Fopen(fn_dirs, fmode_w);
    nb = 0;
    ix = 0;
    while ((rc = rpmgiNext(gi)) == RPMRC_OK) {
	static const char newline[] = "\n";
	rpmbf bf;
	Header h;

	bf = NULL;
	h = rpmgiHeader(gi);
	he->tag = hetag;
	if (headerGet(h, he, 0) && he->c > 0) {
	    /* XXX make sure n >= _nmin in rpmbfParams() */
	    n = (he->c > 10 ? he->c : 10);
	    rpmbfParams(n, e, &m, &k);
	    nb += (m+7)/8;
	    bf = rpmbfNew(m, k, 0);
	    for (jx = 0; jx < (int) he->c; jx++) {
		const char * s = he->p.argv[jx];
		size_t ns = strlen(s);
		xx = rpmbfAdd(bf, s, ns);
		xx = Fwrite(s, 1, ns, fd);
		xx = Fwrite(newline, 1, 1, fd);
		ndirs++;
		ndirb += ns + 1;
	    }
	}
	xx = Fwrite(newline, 1, 1, fd);
	ndirb++;
	bfa[ix++] = bf;
    }
    xx = Fclose(fd);
    xx = Stat(fn_dirs, &sb);
    xx = Unlink(fn_dirs);
    ndirxz = sb.st_size;

fprintf(stdout, "       npkgs: %u\n", (unsigned) npkgs);
fprintf(stdout, "    Dirnames: %u bytes (%u items)\n", (unsigned) ndirb, ndirs);
fprintf(stdout, "  with XZDIO: %u bytes\n", (unsigned) ndirxz);

fprintf(stdout, "Bloom filter: false positives: %5.2g\n", e);
nover = npkgs * 16;
fprintf(stdout, "Uncompressed: %u = parms(%u) + bitmaps(%u) bytes\n", (unsigned)nb+nover, (unsigned)nover, (unsigned)nb);
fprintf(stdout, "  with XZDIO: %u bytes\n", rpmbfWrite(Fopen(fn_bf, fmode_w), bfa, npkgs));
 
    ec = EXIT_SUCCESS;

exit:
    for (ix = 0; ix < (int) npkgs; ix++)
	bfa[ix] = rpmbfFree(bfa[ix]);
    bfa = _free(bfa);
    gi = rpmgiFree(gi);
    (void) rpmtsFree(ts); 
    ts = NULL;
    optCon = rpmcliFini(optCon);

    return ec;
}
Esempio n. 15
0
static int doIcon(Spec spec, Header h)
	/*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
	/*@modifies h, rpmGlobalMacroContext, fileSystem, internalState  @*/
{
    static size_t iconsize = 0;
    HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
    const char *fn, *Lurlfn = NULL;
    struct Source *sp;
    size_t nb;
    rpmuint8_t * icon;
    FD_t fd = NULL;
    int rc = RPMRC_FAIL;	/* assume error */
    int urltype;
    int xx;

    if (iconsize == 0) {
	iconsize = rpmExpandNumeric("%{?_build_iconsize}");
	if (iconsize < 2048)
	    iconsize = 2048;
    }
    icon = alloca(iconsize+1);

    for (sp = spec->sources; sp != NULL; sp = sp->next) {
	if (sp->flags & RPMFILE_ICON)
	    break;
    }
    if (sp == NULL) {
	rpmlog(RPMLOG_ERR, _("No icon file in sources\n"));
	goto exit;
    }

#if defined(RPM_VENDOR_OPENPKG) /* splitted-source-directory */
    /* support splitted source directories, i.e., source files which
       are alternatively placed into the .spec directory and picked
       up from there, too. */
    Lurlfn = rpmGenPath(NULL, "%{_specdir}/", sp->source);
    if (access(Lurlfn, F_OK) == -1) {
        Lurlfn = _free(Lurlfn);
        Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source);
    }
#else
    Lurlfn = rpmGenPath(NULL, "%{_icondir}/", sp->source);
#endif

    fn = NULL;
    urltype = urlPath(Lurlfn, &fn);
    switch (urltype) {  
    case URL_IS_HTTPS: 
    case URL_IS_HTTP:
    case URL_IS_FTP:
    case URL_IS_PATH:
    case URL_IS_UNKNOWN:
	break;
    case URL_IS_DASH:
    case URL_IS_HKP:
    case URL_IS_MONGO:	/* XXX FIXME */
	rpmlog(RPMLOG_ERR, _("Invalid icon URL: %s\n"), Lurlfn);
	goto exit;
	/*@notreached@*/ break;
    }

    fd = Fopen(fn, "r%{?_rpmgio}");
    if (fd == NULL || Ferror(fd)) {
	rpmlog(RPMLOG_ERR, _("Unable to open icon %s: %s\n"),
		fn, Fstrerror(fd));
	rc = RPMRC_FAIL;
	goto exit;
    }

    *icon = '\0';
    nb = Fread(icon, sizeof(icon[0]), iconsize, fd);
    if (Ferror(fd) || nb == 0) {
	rpmlog(RPMLOG_ERR, _("Unable to read icon %s: %s\n"),
		fn, Fstrerror(fd));
	goto exit;
    }
    if (nb >= iconsize) {
	rpmlog(RPMLOG_ERR, _("Icon %s is too big (max. %d bytes)\n"),
		fn, (int)iconsize);
	goto exit;
    }

    if (icon[0] == 'G' && icon[1] == 'I' && icon[2] == 'F')
	he->tag = RPMTAG_GIF;
    else
    if (icon[0] == '/' && icon[1] == '*' && icon[2] == ' '
     && icon[3] == 'X' && icon[4] == 'P' && icon[5] == 'M')
	he->tag = RPMTAG_XPM;
    else
	he->tag = tagValue("Icon");
    he->t = RPM_BIN_TYPE;
    he->p.ui8p = icon;
    he->c = (rpmTagCount)nb;
    xx = headerPut(h, he, 0);
    rc = 0;
    
exit:
    if (fd) {
	(void) Fclose(fd);
	fd = NULL;
    }
    Lurlfn = _free(Lurlfn);
    return rc;
}
Esempio n. 16
0
/*! Parses SIM contacts in TLV format.
 *
 * \param rawData SIM contacts in TLV format.
 * \return List of contacts.
*/
QList<QContact> CntSimStorePrivate::decodeSimContactsL(TDes8& rawData) const
{
    PbkPrintToLog(_L("CntSymbianSimEngine::decodeSimContactsL() - IN"));
    QList<QContact> fetchedContacts;
    QContact currentContact;

    TBuf16<KDataClientBuf> buffer;
    TPtrC16 bufPtr(buffer);

    TUint8 tagValue(0);
    CPhoneBookBuffer::TPhBkTagType dataType;

    bool isAdditionalNumber = false;

    CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer();
    CleanupStack::PushL(pbBuffer);
    pbBuffer->Set(&rawData);
    pbBuffer->StartRead();

    while (pbBuffer->GetTagAndType(tagValue, dataType) == KErrNone) {
        switch (tagValue)
        {
            case RMobilePhoneBookStore::ETagPBAdnIndex:
            {
                //save contact's id (SIM card index) and manager's name
                TUint16  index;
                if (pbBuffer->GetValue(index) == KErrNone) {
                    QScopedPointer<QContactId> contactId(new QContactId());
                    contactId->setLocalId(index);
                    contactId->setManagerUri(m_managerUri);
                    currentContact.setId(*contactId);
                }
                isAdditionalNumber = false;
                break;
            }
            case RMobilePhoneBookStore::ETagPBTonNpi:
            {
                // Note, that TON info can be incorporated into the phone number by Etel
                // implementation (TSY). E.g. this is the case with Nokia TSY.
                // Here general case is implemented.

                // Check number type, we are only interested if it's international or not.
                // We assume here that ETagPBTonNpi always comes after ETagPBNumber, not before.
                TUint8  tonNpi;
                if (pbBuffer->GetValue(tonNpi) == KErrNone) {
                    TUint8  intFlag = (tonNpi & KEtsiTonPosition) >> 4;
                    if (intFlag == 1) {
                        //international number format, append "+" to the last
                        //saved number
                        QList<QContactDetail> phoneNumbers = currentContact.details(
                                QContactPhoneNumber::DefinitionName);
                        if (phoneNumbers.count() > 0) {
                            QContactPhoneNumber lastNumber = static_cast<QContactPhoneNumber>(
                                phoneNumbers.at(phoneNumbers.count() - 1));
                            QString number = lastNumber.number();
                            number.insert(0, "+");
                            lastNumber.setNumber(number);
                            if (m_storeInfo.m_readOnlyAccess)
                                m_engine.setReadOnlyAccessConstraint(&lastNumber);
                            currentContact.saveDetail(&lastNumber);
                        }
                    }
                }

                // We have rearched to the end of the number,
                // invalidate additional number flag.
                isAdditionalNumber = false;
                break;
            }
            case RMobilePhoneBookStore::ETagPBText:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    if (isAdditionalNumber) {
                        // For additional number bufPtr contains number alpha string,
                        // this is ignored currently
                    }
                    else {
                        // Contact name otherwise
                        QContactName name;
                        QString nameString = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                        name.setCustomLabel(nameString);
                        if (m_storeInfo.m_readOnlyAccess)
                            m_engine.setReadOnlyAccessConstraint(&name);
                        currentContact.saveDetail(&name);
                        QContactManager::Error error(QContactManager::NoError);
                        m_engine.setContactDisplayLabel(&currentContact, m_engine.synthesizedDisplayLabel(currentContact, &error));
                    }
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBSecondName:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactNickname nickName;
                    QString name = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    nickName.setNickname(name);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&nickName);
                    currentContact.saveDetail(&nickName);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBNumber:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactPhoneNumber phoneNumber;
                    QString number = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    phoneNumber.setNumber(number);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&phoneNumber);
                    currentContact.saveDetail(&phoneNumber);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBAnrStart:
            {
                // This tag should precede every additional number entry
                isAdditionalNumber = true;
                break;
            }
            case RMobilePhoneBookStore::ETagPBEmailAddress:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactEmailAddress email;
                    QString emailAddress = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    email.setEmailAddress(emailAddress);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&email);
                    currentContact.saveDetail(&email);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBNewEntry:
            {
                // This signals the end of the entry and is a special case
                // which will be handled below.
                break;
            }
            default:
            {
                // An unsupported field type - just skip this value
                pbBuffer->SkipValue(dataType);
                break;
            }
        } //switch

        // save contact to the array of contact to be returned if the whole entry was extracted
        if ((tagValue == RMobilePhoneBookStore::ETagPBNewEntry && currentContact.localId() > 0) ||
            (pbBuffer->RemainingReadLength() == 0 && currentContact.localId() > 0)) {
            fetchedContacts.append(currentContact);
            //clear current contact
            currentContact.clearDetails();
            QScopedPointer<QContactId> contactId(new QContactId());
            contactId->setLocalId(0);
            contactId->setManagerUri(QString());
            currentContact.setId(*contactId);
        }
    } //while
Esempio n. 17
0
static JSBool
rpmts_dbkeys(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
    void * ptr = JS_GetInstancePrivate(cx, obj, &rpmtsClass, NULL);
    rpmts ts = ptr;
    jsval tagid = JSVAL_VOID;
    jsval v = JSVAL_VOID;
    rpmTag tag = RPMTAG_NVRA;
    rpmMireMode _mode = RPMMIRE_PCRE;
    const char * _pat = "^a.*$";
    ARGV_t _av = NULL;
    JSBool ok = JS_FALSE;
    int xx;

_METHOD_DEBUG_ENTRY(_debug);

    if (!(ok = JS_ConvertArguments(cx, argc, argv, "/vvu", &v, &tagid, &v, &_mode)))
        goto exit;

    if (!JSVAL_IS_VOID(tagid)) {
	/* XXX TODO: make sure both tag and key were specified. */
	tag = JSVAL_IS_INT(tagid)
		? (rpmTag) JSVAL_TO_INT(tagid)
		: tagValue(JS_GetStringBytes(JS_ValueToString(cx, tagid)));
    }

    if (JSVAL_IS_VOID(v))
	_pat = "^.*$";
    else if (JSVAL_IS_NULL(v))
	_pat = NULL;
    else if (JSVAL_IS_STRING(v))
	_pat = JS_GetStringBytes(JS_ValueToString(cx, v));
#ifdef	NOTYET
    else if (JSVAL_IS_NUMBER(v)) {
	uint32_t _u = 0;
	if (!JS_ValueToECMAUint32(cx, v, &_u)) {
	    *rval = JSVAL_VOID;
	    goto exit;
	}
    } else
	;
#endif

    switch (_mode) {
    default:
	*rval = JSVAL_VOID;
	goto exit;
	break;
    case RPMMIRE_DEFAULT:
    case RPMMIRE_STRCMP:
    case RPMMIRE_REGEX:
    case RPMMIRE_GLOB:
    case RPMMIRE_PCRE:
	break;
    }

    if (rpmtsGetRdb(ts) == NULL)
	xx = rpmtsOpenDB(ts, O_RDONLY);

    if (rpmdbMireApply(rpmtsGetRdb(ts), tag, _mode, _pat, &_av))
	*rval = JSVAL_VOID;
    else if (_av == NULL || _av[0] == NULL)
	*rval = JSVAL_NULL;
    else {
	int _ac = argvCount(_av);
	int i;
	JSObject * arr = JS_NewArrayObject(cx, 0, NULL);
	*rval = OBJECT_TO_JSVAL(arr);

	for (i = 0; i < _ac; i++) {
	    v = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, _av[i]));
	    ok = JS_SetElement(cx, arr, i, &v);
	}
    }

exit:
    ok = JS_TRUE;
    _av = argvFree(_av);
    return ok;
}