Browse Source

qt: stream.kill hrefs done - step to completion of #914

pull/1606/head
user 4 years ago
parent
commit
0b084956e6
  1. 56
      qt/i2pd_qt/mainwindow.cpp
  2. 1
      qt/i2pd_qt/mainwindow.h

56
qt/i2pd_qt/mainwindow.cpp

@ -45,6 +45,7 @@ std::string programOptionsWriterCurrentSection;
MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *parent) : MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *parent) :
QMainWindow(parent) QMainWindow(parent)
,currentLocalDestinationB32("")
,logStream(logStream_) ,logStream(logStream_)
,delayedSaveManagerPtr(new DelayedSaveManagerImpl()) ,delayedSaveManagerPtr(new DelayedSaveManagerImpl())
,dataSerial(DelayedSaveManagerImpl::INITIAL_DATA_SERIAL) ,dataSerial(DelayedSaveManagerImpl::INITIAL_DATA_SERIAL)
@ -135,6 +136,7 @@ MainWindow::MainWindow(std::shared_ptr<std::iostream> logStream_, QWidget *paren
//childTextBrowser->setOpenExternalLinks(false); //childTextBrowser->setOpenExternalLinks(false);
childTextBrowser->setOpenLinks(false); childTextBrowser->setOpenLinks(false);
connect(textBrowser, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedHandler(const QUrl&))); connect(textBrowser, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedHandler(const QUrl&)));
connect(childTextBrowser, SIGNAL(anchorClicked(const QUrl&)), this, SLOT(anchorClickedHandler(const QUrl&)));
pageWithBackButton = new PageWithBackButton(this, childTextBrowser); pageWithBackButton = new PageWithBackButton(this, childTextBrowser);
ui->verticalLayout_2->addWidget(pageWithBackButton); ui->verticalLayout_2->addWidget(pageWithBackButton);
pageWithBackButton->hide(); pageWithBackButton->hide();
@ -992,20 +994,60 @@ void MainWindow::anchorClickedHandler(const QUrl & link) {
qDebug()<<debugStr; qDebug()<<debugStr;
//QMessageBox::information(this, "", debugStr); //QMessageBox::information(this, "", debugStr);
/* /?page=local_destination&b32=xx...xx */
QString str=link.toString(); QString str=link.toString();
#define LOCAL_DEST_B32_PREFIX "/?page=local_destination&b32=" std::map<std::string, std::string> params;
static size_t LOCAL_DEST_B32_PREFIX_SZ=QString(LOCAL_DEST_B32_PREFIX).size(); i2p::http::URL url;
if(str.startsWith(LOCAL_DEST_B32_PREFIX)) { url.parse(str.toStdString());
str = str.right(str.size()-LOCAL_DEST_B32_PREFIX_SZ); url.parse_query(params);
qDebug () << "b32:" << str; const std::string page = params["page"];
const std::string cmd = params["cmd"];
if(page == "local_destination") {
std::string b32 = params["b32"];
currentLocalDestinationB32 = b32;
pageWithBackButton->show(); pageWithBackButton->show();
textBrowser->hide(); textBrowser->hide();
std::stringstream s; std::stringstream s;
std::string strstd = str.toStdString(); std::string strstd = currentLocalDestinationB32;
i2p::http::ShowLocalDestination(s,strstd,0); i2p::http::ShowLocalDestination(s,strstd,0);
childTextBrowser->setHtml(QString::fromStdString(s.str())); childTextBrowser->setHtml(QString::fromStdString(s.str()));
} }
if(cmd == "closestream") {
std::string b32 = params["b32"];
uint32_t streamID = std::stoul(params["streamID"], nullptr);
i2p::data::IdentHash ident;
ident.FromBase32 (b32);
auto dest = i2p::client::context.FindLocalDestination (ident);
if (streamID) {
if (dest) {
if(dest->DeleteStream (streamID))
QMessageBox::information(
this,
QApplication::tr("Success"),
QApplication::tr("<HTML><b>SUCCESS</b>: Stream closed"));
else
QMessageBox::critical(
this,
QApplication::tr("Error"),
QApplication::tr("<HTML><b>ERROR</b>: Stream not found or already was closed"));
}
else
QMessageBox::critical(
this,
QApplication::tr("Error"),
QApplication::tr("<HTML><b>ERROR</b>: Destination not found"));
}
else
QMessageBox::critical(
this,
QApplication::tr("Error"),
QApplication::tr("<HTML><b>ERROR</b>: StreamID is null"));
std::stringstream s;
std::string strstd = currentLocalDestinationB32;
i2p::http::ShowLocalDestination(s,strstd,0);
childTextBrowser->setHtml(QString::fromStdString(s.str()));
}
} }
void MainWindow::backClickedFromChild() { void MainWindow::backClickedFromChild() {

1
qt/i2pd_qt/mainwindow.h

@ -410,6 +410,7 @@ class DelayedSaveManagerImpl;
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private: private:
std::string currentLocalDestinationB32;
std::shared_ptr<std::iostream> logStream; std::shared_ptr<std::iostream> logStream;
DelayedSaveManagerImpl* delayedSaveManagerPtr; DelayedSaveManagerImpl* delayedSaveManagerPtr;
DelayedSaveManager::DATA_SERIAL_TYPE dataSerial; DelayedSaveManager::DATA_SERIAL_TYPE dataSerial;

Loading…
Cancel
Save