Changeset View
Changeset View
Standalone View
Standalone View
plugins/htmlinterface/htmlinterfaceplugin.cpp
Show All 23 Lines | |||||
24 | 24 | | |||
25 | #include <KActionCollection> | 25 | #include <KActionCollection> | ||
26 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
27 | #include <KMainWindow> | 27 | #include <KMainWindow> | ||
28 | #include <KPluginFactory> | 28 | #include <KPluginFactory> | ||
29 | #include <QThread> | 29 | #include <QThread> | ||
30 | 30 | | |||
31 | #include "htmlinterfaceplugin.h" | 31 | #include "htmlinterfaceplugin.h" | ||
32 | // #include <util/fileops.h> | | |||
33 | // #include <interfaces/guiinterface.h> | | |||
34 | #include <interfaces/coreinterface.h> | 32 | #include <interfaces/coreinterface.h> | ||
35 | #include <interfaces/torrentinterface.h> | 33 | #include <interfaces/torrentinterface.h> | ||
36 | // #include <interfaces/torrentfileinterface.h> | | |||
37 | #include <torrent/queuemanager.h> | 34 | #include <torrent/queuemanager.h> | ||
38 | #include "mongoose.h" | | |||
39 | // #include "htmlinterfacemanager.h" | | |||
40 | // #include "htmlinterfacedialog.h" | | |||
41 | #include "webserver.h" | 35 | #include "webserver.h" | ||
42 | 36 | | |||
43 | 37 | | |||
44 | 38 | | |||
45 | K_PLUGIN_FACTORY_WITH_JSON(ktorrent_htmlinterface, "ktorrent_htmlinterface.json", registerPlugin<kt::HtmlInterfacePlugin>();) | 39 | K_PLUGIN_FACTORY_WITH_JSON(ktorrent_htmlinterface, "ktorrent_htmlinterface.json", registerPlugin<kt::HtmlInterfacePlugin>();) | ||
46 | 40 | | |||
47 | using namespace bt; | 41 | using namespace bt; | ||
48 | using namespace std; | 42 | using namespace std; | ||
49 | 43 | | |||
50 | namespace kt | 44 | namespace kt | ||
51 | { | 45 | { | ||
52 | HtmlInterfacePlugin::HtmlInterfacePlugin(QObject* parent, const QVariantList &args): Plugin(parent) | 46 | HtmlInterfacePlugin::HtmlInterfacePlugin(QObject* parent, const QVariantList &args): Plugin(parent) | ||
53 | { | 47 | { | ||
54 | Q_UNUSED(args); | 48 | Q_UNUSED(args); | ||
55 | qInfo("I've still been constructed!"); | 49 | qInfo("I've still been constructed!"); | ||
56 | // download_order_action = new QAction(QIcon::fromTheme(QStringLiteral("view-sort-ascending")), i18n("File Download Order"), this); | | |||
57 | // connect(download_order_action, &QAction::triggered, this, &HtmlInterfacePlugin::showHtmlInterfaceDialog); | | |||
58 | // actionCollection()->addAction(QStringLiteral("download_order"), download_order_action); | | |||
59 | // setXMLFile(QStringLiteral("ktorrent_htmlinterfaceui.rc")); | | |||
60 | // managers.setAutoDelete(true); | | |||
61 | } | 50 | } | ||
62 | 51 | | |||
63 | 52 | | |||
64 | HtmlInterfacePlugin::~HtmlInterfacePlugin() | 53 | HtmlInterfacePlugin::~HtmlInterfacePlugin() | ||
65 | { | 54 | { | ||
66 | } | 55 | } | ||
67 | 56 | | |||
68 | 57 | | |||
69 | bool HtmlInterfacePlugin::versionCheck(const QString& version) const | 58 | bool HtmlInterfacePlugin::versionCheck(const QString& version) const | ||
70 | { | 59 | { | ||
71 | return version == QStringLiteral(KT_VERSION_MACRO); | 60 | return version == QStringLiteral(KT_VERSION_MACRO); | ||
72 | } | 61 | } | ||
73 | 62 | | |||
74 | void HtmlInterfacePlugin::load() | 63 | void HtmlInterfacePlugin::load() | ||
75 | { | 64 | { | ||
76 | qInfo("I've been loaded"); | 65 | qInfo("I've been loaded"); | ||
77 | HtmlInterfacePlugin::instance = this; | 66 | ws = new WebServer(getCore()); | ||
78 | thread = new QThread; | 67 | ws->process(); | ||
79 | worker = new WebServer(getCore()); | | |||
80 | worker->moveToThread(thread); | | |||
81 | // connect(worker, SIGNAL (error(QString)), this, SLOT (errorString(QString))); | | |||
82 | connect(thread, SIGNAL (started()), worker, SLOT (process())); | | |||
83 | connect(worker, SIGNAL (finished()), thread, SLOT (quit())); | | |||
84 | connect(worker, SIGNAL (finished()), worker, SLOT (deleteLater())); | | |||
85 | connect(thread, SIGNAL (finished()), thread, SLOT (deleteLater())); | | |||
86 | thread->start(); | | |||
87 | // TorrentActivityInterface* ta = getGUI()->getTorrentActivity(); | | |||
88 | // ta->addViewListener(this); | | |||
89 | // connect(getCore(), SIGNAL(torrentAdded(bt::TorrentInterface*)), this, SLOT(torrentAdded(bt::TorrentInterface*))); | | |||
90 | // connect(getCore(), SIGNAL(torrentRemoved(bt::TorrentInterface*)), this, SLOT(torrentRemoved(bt::TorrentInterface*))); | | |||
91 | // currentTorrentChanged(ta->getCurrentTorrent()); | | |||
92 | // | | |||
93 | // kt::QueueManager* qman = getCore()->getQueueManager(); | | |||
94 | // for (kt::QueueManager::iterator i = qman->begin(); i != qman->end(); i++) | | |||
95 | // torrentAdded(*i); | | |||
96 | } | 68 | } | ||
97 | 69 | | |||
98 | void HtmlInterfacePlugin::unload() | 70 | void HtmlInterfacePlugin::unload() | ||
99 | { | 71 | { | ||
100 | // TorrentActivityInterface* ta = getGUI()->getTorrentActivity(); | 72 | delete ws; | ||
101 | // ta->removeViewListener(this); | 73 | } | ||
102 | // disconnect(getCore(), SIGNAL(torrentAdded(bt::TorrentInterface*)), this, SLOT(torrentAdded(bt::TorrentInterface*))); | 74 | | ||
103 | // disconnect(getCore(), SIGNAL(torrentRemoved(bt::TorrentInterface*)), this, SLOT(torrentRemoved(bt::TorrentInterface*))); | | |||
104 | // managers.clear(); | | |||
105 | } | | |||
106 | | ||||
107 | // void HtmlInterfacePlugin::showHtmlInterfaceDialog() | | |||
108 | // { | | |||
109 | // bt::TorrentInterface* tor = getGUI()->getTorrentActivity()->getCurrentTorrent(); | | |||
110 | // if (!tor || !tor->getStats().multi_file_torrent) | | |||
111 | // return; | | |||
112 | // | | |||
113 | // HtmlInterfaceDialog dlg(this, tor, getGUI()->getMainWindow()); | | |||
114 | // dlg.exec(); | | |||
115 | // } | | |||
116 | // | | |||
117 | void HtmlInterfacePlugin::currentTorrentChanged(bt::TorrentInterface* tc) | 75 | void HtmlInterfacePlugin::currentTorrentChanged(bt::TorrentInterface* tc) | ||
118 | { | 76 | { | ||
119 | // download_order_action->setEnabled(tc && tc->getStats().multi_file_torrent); | | |||
120 | } | 77 | } | ||
121 | // | 78 | | ||
122 | // HtmlInterfaceManager* HtmlInterfacePlugin::manager(bt::TorrentInterface* tc) | | |||
123 | // { | | |||
124 | // return managers.find(tc);Aumyenne | | |||
125 | | ||||
126 | // } | | |||
127 | // | | |||
128 | // HtmlInterfaceManager* HtmlInterfacePlugin::createManager(bt::TorrentInterface* tc) | | |||
129 | // { | | |||
130 | // HtmlInterfaceManager* m = manager(tc); | | |||
131 | // if (m) | | |||
132 | // return m; | | |||
133 | // | | |||
134 | // m = new HtmlInterfaceManager(tc); | | |||
135 | // managers.insert(tc, m); | | |||
136 | // return m; | | |||
137 | // } | | |||
138 | // | | |||
139 | // void HtmlInterfacePlugin::destroyManager(bt::TorrentInterface* tc) | | |||
140 | // { | | |||
141 | // managers.erase(tc); | | |||
142 | // } | | |||
143 | // | | |||
144 | // void HtmlInterfacePlugin::torrentAdded(bt::TorrentInterface* tc) | | |||
145 | // { | | |||
146 | // if (bt::Exists(tc->getTorDir() + QStringLiteral("download_order"))) | | |||
147 | // { | | |||
148 | // HtmlInterfaceManager* m = createManager(tc); | | |||
149 | // m->load(); | | |||
150 | // m->update(); | | |||
151 | // connect(tc, SIGNAL(chunkDownloaded(bt::TorrentInterface*, bt::Uint32)), | | |||
152 | // m, SLOT(chunkDownloaded(bt::TorrentInterface*, bt::Uint32))); | | |||
153 | // } | | |||
154 | // } | | |||
155 | // | | |||
156 | // void HtmlInterfacePlugin::torrentRemoved(bt::TorrentInterface* tc) | | |||
157 | // { | | |||
158 | // managers.erase(tc); | | |||
159 | // } | | |||
160 | } | 79 | } | ||
161 | 80 | | |||
162 | 81 | | |||
163 | 82 | | |||
164 | #include <htmlinterfaceplugin.moc> | 83 | #include <htmlinterfaceplugin.moc> |