Exemplo n.º 1
0
bool
StdWidgetFactory::readSpecialProperty(const QCString &classname, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *)
{
	QString tag = node.tagName();
	QString name = node.attribute("name");

	if((tag == "item") && (classname == "KComboBox"))
	{
		KComboBox *combo = (KComboBox*)w;
		QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
		if(val.canCast(QVariant::Pixmap))
			combo->insertItem(val.toPixmap());
		else
			combo->insertItem(val.toString());
		return true;
	}

	if((tag == "item") && (classname == "KListBox"))
	{
		KListBox *listbox = (KListBox*)w;
		QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
		if(val.canCast(QVariant::Pixmap))
			listbox->insertItem(val.toPixmap());
		else
			listbox->insertItem(val.toString());
		return true;
	}

	if((tag == "column") && (classname == "KListView"))
	{
		KListView *listview = (KListView*)w;
		int id=0;
		for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
		{
			QString prop = n.toElement().attribute("name");
			QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name);
			if(prop == "text")
				id = listview->addColumn(val.toString());
			else if(prop == "width")
				listview->setColumnWidth(id, val.toInt());
			else if(prop == "resizable")
				listview->header()->setResizeEnabled(val.toBool(), id);
			else if(prop == "clickable")
				listview->header()->setClickEnabled(val.toBool(), id);
			else if(prop == "fullwidth")
				listview->header()->setStretchEnabled(val.toBool(), id);
		}
		return true;
	}
	else if((tag == "item") && (classname == "KListView"))
	{
		KListView *listview = (KListView*)w;
		readListItem(node, 0, listview);
		return true;
	}

	return false;
}
Exemplo n.º 2
0
bool
StdWidgetFactory::saveSpecialProperty(const QCString &classname, const QString &name, const QVariant &, QWidget *w, QDomElement &parentNode, QDomDocument &domDoc)
{
	if(name == "list_items" && classname == "KComboBox")
	{
		KComboBox *combo = (KComboBox*)w;
		for(int i=0; i < combo->count(); i++)
		{
			QDomElement item = domDoc.createElement("item");
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i));
			parentNode.appendChild(item);
		}
		return true;
	}
	else if(name == "list_items" && classname == "KListBox")
	{
		KListBox *listbox = (KListBox*)w;
		for(uint i=0; i < listbox->count(); i++)
		{
			QDomElement item = domDoc.createElement("item");
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i));
			parentNode.appendChild(item);
		}
		return true;
	}
	else if(name == "list_contents" && classname == "KListView")
	{
		KListView *listview = (KListView*)w;
		// First we save the columns
		for(int i = 0; i < listview->columns(); i++)
		{
			QDomElement item = domDoc.createElement("column");
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i));
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i));
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i));
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i));
			KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i));
			parentNode.appendChild(item);
		}

		// Then we save the list view items
		QListViewItem *item = listview->firstChild();
		while(item)
		{
			saveListItem(item, parentNode, domDoc);
			item = item->nextSibling();
		}
		return true;
	}

	return false;
}
void kiptablesgenerator::slotNewInterface()
{
  QString interface;
  KListBox *interfaces = (KListBox*) namedWidgets["interfaces"];
  
  interface = KInputDialog::getText(i18n("Add Interface"),
    i18n("Enter the name of the interface, eg eth1"));
  if (interface == "")
    return;
  
  interfaces->insertItem(interface);
  interfaces->setSelected(interfaces->count() - 1, true);
}
Exemplo n.º 4
0
void KMConfigFilter::loadConfig(KConfig *conf)
{
    conf->setGroup("Filter");
    QStringList m_plist = conf->readListEntry("Printers");
    QPtrListIterator< KMPrinter > it(*(KMManager::self()->printerListComplete(false)));
    for(; it.current(); ++it)
    {
        if(!it.current()->isSpecial() && !it.current()->isVirtual())
        {
            KListBox *lb = (m_plist.find(it.current()->printerName()) == m_plist.end() ? m_list1 : m_list2);
            lb->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName());
        }
    }
    m_list1->sort();
    m_list2->sort();
    m_locationre->setText(conf->readEntry("LocationRe"));
}
void kiptablesgenerator::setupInterfacesPage()
{
  interfacesPage = new QFrame(this);
  
  QVBoxLayout *layout = new QVBoxLayout(interfacesPage);
  
  QLabel *intro = new QLabel(i18n(
    "<p>Which of the following interfaces do you want to filter?</p>"
    "<p>It is strongly advised <b>not</b> to filter '<tt>lo</tt>'.</p>"), interfacesPage);
  intro->show();
  layout->addWidget(intro);
  
  KListBox *interfaces = new KListBox(interfacesPage);

  char buffer[IFNAMSIZ];
  for(unsigned int i = 1; if_indextoname(i, buffer) != NULL; i++)
  {
          interfaces->insertItem((QString)buffer);
  }
  
  interfaces->setSelectionMode(QListBox::Multi);
  for (unsigned short i = 0; i < interfaces->count(); i++)
    if (interfaces->item(i)->text() != "lo")
      interfaces->setSelected(i, true);
  interfaces->show();
  layout->addWidget(interfaces);
  namedWidgets["iInterfaces"] = interfaces;
  
  KPushButton *newInterface = new KPushButton(i18n("A&dd Interface..."), interfacesPage);
  newInterface->show();
  layout->addWidget(newInterface);
  connect(newInterface, SIGNAL(clicked()), this, SLOT(slotNewInterface()));
  
  interfacesPage->show();
  this->addPage(interfacesPage, i18n("Interfaces"));
}
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()));
}
Exemplo n.º 7
0
bool
StdWidgetFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container)
{
	setWidget(w, container);
//	m_container = container;
	if(classname == "KLineEdit")
	{
		KLineEdit *lineedit = static_cast<KLineEdit*>(w);
		createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true);
		return true;
	}
	else if(classname == "QLabel")
	{
		QLabel *label = static_cast<QLabel*>(w);
		if(label->textFormat() == RichText)
		{
			//m_widget = w;
//			setWidget(w, container);
			editText();
		}
		else
			createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
		return true;
	}
	else if(classname == "KPushButton")
	{
		KPushButton *push = static_cast<KPushButton*>(w);
		QRect r = w->style().subRect(QStyle::SR_PushButtonContents, w);
		QRect editorRect = QRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
		//r.setX(r.x() + 5);
		//r.setY(r.y() + 5);
		//r.setWidth(r.width()-10);
		//r.setHeight(r.height() - 10);
		createEditor(classname, push->text(), push, container, editorRect, Qt::AlignCenter, false, false, Qt::PaletteButton);
		return true;
	}
	else if(classname == "QRadioButton")
	{
		QRadioButton *radio = static_cast<QRadioButton*>(w);
		QRect r = w->style().subRect(QStyle::SR_RadioButtonContents, w);
		QRect editorRect = QRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
		createEditor(classname, radio->text(), radio, container, editorRect, Qt::AlignAuto);
		return true;
	}
	else if(classname == "QCheckBox")
	{
		QCheckBox *check = static_cast<QCheckBox*>(w);
		//QRect r(check->geometry());
		//r.setX(r.x() + 20);
		QRect r = w->style().subRect(QStyle::SR_CheckBoxContents, w);
		QRect editorRect = QRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
		createEditor(classname, check->text(), check, container, editorRect, Qt::AlignAuto);
		return true;
	}
	else if((classname == "KComboBox") || (classname == "KListBox"))
	{
		QStringList list;
		if(classname == "KListBox")
		{
			KListBox *listbox = (KListBox*)w;
			for(uint i=0; i < listbox->count(); i++)
				list.append(listbox->text(i));
		}
		else if(classname == "KComboBox")
		{
			KComboBox *combo = (KComboBox*)w;
			for(int i=0; i < combo->count(); i++)
				list.append(combo->text(i));
		}

		if(editList(w, list))
		{
			if(classname == "KListBox")
			{
				((KListBox*)w)->clear();
				((KListBox*)w)->insertStringList(list);
			}
			else if(classname == "KComboBox")
			{
				((KComboBox*)w)->clear();
				((KComboBox*)w)->insertStringList(list);
			}
		}
		return true;
	}
	else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") ||
		(classname == "KDateWidget") || (classname == "KIntSpinBox")) {
		disableFilter(w, container);
		return true;
	}
	return false;
}