Source Code (Use browser search to find items of interest.)
Class Index
knu'HostDlg (./kdenetwork/knu/HostDlg.h:59)
class HostDlg: public CommandDlg
{
Q_OBJECT
public:
HostDlg(QString commandName,
QWidget* parent = NULL, const char* name = NULL);
virtual ~HostDlg();
protected:
bool buildCommandLine(QString args);
// additional widgets
QLabel *hostLbl1;
QComboBox *hostCb1;
QFrame *hostF1;
QLabel *hostLbl2;
QComboBox *hostCb2;
QFrame *frame1;
// layout
QBoxLayout *layout3;
};
knu'HostDlg::HostDlg() (./kdenetwork/knu/HostDlg.cpp:107)
HostDlg::HostDlg(QString commandName,
QWidget* parent, const char* name)
: CommandDlg(commandName, parent, name)
{
KConfig *kc = kapp->config();
layout1 = new QBoxLayout(commandBinOK, QBoxLayout::TopToBottom, SEPARATION);
CHECK_PTR(layout1);
layout2 = new QBoxLayout(QBoxLayout::LeftToRight, SEPARATION);
CHECK_PTR(layout2);
layout1->addLayout(layout2, 0);
// Frame for options
frame1 = new QFrame(commandBinOK, "frame_1");
CHECK_PTR(frame1);
frame1->setFrameStyle(QFrame::Box | QFrame::Sunken);
frame1->setMinimumSize(0, 2*fontMetrics().height());
layout1->addWidget(frame1, 0);
layout3 = new QBoxLayout(frame1, QBoxLayout::LeftToRight, SEPARATION/2);
CHECK_PTR(layout3);
// Make the layout of CommandDlg
layout2->addWidget(commandLbl1);
layout2->addWidget(commandArgs);
layout2->addSpacing(2*SEPARATION);
layout2->addWidget(commandGoBtn);
layout2->addWidget(commandStopBtn);
// Layout for options
layout3->addStretch(10);
hostCb1 = new QComboBox(frame1, "ComboBox_1");
CHECK_PTR(hostCb1);
// This is the array of what is the search for ComboBox.
// Warning: member buildCommandLine use index=1 for PTR and index=0 for A
hostCb1->insertItem(i18n("address (A)"));
hostCb1->insertItem(i18n("name (PTR)"));
hostCb1->insertItem(i18n("name server (NS)"));
hostCb1->insertItem(i18n("mail exchanger (MX)"));
hostCb1->insertItem(i18n("alias (CNAME)"));
hostCb1->insertItem(i18n("start of authority (SOA)"));
hostCb1->insertItem(i18n("any record (ANY)"));
hostCb1->adjustSize();
hostCb1->setFixedSize(hostCb1->size());
hostLbl1 = new QLabel(hostCb1, i18n("Se&arch for:"), frame1, "Label_1");
CHECK_PTR(hostLbl1);
hostLbl1->adjustSize();
hostLbl1->setFixedSize(hostLbl1->width(), 2*fontMetrics().height());
layout3->addWidget(hostLbl1);
layout3->addWidget(hostCb1);
layout3->addStretch(10);
hostCb2 = new QComboBox(TRUE, frame1, "ComboBox_2");
CHECK_PTR(hostCb2);
hostCb2->insertItem(i18n("default server"));
hostCb2->insertItem("888.888.888.888");
hostCb2->adjustSize();
hostCb2->setFixedSize(hostCb2->size());
hostCb2->removeItem(1);
// we should read the /etc/resolv.conf file and add the nameservers entries
// in next version maybe?
// For now, we are reading the server list from the config file.
kc->setGroup(configGroupName);
if (kc->hasKey("Servers")) {
QStringList server_list = kc->readListEntry("Servers", ';');
// I don't use ->insertStringList() because I want to be able to remove spaces in
// the strings
for (QStringList::Iterator it = server_list.begin();
it != server_list.end(); ++it) {
hostCb2->insertItem((*it).stripWhiteSpace());
}
}
hostCb2->setInsertionPolicy(QComboBox::AtTop);
hostLbl2 = new QLabel(hostCb2, i18n("Ser&ver:"), frame1, "Label_2");
CHECK_PTR(hostLbl2);
hostLbl2->adjustSize();
hostLbl2->setFixedSize(hostLbl2->size());
//hostLbl2->resize(hostLbl2->width(), cbh);
layout3->addWidget(hostLbl2);
layout3->addWidget(hostCb2);
layout3->addStretch(10);
layout3->activate();
frame1->adjustSize();
frame1->setMinimumSize(frame1->size());
layout1->addWidget(commandTextArea, 10);
layout1->activate();
#if 0
kc->setGroup(configGroupName);
if (firstTimeLauching) {
debug("=> firstTimeLauching <=");
kc->writeEntry("binaryType", "host");
if (!commandFound) {
if (::test_for_exec("nslookup")) {
kc->writeEntry("path", "nslookup");
kc->writeEntry("binaryType", "nslookup");
}
}
}
#endif
/*
* Look at the command binary to see which widget to display
*/
kc->setGroup(configGroupName);
if (!kc->hasKey("path")) {
// It's the first execution,
// so we have to search for the pathname
kc->writeEntry("path", commandName);
checkBinaryAndDisplayWidget();
if (commandFound) {
// All is OK : we can enable this tab.
if (!kc->hasKey("enable")) {
kc->writeEntry("enable", 1);
}
} else {
if (::test_for_exec("nslookup")) {
kc->writeEntry("path", "nslookup");
kc->writeEntry("binaryType", "nslookup");
checkBinaryAndDisplayWidget();
}
}
} else {
checkBinaryAndDisplayWidget();
}
// Commit changes in configfile (if needed)
kc->sync();
}
/**
* Destructor
*/
knu'HostDlg::~HostDlg() (./kdenetwork/knu/HostDlg.cpp:255)
HostDlg::~HostDlg()
{
}
/**
* build the command line from widgets
*/
bool
knu'HostDlg::buildCommandLine() (./kdenetwork/knu/HostDlg.cpp:264)
HostDlg::buildCommandLine(QString args)
{
QString s, queryType;
QRegExp *regexp;
int len, start;
QString bin;
KConfig *kc = kapp->config();
kc->setGroup(configGroupName);
bin = kc->readEntry("path");
if (bin.isEmpty()) {
return FALSE;
} else {
bool nslookupBinary = FALSE;
if (!stricmp(kc->readEntry("binaryType"), "nslookup")) {
nslookupBinary = TRUE;
}
childProcess.clearArguments();
childProcess.setExecutable(bin);
// Add arguments
s = (kc->readEntry("arguments")).simplifyWhiteSpace();
if (!s.isEmpty()) {
while (s.contains(' ', FALSE) != 0) {
int pos = s.find(' ', 0, FALSE);
childProcess << s.left(pos);
s = s.remove(0, pos+1);
}
childProcess << s;
}
// search for: combobox
s = ((QString)(hostCb1->currentText())).stripWhiteSpace();;
// - extract the query type from the string
regexp = new QRegExp("([A-Za-z]+)");
CHECK_PTR(regexp);
start = regexp->match(s, 0, &len);
ASSERT(start>0);
queryType = s.mid(start+1, len-2); // to remove ()
//debug ("queryType=%s", (const char *)queryType);
delete regexp;
if (!strcmp(queryType, "A")) {
// - if q=A and the args is an IP address, then q=PTR
if (args.contains(QRegExp("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$")) > 0) {
//debug("This is an IP address");
queryType = "PTR";
hostCb1->setCurrentItem(1);
}
} else if (!strcmp(queryType, "PTR")) {
// - if q=PTR and the args is an name, then q=A
if (args.contains(QRegExp("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$")) > 0) {
} else {
//debug("This is _not_ an IP address");
queryType = "A";
hostCb1->setCurrentItem(0);
}
}
if (nslookupBinary) {
childProcess << "-query=" + queryType;
} else {
childProcess << "-t" << queryType;
}
childProcess << args;
// server: combobox
if (strcmp(i18n("default server"), hostCb2->currentText())) {
// it's not the default server
childProcess << hostCb2->currentText();
}
return TRUE;
}
}
/* ******************************************************************** */
/**
* make a new config object
*
* @param parent parent widget
* @param name name of the widget
*/