diff options
author | Michele Calgaro <[email protected]> | 2025-03-02 18:37:22 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2025-03-06 12:31:12 +0900 |
commit | 44ef0bd5fe47a43e47aec5f7981b6c1d728dd9a8 (patch) | |
tree | 2b29e921a9bccea53444ed9bbed06a25a5fe20cc /src/apps/ktupnptest | |
parent | d1f24dae035c506d945ca13f2be398aa0a4de8cc (diff) | |
download | ktorrent-master.tar.gz ktorrent-master.zip |
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/apps/ktupnptest')
-rw-r--r-- | src/apps/ktupnptest/Makefile.am | 10 | ||||
-rw-r--r-- | src/apps/ktupnptest/main.cpp | 97 | ||||
-rw-r--r-- | src/apps/ktupnptest/mainwidget.ui | 75 | ||||
-rw-r--r-- | src/apps/ktupnptest/upnptestapp.cpp | 87 | ||||
-rw-r--r-- | src/apps/ktupnptest/upnptestapp.h | 59 |
5 files changed, 328 insertions, 0 deletions
diff --git a/src/apps/ktupnptest/Makefile.am b/src/apps/ktupnptest/Makefile.am new file mode 100644 index 0000000..9920c54 --- /dev/null +++ b/src/apps/ktupnptest/Makefile.am @@ -0,0 +1,10 @@ +INCLUDES = -I$(srcdir)/../../libktorrent -I$(srcdir)/../.. $(all_includes) +METASOURCES = AUTO +bin_PROGRAMS = ktupnptest + +ktupnptest_SOURCES = main.cpp upnptestapp.cpp mainwidget.ui +ktupnptest_LDADD = ../../plugins/upnp/libktupnp.la \ + ../../libktorrent/libktorrent.la $(LIB_TDEIO) +ktupnptest_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor +noinst_HEADERS = upnptestapp.h +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/src/apps/ktupnptest/main.cpp b/src/apps/ktupnptest/main.cpp new file mode 100644 index 0000000..2493f36 --- /dev/null +++ b/src/apps/ktupnptest/main.cpp @@ -0,0 +1,97 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <stdio.h> +#include <stdlib.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <tdecmdlineargs.h> +#include <libktorrent/functions.h> + + +#include "upnptestapp.h" + +using namespace kt; +using namespace bt; + +static const char description[] = + I18N_NOOP("A TDE KPart Application"); + +static const char version[] = "1.3dev"; + +static TDECmdLineOptions options[] = +{ +// { "+[URL]", I18N_NOOP( "Document to open" ), 0 }, + TDECmdLineLastOption +}; + + + + +int main(int argc,char** argv) +{ + Globals::instance().setDebugMode(true); + TDEAboutData about("ktupnptest", I18N_NOOP("KTUPnPTest"), version, description, + TDEAboutData::License_GPL, "(C) 2005 Joris Guisson", 0); + TDECmdLineArgs::init(argc, argv,&about); + TDECmdLineArgs::addCmdLineOptions( options ); + TDEApplication app; + Globals::instance().initLog(kt::DataDir() + "ktupnptest.log"); + UPnPTestApp* mwnd = new UPnPTestApp(); + + app.setMainWidget(mwnd); + mwnd->show(); + app.exec(); + Globals::cleanup(); + return 0; + + /* + if (argc >= 2) + { + kt::UPnPRouter router(TQString(),"http://foobar.com"); + kt::UPnPDescriptionParser dp; + + if (!dp.parse(argv[1],&router)) + { + Out() << "Cannot parse " << TQString(argv[1]) << endl; + } + else + { + Out() << "Succesfully parsed the UPnP contents" << endl; + router.debugPrintData(); + } + } + + + Out() << "Doing second test" << endl; + UPnPMCastSocket mcast; + UPnPRouter* r = mcast.parseResponse(TQCString(test_ps)); + if (r) + { + Out() << "Succesfully parsed test_ps" << endl; + delete r; + } + else + { + Out() << "Failed to parse test_ps" << endl; + } + */ + +} diff --git a/src/apps/ktupnptest/mainwidget.ui b/src/apps/ktupnptest/mainwidget.ui new file mode 100644 index 0000000..7faa40d --- /dev/null +++ b/src/apps/ktupnptest/mainwidget.ui @@ -0,0 +1,75 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>MainWidget</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>MainWidget</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>600</width> + <height>480</height> + </rect> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQTextBrowser"> + <property name="name"> + <cstring>output</cstring> + </property> + </widget> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>layout1</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <spacer> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Horizontal</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>61</width> + <height>20</height> + </size> + </property> + </spacer> + <widget class="KPushButton"> + <property name="name"> + <cstring>test_btn</cstring> + </property> + <property name="text"> + <string>Test</string> + </property> + </widget> + <widget class="KPushButton"> + <property name="name"> + <cstring>close_btn</cstring> + </property> + <property name="text"> + <string>Close</string> + </property> + </widget> + </hbox> + </widget> + </vbox> +</widget> +<customwidgets> +</customwidgets> +<layoutdefaults spacing="6" margin="11"/> +<includes> + <include location="global" impldecl="in implementation">kpushbutton.h</include> +</includes> +</UI> diff --git a/src/apps/ktupnptest/upnptestapp.cpp b/src/apps/ktupnptest/upnptestapp.cpp new file mode 100644 index 0000000..a6e0852 --- /dev/null +++ b/src/apps/ktupnptest/upnptestapp.cpp @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include <kpushbutton.h> +#include <tdelocale.h> +#include <tdeapplication.h> +#include <tdemessagebox.h> +#include <tqtextbrowser.h> +#include <util/error.h> +#include "upnptestapp.h" +#include "mainwidget.h" + +using namespace bt; +using namespace kt; + +UPnPTestApp::UPnPTestApp(TQWidget *parent, const char *name) + : TDEMainWindow(parent, name) +{ + sock = new UPnPMCastSocket(true); + connect(sock,TQ_SIGNAL(discovered( UPnPRouter* )),this,TQ_SLOT(discovered( UPnPRouter* ))); + mwnd = new MainWidget(this); + setCentralWidget(mwnd); + connect(mwnd->test_btn,TQ_SIGNAL(clicked()),this,TQ_SLOT(onTestBtn())); + connect(mwnd->close_btn,TQ_SIGNAL(clicked()),this,TQ_SLOT(onCloseBtn())); + bt::Log & lg = bt::Globals::instance().getLog(0); + lg.addMonitor(this); + Out() << "UPnPTestApp started up !" << endl; +} + + +UPnPTestApp::~UPnPTestApp() +{ + sock->deleteLater(); +} + +void UPnPTestApp::discovered(kt::UPnPRouter* router) +{ + try + { + router->forward(net::Port(9999,net::TCP,false)); + } + catch (Error & e) + { + KMessageBox::error(this,e.toString()); + } +} + +void UPnPTestApp::onTestBtn() +{ + sock->discover(); +} + +void UPnPTestApp::onCloseBtn() +{ + tdeApp->quit(); +} + +bool UPnPTestApp::queryExit() +{ + bt::Log & lg = bt::Globals::instance().getLog(0); + lg.removeMonitor(this); + return true; +} + +void UPnPTestApp::message(const TQString& line, unsigned int arg) +{ + mwnd->output->append(line); +} + + +#include "upnptestapp.moc" diff --git a/src/apps/ktupnptest/upnptestapp.h b/src/apps/ktupnptest/upnptestapp.h new file mode 100644 index 0000000..7c5ac98 --- /dev/null +++ b/src/apps/ktupnptest/upnptestapp.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef UPNPTESTAPP_H +#define UPNPTESTAPP_H + +#include <tdemainwindow.h> +#include <libktorrent/util/log.h> +#include <libktorrent/torrent/globals.h> +#include <plugins/upnp/upnprouter.h> +#include <plugins/upnp/upnpdescriptionparser.h> +#include <plugins/upnp/upnpmcastsocket.h> +#include <interfaces/logmonitorinterface.h> + +class MainWidget; + +using kt::UPnPRouter; + +/** + @author Joris Guisson <[email protected]> +*/ +class UPnPTestApp : public TDEMainWindow, public kt::LogMonitorInterface +{ + TQ_OBJECT + +public: + UPnPTestApp(TQWidget *parent = 0, const char *name = 0); + virtual ~UPnPTestApp(); + + virtual void message(const TQString& line, unsigned int arg); + bool queryExit(); + +private slots: + void discovered(UPnPRouter* router); + void onTestBtn(); + void onCloseBtn(); + +private: + kt::UPnPMCastSocket* sock; + MainWidget* mwnd; +}; + +#endif |