Browse Source

qt ui - status main page now works

pull/925/head
hypnosis-i2p 7 years ago
parent
commit
163cbcb89d
  1. 60
      daemon/HTTPServer.cpp
  2. 3
      daemon/HTTPServer.h
  3. 6
      qt/i2pd_qt/i2pd_qt.pro
  4. 66
      qt/i2pd_qt/mainwindow.cpp
  5. 22
      qt/i2pd_qt/mainwindow.h
  6. 62
      qt/i2pd_qt/mainwindow.ui
  7. 6
      qt/i2pd_qt/textbrowsertweaked1.cpp
  8. 22
      qt/i2pd_qt/textbrowsertweaked1.h

60
daemon/HTTPServer.cpp

@ -185,7 +185,7 @@ namespace http {
s << "<b>ERROR:</b>&nbsp;" << string << "<br>\r\n"; s << "<b>ERROR:</b>&nbsp;" << string << "<br>\r\n";
} }
static void ShowStatus (std::stringstream& s) void ShowStatus (std::stringstream& s, bool includeHiddenContent)
{ {
s << "<b>Uptime:</b> "; s << "<b>Uptime:</b> ";
ShowUptime(s, i2p::context.GetUptime ()); ShowUptime(s, i2p::context.GetUptime ());
@ -233,33 +233,35 @@ namespace http {
s << " (" << (double) i2p::transport::transports.GetTransitBandwidth () / 1024 << " KiB/s)<br>\r\n"; s << " (" << (double) i2p::transport::transports.GetTransitBandwidth () / 1024 << " KiB/s)<br>\r\n";
s << "<b>Data path:</b> " << i2p::fs::GetDataDir() << "<br>\r\n"; s << "<b>Data path:</b> " << i2p::fs::GetDataDir() << "<br>\r\n";
s << "<div class='slide'\r\n><label for='slide1'>Hidden content. Press on text to see.</label>\r\n<input type='checkbox' id='slide1'/>\r\n<p class='content'>\r\n"; s << "<div class='slide'\r\n><label for='slide1'>Hidden content. Press on text to see.</label>\r\n<input type='checkbox' id='slide1'/>\r\n<p class='content'>\r\n";
s << "<b>Router Ident:</b> " << i2p::context.GetRouterInfo().GetIdentHashBase64() << "<br>\r\n"; if(includeHiddenContent) {
s << "<b>Router Family:</b> " << i2p::context.GetRouterInfo().GetProperty("family") << "<br>\r\n"; s << "<b>Router Ident:</b> " << i2p::context.GetRouterInfo().GetIdentHashBase64() << "<br>\r\n";
s << "<b>Router Caps:</b> " << i2p::context.GetRouterInfo().GetProperty("caps") << "<br>\r\n"; s << "<b>Router Family:</b> " << i2p::context.GetRouterInfo().GetProperty("family") << "<br>\r\n";
s << "<b>Our external address:</b>" << "<br>\r\n" ; s << "<b>Router Caps:</b> " << i2p::context.GetRouterInfo().GetProperty("caps") << "<br>\r\n";
for (const auto& address : i2p::context.GetRouterInfo().GetAddresses()) s << "<b>Our external address:</b>" << "<br>\r\n" ;
{ for (const auto& address : i2p::context.GetRouterInfo().GetAddresses())
switch (address->transportStyle) {
{ switch (address->transportStyle)
case i2p::data::RouterInfo::eTransportNTCP: {
if (address->host.is_v6 ()) case i2p::data::RouterInfo::eTransportNTCP:
s << "NTCP6&nbsp;&nbsp;"; if (address->host.is_v6 ())
else s << "NTCP6&nbsp;&nbsp;";
s << "NTCP&nbsp;&nbsp;"; else
break; s << "NTCP&nbsp;&nbsp;";
case i2p::data::RouterInfo::eTransportSSU: break;
if (address->host.is_v6 ()) case i2p::data::RouterInfo::eTransportSSU:
s << "SSU6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; if (address->host.is_v6 ())
else s << "SSU6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
s << "SSU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; else
break; s << "SSU&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
default: break;
s << "Unknown&nbsp;&nbsp;"; default:
} s << "Unknown&nbsp;&nbsp;";
s << address->host.to_string() << ":" << address->port << "<br>\r\n"; }
} s << address->host.to_string() << ":" << address->port << "<br>\r\n";
s << "</p>\r\n</div>\r\n"; }
s << "<b>Routers:</b> " << i2p::data::netdb.GetNumRouters () << " "; }
s << "</p>\r\n</div>\r\n";
s << "<b>Routers:</b> " << i2p::data::netdb.GetNumRouters () << " ";
s << "<b>Floodfills:</b> " << i2p::data::netdb.GetNumFloodfills () << " "; s << "<b>Floodfills:</b> " << i2p::data::netdb.GetNumFloodfills () << " ";
s << "<b>LeaseSets:</b> " << i2p::data::netdb.GetNumLeaseSets () << "<br>\r\n"; s << "<b>LeaseSets:</b> " << i2p::data::netdb.GetNumLeaseSets () << "<br>\r\n";
@ -797,7 +799,7 @@ namespace http {
} else if (req.uri.find("cmd=") != std::string::npos) { } else if (req.uri.find("cmd=") != std::string::npos) {
HandleCommand (req, res, s); HandleCommand (req, res, s);
} else { } else {
ShowStatus (s); ShowStatus (s, true);
res.add_header("Refresh", "10"); res.add_header("Refresh", "10");
} }
ShowPageTail (s); ShowPageTail (s);

3
daemon/HTTPServer.h

@ -7,6 +7,7 @@
#include <map> #include <map>
#include <thread> #include <thread>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <sstream>
#include "HTTP.h" #include "HTTP.h"
namespace i2p namespace i2p
@ -75,6 +76,8 @@ namespace http
boost::asio::io_service::work m_Work; boost::asio::io_service::work m_Work;
boost::asio::ip::tcp::acceptor m_Acceptor; boost::asio::ip::tcp::acceptor m_Acceptor;
}; };
void ShowStatus (std::stringstream& s, bool includeHiddenContent);
} // http } // http
} // i2p } // i2p

6
qt/i2pd_qt/i2pd_qt.pro

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

66
qt/i2pd_qt/mainwindow.cpp

@ -1,6 +1,8 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "ui_statusbuttons.h" #include "ui_statusbuttons.h"
#include "ui_statushtmlpaneform.h"
#include <sstream>
#include <QMessageBox> #include <QMessageBox>
#include <QTimer> #include <QTimer>
#include <QFile> #include <QFile>
@ -10,6 +12,8 @@
#include "FS.h" #include "FS.h"
#include "Log.h" #include "Log.h"
#include "HTTPServer.h"
#ifndef ANDROID #ifndef ANDROID
# include <QtDebug> # include <QtDebug>
#endif #endif
@ -28,6 +32,8 @@ MainWindow::MainWindow(QWidget *parent) :
#ifndef ANDROID #ifndef ANDROID
,quitting(false) ,quitting(false)
#endif #endif
,wasSelectingAtStatusMainPage(false)
,showHiddenInfoStatusMainPage(false)
,ui(new Ui::MainWindow) ,ui(new Ui::MainWindow)
,statusButtonsUI(new Ui::StatusButtonsForm) ,statusButtonsUI(new Ui::StatusButtonsForm)
,i2pController(nullptr) ,i2pController(nullptr)
@ -40,6 +46,8 @@ MainWindow::MainWindow(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
statusButtonsUI->setupUi(ui->statusButtonsPane); statusButtonsUI->setupUi(ui->statusButtonsPane);
//,statusHtmlUI(new Ui::StatusHtmlPaneForm)
//statusHtmlUI->setupUi(lastStatusWidgetui->statusWidget);
ui->statusButtonsPane->setFixedSize(171,300); ui->statusButtonsPane->setFixedSize(171,300);
ui->verticalLayout->setGeometry(QRect(0,0,171,ui->verticalLayout->geometry().height())); ui->verticalLayout->setGeometry(QRect(0,0,171,ui->verticalLayout->geometry().height()));
//ui->statusButtonsPane->adjustSize(); //ui->statusButtonsPane->adjustSize();
@ -75,8 +83,17 @@ MainWindow::MainWindow(QWidget *parent) :
createTrayIcon(); createTrayIcon();
#endif #endif
QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusPage())); textBrowser = new TextBrowserTweaked1();
setStatusButtonsVisible(true); ui->verticalLayout_2->addWidget(textBrowser);
scheduleMainPageUpdates();
QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
showStatusMainPage();
QObject::connect(statusButtonsUI->mainPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
QObject::connect(textBrowser, SIGNAL(mouseReleased()), this, SLOT(statusHtmlPageMouseReleased()));
QObject::connect(textBrowser, SIGNAL(selectionChanged()), this, SLOT(statusHtmlPageSelectionChanged()));
QObject::connect(ui->settingsPagePushButton, SIGNAL(released()), this, SLOT(showSettingsPage())); QObject::connect(ui->settingsPagePushButton, SIGNAL(released()), this, SLOT(showSettingsPage()));
QObject::connect(ui->tunnelsPagePushButton, SIGNAL(released()), this, SLOT(showTunnelsPage())); QObject::connect(ui->tunnelsPagePushButton, SIGNAL(released()), this, SLOT(showTunnelsPage()));
@ -243,6 +260,49 @@ void MainWindow::setStatusButtonsVisible(bool visible) {
ui->statusButtonsPane->setVisible(visible); ui->statusButtonsPane->setVisible(visible);
} }
// see also: HTTPServer.cpp
QString MainWindow::getStatusMainPageHtml(bool showHiddenInfo) {
std::stringstream s;
i2p::http::ShowStatus (s, showHiddenInfo);
std::string str = s.str();
return QString::fromStdString(str);
}
void MainWindow::showStatusMainPage() {
showHiddenInfoStatusMainPage=false;
showStatusPage();
textBrowser->setHtml(getStatusMainPageHtml(false));
textBrowser->show();
wasSelectingAtStatusMainPage=false;
}
void MainWindow::scheduleMainPageUpdates() {
statusMainPageUpdateTimer = new QTimer(this);
connect(statusMainPageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatusMainPage()));
statusMainPageUpdateTimer->start(10*1000/*millis*/);
}
void MainWindow::statusHtmlPageMouseReleased() {
if(wasSelectingAtStatusMainPage){
QString selection = textBrowser->textCursor().selectedText();
if(!selection.isEmpty()&&!selection.isNull())return;
}
showHiddenInfoStatusMainPage=!showHiddenInfoStatusMainPage;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage));
}
void MainWindow::statusHtmlPageSelectionChanged() {
wasSelectingAtStatusMainPage=true;
}
void MainWindow::updateStatusMainPage() {
showHiddenInfoStatusMainPage=false;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage));
}
//TODO //TODO
void MainWindow::resizeEvent(QResizeEvent *event) void MainWindow::resizeEvent(QResizeEvent *event)
{ {
@ -363,6 +423,7 @@ void MainWindow::handleGracefulQuitTimerEvent() {
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
qDebug("Destroying main window"); qDebug("Destroying main window");
delete statusMainPageUpdateTimer;
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) { for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
MainWindowItem* item = *it; MainWindowItem* item = *it;
item->deleteLater(); item->deleteLater();
@ -642,3 +703,4 @@ void MainWindow::addClientTunnelPushButtonReleased() {
void MainWindow::setI2PController(i2p::qt::Controller* controller_) { void MainWindow::setI2PController(i2p::qt::Controller* controller_) {
this->i2pController = controller_; this->i2pController = controller_;
} }

22
qt/i2pd_qt/mainwindow.h

@ -40,6 +40,7 @@
#include "ServerTunnelPane.h" #include "ServerTunnelPane.h"
#include "ClientTunnelPane.h" #include "ClientTunnelPane.h"
#include "TunnelConfig.h" #include "TunnelConfig.h"
#include "textbrowsertweaked1.h"
#include "Config.h" #include "Config.h"
#include "FS.h" #include "FS.h"
@ -306,8 +307,9 @@ public:
}; };
namespace Ui { namespace Ui {
class MainWindow; class MainWindow;
class StatusButtonsForm; class StatusButtonsForm;
class StatusHtmlPaneForm;
} }
using namespace i2p::client; using namespace i2p::client;
@ -343,13 +345,23 @@ private slots:
void iconActivated(QSystemTrayIcon::ActivationReason reason); void iconActivated(QSystemTrayIcon::ActivationReason reason);
void toggleVisibilitySlot(); void toggleVisibilitySlot();
#endif #endif
void showStatusPage(); void showStatusMainPage();
void statusHtmlPageMouseReleased();
void statusHtmlPageSelectionChanged();
void updateStatusMainPage();
void scheduleMainPageUpdates();
void showSettingsPage(); void showSettingsPage();
void showTunnelsPage(); void showTunnelsPage();
void showRestartPage(); void showRestartPage();
void showQuitPage(); void showQuitPage();
private: private:
QTimer * statusMainPageUpdateTimer;
bool wasSelectingAtStatusMainPage;
bool showHiddenInfoStatusMainPage;
void showStatusPage();
#ifndef ANDROID #ifndef ANDROID
void createActions(); void createActions();
void createTrayIcon(); void createTrayIcon();
@ -362,6 +374,8 @@ private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
Ui::StatusButtonsForm* statusButtonsUI; Ui::StatusButtonsForm* statusButtonsUI;
TextBrowserTweaked1 * textBrowser;
i2p::qt::Controller* i2pController; i2p::qt::Controller* i2pController;
protected: protected:
@ -373,6 +387,8 @@ protected:
void setStatusButtonsVisible(bool visible); void setStatusButtonsVisible(bool visible);
QString getStatusMainPageHtml(bool showHiddenInfo);
QList<MainWindowItem*> configItems; QList<MainWindowItem*> configItems;
NonGUIOptionItem* logOption; NonGUIOptionItem* logOption;
NonGUIOptionItem* daemonOption; NonGUIOptionItem* daemonOption;

62
qt/i2pd_qt/mainwindow.ui

@ -6,19 +6,19 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>904</width> <width>908</width>
<height>550</height> <height>550</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>904</width> <width>908</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>950</width> <width>908</width>
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
@ -34,13 +34,13 @@
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>904</width> <width>908</width>
<height>0</height> <height>550</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>908</width>
<height>550</height> <height>550</height>
</size> </size>
</property> </property>
@ -49,8 +49,8 @@
<rect> <rect>
<x>10</x> <x>10</x>
<y>10</y> <y>10</y>
<width>931</width> <width>888</width>
<height>715</height> <height>530</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
@ -183,26 +183,32 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>713</width>
<height>713</height> <height>713</height>
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="statusPage"> <widget class="QWidget" name="statusPage">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="verticalLayoutWidget_5"> <widget class="QWidget" name="verticalLayoutWidget_5">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>686</width> <width>713</width>
<height>531</height> <height>531</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetMinAndMaxSize</enum> <enum>QLayout::SetMaximumSize</enum>
</property> </property>
<item> <item>
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
@ -217,17 +223,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="verticalSpacer_4"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="orientation"> <property name="sizeConstraint">
<enum>Qt::Vertical</enum> <enum>QLayout::SetMaximumSize</enum>
</property> </property>
<property name="sizeHint" stdset="0"> </layout>
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -244,7 +244,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>706</width> <width>711</width>
<height>531</height> <height>531</height>
</rect> </rect>
</property> </property>
@ -283,8 +283,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>684</width> <width>80</width>
<height>496</height> <height>26</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -3045,7 +3045,7 @@ Comma separated list of base64 identities:</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>706</width> <width>711</width>
<height>531</height> <height>531</height>
</rect> </rect>
</property> </property>
@ -3110,7 +3110,7 @@ Comma separated list of base64 identities:</string>
<widget class="QWidget" name="tunnelsScrollAreaWidgetContents"> <widget class="QWidget" name="tunnelsScrollAreaWidgetContents">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>-18</x> <x>0</x>
<y>0</y> <y>0</y>
<width>699</width> <width>699</width>
<height>425</height> <height>425</height>
@ -3128,8 +3128,8 @@ Comma separated list of base64 identities:</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>686</width> <width>711</width>
<height>496</height> <height>531</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -3183,8 +3183,8 @@ Comma separated list of base64 identities:</string>
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>686</width> <width>711</width>
<height>496</height> <height>531</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="quitPageVerticalLayout"> <layout class="QVBoxLayout" name="quitPageVerticalLayout">

6
qt/i2pd_qt/textbrowsertweaked1.cpp

@ -0,0 +1,6 @@
#include "textbrowsertweaked1.h"
TextBrowserTweaked1::TextBrowserTweaked1()
{
}

22
qt/i2pd_qt/textbrowsertweaked1.h

@ -0,0 +1,22 @@
#ifndef TEXTBROWSERTWEAKED1_H
#define TEXTBROWSERTWEAKED1_H
#include <QTextBrowser>
class TextBrowserTweaked1 : public QTextBrowser
{
Q_OBJECT
public:
TextBrowserTweaked1();
signals:
void mouseReleased();
protected:
void mouseReleaseEvent(QMouseEvent *event) {
emit mouseReleased();
}
};
#endif // TEXTBROWSERTWEAKED1_H
Loading…
Cancel
Save