← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcpp-plugin-sdk-cpp/DescriptionRotator] Rev 37: show the online time in the description

 

------------------------------------------------------------
revno: 37
committer: poy <poy@xxxxxxxxxx>
branch nick: DescriptionRotator
timestamp: Tue 2013-06-18 23:14:12 +0200
message:
  show the online time in the description
modified:
  src/Plugin.cpp
  src/Plugin.h
  src/Rule.cpp
  src/Rule.h
  src/RuleDlg.cpp
  src/version.h


--
lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DescriptionRotator
https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DescriptionRotator

Your team Dcplusplus-team is subscribed to branch lp:~dcplusplus-team/dcpp-plugin-sdk-cpp/DescriptionRotator.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcpp-plugin-sdk-cpp/DescriptionRotator/+edit-subscription
=== modified file 'src/Plugin.cpp'
--- src/Plugin.cpp	2013-06-16 13:26:53 +0000
+++ src/Plugin.cpp	2013-06-18 21:14:12 +0000
@@ -143,13 +143,16 @@
 
 	for(auto& hub: hubs) {
 
-		if(hub.second.next && hub.second.next < tick) {
+		if(hub.second.next && hub.second.next > tick) {
 			continue;
 		}
 
 		// 0 means the new description has just been sent by onHubDataOut; find the next update time.
 		bool send = hub.second.next;
 		hub.second.next = 0;
+		if(!hub.second.init) {
+			hub.second.init = tick;
+		}
 
 		auto description = send ? hub.second.description : string();
 		if(!hub.second.sid && !description.empty()) {
@@ -162,7 +165,7 @@
 		}
 
 		for(auto& rule: rules) {
-			if(rule.match(hub.first, description)) {
+			if(rule.match(hub.first, description, tick - hub.second.init)) {
 				hub.second.next = hub.second.next ? std::min(hub.second.next, static_cast<uint64_t>(rule.delay)) : rule.delay;
 			}
 		}
@@ -242,6 +245,7 @@
 					info.sid = cmd.getFrom();
 					info.description = initial_desc;
 					info.next = 0;
+					info.init = 0;
 
 					info.sending = true;
 					Hubs::handle()->send_protocol_cmd(hub, cmd.toString(cmd.getFrom()).c_str());
@@ -272,6 +276,7 @@
 					info.sid = 0;
 					info.description = cmd;
 					info.next = 0;
+					info.init = 0;
 
 					info.sending = true;
 					Hubs::handle()->send_protocol_cmd(hub, cmd.c_str());
@@ -305,6 +310,8 @@
 			}
 		}
 
+		rule.online = Config::getConfig(conf("Online").c_str());
+
 		rule.refresh();
 
 		++counter;
@@ -328,6 +335,8 @@
 			Config::setConfig(conf("Description_" + boost::lexical_cast<string>(descriptions)).c_str(), rule.descriptions[descriptions]);
 		}
 
+		Config::setConfig(conf("Online").c_str(), rule.online);
+
 		++counter;
 	}
 }

=== modified file 'src/Plugin.h'
--- src/Plugin.h	2013-06-13 21:53:03 +0000
+++ src/Plugin.h	2013-06-18 21:14:12 +0000
@@ -65,6 +65,7 @@
 		bool sending;
 		uint32_t sid;
 		string description;
+		uint64_t init;
 		uint64_t next;
 	};
 	unordered_map<string, HubInfo> hubs;

=== modified file 'src/Rule.cpp'
--- src/Rule.cpp	2013-06-08 11:49:39 +0000
+++ src/Rule.cpp	2013-06-18 21:14:12 +0000
@@ -22,6 +22,7 @@
 #include <random>
 
 #include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
 
 Rule::Rule() :
 	position(Replace),
@@ -43,7 +44,7 @@
 	}
 }
 
-bool Rule::match(const string& url, string& param) const {
+bool Rule::match(const string& url, string& param, uint64_t diff) const {
 	if(!hub.empty()) {
 		std::vector<string> hubs;
 		boost::split(hubs, hub, boost::is_any_of(";"));
@@ -71,5 +72,11 @@
 	case Append: param += (!param.empty() ? " - " : "") + description; break;
 	}
 
+	if(!online.empty()) {
+		auto online_param = boost::replace_all_copy(online, "%H%", boost::lexical_cast<string>(diff / 1000 / 60 / 60));
+		boost::replace_all(online_param, "%M%", boost::lexical_cast<string>(diff / 1000 / 60));
+		param += " - " + move(online_param);
+	}
+
 	return true;
 }

=== modified file 'src/Rule.h'
--- src/Rule.h	2013-06-08 11:49:39 +0000
+++ src/Rule.h	2013-06-18 21:14:12 +0000
@@ -25,12 +25,13 @@
 	Rule();
 
 	void refresh();
-	bool match(const string& url, string& param) const;
+	bool match(const string& url, string& param, uint64_t diff = 0) const;
 
 	string hub;
 	enum { Replace, Prepend, Append } position;
 	uint32_t delay; // in minutes
 	std::vector<string> descriptions;
+	string online;
 };
 
 #endif

=== modified file 'src/RuleDlg.cpp'
--- src/RuleDlg.cpp	2013-06-08 11:49:39 +0000
+++ src/RuleDlg.cpp	2013-06-18 21:14:12 +0000
@@ -58,7 +58,7 @@
 }
 
 int RuleDlg::run() {
-	create(Seed(dwt::Point(600, 500)));
+	create(Seed(dwt::Point(600, 600)));
 	return show();
 }
 
@@ -88,7 +88,7 @@
 	}
 
 	{
-		auto cur = grid->addChild(GroupBox::Seed(_T("Descriptions")))->addChild(Grid::Seed(2, 1));
+		auto cur = grid->addChild(GroupBox::Seed(_T("Descriptions")))->addChild(Grid::Seed(3, 1));
 		cur->row(0).mode = GridInfo::FILL;
 		cur->row(0).align = GridInfo::STRETCH;
 		cur->column(0).mode = GridInfo::FILL;
@@ -149,12 +149,10 @@
 		};
 		table->onSelectionChanged(selChanged);
 		selChanged();
-	}
 
-	{
 		ComboBox::Seed cs { };
 		cs.style |= CBS_DROPDOWNLIST;
-		auto combo = grid->addChild(GroupBox::Seed())->addChild(cs);
+		auto combo = cur->addChild(cs);
 		combo->addValue(_T("Replace the description with one from this list"));
 		combo->addValue(_T("Prepend the description with one from this list (add at the beginning)"));
 		combo->addValue(_T("Append the description with one from this list (add at the end)"));
@@ -163,6 +161,19 @@
 	}
 
 	{
+		auto cur = grid->addChild(GroupBox::Seed(_T("Add online time to the description")))->addChild(Grid::Seed(3, 1));
+		cur->column(0).mode = GridInfo::FILL;
+		cur->setSpacing(grid->getSpacing());
+
+		cur->addChild(Label::Seed(_T("Text to add (use %H% for the amount of online hours, %M% for minutes)")));
+
+		TextBox::Seed ts(Util::toT(rule.online));
+		ts.style |= ES_AUTOHSCROLL;
+		auto box = cur->addChild(ts);
+		box->onUpdated([this, box] { rule.online = Util::fromT(box->getText()); });
+	}
+
+	{
 		auto cur = grid->addChild(GroupBox::Seed(_T("Rotation delay")))->addChild(Grid::Seed(1, 3));
 		cur->column(1).size = 40;
 		cur->column(1).mode = GridInfo::STATIC;

=== modified file 'src/version.h'
--- src/version.h	2013-06-08 11:49:39 +0000
+++ src/version.h	2013-06-18 21:14:12 +0000
@@ -31,7 +31,7 @@
 #define PLUGIN_AUTHOR "DC++"
 
 /* Short description of the plugin */
-#define PLUGIN_DESC "Rotate between multiple descriptions."
+#define PLUGIN_DESC "Rotate between multiple descriptions, show the online time."
 
 /* Version of the plugin (note: not API version) */
 #define PLUGIN_VERSION 1.0