linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #07357
[Branch ~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin] Rev 36: log to a file
------------------------------------------------------------
revno: 36
committer: poy <poy@xxxxxxxxxx>
branch nick: DevPlugin
timestamp: Sun 2013-08-11 18:38:46 +0200
message:
log to a file
modified:
src/GUI.cpp
src/GUI.h
--
lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin
Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DevPlugin/+edit-subscription
=== modified file 'src/GUI.cpp'
--- src/GUI.cpp 2013-05-13 19:07:51 +0000
+++ src/GUI.cpp 2013-08-11 16:38:46 +0000
@@ -38,6 +38,7 @@
#include <dwt/widgets/GroupBox.h>
#include <dwt/widgets/Menu.h>
#include <dwt/widgets/MessageBox.h>
+#include <dwt/widgets/SaveDialog.h>
#include <dwt/widgets/Table.h>
#include <dwt/widgets/TextBox.h>
#include <dwt/widgets/Window.h>
@@ -144,7 +145,7 @@
}
{
- auto cur = grid->addChild(Grid::Seed(1, 4));
+ auto cur = grid->addChild(Grid::Seed(1, 5));
cur->setSpacing(30);
auto hubMessagesW = cur->addChild(CheckBox::Seed(_T("Add hub messages")));
@@ -170,23 +171,49 @@
});
}
- cur = cur->addChild(GroupBox::Seed(_T("Regex filter")))->addChild(Grid::Seed(1, 2));
- cur->column(0).size = 300;
- TextBox::Seed seed;
- seed.style |= ES_AUTOHSCROLL;
- auto regexW = cur->addChild(seed);
-
- Button::Seed bs(_T("Apply"));
- bs.padding.x += 8;
- cur->addChild(bs)->onClicked([this, regexW] {
- regex = "";
- try {
- regex.assign(Util::fromT(regexW->getText()));
- } catch(const std::runtime_error&) {
- dwt::MessageBox(window).show(_T("Invalid regular expression"), window->getText(),
- dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONEXCLAMATION);
- }
- });
+ {
+ auto cur2 = cur->addChild(GroupBox::Seed(_T("Regex filter")))->addChild(Grid::Seed(1, 2));
+ cur2->column(0).size = 250;
+
+ TextBox::Seed seed;
+ seed.style |= ES_AUTOHSCROLL;
+ auto box = cur2->addChild(seed);
+
+ Button::Seed bs(_T("Apply"));
+ bs.padding.x += 8;
+ cur2->addChild(bs)->onClicked([this, box] {
+ regex = "";
+ try {
+ regex.assign(Util::fromT(box->getText()));
+ } catch(const std::runtime_error&) {
+ dwt::MessageBox(window).show(_T("Invalid regular expression"), window->getText(),
+ dwt::MessageBox::BOX_OK, dwt::MessageBox::BOX_ICONEXCLAMATION);
+ }
+ });
+ }
+
+ {
+ auto cur2 = cur->addChild(GroupBox::Seed(_T("Log to a file")))->addChild(Grid::Seed(1, 2));
+ cur2->column(0).size = 250;
+
+ log = Config::getConfig("Log");
+
+ TextBox::Seed seed(Util::toT(log));
+ seed.style |= ES_AUTOHSCROLL;
+ auto box = cur2->addChild(seed);
+ box->onUpdated([this, box] { log = Util::fromT(box->getText()); Config::setConfig("Log", log); });
+
+ Button::Seed bs(_T("Browse"));
+ bs.padding.x += 8;
+ cur2->addChild(bs)->onClicked([this, box] {
+ auto file = Util::toT(log);
+ if(SaveDialog(window).open(file)) {
+ log = Util::fromT(file);
+ Config::setConfig("Log", log);
+ box->setText(file);
+ }
+ });
+ }
}
{
@@ -245,6 +272,11 @@
void GUI::timer() {
int pos = -1;
+ FILE* f = nullptr;
+ if(!log.empty()) {
+ f = fopen(log.c_str(), "a");
+ }
+
std::unique_ptr<Message> messagePtr;
while(messages.pop(messagePtr)) {
auto& message = *messagePtr.get();
@@ -269,6 +301,11 @@
}
}
+ if(f) {
+ fprintf(f, "%u [%s] %s:%u (%s): %s\n", counter, message.sending ? "Out" : "In",
+ message.ip.c_str(), message.port, message.peer.c_str(), message.message.c_str());
+ }
+
auto item = new Item;
item->index = Util::toT(boost::lexical_cast<string>(counter));
item->dir = message.sending ? _T("Out") : _T("In");
@@ -293,6 +330,10 @@
}
}
+ if(f) {
+ fclose(f);
+ }
+
if(scroll && pos != -1) { // make sure something was added
table->ensureVisible(pos);
}
=== modified file 'src/GUI.h'
--- src/GUI.h 2013-05-13 19:07:51 +0000
+++ src/GUI.h 2013-08-11 16:38:46 +0000
@@ -58,6 +58,7 @@
unordered_set<tstring> filter;
tstring filterSel;
boost::regex regex;
+ string log;
// objects associated to each list litem as LPARAMs.
struct Item {