예제 #1
0
nsresult
nsAutoCompleteController::StartSearches()
{
  // Don't create a new search timer if we're already waiting for one to fire.
  // If we don't check for this, we won't be able to cancel the original timer
  // and may crash when it fires (bug 236659).
  if (mTimer || !mInput)
    return NS_OK;

  // Get the timeout for delayed searches.
  PRUint32 timeout;
  mInput->GetTimeout(&timeout);

  PRUint32 immediateSearchesCount = mImmediateSearchesCount;
  if (timeout == 0) {
    // All the searches should be executed immediately.
    immediateSearchesCount = mSearches.Count();
  }

  if (immediateSearchesCount > 0) {
    nsresult rv = BeforeSearches();
    if (NS_FAILED(rv))
      return rv;
    StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_IMMEDIATE);

    if (mSearches.Count() == immediateSearchesCount) {
      // Either all searches are immediate, or the timeout is 0.  In the
      // latter case we still have to execute the delayed searches, otherwise
      // this will be a no-op.
      StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED);

      // All the searches have been started, just finish.
      AfterSearches();
      return NS_OK;
    }
  }

  MOZ_ASSERT(timeout > 0, "Trying to delay searches with a 0 timeout!");

  // Now start the delayed searches.
  nsresult rv;
  mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
  if (NS_FAILED(rv))
      return rv;
  rv = mTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
  if (NS_FAILED(rv))
      mTimer = nsnull;

  return rv;
}
예제 #2
0
NS_IMETHODIMP
nsAutoCompleteController::Notify(nsITimer *timer)
{
  mTimer = nsnull;
  StartSearch();
  return NS_OK;
}
NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsISimpleEnumerator* *result)
{
  nsresult rv;

  if (mIsQueryURI)
  {
    rv = StartSearch();
    NS_ENSURE_SUCCESS(rv, rv);

    // TODO
    // Search is synchronous so need to return
    // results after search is complete
    nsCOMPtr<nsIMutableArray> array(do_CreateInstance(NS_ARRAY_CONTRACTID));
    for (auto iter = mSearchCache.Iter(); !iter.Done(); iter.Next()) {
      array->AppendElement(iter.Data(), false);
    }
    return NS_NewArrayEnumerator(result, array);
  }

  rv = GetAbDatabase();

  if (NS_FAILED(rv) || !mDatabase)
    return rv;

  return m_IsMailList ? mDatabase->EnumerateListAddresses(this, result) :
                        mDatabase->EnumerateCards(this, result);
}
예제 #4
0
bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
{
	std::vector<std::string> tags(
		std::make_move_iterator(GetList(tag)),
		std::make_move_iterator(StringIterator())
	);
	if (number > tags.size())
		return false;

	std::random_shuffle(tags.begin(), tags.end());
	auto it = tags.begin()+rand()%(tags.size()-number);
	for (size_t i = 0; i < number && it != tags.end(); ++i)
	{
		StartSearch(true);
		AddSearch(tag, *it++);
		std::vector<std::string> paths;
		MPD::SongIterator s = CommitSearchSongs(), end;
		for (; s != end; ++s)
			paths.push_back(s->getURI());
		StartCommandsList();
		for (const auto &path : paths)
			AddSong(path);
		CommitCommandsList();
	}
	return true;
}
예제 #5
0
// main qt window
mainWin::mainWin()
{

   // font for label
   QFont tutFont("Arial", 7);
   QFont mainFont("Arial", 25);

   //sets up canvas
   canvas = new Canvas(this);
   //sets up buttons
   next = new QPushButton("Go");
   close = new QPushButton("close");
   inst  = new QPushButton("move goal = Right click and drag");
   inst2 = new QPushButton("move start = Left click and drag");
   next->setFont(mainFont);
   close->setFont(mainFont);

   // QT connections
   connect(next, SIGNAL(clicked()), canvas, SLOT(StartSearch()));
   connect(close, SIGNAL(clicked()), this, SLOT(close()));

   //sets up layout for window
   QGridLayout *layout = new QGridLayout;
   layout -> addWidget(canvas,0,0,4,4);
   layout -> addWidget(inst,5,0,1,1);
   layout -> addWidget(inst2,5,2,1,1);
   layout -> addWidget(next,7,0,1,3);
   layout -> addWidget(close,7,3,1,1);
   setLayout(layout);

   // sets up timer, connects it then starts it.
   timer = new QTimer(this);
   connect(timer, SIGNAL(timeout()), this, SLOT(updateSearch()));
   timer->start(10);
}
예제 #6
0
SolverResult
ContestDijkstra::Solve(bool exhaustive)
{
  assert(num_stages <= MAX_STAGES);

  if (trace_master.size() < num_stages) {
    /* not enough data in master trace */
    ClearTrace();
    finished = false;
    return SolverResult::FAILED;
  }

  if (finished || dijkstra.IsEmpty()) {
    UpdateTrace(exhaustive);

    if (n_points < num_stages)
      return SolverResult::FAILED;

    // don't re-start search unless we have had new data appear
    if (!trace_dirty && !finished)
      return SolverResult::FAILED;
  } else if (exhaustive || n_points < num_stages ||
             CheckMasterSerial()) {
    UpdateTrace(exhaustive);
    if (n_points < num_stages)
      return SolverResult::FAILED;
  }

  assert(n_points >= num_stages);

  if (trace_dirty) {
    trace_dirty = false;
    finished = false;

    dijkstra.Clear();
    dijkstra.Reserve(CONTEST_QUEUE_SIZE);

    StartSearch();
    AddStartEdges();
    if (dijkstra.IsEmpty())
      return SolverResult::FAILED;
  }

  SolverResult result = DistanceGeneral(exhaustive ? 0 - 1 : 25);
  if (result != SolverResult::INCOMPLETE) {
    if (incremental && continuous)
      /* enable the incremental solver, which considers the existing
         Dijkstra edge map */
      finished = true;
    else
      /* start the next iteration from scratch */
      dijkstra.Clear();

    if (result == SolverResult::VALID && !SaveSolution())
      result = SolverResult::FAILED;
  }

  return result;
}
예제 #7
0
void VSCSearch::SetupConnections()
{
    connect( this->ui.pushButtonStart, SIGNAL( clicked() ), this, SLOT(StartSearch()));
    connect( this->ui.pushButtonStop, SIGNAL( clicked() ), this, SLOT(StopSearch()));
    connect( this->ui.pushButtonAdd, SIGNAL( clicked() ), this, SLOT(AddAll()));
	connect( this->ui.pushButtonSelect, SIGNAL( clicked() ), this, SLOT(SelectAll()));
	connect( this, SIGNAL(NewSearchedItem(astring, astring, astring, astring, astring, astring) ), this, SLOT(AddItem(astring, astring, astring, astring, astring, astring)), Qt::QueuedConnection);
	//Qt::QueuedConnection
}
/**
 * Launch search UI.
 *
 * <p>The search manager will open a search widget in an overlapping
 * window, and the underlying activity may be obscured.  The search
 * entry state will remain in effect until one of the following events:
 * <ul>
 * <li>The user completes the search.  In most cases this will launch
 * a search intent.</li>
 * <li>The user uses the back, home, or other keys to exit the search.</li>
 * <li>The application calls the {@link #stopSearch}
 * method, which will hide the search window and return focus to the
 * activity from which it was launched.</li>
 *
 * <p>Most applications will <i>not</i> use this interface to invoke search.
 * The primary method for invoking search is to call
 * {@link android.app.Activity#onSearchRequested Activity.onSearchRequested()} or
 * {@link android.app.Activity#startSearch Activity.startSearch()}.
 *
 * @param initialQuery A search string can be pre-entered here, but this
 * is typically null or empty.
 * @param selectInitialQuery If true, the intial query will be preselected, which means that
 * any further typing will replace it.  This is useful for cases where an entire pre-formed
 * query is being inserted.  If false, the selection point will be placed at the end of the
 * inserted query.  This is useful when the inserted query is text that the user entered,
 * and the user would expect to be able to keep typing.  <i>This parameter is only meaningful
 * if initialQuery is a non-empty string.</i>
 * @param launchActivity The ComponentName of the activity that has launched this search.
 * @param appSearchData An application can insert application-specific
 * context here, in order to improve quality or specificity of its own
 * searches.  This data will be returned with SEARCH intent(s).  Null if
 * no extra data is required.
 * @param globalSearch If false, this will only launch the search that has been specifically
 * defined by the application (which is usually defined as a local search).  If no default
 * search is defined in the current application or activity, global search will be launched.
 * If true, this will always launch a platform-global (e.g. web-based) search instead.
 *
 * @see android.app.Activity#onSearchRequested
 * @see #stopSearch
 */
ECode CSearchManager::StartSearch(
    /* [in] */ const String &initialQuery,
    /* [in] */ Boolean selectInitialQuery,
    /* [in] */ IComponentName *launchActivity,
    /* [in] */ IBundle *appSearchData,
    /* [in] */ Boolean globalSearch)
{
    return StartSearch(initialQuery, selectInitialQuery, launchActivity,
                       appSearchData, globalSearch, NULL);
}
예제 #9
0
NS_IMETHODIMP nsAbLDAPDirectory::GetChildCards(nsISimpleEnumerator** result)
{
    nsresult rv;

    // when offline, we need to get the child cards for the local, replicated mdb directory
    PRBool offline;
    nsCOMPtr <nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv,rv);
    rv = ioService->GetOffline(&offline);
    NS_ENSURE_SUCCESS(rv,rv);

    if (offline) {
        nsCString fileName;
        rv = GetReplicationFileName(fileName);
        NS_ENSURE_SUCCESS(rv,rv);

        // if there is no fileName, bail out now.
        if (fileName.IsEmpty())
            return NS_OK;

        // perform the same query, but on the local directory
        nsCAutoString localDirectoryURI(NS_LITERAL_CSTRING(kMDBDirectoryRoot));
        localDirectoryURI.Append(fileName);
        if (mIsQueryURI)
        {
            localDirectoryURI.AppendLiteral("?");
            localDirectoryURI.Append(mQueryString);
        }

        nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
                                         &rv));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr <nsIAbDirectory> directory;
        rv = abManager->GetDirectory(localDirectoryURI,
                                     getter_AddRefs(directory));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = directory->GetChildCards(result);
    }
    else {
        // Start the search
        rv = StartSearch();
        NS_ENSURE_SUCCESS(rv, rv);

        rv = NS_NewEmptyEnumerator(result);
    }

    NS_ENSURE_SUCCESS(rv,rv);
    return rv;
}
예제 #10
0
NS_IMETHODIMP
nsAutoCompleteController::Notify(nsITimer *timer)
{
  mTimer = nsnull;

  if (mImmediateSearchesCount == 0) {
    // If there were no immediate searches, BeforeSearches has not yet been
    // called, so do it now.
    nsresult rv = BeforeSearches();
    if (NS_FAILED(rv))
      return rv;
  }
  StartSearch(nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED);
  AfterSearches();
  return NS_OK;
}
예제 #11
0
/**
 * Similar to {@link #startSearch} but actually fires off the search query after invoking
 * the search dialog.  Made available for testing purposes.
 *
 * @param query The query to trigger.  If empty, request will be ignored.
 * @param launchActivity The ComponentName of the activity that has launched this search.
 * @param appSearchData An application can insert application-specific
 * context here, in order to improve quality or specificity of its own
 * searches.  This data will be returned with SEARCH intent(s).  Null if
 * no extra data is required.
 *
 * @see #startSearch
 */
ECode CSearchManager::TriggerSearch(
    /* [in] */ const String &query,
    /* [in] */ IComponentName *launchActivity,
    /* [in] */ IBundle *appSearchData)
{
    String name;
    launchActivity->GetPackageName(&name);
    if (!mAssociatedPackage.Equals(name)) {
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
        //throw new IllegalArgumentException("invoking app search on a different package " +
        //        "not associated with this search manager");
    }
    if (query == NULL || TextUtils::GetTrimmedLength(query) == 0) {
        //Log.w(TAG, "triggerSearch called with empty query, ignoring.");
        return;
    }
    StartSearch(query, false, launchActivity, appSearchData, false);
    mSearchDialog->LaunchQuerySearch();
    return NOERROR;
}
예제 #12
0
bool DfpnSolver::Validate(DfpnHashTable& hashTable, const SgBlackWhite winner,
                          SgSearchTracer& tracer)
{
    SG_ASSERT_BW(winner);
    DfpnData data;
    if (! TTRead(data))
    {
        PointSequence pv;
        StartSearch(hashTable, pv);
        const bool wasRead = TTRead(data);
        SG_DEBUG_ONLY(wasRead);
        SG_ASSERT(wasRead);
    }

    const bool orNode = (winner == GetColorToMove());
    if (orNode)
    {
        if (! data.m_bounds.IsWinning())
        {
            SgWarning() << "OR not winning. DfpnData:" << data << std::endl;
            return false;
        }
    }
    else // AND node
    {
        if (! data.m_bounds.IsLosing())
        {
            SgWarning() << "AND not losing. DfpnData:" << data << std::endl;
            return false;
        }
	}

    SgEmptyBlackWhite currentWinner;
    if (TerminalState(GetColorToMove(), currentWinner))
    {
        if (winner == currentWinner)
            return true;
        else
        {
            SgWarning() << "winner disagreement: " 
                << SgEBW(winner) << ' ' << SgEBW(currentWinner) 
                << std::endl;
            return false;
        }
    }

    std::vector<SgMove> moves;
    if (orNode)
        moves.push_back(data.m_bestMove);
    else // AND node
        GenerateChildren(moves);

    // recurse
    for (std::vector<SgMove>::const_iterator it = moves.begin();
         it != moves.end(); ++it)
    {
        tracer.AddTraceNode(*it, GetColorToMove());
        PlayMove(*it);
        if (! Validate(hashTable, winner, tracer))
            return false;
        UndoMove();
        tracer.TakeBackTraceNode();
    }
    return true;
}
예제 #13
0
SgEmptyBlackWhite DfpnSolver::StartSearch(DfpnHashTable& hashTable, 
                                          PointSequence& pv)
{
    return StartSearch(hashTable, pv, 
                       DfpnBounds(DfpnBounds::MAX_WORK, DfpnBounds::MAX_WORK));
}