mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-22 11:17:31 +01:00
Various places in the code had logic for what directory to display in
QFileDialog. There is now a single function to call, FWBSettings::getOpenFileDir() that will compute what directory to start in. Cleaned out some code using QFileDialog that is never used (execDialog and file button in CommentEditor). Fixes #2517
This commit is contained in:
parent
69364a4ee9
commit
872fd64cb6
@ -8,6 +8,13 @@
|
||||
|
||||
* Fixed #2528, display icon next to "new subfolder" menu item.
|
||||
|
||||
* Added feature #2517: directory location caching. Use
|
||||
FWBSettings::{get|set}OpenFileDir() any time we use QFileDialog so
|
||||
that the directory you navigated to last time shows up in the next
|
||||
file dialog. This behavior is overridden by setting a working
|
||||
directory. If the directory no longer exists, gracefully fall
|
||||
back to something sensible.
|
||||
|
||||
2011-06-23 theron <theron@netcitadel.com>
|
||||
|
||||
* Added support for creating user-defined subfolders. The
|
||||
|
||||
@ -150,37 +150,25 @@ void AddressTableDialog::applyChanges()
|
||||
|
||||
void AddressTableDialog::browse()
|
||||
{
|
||||
|
||||
QString dir;
|
||||
dir = st->getWDir();
|
||||
if (dir.isEmpty()) dir = st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir = "~";
|
||||
|
||||
// build a dialog that will let user select existing file or enter
|
||||
// a name even if the file does not exist
|
||||
|
||||
QFileDialog fd(this);
|
||||
fd.setWindowTitle(tr("Choose a file or type the name to create new"));
|
||||
fd.setDirectory(dir);
|
||||
fd.setFileMode(QFileDialog::AnyFile);
|
||||
fd.setNameFilter(tr("All files (*)"));
|
||||
fd.setViewMode(QFileDialog::Detail);
|
||||
QString s = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Choose a file or type the name to create new"),
|
||||
st->getOpenFileDir(mw->getCurrentFileName()),
|
||||
tr("All files (*)"));
|
||||
|
||||
if (fd.exec())
|
||||
{
|
||||
QString s = fd.selectedFiles()[0];
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
m_dialog->filename->setText(s);
|
||||
// assign focus to the "file name" input field so that it
|
||||
// generates signal editFinished when user clicks
|
||||
// elsewhere. We use this signal to call changed() which in
|
||||
// turn calls applyChanges() to save data
|
||||
m_dialog->filename->setFocus(Qt::OtherFocusReason);
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
m_dialog->filename->setText(s);
|
||||
// assign focus to the "file name" input field so that it
|
||||
// generates signal editFinished when user clicks
|
||||
// elsewhere. We use this signal to call changed() which in
|
||||
// turn calls applyChanges() to save data
|
||||
m_dialog->filename->setFocus(Qt::OtherFocusReason);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void AddressTableDialog::editFile( void )
|
||||
|
||||
@ -56,16 +56,9 @@ CommentEditorPanel::CommentEditorPanel(QWidget *p) : BaseObjectDialog(p)
|
||||
{
|
||||
m_widget = new Ui::CommentEditorPanel_q;
|
||||
m_widget->setupUi(this);
|
||||
m_widget->inputFromFileButton->hide();
|
||||
rule=NULL;
|
||||
}
|
||||
|
||||
void CommentEditorPanel::setFileInput(bool enableLoadFromFile)
|
||||
{
|
||||
if (enableLoadFromFile) m_widget->inputFromFileButton->show();
|
||||
else m_widget->inputFromFileButton->hide();
|
||||
}
|
||||
|
||||
QString CommentEditorPanel::text()
|
||||
{
|
||||
return m_widget->editor->toPlainText();
|
||||
@ -76,36 +69,6 @@ void CommentEditorPanel::setText(QString s)
|
||||
m_widget->editor->setText(s);
|
||||
}
|
||||
|
||||
void CommentEditorPanel::loadFromFile()
|
||||
{
|
||||
if ( QMessageBox::warning(
|
||||
this,"Firewall Builder",
|
||||
tr("Warning: loading from file discards current contents of the script."),
|
||||
"&Load", "&Cancel", QString::null, 0, 1 )==0)
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this, tr("Choose file that contains PIX commands"), st->getWDir());
|
||||
if (filename!="")
|
||||
{
|
||||
ifstream ifile(filename.toLatin1().constData());
|
||||
if (!ifile)
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,"Firewall Builder",
|
||||
tr("Could not open file %1").arg(filename),
|
||||
"&Continue", QString::null, QString::null, 0, 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
while (ifile.getline(buf,1024))
|
||||
{
|
||||
m_widget->editor->append( buf );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CommentEditorPanel::changed()
|
||||
{
|
||||
emit changed_sign();
|
||||
|
||||
@ -47,15 +47,10 @@ class CommentEditorPanel : public BaseObjectDialog
|
||||
~CommentEditorPanel();
|
||||
libfwbuilder::Rule *rule;
|
||||
|
||||
void setFileInput(bool enableLoadFromFile);
|
||||
|
||||
QString text();
|
||||
void setText(QString s);
|
||||
|
||||
public slots:
|
||||
virtual void loadFromFile();
|
||||
|
||||
|
||||
virtual void changed();
|
||||
virtual void applyChanges();
|
||||
virtual void loadFWObject(libfwbuilder::FWObject *obj);
|
||||
|
||||
@ -683,42 +683,31 @@ void DiscoveryDruid::startBackgroundProcess()
|
||||
|
||||
void DiscoveryDruid::browseHostsFile()
|
||||
{
|
||||
QString dir;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
QString s = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
st->getOpenFileDir(),
|
||||
"All files (*)");
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
m_dialog->filename->setText(s);
|
||||
}
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
m_dialog->filename->setText(s);
|
||||
|
||||
}
|
||||
|
||||
void DiscoveryDruid::browseForImport()
|
||||
{
|
||||
QString dir;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
QString s = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
st->getOpenFileDir(),
|
||||
"All files (*)");
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
m_dialog->import_filename->setText(s);
|
||||
}
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
m_dialog->import_filename->setText(s);
|
||||
}
|
||||
|
||||
void DiscoveryDruid::updatePrg()
|
||||
@ -1495,41 +1484,34 @@ void DiscoveryDruid::loadDataFromImporter()
|
||||
|
||||
void DiscoveryDruid::saveScanLog()
|
||||
{
|
||||
QString dir;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
st->getOpenFileDir(),
|
||||
"Text file (*.txt)");
|
||||
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
if (!s.isEmpty())
|
||||
if (s.endsWith(".txt")) s += ".txt";
|
||||
|
||||
QFile f(s);
|
||||
if (f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
if (s.endsWith(".txt"))
|
||||
if (fwbdebug)
|
||||
{
|
||||
s+=".txt";
|
||||
}
|
||||
QFile f(s);
|
||||
if (f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("Saving crawler log to file: %d chars",
|
||||
m_dialog->discoverylog->toPlainText().length());
|
||||
qDebug("--------------------------------");
|
||||
}
|
||||
QTextStream strm(&f);
|
||||
QString txt = m_dialog->discoverylog->toPlainText();
|
||||
strm << txt << endl;
|
||||
if (fwbdebug) qDebug("%s",txt.toAscii().constData());
|
||||
if (fwbdebug)
|
||||
qDebug("--------------------------------");
|
||||
f.close();
|
||||
qDebug("Saving crawler log to file: %d chars",
|
||||
m_dialog->discoverylog->toPlainText().length());
|
||||
qDebug("--------------------------------");
|
||||
}
|
||||
|
||||
QTextStream strm(&f);
|
||||
QString txt = m_dialog->discoverylog->toPlainText();
|
||||
strm << txt << endl;
|
||||
if (fwbdebug) qDebug("%s",txt.toAscii().constData());
|
||||
if (fwbdebug)
|
||||
qDebug("--------------------------------");
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,7 +70,6 @@ const char* ResSetpath = SETTINGS_PATH_PREFIX "/System/ResPath";
|
||||
const char* compression = SETTINGS_PATH_PREFIX "/DataFile/compression";
|
||||
const char* wdirSetpath = SETTINGS_PATH_PREFIX "/Environment/WDir";
|
||||
const char* ofdirSetpath = SETTINGS_PATH_PREFIX "/Environment/OpenFileDir";
|
||||
const char* sfdirSetpath = SETTINGS_PATH_PREFIX "/Environment/SaveFileDir";
|
||||
const char* startupActionSetpath =
|
||||
SETTINGS_PATH_PREFIX "/Environment/StartupAction";
|
||||
const char* labelColorPath = SETTINGS_PATH_PREFIX "/ColorLabels/color_";
|
||||
@ -506,24 +505,32 @@ void FWBSettings::setTooltipDelay(int v) { setValue( tooltipDelay, v); }
|
||||
QString FWBSettings::getLastEdited() { return value(lastEditedSetpath).toString();}
|
||||
void FWBSettings::setLastEdited(const QString &file) { setValue(lastEditedSetpath,file);}
|
||||
|
||||
QString FWBSettings::getOpenFileDir()
|
||||
QString FWBSettings::getOpenFileDir(const QString &existingPath)
|
||||
{
|
||||
return value(ofdirSetpath).toString();
|
||||
QString ret = getWDir();
|
||||
if (!ret.isEmpty() && QFileInfo(ret).isDir()) return ret;
|
||||
|
||||
ret = value(ofdirSetpath).toString();
|
||||
if (!ret.isEmpty() && QFileInfo(ret).isDir()) return ret;
|
||||
|
||||
if (!existingPath.isEmpty()) {
|
||||
ret = getFileDir(existingPath);
|
||||
if (QFileInfo(ret).isDir()) return ret;
|
||||
}
|
||||
|
||||
return userDataDir.c_str();
|
||||
}
|
||||
|
||||
void FWBSettings::setOpenFileDir( const QString &d )
|
||||
void FWBSettings::setOpenFileDir(const QString &d)
|
||||
{
|
||||
setValue(ofdirSetpath,d);
|
||||
}
|
||||
QString dirPath = d;
|
||||
|
||||
QString FWBSettings::getSaveFileDir()
|
||||
{
|
||||
return value(sfdirSetpath).toString();
|
||||
}
|
||||
QFileInfo info(d);
|
||||
if (!info.isDir()) {
|
||||
dirPath = info.dir().path();
|
||||
}
|
||||
|
||||
void FWBSettings::setSaveFileDir( const QString &d )
|
||||
{
|
||||
setValue(sfdirSetpath,d);
|
||||
setValue(ofdirSetpath, dirPath);
|
||||
}
|
||||
|
||||
void FWBSettings::save()
|
||||
|
||||
@ -83,12 +83,9 @@ class FWBSettings : public QSettings
|
||||
QString getWDir();
|
||||
void setWDir( const QString &wd );
|
||||
|
||||
QString getOpenFileDir();
|
||||
QString getOpenFileDir( const QString &existingPath = "");
|
||||
void setOpenFileDir( const QString &d );
|
||||
|
||||
QString getSaveFileDir();
|
||||
void setSaveFileDir( const QString &d );
|
||||
|
||||
int getInfoStyle();
|
||||
void setInfoStyle(int s);
|
||||
|
||||
|
||||
@ -677,39 +677,20 @@ void FWWindow::fileOpen()
|
||||
QString dir;
|
||||
QMdiSubWindow *last_active_window = m_mainWindow->m_space->activeSubWindow();
|
||||
|
||||
/*
|
||||
* Pick default directory where to look for the file to open.
|
||||
* 1) if "work directory" is configured in preferences, always use it
|
||||
* 2) if it is blank, use the same directory where currently opened file is
|
||||
* 3) if this is the first file to be opened, get directory where the user opened
|
||||
* during last session from settings using st->getOpenFileDir
|
||||
*/
|
||||
|
||||
dir = st->getWDir();
|
||||
if (fwbdebug) qDebug("Choosing directory for file open 1: %s",
|
||||
dir.toStdString().c_str());
|
||||
|
||||
if (dir.isEmpty() && !mw->getCurrentFileName().isEmpty())
|
||||
dir = getFileDir(mw->getCurrentFileName());
|
||||
if (fwbdebug) qDebug("Choosing directory for file open 2: %s",
|
||||
dir.toStdString().c_str());
|
||||
|
||||
if (dir.isEmpty()) dir = st->getOpenFileDir();
|
||||
if (fwbdebug) qDebug("Choosing directory for file open 3: %s",
|
||||
dir.toStdString().c_str());
|
||||
|
||||
QString file_name = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Open File"),
|
||||
dir,
|
||||
st->getOpenFileDir(mw->getCurrentFileName()),
|
||||
"FWB files (*.fwb *.fwl *.xml);;All Files (*)");
|
||||
|
||||
if (file_name.isEmpty())
|
||||
{
|
||||
m_mainWindow->m_space->setActiveSubWindow(last_active_window);
|
||||
return ;
|
||||
return;
|
||||
}
|
||||
|
||||
st->setOpenFileDir(file_name);
|
||||
|
||||
// Using absoluteFilePath(), see #1334
|
||||
QFileInfo fi(file_name);
|
||||
QString file_path = fi.absoluteFilePath();
|
||||
|
||||
@ -115,161 +115,142 @@ void FilterDialog::apply()
|
||||
|
||||
void FilterDialog::save()
|
||||
{
|
||||
QString dir;
|
||||
if (LastFile.isEmpty())
|
||||
{
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
}
|
||||
else
|
||||
{
|
||||
dir=LastFile;
|
||||
}
|
||||
QString dir = LastFile;
|
||||
if (dir.isEmpty()) dir = st->getOpenFileDir();
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Save file dialog",
|
||||
dir,
|
||||
"FWBuilder filter files (*.fwf)");
|
||||
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
if (!s.isEmpty())
|
||||
if (!s.endsWith(".fwf")) s += ".fwf";
|
||||
|
||||
xmlDocPtr doc;
|
||||
|
||||
xmlNodePtr node;
|
||||
//xmlNodePtr tree;
|
||||
|
||||
doc = xmlNewDoc(TOXMLCAST("1.0"));
|
||||
doc->children = xmlNewDocNode(doc, NULL, TOXMLCAST("FWB_FILTER"), NULL);
|
||||
|
||||
xmlSetProp(doc->children, TOXMLCAST("version"),
|
||||
TOXMLCAST( VERSION ));
|
||||
xmlSetProp(doc->children, TOXMLCAST("CaseSensitive"),
|
||||
TOXMLCAST( ((m_dialog->case_sensitive->isChecked())?"1":"0") ));
|
||||
xmlSetProp(doc->children, TOXMLCAST("Match"),
|
||||
TOXMLCAST( QString("%1").arg(m_dialog->combo->currentIndex()).toLatin1().constData() ));
|
||||
|
||||
QString buf;
|
||||
int n=m_dialog->table->rowCount();
|
||||
for (int i=0;i<n;i++)
|
||||
{
|
||||
if (!s.endsWith(".fwf"))
|
||||
{
|
||||
s+=".fwf";
|
||||
}
|
||||
node = xmlNewChild(doc->children, NULL,
|
||||
TOXMLCAST("FWB_FILTER_ITEM"), NULL);
|
||||
|
||||
xmlDocPtr doc;
|
||||
buf=QString("%1").arg(((QComboBox*)m_dialog->table->cellWidget(i,0))->currentIndex());
|
||||
xmlSetProp(node,(const xmlChar*) "Target",
|
||||
TOXMLCAST(buf.toLatin1().constData()) );
|
||||
|
||||
xmlNodePtr node;
|
||||
//xmlNodePtr tree;
|
||||
|
||||
doc = xmlNewDoc(TOXMLCAST("1.0"));
|
||||
doc->children = xmlNewDocNode(doc, NULL, TOXMLCAST("FWB_FILTER"), NULL);
|
||||
|
||||
xmlSetProp(doc->children, TOXMLCAST("version"),
|
||||
TOXMLCAST( VERSION ));
|
||||
xmlSetProp(doc->children, TOXMLCAST("CaseSensitive"),
|
||||
TOXMLCAST( ((m_dialog->case_sensitive->isChecked())?"1":"0") ));
|
||||
xmlSetProp(doc->children, TOXMLCAST("Match"),
|
||||
TOXMLCAST( QString("%1").arg(m_dialog->combo->currentIndex()).toLatin1().constData() ));
|
||||
|
||||
QString buf;
|
||||
int n=m_dialog->table->rowCount();
|
||||
for (int i=0;i<n;i++)
|
||||
{
|
||||
node = xmlNewChild(doc->children , NULL , TOXMLCAST("FWB_FILTER_ITEM"), NULL);
|
||||
|
||||
buf=QString("%1").arg(((QComboBox*)m_dialog->table->cellWidget(i,0))->currentIndex());
|
||||
xmlSetProp(node,(const xmlChar*) "Target",
|
||||
TOXMLCAST(buf.toLatin1().constData()) );
|
||||
|
||||
buf=QString("%1").arg(((QComboBox*)m_dialog->table->cellWidget(i,1))->currentIndex());
|
||||
xmlSetProp(node, (const xmlChar*) "Type",
|
||||
TOXMLCAST(buf.toLatin1().constData()) );
|
||||
|
||||
xmlSetProp(node, (const xmlChar*) "Pattern",
|
||||
TOXMLCAST(m_dialog->table->item(i,2)->text().toLatin1().constData()));
|
||||
}
|
||||
|
||||
|
||||
xmlSaveFile(s.toLatin1().constData(),doc);
|
||||
xmlFreeDoc(doc);
|
||||
buf=QString("%1").arg(((QComboBox*)m_dialog->table->cellWidget(i,1))->currentIndex());
|
||||
xmlSetProp(node, (const xmlChar*) "Type",
|
||||
TOXMLCAST(buf.toLatin1().constData()) );
|
||||
|
||||
xmlSetProp(node, (const xmlChar*) "Pattern",
|
||||
TOXMLCAST(m_dialog->table->item(i,2)->text().toLatin1().constData()));
|
||||
}
|
||||
|
||||
xmlSaveFile(s.toLatin1().constData(),doc);
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
void FilterDialog::load()
|
||||
{
|
||||
QString dir;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
QString s = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
"Open file dialog",
|
||||
dir,
|
||||
st->getOpenFileDir(),
|
||||
"FWBuilder filter files (*.fwf)");
|
||||
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
if (!s.isEmpty())
|
||||
xmlDocPtr doc=xmlParseFile(s.toLatin1().constData());
|
||||
//TODO: use local codepage
|
||||
if (doc == NULL)
|
||||
{
|
||||
|
||||
xmlDocPtr doc=xmlParseFile(s.toLatin1().constData());
|
||||
//TODO: use local codepage
|
||||
if (doc == NULL)
|
||||
{
|
||||
qDebug("Document not parsed successfully.");
|
||||
return;
|
||||
}
|
||||
|
||||
xmlNodePtr node= xmlDocGetRootElement(doc);
|
||||
|
||||
if (node == NULL)
|
||||
{
|
||||
qDebug("empty document");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (xmlStrcmp(node->name,(const xmlChar*) "FWB_FILTER"))
|
||||
{
|
||||
qDebug("document of the wrong type. (FWB_FILTER)");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
xmlChar *xmlbuf;
|
||||
QString qbuf;
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "CaseSensitive");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->case_sensitive->setChecked(qbuf.toInt());
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Match");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->combo->setCurrentIndex(qbuf.toInt());
|
||||
|
||||
|
||||
node=node->xmlChildrenNode;
|
||||
while (node != NULL)
|
||||
{
|
||||
if (xmlStrcmp(node->name,(const xmlChar*) "FWB_FILTER_ITEM"))
|
||||
{
|
||||
qDebug("document of the wrong type. (FWB_FILTER_ITEM)");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
addPattern();
|
||||
int n=m_dialog->table->rowCount()-1;
|
||||
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Target");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
((QComboBox*)m_dialog->table->cellWidget(n,0))->setCurrentIndex(
|
||||
qbuf.toInt());
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Type");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
((QComboBox*)m_dialog->table->cellWidget(n,1))->setCurrentIndex(
|
||||
qbuf.toInt());
|
||||
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Pattern");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->table->item(n,2)->setText(qbuf);
|
||||
|
||||
node=node->next;
|
||||
}
|
||||
LastFile=s;
|
||||
qDebug("Document not parsed successfully.");
|
||||
return;
|
||||
}
|
||||
|
||||
xmlNodePtr node= xmlDocGetRootElement(doc);
|
||||
|
||||
if (node == NULL)
|
||||
{
|
||||
qDebug("empty document");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
if (xmlStrcmp(node->name,(const xmlChar*) "FWB_FILTER"))
|
||||
{
|
||||
qDebug("document of the wrong type. (FWB_FILTER)");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
xmlChar *xmlbuf;
|
||||
QString qbuf;
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "CaseSensitive");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->case_sensitive->setChecked(qbuf.toInt());
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Match");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->combo->setCurrentIndex(qbuf.toInt());
|
||||
|
||||
|
||||
node=node->xmlChildrenNode;
|
||||
while (node != NULL)
|
||||
{
|
||||
if (xmlStrcmp(node->name,(const xmlChar*) "FWB_FILTER_ITEM"))
|
||||
{
|
||||
qDebug("document of the wrong type. (FWB_FILTER_ITEM)");
|
||||
xmlFreeDoc(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
addPattern();
|
||||
int n=m_dialog->table->rowCount()-1;
|
||||
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Target");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
((QComboBox*)m_dialog->table->cellWidget(n,0))->setCurrentIndex(
|
||||
qbuf.toInt());
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Type");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
((QComboBox*)m_dialog->table->cellWidget(n,1))->setCurrentIndex(
|
||||
qbuf.toInt());
|
||||
|
||||
|
||||
xmlbuf=xmlGetProp(node,(const xmlChar*) "Pattern");
|
||||
qbuf=FROMXMLCAST(xmlbuf);
|
||||
FREEXMLBUFF(xmlbuf);
|
||||
m_dialog->table->item(n,2)->setText(qbuf);
|
||||
|
||||
node=node->next;
|
||||
}
|
||||
LastFile=s;
|
||||
}
|
||||
|
||||
void FilterDialog::update()
|
||||
|
||||
@ -398,19 +398,23 @@ void PrefsDialog::findWDir()
|
||||
void PrefsDialog::findSSH()
|
||||
{
|
||||
QString fp = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Find Secure Shell utility") );
|
||||
this, tr("Find Secure Shell utility"), st->getOpenFileDir());
|
||||
|
||||
if (!fp.isEmpty()) m_dialog->sshPath->setText(fp);
|
||||
if (fp.isEmpty()) return;
|
||||
st->setOpenFileDir(fp);
|
||||
|
||||
m_dialog->sshPath->setText(fp);
|
||||
}
|
||||
|
||||
void PrefsDialog::findSCP()
|
||||
{
|
||||
QString fp = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
tr("Find SCP utility") );
|
||||
this, tr("Find SCP utility"), st->getOpenFileDir());
|
||||
|
||||
if (!fp.isEmpty()) m_dialog->scpPath->setText(fp);
|
||||
if (fp.isEmpty()) return;
|
||||
st->setOpenFileDir(fp);
|
||||
|
||||
m_dialog->scpPath->setText(fp);
|
||||
}
|
||||
|
||||
void PrefsDialog::accept()
|
||||
|
||||
@ -464,31 +464,6 @@ void ProjectPanel::editPaste()
|
||||
}
|
||||
}
|
||||
|
||||
QString ProjectPanel::getDestDir(const QString &fname)
|
||||
{
|
||||
QString destdir = "";
|
||||
|
||||
if (st->getWDir().isEmpty())
|
||||
{
|
||||
if (fname.isEmpty())
|
||||
{
|
||||
destdir = userDataDir.c_str();
|
||||
} else
|
||||
{
|
||||
QFileInfo fi(fname);
|
||||
if (fi.isDir()) destdir = fname;
|
||||
else
|
||||
{
|
||||
destdir = fi.canonicalPath();
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
destdir = st->getWDir();
|
||||
}
|
||||
return destdir;
|
||||
}
|
||||
|
||||
void ProjectPanel::setFileName(const QString &fname)
|
||||
{
|
||||
systemFile = false;
|
||||
|
||||
@ -211,17 +211,6 @@ public:
|
||||
|
||||
bool saveIfModified(bool include_discard_button=true);
|
||||
|
||||
// semi-intelligent way to guess most appropriate
|
||||
// destination directory for various file save or file open
|
||||
// operations. If working directory is configured in
|
||||
// preferences, then getDestDir returns that. If it is not
|
||||
// configured and file name is given on the command line,
|
||||
// directory where that file is located is returned. If
|
||||
// parameter filename is empty, then current directory
|
||||
// is returned (however on windows and mac userDataDir is returned)
|
||||
|
||||
QString getDestDir(const QString &filename);
|
||||
|
||||
QString chooseNewFileName(const QString &fname, const QString &title);
|
||||
void setFileName(const QString &fname);
|
||||
void restoreDepends(libfwbuilder::FWObject *obj_old,
|
||||
|
||||
@ -136,8 +136,6 @@ bool ProjectPanel::saveIfModified(bool include_discard_button)
|
||||
QString ProjectPanel::chooseNewFileName(const QString &fname,
|
||||
const QString &title)
|
||||
{
|
||||
QString destdir = getDestDir(fname);
|
||||
|
||||
// when file open dialog is created using static function
|
||||
// QFileDialog::getSaveFileName, its behavior is different on
|
||||
// Linux and Mac (did not check on windows)
|
||||
@ -159,7 +157,7 @@ QString ProjectPanel::chooseNewFileName(const QString &fname,
|
||||
fd.setDefaultSuffix("fwb");
|
||||
fd.setFilter(tr( "FWB Files (*.fwb);;All Files (*)" ) );
|
||||
fd.setWindowTitle(title);
|
||||
fd.setDirectory(destdir);
|
||||
fd.setDirectory(st->getOpenFileDir(fname));
|
||||
fd.setAcceptMode(QFileDialog::AcceptSave);
|
||||
|
||||
QString fn;
|
||||
@ -169,6 +167,7 @@ QString ProjectPanel::chooseNewFileName(const QString &fname,
|
||||
fn = fileNames.front();
|
||||
QFileInfo finfo(fn);
|
||||
if (finfo.suffix().isEmpty()) fn += ".fwb";
|
||||
st->setOpenFileDir(fn);
|
||||
}
|
||||
|
||||
return fn;
|
||||
@ -458,18 +457,20 @@ void ProjectPanel::fileCompare()
|
||||
QString fname1 = QFileDialog::getOpenFileName(
|
||||
mainW,
|
||||
tr("Choose the first file"),
|
||||
st->getWDir(),
|
||||
st->getOpenFileDir(),
|
||||
"FWB files (*.fwb);;FWB Library Files (*.fwl);;All Files (*)");
|
||||
|
||||
if (fname1.isEmpty()) return; // Cancel
|
||||
st->setOpenFileDir(fname1);
|
||||
|
||||
QString fname2 = QFileDialog::getOpenFileName(
|
||||
mainW,
|
||||
tr("Choose the second file"),
|
||||
st->getWDir(),
|
||||
st->getOpenFileDir(),
|
||||
"FWB files (*.fwb);;FWB Library Files (*.fwl);;All Files (*)");
|
||||
|
||||
if (fname2.isEmpty()) return; // Cancel
|
||||
st->setOpenFileDir(fname2);
|
||||
|
||||
MessageBoxUpgradePredicate upgrade_predicate(mainW);
|
||||
|
||||
@ -539,23 +540,18 @@ void ProjectPanel::fileCompare()
|
||||
{
|
||||
// save report to a file
|
||||
|
||||
QString destdir = getDestDir(fname1);
|
||||
|
||||
QString fn = QFileDialog::getSaveFileName( this,
|
||||
tr("Choose name and location for the report file"),
|
||||
destdir,
|
||||
st->getOpenFileDir(fname1),
|
||||
tr( "TXT Files (*.txt);;All Files (*)" ));
|
||||
|
||||
if (fn.isEmpty()) return; // Cancel
|
||||
st->setOpenFileDir(fn);
|
||||
|
||||
if (!fn.endsWith(".txt")) fn += ".txt";
|
||||
if (fwbdebug)
|
||||
qDebug() << QString("Saving report to %1").arg(fn);
|
||||
|
||||
if (fn.isEmpty() ) return ; // Cancel
|
||||
|
||||
if (!fn.endsWith(".txt"))
|
||||
{
|
||||
fn+=".txt";
|
||||
}
|
||||
|
||||
QFile report_file(fn);
|
||||
if (report_file.open(QIODevice::WriteOnly))
|
||||
{
|
||||
@ -593,7 +589,6 @@ void ProjectPanel::fileExport()
|
||||
LibExportDialog ed;
|
||||
list<FWObject*> selectedLibs;
|
||||
map<int,FWObject*>::iterator i;
|
||||
QString path="";
|
||||
int lib_idx = -1;
|
||||
do
|
||||
{
|
||||
@ -620,7 +615,7 @@ void ProjectPanel::fileExport()
|
||||
} while (!exportLibraryTest(selectedLibs));
|
||||
|
||||
FWObject *selLib = ed.mapOfLibs[ lib_idx ];
|
||||
path = st->getWDir() + QString::fromUtf8(selLib->getName().c_str()) + ".fwl";
|
||||
QString path = st->getOpenFileDir() + QString::fromUtf8(selLib->getName().c_str()) + ".fwl";
|
||||
|
||||
resetFD();
|
||||
|
||||
@ -640,6 +635,7 @@ void ProjectPanel::fileExport()
|
||||
tr("&Yes"), tr("&No"), QString::null,
|
||||
0, 1 )==1 ) return;
|
||||
|
||||
st->setOpenFileDir(path);
|
||||
exportLibraryTo(fname,selectedLibs,ed.m_dialog->exportRO->isChecked());
|
||||
}
|
||||
|
||||
|
||||
@ -69,33 +69,35 @@ QString SimpleTextEditor::text()
|
||||
|
||||
void SimpleTextEditor::loadFromFile()
|
||||
{
|
||||
if ( QMessageBox::warning(
|
||||
this,"Firewall Builder",
|
||||
tr("Warning: loading from file discards current contents of the script."),
|
||||
"&Load", "&Cancel", QString::null, 0, 1 )==0)
|
||||
if (QMessageBox::warning(this, tr("Firewall Builder"),
|
||||
tr("Warning: loading from file discards "
|
||||
"current contents of the script."),
|
||||
"&Load", "&Cancel", QString::null, 0, 1 ) != 0)
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName( this, tr("Choose file"),
|
||||
st->getWDir());
|
||||
return;
|
||||
}
|
||||
|
||||
if (filename!="")
|
||||
{
|
||||
ifstream ifile(filename.toLatin1().constData());
|
||||
if (!ifile)
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,"Firewall Builder",
|
||||
tr("Could not open file %1").arg(filename),
|
||||
"&Continue", QString::null, QString::null, 0, 1 );
|
||||
return;
|
||||
}
|
||||
QString filename = QFileDialog::getOpenFileName(this, tr("Choose file"),
|
||||
st->getOpenFileDir());
|
||||
|
||||
m_dialog->editor->clear();
|
||||
char buf[1024];
|
||||
while (ifile.getline(buf,1024))
|
||||
{
|
||||
m_dialog->editor->append( buf );
|
||||
}
|
||||
}
|
||||
if (filename.isEmpty()) return;
|
||||
st->setOpenFileDir(filename);
|
||||
|
||||
ifstream ifile(filename.toLatin1().constData());
|
||||
if (!ifile)
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,"Firewall Builder",
|
||||
tr("Could not open file %1").arg(filename),
|
||||
"&Continue", QString::null, QString::null, 0, 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
m_dialog->editor->clear();
|
||||
char buf[1024];
|
||||
while (ifile.getline(buf,1024))
|
||||
{
|
||||
m_dialog->editor->append( buf );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
<ui version="4.0" >
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CommentEditorPanel_q</class>
|
||||
<widget class="QWidget" name="CommentEditorPanel_q" >
|
||||
<property name="enabled" >
|
||||
<widget class="QWidget" name="CommentEditorPanel_q">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
@ -12,91 +13,23 @@
|
||||
<height>217</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<property name="windowTitle">
|
||||
<string>Comment Editor Panel</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="TextEditWidget" name="editor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="TextEditWidget" name="editor" >
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>500</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line6" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="inputFromFileButton" >
|
||||
<property name="text" >
|
||||
<string>Import from file ...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>211</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TextEditWidget</class>
|
||||
@ -112,11 +45,11 @@
|
||||
<receiver>CommentEditorPanel_q</receiver>
|
||||
<slot>changed()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<hint type="sourcelabel">
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<hint type="destinationlabel">
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
|
||||
@ -1,153 +0,0 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2004 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
$Id$
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "global.h"
|
||||
|
||||
#include "execDialog.h"
|
||||
|
||||
#include <qdir.h>
|
||||
#include <qregexp.h>
|
||||
#include <qtimer.h>
|
||||
#include <qtextbrowser.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qfile.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qtextstream.h>
|
||||
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
# include <stdio.h>
|
||||
# include <sys/timeb.h>
|
||||
# include <time.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
execDialog::~execDialog()
|
||||
{
|
||||
delete m_dialog;
|
||||
}
|
||||
|
||||
execDialog::execDialog(QWidget *parent,const QStringList &args, const QString &closeButtonText)
|
||||
: QDialog(parent), proc(parent)
|
||||
{
|
||||
m_dialog = new Ui::execDialog_q;
|
||||
m_dialog->setupUi(this);
|
||||
|
||||
m_dialog->output->setWordWrapMode( QTextOption::NoWrap );
|
||||
res=-1;
|
||||
|
||||
if (! closeButtonText.isEmpty()) m_dialog->buttonOk->setText(closeButtonText);
|
||||
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(&proc, SIGNAL(readyReadStdout()), this, SLOT(readFromStdout()) );
|
||||
connect(&proc, SIGNAL(processExited()), this, SLOT(processExited()) );
|
||||
|
||||
arguments = args;
|
||||
|
||||
m_dialog->stopButton->hide();
|
||||
m_dialog->saveLogButton->hide();
|
||||
}
|
||||
|
||||
void execDialog::readFromStdout()
|
||||
{
|
||||
// output->append( proc.readStdout() );
|
||||
m_dialog->output->moveCursor( QTextCursor::End );
|
||||
m_dialog->output->insertPlainText( proc.readAllStandardOutput() );
|
||||
}
|
||||
|
||||
void execDialog::stopProcess()
|
||||
{
|
||||
proc.terminate();
|
||||
QTimer::singleShot( 1000, &proc, SLOT( kill() ) );
|
||||
}
|
||||
|
||||
void execDialog::processExited()
|
||||
{
|
||||
m_dialog->stopButton->hide();
|
||||
m_dialog->saveLogButton->show();
|
||||
m_dialog->buttonOk->setEnabled( true );
|
||||
m_dialog->buttonOk->setFocus();
|
||||
res=proc.exitStatus();
|
||||
}
|
||||
|
||||
int execDialog::run()
|
||||
{
|
||||
m_dialog->output->append( arguments.join(" ") );
|
||||
m_dialog->output->append("\n");
|
||||
|
||||
QStringList args = arguments;
|
||||
|
||||
assert(!args.empty());
|
||||
QString command = args[0];
|
||||
args.pop_front();
|
||||
|
||||
proc.start(command, args);
|
||||
|
||||
if ( !proc.waitForStarted() )
|
||||
{
|
||||
m_dialog->output->append( tr("Error: Failed to start program") );
|
||||
return exec();
|
||||
}
|
||||
m_dialog->saveLogButton->hide();
|
||||
m_dialog->stopButton->show();
|
||||
m_dialog->stopButton->setFocus();
|
||||
m_dialog->buttonOk->setEnabled( false );
|
||||
exec();
|
||||
return res;
|
||||
}
|
||||
void execDialog::saveLog()
|
||||
{
|
||||
QString dir;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
"Text file (*.txt)");
|
||||
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
if (!s.endsWith(".txt"))
|
||||
{
|
||||
s+=".txt";
|
||||
}
|
||||
QFile f(s);
|
||||
if (f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QTextStream (&f) << m_dialog->output->toPlainText();
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2004 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
$Id$
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __EXECDIALOG_H_
|
||||
#define __EXECDIALOG_H_
|
||||
|
||||
#include <ui_execdialog_q.h>
|
||||
|
||||
#include <qlist.h>
|
||||
#include <qstring.h>
|
||||
#include <qprocess.h>
|
||||
#include <qwidget.h>
|
||||
|
||||
class execDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QProcess proc;
|
||||
int res;
|
||||
Ui::execDialog_q *m_dialog;
|
||||
QStringList arguments;
|
||||
|
||||
public:
|
||||
execDialog(QWidget *parent,const QStringList &args, const QString &closeButtonText="");
|
||||
~execDialog();
|
||||
int run();
|
||||
|
||||
public slots:
|
||||
|
||||
virtual void readFromStdout();
|
||||
virtual void stopProcess();
|
||||
virtual void processExited();
|
||||
virtual void saveLog();
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -1,195 +0,0 @@
|
||||
<ui version="4.0" >
|
||||
<class>execDialog_q</class>
|
||||
<widget class="QDialog" name="execDialog_q" >
|
||||
<property name="enabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>513</width>
|
||||
<height>297</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Executing external command</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="output" />
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="saveLogButton" >
|
||||
<property name="text" >
|
||||
<string>Save log to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopButton" >
|
||||
<property name="minimumSize" >
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>28</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" >
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonOk" >
|
||||
<property name="text" >
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
<property name="shortcut" >
|
||||
<string>Alt+C</string>
|
||||
</property>
|
||||
<property name="autoDefault" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<tabstops>
|
||||
<tabstop>output</tabstop>
|
||||
<tabstop>saveLogButton</tabstop>
|
||||
<tabstop>stopButton</tabstop>
|
||||
<tabstop>buttonOk</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonOk</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>execDialog_q</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>stopButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>execDialog_q</receiver>
|
||||
<slot>stopProcess()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>saveLogButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>execDialog_q</receiver>
|
||||
<slot>saveLog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@ -705,12 +705,6 @@ void instDialog::hideEvent( QHideEvent *ev)
|
||||
|
||||
void instDialog::saveLog()
|
||||
{
|
||||
QString dir;
|
||||
//if (m_dialog->procLogDisplay==NULL) return;
|
||||
dir=st->getWDir();
|
||||
if (dir.isEmpty()) dir=st->getOpenFileDir();
|
||||
if (dir.isEmpty()) dir="~";
|
||||
|
||||
/*
|
||||
* We use QTextEdit::append to add lines to the log buffer, each
|
||||
append creates a new paragraph so QTextEdit::text returns only
|
||||
@ -723,26 +717,22 @@ void instDialog::saveLog()
|
||||
QString s = QFileDialog::getSaveFileName(
|
||||
this,
|
||||
"Choose a file",
|
||||
dir,
|
||||
st->getOpenFileDir(),
|
||||
"Text file (*.txt)");
|
||||
|
||||
if (s.isEmpty()) return;
|
||||
st->setOpenFileDir(s);
|
||||
|
||||
if (!s.endsWith(".txt")) s += ".txt";
|
||||
if (fwbdebug)
|
||||
qDebug( "Saving log to file %s", s.toAscii().constData() );
|
||||
|
||||
if (!s.isEmpty())
|
||||
QFile f(s);
|
||||
if (f.open( QIODevice::WriteOnly ))
|
||||
{
|
||||
if (!s.endsWith(".txt"))
|
||||
{
|
||||
s+=".txt";
|
||||
}
|
||||
|
||||
QFile f(s);
|
||||
if (f.open( QIODevice::WriteOnly ))
|
||||
{
|
||||
QTextStream str( &f );
|
||||
str << logText;
|
||||
f.close();
|
||||
}
|
||||
QTextStream str( &f );
|
||||
str << logText;
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -196,16 +196,13 @@ newFirewallDialog::newFirewallDialog(QWidget *parentw, FWObject *_p) :
|
||||
void newFirewallDialog::browseTemplate()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("FWBuilder template files"), "",
|
||||
this, tr("FWBuilder template files"), st->getOpenFileDir(),
|
||||
tr("FWBuilder template files (*.xml *.fwb *.fwl)"));
|
||||
|
||||
if (fileName=="") return ;
|
||||
if (fileName.isEmpty()) return;
|
||||
st->setOpenFileDir(fileName);
|
||||
|
||||
// QDir dir (fileName);
|
||||
// if (dir.exists ())
|
||||
// {
|
||||
m_dialog->templateFilePath->setText(fileName);
|
||||
// }
|
||||
updateTemplatePanel();
|
||||
}
|
||||
|
||||
|
||||
@ -120,14 +120,14 @@ newHostDialog::newHostDialog(QWidget *parentw, FWObject *_p) : QDialog(parentw)
|
||||
|
||||
void newHostDialog::browseTemplate()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("FWBuilder template files"), "", tr("FWBuilder template files (*.xml *.fwb)"));
|
||||
if (fileName=="")
|
||||
return ;
|
||||
QDir dir (fileName);
|
||||
// if (dir.exists ())
|
||||
// {
|
||||
m_dialog->templateFilePath->setText(fileName);
|
||||
// }
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, tr("FWBuilder template files"), st->getOpenFileDir(),
|
||||
tr("FWBuilder template files (*.xml *.fwb)"));
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
st->setOpenFileDir(fileName);
|
||||
|
||||
m_dialog->templateFilePath->setText(fileName);
|
||||
updateTemplatePanel();
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,8 @@
|
||||
#include <QRegExp>
|
||||
#include <QPixmap>
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "FWBSettings.h"
|
||||
@ -300,21 +302,7 @@ QString quoteString(const QString &str)
|
||||
|
||||
QString getFileDir(const QString &file)
|
||||
{
|
||||
int sn1 = file.lastIndexOf("/",-1);
|
||||
int sn2 = file.lastIndexOf("\\",-1);
|
||||
int sn = (sn1>=0)?sn1:sn2;
|
||||
QString dir;
|
||||
|
||||
if(sn<0) dir = "./";
|
||||
else dir = file.left( sn );
|
||||
|
||||
#ifdef _WIN32
|
||||
/* on windows, if directory is in the root of the drive (like "c:"),
|
||||
* I must append "\" to it
|
||||
*/
|
||||
if (dir.indexOf(":")==(dir.length()-1)) dir=dir + "\\";
|
||||
#endif
|
||||
return dir;
|
||||
return QFileInfo(file).dir().path();
|
||||
}
|
||||
|
||||
void setDisabledPalette(QWidget *w)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user