Browse Source

some qt gui changes

pull/925/head
hypnosis-i2p 7 years ago
parent
commit
07fe51fa25
  1. 2
      daemon/HTTPServer.cpp
  2. 1
      daemon/HTTPServer.h
  3. 6
      qt/i2pd_qt/i2pd_qt.pro
  4. 62
      qt/i2pd_qt/mainwindow.cpp
  5. 11
      qt/i2pd_qt/mainwindow.h
  6. 20
      qt/i2pd_qt/pagewithbackbutton.cpp
  7. 8
      qt/i2pd_qt/pagewithbackbutton.h
  8. 37
      qt/i2pd_qt/routercommandswidget.ui
  9. 7
      qt/i2pd_qt/textbrowsertweaked1.cpp
  10. 6
      qt/i2pd_qt/textbrowsertweaked1.h

2
daemon/HTTPServer.cpp

@ -341,7 +341,7 @@ namespace http { @@ -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;

1
daemon/HTTPServer.h

@ -86,6 +86,7 @@ namespace http @@ -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

6
qt/i2pd_qt/i2pd_qt.pro

@ -88,7 +88,8 @@ SOURCES += DaemonQT.cpp mainwindow.cpp \ @@ -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)
@ -168,7 +169,8 @@ HEADERS += DaemonQT.h mainwindow.h \ @@ -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

62
qt/i2pd_qt/mainwindow.cpp

@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
#include "FS.h"
#include "Log.h"
#include "RouterContext.h"
#include "Transports.h"
#include "HTTPServer.h"
@ -60,7 +61,7 @@ MainWindow::MainWindow(QWidget *parent) : @@ -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();
@ -88,8 +89,21 @@ MainWindow::MainWindow(QWidget *parent) : @@ -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()));
@ -107,6 +121,9 @@ MainWindow::MainWindow(QWidget *parent) : @@ -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()));
@ -279,9 +296,11 @@ void MainWindow::showStatusPage(StatusPage newStatusPage){ @@ -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;
@ -299,6 +318,8 @@ void MainWindow::setStatusButtonsVisible(bool visible) { @@ -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;
@ -753,3 +774,40 @@ void MainWindow::setI2PController(i2p::qt::Controller* controller_) { @@ -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
qt/i2pd_qt/mainwindow.h

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

20
qt/i2pd_qt/pagewithbackbutton.cpp

@ -1,6 +1,24 @@ @@ -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();
}

8
qt/i2pd_qt/pagewithbackbutton.h

@ -7,11 +7,15 @@ class PageWithBackButton : public QWidget @@ -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

37
qt/i2pd_qt/routercommandswidget.ui

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>711</width>
<height>300</height>
</rect>
</property>
@ -24,13 +24,22 @@ @@ -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>
@ -44,6 +53,12 @@ @@ -44,6 +53,12 @@
</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>
@ -51,6 +66,12 @@ @@ -51,6 +66,12 @@
</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>
@ -58,6 +79,12 @@ @@ -58,6 +79,12 @@
</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>
@ -68,6 +95,12 @@ @@ -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>

7
qt/i2pd_qt/textbrowsertweaked1.cpp

@ -1,6 +1,9 @@ @@ -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
qt/i2pd_qt/textbrowsertweaked1.h

@ -2,19 +2,23 @@ @@ -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();
}
};

Loading…
Cancel
Save