Ejemplo n.º 1
0
void RefactoringClient::addSearchResults(const ClangBackEnd::SourceRangesContainer &sourceRanges)
{
    auto filePaths = convertFilePaths(sourceRanges.filePaths());

    for (const auto &sourceRangeWithText : sourceRanges.sourceRangeWithTextContainers())
        addSearchResult(sourceRangeWithText, filePaths);
}
void BorrowerSearch::searchBorrowers() {
        QSettings settings;
        QString borrowersDbFilePath = settings.value("borrowersDbFilePath").toString();

        // If borrowersDbFilePath is not set,
        // Default to APP_DIR/borrowers.db so the program does not crash.
        if ( borrowersDbFilePath.isEmpty() ) {
            borrowersDbFilePath = "borrowers.db";
        }

	clearResults();

	QString lastnameSearch = nameLast->text();
	QString firstnameSearch = nameFirst->text();

	QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );

        db.setDatabaseName( borrowersDbFilePath );

	if ( db.open() ) {
		QString borrowersQuery = "SELECT * FROM borrowers WHERE firstname LIKE '" 
						+ firstnameSearch + "%' AND surname LIKE '" + lastnameSearch 
						+ "%' ORDER BY firstname ASC";
		QSqlQuery query( borrowersQuery );
	
		qDebug() << "Borrower Search SQL: " + borrowersQuery;
	
		QSqlRecord record = query.record();
		while (query.next()) {
			QString lastname = query.value(record.indexOf("surname")).toString();
			QString firstname = query.value(record.indexOf("firstname")).toString();
			QString dateofbirth = query.value(record.indexOf("dateofbirth")).toString();
			QString streetaddress = query.value(record.indexOf("address")).toString();
			QString city = query.value(record.indexOf("city")).toString();
			QString state = query.value(record.indexOf("state")).toString();
			QString zipcode = query.value(record.indexOf("zipcode")).toString();
			QString cardnumber = query.value(record.indexOf("cardnumber")).toString();
			QString address = streetaddress + "\n" + city + ", " + state + "\n" + zipcode;
	
			qDebug() << query.at() << ":" << lastname << "," << firstname;
	
			addSearchResult( lastname, firstname, dateofbirth, address, cardnumber );
		}

		qDebug() << "Search Complete";

	} else {
		qDebug() << db.lastError();
		qFatal( "Failed to connect." );

		QMessageBox::warning(this, tr("Cannot Borrowers File"),
                                   tr("Unable to open the file borrowers.db.\n"
									"This file is needed in order to search for borrowers."
									"Please create the borrowers.db file and place it in"
									"the same directory as this program.\n\n"),
                                   QMessageBox::Ok);
	}

}
Ejemplo n.º 3
0
SearchTask::SearchTask( MarbleAbstractRunner *runner, MarbleRunnerManager *manager, MarbleModel *model, const QString &searchTerm, const GeoDataLatLonAltBox &preferred ) :
    RunnerTask( manager ),
    m_runner( runner ),
    m_searchTerm( searchTerm ),
    m_preferredBbox( preferred )
{
    connect( m_runner, SIGNAL( searchFinished( QVector<GeoDataPlacemark*> ) ),
             manager, SLOT( addSearchResult( QVector<GeoDataPlacemark*> ) ) );
    m_runner->setModel( model );
}
Ejemplo n.º 4
0
void SearchResults::copyFrom(const SearchResults &other, bool clear)
{
	// remove old items
	if (clear) removeAllSearchResults();
	// copy all items from "other"
	for (int n = 0; n < other.results->count(); n++)
	{
		SearchResultItem *item = other.results->at(n);
		addSearchResult(item->getVideoUrl(), item->getImageUrl(), item->getTitle(),
						item->getDescription(), item->getDuration(), item->getRating());
	}
}
Ejemplo n.º 5
0
int process_search(ApplicationUI *app_Object, packedobjectsdObject *podObj_Searcher, packedobjectsdObject *podObj_Responder, xmlDocPtr doc_search)
{
    /* Declare variables */
    int i;
    int ret;
    int size;
    double max_price = 0.0;
    char *movie_title = NULL;
    char xpath_exp[1000];
    xmlXPathContextPtr xpathp = NULL;
    xmlXPathObjectPtr result = NULL;

    ///////////////////// Initialising XPATH ///////////////////

    /* setup xpath context */
    xpathp = xmlXPathNewContext(doc_search);
    if (xpathp == NULL) {
        qDebug() << "Error in xmlXPathNewContext!";
        xmlXPathFreeContext(xpathp);
        return -1;
    }

    if(xmlXPathRegisterNs(xpathp, (const xmlChar *)NS_PREFIX, (const xmlChar *)NS_URL) != 0) {
        qDebug() << "Error: unable to register NS!";
        xmlXPathFreeContext(xpathp);
        return -1;
    }

    ///////////////////// Evaluating XPATH expression ///////////////////

    sprintf(xpath_exp, "/video/message/search/*"); // xpath expression which should return the movie-title and max-price

    result = xmlXPathEvalExpression((const xmlChar *)xpath_exp, xpathp);
    if (result == NULL) {
        qDebug() << "Error in xmlXPathEvalExpression!";
        xmlXPathFreeObject(result);
        xmlXPathFreeContext(xpathp);
        return -1;
    }

    ///////////////////// Processing search broadcast ///////////////////

    /* the xml doc matches "/video/message/search/asterik(*)" */
    if(xmlXPathNodeSetIsEmpty(result->nodesetval)) {
        xmlXPathFreeObject(result);
        xmlXPathFreeContext(xpathp);
        qDebug() << "the search request is not in valid format";
        return -1;
    }
    else {
        size = result->nodesetval->nodeNr;
        xmlNodePtr cur = result->nodesetval->nodeTab[0];

        for(i = 0; i < size; i++)
        {
            if(!(xmlStrcmp(cur->name, (const xmlChar *)"movie-title")))
            {
                xmlChar *key;
                key = xmlNodeListGetString(doc_search, cur->xmlChildrenNode, 1);
                movie_title = strdup((char *)key);
                xmlFree(key);
            }

            if(!(xmlStrcmp(cur->name, (const xmlChar *)"max-price")))
            {
                xmlChar *key;
                key = xmlNodeListGetString(doc_search, cur->xmlChildrenNode, 1);
                max_price = atof((char *)key);
                xmlFree(key);
            }
            cur = cur->next;
        }
    }

    qDebug() << "************** search request details **************";
    qDebug() << "Movie title: " << movie_title;
    qDebug() << "Maximum price: " << max_price;
    qDebug() << "Searcher's id: " << podObj_Responder->last_searcher;

    // Compare the id with local SEARCHER ID and ignore

    if(podObj_Searcher->unique_id == podObj_Responder->last_searcher) {
        qDebug() << "This is a local searcher request so ignoring this request!";
        ret = 1;
    }
    else {
        ///////////////////// Checking on database ///////////////////
        //fflush(stdout);
        /* checking if search broadcast matches record on the database */
        ret = create_response(app_Object, podObj_Responder, movie_title, max_price);

        // Update search queries on GUI
        char temp_string[200];
        sprintf(temp_string, "%lu    %s    %g", podObj_Responder->last_searcher, movie_title, max_price);

        // set label on qml to the search result

        char id_string[200];
        char price_string[200];

        sprintf(id_string, "%lu", podObj_Responder->last_searcher);
        sprintf(price_string, "%g", max_price);

        qDebug() << id_string << movie_title << price_string;
        ret = addSearchResult(id_string, movie_title, price_string);

        if (ret != -1) {
            app_Object->setQuery();
        }

    }
    ///////////////////// Freeing ///////////////////

    free(movie_title);
    xmlXPathFreeObject(result);
    xmlXPathFreeContext(xpathp);

    return ret;
}