Permalink
Browse files

added URL list file iterator to the UI

  • Loading branch information...
1 parent 4901873 commit 7bc57319a2774fb06f5911a5f1aaee1bb50530c6 agentzh committed Jun 12, 2009
Showing with 186 additions and 3 deletions.
  1. +4 −2 VdomBrowser.pro
  2. +1 −1 hunterconfigdialog.cpp
  3. +88 −0 iteratorconfigdialog.cpp
  4. +44 −0 iteratorconfigdialog.h
  5. +32 −0 mainwindow.cpp
  6. +17 −0 mainwindow.h
View
@@ -1,12 +1,14 @@
TEMPLATE = app
-SOURCES += aboutdialog.cpp \
+SOURCES += iteratorconfigdialog.cpp \
+ aboutdialog.cpp \
hunterconfigdialog.cpp \
lineedit.cpp \
urlloader.cpp \
mainwindow.cpp \
webpage.cpp \
main.cpp
-HEADERS += aboutdialog.h \
+HEADERS += iteratorconfigdialog.h \
+ aboutdialog.h \
hunterconfigdialog.h \
version.h \
lineedit.h \
@@ -47,7 +47,7 @@ HunterConfigDialog::HunterConfigDialog(QWidget *parent): QDialog(parent) {
layout->addWidget(formGroup);
QHBoxLayout* buttonsLayout = new QHBoxLayout;
- buttonsLayout->addSpacing(300);
+ buttonsLayout->addSpacing(450);
button = new QPushButton(tr("&Save"), this);
connect(button, SIGNAL(clicked()),
@@ -0,0 +1,88 @@
+#include "iteratorconfigdialog.h"
+//#include <QDebug>
+
+IteratorConfigDialog::IteratorConfigDialog(QWidget *parent): QDialog(parent) {
+ QCompleter *completer = new QCompleter(this);
+ completer->setModel(new QDirModel(completer));
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ m_formGroup = new QGroupBox(tr("&Enable URL iterator"), this);
+ m_formGroup->setCheckable(true);
+ m_formGroup->setChecked(false);
+
+ QGridLayout* formLayout = new QGridLayout(m_formGroup);
+ m_formGroup->setLayout(formLayout);
+ //m_formGroup->setFlat(false);
+
+ QLabel *label = new QLabel(tr("&URL list file"), this);
+ formLayout->addWidget(label, 0, 0);
+
+ m_listFileEdit = new QLineEdit(this);
+ m_listFileEdit->setCompleter(completer);
+ formLayout->addWidget(m_listFileEdit, 0, 1);
+ label->setBuddy(m_listFileEdit);
+
+ QPushButton* button = new QPushButton(tr("Browse..."), this);
+ connect(button, SIGNAL(clicked()),
+ this, SLOT(browseListFile()));
+ formLayout->addWidget(button, 0, 2);
+
+ formLayout->setSpacing(20);
+
+ layout->addWidget(m_formGroup);
+
+ QHBoxLayout* buttonsLayout = new QHBoxLayout;
+ buttonsLayout->addSpacing(450);
+
+ button = new QPushButton(tr("&Save"), this);
+ connect(button, SIGNAL(clicked()),
+ this, SLOT(accept()));
+ buttonsLayout->addWidget(button);
+
+ button = new QPushButton(tr("&Cancel"), this);
+ connect(button, SIGNAL(clicked()),
+ this, SLOT(reject()));
+ buttonsLayout->addWidget(button);
+ buttonsLayout->addStretch();
+
+ layout->addLayout(buttonsLayout);
+ //layout->addStretch();
+
+ setLayout(layout);
+ setFixedSize(QSize(700, 150));
+ setWindowTitle(tr("URL Iterator Configuration"));
+}
+
+void IteratorConfigDialog::accept() {
+ //qDebug() << "Checking form values...\n";
+ if (m_formGroup->isChecked()) {
+ QString progPath = m_listFileEdit->text();
+ if (progPath.isEmpty()) {
+ croak(tr("URL list file path is empty."));
+ m_listFileEdit->selectAll();
+ return;
+ }
+ if (! QFile::exists(progPath)) {
+ croak(tr("URL list file not found."));
+ m_listFileEdit->selectAll();
+ return;
+ }
+ QFile::Permissions perms = QFile::permissions(progPath);
+ if (! (perms & QFile::ReadUser)) {
+ croak(tr("URL list file is not readable."));
+ m_listFileEdit->selectAll();
+ return;
+ }
+ }
+ QDialog::accept();
+}
+
+void IteratorConfigDialog::browseListFile() {
+ const QString& fileName = QFileDialog::getOpenFileName(
+ this, tr("URL List File"),
+ 0, tr("Executable files (*.txt *.list);;Any Files (*)"));
+ if (!fileName.isEmpty()) {
+ m_listFileEdit->setText(fileName);
+ }
+}
+
@@ -0,0 +1,44 @@
+#ifndef ITERATOR_CONFIG_DIALOG_H
+#define ITERATOR_CONFIG_DIALOG_H
+
+#include <qdialog.h>
+#include <QtGui>
+//#include <QDebug>
+
+class IteratorConfigDialog: public QDialog {
+ Q_OBJECT
+
+public:
+ IteratorConfigDialog(QWidget *parent = 0);
+
+ void setIteratorEnabled(bool enabled) {
+ m_formGroup->setChecked(enabled);
+ }
+
+ void setListFile(const QString& path) {
+ m_listFileEdit->setText(path);
+ }
+
+ bool iteratorEnabled() {
+ return m_formGroup->isChecked();
+ }
+
+ QString listFile() const {
+ return m_listFileEdit->text();
+ }
+
+public slots:
+ virtual void accept();
+ void browseListFile();
+
+private:
+ void croak(const QString& msg) {
+ QMessageBox::warning(this, tr("X Hunter Configuration"),
+ msg, QMessageBox::NoButton);
+ }
+ QLineEdit* m_listFileEdit;
+ QGroupBox* m_formGroup;
+};
+
+#endif // HUNTER_CONFIG_DIALOG_H
+
View
@@ -19,6 +19,13 @@ MainWindow::MainWindow(const QString& url): currentZoom(100) {
m_huntButton = new QPushButton(tr("Hun&t"), this);
connect(m_huntButton, SIGNAL(clicked()), SLOT(huntOnly()));
+ m_iteratorConfig = new IteratorConfigDialog(this);
+ connect(m_iteratorConfig, SIGNAL(accepted()),
+ this, SLOT(saveIteratorConfig()));
+
+ m_iterPrevButton = new QPushButton(tr("Prev"), this);
+ m_iterNextButton = new QPushButton(tr("&Next"), this);
+
m_settings = new QSettings(
QSettings::UserScope,
qApp->organizationDomain(),
@@ -228,6 +235,8 @@ void MainWindow::createToolBar() {
bar->addWidget(loadButton);
bar->addWidget(m_huntButton);
+ bar->addWidget(m_iterPrevButton);
+ bar->addWidget(m_iterNextButton);
}
void MainWindow::createMenus() {
@@ -319,6 +328,7 @@ void MainWindow::createSettingsMenu() {
}
prefMenu->addSeparator();
prefMenu->addAction(tr("X &Hunter"), this, SLOT(execHunterConfig()));
+ prefMenu->addAction(tr("&URL Iterator"), this, SLOT(execIteratorConfig()));
}
void MainWindow::createHelpMenu() {
@@ -343,6 +353,9 @@ void MainWindow::writeSettings() {
m_settings->setValue("hunterPath", m_hunterPath);
m_settings->setValue("vdomPath", m_vdomPath);
+ m_settings->setValue("iteratorEnabled", QVariant(m_iteratorEnabled));
+ m_settings->setValue("urlListFile", QVariant(m_urlListFile));
+
m_settings->endGroup();
}
@@ -364,6 +377,10 @@ void MainWindow::readSettings() {
m_vdomPath = m_settings->value("vdomPath").toString();
initHunterConfig();
+ m_iteratorEnabled = m_settings->value("iteratorEnabled").toBool();
+ m_urlListFile = m_settings->value("urlListFile").toString();
+ initIteratorConfig();
+
m_settings->endGroup();
}
@@ -382,6 +399,13 @@ void MainWindow::saveHunterConfig() {
//qDebug() << "Saving hunter config... (hunter: " << m_hunterPath << ")";
}
+void MainWindow::saveIteratorConfig() {
+ m_iteratorEnabled = m_iteratorConfig->iteratorEnabled();
+ m_iterPrevButton->setEnabled(m_iteratorEnabled);
+ m_iterNextButton->setEnabled(m_iteratorEnabled);
+ m_urlListFile = m_iteratorConfig->listFile();
+}
+
void MainWindow::hunterFinished(int exitCode, QProcess::ExitStatus) {
if (exitCode != 0) {
QString msg = QString("Failed to spawn X Hunter %1: %2: "
@@ -624,6 +648,14 @@ void MainWindow::initHunterConfig() {
m_hunterConfig->setVdomPath(m_vdomPath);
}
+void MainWindow::initIteratorConfig() {
+ m_iteratorConfig->setIteratorEnabled(m_iteratorEnabled);
+ m_iterPrevButton->setEnabled(m_iteratorEnabled);
+ m_iterNextButton->setEnabled(m_iteratorEnabled);
+ //update();
+ m_iteratorConfig->setListFile(m_urlListFile);
+}
+
void MainWindow::addUrlToList() {
QUrl::FormattingOptions opts;
opts |= QUrl::RemoveScheme;
View
@@ -12,6 +12,7 @@
#include "lineedit.h"
#include "aboutdialog.h"
#include "hunterconfigdialog.h"
+#include "iteratorconfigdialog.h"
class MainWindow : public QMainWindow
{
@@ -155,19 +156,27 @@ protected slots:
}
void saveHunterConfig();
+ void saveIteratorConfig();
void execHunterConfig() {
initHunterConfig();
m_hunterConfig->exec();
}
+ void execIteratorConfig() {
+ initIteratorConfig();
+ m_iteratorConfig->exec();
+ }
+
private:
QVariant evalJS(const QString& js);
void addUrlToList();
void initHunterConfig();
+ void initIteratorConfig();
+
QVector<int> zoomLevels;
int currentZoom;
@@ -204,6 +213,8 @@ protected slots:
HunterConfigDialog* m_hunterConfig;
QLabel *m_hunterLabel;
+ IteratorConfigDialog* m_iteratorConfig;
+
QStringList m_urlList;
QStringListModel m_urlCompleterModel;
QSettings* m_settings;
@@ -217,10 +228,16 @@ protected slots:
QString m_hunterPath;
QString m_vdomPath;
+ bool m_iteratorEnabled;
+ QString m_urlListFile;
+
QWebVDom* m_webvdom;
QProcess m_hunter;
QPushButton* m_huntButton;
+ QPushButton* m_iterPrevButton;
+ QPushButton* m_iterNextButton;
+
JSonDriver m_jsonDriver;
};

0 comments on commit 7bc5731

Please sign in to comment.