Skip to content

Commit

Permalink
Merge pull request #53 from airdcpp-web/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
maksis committed Jan 25, 2016
2 parents 5771bda + ec8f3bc commit deef556
Show file tree
Hide file tree
Showing 73 changed files with 870 additions and 424 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project (airdcpp-webclient)
cmake_minimum_required (VERSION 2.6.3)
cmake_minimum_required (VERSION 2.8.6)

if (APPLE)
set (PROJECT_NAME_GLOBAL AirDC++ Web Client)
Expand Down
2 changes: 2 additions & 0 deletions airdcpp-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ add_library (airdcpp ${LINK} ${airdcpp_srcs})
# set_property(SOURCE ${PROJECT_SOURCE_DIR}/DCPlusPlus.cpp ${PROJECT_SOURCE_DIR}/UPnPManager.cpp PROPERTY COMPILE_DEFINITIONS USE_MINIUPNP )
#endif()


set_property(SOURCE ${PROJECT_SOURCE_DIR}/airdcpp/StringDefs.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -fno-var-tracking ")
set_property(SOURCE ${PROJECT_SOURCE_DIR}/airdcpp/Updater.h PROPERTY COMPILE_DEFINITIONS NO_CLIENT_UPDATER)

add_definitions (-DNO_CLIENT_UPDATER)
Expand Down
2 changes: 2 additions & 0 deletions airdcpp-core/airdcpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="airdcpp\ActivityManager.cpp" />
<ClCompile Include="airdcpp\AdcCommand.cpp" />
<ClCompile Include="airdcpp\AdcHub.cpp" />
<ClCompile Include="airdcpp\MessageCache.cpp" />
Expand Down Expand Up @@ -346,6 +347,7 @@
<ClCompile Include="airdcpp\ZUtils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="airdcpp\ActivityManager.h" />
<ClInclude Include="airdcpp\AdcCommand.h" />
<ClInclude Include="airdcpp\AdcHub.h" />
<ClInclude Include="airdcpp\AutoSearchQueue.h" />
Expand Down
6 changes: 6 additions & 0 deletions airdcpp-core/airdcpp.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@
<ClCompile Include="airdcpp\ViewFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="airdcpp\ActivityManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="airdcpp\AdcCommand.h">
Expand Down Expand Up @@ -847,6 +850,9 @@
<ClInclude Include="airdcpp\ViewFileManagerListener.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="airdcpp\ActivityManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="airdcpp\StringDefs.h">
Expand Down
80 changes: 80 additions & 0 deletions airdcpp-core/airdcpp/ActivityManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2011-2016 AirDC++ Project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "stdinc.h"

#include "ActivityManager.h"
#include "ClientManager.h"
#include "SettingsManager.h"


namespace dcpp {

ActivityManager::ActivityManager() {
TimerManager::getInstance()->addListener(this);
}

ActivityManager::~ActivityManager() {
TimerManager::getInstance()->removeListener(this);
}

void ActivityManager::updateActivity(time_t aLastActivity) noexcept {
if (aLastActivity < lastActivity) {
return;
}

lastActivity = aLastActivity;
if (awayMode != AWAY_MANUAL) {
setAway(AWAY_OFF);
}
}

void ActivityManager::on(TimerManagerListener::Second, uint64_t aTick) noexcept {
if (!SETTING(AWAY_IDLE_TIME) || awayMode != AWAY_OFF) {
return;
}

if ((lastActivity + SETTING(AWAY_IDLE_TIME) * 60 * 1000ULL) < aTick) {
setAway(AWAY_IDLE);
}
}

void ActivityManager::setAway(AwayMode aNewMode) {
if (aNewMode == awayMode) {
return;
}

if (aNewMode == AWAY_MANUAL || (awayMode == AWAY_MANUAL && aNewMode == AWAY_OFF)) {
//only save the state if away mode is set by user
SettingsManager::getInstance()->set(SettingsManager::AWAY, aNewMode != AWAY_OFF);
}

awayMode = aNewMode;
if (awayMode > AWAY_OFF)
lastActivity = GET_TICK();

ClientManager::getInstance()->infoUpdated();
fire(ActivityManagerListener::AwayModeChanged(), awayMode);
}

string ActivityManager::getAwayMessage(const string& aAwayMsg, ParamMap& params) const noexcept {
params["idleTI"] = Util::formatSeconds(GET_TICK() - lastActivity);
return Util::formatParams(aAwayMsg, params);
}

} // namespace dcpp
68 changes: 68 additions & 0 deletions airdcpp-core/airdcpp/ActivityManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2011-2016 AirDC++ Project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef DCPLUSPLUS_DCPP_ACTIVITY_MANAGER_H
#define DCPLUSPLUS_DCPP_ACTIVITY_MANAGER_H

#include "typedefs.h"

#include "Speaker.h"
#include "TimerManager.h"


namespace dcpp {
//Away modes
enum AwayMode : uint8_t {
AWAY_OFF,
AWAY_IDLE,
AWAY_MANUAL //highest value
};

class ActivityManagerListener {
public:
virtual ~ActivityManagerListener() { }
template<int I> struct X { enum { TYPE = I }; };

typedef X<0> AwayModeChanged;

virtual void on(AwayModeChanged, AwayMode) noexcept { }
};

class ActivityManager : public Speaker<ActivityManagerListener>, public Singleton<ActivityManager>, public TimerManagerListener
{
public:
ActivityManager();
~ActivityManager();

void updateActivity(time_t aLastActivity = GET_TICK()) noexcept;

bool isAway() const noexcept { return awayMode != AWAY_OFF; }
AwayMode getAwayMode() const noexcept { return awayMode; }
void setAway(AwayMode aAway);

string getAwayMessage(const string& aAwayMsg, ParamMap& params) const noexcept;
private:
void on(TimerManagerListener::Second, uint64_t aTick) noexcept;

AwayMode awayMode;
time_t lastActivity = GET_TICK();
};

} // namespace dcpp

#endif // DCPLUSPLUS_DCPP_ACTIVITY_MANAGER_H
3 changes: 2 additions & 1 deletion airdcpp-core/airdcpp/AdcHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "stdinc.h"
#include "version.h"

#include "ActivityManager.h"
#include "AdcCommand.h"
#include "AdcHub.h"
#include "Message.h"
Expand Down Expand Up @@ -1436,7 +1437,7 @@ void AdcHub::infoImpl() {
addParam(lastInfoMap, c, "HO", Util::toString(counts[COUNT_OP]));

addParam(lastInfoMap, c, "VE", shortVersionString);
addParam(lastInfoMap, c, "AW", AirUtil::getAway() ? "1" : Util::emptyString);
addParam(lastInfoMap, c, "AW", ActivityManager::getInstance()->isAway() ? "1" : Util::emptyString);
addParam(lastInfoMap, c, "LC", Localization::getCurrentLocale());

int64_t limit = ThrottleManager::getInstance()->getDownLimit() * 1000;
Expand Down
37 changes: 8 additions & 29 deletions airdcpp-core/airdcpp/AirUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
#include "stdinc.h"

#include "AirUtil.h"
#include "Util.h"
#include "ThrottleManager.h"

#include "ConnectivityManager.h"
#include "File.h"
#include "LogManager.h"
#include "QueueManager.h"
#include "SettingsManager.h"
#include "ConnectivityManager.h"
#include "ResourceManager.h"
#include "StringTokenizer.h"
#include "SettingsManager.h"
#include "ShareManager.h"
#include "SimpleXML.h"
#include "Socket.h"
#include "LogManager.h"
#include "Wildcards.h"
#include "ShareManager.h"
#include "StringTokenizer.h"
#include "ThrottleManager.h"
#include "Util.h"

#include <locale.h>

#include <boost/date_time/format_date_parser.hpp>
Expand Down Expand Up @@ -63,9 +63,6 @@ boost::regex AirUtil::crcReg;
string AirUtil::privKeyFile;
string AirUtil::tempDLDir;

AwayMode AirUtil::away = AWAY_OFF;
time_t AirUtil::awayTime;

AirUtil::TimeCounter::TimeCounter(string aMsg) : start(GET_TICK()), msg(move(aMsg)) {

}
Expand Down Expand Up @@ -750,24 +747,6 @@ string AirUtil::regexEscape(const string& aStr, bool isWildcard) {
return result;
}

void AirUtil::setAway(AwayMode aAway) {
if(aAway != away)
ClientManager::getInstance()->infoUpdated();

if((aAway == AWAY_MANUAL) || (getAwayMode() == AWAY_MANUAL && aAway == AWAY_OFF) ) //only save the state if away mode is set by user
SettingsManager::getInstance()->set(SettingsManager::AWAY, aAway > 0);

away = aAway;

if (away > AWAY_OFF)
awayTime = time(NULL);
}

string AirUtil::getAwayMessage(const string& aAwayMsg, ParamMap& params) {
params["idleTI"] = Util::formatSeconds(time(NULL) - awayTime);
return Util::formatParams(aAwayMsg, params);
}

string AirUtil::subtractCommonDirs(const string& toCompare, const string& toSubtract, char separator) {
if (toSubtract.length() > 3) {
string::size_type i = toSubtract.length()-2;
Expand Down
15 changes: 0 additions & 15 deletions airdcpp-core/airdcpp/AirUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@

namespace dcpp {

//Away modes
enum AwayMode : uint8_t {
AWAY_OFF,
AWAY_IDLE,
AWAY_MINIMIZE,
AWAY_MANUAL //highest value
};

enum DupeType: uint8_t {
DUPE_NONE,
DUPE_SHARE_PARTIAL,
Expand Down Expand Up @@ -137,11 +129,6 @@ class AirUtil {
static string convertMovePath(const string& aPath, const string& aParent, const string& aTarget);
static string regexEscape(const string& aStr, bool isWildcard);

static bool getAway() { return away > 0; }
static AwayMode getAwayMode() { return away; }
static void setAway(AwayMode aAway);
static string getAwayMessage(const string& aAwayMsg, ParamMap& params);

/* Removes common dirs from the end of toSubtract */
static string subtractCommonDirs(const string& toCompare, const string& toSubtract, char separator);

Expand All @@ -151,8 +138,6 @@ class AirUtil {

private:
static bool removeDirectoryIfEmptyRe(const string& tgt, int maxAttempts, int curAttempts);
static AwayMode away;
static time_t awayTime;

};

Expand Down
Loading

0 comments on commit deef556

Please sign in to comment.