Skip to content

Commit

Permalink
some qt gui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nonlin-lin-chaos-order-etc-etal committed Aug 20, 2017
1 parent 822995c commit 07fe51f
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 14 deletions.
2 changes: 1 addition & 1 deletion daemon/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ namespace http {
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";
i2p::data::IdentHash ident;
Expand Down
1 change: 1 addition & 0 deletions daemon/HTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace http
void ShowTransports (std::stringstream& s);
void ShowSAMSessions (std::stringstream& s);
void ShowI2PTunnels (std::stringstream& s);
void ShowLocalDestination (std::stringstream& s, const std::string& b32);
} // http
} // i2p

Expand Down
6 changes: 4 additions & 2 deletions qt/i2pd_qt/i2pd_qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \
../../daemon/I2PControl.cpp \
../../daemon/UnixDaemon.cpp \
../../daemon/UPnP.cpp \
textbrowsertweaked1.cpp
textbrowsertweaked1.cpp \
pagewithbackbutton.cpp

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

INCLUDEPATH += ../../libi2pd
INCLUDEPATH += ../../libi2pd_client
Expand Down
62 changes: 60 additions & 2 deletions qt/i2pd_qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "FS.h"
#include "Log.h"
#include "RouterContext.h"
#include "Transports.h"

#include "HTTPServer.h"

Expand Down Expand Up @@ -60,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent) :
setWindowTitle(QApplication::translate("AppTitle","I2PD"));

//TODO handle resizes and change the below into resize() call
setFixedSize(width(), 550);
setFixedHeight(550);
ui->centralWidget->setFixedHeight(550);
onResize();

Expand Down Expand Up @@ -88,8 +89,21 @@ MainWindow::MainWindow(QWidget *parent) :
createTrayIcon();
#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);
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();

QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
Expand All @@ -107,6 +121,9 @@ MainWindow::MainWindow(QWidget *parent) :
QObject::connect(textBrowser, SIGNAL(mouseReleased()), this, SLOT(statusHtmlPageMouseReleased()));
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()));

Expand Down Expand Up @@ -279,9 +296,11 @@ void MainWindow::showStatusPage(StatusPage newStatusPage){
textBrowser->setHtml(getStatusPageHtml(false));
textBrowser->show();
routerCommandsParent->hide();
pageWithBackButton->hide();
}else{
routerCommandsParent->show();
textBrowser->hide();
pageWithBackButton->hide();
updateRouterCommandsButtons();
}
wasSelectingAtStatusMainPage=false;
Expand All @@ -299,6 +318,8 @@ void MainWindow::setStatusButtonsVisible(bool visible) {
QString MainWindow::getStatusPageHtml(bool showHiddenInfo) {
std::stringstream s;

s << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";

switch (statusPage) {
case main_page: i2p::http::ShowStatus(s, showHiddenInfo);break;
case commands: break;
Expand Down Expand Up @@ -753,3 +774,40 @@ void MainWindow::setI2PController(i2p::qt::Controller* 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);
}
11 changes: 11 additions & 0 deletions qt/i2pd_qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include "QVBoxLayout"
#include "QUrl"

#ifndef ANDROID
# include <QSystemTrayIcon>
Expand Down Expand Up @@ -54,6 +55,7 @@

#include "DaemonQT.h"
#include "SignatureTypeComboboxFactory.h"
#include "pagewithbackbutton.h"

template<typename ValueType>
bool isType(boost::any& a) {
Expand Down Expand Up @@ -357,6 +359,10 @@ private slots:

void showStatusMainPage();
void showStatus_commands_Page();
void runPeerTest();
void enableTransit();
void disableTransit();

void showStatus_local_destinations_Page();
void showStatus_leasesets_Page();
void showStatus_tunnels_Page();
Expand Down Expand Up @@ -392,6 +398,8 @@ private slots:

TextBrowserTweaked1 * textBrowser;
QWidget * routerCommandsParent;
PageWithBackButton * pageWithBackButton;
TextBrowserTweaked1 * childTextBrowser;

i2p::qt::Controller* i2pController;

Expand Down Expand Up @@ -442,6 +450,9 @@ public slots:
void addServerTunnelPushButtonReleased();
void addClientTunnelPushButtonReleased();

void anchorClickedHandler(const QUrl & link);
void backClickedFromChild();

private:
QString datadir;
QString confpath;
Expand Down
20 changes: 19 additions & 1 deletion qt/i2pd_qt/pagewithbackbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
#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();
}
10 changes: 7 additions & 3 deletions qt/i2pd_qt/pagewithbackbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ class PageWithBackButton : public QWidget
{
Q_OBJECT
public:
explicit PageWithBackButton(QWidget *parent = 0);
explicit PageWithBackButton(QWidget *parent, QWidget* child);

signals:

public slots:
void backReleased();

private slots:

void backReleasedSlot();
};

#endif // PAGEWITHBACKBUTTON_H
#endif // PAGEWITHBACKBUTTON_H
37 changes: 35 additions & 2 deletions qt/i2pd_qt/routercommandswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>711</width>
<height>300</height>
</rect>
</property>
Expand All @@ -24,13 +24,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<width>711</width>
<height>301</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
Expand All @@ -44,20 +53,38 @@
</item>
<item>
<widget class="QPushButton" name="runPeerTestPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Run peer test</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="declineTransitTunnelsPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Decline transit tunnels</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="acceptTransitTunnelsPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Accept transit tunnels</string>
</property>
Expand All @@ -68,6 +95,12 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Cancel graceful quit</string>
</property>
Expand Down
7 changes: 5 additions & 2 deletions qt/i2pd_qt/textbrowsertweaked1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "textbrowsertweaked1.h"

TextBrowserTweaked1::TextBrowserTweaked1()
TextBrowserTweaked1::TextBrowserTweaked1(QWidget * parent): QTextBrowser(parent)
{

}

/*void TextBrowserTweaked1::setSource(const QUrl & url) {
emit navigatedTo(url);
}*/
6 changes: 5 additions & 1 deletion qt/i2pd_qt/textbrowsertweaked1.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
#define TEXTBROWSERTWEAKED1_H

#include <QTextBrowser>
#include <QUrl>

class TextBrowserTweaked1 : public QTextBrowser
{
Q_OBJECT

public:
TextBrowserTweaked1();
TextBrowserTweaked1(QWidget * parent);
//virtual void setSource(const QUrl & url);

signals:
void mouseReleased();
//void navigatedTo(const QUrl & link);

protected:
void mouseReleaseEvent(QMouseEvent *event) {
QTextBrowser::mouseReleaseEvent(event);
emit mouseReleased();
}
};
Expand Down

0 comments on commit 07fe51f

Please sign in to comment.