Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merge markit

  • Loading branch information...
commit 728d3f725cae06bde15eddbf1fb43287db2984f8 1 parent 4c7698d
xunxin authored
View
9 VdomBrowser.pro
@@ -5,7 +5,10 @@ SOURCES += iteratorconfigdialog.cpp \
lineedit.cpp \
urlloader.cpp \
mainwindow.cpp \
+ webview.cpp \
webpage.cpp \
+ fielddialog.cpp \
+ viwiedialog.cpp \
main.cpp
HEADERS += iterator.h \
iteratorconfigdialog.h \
@@ -15,7 +18,11 @@ HEADERS += iterator.h \
lineedit.h \
urlloader.h \
mainwindow.h \
- webpage.h
+ webview.h \
+ webpage.h \
+ fielddialog.h \
+ viwiedialog.h
+
CONFIG -= app_bundle
CONFIG += qt warn_on uitools
DESTDIR = $$PWD
View
13 b
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+export QT_WEBKIT=webkit_trunk
+export WEBKITDIR=$HOME/vdom-webkit/webkit/WebKit
+if [ -z "$QTDIR" ]; then
+ export QTDIR=/opt/qt4.5
+fi
+export PATH=$QTDIR/bin:$PATH
+make distclean
+qmake "CONFIG-=debug" -r
+#qmake -r
+make
+
View
137 fielddialog.cpp
@@ -0,0 +1,137 @@
+
+#include <QtGui>
+
+#include "fielddialog.h"
+
+FieldDialog::FieldDialog(QWidget* parent) : QDialog(parent)
+{
+
+ QList<QComboBox> *fieldTypeComboList = new QList<QComboBox>();
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+
+ formGroupBox = new QGroupBox(tr("Field"));
+ QFormLayout *formLayout = new QFormLayout;
+
+ selectedText = new QTextEdit();
+ selectedText->setReadOnly(true);
+ formLayout->addRow(new QLabel(tr("Text:")), selectedText);
+
+ wantText = new QTextEdit();
+ formLayout->addRow(new QLabel(tr("Want:")), wantText);
+
+ nameCombo = new QComboBox();
+ formLayout->addRow(new QLabel(tr("Name: ")), nameCombo);
+
+ typeCombo = new QComboBox();
+ typeCombo->addItem("image");
+ typeCombo->addItem("text");
+
+ typeCombo->setEditable(false);
+
+ formLayout->addRow(new QLabel(tr("Type: ")), typeCombo);
+
+ filtersTable = new QTableWidget(0, 3);
+ QStringList list;
+ list << tr("Filter Type") << tr("Filter Arg") << tr("Delete");
+ filtersTable->setHorizontalHeaderLabels (list);
+ formLayout->addRow(new QLabel(tr("Filters: ")), filtersTable);
+
+ xpathsTable = new QTableWidget(0, 3);
+ xpathsTable->setHorizontalHeaderLabels ( QStringList() << tr("Xpath") << tr("Start") << tr("End"));
+ formLayout->addRow(new QLabel(tr("Xpath: ")), xpathsTable);
+/*
+ fieldTypeCombo = new QComboBox();
+ fieldTypeCombo->addItem(tr("suffix"));
+ fieldTypeCombo->addItem(tr("prefix"));
+ qDebug() << filtersTable->rowCount();
+ qDebug() << filtersTable->currentRow();
+ qDebug() << filtersTable->currentColumn();
+
+ filtersTable->setCellWidget(0, 0, fieldTypeCombo);
+
+ filtersTable->setCellWidget(1, 0, new QComboBox(fieldTypeCombo));
+ filtersTable->setCellWidget(2, 0, new QComboBox(fieldTypeCombo));
+ */
+
+
+ formGroupBox->setLayout(formLayout);
+
+ mainLayout->addWidget(formGroupBox);
+
+ buttonsGroupBox = new QGroupBox(tr("Process: "));
+ QHBoxLayout *hboxLayout = new QHBoxLayout;
+ addBtn = new QPushButton(tr("Add"));
+ hboxLayout->addWidget(addBtn);
+ overrideBtn = new QPushButton(tr("Override"));
+ hboxLayout->addWidget(overrideBtn);
+ deleteBtn = new QPushButton(tr("Delete"));
+ hboxLayout->addWidget(deleteBtn);
+
+ cancelBtn = new QPushButton(tr("Cancel"));
+ connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
+ hboxLayout->addWidget(cancelBtn);
+ buttonsGroupBox->setLayout(hboxLayout);
+
+ mainLayout->addWidget(buttonsGroupBox);
+
+
+ setLayout(mainLayout);
+
+ setWindowTitle(tr("Field Panel"));
+
+ connect(addBtn, SIGNAL(clicked()), this, SIGNAL(addField()));
+ connect(overrideBtn, SIGNAL(clicked()), this, SIGNAL(overrideField()));
+ connect(deleteBtn, SIGNAL(clicked()), this, SIGNAL(deleteField()));
+
+
+}
+
+bool FieldDialog::refresh(const QVariant& selected)
+{
+ qDebug() << selected;
+ Q_ASSERT(selected.toMap().type() == QVariant::Map);
+
+ fieldJson = selected;
+
+ QVariantMap fieldMap = selected.toMap();
+
+ QString type = fieldMap["type"].toString();
+ qDebug() << "type:" << type;
+ typeCombo->setCurrentIndex(typeCombo->findText(type));
+
+ QString text = fieldMap["text"].toString();
+ selectedText->setPlainText(text);
+
+ QString want = fieldMap["want"].toString();
+ wantText->setPlainText(want);
+
+
+ xpathsTable->clear();
+ QVariantList xpathList = fieldMap["xpaths"].toList();
+ int len = xpathList.length();
+ for (int i = 0; i < len; i++) {
+ QVariant var = xpathList.at(i);
+
+ QVariantMap xpathMap = var.toMap();
+
+ QString xpath = xpathMap["xpath"].toString();
+ int start = xpathMap["start"].toInt();
+ int end = xpathMap["end"].toInt();
+ xpathsTable->setRowCount(xpathsTable->rowCount() + 1);
+ //xpathsTable->insertRow(1);
+
+ xpathsTable->setItem(i, 0, new QTableWidgetItem(xpath));
+ xpathsTable->setItem(i, 1, new QTableWidgetItem(QString::number(start)));
+ xpathsTable->setItem(i, 2, new QTableWidgetItem(QString::number(end)));
+ }
+ // nameCombo
+ // typeCombo
+ //
+ // fieldsTable
+ return true;
+}
+
+QVariant FieldDialog::getValue()
+{
+ return fieldJson;
+}
View
58 fielddialog.h
@@ -0,0 +1,58 @@
+#ifndef FIELD_DIALOG_H
+#define FIELD_DIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QDialoButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QMenu;
+class QMenuBar;
+class QPushButton;
+class QTextEdit;
+class QTableWidget;
+QT_END_NAMESPACE
+
+class FieldDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ FieldDialog(QWidget *parent = 0);
+ bool refresh(const QVariant&);
+ QVariant getValue();
+
+signals:
+ void addField();
+ void deleteField();
+ void overrideField();
+
+private:
+ QGroupBox *buttonsGroupBox;
+ QGroupBox *formGroupBox;
+
+ QPushButton *addBtn;
+ QPushButton *deleteBtn;
+ QPushButton *overrideBtn;
+ QPushButton *cancelBtn;
+
+ QTextEdit *selectedText;
+ QTextEdit *wantText;
+ QComboBox *nameCombo;
+ QComboBox *typeCombo;
+
+ QList<QComboBox> *fieldTypeComboList;
+ QTableWidget *filtersTable;
+
+ QTableWidget *xpathsTable;
+ QDialoButtonBox *buttonBox;
+
+ QVariant fieldJson;
+};
+
+#endif
View
145 mainwindow.cpp
@@ -1,5 +1,6 @@
#include "mainwindow.h"
#include "webpage.h"
+#include "webview.h"
#include <stdlib.h>
const static int MAX_FILE_LINE_LEN = 2048;
@@ -126,6 +127,7 @@ void MainWindow::setupUI() {
createUrlEdit();
createToolBar();
createMenus();
+ createViwieUI();
//m_hunterConfig->hide();
}
@@ -141,8 +143,11 @@ void MainWindow::createCentralWidget() {
}
void MainWindow::createWebView() {
- m_view = new QWebView(this);
- QWebPage* page = new QWebPage(m_view);
+ //m_view = new QWebView(this);
+ //QWebPage* page = new QWebPage(m_view);
+ m_view = new WebView(this);
+ QWebPage* page = webPage();
+
page->settings()->setAttribute(QWebSettings::JavascriptEnabled, m_enableJavascript);
page->settings()->setAttribute(QWebSettings::PluginsEnabled, m_enablePlugins);
page->settings()->setAttribute(QWebSettings::AutoLoadImages, m_enableImages);
@@ -161,6 +166,7 @@ void MainWindow::createWebView() {
connect(m_view, SIGNAL(urlChanged(const QUrl&)), this, SLOT(updateUrl(const QUrl&)));
connect(m_view, SIGNAL(linkClicked(const QUrl&)), this, SLOT(loadUrl(const QUrl&)));
+
m_view->pageAction(QWebPage::Back)->setShortcut(QKeySequence::Back);
m_view->pageAction(QWebPage::Stop)->setShortcut(Qt::Key_Escape);
m_view->pageAction(QWebPage::Forward)->setShortcut(QKeySequence::Forward);
@@ -344,6 +350,141 @@ void MainWindow::createHelpMenu() {
this, SLOT(aboutMe()));
}
+void MainWindow::createViwieUI() {
+ Q_ASSERT(m_view != NULL);
+
+ m_webSelected = new QWebSelected(m_view->page());
+
+ m_fieldDialog = new FieldDialog(this);
+ m_viwieDialog = new ViwieDialog(this);
+ connect(m_view, SIGNAL(showTextFieldDialog()), this, SLOT(showTextFieldDialog()));
+ connect(m_view, SIGNAL(showImageFieldDialog()), this, SLOT(showImageFieldDialog()));
+
+ connect(m_view, SIGNAL(showViwieDialog()), this, SLOT(showViwieDialog()));
+
+ connect(m_fieldDialog, SIGNAL(addField()), this, SLOT(addField()));
+ connect(m_fieldDialog, SIGNAL(overrideField()), this, SLOT(overrideField()));
+ connect(m_fieldDialog, SIGNAL(deleteField()), this, SLOT(deleteField()));
+
+ connect(m_viwieDialog, SIGNAL(permanentSave()), this, SLOT(permanentSaveViwie()));
+ connect(m_viwieDialog, SIGNAL(tmpSave()), this, SLOT(tmpSaveViwie()));
+
+}
+
+void MainWindow::showTextFieldDialog() {
+ QVariantMap fieldMap;
+
+ fieldMap.insert("type", QVariant("text"));
+ fieldMap.insert("text", QVariant(m_view->page()->selectedText()));
+ QVariant selectedNodes = m_webSelected->getSelectedNodes();
+ fieldMap.insert("xpaths", selectedNodes);
+
+ m_fieldDialog->refresh(fieldMap);
+
+ m_fieldDialog->exec();
+}
+
+void MainWindow::showImageFieldDialog() {
+ QVariantMap fieldMap;
+ QPoint pos = m_view->hitPos;
+ fieldMap.insert("type", QVariant("image"));
+ QVariant hitNode = m_webSelected->getClickedNode(pos);
+ fieldMap.insert("xpaths", hitNode);
+
+ m_fieldDialog->refresh(fieldMap);
+
+ m_fieldDialog->exec();
+}
+
+
+void MainWindow::showViwieDialog() {
+ if (viwieTags.isNull()) {
+ QVariantMap map;
+ QString url = m_view->url().toString();
+
+ map.insert("url", QVariant(url));
+ viwieTags = QVariant(map);
+ }
+
+ m_viwieDialog->refresh(viwieTags);
+ m_viwieDialog->exec();
+}
+
+void MainWindow::hideViwieDialog() {
+ m_viwieDialog->hide();
+}
+
+
+void MainWindow::addField() {
+ if (viwieTags.isNull()) {
+ QMessageBox::warning(this, tr("Add Field"),
+ "No url and category selected!", QMessageBox::NoButton);
+ return;
+ }
+
+ QVariantMap viwieMap = viwieTags.toMap();
+ QString cat = viwieMap["category"].toString();
+ if (cat.isNull()) {
+ QMessageBox::warning(this, tr("Add Field"),
+ "No category selected on Viwie panel", QMessageBox::NoButton);
+ return;
+ }
+ QVariant fieldsVar = viwieMap["fields"];
+ if (fieldsVar.isNull()) {
+ QVariantList fieldList;
+ fieldList.push_back(m_fieldDialog->getValue());
+ viwieMap.insert("fields", QVariant(fieldList));
+ } else {
+ QVariantList fieldList = fieldsVar.toList();
+ QVariantMap fieldMap = m_fieldDialog->getValue().toMap();
+ QString name = fieldMap["name"].toString();
+ if (name.isEmpty()) {
+ QMessageBox::warning(this, tr("Add Field"),
+ "No name selected!", QMessageBox::NoButton);
+ return;
+ }
+ int len = fieldList.count();
+ for (int i = 0; i < len; i++) {
+ QString n = fieldList.at(i).toMap().value("name").toString();
+ if (n == name) {
+ QMessageBox::warning(this, tr("Add Field"),
+ "The name has already existed!", QMessageBox::NoButton);
+ return;
+ }
+ }
+ fieldList.push_back(m_fieldDialog->getValue());
+ viwieMap.insert("fields", QVariant(fieldList));
+ }
+ viwieTags = QVariant(viwieMap);
+
+ m_fieldDialog->accept();
+}
+
+void MainWindow::overrideField() {
+ m_fieldDialog->accept();
+}
+
+void MainWindow::deleteField() {
+ m_fieldDialog->accept();
+}
+
+void MainWindow::tmpSaveViwie() {
+ QVariant newViwie = m_viwieDialog->getValue();
+ viwieTags = newViwie;
+
+ m_viwieDialog->accept();
+}
+
+void MainWindow::permanentSaveViwie() {
+ tmpSaveViwie();
+ qDebug() << "Permanent Save: " << viwieTags;
+ m_viwieDialog->accept();
+}
+
+
+void MainWindow::showDetailField(const QVariant& detail) {
+}
+
void MainWindow::writeSettings() {
m_settings->beginGroup("MainWindow");
View
36 mainwindow.h
@@ -15,6 +15,11 @@
#include "iteratorconfigdialog.h"
#include "iterator.h"
+#include <qwebselected.h>
+#include "fielddialog.h"
+#include "viwiedialog.h"
+#include "webview.h"
+
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -54,7 +59,29 @@ protected slots:
m_itemInfoEdit->append(QString::fromUtf8(m_hunter.readAllStandardError()));
}
+<<<<<<< HEAD:VdomBrowser/mainwindow.h
void loadUrl(const QUrl& url);
+=======
+ // viwie slots
+ void showTextFieldDialog();
+ void showImageFieldDialog();
+ void showViwieDialog();
+ void hideViwieDialog();
+
+ void addField();
+ void overrideField();
+ void deleteField();
+
+ void tmpSaveViwie();
+ void permanentSaveViwie();
+ void showDetailField(const QVariant& detail);
+
+ void loadUrl(const QUrl& url) {
+ //fprintf(stderr, "Loading new url...");
+ m_view->load(url);
+ m_view->setFocus(Qt::OtherFocusReason);
+ }
+>>>>>>> add markit project:VdomBrowser/mainwindow.h
void updateUrl(const QUrl& url) {
m_urlEdit->setText(url.toEncoded());
@@ -201,7 +228,7 @@ protected slots:
QTextEdit* m_itemInfoEdit;
QTextEdit* m_pageInfoEdit;
- QWebView *m_view;
+ WebView *m_view;
LineEdit *m_urlEdit;
QWidget *m_sidebar;
QProgressBar *m_progress;
@@ -210,6 +237,13 @@ protected slots:
IteratorConfigDialog* m_iteratorConfig;
+ bool m_viwieEnabled;
+ void createViwieUI();
+ QWebSelected* m_webSelected;
+ ViwieDialog *m_viwieDialog;
+ FieldDialog *m_fieldDialog;
+ QVariant viwieTags;
+
QStringList m_urlList;
QStringListModel m_urlCompleterModel;
QSettings* m_settings;
View
76 viwiedialog.cpp
@@ -0,0 +1,76 @@
+#include "viwiedialog.h"
+
+
+ViwieDialog::ViwieDialog(QWidget *parent)
+ :QDialog(parent)
+{
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ formGroupBox = new QGroupBox(tr("Page"));
+
+ QFormLayout *formLayout = new QFormLayout();
+ urlEditor = new QLineEdit();
+ urlEditor->setText("http://www.google.com");
+ urlEditor->setReadOnly(true);
+ formLayout->addRow(new QLabel(tr("Url: ")), urlEditor);
+
+ catCombo = new QComboBox();
+ catCombo->addItem("cat1");
+ catCombo->addItem("cat2");
+ formLayout->addRow(new QLabel(tr("Category: ")), catCombo);
+ fieldsTable = new QTableWidget(0, 3);
+ QStringList list;
+ list << tr("Field Name") << tr("Field Type") << tr("Detail");
+ fieldsTable->setHorizontalHeaderLabels (list);
+ formLayout->addRow(new QLabel(tr("Fields: ")), fieldsTable);
+
+ formGroupBox->setLayout(formLayout);
+ mainLayout->addWidget(formGroupBox);
+
+ buttonsGroupBox = new QGroupBox(tr("Process: "));
+ QHBoxLayout *hboxLayout = new QHBoxLayout;
+ QPushButton *tmpSaveBtn = new QPushButton(tr("Temp Save"));
+ QPushButton *permSaveBtn = new QPushButton(tr("Permanent Save"));
+ QPushButton *cancelBtn = new QPushButton(tr("Cancel"));
+ connect(cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
+
+ hboxLayout->addWidget(tmpSaveBtn);
+ hboxLayout->addWidget(permSaveBtn);
+ hboxLayout->addWidget(cancelBtn);
+
+ buttonsGroupBox->setLayout(hboxLayout);
+
+ mainLayout->addWidget(buttonsGroupBox);
+ setLayout(mainLayout);
+ setWindowTitle(tr("Vision-based Web Information Extraction "));
+}
+
+QVariant ViwieDialog::getValue()
+{
+
+ return viwieJson;
+}
+
+bool ViwieDialog::refresh(const QVariant& viwieTags)
+{
+ QVariantMap viwieMap = viwieTags.toMap();
+
+ QString url = viwieMap["url"].toString();
+ urlEditor->setText(url);
+
+ fieldsTable->clear();
+ QVariantList fieldsList = viwieMap["fields"].toList();
+ int len = fieldsList.length();
+ for (int i = 0; i < len; i++) {
+ QVariantMap fieldMap = fieldsList.at(i).toMap();
+
+ QString name = fieldMap["name"].toString();
+ QString type = fieldMap["type"].toString();
+ fieldsTable->setRowCount(fieldsTable->rowCount() + 1);
+
+ fieldsTable->setItem(i, 0, new QTableWidgetItem(name));
+ fieldsTable->setItem(i, 1, new QTableWidgetItem(type));
+ }
+
+ return true;
+}
View
61 viwiedialog.h
@@ -0,0 +1,61 @@
+#ifndef PAGE_TAG_DIALOG_H
+#define PAGE_TAG_DIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#include <QVariant>
+
+QT_BEGIN_NAMESPACE
+class QAction;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QMenu;
+class QMenuBar;
+class QPushButton;
+class QTextEdit;
+class QTableWidget;
+QT_END_NAMESPACE
+
+class ViwieDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ ViwieDialog(QWidget *parent = 0);
+
+ bool refresh(const QVariant&);
+ QVariant getValue();
+
+public slots:
+ void emitShowDetailField() {
+ QVariant detail;
+
+ emit showDetailField(detail);
+ }
+
+signals:
+ void permanentSave();
+ void tmpSave();
+
+ void showDetailField(const QVariant& detail);
+
+private:
+ QGroupBox *formGroupBox;
+ QGroupBox *buttonsGroupBox;
+
+ QLineEdit *urlEditor;
+ QComboBox *catCombo;
+
+ QTableWidget *fieldsTable;
+ QPushButton *tmpSaveBtn;
+ QPushButton *permSaveBtn;
+ QPushButton *cancelBtn;
+
+ QDialogButtonBox *buttonBox;
+
+ QVariant viwieJson;
+};
+
+#endif
View
45 webview.cpp
@@ -0,0 +1,45 @@
+#include "webview.h"
+
+WebView::WebView(QWidget *parent)
+ :QWebView(parent),
+ m_page(new WebPage(this))
+{
+ setPage(m_page);
+}
+
+void WebView::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu *menu = new QMenu(this);
+
+ QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
+ //if (!page()->selectedText().isNull()) {
+ // qDebug() << " selected Text is null()";
+ //}
+ if (!page()->selectedText().isEmpty()) {
+ if (!menu->isEmpty())
+ menu->addSeparator();
+ menu->addAction(tr("&Add Text Field"), this, SIGNAL(showTextFieldDialog()));
+ }
+
+ if (!r.imageUrl().isEmpty()) {
+ if (!menu->isEmpty())
+ menu->addSeparator();
+ hitPos = event->pos();
+ menu->addAction(tr("&Add Image Field"), this, SIGNAL(showImageFieldDialog()));
+ }
+
+ if (!menu->isEmpty())
+ menu->addSeparator();
+ menu->addAction(tr("&Viwie"), this, SIGNAL(showViwieDialog()));
+
+ if (menu->isEmpty()) {
+ delete menu;
+ menu = page()->createStandardContextMenu();
+ }
+ menu->exec(mapToGlobal(event->pos()));
+ delete menu;
+
+ //QWebView::contextMenuEvent(event);
+}
+
+
View
37 webview.h
@@ -0,0 +1,37 @@
+#ifndef VDOMWEBVIEW_H
+#define VDOMWEBVIEW_H
+
+
+#include <qwebview.h>
+#include <webpage.h>
+#include <QDebug>
+#include <QtGui>
+#include <qwebframe.h>
+#include "fielddialog.h"
+#include "viwiedialog.h"
+
+
+class WebView : public QWebView
+{
+ Q_OBJECT
+
+public:
+ WebView(QWidget *parent = 0);
+
+ WebPage *webPage() const { return m_page; }
+
+signals:
+ void showImageFieldDialog();
+ void showTextFieldDialog();
+
+ void showViwieDialog();
+
+public:
+ QPoint hitPos;
+
+protected:
+ void contextMenuEvent(QContextMenuEvent *event);
+ WebPage* m_page;
+};
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.