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 { @@ -273,7 +273,7 @@ namespace http {
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";
for (auto& it: i2p::client::context.GetDestinations ())
@ -399,7 +399,7 @@ namespace http { @@ -399,7 +399,7 @@ namespace http {
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";
int counter = 1;
@ -432,7 +432,7 @@ namespace http { @@ -432,7 +432,7 @@ namespace http {
// 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";
@ -454,7 +454,7 @@ namespace http { @@ -454,7 +454,7 @@ namespace http {
s << "<br>\r\n";
}
static void ShowCommands (std::stringstream& s, uint32_t token)
void ShowCommands (std::stringstream& s, uint32_t token)
{
/* commands */
s << "<b>Router Commands</b><br>\r\n";
@ -476,7 +476,7 @@ namespace http { @@ -476,7 +476,7 @@ namespace http {
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";
for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
@ -491,7 +491,7 @@ namespace http { @@ -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";
auto ntcpServer = i2p::transport::transports.GetNTCPServer ();
@ -577,7 +577,7 @@ namespace http { @@ -577,7 +577,7 @@ namespace http {
}
}
static void ShowSAMSessions (std::stringstream& s)
void ShowSAMSessions (std::stringstream& s)
{
auto sam = i2p::client::context.GetSAMBridge ();
if (!sam) {
@ -624,7 +624,7 @@ namespace http { @@ -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";
for (auto& it: i2p::client::context.GetClientTunnels ())

9
daemon/HTTPServer.h

@ -77,7 +77,16 @@ namespace http @@ -77,7 +77,16 @@ namespace http
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 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
} // i2p

69
qt/i2pd_qt/mainwindow.cpp

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
#include <assert.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_statusbuttons.h"
@ -85,11 +86,20 @@ MainWindow::MainWindow(QWidget *parent) : @@ -85,11 +86,20 @@ MainWindow::MainWindow(QWidget *parent) :
textBrowser = new TextBrowserTweaked1();
ui->verticalLayout_2->addWidget(textBrowser);
scheduleMainPageUpdates();
scheduleStatusPageUpdates();
QObject::connect(ui->statusPagePushButton, SIGNAL(released()), this, SLOT(showStatusMainPage()));
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(selectionChanged()), this, SLOT(statusHtmlPageSelectionChanged()));
@ -250,7 +260,14 @@ MainWindow::MainWindow(QWidget *parent) : @@ -250,7 +260,14 @@ MainWindow::MainWindow(QWidget *parent) :
//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::showTunnelsPage(){ui->stackedWidget->setCurrentIndex(2);setStatusButtonsVisible(false);}
void MainWindow::showRestartPage(){ui->stackedWidget->setCurrentIndex(3);setStatusButtonsVisible(false);}
@ -261,27 +278,41 @@ void MainWindow::setStatusButtonsVisible(bool visible) { @@ -261,27 +278,41 @@ void MainWindow::setStatusButtonsVisible(bool visible) {
}
// see also: HTTPServer.cpp
QString MainWindow::getStatusMainPageHtml(bool showHiddenInfo) {
QString MainWindow::getStatusPageHtml(bool showHiddenInfo) {
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();
return QString::fromStdString(str);
}
void MainWindow::showStatusMainPage() {
showHiddenInfoStatusMainPage=false;
showStatusPage();
textBrowser->setHtml(getStatusMainPageHtml(false));
textBrowser->show();
wasSelectingAtStatusMainPage=false;
}
void MainWindow::showStatusMainPage() { showStatusPage(StatusPage::main_page); }
void MainWindow::showStatus_commands_Page() { showStatusPage(StatusPage::commands); }
void MainWindow::showStatus_local_destinations_Page() { showStatusPage(StatusPage::local_destinations); }
void MainWindow::showStatus_leasesets_Page() { showStatusPage(StatusPage::leasesets); }
void MainWindow::showStatus_tunnels_Page() { showStatusPage(StatusPage::tunnels); }
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() {
statusMainPageUpdateTimer = new QTimer(this);
connect(statusMainPageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatusMainPage()));
statusMainPageUpdateTimer->start(10*1000/*millis*/);
void MainWindow::scheduleStatusPageUpdates() {
statusPageUpdateTimer = new QTimer(this);
connect(statusPageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatusPage()));
statusPageUpdateTimer->start(10*1000/*millis*/);
}
void MainWindow::statusHtmlPageMouseReleased() {
@ -290,16 +321,16 @@ void MainWindow::statusHtmlPageMouseReleased() { @@ -290,16 +321,16 @@ void MainWindow::statusHtmlPageMouseReleased() {
if(!selection.isEmpty()&&!selection.isNull())return;
}
showHiddenInfoStatusMainPage=!showHiddenInfoStatusMainPage;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage));
textBrowser->setHtml(getStatusPageHtml(showHiddenInfoStatusMainPage));
}
void MainWindow::statusHtmlPageSelectionChanged() {
wasSelectingAtStatusMainPage=true;
}
void MainWindow::updateStatusMainPage() {
void MainWindow::updateStatusPage() {
showHiddenInfoStatusMainPage=false;
textBrowser->setHtml(getStatusMainPageHtml(showHiddenInfoStatusMainPage));
textBrowser->setHtml(getStatusPageHtml(showHiddenInfoStatusMainPage));
}
@ -423,7 +454,7 @@ void MainWindow::handleGracefulQuitTimerEvent() { @@ -423,7 +454,7 @@ void MainWindow::handleGracefulQuitTimerEvent() {
MainWindow::~MainWindow()
{
qDebug("Destroying main window");
delete statusMainPageUpdateTimer;
delete statusPageUpdateTimer;
for(QList<MainWindowItem*>::iterator it = configItems.begin(); it!= configItems.end(); ++it) {
MainWindowItem* item = *it;
item->deleteLater();

27
qt/i2pd_qt/mainwindow.h

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

Loading…
Cancel
Save