TEST_F(ParserFactoryTests, factory2Filters)
{
    ASSERT_TRUE( parseDocument(
        "structure sname { integer i1;  integer i2; }\n"
        "object factory<sname> name { filter i1 with blah1; filter i2 with blah2; }") );

    EXPECT_EQ(2U, mDocument->objects().size());
    EXPECT_TRUE(checkFactory(1, 2, 1, "name", compil::Factory::EType::object()));
    EXPECT_TRUE(checkFactoryParameterType(1, "sname"));
    EXPECT_TRUE(checkFilter(1, 0, 2, 30, "i1", "blah1"));
    EXPECT_TRUE(checkFilter(1, 1, 2, 52, "i2", "blah2"));
}
Beispiel #2
0
	void LogHandler::publish(const LogRecord& rec)
	{
		if(checkFilter(rec) != DENY)
		{
			doPublish(rec);
		}
	}
Beispiel #3
0
bool Debug::checkFilterString(const char *filter_str)
{
  if (filter_str == NULL) {
    cerr << "Error: unrecognized component filter: NULL" << endl;
    return true; // error
  }

  // check for default filter ("none") before reporting RUBY_DEBUG error
  if ( (string(filter_str) == "none") ) {
    return false; // no error
  }
  
  if (RUBY_DEBUG == false) {
    cerr << "Error: User specified set of debug components, but the RUBY_DEBUG compile-time flag is false." << endl;
    cerr << "Solution: Re-compile with RUBY_DEBUG set to true." << endl;
    return true; // error
  }
  
  if ( (string(filter_str) == "all") ) {
    return false; // no error
  }

  // scan string checking each character
  for (unsigned int i = 0; i < strlen(filter_str); i++) {
    bool unrecognized = checkFilter( filter_str[i] );
    if (unrecognized == true) {
      return true; // error
    }
  }
  return false; // no error
}
Beispiel #4
0
static bool
ScanFiles(File::Visitor &visitor, Path sPath,
          const TCHAR* filter = _T("*"))
{
  TCHAR DirPath[MAX_PATH];
  TCHAR FileName[MAX_PATH];

  if (sPath != nullptr)
    // e.g. "/test/data/something"
    _tcscpy(DirPath, sPath.c_str());
  else
    DirPath[0] = 0;

  // "/test/data/something/"
  _tcscat(DirPath, _T(DIR_SEPARATOR_S));
  _tcscpy(FileName, DirPath);

  // "/test/data/something/*.igc"
  _tcscat(FileName, filter);

  // Find the first matching file
  WIN32_FIND_DATA FindFileData;
  HANDLE hFind = FindFirstFile(FileName, &FindFileData);

  // If no matching file found -> return false
  if (hFind == INVALID_HANDLE_VALUE)
    return false;

  // Loop through remaining matching files
  while (true) {
    if (!IsDots(FindFileData.cFileName) &&
        !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
        checkFilter(FindFileData.cFileName, filter)) {
      // "/test/data/something/"
      _tcscpy(FileName, DirPath);
      // "/test/data/something/blubb.txt"
      _tcscat(FileName, FindFileData.cFileName);
      // Call visitor with the file that was found
      visitor.Visit(Path(FileName), Path(FindFileData.cFileName));
    }

    // Look for next matching file
    if (!FindNextFile(hFind, &FindFileData)) {
      if (GetLastError() == ERROR_NO_MORE_FILES)
        // No more files/folders
        // -> Jump out of the loop
        break;
      else {
        // Some error occured
        // -> Close the handle and return false
        FindClose(hFind);
        return false;
      }
    }
  }
  // Close the file handle
  FindClose(hFind);

  return true;
}
CaptureFilterCombo::CaptureFilterCombo(QWidget *parent, bool plain) :
    QComboBox(parent),
    cf_edit_(NULL)
{
    cf_edit_ = new CaptureFilterEdit(this, plain);

    setEditable(true);
    // Enabling autocompletion here gives us two simultaneous completions:
    // Inline (highlighted text) for entire filters, handled here and popup
    // completion for fields handled by CaptureFilterEdit.
    setAutoCompletion(false);
    setLineEdit(cf_edit_);
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    setInsertPolicy(QComboBox::NoInsert);
    setAccessibleName(tr("Capture filter selector"));
    setStyleSheet(
            "QComboBox {"
#ifdef Q_OS_MAC
            "  border: 1px solid gray;"
#else
            "  border: 1px solid palette(shadow);"
#endif
            "  border-radius: 3px;"
            "  padding: 0px 0px 0px 0px;"
            "  margin-left: 0px;"
            "  min-width: 20em;"
            " }"

            "QComboBox::drop-down {"
            "  subcontrol-origin: padding;"
            "  subcontrol-position: top right;"
            "  width: 16px;"
            "  border-left-width: 0px;"
            " }"

            "QComboBox::down-arrow {"
            "  image: url(:/icons/toolbar/14x14/x-filter-dropdown.png);"
            " }"

            "QComboBox::down-arrow:on { /* shift the arrow when popup is open */"
            "  top: 1px;"
            "  left: 1px;"
            "}"
            );

    connect(this, SIGNAL(interfacesChanged()), cf_edit_, SLOT(checkFilter()));
    connect(cf_edit_, SIGNAL(pushFilterSyntaxStatus(const QString&)),
            this, SIGNAL(pushFilterSyntaxStatus(const QString&)));
    connect(cf_edit_, SIGNAL(popFilterSyntaxStatus()),
            this, SIGNAL(popFilterSyntaxStatus()));
    connect(cf_edit_, SIGNAL(captureFilterSyntaxChanged(bool)),
            this, SIGNAL(captureFilterSyntaxChanged(bool)));
    connect(cf_edit_, SIGNAL(startCapture()), this, SIGNAL(startCapture()));
    connect(cf_edit_, SIGNAL(startCapture()), this, SLOT(saveAndRebuildFilterList()));
    connect(wsApp, SIGNAL(appInitialized()), this, SLOT(rebuildFilterList()));
    connect(wsApp, SIGNAL(preferencesChanged()), this, SLOT(rebuildFilterList()));

    rebuildFilterList();
    clearEditText();
}
void CaptureFilterEdit::updateBookmarkMenu()
{
    if (!bookmark_button_)
        return;

    QMenu *bb_menu = bookmark_button_->menu();
    bb_menu->clear();

    save_action_ = bb_menu->addAction(tr("Save this filter"));
    connect(save_action_, SIGNAL(triggered(bool)), this, SLOT(saveFilter()));
    remove_action_ = bb_menu->addAction(tr("Remove this filter"));
    connect(remove_action_, SIGNAL(triggered(bool)), this, SLOT(removeFilter()));
    QAction *manage_action = bb_menu->addAction(tr("Manage Capture Filters"));
    connect(manage_action, SIGNAL(triggered(bool)), this, SLOT(showFilters()));
    bb_menu->addSeparator();

    for (GList *cf_item = get_filter_list_first(CFILTER_LIST); cf_item; cf_item = g_list_next(cf_item)) {
        if (!cf_item->data) continue;
        filter_def *cf_def = (filter_def *) cf_item->data;
        if (!cf_def->name || !cf_def->strval) continue;

        int one_em = bb_menu->fontMetrics().height();
        QString prep_text = QString("%1: %2").arg(cf_def->name).arg(cf_def->strval);
        prep_text = bb_menu->fontMetrics().elidedText(prep_text, Qt::ElideRight, one_em * 40);

        QAction *prep_action = bb_menu->addAction(prep_text);
        prep_action->setData(cf_def->strval);
        connect(prep_action, SIGNAL(triggered(bool)), this, SLOT(prepareFilter()));
    }

    checkFilter();
}
CaptureFilterCombo::CaptureFilterCombo(QWidget *parent) :
    QComboBox(parent),
    cf_edit_(NULL)
{
    cf_edit_ = new CaptureFilterEdit();

    setEditable(true);
    setLineEdit(cf_edit_);
    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
    setInsertPolicy(QComboBox::NoInsert);
    setAccessibleName(tr("Capture filter selector"));
    setStyleSheet(
            "QComboBox {"
#ifdef Q_OS_MAC
            "  border: 1px solid gray;"
#else
            "  border: 1px solid palette(shadow);"
#endif
            "  border-radius: 3px;"
            "  padding: 0px 0px 0px 0px;"
            "  margin-left: 0px;"
            "  min-width: 20em;"
            " }"

            "QComboBox::drop-down {"
            "  subcontrol-origin: padding;"
            "  subcontrol-position: top right;"
            "  width: 16px;"
            "  border-left-width: 0px;"
            " }"

            "QComboBox::down-arrow {"
            "  image: url(:/dfilter/dfilter_dropdown.png);"
            " }"

            "QComboBox::down-arrow:on { /* shift the arrow when popup is open */"
            "  top: 1px;"
            "  left: 1px;"
            "}"
            );
    completer()->setCompletionMode(QCompleter::PopupCompletion);

    connect(this, SIGNAL(interfacesChanged()), cf_edit_, SLOT(checkFilter()));
    connect(cf_edit_, SIGNAL(pushFilterSyntaxStatus(QString&)),
            this, SIGNAL(pushFilterSyntaxStatus(QString&)));
    connect(cf_edit_, SIGNAL(popFilterSyntaxStatus()),
            this, SIGNAL(popFilterSyntaxStatus()));
    connect(cf_edit_, SIGNAL(captureFilterSyntaxChanged(bool)),
            this, SIGNAL(captureFilterSyntaxChanged(bool)));
    connect(cf_edit_, SIGNAL(startCapture()), this, SIGNAL(startCapture()));
    connect(cf_edit_, SIGNAL(startCapture()), this, SLOT(rebuildFilterList()));
    connect(wsApp, SIGNAL(appInitialized()), this, SLOT(rebuildFilterList()));
    connect(wsApp, SIGNAL(preferencesChanged()), this, SLOT(rebuildFilterList()));

    rebuildFilterList(false);
    clearEditText();
}
Beispiel #8
0
void BufferSinkFilterContext::assign(const FilterContext &ctx, OptionalErrorCode ec)
{
    clear_if(ec);
    m_type = checkFilter(ctx.filter());
    if (m_type == FilterMediaType::Unknown) {
        throws_if(ec, Errors::IncorrectBufferSinkFilter);
        return;
    }
    m_sink = ctx;
}
Beispiel #9
0
pid_t sysWaitPid(pid_t filter, void *waitStatus, int options) {
	//check if any of the current children that match the filter are status=PROCSTATE_FINISHED 
	//if so return
	pid_t ret = 0;
	bool exist = false;
	thread_t curThread = getCurrentThread();
	struct Process *proc = curThread->process;

	acquireSpinlock(&curThread->lock); //lock curThread early to prevent child exit during execution of this function
	acquireSpinlock(&proc->lock);
	struct Process *child = proc->children;
	while (child) {
		acquireSpinlock(&child->lock);
		if (checkFilter(filter, child)) {
			exist = true;
			if (child->state == PROCSTATE_FINISHED) {
				releaseSpinlock(&child->lock);
				ret = child->pid;
				break;
			}
		}
		struct Process *next = child->nextChild;
		releaseSpinlock(&child->lock);
		child = next;
	}
	releaseSpinlock(&proc->lock);
	if (ret > 0) {
		if (waitStatus) {
			//*waitStatus = child->exitValue; //TODO expand this when signals get added
			memcpy(waitStatus, &proc->exitInfo, sizeof(proc->exitInfo));
		}
		removeProcess(child);
		releaseSpinlock(&curThread->lock);
		return ret;
	}
	if (!exist) {
		releaseSpinlock(&curThread->lock);
		return -ECHILD; //child does not exist
	}
	
	//save filter
	//Wait for children to exit
	
	curThread->state = THREADSTATE_PIDWAIT;
	curThread->waitPid = filter;
	kthreadStop();

	if (waitStatus) {
		//*waitStatus = curThread->waitProc->exitValue;
		memcpy(waitStatus, &proc->exitInfo, sizeof(proc->exitInfo));
	}
	removeProcess(curThread->waitProc);

	return curThread->waitPid;
}
TEST_F(ParserFactoryTests, factoryTypeNameCommentOpenFilterFieldWithMethodSemicolonClose)
{
    ASSERT_TRUE( parseDocument(
        "structure sname { integer i; }\n"
        "object factory<sname> name { filter i with blah; }") );

    EXPECT_EQ(2U, mDocument->objects().size());
    EXPECT_TRUE(checkFactory(1, 2, 1, "name", compil::Factory::EType::object()));
    EXPECT_TRUE(checkFactoryParameterType(1, "sname"));
    EXPECT_TRUE(checkFilter(1, 0, 2, 30, "i", "blah"));
}
Beispiel #11
0
void Capture::addFilter(ISD::GDInterface *newFilter)
{
    FilterCaptureCombo->addItem(newFilter->getDeviceName());

    Filters.append(static_cast<ISD::Filter *>(newFilter));

    checkFilter(0);

    FilterCaptureCombo->setCurrentIndex(0);

}
int main(){
  checkSearch("upnp:class = \"object.item.imageItem\" and ( dc:date >= \"2001-10-01\" and dc:date <= \"2001-10-31\" )",
              "class == 'object.item.imageItem' AND ( date >= '2001-10-01' AND date <= '2001-10-31' ) ");

  checkSearch("@id = \"20\"",
              string());

  checkSearch("dc:title contains \"Christmas\"",
              "title LIKE '%Christmas%' ");

  checkSearch("upnp:class derivedfrom \"object.container.album\"",
              "class LIKE '%object.container.album%' ");

  checkFilter("@id,@parentID,@restricted,dc:title");

  checkFilter("*");

  checkFilter("@id,dc:title,upnp:longDescription,res");

  checkFilter("@id,@parentID,@restricted,dc:title,upnp:class,res,dc:date,@childCount,sec:CaptionInfo,sec:CaptionInfoEx,sec:dcmInfo,sec:MetaFileInfo,res@resolution,res@size,upnp:genre,dc:date,upnp:album,res@duration,upnp:albumArtURI,res@bitrate,dc:creator");

  checkFilter("dc:title,av:mediaClass,dc:date,@childCount,res,upnp:rating,upnp:rating@type,upnp:class,res@resolution,res@av:mpfEntries,upnp:album,upnp:genre,upnp:albumArtURI,upnp:albumArtURI@dlna:profileID,dc:creator,res@size,res@duration,res@bitrate,res@protocolInfo");

  checkSort("");

  checkSort("+dc:title,-dc:creator");

  checkSort("dc:title");

  checkSort("+upnp:class");

  checkSort("+@id");

  checkSort("-dc:date");

  return 0;
}
//thread function with connections check loop
static unsigned __stdcall checkthread(void *dummy)
{

#ifdef _DEBUG
	_OutputDebugString(_T("check thread started"));
#endif
	while(1)
	{
		struct CONNECTION* conn=NULL,*connOld=first,*cur=NULL;
#ifdef _DEBUG
		_OutputDebugString(_T("checking connections table..."));
#endif
		if (WAIT_OBJECT_0 == WaitForSingleObject(killCheckThreadEvent,100))
		{
			hConnectionCheckThread=NULL;
			return 0;
		}

		conn=GetConnectionsTable();
		cur=conn;
		while(cur!=NULL) {	
			if (searchConnection(first,cur->strIntIp,cur->strExtIp,cur->intIntPort,cur->intExtPort,cur->state)==NULL && (settingStatusMask & (1 << (cur->state-1)))) {				

#ifdef _DEBUG
				TCHAR msg[1024];
				mir_sntprintf(msg,_countof(msg),_T("%s:%d\n%s:%d"),cur->strIntIp,cur->intIntPort,cur->strExtIp,cur->intExtPort);
				_OutputDebugString(_T("New connection: %s"),msg);
#endif
				pid2name(cur->Pid, cur->PName, SIZEOF(cur->PName));
				if ( WAIT_OBJECT_0 == WaitForSingleObject( hExceptionsMutex, 100 ))
				{
					if (checkFilter(connExceptions,cur))
					{
						showMsg(cur->PName,cur->Pid,cur->strIntIp,cur->strExtIp,cur->intIntPort,cur->intExtPort,cur->state);
						SkinPlaySound(PLUGINNAME_NEWSOUND);
					}
					ReleaseMutex(hExceptionsMutex);
				}
			}
			cur=cur->next;
		}

		first=conn;
		deleteConnectionsTable(connOld);
		Sleep(settingInterval);
	}
	hConnectionCheckThread=NULL;
	return 1;
}
Beispiel #14
0
void LightSolver::pass1()
{
	//Clear the lights and draw occluders into them.
	for (LightSource* light : lights)
	{
		if (light->isEnabled())
		{
			light->clear();
			sf::RenderTexture* tx = light->getOccluder();

			//Set up the view of the light.
			sf::View orig = tx->getView();
			sf::View view = tx->getView();
			view.setCenter(light->getPosition());
			tx->setView(view);

			//Draw occluders
			for (const Occluder* occluder : occluders)
			{
				if (checkFilter(light, occluder))
				{
					tx->draw(*occluder);
				}
			}

			//Calculate shadows
			light->calculateShadow();

			//Draw the light into the color buffer.
			drawToColorFBO(light);

			sf::RenderStates states(sf::BlendAdd);
			fullScreenBuffer.draw(*light, states);

			tx->setView(orig);
		}
	}

	//Once all lights are rendered, update the respective fbo-textures.
	fullScreenBuffer.display();
	colorBuffer.display();
}
Beispiel #15
0
void DkFileAssociationsPreference::createLayout() {
	
	QStringList fileFilters = Settings::param().app().openFilters;

	mModel = new QStandardItemModel(this);
	mModel->setObjectName("fileModel");
	for (int rIdx = 1; rIdx < fileFilters.size(); rIdx++)
		mModel->appendRow(getItems(fileFilters.at(rIdx), checkFilter(fileFilters.at(rIdx), Settings::param().app().browseFilters), checkFilter(fileFilters.at(rIdx), Settings::param().app().registerFilters)));

	mModel->setHeaderData(0, Qt::Horizontal, tr("Filter"));
	mModel->setHeaderData(1, Qt::Horizontal, tr("Browse"));
	mModel->setHeaderData(2, Qt::Horizontal, tr("Register"));

	QTableView* filterTableView = new QTableView(this);
	filterTableView->setModel(mModel);
	filterTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	filterTableView->verticalHeader()->hide();
	//filterTableView->horizontalHeader()->hide();
	filterTableView->setShowGrid(false);
	filterTableView->resizeColumnsToContents();
	filterTableView->resizeRowsToContents();
	filterTableView->setWordWrap(false);

	QPushButton* openDefault = new QPushButton(tr("Set as Default Viewer"), this);
	openDefault->setObjectName("openDefault");

	// now the final widgets
	QVBoxLayout* layout = new QVBoxLayout(this);
	layout->addWidget(filterTableView);

#ifdef Q_OS_WIN
	layout->addWidget(openDefault);
#else
	openDefault->hide();
#endif

}
Beispiel #16
0
void exitProcess(struct Process *proc) { //can also be called on failed fork
	proc->state = PROCSTATE_FINISHED;

	//Orphan any children
	acquireSpinlock(&initProcess.lock);
	struct Process *child = proc->children;
	while (child) {
		acquireSpinlock(&child->lock);
		struct Process *nextChild = child->nextChild;
		linkChild(&initProcess, child);
		releaseSpinlock(&child->lock);
		child = nextChild;
	}
	releaseSpinlock(&initProcess.lock);

	//destroy memory
	mmapDestroy(proc);
	
	//destroy files
	for (int i = 0; i < NROF_INLINE_FDS + proc->nrofFDs; i++) {
		sysClose(i);
	}

	//notify parent TODO send SIGCHLD
	struct Process *parent = proc->parent;
	acquireSpinlock(&parent->lock);
	//TODO add support for multiple threads
	thread_t parentThread = parent->mainThread;
	acquireSpinlock(&parentThread->lock);
	if (parentThread->state == THREADSTATE_PIDWAIT && checkFilter(parentThread->waitPid, proc)) {
		parentThread->waitProc = proc;
		readyQueuePush(parentThread->queueEntry); //TODO
	}
	releaseSpinlock(&parentThread->lock);
	releaseSpinlock(&parent->lock);
}
Beispiel #17
0
int read_post(struct stream *myStream, char **data, struct filter *my_Filter){
  char rBuffer[buffLen]; // Temporary buffer for holding ETHERNET/UDP packets, while filling buffer.

  struct sockaddr from;
  struct cap_header *cp;


  int readBytes=0;
  int filterStatus=0;
  int skip_counter=-1;
  int i=0;
  char *ether=rBuffer;
  struct ethhdr *eh=(struct ethhdr *)ether;
  struct sendhead *sh;
  if(myStream->type==1)
    sh=(struct sendhead *)(rBuffer+sizeof(struct ethhdr));
  if(myStream->type==2 || myStream->type==3)
    sh=(struct sendhead *)ether;
  
  readBytes=0;
  filterStatus=0;
  skip_counter=-1;


  do{
    skip_counter++;
    if(myStream->bufferSize==0){// Initial or last read?
      if (0) printf("Initial read.\n");
      switch(myStream->type){
	case 3://TCP
	  if(myStream->flushed==1){
	    if (0) printf("EOF stream reached.\n");
	    return(0);
	  }
	  myStream->bufferSize=0;
	  bzero(rBuffer,buffLen);
	  myStream->pktCount=0;
	  
	  
	  while(myStream->bufferSize<7410){ // This equals approx 5 packets each of 
//	    if (0) printf("ETH read from %d, to %p max %d bytes, from socket %p\n",myStream->mySocket, myStream->buffer, buffLen,&from);
	    readBytes=recvfrom(myStream->mySocket, myStream->buffer, buffLen, 0, &from, (socklen_t*)&from);

	    if(readBytes<0){
	      perror("Cannot receive Net stream data.");
	      return(0);
	    }
	    if(readBytes==0){
	      perror("Connection closed by client.");
	      myStream->flushed=1;
	      myStream->readPos=0;
	      break;
	    }

	    myStream->bufferSize+=readBytes;
	    if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
//	      if (0) printf("sequenceNr = %04x\nmyStream->readPos=%d\n",ntohs(sh->sequencenr),myStream->readPos);
	    if(ntohs(sh->flush)==1){
	      if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
	      myStream->flushed=1;
	      break;//Break the while loop.
	    }
	  }
	  myStream->readPos=0;
	  if (0) printf("Initial read complete.\n");

	  break;
	case 2://UDP
	  if(myStream->flushed==1){
	    if (0) printf("EOF stream reached.\n");
	    return(0);
	  }
	  myStream->bufferSize=0;
	  bzero(rBuffer,buffLen);
	  myStream->pktCount=0;
	  
	  
	  while(myStream->bufferSize<7410){ // This equals approx 5 packets each of 
//	    if (0) printf("ETH read from %d, to %p max %d bytes, from socket %p\n",myStream->mySocket, myStream->buffer, buffLen,&from);
	    readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0, &from, (socklen_t*)&from);

	    if(readBytes<0){
	      perror("Cannot receive Net stream data.");
	      return(0);
	    }
	    if(readBytes==0){
	      perror("Connection closed by client.");
	      return(0);
	    }
	    myStream->pktCount+=ntohs(sh->nopkts);
	    if(myStream->bufferSize==0) {
	      myStream->expSeqnr=ntohl(sh->sequencenr)+1;
	      myStream->FH.version.minor=ntohs(sh->version.minor);
	      myStream->FH.version.major=ntohs(sh->version.major);
	    } else {
	      if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		myStream->expSeqnr=ntohl(sh->sequencenr);
	      } 
	      myStream->expSeqnr++;
	      if(myStream->expSeqnr>=0xFFFF){
		myStream->expSeqnr=0;
	      }
	      
	    }
	    memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
	    myStream->bufferSize+=(readBytes-sizeof(struct sendhead));
	    if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
//	      if (0) printf("sequenceNr = %04x\nmyStream->readPos=%d\n",ntohs(sh->sequencenr),myStream->readPos);
	    if(ntohs(sh->flush)==1){
	      if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
	      myStream->flushed=1;
	      break;//Break the while loop.
	    }
	  }
	  myStream->readPos=0;
	  if (0) printf("Initial read complete.\n");
	  break;
	case 1://ETHERNET
	  if(myStream->flushed==1){
	    if (0) printf("EOF stream reached.\n");
	    return(0);
	  }
	  myStream->bufferSize=0;
	  bzero(rBuffer,buffLen);
	  myStream->pktCount=0;


	  while(myStream->bufferSize<7410){ // This equals approx 5 packets each of 
//	    if (0) printf("ETH read from %d, to %p max %d bytes\n",myStream->mySocket, myStream->buffer, buffLen);
	    readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0, NULL, NULL);
//	    if (0) printf("eth.type=%04x %02X:%02X:%02X:%02X:%02X:%02X --> %02X:%02X:%02X:%02X:%02X:%02X",ntohs(eh->h_proto),eh->h_source[0],eh->h_source[1],eh->h_source[2],eh->h_source[3],eh->h_source[4],eh->h_source[5],eh->h_dest[0],eh->h_dest[1],eh->h_dest[2],eh->h_dest[3],eh->h_dest[4],eh->h_dest[5]);
//	    if (0) printf("myStream->address = %02x:%02x:%02x:%02x:%02x:%02x \n",myStream->address[0],myStream->address[1],myStream->address[2],myStream->address[3],myStream->address[4],myStream->address[5]);

	    if(readBytes<0){
	      perror("Cannot receive Net stream data.");
	      return(0);
	    }
	    if(readBytes==0){
	      perror("Connection closed by client.");
	      return(0);
	    }

	    if(ntohs(eh->h_proto) == LLPROTO && memcmp((const void*)eh->h_dest,(const void*)myStream->address, ETH_ALEN)==0){
	      myStream->pktCount+=ntohs(sh->nopkts);
	      if(myStream->bufferSize==0) {
		myStream->expSeqnr=ntohl(sh->sequencenr)+1;
		myStream->FH.version.minor=ntohs(sh->version.minor);
		myStream->FH.version.major=ntohs(sh->version.major);

	      } else {
		if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		  if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		  myStream->expSeqnr=ntohl(sh->sequencenr);
		} 
		myStream->expSeqnr++;
		if(myStream->expSeqnr>=0xFFFF){
		  myStream->expSeqnr=0;
		}
		
	      }
	      memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct ethhdr)+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
	      myStream->bufferSize+=(readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
	      if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
//	      if (0) printf("sequenceNr = %04x\nmyStream->readPos=%d\n",ntohs(sh->sequencenr),myStream->readPos);
	      if(ntohs(sh->flush)==1){
		if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
		myStream->flushed=1;
		break;//Break the while loop.
	      }
	    } else {
//	      if (0) printf("Not my address, %d bytes.\n", readBytes);
	    }


	  }
	  myStream->readPos=0;
	  if (0) printf("Initial read complete.\n");
	  break;
	case 0:
	default:
	  readBytes=fread(myStream->buffer, 1, buffLen, myStream->myFile);
	  myStream->bufferSize=readBytes;
	  myStream->readPos=0;
	  break;
      }
//      if (0) printf("Read op filled: %p --- %04x --- %p \n", myStream->buffer, readBytes, myStream->buffer+readBytes);
      if(myStream->bufferSize<buffLen){
	switch(myStream->type){
	  case 3:
	  case 2:
	  case 1:
	    break;
	  case 0:
	  default:
	    if(ferror(myStream->myFile)>0){
	      perror("Reading file.");
	      return(0); // Some error occured.
	    }
	}
      }
      
      if(myStream->bufferSize==0) {
	switch(myStream->type){
	  case 3:
	  case 2:
	  case 1:
	    perror("Connection closed. ");
	    return(0);
	    break;
	  case 0:
	  default:
	    if(feof(myStream->myFile)){
	      perror("EOF reached.");
	      return(0);// End-of-file reached.
	    }
	}
      }

    } else {
      // We have some data in the buffer.
      cp=(struct cap_header*)(myStream->buffer+myStream->readPos);
      if( (cp->caplen+myStream->readPos+sizeof(struct cap_header))<=myStream->bufferSize ) {
	// And we can simply move the pointer forward.

	myStream->readPos+=(cp->caplen+sizeof(struct cap_header));
	cp=(struct cap_header*)(myStream->buffer+myStream->readPos);
	if (0) printf("MtNPt. Next packet is  %d bytes long.\n", cp->caplen);
	if (0) printf("bufferSize = %d, readPos = %d \n", myStream->bufferSize, myStream->readPos);
	if( (cp->caplen+myStream->readPos+sizeof(struct cap_header))>myStream->bufferSize) {
	  // If we read this packet we can potentially endup out side the buffer!!!
	  if (0) printf("\nPacket incomplete.\t");
	  int amount=(myStream->bufferSize)-(myStream->readPos);
	  if (0) printf("Moving %d bytes from %p -> %p \t", amount, myStream->buffer+myStream->readPos, myStream->buffer); 
	  memmove(myStream->buffer,myStream->buffer+myStream->readPos, amount);
	  bzero(myStream->buffer+amount,buffLen-amount);
	  switch(myStream->type){
	    case 3://TCP
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      myStream->bufferSize=amount;
	      bzero(rBuffer,buffLen);
	      myStream->pktCount=0;
	      if (0) printf("Normal read, data present %d\n",amount);
	      if (0) printf("rBuffer = %p, from = %p \n",&rBuffer, &from);
	      while(myStream->bufferSize<7410){
		readBytes=recvfrom(myStream->mySocket, myStream->buffer+myStream->bufferSize, buffLen-myStream->bufferSize, 0,&from, (socklen_t*)&from);
		if(readBytes<0){
		  perror("Cannot receive tcp data.");
		  return(0);
		}
		if(readBytes==0){
		  perror("Connection closed by client.");
		  myStream->flushed=1;
		  myStream->readPos=0;
		  myStream->bufferSize+=(readBytes);
		  break;
		}

		myStream->bufferSize+=(readBytes);
		if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
	      }
	      myStream->readPos=0;

	      break;
	    case 2://UDP
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      myStream->bufferSize=amount;
	      bzero(rBuffer,buffLen);
	      myStream->pktCount=0;
	      if (0) printf("Normal read, data present %d\n",amount);
	      if (0) printf("rBuffer = %p, from = %p \n",&rBuffer, &from);
	      while(myStream->bufferSize<7410){
		readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0,&from, (socklen_t*)&from);
		if(readBytes<0){
		  perror("Cannot receive Ethernet data.");
		  return(0);
		}
		if(readBytes==0){
		  perror("Connection closed by client.");
		  return(0);
		}

		myStream->pktCount+=ntohs(sh->nopkts);
		if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		  if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		  myStream->expSeqnr=ntohl(sh->sequencenr);
		}
		myStream->expSeqnr++;
		if(myStream->expSeqnr>=0xFFFF){
		  myStream->expSeqnr=0;
		}
		memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
		myStream->bufferSize+=(readBytes-sizeof(struct sendhead));
		if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
		if(ntohs(sh->flush)==1){
		  if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
		  myStream->flushed=1;
		  break;//Break the while loop.
		}
	      }
	      myStream->readPos=0;

	      break;
	    case 1://ETHERNET
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      myStream->bufferSize=amount;
	      myStream->pktCount=0;
	      bzero(rBuffer,buffLen);
	      if (0) printf("Normal read, data present %d\n",amount);
	      if (0) printf("rBuffer = %p, from = %p \n",&rBuffer, &from);
	      while(myStream->bufferSize<7410){
		readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0,NULL, NULL);
//		if (0) printf("eth.type=%04x %02X:%02X:%02X:%02X:%02X:%02X --> %02X:%02X:%02X:%02X:%02X:%02X",ntohs(eh->h_proto),eh->h_source[0],eh->h_source[1],eh->h_source[2],eh->h_source[3],eh->h_source[4],eh->h_source[5],eh->h_dest[0],eh->h_dest[1],eh->h_dest[2],eh->h_dest[3],eh->h_dest[4],eh->h_dest[5]);
//		if (0) printf("rBuffer = %p --> %d, from = %p eh = %p \n",&rBuffer, readBytes,&from,eh);
		if(readBytes<0){
		  perror("Cannot receive Ethernet data.");
		  return(0);
		}
		if(readBytes==0){
		  perror("Connection closed by client.");
		  return(0);
		}
		if(ntohs(eh->h_proto) == LLPROTO && memcmp((const void*)eh->h_dest,(const void*)myStream->address, ETH_ALEN)==0){
		  myStream->pktCount+=ntohs(sh->nopkts);
		  if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		    if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		    myStream->expSeqnr=ntohl(sh->sequencenr);
		  }
		  myStream->expSeqnr++;
		  if(myStream->expSeqnr>=0xFFFF){
		    myStream->expSeqnr=0;
		  }
		  memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct ethhdr)+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
		  myStream->bufferSize+=(readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
		  if (0) printf("Buffer Size = %d / %d Packet contained %d packets\n",myStream->bufferSize, buffLen,ntohs(sh->nopkts));
		  if(ntohs(sh->flush)==1){
		    if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
		    myStream->flushed=1;
		    break;//Break the while loop.
		  }
		} else {
//		  if (0) printf("Not my address, %d bytes.\n", readBytes);
		}
	      }
	      myStream->readPos=0;
	      break;
	    case 0:
	    default:
	      readBytes=fread((myStream->buffer+amount), 1, buffLen-amount, myStream->myFile);
	      myStream->bufferSize=amount+readBytes;
	      myStream->readPos=0;
	      break;
	  }
	  if (0) printf("Read op filled: %p --- %d(Max:%d) --- %p \n", myStream->buffer+amount, myStream->bufferSize, buffLen-amount, myStream->buffer+amount+readBytes);

	  if( myStream->bufferSize<(buffLen-amount)){
	    switch(myStream->type){
	      case 3:
	      case 2:
	      case 1:
		break;
	      case 0:
	      default:
		if(ferror(myStream->myFile)>0){
		  if (0) printf("ERROR:Reading file.\n");
		  return(0); // Some error occured.
		}
		break;
	    }
	  }
	  
	  if(myStream->bufferSize==0) {
	    switch(myStream->type){
	      case 3:
	      case 2:
	      case 1:
		break;
	      case 0:
	      default:
		if(feof(myStream->myFile)){
		  if (0) printf("ERROR: 1EOF reached\n");
		  return(0);// End-of-file reached.
		}
		break;
	    }
	  }
	  myStream->readPos=0;	 
	}
      } else { 
	if (0) printf("\nInsufficient data\t");
	// We have data, but not enough. We need to move the existing data to the front and fill up with new.
	int amount=(myStream->bufferSize)-(myStream->readPos+sizeof(struct cap_header)+cp->caplen);
	// Move the data
	if (0) printf("No need to move data, since ETH/UDP are 'messages', containing complete packets. amount = %d\n", amount);
	bzero(myStream->buffer,buffLen);
	memmove(myStream->buffer,myStream->buffer+myStream->readPos, amount);
	switch(myStream->type){
	  case 3:
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      if(myStream->flushed==1){
		if (0) printf("EOF stream reached.\n");
		return(0);
	      }
	      myStream->bufferSize=amount;
	      bzero(rBuffer,buffLen);
	      myStream->pktCount=0;
	      if (0) printf("Normal read, data present %d\n",amount);
	      if (0) printf("rBuffer = %p, from = %p \n",&rBuffer, &from);
	      while(myStream->bufferSize<7410){
		readBytes=recvfrom(myStream->mySocket, 
				   myStream->buffer+myStream->bufferSize, 
				   buffLen-myStream->bufferSize, 0,&from, (socklen_t*)&from);
		if(readBytes<0){
		  perror("Cannot receive tcp data.");
		  return(0);
		}
		if(readBytes==0){
		  perror("Connection closed by client.");
		  myStream->flushed=1;
		  myStream->readPos=0;
		  myStream->bufferSize+=(readBytes);
		  break;
		}
		myStream->bufferSize+=(readBytes);
		if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
	      }
	      myStream->readPos=0;

	    break;

	  case 2:
	    if(myStream->flushed==1){
	      if (0) printf("EOF stream reached.\n");
	      return(0);
	    }
	    myStream->bufferSize=amount;
	    myStream->pktCount=0;
	    amount=0;
	    if (0) printf("Secondary read, incomplete packet.\n");
	    while(myStream->bufferSize<7410){
	      readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0,&from, (socklen_t*)&from);
	      if(readBytes<0){
		perror("Cannot receive Ethernet data.");
		return(0);
	      }
	      if(readBytes==0){
		perror("Connection closed by client.");
		return(0);
	      }
	      myStream->pktCount+=ntohs(sh->nopkts);
	      if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		myStream->expSeqnr=ntohl(sh->sequencenr);
	      }
	      myStream->expSeqnr++;
	      if(myStream->expSeqnr>=0xFFFF){
		myStream->expSeqnr=0;
	      }
	      memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
	      myStream->bufferSize+=(readBytes-sizeof(struct sendhead));
	      if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
	      if(ntohs(sh->flush)==1){
		if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
		myStream->flushed=1;
		break;//Break the while loop.
	      }
	    }
	    myStream->readPos=0;
	    break;
	  case 1:
	    if(myStream->flushed==1){
	      return(0);
	    }
	    myStream->bufferSize=amount;
	    myStream->pktCount=0;
	    amount=0;
//	    if (0) printf("Secondary read, incomplete packet.\n");
	    while(myStream->bufferSize<7410){
	      readBytes=recvfrom(myStream->mySocket, rBuffer, buffLen, 0,NULL, NULL);
	      if(readBytes<0){
		perror("Cannot receive Ethernet data.");
		return(0);
	      }
	      if(readBytes==0){
		perror("Connection closed by client.");
		return(0);
	      }
	      if(ntohs(eh->h_proto) == LLPROTO && memcmp((const void*)eh->h_dest,(const void*)myStream->address, ETH_ALEN)==0){
		myStream->pktCount+=ntohs(sh->nopkts);
		if(myStream->expSeqnr!=ntohl(sh->sequencenr)){
		  if (0) printf("Missmatch of sequence numbers. Expeced %ld got %d\n",myStream->expSeqnr, ntohl(sh->sequencenr));
		  myStream->expSeqnr=ntohl(sh->sequencenr);
		}
		myStream->expSeqnr++;
		if(myStream->expSeqnr>=0xFFFF){
		  myStream->expSeqnr=0;
		}
		memcpy(myStream->buffer+myStream->bufferSize, rBuffer+sizeof(struct ethhdr)+sizeof(struct sendhead), readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
		myStream->bufferSize+=(readBytes-sizeof(struct ethhdr)-sizeof(struct sendhead));
		if (0) printf("Buffer Size = %d / %d \n",myStream->bufferSize, buffLen);
		if(ntohs(sh->flush)==1){
		  if (0) printf("Indicataion of termination from sender.. %d/%d\n", readBytes, myStream->if_mtu);
		  myStream->flushed=1;
		  break;//Break the while loop.
		}
	      } else {
//		if (0) printf("Not my address, %d bytes.\n", readBytes);
	      }
	    }
	    myStream->readPos=0;
	    break;
	  case 0:
	  default:	      
	    readBytes=fread((myStream->buffer+amount), 1, buffLen-amount, myStream->myFile);
	    myStream->bufferSize=amount+readBytes;
	    myStream->readPos=0;
	    break;
	}

	if (0) printf("Read op filled: %p --- %d(Max:%d) --- %p \n", myStream->buffer+amount, myStream->bufferSize, buffLen-amount, myStream->buffer+amount+readBytes);
	if( (myStream->bufferSize)<buffLen){
	  switch(myStream->type){
	    case 3:
	    case 2:
	    case 1:
	      break;
	    case 0:
	    default:
	      if(ferror(myStream->myFile)>0){
		if (0) printf("ERROR:Reading file.\n");
		return(0); // Some error occured.
	      }
	      break;
	  }
	}
	
	if(myStream->bufferSize==0) {
	  switch(myStream->type){
	    case 3:
	    case 2:
	    case 1:
	      break;
	    case 0:
	    default:
	      if(feof(myStream->myFile)){
		if (0) printf("ERROR: 1EOF reached\n");
		return(0);// End-of-file reached.
	      }
	      break;
	  }
	}
      }
    }
    *data=myStream->buffer+myStream->readPos;
    filterStatus=checkFilter((myStream->buffer+myStream->readPos),my_Filter);
//    if (0) printf("[%d]", skip_counter);
  }while(filterStatus==0);
//  if (0) printf("Skipped %d packets.\n",skip_counter);
  
  return(1);
}
bool DisplayFilterEdit::checkFilter()
{
    checkFilter(text());

    return syntaxState() != Invalid;
}
DisplayFilterEdit::DisplayFilterEdit(QWidget *parent, DisplayFilterEditType type) :
    SyntaxLineEdit(parent),
    type_(type),
    bookmark_button_(NULL),
    clear_button_(NULL),
    apply_button_(NULL)
{
    setAccessibleName(tr("Display filter entry"));

    completion_model_ = new QStringListModel(this);
    setCompleter(new QCompleter(completion_model_, this));
    setCompletionTokenChars(fld_abbrev_chars_);

    setDefaultPlaceholderText();

    //   DFCombo
    //     Bookmark
    //     DisplayFilterEdit
    //     Clear button
    //     Apply (right arrow)
    //     Combo drop-down

    if (type_ == DisplayFilterToApply) {
        bookmark_button_ = new StockIconToolButton(this, "x-filter-bookmark");
        bookmark_button_->setCursor(Qt::ArrowCursor);
        bookmark_button_->setMenu(new QMenu());
        bookmark_button_->setPopupMode(QToolButton::InstantPopup);
        bookmark_button_->setToolTip(tr("Manage saved bookmarks."));
        bookmark_button_->setIconSize(QSize(14, 14));
        bookmark_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "}"
                "QToolButton::menu-indicator { image: none; }"
                );
    }

    if (type_ == DisplayFilterToApply) {
        clear_button_ = new StockIconToolButton(this, "x-filter-clear");
        clear_button_->setCursor(Qt::ArrowCursor);
        clear_button_->setToolTip(QString());
        clear_button_->setIconSize(QSize(14, 14));
        clear_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "  margin-left: 1px;"
                "}"
                );
        connect(clear_button_, SIGNAL(clicked()), this, SLOT(clearFilter()));
    }

    connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));

    if (type_ == DisplayFilterToApply) {
        apply_button_ = new StockIconToolButton(this, "x-filter-apply");
        apply_button_->setCursor(Qt::ArrowCursor);
        apply_button_->setEnabled(false);
        apply_button_->setToolTip(tr("Apply this filter string to the display."));
        apply_button_->setIconSize(QSize(24, 14));
        apply_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "}"
                );
        connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyDisplayFilter()));
        connect(this, SIGNAL(returnPressed()), this, SLOT(applyDisplayFilter()));
    }

    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    QSize bksz;
    if (bookmark_button_) {
        bksz = bookmark_button_->sizeHint();
    }
    QSize cbsz;
    if (clear_button_) {
        cbsz = clear_button_->sizeHint();
    }
    QSize apsz;
    if (apply_button_) {
        apsz = apply_button_->sizeHint();
    }
    setStyleSheet(QString(
            "DisplayFilterEdit {"
            "  padding-left: %1px;"
            "  margin-left: %2px;"
            "  margin-right: %3px;"
            "}"
            )
            .arg(frameWidth + 1)
            .arg(bksz.width())
            .arg(cbsz.width() + apsz.width() + frameWidth + 1)
                  );
    checkFilter();
}
bool FieldFilterEdit::checkFilter()
{
    checkFilter(text());

    return syntaxState() != Invalid;
}
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) :
    SyntaxLineEdit(parent),
    plain_(plain),
    field_name_only_(false),
    bookmark_button_(NULL),
    clear_button_(NULL),
    apply_button_(NULL)
{
    setAccessibleName(tr("Capture filter entry"));

    completion_model_ = new QStringListModel(this);
    setCompleter(new QCompleter(completion_model_, this));
    setCompletionTokenChars(libpcap_primitive_chars_);

    placeholder_text_ = QString(tr("Enter a capture filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
    setPlaceholderText(placeholder_text_);
#endif

    // These are fully implemented in DisplayFilterEdit but not here.

    if (!plain_) {
        bookmark_button_ = new StockIconToolButton(this, "x-filter-bookmark");
        bookmark_button_->setCursor(Qt::ArrowCursor);
        bookmark_button_->setPopupMode(QToolButton::InstantPopup);
        bookmark_button_->setToolTip(tr("Manage saved bookmarks."));
        bookmark_button_->setIconSize(QSize(14, 14));
        bookmark_button_->setStyleSheet(
                    "QToolButton {"
                    "  border: none;"
                    "  background: transparent;" // Disables platform style on Windows.
                    "  padding: 0 0 0 0;"
                    "}"
                    "QToolButton::menu-indicator { image: none; }"
            );
        connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked()));
    }

    if (!plain_) {
        clear_button_ = new StockIconToolButton(this, "x-filter-clear");
        clear_button_->setCursor(Qt::ArrowCursor);
        clear_button_->setToolTip(QString());
        clear_button_->setIconSize(QSize(14, 14));
        clear_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "  margin-left: 1px;"
                "}"
                );
        connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear()));
    }

    connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));

    if (!plain_) {
        apply_button_ = new StockIconToolButton(this, "x-filter-apply");
        apply_button_->setCursor(Qt::ArrowCursor);
        apply_button_->setEnabled(false);
        apply_button_->setToolTip(tr("Apply this filter string to the display."));
        apply_button_->setIconSize(QSize(24, 14));
        apply_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "}"
                );
        connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter()));
        connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter()));
    }

    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    QSize bksz;
    if (bookmark_button_) bksz = bookmark_button_->sizeHint();
    QSize cbsz;
    if (clear_button_) cbsz = clear_button_->sizeHint();
    QSize apsz;
    if (apply_button_) apsz = apply_button_->sizeHint();

    setStyleSheet(QString(
            "CaptureFilterEdit {"
            "  padding-left: %1px;"
            "  margin-left: %2px;"
            "  margin-right: %3px;"
            "}"
            )
            .arg(frameWidth + 1)
            .arg(bksz.width())
            .arg(cbsz.width() + apsz.width() + frameWidth + 1)
            );

    QThread *syntax_thread = new QThread;
    syntax_worker_ = new CaptureFilterSyntaxWorker;
    syntax_worker_->moveToThread(syntax_thread);
    connect(wsApp, SIGNAL(appInitialized()), this, SLOT(initCaptureFilter()));
    connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start()));
    connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter()));
    connect(syntax_worker_, SIGNAL(syntaxResult(QString,bool,QString)),
            this, SLOT(setFilterSyntaxState(QString,bool,QString)));
    connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater()));
    syntax_thread->start();

    checkFilter();
}
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) :
    SyntaxLineEdit(parent),
    plain_(plain),
    field_name_only_(false),
    enable_save_action_(false),
    save_action_(NULL),
    remove_action_(NULL),
    bookmark_button_(NULL),
    clear_button_(NULL),
    apply_button_(NULL)
{
    setAccessibleName(tr("Capture filter entry"));

    completion_model_ = new QStringListModel(this);
    setCompleter(new QCompleter(completion_model_, this));
    setCompletionTokenChars(libpcap_primitive_chars_);

    setConflict(false);

    if (!plain_) {
        bookmark_button_ = new StockIconToolButton(this, "x-capture-filter-bookmark");
        bookmark_button_->setCursor(Qt::ArrowCursor);
        bookmark_button_->setMenu(new QMenu());
        bookmark_button_->setPopupMode(QToolButton::InstantPopup);
        bookmark_button_->setToolTip(tr("Manage saved bookmarks."));
        bookmark_button_->setIconSize(QSize(14, 14));
        bookmark_button_->setStyleSheet(
                    "QToolButton {"
                    "  border: none;"
                    "  background: transparent;" // Disables platform style on Windows.
                    "  padding: 0 0 0 0;"
                    "}"
                    "QToolButton::menu-indicator { image: none; }"
            );
        connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked()));
    }

    if (!plain_) {
        clear_button_ = new StockIconToolButton(this, "x-filter-clear");
        clear_button_->setCursor(Qt::ArrowCursor);
        clear_button_->setToolTip(QString());
        clear_button_->setIconSize(QSize(14, 14));
        clear_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "  margin-left: 1px;"
                "}"
                );
        connect(clear_button_, SIGNAL(clicked()), this, SLOT(clearFilter()));
    }

    connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));

#if 0
    // Disable the apply button for now
    if (!plain_) {
        apply_button_ = new StockIconToolButton(this, "x-filter-apply");
        apply_button_->setCursor(Qt::ArrowCursor);
        apply_button_->setEnabled(false);
        apply_button_->setToolTip(tr("Apply this filter string to the display."));
        apply_button_->setIconSize(QSize(24, 14));
        apply_button_->setStyleSheet(
                "QToolButton {"
                "  border: none;"
                "  background: transparent;" // Disables platform style on Windows.
                "  padding: 0 0 0 0;"
                "}"
                );
        connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter()));
    }
#endif
    connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter()));

    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    QSize bksz;
    if (bookmark_button_) bksz = bookmark_button_->sizeHint();
    QSize cbsz;
    if (clear_button_) cbsz = clear_button_->sizeHint();
    QSize apsz;
    if (apply_button_) apsz = apply_button_->sizeHint();

    setStyleSheet(QString(
            "CaptureFilterEdit {"
            "  padding-left: %1px;"
            "  margin-left: %2px;"
            "  margin-right: %3px;"
            "}"
            )
            .arg(frameWidth + 1)
            .arg(bksz.width())
            .arg(cbsz.width() + apsz.width() + frameWidth + 1)
            );

    QComboBox *cf_combo = qobject_cast<QComboBox *>(parent);
    if (cf_combo) {
        connect(cf_combo, SIGNAL(activated(QString)), this, SIGNAL(textEdited(QString)));
    }

    QThread *syntax_thread = new QThread;
    syntax_worker_ = new CaptureFilterSyntaxWorker;
    syntax_worker_->moveToThread(syntax_thread);
    connect(wsApp, SIGNAL(appInitialized()), this, SLOT(updateBookmarkMenu()));
    connect(wsApp, SIGNAL(captureFilterListChanged()), this, SLOT(updateBookmarkMenu()));
    connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start()));
    connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter()));
    connect(syntax_worker_, SIGNAL(syntaxResult(QString,int,QString)),
            this, SLOT(setFilterSyntaxState(QString,int,QString)));
    connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater()));
    syntax_thread->start();
}
void CaptureFilterEdit::checkFilter()
{
    checkFilter(text());
}
CaptureFilterEdit::CaptureFilterEdit(QWidget *parent, bool plain) :
    SyntaxLineEdit(parent),
    plain_(plain),
    field_name_only_(false),
    apply_button_(NULL)
{
    setAccessibleName(tr("Capture filter entry"));

    completion_model_ = new QStringListModel(this);
    setCompleter(new QCompleter(completion_model_, this));
    setCompletionTokenChars(libpcap_primitive_chars_);

    placeholder_text_ = QString(tr("Enter a capture filter %1")).arg(UTF8_HORIZONTAL_ELLIPSIS);
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
    setPlaceholderText(placeholder_text_);
#endif

    //   DFCombo
    //     Bookmark (star)
    //     DispalyFilterEdit
    //     Clear button
    //     Apply (right arrow) + Cancel (x) + Reload (arrowed circle)
    //     Combo drop-down

    // XXX - Move bookmark and apply buttons to the toolbar a la Firefox, Chrome & Safari?
    // XXX - Use native buttons on OS X?

    bookmark_button_ = new QToolButton(this);
    bookmark_button_->setCursor(Qt::ArrowCursor);
    bookmark_button_->setStyleSheet(QString(
            "QToolButton { /* all types of tool button */"
            "  border 0 0 0 0;"
#ifdef Q_OS_MAC
            "  border-right: %1px solid gray;"
#else
            "  border-right: %1px solid palette(shadow);"
#endif
            "  border-top-left-radius: 3px;"
            "  border-bottom-left-radius: 3px;"
            "  padding-left: 1px;"
            "  image: url(:/dfilter/dfilter_bookmark_normal.png) center;"
            "}"

            "QToolButton:hover {"
            "  image: url(:/dfilter/dfilter_bookmark_hover.png) center;"
            "}"
            "QToolButton:pressed {"
            "  image: url(:/dfilter/dfilter_bookmark_pressed.png) center;"
            "}"
            "QToolButton:disabled {"
            "  image: url(:/dfilter/dfilter_bookmark_disabled.png) center;"
            "}"


            ).arg(plain_ ? 0 : 1)
            );
    connect(bookmark_button_, SIGNAL(clicked()), this, SLOT(bookmarkClicked()));

    clear_button_ = new QToolButton(this);
    clear_button_->setCursor(Qt::ArrowCursor);
    clear_button_->setStyleSheet(
            "QToolButton {"
            "  image: url(:/dfilter/dfilter_erase_normal.png) center;"
            "  border: none;"
            "  width: 16px;"
            "}"
            "QToolButton:hover {"
            "  image: url(:/dfilter/dfilter_erase_active.png) center;"
            "}"
            "QToolButton:pressed {"
            "  image: url(:/dfilter/dfilter_erase_selected.png) center;"
            "}"
            );
    clear_button_->hide();
    connect(clear_button_, SIGNAL(clicked()), this, SLOT(clear()));
    connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(checkFilter(const QString&)));

    if (!plain_) {
        apply_button_ = new QToolButton(this);
        apply_button_->setCursor(Qt::ArrowCursor);
        apply_button_->setEnabled(false);
        apply_button_->setStyleSheet(
                "QToolButton { /* all types of tool button */"
                "  border 0 0 0 0;"
                "  border-top-right-radius: 3px;"
                "  border-bottom-right-radius: 3px;"
                "  padding-right: 1px;"
                "  image: url(:/dfilter/dfilter_apply_normal.png) center;"
                "}"

                "QToolButton:hover {"
                "  image: url(:/dfilter/dfilter_apply_hover.png) center;"
                "}"
                "QToolButton:pressed {"
                "  image: url(:/dfilter/dfilter_apply_pressed.png) center;"
                "}"
                "QToolButton:disabled {"
                "  image: url(:/dfilter/dfilter_apply_disabled.png) center;"
                "}"
                );
        connect(apply_button_, SIGNAL(clicked()), this, SLOT(applyCaptureFilter()));
        connect(this, SIGNAL(returnPressed()), this, SLOT(applyCaptureFilter()));
    }

    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
    QSize bksz = bookmark_button_->sizeHint();
    QSize cbsz = clear_button_->sizeHint();
    QSize apsz;
    if (apply_button_) {
        apsz = apply_button_->sizeHint();
    } else {
        apsz.setHeight(0); apsz.setWidth(0);
    }
    setStyleSheet(QString(
            "CaptureFilterEdit {"
            "  padding-left: %1px;"
            "  margin-left: %2px;"
            "  margin-right: %3px;"
            "}"
            )
            .arg(frameWidth + 1)
            .arg(bksz.width())
            .arg(cbsz.width() + apsz.width() + frameWidth + 1)
            );

    QThread *syntax_thread = new QThread;
    syntax_worker_ = new CaptureFilterSyntaxWorker;
    syntax_worker_->moveToThread(syntax_thread);
    connect(wsApp, SIGNAL(appInitialized()), this, SLOT(initCaptureFilter()));
    connect(syntax_thread, SIGNAL(started()), syntax_worker_, SLOT(start()));
    connect(syntax_thread, SIGNAL(started()), this, SLOT(checkFilter()));
    connect(syntax_worker_, SIGNAL(syntaxResult(QString,bool,QString)),
            this, SLOT(setFilterSyntaxState(QString,bool,QString)));
    connect(syntax_thread, SIGNAL(finished()), syntax_worker_, SLOT(deleteLater()));
    syntax_thread->start();
}