some qt gui changes

This commit is contained in:
hypnosis-i2p 2017-08-20 10:22:30 +08:00
parent 822995cbaf
commit 07fe51fa25
10 changed files with 148 additions and 14 deletions

View File

@ -341,7 +341,7 @@ namespace http {
s << "<br>" << std::endl; s << "<br>" << std::endl;
} }
static void ShowLocalDestination (std::stringstream& s, const std::string& b32) void ShowLocalDestination (std::stringstream& s, const std::string& b32)
{ {
s << "<b>Local Destination:</b><br>\r\n<br>\r\n"; s << "<b>Local Destination:</b><br>\r\n<br>\r\n";
i2p::data::IdentHash ident; i2p::data::IdentHash ident;

View File

@ -86,6 +86,7 @@ namespace http
void ShowTransports (std::stringstream& s); void ShowTransports (std::stringstream& s);
void ShowSAMSessions (std::stringstream& s); void ShowSAMSessions (std::stringstream& s);
void ShowI2PTunnels (std::stringstream& s); void ShowI2PTunnels (std::stringstream& s);
void ShowLocalDestination (std::stringstream& s, const std::string& b32);
} // http } // http
} // i2p } // i2p

View File

@ -88,7 +88,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \
../../daemon/I2PControl.cpp \ ../../daemon/I2PControl.cpp \
../../daemon/UnixDaemon.cpp \ ../../daemon/UnixDaemon.cpp \
../../daemon/UPnP.cpp \ ../../daemon/UPnP.cpp \
textbrowsertweaked1.cpp textbrowsertweaked1.cpp \
pagewithbackbutton.cpp
#qt creator does not handle this well #qt creator does not handle this well
#SOURCES += $$files(../../libi2pd/*.cpp) #SOURCES += $$files(../../libi2pd/*.cpp)
@ -168,7 +169,8 @@ HEADERS += DaemonQT.h mainwindow.h \
../../daemon/HTTPServer.h \ ../../daemon/HTTPServer.h \
../../daemon/I2PControl.h \ ../../daemon/I2PControl.h \
../../daemon/UPnP.h \ ../../daemon/UPnP.h \
textbrowsertweaked1.h textbrowsertweaked1.h \
pagewithbackbutton.h
INCLUDEPATH += ../../libi2pd INCLUDEPATH += ../../libi2pd
INCLUDEPATH += ../../libi2pd_client INCLUDEPATH += ../../libi2pd_client

View File

@ -15,6 +15,7 @@
#include "FS.h" #include "FS.h"
#include "Log.h" #include "Log.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Transports.h"
#include "HTTPServer.h" #include "HTTPServer.h"
@ -60,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent) :
setWindowTitle(QApplication::translate("AppTitle","I2PD")); setWindowTitle(QApplication::translate("AppTitle","I2PD"));
//TODO handle resizes and change the below into resize() call //TODO handle resizes and change the below into resize() call
setFixedSize(width(), 550); setFixedHeight(550);
ui->centralWidget->setFixedHeight(550); ui->centralWidget->setFixedHeight(550);
onResize(); onResize();
@ -88,8 +89,21 @@ MainWindow::MainWindow(QWidget *parent) :
createTrayIcon(); createTrayIcon();
#endif #endif
textBrowser = new TextBrowserTweaked1(); textBrowser = new TextBrowserTweaked1(this);
//textBrowser->setOpenExternalLinks(false);
textBrowser->setOpenLinks(false);
/*textBrowser->setTextInteractionFlags(textBrowser->textInteractionFlags()|
Qt::LinksAccessibleByMouse|Qt::LinksAccessibleByKeyboard|
Qt::TextSelectableByMouse|Qt::TextSelectableByKeyboard);*/
ui->verticalLayout_2->addWidget(textBrowser); ui->verticalLayout_2->addWidget(textBrowser);
childTextBrowser = new TextBrowserTweaked1(this);
//childTextBrowser->setOpenExternalLinks(false);
childTextBrowser->setOpenLinks(false);
connect(textBrowser, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedHandler(const QUrl&)));
pageWithBackButton = new PageWithBackButton(this, childTextBrowser);
ui->verticalLayout_2->addWidget(pageWithBackButton);
pageWithBackButton->hide();
connect(pageWithBackButton, SIGNAL(backReleased()), this, SLOT(backClickedFromChild()));
scheduleStatusPageUpdates(); scheduleStatusPageUpdates();
QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage())); QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
@ -107,6 +121,9 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(textBrowser, SIGNAL(mouseReleased()), this, SLOT(statusHtmlPageMouseReleased())); QObject::connect(textBrowser, SIGNAL(mouseReleased()), this, SLOT(statusHtmlPageMouseReleased()));
QObject::connect(textBrowser, SIGNAL(selectionChanged()), this, SLOT(statusHtmlPageSelectionChanged())); QObject::connect(textBrowser, SIGNAL(selectionChanged()), this, SLOT(statusHtmlPageSelectionChanged()));
QObject::connect(routerCommandsUI->runPeerTestPushButton, SIGNAL(released()), this, SLOT(runPeerTest()));
QObject::connect(routerCommandsUI->acceptTransitTunnelsPushButton, SIGNAL(released()), this, SLOT(enableTransit()));
QObject::connect(routerCommandsUI->declineTransitTunnelsPushButton, SIGNAL(released()), this, SLOT(disableTransit()));
QObject::connect(ui->settingsPagePushButton, SIGNAL(released()), this, SLOT(showSettingsPage())); QObject::connect(ui->settingsPagePushButton, SIGNAL(released()), this, SLOT(showSettingsPage()));
@ -279,9 +296,11 @@ void MainWindow::showStatusPage(StatusPage newStatusPage){
textBrowser->setHtml(getStatusPageHtml(false)); textBrowser->setHtml(getStatusPageHtml(false));
textBrowser->show(); textBrowser->show();
routerCommandsParent->hide(); routerCommandsParent->hide();
pageWithBackButton->hide();
}else{ }else{
routerCommandsParent->show(); routerCommandsParent->show();
textBrowser->hide(); textBrowser->hide();
pageWithBackButton->hide();
updateRouterCommandsButtons(); updateRouterCommandsButtons();
} }
wasSelectingAtStatusMainPage=false; wasSelectingAtStatusMainPage=false;
@ -299,6 +318,8 @@ void MainWindow::setStatusButtonsVisible(bool visible) {
QString MainWindow::getStatusPageHtml(bool showHiddenInfo) { QString MainWindow::getStatusPageHtml(bool showHiddenInfo) {
std::stringstream s; std::stringstream s;
s << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";
switch (statusPage) { switch (statusPage) {
case main_page: i2p::http::ShowStatus(s, showHiddenInfo);break; case main_page: i2p::http::ShowStatus(s, showHiddenInfo);break;
case commands: break; case commands: break;
@ -753,3 +774,40 @@ void MainWindow::setI2PController(i2p::qt::Controller* controller_) {
this->i2pController = controller_; this->i2pController = controller_;
} }
void MainWindow::runPeerTest() {
i2p::transport::transports.PeerTest();
}
void MainWindow::enableTransit() {
i2p::context.SetAcceptsTunnels(true);
updateRouterCommandsButtons();
}
void MainWindow::disableTransit() {
i2p::context.SetAcceptsTunnels(false);
updateRouterCommandsButtons();
}
void MainWindow::anchorClickedHandler(const QUrl & link) {
QString debugStr=QString()+"anchorClicked: "+"\""+link.toString()+"\"";
qDebug()<<debugStr;
//QMessageBox::information(this, "", debugStr);
/* /?page=local_destination&b32=xx...xx */
QString str=link.toString();
#define LOCAL_DEST_B32_PREFIX "/?page=local_destination&b32="
static size_t LOCAL_DEST_B32_PREFIX_SZ=QString(LOCAL_DEST_B32_PREFIX).size();
if(str.startsWith(LOCAL_DEST_B32_PREFIX)) {
str = str.right(str.size()-LOCAL_DEST_B32_PREFIX_SZ);
qDebug () << "b32:" << str;
pageWithBackButton->show();
textBrowser->hide();
std::stringstream s;
i2p::http::ShowLocalDestination(s,str.toStdString());
childTextBrowser->setHtml(QString::fromStdString(s.str()));
}
}
void MainWindow::backClickedFromChild() {
showStatusPage(statusPage);
}

View File

@ -24,6 +24,7 @@
#include <QtWidgets/QPushButton> #include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem> #include <QtWidgets/QSpacerItem>
#include "QVBoxLayout" #include "QVBoxLayout"
#include "QUrl"
#ifndef ANDROID #ifndef ANDROID
# include <QSystemTrayIcon> # include <QSystemTrayIcon>
@ -54,6 +55,7 @@
#include "DaemonQT.h" #include "DaemonQT.h"
#include "SignatureTypeComboboxFactory.h" #include "SignatureTypeComboboxFactory.h"
#include "pagewithbackbutton.h"
template<typename ValueType> template<typename ValueType>
bool isType(boost::any& a) { bool isType(boost::any& a) {
@ -357,6 +359,10 @@ private slots:
void showStatusMainPage(); void showStatusMainPage();
void showStatus_commands_Page(); void showStatus_commands_Page();
void runPeerTest();
void enableTransit();
void disableTransit();
void showStatus_local_destinations_Page(); void showStatus_local_destinations_Page();
void showStatus_leasesets_Page(); void showStatus_leasesets_Page();
void showStatus_tunnels_Page(); void showStatus_tunnels_Page();
@ -392,6 +398,8 @@ private:
TextBrowserTweaked1 * textBrowser; TextBrowserTweaked1 * textBrowser;
QWidget * routerCommandsParent; QWidget * routerCommandsParent;
PageWithBackButton * pageWithBackButton;
TextBrowserTweaked1 * childTextBrowser;
i2p::qt::Controller* i2pController; i2p::qt::Controller* i2pController;
@ -442,6 +450,9 @@ public slots:
void addServerTunnelPushButtonReleased(); void addServerTunnelPushButtonReleased();
void addClientTunnelPushButtonReleased(); void addClientTunnelPushButtonReleased();
void anchorClickedHandler(const QUrl & link);
void backClickedFromChild();
private: private:
QString datadir; QString datadir;
QString confpath; QString confpath;

View File

@ -1,6 +1,24 @@
#include "pagewithbackbutton.h" #include "pagewithbackbutton.h"
#include "QVBoxLayout"
#include "QHBoxLayout"
#include "QPushButton"
PageWithBackButton::PageWithBackButton(QWidget *parent) : QWidget(parent) PageWithBackButton::PageWithBackButton(QWidget *parent, QWidget* child) : QWidget(parent)
{ {
QVBoxLayout * layout = new QVBoxLayout();
setLayout(layout);
QWidget * topBar = new QWidget();
QHBoxLayout * topBarLayout = new QHBoxLayout();
topBar->setLayout(topBarLayout);
layout->addWidget(topBar);
layout->addWidget(child);
QPushButton * backButton = new QPushButton(topBar);
backButton->setText("< Back");
topBarLayout->addWidget(backButton);
connect(backButton, SIGNAL(released()), this, SLOT(backReleasedSlot()));
}
void PageWithBackButton::backReleasedSlot() {
emit backReleased();
} }

View File

@ -7,11 +7,15 @@ class PageWithBackButton : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PageWithBackButton(QWidget *parent = 0); explicit PageWithBackButton(QWidget *parent, QWidget* child);
signals: signals:
public slots: void backReleased();
private slots:
void backReleasedSlot();
}; };
#endif // PAGEWITHBACKBUTTON_H #endif // PAGEWITHBACKBUTTON_H

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>711</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
@ -24,13 +24,22 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>401</width> <width>711</width>
<height>301</height> <height>301</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
@ -44,6 +53,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="runPeerTestPushButton"> <widget class="QPushButton" name="runPeerTestPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Run peer test</string> <string>Run peer test</string>
</property> </property>
@ -51,6 +66,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="declineTransitTunnelsPushButton"> <widget class="QPushButton" name="declineTransitTunnelsPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Decline transit tunnels</string> <string>Decline transit tunnels</string>
</property> </property>
@ -58,6 +79,12 @@
</item> </item>
<item> <item>
<widget class="QPushButton" name="acceptTransitTunnelsPushButton"> <widget class="QPushButton" name="acceptTransitTunnelsPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Accept transit tunnels</string> <string>Accept transit tunnels</string>
</property> </property>
@ -68,6 +95,12 @@
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text"> <property name="text">
<string>Cancel graceful quit</string> <string>Cancel graceful quit</string>
</property> </property>

View File

@ -1,6 +1,9 @@
#include "textbrowsertweaked1.h" #include "textbrowsertweaked1.h"
TextBrowserTweaked1::TextBrowserTweaked1() TextBrowserTweaked1::TextBrowserTweaked1(QWidget * parent): QTextBrowser(parent)
{ {
} }
/*void TextBrowserTweaked1::setSource(const QUrl & url) {
emit navigatedTo(url);
}*/

View File

@ -2,19 +2,23 @@
#define TEXTBROWSERTWEAKED1_H #define TEXTBROWSERTWEAKED1_H
#include <QTextBrowser> #include <QTextBrowser>
#include <QUrl>
class TextBrowserTweaked1 : public QTextBrowser class TextBrowserTweaked1 : public QTextBrowser
{ {
Q_OBJECT Q_OBJECT
public: public:
TextBrowserTweaked1(); TextBrowserTweaked1(QWidget * parent);
//virtual void setSource(const QUrl & url);
signals: signals:
void mouseReleased(); void mouseReleased();
//void navigatedTo(const QUrl & link);
protected: protected:
void mouseReleaseEvent(QMouseEvent *event) { void mouseReleaseEvent(QMouseEvent *event) {
QTextBrowser::mouseReleaseEvent(event);
emit mouseReleased(); emit mouseReleased();
} }
}; };