Browse Source

qt ui - now all buttons have handlers

pull/925/head
hypnosis-i2p 7 years ago
parent
commit
856dda68db
  1. 16
      daemon/HTTPServer.cpp
  2. 9
      daemon/HTTPServer.h
  3. 69
      qt/i2pd_qt/mainwindow.cpp
  4. 27
      qt/i2pd_qt/mainwindow.h

16
daemon/HTTPServer.cpp

@ -273,7 +273,7 @@ namespace http {
s << "<b>Transit Tunnels:</b> " << std::to_string(transitTunnelCount) << "<br>\r\n"; s << "<b>Transit Tunnels:</b> " << std::to_string(transitTunnelCount) << "<br>\r\n";
} }
static void ShowLocalDestinations (std::stringstream& s) void ShowLocalDestinations (std::stringstream& s)
{ {
s << "<b>Local Destinations:</b><br>\r\n<br>\r\n"; s << "<b>Local Destinations:</b><br>\r\n<br>\r\n";
for (auto& it: i2p::client::context.GetDestinations ()) for (auto& it: i2p::client::context.GetDestinations ())
@ -399,7 +399,7 @@ namespace http {
ShowError(s, "I2CP is not enabled"); ShowError(s, "I2CP is not enabled");
} }
static void ShowLeasesSets(std::stringstream& s) void ShowLeasesSets(std::stringstream& s)
{ {
s << "<div id='leasesets'><b>LeaseSets (click on to show info):</b></div><br>\r\n"; s << "<div id='leasesets'><b>LeaseSets (click on to show info):</b></div><br>\r\n";
int counter = 1; int counter = 1;
@ -432,7 +432,7 @@ namespace http {
// end for each lease set // end for each lease set
} }
static void ShowTunnels (std::stringstream& s) void ShowTunnels (std::stringstream& s)
{ {
s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n"; s << "<b>Queue size:</b> " << i2p::tunnel::tunnels.GetQueueSize () << "<br>\r\n";
@ -454,7 +454,7 @@ namespace http {
s << "<br>\r\n"; s << "<br>\r\n";
} }
static void ShowCommands (std::stringstream& s, uint32_t token) void ShowCommands (std::stringstream& s, uint32_t token)
{ {
/* commands */ /* commands */
s << "<b>Router Commands</b><br>\r\n"; s << "<b>Router Commands</b><br>\r\n";
@ -476,7 +476,7 @@ namespace http {
s << " <a href=\"/?cmd=" << HTTP_COMMAND_SHUTDOWN_NOW << "&token=" << token << "\">Force shutdown</a><br>\r\n"; s << " <a href=\"/?cmd=" << HTTP_COMMAND_SHUTDOWN_NOW << "&token=" << token << "\">Force shutdown</a><br>\r\n";
} }
static void ShowTransitTunnels (std::stringstream& s) void ShowTransitTunnels (std::stringstream& s)
{ {
s << "<b>Transit tunnels:</b><br>\r\n<br>\r\n"; s << "<b>Transit tunnels:</b><br>\r\n<br>\r\n";
for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ()) for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
@ -491,7 +491,7 @@ namespace http {
} }
} }
static void ShowTransports (std::stringstream& s) void ShowTransports (std::stringstream& s)
{ {
s << "<b>Transports:</b><br>\r\n<br>\r\n"; s << "<b>Transports:</b><br>\r\n<br>\r\n";
auto ntcpServer = i2p::transport::transports.GetNTCPServer (); auto ntcpServer = i2p::transport::transports.GetNTCPServer ();
@ -577,7 +577,7 @@ namespace http {
} }
} }
static void ShowSAMSessions (std::stringstream& s) void ShowSAMSessions (std::stringstream& s)
{ {
auto sam = i2p::client::context.GetSAMBridge (); auto sam = i2p::client::context.GetSAMBridge ();
if (!sam) { if (!sam) {
@ -624,7 +624,7 @@ namespace http {
} }
} }
static void ShowI2PTunnels (std::stringstream& s) void ShowI2PTunnels (std::stringstream& s)
{ {
s << "<b>Client Tunnels:</b><br>\r\n<br>\r\n"; s << "<b>Client Tunnels:</b><br>\r\n<br>\r\n";
for (auto& it: i2p::client::context.GetClientTunnels ()) for (auto& it: i2p::client::context.GetClientTunnels ())

9
daemon/HTTPServer.h

@ -77,7 +77,16 @@ namespace http
boost::asio::ip::tcp::acceptor m_Acceptor; boost::asio::ip::tcp::acceptor m_Acceptor;
}; };
//all the below functions are also used by Qt GUI, see mainwindow.cpp -> getStatusPageHtml
void ShowStatus (std::stringstream& s, bool includeHiddenContent); void ShowStatus (std::stringstream& s, bool includeHiddenContent);
void ShowLocalDestinations (std::stringstream& s);
void ShowLeasesSets(std::stringstream& s);
void ShowTunnels (std::stringstream& s);
void ShowCommands (std::stringstream& s, uint32_t token);
void ShowTransitTunnels (std::stringstream& s);
void ShowTransports (std::stringstream& s);
void ShowSAMSessions (std::stringstream& s);
void ShowI2PTunnels (std::stringstream& s);
} // http } // http
} // i2p } // i2p

69
qt/i2pd_qt/mainwindow.cpp

@ -1,3 +1,4 @@
#include <assert.h>
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include "ui_statusbuttons.h" #include "ui_statusbuttons.h"
@ -85,11 +86,20 @@ MainWindow::MainWindow(QWidget *parent) :
textBrowser = new TextBrowserTweaked1(); textBrowser = new TextBrowserTweaked1();
ui->verticalLayout_2->addWidget(textBrowser); ui->verticalLayout_2->addWidget(textBrowser);
scheduleMainPageUpdates(); scheduleStatusPageUpdates();
QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage())); QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
showStatusMainPage(); showStatusMainPage();
QObject::connect(statusButtonsUI->mainPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage())); QObject::connect(statusButtonsUI->mainPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
QObject::connect(statusButtonsUI->routerCommandsPushButton, SIGNAL(released()), this, SLOT(showStatus_commands_Page()));
QObject::connect(statusButtonsUI->localDestinationsPushButton, SIGNAL(released()), this, SLOT(showStatus_local_destinations_Page()));
QObject::connect(statusButtonsUI->leasesetsPushButton, SIGNAL(released()), this, SLOT(showStatus_leasesets_Page()));
QObject::connect(statusButtonsUI->tunnelsPushButton, SIGNAL(released()), this, SLOT(showStatus_tunnels_Page()));
QObject::connect(statusButtonsUI->transitTunnelsPushButton, SIGNAL(released()), this, SLOT(showStatus_transit_tunnels_Page()));
QObject::connect(statusButtonsUI->transportsPushButton, SIGNAL(released()), this, SLOT(showStatus_transports_Page()));
QObject::connect(statusButtonsUI->i2pTunnelsPushButton, SIGNAL(released()), this, SLOT(showStatus_i2p_tunnels_Page()));
QObject::connect(statusButtonsUI->samSessionsPushButton, SIGNAL(released()), this, SLOT(showStatus_sam_sessions_Page()));
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()));
@ -250,7 +260,14 @@ MainWindow::MainWindow(QWidget *parent) :
//QMetaObject::connectSlotsByName(this); //QMetaObject::connectSlotsByName(this);
} }
void MainWindow::showStatusPage(){ui->stackedWidget->setCurrentIndex(0);setStatusButtonsVisible(true);} void MainWindow::showStatusPage(StatusPage newStatusPage){
ui->stackedWidget->setCurrentIndex(0);
setStatusButtonsVisible(true);
statusPage=newStatusPage;
showHiddenInfoStatusMainPage=false;
textBrowser->setHtml(getStatusPageHtml(false));
wasSelectingAtStatusMainPage=false;
}
void MainWindow::showSettingsPage(){ui->stackedWidget->setCurrentIndex(1);setStatusButtonsVisible(false);} void MainWindow::showSettingsPage(){ui->stackedWidget->setCurrentIndex(1);setStatusButtonsVisible(false);}
void MainWindow::showTunnelsPage(){ui->stackedWidget->setCurrentIndex(2);setStatusButtonsVisible(false);} void MainWindow::showTunnelsPage(){ui->stackedWidget->setCurrentIndex(2);setStatusButtonsVisible(false);}
void MainWindow::showRestartPage(){ui->stackedWidget->setCurrentIndex(3);setStatusButtonsVisible(false);} void MainWindow::showRestartPage(){ui->stackedWidget->setCurrentIndex(3);setStatusButtonsVisible(false);}
@ -261,27 +278,41 @@ void MainWindow::setStatusButtonsVisible(bool visible) {
} }
// see also: HTTPServer.cpp // see also: HTTPServer.cpp
QString MainWindow::getStatusMainPageHtml(bool showHiddenInfo) { QString MainWindow::getStatusPageHtml(bool showHiddenInfo) {
std::stringstream s; std::stringstream s;
i2p::http::ShowStatus (s, showHiddenInfo); switch (statusPage) {
case main_page: i2p::http::ShowStatus(s, showHiddenInfo);break;
case commands: i2p::http::ShowCommands(s, /*token=*/0); break;
case local_destinations: i2p::http::ShowLocalDestinations(s);break;
case leasesets: i2p::http::ShowLeasesSets(s); break;
case tunnels: i2p::http::ShowTunnels(s); break;
case transit_tunnels: i2p::http::ShowTransitTunnels(s); break;
case transports: i2p::http::ShowTransports(s); break;
case i2p_tunnels: i2p::http::ShowI2PTunnels(s); break;
case sam_sessions: i2p::http::ShowSAMSessions(s); break;
default: assert(false); break;
}
std::string str = s.str(); std::string str = s.str();
return QString::fromStdString(str); return QString::fromStdString(str);
} }
void MainWindow::showStatusMainPage() { void MainWindow::showStatusMainPage() { showStatusPage(StatusPage::main_page); }
showHiddenInfoStatusMainPage=false; void MainWindow::showStatus_commands_Page() { showStatusPage(StatusPage::commands); }
showStatusPage(); void MainWindow::showStatus_local_destinations_Page() { showStatusPage(StatusPage::local_destinations); }
textBrowser->setHtml(getStatusMainPageHtml(false)); void MainWindow::showStatus_leasesets_Page() { showStatusPage(StatusPage::leasesets); }
textBrowser->show(); void MainWindow::showStatus_tunnels_Page() { showStatusPage(StatusPage::tunnels); }
wasSelectingAtStatusMainPage=false; void MainWindow::showStatus_transit_tunnels_Page() { showStatusPage(StatusPage::transit_tunnels); }
} void MainWindow::showStatus_transports_Page() { showStatusPage(StatusPage::transports); }
void MainWindow::showStatus_i2p_tunnels_Page() { showStatusPage(StatusPage::i2p_tunnels); }
void MainWindow::showStatus_sam_sessions_Page() { showStatusPage(StatusPage::sam_sessions); }
void MainWindow::scheduleMainPageUpdates() { void MainWindow::scheduleStatusPageUpdates() {
statusMainPageUpdateTimer = new QTimer(this); statusPageUpdateTimer = new QTimer(this);
connect(statusMainPageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatusMainPage())); connect(statusPageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatusPage()));
statusMainPageUpdateTimer->start(10*1000/*millis*/); statusPageUpdateTimer->start(10*1000/*millis*/);
} }
void MainWindow::statusHtmlPageMouseReleased() { void MainWindow::statusHtmlPageMouseReleased() {
@ -290,16 +321,16 @@ void MainWindow::statusHtmlPageMouseReleased() {
if(!selection.isEmpty()&&!selection.isNull())return; if(!selection.isEmpty()&&!selection.isNull())return;
} }
showHiddenInfoStatusMainPage=!showHiddenInfoStatusMainPage; showHiddenInfoStatusMainPage=!showHiddenInfoStatusMainPage;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage)); textBrowser->setHtml(getStatusPageHtml(showHiddenInfoStatusMainPage));
} }
void MainWindow::statusHtmlPageSelectionChanged() { void MainWindow::statusHtmlPageSelectionChanged() {
wasSelectingAtStatusMainPage=true; wasSelectingAtStatusMainPage=true;
} }
void MainWindow::updateStatusMainPage() { void MainWindow::updateStatusPage() {
showHiddenInfoStatusMainPage=false; showHiddenInfoStatusMainPage=false;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage)); textBrowser->setHtml(getStatusPageHtml(showHiddenInfoStatusMainPage));
} }
@ -423,7 +454,7 @@ void MainWindow::handleGracefulQuitTimerEvent() {
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
qDebug("Destroying main window"); qDebug("Destroying main window");
delete statusMainPageUpdateTimer; delete statusPageUpdateTimer;
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();

27
qt/i2pd_qt/mainwindow.h

@ -335,7 +335,12 @@ public:
// void setVisible(bool visible); // void setVisible(bool visible);
//#endif //#endif
private:
enum StatusPage {main_page, commands, local_destinations, leasesets, tunnels, transit_tunnels,
transports, i2p_tunnels, sam_sessions};
private slots: private slots:
void handleQuitButton(); void handleQuitButton();
void handleGracefulQuitButton(); void handleGracefulQuitButton();
void handleDoRestartButton(); void handleDoRestartButton();
@ -345,11 +350,20 @@ private slots:
void iconActivated(QSystemTrayIcon::ActivationReason reason); void iconActivated(QSystemTrayIcon::ActivationReason reason);
void toggleVisibilitySlot(); void toggleVisibilitySlot();
#endif #endif
void showStatusMainPage(); void scheduleStatusPageUpdates();
void statusHtmlPageMouseReleased(); void statusHtmlPageMouseReleased();
void statusHtmlPageSelectionChanged(); void statusHtmlPageSelectionChanged();
void updateStatusMainPage(); void updateStatusPage();
void scheduleMainPageUpdates();
void showStatusMainPage();
void showStatus_commands_Page();
void showStatus_local_destinations_Page();
void showStatus_leasesets_Page();
void showStatus_tunnels_Page();
void showStatus_transit_tunnels_Page();
void showStatus_transports_Page();
void showStatus_i2p_tunnels_Page();
void showStatus_sam_sessions_Page();
void showSettingsPage(); void showSettingsPage();
void showTunnelsPage(); void showTunnelsPage();
@ -357,11 +371,12 @@ private slots:
void showQuitPage(); void showQuitPage();
private: private:
QTimer * statusMainPageUpdateTimer; StatusPage statusPage;
QTimer * statusPageUpdateTimer;
bool wasSelectingAtStatusMainPage; bool wasSelectingAtStatusMainPage;
bool showHiddenInfoStatusMainPage; bool showHiddenInfoStatusMainPage;
void showStatusPage(); void showStatusPage(StatusPage newStatusPage);
#ifndef ANDROID #ifndef ANDROID
void createActions(); void createActions();
void createTrayIcon(); void createTrayIcon();
@ -387,7 +402,7 @@ protected:
void setStatusButtonsVisible(bool visible); void setStatusButtonsVisible(bool visible);
QString getStatusMainPageHtml(bool showHiddenInfo); QString getStatusPageHtml(bool showHiddenInfo);
QList<MainWindowItem*> configItems; QList<MainWindowItem*> configItems;
NonGUIOptionItem* logOption; NonGUIOptionItem* logOption;

Loading…
Cancel
Save