void MsgAudioSelectionEngine::HandleQueryCompletedL(CMdEQuery& aQuery,
        TInt aError)
    {
    iNameList.clear();
    iUriList.clear();
    if (aError == KErrCancel)
        {
        emit queryError(aError);
        return;
        }
    else
        {
        QMap<QString,QString> nameUriList;
        CMdEObjectQuery* query = static_cast<CMdEObjectQuery*> (&aQuery);
        TInt count = query->Count();
        for (TInt i = 0; i < count; ++i)
            {
            CMdEObject* object =
                    (CMdEObject*) query->TakeOwnershipOfResult(i);
            CleanupStack::PushL(object);
            CMdEPropertyDef& propDef = MsgAudioSelectionEngine::PropertyDefL(
                    iSession, MsgAudioSelectionEngine::EAttrFileName);

            CMdEProperty* property = 0;
            TInt err = object->Property(propDef, property, 0);
            if (err != KErrNotFound && property)
                {
                QString songName(XQConversions::s60DescToQString(
                        property->TextValueL()));
                QString uriValue(XQConversions::s60DescToQString(
                        object->Uri()));
                
                //insert into the map
                nameUriList.insertMulti(uriValue, songName);
                }
            CleanupStack::PopAndDestroy(object);
            }
        
        //now get all the song names and sort them
        iNameList = nameUriList.values();
        iNameList.sort();
        
        // go through the song list and get the associated uri
        // insert into the uri list
        int nameListTotal = iNameList.count();
        for(int nameListCount = 0; 
                nameListCount<nameListTotal;
                nameListCount++)
            {
            QString key = nameUriList.key(iNameList.at(nameListCount));
            iUriList.append(key);
            nameUriList.remove(key);                        
            }
        
        // emit the list to the model
        emit queryComplete(iNameList, iUriList);
        }
    }
Exemplo n.º 2
0
nsresult
ProxyAutoConfig::GetProxyForURI(const nsCString &aTestURI,
                                const nsCString &aTestHost,
                                nsACString &result)
{
  if (mJSNeedsSetup)
    SetupJS();

  if (!mJSRuntime || !mJSRuntime->IsOK())
    return NS_ERROR_NOT_AVAILABLE;

  JSContext *cx = mJSRuntime->Context();
  JSAutoRequest ar(cx);
  JSAutoCompartment ac(cx, mJSRuntime->Global());

  // the sRunning flag keeps a new PAC file from being installed
  // while the event loop is spinning on a DNS function. Don't early return.
  sRunning = this;
  mRunningHost = aTestHost;

  nsresult rv = NS_ERROR_FAILURE;
  JS::RootedString uriString(cx, JS_NewStringCopyZ(cx, aTestURI.get()));
  JS::RootedString hostString(cx, JS_NewStringCopyZ(cx, aTestHost.get()));

  if (uriString && hostString) {
    JS::RootedValue uriValue(cx, STRING_TO_JSVAL(uriString));
    JS::RootedValue hostValue(cx, STRING_TO_JSVAL(hostString));

    JS::Value argv[2] = { uriValue, hostValue };
    JS::Rooted<JS::Value> rval(cx);
    bool ok = JS_CallFunctionName(cx, mJSRuntime->Global(),
                                    "FindProxyForURL", 2, argv, rval.address());

    if (ok && rval.isString()) {
      nsDependentJSString pacString;
      if (pacString.init(cx, rval.toString())) {
        CopyUTF16toUTF8(pacString, result);
        rv = NS_OK;
      }
    }
  }

  mRunningHost.Truncate();
  sRunning = nullptr;
  return rv;
}