示例#1
0
void CDPWizard::lstVariablesToCalc_selectionChanged()
{
    QString myQString;
    int selectionSizeInt=0;
    for ( unsigned int i = 0; i < lstVariablesToCalc->count(); i++ )
    {
        QListBoxItem *item = lstVariablesToCalc->item( i );
        // if the item is selected...
        if ( item->isSelected() )
        {
            // increment the count of selected items
            selectionSizeInt++;
        }
    }
    myQString.sprintf("<p align=\"right\">(%i) Variables selected </p>",selectionSizeInt);
    lblVariableCount->setText(myQString);

    if (selectionSizeInt==0)
    {
        setNextEnabled(currentPage(), false);
    }
    else
    {
        setNextEnabled(currentPage(), true);
    }

}
示例#2
0
int ListBoxDnd::buildList( ListBoxItemList & list )
{
    QListBoxItem * i = ((QListBox *)src)->firstItem();
    while ( i ) {
	if ( i->isSelected() ) {
	    ((QListBox *)src)->setSelected( i, FALSE );
	    list.append( i );
	}
	i = i->next();
    }
    return list.count();
}
示例#3
0
void KActionSelector::buttonRemoveClicked()
{
  // move all selected items from selected to available listbox
  QListBoxItem *item = d->selectedListBox->firstItem();
  while ( item ) {
    if ( item->isSelected() ) {
      d->selectedListBox->takeItem( item );
      d->availableListBox->insertItem( item, insertionIndex( d->availableListBox, d->availableInsertionPolicy ) );
      d->availableListBox->setCurrentItem( item );
      emit removed( item );
    }
    item = item->next();
  }
  if ( d->availableInsertionPolicy == Sorted )
    d->availableListBox->sort();
  d->availableListBox->setFocus();
}
示例#4
0
void CDPWizard::run()
{
  QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
  qApp->processEvents();
  //mark the start time:
  startTime.start();
  QString myLabelString;
  myLabelString.sprintf("<p align=\"right\">Time elapsed: %d s</p>", startTime.elapsed()/1000);
  lblElapsedTime->setText(myLabelString);

  int myFirstYearInFileInt, myJobStartYearInt, myJobEndYearInt;
  QString myInputFileTypeString, myOutputFileTypeString, myOutputPathString;
  QString myQString;

  // get the ouput file path
  climateDataProcessor->setOutputFilePathString(leOutputPath->text()+QDir::separator ());

  // get the input file type
  climateDataProcessor->setInputFileType("GDAL Supported Raster");

  // get the ouput file type
  climateDataProcessor->setOutputFileType(cboOutputFormat->currentText());


  //! @todo Get rid of the whole files in series paradigm
  climateDataProcessor->setFilesInSeriesFlag(true);


  //setup the climate data processor's filereaders
  /** @todo see what this hardcoding means and remove if possible */
  if (!climateDataProcessor->makeFileGroups ())
  {
    std::cerr << "cdpwizards call to make file groups failed!" << std::endl;
    return;
  }
  //add each selected user calculation to the user calculation map
  // Go through all items of the first ListBox
  unsigned int myVarsCount=0;
  for ( unsigned int i = 0; i < lstVariablesToCalc->count(); i++ )
  {
    QListBoxItem *myQListBoxItem = lstVariablesToCalc->item( i );
    // if the item is selected...
    if ( myQListBoxItem->isSelected() )
    {
      climateDataProcessor->addUserCalculation(myQListBoxItem->text().latin1() );
      myVarsCount++;
    }
  }

  progressTotalJob->setProgress(0,myVarsCount);
  //get a summary of the climate dataprocessor class now
#ifdef QGISDEBUG
  std::cout << climateDataProcessor->getDescription() << endl;
#endif
  //
  //now we let the climatedataprocessor run!
  //
  climateDataProcessor->run();
  QApplication::restoreOverrideCursor();
  setFinishEnabled( step_6, TRUE );
} //end of run()
示例#5
0
void CDPWizard::formSelected(const QString  &thePageNameQString)
{
    QString myQString;
    QLineEdit *myLineEdit;

    if (thePageNameQString==tr("Raw data file selection"))
    {
#ifdef QGISDEBUG
        std::cout << "Opening Raw Data File Selection page" << std::endl;
#endif

        checkInputFilenames();
    }

    if (thePageNameQString==tr("File type and variables")) //we do this after leaving the file selection page
    {

        //#ifdef QGISDEBUG
        std::cout << "Leaving file selection page" << std::endl;
        //#endif
        /** @todo Add some checking to make sure each file exists and is readable and valid for its type */
        climateDataProcessor->setMeanTempFileName(leMeanTemp->text());
        climateDataProcessor->setMinTempFileName(leMinTemp->text());
        climateDataProcessor->setMaxTempFileName(leMaxTemp->text());
        climateDataProcessor->setDiurnalTempFileName(leDiurnalTemp->text());
        climateDataProcessor->setMeanPrecipFileName(leMeanPrecipitation->text());
        climateDataProcessor->setFrostDaysFileName(leFrostDays->text());
        climateDataProcessor->setTotalSolarRadFileName(leTotalSolarRadiation->text());

        //turn off next button until one or more variables have been selected
        setNextEnabled(currentPage(), false);


        /////////////////////////////////////////////////////////////////////
        //
        // OK now we need to update the list of available calculations that
        //                       can be carried out.
        //
        /////////////////////////////////////////////////////////////////////
        //
        // get the input file type
        //
        climateDataProcessor->setInputFileType("GDAL Supported Raster");
        //Should not need to have the next line here - it slows everythinf down!
        //climateDataProcessor->makeFileGroups();
        //#ifdef QGISDEBUG

        std::cout << "Getting available calculations list" << std::endl;
        //#endif

        climateDataProcessor->makeAvailableCalculationsMap();
        // and then update the list box

        //List the calculations in  availableCalculationsMap  using an iterator
        QMap<QString, bool> myAvailableCalculationsMap = climateDataProcessor->getAvailableCalculationsMap();
        QMap<QString, bool>::const_iterator myIter;
        //#ifdef QGISDEBUG

        std::cout << myAvailableCalculationsMap.size() << " available calculations in list which are:" << std::endl;
        std::cout << climateDataProcessor->getDescription() << std::endl;
        //#endif
        //clear the current entries from the box
        lstVariablesToCalc->clear();
        for (myIter=myAvailableCalculationsMap.begin(); myIter != myAvailableCalculationsMap.end(); myIter++)
        {
            if (myIter.data())
            {
                //#ifdef QGISDEBUG
                std::cout << myIter.key() << QString(": true\n");
                //#endif

                //need to add some logic here to select the inserted item
                lstVariablesToCalc->insertItem(myIter.key());
            }
            else
            {
#ifdef QGISDEBUG
                std::cout << myIter->first <<  QString(": false\n");
#endif

                //need to add some logic here to select the inserted item
                lstVariablesToCalc->insertItem(myIter.key());
            }
        }
    } //end of test for page 3

    if (thePageNameQString==tr("Output destination")) //we do this after leaving the file type and variables page
    {

    }



    if (thePageNameQString==tr("Summary of processing to be performed")) //we do this when  we arrive at the summary of variables to be calculated
    {
        //update the summary of vars to calculate
        txtVariableSummary->clear();
        for ( unsigned int i = 0; i < lstVariablesToCalc->count(); i++ )
        {
            QListBoxItem *item = lstVariablesToCalc->item( i );
            // if the item is selected...
            if ( item->isSelected() )
            {
                // increment the count of selected items
                txtVariableSummary->append(item->text());
            }
        }

        //update the output file format summary box
        leInputFormatSummary->setText("GDAL Supported Raster");

        //update the file output path box
        leOutputPathSummary->setText(leOutputPath->text());

        txtInputFileSummary->clear();
        txtInputFileSummary->append(leMeanTemp->text());
        txtInputFileSummary->append(leMinTemp->text());
        txtInputFileSummary->append(leMaxTemp->text());
        txtInputFileSummary->append(leDiurnalTemp->text());
        txtInputFileSummary->append(leMeanPrecipitation->text());
        txtInputFileSummary->append(leMeanPrecipitation->text());
        txtInputFileSummary->append(leFrostDays->text());
        txtInputFileSummary->append(leTotalSolarRadiation->text());
    } //end of test for page 5

    if (thePageNameQString==tr("Progress")) //we do this when we start the calculation
    {
        qApp->processEvents();
        run();
    }
} //end of formSelected
void MessageFilterDialog::checkState()
{
  bool update = false;
  bool add = false;

  // the state check varies depending on if their is a current filter or not
  if (m_currentFilter)
  {
    uint32_t type;
    uint64_t types = 0;
    
    // buttons should only be enabled for valid message filter content
    if (!m_name->text().isEmpty() &&
	!m_pattern->text().isEmpty() &&
	QRegExp(m_pattern->text()).isValid())
    {
      // iterate over all the message types
      for (QListBoxItem* currentLBT = m_messageTypes->firstItem();
	   currentLBT;
	   currentLBT = currentLBT->next())
      {
	// is the current item selected
	if (currentLBT->isSelected())
	{
	  // get the items message type
	  type = ((MessageFilterListBoxText*)currentLBT)->data();

	  // add the message type into the message types
	  types |= (uint64_t(1) << type);

	  // found a selected item, fields are valid for update
	  update = true;
	}
      }

      // only enable add if the filter is different from its predecessor
      if ((m_name->text() != m_currentFilter->name()) || 
	  (m_pattern->text() != m_currentFilter->regexp().pattern()) ||
	  (types != m_currentFilter->types()))
	add = true;

    }
  }
  else
  {
    // buttons should only be enabled for valid message filter content
    if (!m_name->text().isEmpty() &&
	!m_pattern->text().isEmpty())
    {
      // iterate over all the message types
      for (QListBoxItem* currentLBT = m_messageTypes->firstItem();
	   currentLBT;
	   currentLBT = currentLBT->next())
      {
	// if the item isn't selected, try the next item
	if (!currentLBT->isSelected())
	  continue;
	
	// found a selected item, fields are valid for add
	add = true;
	break;
      }
    }
  }

  // set the button states according to the results from above
  m_add->setEnabled(add);
  m_update->setEnabled(update);

  // only enable delete if editing an existing filter
  m_delete->setEnabled(m_currentFilter != 0);
}
void MessageFilterDialog::addFilter()
{
  uint32_t type;
  uint64_t types = 0;

  // iterate over the message types
  for (QListBoxItem* currentLBT = m_messageTypes->firstItem();
       currentLBT;
       currentLBT = currentLBT->next())
  {
    // if the item isn't selected, add in its type flag, and enable updates
    if (currentLBT->isSelected())
    {
      // get the message type of the selected item
      type = ((MessageFilterListBoxText*)currentLBT)->data();

      // add its flag to the types 
      types |= (uint64_t(1) << type);
    }
  } 

  // create a message filter object
  MessageFilter newFilter(m_name->text(), types, m_pattern->text());

  // if this isn't a valid filter, don't create it
  if (!newFilter.valid())
    return;

  // add the new filter
  m_currentFilterNum = m_filters->addFilter(newFilter);
  
  // if it is a valid filter, make the new filter the current selection
  if (m_currentFilterNum != 0xFF)
  {
    // retrieve the current item
    m_currentFilter = m_filters->filter(m_currentFilterNum);

    // iterate over the existing filters
    for (QListBoxItem* currentLBT = m_existingFilters->firstItem();
	 currentLBT;
	 currentLBT = currentLBT->next())
    {
      // find the current filter
      if (((MessageFilterListBoxText*)currentLBT)->data() == m_currentFilterNum)
      {
	// make the current filter the selected filter
	m_existingFilters->setSelected(currentLBT, true);
	break;
      }
    }
  }
  else // clear the current filter
  {
    // clear the current filter
    m_currentFilter = 0;
    clearFilter();
  }
  
  // setup the current dialog state
  checkState();
}
void kiptablesgenerator::accept()
{
  QString rulesList;
  rulesList =
    "#!/bin/sh\n" +
    i18n("# Generated by KIptablesGenerator\n") +
    i18n("# Copyright (c) 2004 Fred Emmott <*****@*****.**>\n") +
    i18n("# See KIptablesGenerator for license information.\n") + 
    i18n("# You probably want to make this a startup script, eg on\n") +
    i18n("# slackware you probably want to save this as /etc/rc.d/rc.firewall\n")+
    "IPTABLES=/usr/sbin/iptables\n";
  if (((QButtonGroup*) namedWidgets["incomingYesNo"])->selected()->name() == (QString) "yes")
  {
    if ( ((KComboBox*) namedWidgets["incomingPolicy"])->currentItem() == 0)
      rulesList += "$IPTABLES -P INPUT ACCEPT\n";
    else
      rulesList += "$IPTABLES -P INPUT DROP\n";
      
    KListBox* interfaces = (KListBox*) namedWidgets["iInterfaces"];
    for (unsigned int i = 0; i < interfaces->count(); i++)
    {
      QListBoxItem* interface = interfaces->item(i);
      if (! interface->isSelected())
          rulesList += QString("$IPTABLES -A INPUT -i %1 -j ACCEPT\n").arg(interface->text());
    }
    
    KListView* hosts = (KListView*) namedWidgets["hostsList"];
    QListViewItem* host = hosts->firstChild();
    while (host)
    {
      QString
        accept = host->text(0),
        ipOrMAC = host->text(1),
        address = host->text(2),
        action;
      accept == i18n("Allow")
        ? action = "ACCEPT"
        : action = "DROP";
      ipOrMAC == i18n("IP")
        ? rulesList += QString("$IPTABLES -A INPUT -s %1 -j %2\n").arg(address).arg(action)
        : rulesList += QString("$IPTABLES -A INPUT -m mac --mac-source %1 -j %2\n").arg(address).arg(action);
      host = host->nextSibling();
    }    
 
    if (((QCheckBox *) namedWidgets["iCheckLocalSpoof"])->isChecked())
      rulesList += "$IPTABLES -A INPUT ! -i lo -d 127.0.0.0/8 -j DROP\n";
    if (((QCheckBox *) namedWidgets["iSynFloodProtect"])->isChecked())
    {
      rulesList += "$IPTABLES -N Flood-Scan\n";
      rulesList += "$IPTABLES -A INPUT -p tcp -m tcp --syn -j Flood-Scan\n";
      rulesList += "$IPTABLES -A Flood-Scan -m limit --limit 1/s --limit-burst 20 -j RETURN\n";
      rulesList += "$IPTABLES -A Flood-Scan -j DROP\n";
    }
    if (((QCheckBox *) namedWidgets["iCheckSyn"])->isChecked())
      rulesList += "$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m conntrack --ctstate NEW -j DROP\n";
    if (((QCheckBox *) namedWidgets["iCheckSynFin"])->isChecked())
      rulesList += "$IPTABLES -A INPUT -p tcp -m tcp --tcp-flags SYN,FIN SYN,FIN -j DROP\n";
         
    if ( ((QCheckBox*) namedWidgets["iConntrackAllSame"])->isChecked() )
    {
      if ( ((QCheckBox*) namedWidgets["iConntrackAllEstablished"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackAllRelated"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -m conntrack --ctstate RELATED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackAllNew"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -m conntrack --ctstate NEW -j ACCEPT\n";
    }
    else
    {
      if ( ((QCheckBox*) namedWidgets["iConntrackTcpEstablished"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p tcp -m conntrack --ctstate ESTABLISHED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackTcpRelated"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p tcp -m conntrack --ctstate RELATED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackTcpNew"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p tcp -m conntrack --ctstate NEW -j ACCEPT\n";
        
      if ( ((QCheckBox*) namedWidgets["iConntrackUdpEstablished"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p udp -m conntrack --ctstate ESTABLISHED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackUdpRelated"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p udp -m conntrack --ctstate RELATED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackUdpNew"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p udp -m conntrack --ctstate NEW -j ACCEPT\n";
      
      if ( ((QCheckBox*) namedWidgets["iConntrackICMPEstablished"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p icmp -m conntrack --ctstate ESTABLISHED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackICMPRelated"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p icmp -m conntrack --ctstate RELATED -j ACCEPT\n";
      if ( ((QCheckBox*) namedWidgets["iConntrackICMPNew"])->isChecked() )
        rulesList += "$IPTABLES -A INPUT -p icmp -m conntrack --ctstate NEW -j ACCEPT\n";
    }

    KListView* services = (KListView*) namedWidgets["iPorts"];
    QListViewItem* service = services->firstChild();
    while (service)
    {
      // columns: portNumber, protoName, action, portName
      QString
        portNumber = service->text(0),
        protocol = service->text(1),
        action = service->text(2),
        portName = service->text(3);
        
      action == i18n("Accept") ? action = "ACCEPT" : action = "DROP";
      if (protocol == i18n("TCP & UDP") || protocol == i18n("TCP"))
        rulesList += QString("$IPTABLES -A INPUT -p tcp -m tcp --dport %1 -j %2\n").arg(portNumber).arg(action);
      if (protocol == i18n("TCP & UDP") || protocol == i18n("UDP"))
        rulesList += QString("$IPTABLES -A INPUT -p udp -m udp --dport %1 -j %2\n").arg(portNumber).arg(action);
      if (protocol == i18n("ICMP"))
        rulesList += QString("$IPTABLES -A INPUT -p icmp -m icmp --icmp-type %1 -j %2\n").arg(portName).arg(action);
       service = service->nextSibling();
    }

    KListView* forwards = (KListView*) namedWidgets["forwardsList"];
    QListViewItem* forward = forwards->firstChild();
    while (forward)
    {
      QString
        direction = forward->text(0),
        localPort = forward->text(1),
        destination = forward->text(2);
      direction == i18n("Incoming")
        ? rulesList += QString("$IPTABLES -t nat -A PREROUTING -p tcp -m tcp --dport %1 -j DNAT --to %2\n").arg(localPort).arg(destination)
        : rulesList += QString("$IPTABLES -t nat -A OUTPUT -p tcp -m tcp --dport %1 -j DNAT --to %2\n").arg(localPort).arg(destination);
      forward = forward->nextSibling();
    }
  }
 
  this->hide();
  rulesDialog = new RulesDialog(this,(char*) 0, &rulesList);
  rulesDialog->show();
  connect(rulesDialog, SIGNAL(closeClicked()), this, SLOT(slotShownRules()));
}