merged upstream/master

This commit is contained in:
csoler 2020-10-13 22:54:23 +02:00
commit 80f5f0350c
244 changed files with 9307 additions and 4823 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,55 @@
#!/bin/bash
<<LICENSE
Copyright (C) 2020 Gioacchino Mazzurco <gio@eigenlab.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
LICENSE
<<README
Generate a clean DHT bootstrap node list.
Feeds on previously known nodes from standard input and a few well known
mainline DHT bootstrap nodes. Prints only nodes that appears to be active to a
quick nmap check. Make sure your internet connection is working well before
using this.
Example usage:
--------------------------------
cat bdboot.txt | bdboot_generate.sh | tee /tmp/bdboot_generated.txt
cat /tmp/bdboot_generated.txt | sort -u > bdboot.txt
--------------------------------
README
function check_dht_host()
{
mHost="$1"
mPort="$2"
sudo nmap -oG - -sU -p $mPort $mHost | grep open | \
awk '{print $2" "$5}' | awk -F/ '{print $1}'
}
cat | while read line; do
hostIP="$(echo $line | awk '{print $1}')"
hostPort="$(echo $line | awk '{print $2}')"
check_dht_host $hostIP $hostPort
done
check_dht_host router.utorrent.com 6881
check_dht_host router.bittorrent.com 6881
check_dht_host dht.libtorrent.org 25401
check_dht_host dht.transmissionbt.com 6881

View file

@ -21,7 +21,6 @@
*******************************************************************************/ *******************************************************************************/
#include "dht/connectstatebox.h" #include "dht/connectstatebox.h"
#include "retroshare/rsconfig.h"
#include "util/rsrandom.h" #include "util/rsrandom.h"
#include "util/rsstring.h" #include "util/rsstring.h"
@ -260,26 +259,26 @@ std::string PeerConnectStateBox::connectState() const
} }
uint32_t convertNetStateToInternal(uint32_t netmode, uint32_t nathole, uint32_t nattype) uint32_t convertNetStateToInternal(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t connNet = CSB_NETSTATE_UNKNOWN; uint32_t connNet = CSB_NETSTATE_UNKNOWN;
if (netmode == RSNET_NETWORK_EXTERNALIP) if (netmode == RsNetworkMode::EXTERNALIP)
{ {
connNet = CSB_NETSTATE_FORWARD; connNet = CSB_NETSTATE_FORWARD;
} }
else if ((nathole != RSNET_NATHOLE_UNKNOWN) && (nathole != RSNET_NATHOLE_NONE)) else if ((nathole != RsNatHoleMode::UNKNOWN) && (nathole != RsNatHoleMode::NONE))
{ {
connNet = CSB_NETSTATE_FORWARD; connNet = CSB_NETSTATE_FORWARD;
} }
else if (netmode == RSNET_NETWORK_BEHINDNAT) else if (netmode == RsNetworkMode::BEHINDNAT)
{ {
if ((nattype == RSNET_NATTYPE_RESTRICTED_CONE) || if ((nattype == RsNatTypeMode::RESTRICTED_CONE) ||
(nattype == RSNET_NATTYPE_FULL_CONE)) (nattype == RsNatTypeMode::FULL_CONE))
{ {
connNet = CSB_NETSTATE_STABLENAT; connNet = CSB_NETSTATE_STABLENAT;
} }
else if (nattype == RSNET_NATTYPE_DETERM_SYM) else if (nattype == RsNatTypeMode::DETERM_SYM)
{ {
connNet = CSB_NETSTATE_EXCLUSIVENAT; connNet = CSB_NETSTATE_EXCLUSIVENAT;
} }
@ -300,20 +299,20 @@ bool shouldUseProxyPortInternal(uint32_t netstate)
return true; return true;
} }
bool PeerConnectStateBox::shouldUseProxyPort(uint32_t netmode, uint32_t nathole, uint32_t nattype) bool PeerConnectStateBox::shouldUseProxyPort(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return shouldUseProxyPortInternal(netstate); return shouldUseProxyPortInternal(netstate);
} }
uint32_t PeerConnectStateBox::calcNetState(uint32_t netmode, uint32_t nathole, uint32_t nattype) uint32_t PeerConnectStateBox::calcNetState(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);
return netstate; return netstate;
} }
uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, uint32_t netmode, uint32_t nathole, uint32_t nattype) uint32_t PeerConnectStateBox::connectCb(uint32_t cbtype, RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype)
{ {
uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype); uint32_t netstate = convertNetStateToInternal(netmode, nathole, nattype);

View file

@ -75,17 +75,19 @@
#include "util/rstime.h" #include "util/rstime.h"
#include <inttypes.h> #include <inttypes.h>
#include <retroshare/rsconfig.h>
class PeerConnectStateBox class PeerConnectStateBox
{ {
public: public:
PeerConnectStateBox(); PeerConnectStateBox();
uint32_t connectCb(uint32_t cbtype, uint32_t netmode, uint32_t nathole, uint32_t nattype); uint32_t connectCb(uint32_t cbtype, RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype);
uint32_t updateCb(uint32_t updateType); uint32_t updateCb(uint32_t updateType);
bool shouldUseProxyPort(uint32_t netmode, uint32_t nathole, uint32_t nattype); bool shouldUseProxyPort(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype);
uint32_t calcNetState(uint32_t netmode, uint32_t nathole, uint32_t nattype); uint32_t calcNetState(RsNetworkMode netmode, RsNatHoleMode nathole, RsNatTypeMode nattype);
std::string connectState() const; std::string connectState() const;
std::string mPeerId; std::string mPeerId;

View file

@ -45,20 +45,20 @@ class DhtPeerDetails
DhtPeerDetails(); DhtPeerDetails();
uint32_t mPeerType; RsDhtPeerType mPeerType;
bdId mDhtId; bdId mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
/* direct from the DHT! */ /* direct from the DHT! */
uint32_t mDhtState; // One of RSDHT_PEERDHT_[...] RsDhtPeerDht mDhtState;
rstime_t mDhtUpdateTS; rstime_t mDhtUpdateTS;
/* internal state */ /* internal state */
PeerConnectStateBox mConnectLogic; PeerConnectStateBox mConnectLogic;
/* Actual Connection Status */ /* Actual Connection Status */
uint32_t mPeerConnectState; // One of RSDHT_PEERCONN_ RsDhtPeerConnectState mPeerConnectState;
std::string mPeerConnectMsg; std::string mPeerConnectMsg;
uint32_t mPeerConnectMode; uint32_t mPeerConnectMode;
bdId mPeerConnectPeerId; bdId mPeerConnectPeerId;
@ -77,7 +77,7 @@ class DhtPeerDetails
/* Connection Request Status */ /* Connection Request Status */
std::string mPeerReqStatusMsg; std::string mPeerReqStatusMsg;
uint32_t mPeerReqState; RsDhtPeerRequest mPeerReqState;
uint32_t mPeerReqMode; uint32_t mPeerReqMode;
bdId mPeerReqProxyId; bdId mPeerReqProxyId;
rstime_t mPeerReqTS; rstime_t mPeerReqTS;
@ -294,11 +294,11 @@ public:
virtual int addRelayServer(std::string ids); virtual int addRelayServer(std::string ids);
virtual int removeRelayServer(std::string ids); virtual int removeRelayServer(std::string ids);
virtual uint32_t getRelayMode(); virtual RsDhtRelayMode getRelayMode();
virtual int setRelayMode(uint32_t mode); virtual int setRelayMode(RsDhtRelayMode mode);
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth); virtual int getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth);
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth); virtual int setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth);
private: private:
@ -307,7 +307,7 @@ private:
int pushRelayServers(); int pushRelayServers();
std::list<std::string> mRelayServerList; std::list<std::string> mRelayServerList;
uint32_t mRelayMode; RsDhtRelayMode mRelayMode;
protected: protected:
/*****************************************************************/ /*****************************************************************/
@ -348,9 +348,9 @@ public:
private: private:
DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, uint32_t type); DhtPeerDetails *addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type);
int removeInternalPeer_locked(const RsPeerId& pid); int removeInternalPeer_locked(const RsPeerId& pid);
DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type); DhtPeerDetails *findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type);
DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid); DhtPeerDetails *findInternalRsPeer_locked(const RsPeerId &pid);
bool havePeerTranslation_locked(const RsPeerId &pid); bool havePeerTranslation_locked(const RsPeerId &pid);

View file

@ -302,16 +302,16 @@ void convertDhtPeerDetailsToRsDhtNetPeer(RsDhtNetPeer &status, const DhtPeerDeta
switch(details.mPeerConnectMode) switch(details.mPeerConnectMode)
{ {
default: default:
status.mPeerConnectMode = RSDHT_TOU_MODE_NONE; status.mPeerConnectMode = RsDhtTouMode::NONE;
break; break;
case BITDHT_CONNECT_MODE_DIRECT: case BITDHT_CONNECT_MODE_DIRECT:
status.mPeerConnectMode = RSDHT_TOU_MODE_DIRECT; status.mPeerConnectMode = RsDhtTouMode::DIRECT;
break; break;
case BITDHT_CONNECT_MODE_PROXY: case BITDHT_CONNECT_MODE_PROXY:
status.mPeerConnectMode = RSDHT_TOU_MODE_PROXY; status.mPeerConnectMode = RsDhtTouMode::PROXY;
break; break;
case BITDHT_CONNECT_MODE_RELAY: case BITDHT_CONNECT_MODE_RELAY:
status.mPeerConnectMode = RSDHT_TOU_MODE_RELAY; status.mPeerConnectMode = RsDhtTouMode::RELAY;
break; break;
} }

View file

@ -83,7 +83,7 @@ int p3BitDht::InfoCallback(const bdId *id, uint32_t /*type*/, uint32_t /*flags*/
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
@ -204,7 +204,7 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(id->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
@ -222,26 +222,26 @@ int p3BitDht::PeerCallback(const bdId *id, uint32_t status)
switch(status) switch(status)
{ {
default: default:
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; dpd->mDhtState = RsDhtPeerDht::NOT_ACTIVE;
break; break;
case BITDHT_MGR_QUERY_FAILURE: case BITDHT_MGR_QUERY_FAILURE:
dpd->mDhtState = RSDHT_PEERDHT_FAILURE; dpd->mDhtState = RsDhtPeerDht::FAILURE;
break; break;
case BITDHT_MGR_QUERY_PEER_OFFLINE: case BITDHT_MGR_QUERY_PEER_OFFLINE:
dpd->mDhtState = RSDHT_PEERDHT_OFFLINE; dpd->mDhtState = RsDhtPeerDht::OFFLINE;
break; break;
case BITDHT_MGR_QUERY_PEER_UNREACHABLE: case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
dpd->mDhtState = RSDHT_PEERDHT_UNREACHABLE; dpd->mDhtState = RsDhtPeerDht::UNREACHABLE;
dpd->mDhtId = *id; // set the IP:Port of the unreachable peer. dpd->mDhtId = *id; // set the IP:Port of the unreachable peer.
UnreachablePeerCallback_locked(id, status, dpd); UnreachablePeerCallback_locked(id, status, dpd);
break; break;
case BITDHT_MGR_QUERY_PEER_ONLINE: case BITDHT_MGR_QUERY_PEER_ONLINE:
dpd->mDhtState = RSDHT_PEERDHT_ONLINE; dpd->mDhtState = RsDhtPeerDht::ONLINE;
dpd->mDhtId = *id; // set the IP:Port of the Online peer. dpd->mDhtId = *id; // set the IP:Port of the Online peer.
OnlinePeerCallback_locked(id, status, dpd); OnlinePeerCallback_locked(id, status, dpd);
@ -262,8 +262,8 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t /*status*/, Dht
/* remove unused parameter warnings */ /* remove unused parameter warnings */
(void) id; (void) id;
if ((dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) || if ((dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED) ||
(dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)) (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING))
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -367,8 +367,8 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t /*status*/, Dht
int p3BitDht::UnreachablePeerCallback_locked(const bdId *id, uint32_t /*status*/, DhtPeerDetails *dpd) int p3BitDht::UnreachablePeerCallback_locked(const bdId *id, uint32_t /*status*/, DhtPeerDetails *dpd)
{ {
if ((dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) || if ((dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED) ||
(dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)) (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING))
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -717,7 +717,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
proxyPort = dpd->mConnectLogic.shouldUseProxyPort( proxyPort = dpd->mConnectLogic.shouldUseProxyPort(
@ -811,7 +811,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mExclusiveProxyLock = true; dpd->mExclusiveProxyLock = true;
@ -939,7 +939,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerCbMsg = "ERROR : "; dpd->mPeerCbMsg = "ERROR : ";
@ -980,7 +980,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
if (errcode) if (errcode)
@ -989,7 +989,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
dpd->mPeerReqStatusMsg = "STOPPED: "; dpd->mPeerReqStatusMsg = "STOPPED: ";
dpd->mPeerReqStatusMsg += decodeConnectionError(errcode); dpd->mPeerReqStatusMsg += decodeConnectionError(errcode);
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED; dpd->mPeerReqState = RsDhtPeerRequest::STOPPED;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
int updatecode = CSB_UPDATE_FAILED_ATTEMPT; int updatecode = CSB_UPDATE_FAILED_ATTEMPT;
@ -1048,7 +1048,7 @@ int p3BitDht::ConnectCallback(const bdId *srcId, const bdId *proxyId, const bdId
else // a new connection attempt. else // a new connection attempt.
{ {
dpd->mPeerReqStatusMsg = "Connect Attempt"; dpd->mPeerReqStatusMsg = "Connect Attempt";
dpd->mPeerReqState = RSDHT_PEERREQ_RUNNING; dpd->mPeerReqState = RsDhtPeerRequest::RUNNING;
dpd->mPeerReqMode = mode; dpd->mPeerReqMode = mode;
dpd->mPeerReqProxyId = *proxyId; dpd->mPeerReqProxyId = *proxyId;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1232,7 +1232,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
connectOk = true; connectOk = true;
@ -1387,11 +1387,11 @@ int p3BitDht::doActions()
#endif #endif
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mPeerReqStatusMsg = "Connect Request"; dpd->mPeerReqStatusMsg = "Connect Request";
dpd->mPeerReqState = RSDHT_PEERREQ_RUNNING; dpd->mPeerReqState = RsDhtPeerRequest::RUNNING;
dpd->mPeerReqMode = action.mMode; dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1428,13 +1428,13 @@ int p3BitDht::doActions()
//} //}
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::FRIEND);
if (dpd) if (dpd)
{ {
dpd->mConnectLogic.updateCb(failReason); dpd->mConnectLogic.updateCb(failReason);
dpd->mPeerReqStatusMsg = "Req Mode Unavailable"; dpd->mPeerReqStatusMsg = "Req Mode Unavailable";
dpd->mPeerReqState = RSDHT_PEERREQ_STOPPED; dpd->mPeerReqState = RsDhtPeerRequest::STOPPED;
dpd->mPeerReqMode = action.mMode; dpd->mPeerReqMode = action.mMode;
dpd->mPeerReqTS = now; dpd->mPeerReqTS = now;
@ -1496,7 +1496,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mSrcId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
if (action.mAnswer) if (action.mAnswer)
@ -1604,7 +1604,7 @@ int p3BitDht::doActions()
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RsDhtPeerType::ANY);
if (dpd) if (dpd)
{ {
peerRsId = dpd->mRsId; peerRsId = dpd->mRsId;
@ -1730,7 +1730,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
rstime_t now = time(NULL); rstime_t now = time(NULL);
/* check if they are in our friend list */ /* check if they are in our friend list */
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerId->id), RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
@ -1749,14 +1749,14 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
/* flag as failed */ /* flag as failed */
it->second.mDhtId = *peerId; it->second.mDhtId = *peerId;
it->second.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; it->second.mDhtState = RsDhtPeerDht::NOT_ACTIVE;
it->second.mDhtUpdateTS = now; it->second.mDhtUpdateTS = now;
it->second.mPeerType = RSDHT_PEERTYPE_OTHER; it->second.mPeerType = RsDhtPeerType::OTHER;
it->second.mPeerCbMsg = "Denied Non-Friend"; it->second.mPeerCbMsg = "Denied Non-Friend";
it->second.mPeerReqStatusMsg = "Denied Non-Friend"; it->second.mPeerReqStatusMsg = "Denied Non-Friend";
it->second.mPeerReqState = RSDHT_PEERREQ_STOPPED; it->second.mPeerReqState = RsDhtPeerRequest::STOPPED;
it->second.mPeerReqTS = now; it->second.mPeerReqTS = now;
it->second.mPeerReqMode = 0; it->second.mPeerReqMode = 0;
//it->second.mPeerProxyId; //it->second.mPeerProxyId;
@ -1765,7 +1765,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
it->second.mPeerCbMsg = "Denied Non-Friend"; it->second.mPeerCbMsg = "Denied Non-Friend";
it->second.mPeerConnectMsg = "Denied Non-Friend"; it->second.mPeerConnectMsg = "Denied Non-Friend";
it->second.mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; it->second.mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
return 0; return 0;
@ -1774,7 +1774,7 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
/* are a friend */ /* are a friend */
if (dpd->mPeerConnectState == RSDHT_PEERCONN_CONNECTED) if (dpd->mPeerConnectState == RsDhtPeerConnectState::CONNECTED)
{ {
std::cerr << "p3BitDht::checkConnectionAllowed() ERROR Peer Already Connected, DENIED"; std::cerr << "p3BitDht::checkConnectionAllowed() ERROR Peer Already Connected, DENIED";
std::cerr << std::endl; std::cerr << std::endl;
@ -1979,7 +1979,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
{ {
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/ RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RSDHT_PEERTYPE_FRIEND); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(peerConnectId.id), RsDhtPeerType::FRIEND);
/* grab a socket */ /* grab a socket */
if (!dpd) if (!dpd)
{ {
@ -1988,7 +1988,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
return; return;
} }
if (dpd->mPeerConnectState != RSDHT_PEERCONN_DISCONNECTED) if (dpd->mPeerConnectState != RsDhtPeerConnectState::DISCONNECTED)
{ {
std::cerr << "p3BitDht::initiateConnection() ERROR Peer is not Disconnected"; std::cerr << "p3BitDht::initiateConnection() ERROR Peer is not Disconnected";
std::cerr << std::endl; std::cerr << std::endl;
@ -2003,7 +2003,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
{ {
default: default:
case BITDHT_CONNECT_MODE_DIRECT: case BITDHT_CONNECT_MODE_DIRECT:
// touConnectMode = RSDHT_TOU_MODE_DIRECT; // touConnectMode = RsDhtTouMode::DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT; connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
delay = delayOrBandwidth; delay = delayOrBandwidth;
break; break;
@ -2021,12 +2021,12 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
delay = delayOrBandwidth; delay = delayOrBandwidth;
if (useProxyPort) if (useProxyPort)
{ {
// touConnectMode = RSDHT_TOU_MODE_PROXY; // touConnectMode = RsDhtTouMode::PROXY;
connectFlags |= RS_CB_FLAG_MODE_UDP_PROXY; connectFlags |= RS_CB_FLAG_MODE_UDP_PROXY;
} }
else else
{ {
// touConnectMode = RSDHT_TOU_MODE_DIRECT; // touConnectMode = RsDhtTouMode::DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT; connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
} }
@ -2034,7 +2034,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
break; break;
case BITDHT_CONNECT_MODE_RELAY: case BITDHT_CONNECT_MODE_RELAY:
// touConnectMode = RSDHT_TOU_MODE_RELAY; // touConnectMode = RsDhtTouMode::RELAY;
connectFlags |= RS_CB_FLAG_MODE_UDP_RELAY; connectFlags |= RS_CB_FLAG_MODE_UDP_RELAY;
bandwidth = delayOrBandwidth; bandwidth = delayOrBandwidth;
break; break;
@ -2047,7 +2047,7 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
/* store results in Status */ /* store results in Status */
dpd->mPeerConnectMsg = "UDP started"; dpd->mPeerConnectMsg = "UDP started";
dpd->mPeerConnectState = RSDHT_PEERCONN_UDP_STARTED; dpd->mPeerConnectState = RsDhtPeerConnectState::UDP_STARTED;
dpd->mPeerConnectUdpTS = time(NULL); dpd->mPeerConnectUdpTS = time(NULL);
dpd->mPeerConnectMode = mode; dpd->mPeerConnectMode = mode;
dpd->mPeerConnectPoint = loc; dpd->mPeerConnectPoint = loc;
@ -2092,22 +2092,22 @@ int p3BitDht::installRelayConnection(const bdId *srcId, const bdId *destId, uint
#endif #endif
/* grab a socket */ /* grab a socket */
DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_src = findInternalDhtPeer_locked(&(srcId->id), RsDhtPeerType::ANY);
DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd_dest = findInternalDhtPeer_locked(&(destId->id), RsDhtPeerType::ANY);
if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FRIEND)) if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FRIEND)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FRIEND))
{ {
relayClass = UDP_RELAY_CLASS_FRIENDS; relayClass = UDP_RELAY_CLASS_FRIENDS;
} }
else if ((dpd_src) && (dpd_src->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_src) && (dpd_src->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
else if ((dpd_dest) && (dpd_dest->mPeerType == RSDHT_PEERTYPE_FOF)) else if ((dpd_dest) && (dpd_dest->mPeerType == RsDhtPeerType::FOF))
{ {
relayClass = UDP_RELAY_CLASS_FOF; relayClass = UDP_RELAY_CLASS_FOF;
} }
@ -2178,12 +2178,12 @@ void p3BitDht::monitorConnections()
for(it = mPeers.begin(); it != mPeers.end(); ++it) for(it = mPeers.begin(); it != mPeers.end(); ++it)
{ {
/* ignore ones which aren't friends */ /* ignore ones which aren't friends */
if (it->second.mPeerType != RSDHT_PEERTYPE_FRIEND) if (it->second.mPeerType != RsDhtPeerType::FRIEND)
{ {
continue; continue;
} }
if (it->second.mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED) if (it->second.mPeerConnectState == RsDhtPeerConnectState::UDP_STARTED)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::monitorConnections() Connection in progress to: "; std::cerr << "p3BitDht::monitorConnections() Connection in progress to: ";
@ -2225,7 +2225,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
} }
/* sanity checking */ /* sanity checking */
if (dpd->mPeerConnectState != RSDHT_PEERCONN_UDP_STARTED) if (dpd->mPeerConnectState != RsDhtPeerConnectState::UDP_STARTED)
{ {
/* ERROR */ /* ERROR */
std::cerr << "p3BitDht::Feedback_Connected() ERROR not in UDP_STARTED mode for: "; std::cerr << "p3BitDht::Feedback_Connected() ERROR not in UDP_STARTED mode for: ";
@ -2242,7 +2242,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
#endif #endif
/* switch state! */ /* switch state! */
dpd->mPeerConnectState = RSDHT_PEERCONN_CONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::CONNECTED;
dpd->mPeerConnectTS = time(NULL); dpd->mPeerConnectTS = time(NULL);
dpd->mConnectLogic.updateCb(CSB_UPDATE_CONNECTED); dpd->mConnectLogic.updateCb(CSB_UPDATE_CONNECTED);
@ -2250,7 +2250,7 @@ void p3BitDht::Feedback_Connected(const RsPeerId& pid)
rs_sprintf(dpd->mPeerConnectMsg, "Connected in %ld secs", dpd->mPeerConnectTS - dpd->mPeerConnectUdpTS); rs_sprintf(dpd->mPeerConnectMsg, "Connected in %ld secs", dpd->mPeerConnectTS - dpd->mPeerConnectUdpTS);
// Remove the Connection Request. // Remove the Connection Request.
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::monitorConnections() Request Active, Stopping Request"; std::cerr << "p3BitDht::monitorConnections() Request Active, Stopping Request";
@ -2334,7 +2334,7 @@ void p3BitDht::Feedback_ConnectionClosed(const RsPeerId& pid)
void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd) void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
{ {
if (dpd->mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED) if (dpd->mPeerConnectState == RsDhtPeerConnectState::UDP_STARTED)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: "; std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: ";
@ -2345,11 +2345,11 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
/* shut it down */ /* shut it down */
/* ONLY need to update ConnectLogic - if it was our Attempt Running */ /* ONLY need to update ConnectLogic - if it was our Attempt Running */
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT); dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT);
} }
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
dpd->mPeerConnectMsg = "UDP Failed"; dpd->mPeerConnectMsg = "UDP Failed";
} }
@ -2363,14 +2363,14 @@ void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd)
dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED); dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED);
dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; dpd->mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
dpd->mPeerConnectClosedTS = time(NULL); dpd->mPeerConnectClosedTS = time(NULL);
rs_sprintf(dpd->mPeerConnectMsg, "Closed, Alive for: %ld secs", dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS); rs_sprintf(dpd->mPeerConnectMsg, "Closed, Alive for: %ld secs", dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS);
} }
if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) if (dpd->mPeerReqState == RsDhtPeerRequest::RUNNING)
{ {
#ifdef DEBUG_PEERNET #ifdef DEBUG_PEERNET
std::cerr << "p3BitDht::UdpConnectionFailed_locked() "; std::cerr << "p3BitDht::UdpConnectionFailed_locked() ";

View file

@ -64,7 +64,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
DhtPeerDetails *dpd = findInternalRsPeer_locked(pid); DhtPeerDetails *dpd = findInternalRsPeer_locked(pid);
if (!dpd) if (!dpd)
{ {
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FRIEND);
if (!dpd) if (!dpd)
{ {
/* ERROR */ /* ERROR */
@ -76,7 +76,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
} }
/* new entry... what do we need to set? */ /* new entry... what do we need to set? */
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING; dpd->mDhtState = RsDhtPeerDht::SEARCHING;
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: "; std::cerr << "p3BitDht::findPeer() Installed new DhtPeer with pid => NodeId: ";
@ -93,7 +93,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
if (dpd->mDhtState != RSDHT_PEERDHT_NOT_ACTIVE) if (dpd->mDhtState != RsDhtPeerDht::NOT_ACTIVE)
{ {
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() WARNING DhtState is Already Active!"; std::cerr << "p3BitDht::findPeer() WARNING DhtState is Already Active!";
@ -104,7 +104,7 @@ bool p3BitDht::findPeer(const RsPeerId& pid)
else else
{ {
/* flag as searching */ /* flag as searching */
dpd->mDhtState = RSDHT_PEERDHT_SEARCHING; dpd->mDhtState = RsDhtPeerDht::SEARCHING;
#ifdef DEBUG_BITDHT #ifdef DEBUG_BITDHT
std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING"; std::cerr << "p3BitDht::findPeer() Marking Old Peer as SEARCHING";
std::cerr << std::endl; std::cerr << std::endl;
@ -150,13 +150,13 @@ bool p3BitDht::dropPeer(const RsPeerId& pid)
#endif #endif
//addFriend(pid); //addFriend(pid);
dpd = addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF); dpd = addInternalPeer_locked(pid, RsDhtPeerType::FOF);
return false; return false;
} }
/* flag as searching */ /* flag as searching */
dpd->mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; dpd->mDhtState = RsDhtPeerDht::NOT_ACTIVE;
nid = dpd->mDhtId.id; nid = dpd->mDhtId.id;
@ -242,7 +242,7 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
addrv4.sin_addr = ap->sin_addr; addrv4.sin_addr = ap->sin_addr;
addrv4.sin_port = ap->sin_port; addrv4.sin_port = ap->sin_port;
int p3type = 0; RsDhtPeerType p3type = RsDhtPeerType::ANY;
int bdflags = 0; int bdflags = 0;
bdId id; bdId id;
bool isOwnId = false; bool isOwnId = false;
@ -253,27 +253,27 @@ int p3BitDht::addKnownPeer( const RsPeerId &pid,
return 0; return 0;
break; break;
case NETASSIST_KNOWN_PEER_WHITELIST: case NETASSIST_KNOWN_PEER_WHITELIST:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST; bdflags = BITDHT_PEER_STATUS_DHT_WHITELIST;
break; break;
case NETASSIST_KNOWN_PEER_FOF: case NETASSIST_KNOWN_PEER_FOF:
p3type = RSDHT_PEERTYPE_FOF; p3type = RsDhtPeerType::FOF;
bdflags = BITDHT_PEER_STATUS_DHT_FOF; bdflags = BITDHT_PEER_STATUS_DHT_FOF;
break; break;
case NETASSIST_KNOWN_PEER_FRIEND: case NETASSIST_KNOWN_PEER_FRIEND:
p3type = RSDHT_PEERTYPE_FRIEND; p3type = RsDhtPeerType::FRIEND;
bdflags = BITDHT_PEER_STATUS_DHT_FRIEND; bdflags = BITDHT_PEER_STATUS_DHT_FRIEND;
break; break;
case NETASSIST_KNOWN_PEER_RELAY: case NETASSIST_KNOWN_PEER_RELAY:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER; bdflags = BITDHT_PEER_STATUS_DHT_RELAY_SERVER;
break; break;
case NETASSIST_KNOWN_PEER_SELF: case NETASSIST_KNOWN_PEER_SELF:
p3type = RSDHT_PEERTYPE_OTHER; p3type = RsDhtPeerType::OTHER;
bdflags = BITDHT_PEER_STATUS_DHT_SELF; bdflags = BITDHT_PEER_STATUS_DHT_SELF;
isOwnId = true; isOwnId = true;
@ -364,7 +364,7 @@ int p3BitDht::addFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FRIEND)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FRIEND));
} }
@ -372,7 +372,7 @@ int p3BitDht::addFriendOfFriend(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_FOF)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::FOF));
} }
@ -380,7 +380,7 @@ int p3BitDht::addOther(const std::string pid)
{ {
RsStackMutex stack(dhtMtx); /********* LOCKED *********/ RsStackMutex stack(dhtMtx); /********* LOCKED *********/
return (NULL != addInternalPeer_locked(pid, RSDHT_PEERTYPE_OTHER)); return (NULL != addInternalPeer_locked(pid, RsDhtPeerType::OTHER));
} }
#endif #endif
@ -397,7 +397,7 @@ int p3BitDht::removePeer(const RsPeerId& pid)
********************************* Basic Peer Details ************************************* ********************************* Basic Peer Details *************************************
******************************************************************************************/ ******************************************************************************************/
DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t type) DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, RsDhtPeerType type)
{ {
/* create the data structure */ /* create the data structure */
if (!havePeerTranslation_locked(pid)) if (!havePeerTranslation_locked(pid))
@ -411,18 +411,18 @@ DhtPeerDetails *p3BitDht::addInternalPeer_locked(const RsPeerId& pid, uint32_t t
return 0; return 0;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if (!dpd) if (!dpd)
{ {
DhtPeerDetails newdpd; DhtPeerDetails newdpd;
newdpd.mDhtId.id = id; newdpd.mDhtId.id = id;
newdpd.mRsId = pid; newdpd.mRsId = pid;
newdpd.mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; newdpd.mDhtState = RsDhtPeerDht::NOT_ACTIVE;
newdpd.mPeerType = RSDHT_PEERTYPE_ANY; newdpd.mPeerType = RsDhtPeerType::ANY;
mPeers[id] = newdpd; mPeers[id] = newdpd;
dpd = findInternalDhtPeer_locked(&id, RSDHT_PEERTYPE_ANY); dpd = findInternalDhtPeer_locked(&id, RsDhtPeerType::ANY);
if(dpd == NULL) if(dpd == NULL)
{ {
@ -462,14 +462,14 @@ int p3BitDht::removeInternalPeer_locked(const RsPeerId& pid)
/* indexed by bdNodeId, as this is the more used call interface */ /* indexed by bdNodeId, as this is the more used call interface */
DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, uint32_t type) DhtPeerDetails *p3BitDht::findInternalDhtPeer_locked(const bdNodeId *id, RsDhtPeerType type)
{ {
std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id); std::map<bdNodeId, DhtPeerDetails>::iterator it = mPeers.find(*id);
if (it == mPeers.end()) if (it == mPeers.end())
{ {
return NULL; return NULL;
} }
if (type) if (type != RsDhtPeerType::ANY)
{ {
if (it->second.mPeerType != type) if (it->second.mPeerType != type)
{ {
@ -495,7 +495,7 @@ DhtPeerDetails *p3BitDht::findInternalRsPeer_locked(const RsPeerId &pid)
return NULL; return NULL;
} }
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RSDHT_PEERTYPE_ANY); DhtPeerDetails *dpd = findInternalDhtPeer_locked(&id,RsDhtPeerType::ANY);
return dpd; return dpd;
} }
@ -717,13 +717,13 @@ int p3BitDht::calculateNodeId(const RsPeerId& pid, bdNodeId *id)
DhtPeerDetails::DhtPeerDetails() DhtPeerDetails::DhtPeerDetails()
{ {
mDhtState = RSDHT_PEERDHT_NOT_ACTIVE; mDhtState = RsDhtPeerDht::NOT_ACTIVE;
mDhtState = RSDHT_PEERDHT_SEARCHING; mDhtState = RsDhtPeerDht::SEARCHING;
mDhtUpdateTS = time(NULL); mDhtUpdateTS = time(NULL);
mPeerReqStatusMsg = "Just Added"; mPeerReqStatusMsg = "Just Added";
mPeerReqState = RSDHT_PEERREQ_STOPPED; mPeerReqState = RsDhtPeerRequest::STOPPED;
mPeerReqMode = 0; mPeerReqMode = 0;
//mPeerReqProxyId; //mPeerReqProxyId;
mPeerReqTS = time(NULL); mPeerReqTS = time(NULL);
@ -737,7 +737,7 @@ DhtPeerDetails::DhtPeerDetails()
//mPeerCbDestId = 0; //mPeerCbDestId = 0;
mPeerCbTS = 0; mPeerCbTS = 0;
mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; mPeerConnectState = RsDhtPeerConnectState::DISCONNECTED;
mPeerConnectMsg = "Disconnected"; mPeerConnectMsg = "Disconnected";
mPeerConnectMode = 0; mPeerConnectMode = 0;
//dpd->mPeerConnectProxyId; //dpd->mPeerConnectProxyId;

View file

@ -35,7 +35,7 @@
int p3BitDht::setupRelayDefaults() int p3BitDht::setupRelayDefaults()
{ {
uint32_t mode = RSDHT_RELAY_ENABLED | RSDHT_RELAY_MODE_OFF; RsDhtRelayMode mode = RsDhtRelayMode::ENABLED | RsDhtRelayMode::OFF;
setRelayMode(mode); setRelayMode(mode);
return 1; return 1;
@ -111,19 +111,19 @@ int p3BitDht::pushRelayServers()
} }
uint32_t p3BitDht::getRelayMode() RsDhtRelayMode p3BitDht::getRelayMode()
{ {
RsStackMutex stack(dhtMtx); /*********** LOCKED **********/ RsStackMutex stack(dhtMtx); /*********** LOCKED **********/
return mRelayMode; return mRelayMode;
} }
int p3BitDht::setRelayMode(uint32_t mode) int p3BitDht::setRelayMode(RsDhtRelayMode mode)
{ {
std::cerr << "p3BitDht::setRelayMode(" << mode << ")"; std::cerr << "p3BitDht::setRelayMode(" << mode << ")";
std::cerr << std::endl; std::cerr << std::endl;
if (mode & RSDHT_RELAY_ENABLED) if (!!(mode & RsDhtRelayMode::ENABLED))
{ {
mUdpBitDht->ConnectionOptions( mUdpBitDht->ConnectionOptions(
BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY, BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY,
@ -136,18 +136,18 @@ int p3BitDht::setRelayMode(uint32_t mode)
BITDHT_CONNECT_OPTION_AUTOPROXY); BITDHT_CONNECT_OPTION_AUTOPROXY);
} }
int relaymode = mode & RSDHT_RELAY_MODE_MASK; RsDhtRelayMode relaymode = mode & RsDhtRelayMode::MASK;
switch(relaymode) switch(relaymode)
{ {
case RSDHT_RELAY_MODE_OFF: case RsDhtRelayMode::OFF:
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_IGNORED); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_IGNORED);
break; break;
case RSDHT_RELAY_MODE_ON: case RsDhtRelayMode::ON:
pushRelayServers(); pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_FLAGGED); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_FLAGGED);
break; break;
case RSDHT_RELAY_MODE_SERVER: case RsDhtRelayMode::SERVER:
pushRelayServers(); pushRelayServers();
mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_SERVER); mUdpBitDht->setDhtMode(BITDHT_MODE_RELAYSERVERS_SERVER);
break; break;
@ -163,13 +163,13 @@ int p3BitDht::setRelayMode(uint32_t mode)
return 1; return 1;
} }
int p3BitDht::getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) int p3BitDht::getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth)
{ {
std::cerr << "p3BitDht::getRelayAllowance(" << classIdx << "): "; std::cerr << "p3BitDht::getRelayAllowance(" << static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx) << "): ";
if ((classIdx >= 0) && (classIdx < RSDHT_RELAY_NUM_CLASS)) if ((classIdx >= RsDhtRelayClass::ALL) && (classIdx < RsDhtRelayClass::NUM_CLASS))
{ {
count = mRelay->getRelayClassMax(classIdx); count = mRelay->getRelayClassMax(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx));
bandwidth = mRelay->getRelayClassBandwidth(classIdx); bandwidth = mRelay->getRelayClassBandwidth(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx));
std::cerr << " count: " << count << " bandwidth: " << bandwidth; std::cerr << " count: " << count << " bandwidth: " << bandwidth;
std::cerr << std::endl; std::cerr << std::endl;
@ -181,13 +181,13 @@ int p3BitDht::getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwid
return 0; return 0;
} }
int p3BitDht::setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) int p3BitDht::setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth)
{ {
std::cerr << "p3BitDht::getRelayAllowance(" << classIdx << ", "; std::cerr << "p3BitDht::getRelayAllowance(" << static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx) << ", ";
std::cerr << ", " << count << ", " << bandwidth << ")"; std::cerr << ", " << count << ", " << bandwidth << ")";
std::cerr << std::endl; std::cerr << std::endl;
int retval = mRelay->setRelayClassMax(classIdx, count, bandwidth); int retval = mRelay->setRelayClassMax(static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(classIdx), count, bandwidth);
IndicateConfigChanged(); IndicateConfigChanged();
return retval; return retval;
@ -224,7 +224,7 @@ bool p3BitDht::saveList(bool &cleanup, std::list<RsItem *> &saveList)
/* Push Relay Class Stuff */ /* Push Relay Class Stuff */
int i; int i;
for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) for(i = 0; i < static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS); ++i)
{ {
rs_sprintf(kv.key, "RELAY_CLASS%d_COUNT", i); rs_sprintf(kv.key, "RELAY_CLASS%d_COUNT", i);
rs_sprintf(kv.value, "%d", mRelay->getRelayClassMax(i)); rs_sprintf(kv.value, "%d", mRelay->getRelayClassMax(i));
@ -302,11 +302,11 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
//config->print(std::cerr, 0); //config->print(std::cerr, 0);
std::list<std::string> servers; std::list<std::string> servers;
int peers[RSDHT_RELAY_NUM_CLASS] = {0}; int peers[static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)] = {0};
int bandwidth[RSDHT_RELAY_NUM_CLASS] = {0}; int bandwidth[static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)] = {0};
bool haveMode = false; bool haveMode = false;
int mode = 0; RsDhtRelayMode mode = RsDhtRelayMode::DISABLED;
std::list<RsTlvKeyValue>::iterator it; std::list<RsTlvKeyValue>::iterator it;
for(it = config->tlvkvs.pairs.begin(); it != config->tlvkvs.pairs.end(); ++it) for(it = config->tlvkvs.pairs.begin(); it != config->tlvkvs.pairs.end(); ++it)
@ -322,7 +322,7 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
} }
else if (0 == strncmp(key.c_str(), "RELAY_MODE", 10)) else if (0 == strncmp(key.c_str(), "RELAY_MODE", 10))
{ {
mode = atoi(value.c_str()); mode = static_cast<RsDhtRelayMode>(atoi(value.c_str()));
haveMode = true; haveMode = true;
//std::cerr << "p3BitDht::loadList() Found Mode: " << mode; //std::cerr << "p3BitDht::loadList() Found Mode: " << mode;
@ -386,7 +386,7 @@ bool p3BitDht::loadList(std::list<RsItem *>& load)
} }
int i; int i;
for(i = 0; i < RSDHT_RELAY_NUM_CLASS; ++i) for(i = 0; i < static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS); ++i)
{ {
mRelay->setRelayClassMax(i, peers[i], bandwidth[i]); mRelay->setRelayClassMax(i, peers[i], bandwidth[i]);
} }

View file

@ -388,6 +388,11 @@ void p3discovery2::recvOwnContactInfo(const RsPeerId &fromId, const RsDiscContac
setPeerVersion(fromId, item->version); setPeerVersion(fromId, item->version);
// Hidden nodes do not need IP information. So that information is dropped.
// However, that doesn't mean hidden nodes do not know that information. Normally
// normal nodes should not send it, but old nodes still do.
if(!mPeerMgr->isHiddenNode(rsPeers->getOwnId()))
updatePeerAddresses(item); updatePeerAddresses(item);
// if the peer is not validated, we stop the exchange here // if the peer is not validated, we stop the exchange here

View file

@ -1063,8 +1063,12 @@ void p3LinkMgrIMPL::peerStatus(const RsPeerId& id, const pqiIpAddrSet &addrs,
uint32_t peer_vs_dht = 0; uint32_t peer_vs_dht = 0;
uint32_t peerNetMode = 0; uint32_t peerNetMode = 0;
uint32_t ownNetMode = mNetMgr->getNetworkMode(); int ownNetMode;
{
peerState ps;
mPeerMgr->getOwnNetStatus(ps);
ownNetMode = ps.netMode;
}
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/

View file

@ -124,8 +124,8 @@ p3NetMgrIMPL::p3NetMgrIMPL() : mPeerMgr(nullptr), mLinkMgr(nullptr),
mNetFlags = pqiNetStatus(); mNetFlags = pqiNetStatus();
mOldNetFlags = pqiNetStatus(); mOldNetFlags = pqiNetStatus();
mOldNatType = RSNET_NATTYPE_UNKNOWN; mOldNatType = RsNatTypeMode::UNKNOWN;
mOldNatHole = RSNET_NATHOLE_UNKNOWN; mOldNatHole = RsNatHoleMode::UNKNOWN;
sockaddr_storage_clear(mLocalAddr); sockaddr_storage_clear(mLocalAddr);
sockaddr_storage_clear(mExtAddr); sockaddr_storage_clear(mExtAddr);
@ -1629,31 +1629,31 @@ void p3NetMgrIMPL::setIPServersEnabled(bool b)
************************************** NetStateBox ****************************************** ************************************** NetStateBox ******************************************
**********************************************************************************************/ **********************************************************************************************/
uint32_t p3NetMgrIMPL::getNetStateMode() RsNetState p3NetMgrIMPL::getNetStateMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetStateMode(); return mNetStateBox.getNetStateMode();
} }
uint32_t p3NetMgrIMPL::getNetworkMode() RsNetworkMode p3NetMgrIMPL::getNetworkMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNetworkMode(); return mNetStateBox.getNetworkMode();
} }
uint32_t p3NetMgrIMPL::getNatTypeMode() RsNatTypeMode p3NetMgrIMPL::getNatTypeMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatTypeMode(); return mNetStateBox.getNatTypeMode();
} }
uint32_t p3NetMgrIMPL::getNatHoleMode() RsNatHoleMode p3NetMgrIMPL::getNatHoleMode()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getNatHoleMode(); return mNetStateBox.getNatHoleMode();
} }
uint32_t p3NetMgrIMPL::getConnectModes() RsConnectModes p3NetMgrIMPL::getConnectModes()
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
return mNetStateBox.getConnectModes(); return mNetStateBox.getConnectModes();
@ -1768,8 +1768,8 @@ void p3NetMgrIMPL::updateNetStateBox_temporal()
void p3NetMgrIMPL::updateNatSetting() void p3NetMgrIMPL::updateNatSetting()
{ {
bool updateRefreshRate = false; bool updateRefreshRate = false;
uint32_t natType = RSNET_NATTYPE_UNKNOWN; RsNatTypeMode natType = RsNatTypeMode::UNKNOWN;
uint32_t natHole = RSNET_NATHOLE_UNKNOWN; RsNatHoleMode natHole = RsNatHoleMode::UNKNOWN;
{ {
RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mNetMtx); /****** STACK LOCK MUTEX *******/
@ -1806,9 +1806,9 @@ void p3NetMgrIMPL::updateNatSetting()
if (mProxyStunner) { if (mProxyStunner) {
switch(natType) switch(natType)
{ {
case RSNET_NATTYPE_RESTRICTED_CONE: case RsNatTypeMode::RESTRICTED_CONE:
{ {
if ((natHole == RSNET_NATHOLE_NONE) || (natHole == RSNET_NATHOLE_UNKNOWN)) if ((natHole == RsNatHoleMode::NONE) || (natHole == RsNatHoleMode::UNKNOWN))
{ {
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_FAST); mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_FAST);
} }
@ -1818,12 +1818,12 @@ void p3NetMgrIMPL::updateNatSetting()
} }
break; break;
} }
case RSNET_NATTYPE_NONE: case RsNatTypeMode::NONE:
case RSNET_NATTYPE_UNKNOWN: case RsNatTypeMode::UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC: case RsNatTypeMode::SYMMETRIC:
case RSNET_NATTYPE_DETERM_SYM: case RsNatTypeMode::DETERM_SYM:
case RSNET_NATTYPE_FULL_CONE: case RsNatTypeMode::FULL_CONE:
case RSNET_NATTYPE_OTHER: case RsNatTypeMode::OTHER:
mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW); mProxyStunner->setRefreshPeriod(NET_STUNNER_PERIOD_SLOW);
break; break;
@ -1836,22 +1836,22 @@ void p3NetMgrIMPL::updateNatSetting()
* So that messages can get through. * So that messages can get through.
* We only want to be attached - if we don't have a stable DHT port. * We only want to be attached - if we don't have a stable DHT port.
*/ */
if ((natHole == RSNET_NATHOLE_NONE) || (natHole == RSNET_NATHOLE_UNKNOWN)) if ((natHole == RsNatHoleMode::NONE) || (natHole == RsNatHoleMode::UNKNOWN))
{ {
switch(natType) switch(natType)
{ {
/* switch to attach mode if we have a bad firewall */ /* switch to attach mode if we have a bad firewall */
case RSNET_NATTYPE_UNKNOWN: case RsNatTypeMode::UNKNOWN:
case RSNET_NATTYPE_SYMMETRIC: case RsNatTypeMode::SYMMETRIC:
case RSNET_NATTYPE_RESTRICTED_CONE: case RsNatTypeMode::RESTRICTED_CONE:
case RSNET_NATTYPE_DETERM_SYM: case RsNatTypeMode::DETERM_SYM:
case RSNET_NATTYPE_OTHER: case RsNatTypeMode::OTHER:
netAssistAttach(true); netAssistAttach(true);
break; break;
/* switch off attach mode if we have a nice firewall */ /* switch off attach mode if we have a nice firewall */
case RSNET_NATTYPE_NONE: case RsNatTypeMode::NONE:
case RSNET_NATTYPE_FULL_CONE: case RsNatTypeMode::FULL_CONE:
netAssistAttach(false); netAssistAttach(false);
break; break;
} }
@ -1970,8 +1970,8 @@ void p3NetMgrIMPL::updateNetStateBox_reset()
mNetStateBox.reset(); mNetStateBox.reset();
mOldNatHole = RSNET_NATHOLE_UNKNOWN; mOldNatHole = RsNatHoleMode::UNKNOWN;
mOldNatType = RSNET_NATTYPE_UNKNOWN; mOldNatType = RsNatTypeMode::UNKNOWN;
} }
} }

View file

@ -103,11 +103,11 @@ virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reas
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0; virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode) = 0;
/* Get Network State */ /* Get Network State */
virtual uint32_t getNetStateMode() = 0; virtual RsNetState getNetStateMode() = 0;
virtual uint32_t getNetworkMode() = 0; virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0; virtual RsNatHoleMode getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0; virtual RsConnectModes getConnectModes() = 0;
/* Shut It Down! */ /* Shut It Down! */
virtual bool shutdown() = 0; /* blocking shutdown call */ virtual bool shutdown() = 0; /* blocking shutdown call */
@ -154,11 +154,11 @@ virtual bool netAssistBadPeer(const struct sockaddr_storage &addr, uint32_t reas
virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode); virtual bool netAssistStatusUpdate(const RsPeerId &id, int mode);
/* Get Network State */ /* Get Network State */
virtual uint32_t getNetStateMode(); virtual RsNetState getNetStateMode();
virtual uint32_t getNetworkMode(); virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode(); virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode(); virtual RsNatHoleMode getNatHoleMode();
virtual uint32_t getConnectModes(); virtual RsConnectModes getConnectModes();
/* Shut It Down! */ /* Shut It Down! */
virtual bool shutdown(); /* blocking shutdown call */ virtual bool shutdown(); /* blocking shutdown call */
@ -323,8 +323,8 @@ void netStatusReset_locked();
pqiNetStateBox mNetStateBox; pqiNetStateBox mNetStateBox;
rstime_t mDoNotNetCheckUntilTs; rstime_t mDoNotNetCheckUntilTs;
uint32_t mOldNatType; RsNatTypeMode mOldNatType;
uint32_t mOldNatHole; RsNatHoleMode mOldNatHole;
RS_SET_CONTEXT_DEBUG_LEVEL(2) RS_SET_CONTEXT_DEBUG_LEVEL(2)
}; };

View file

@ -20,7 +20,6 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include "retroshare/rsconfig.h"
#include "util/rsnet.h" #include "util/rsnet.h"
#include "pqi/pqinetstatebox.h" #include "pqi/pqinetstatebox.h"
#include "util/rstime.h" #include "util/rstime.h"
@ -147,32 +146,32 @@ void pqiNetStateBox::setDhtState(bool on, bool active)
/* Extract Net State */ /* Extract Net State */
uint32_t pqiNetStateBox::getNetworkMode() RsNetworkMode pqiNetStateBox::getNetworkMode()
{ {
updateNetState(); updateNetState();
return mNetworkMode; return mNetworkMode;
} }
uint32_t pqiNetStateBox::getNatTypeMode() RsNatTypeMode pqiNetStateBox::getNatTypeMode()
{ {
updateNetState(); updateNetState();
return mNatTypeMode; return mNatTypeMode;
} }
uint32_t pqiNetStateBox::getNatHoleMode() RsNatHoleMode pqiNetStateBox::getNatHoleMode()
{ {
updateNetState(); updateNetState();
return mNatHoleMode; return mNatHoleMode;
} }
uint32_t pqiNetStateBox::getConnectModes() RsConnectModes pqiNetStateBox::getConnectModes()
{ {
updateNetState(); updateNetState();
return mConnectModes; return mConnectModes;
} }
uint32_t pqiNetStateBox::getNetStateMode() RsNetState pqiNetStateBox::getNetStateMode()
{ {
updateNetState(); updateNetState();
return mNetStateMode; return mNetStateMode;
@ -193,11 +192,11 @@ void pqiNetStateBox::reset()
mStatusOkay = false; mStatusOkay = false;
//rstime_t mStatusTS; //rstime_t mStatusTS;
mNetworkMode = RSNET_NETWORK_UNKNOWN; mNetworkMode = RsNetworkMode::UNKNOWN;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UNKNOWN; mNatHoleMode = RsNatHoleMode::UNKNOWN;
mConnectModes = RSNET_CONNECT_NONE; mConnectModes = RsConnectModes::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN; mNetStateMode = RsNetState::BAD_UNKNOWN;
/* Parameters set externally */ /* Parameters set externally */
@ -302,11 +301,11 @@ void pqiNetStateBox::determineNetworkState()
/* firstly lets try to identify OFFLINE / UNKNOWN */ /* firstly lets try to identify OFFLINE / UNKNOWN */
if ((!mStunProxySet) || (!mStunDhtSet)) if ((!mStunProxySet) || (!mStunDhtSet))
{ {
mNetworkMode = RSNET_NETWORK_UNKNOWN; mNetworkMode = RsNetworkMode::UNKNOWN;
// Assume these. // Assume these.
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_UNKNOWN; mNetStateMode = RsNetState::BAD_UNKNOWN;
//mExtAddress = .... unknown; //mExtAddress = .... unknown;
//mExtAddrStable = false; //mExtAddrStable = false;
@ -335,19 +334,19 @@ void pqiNetStateBox::determineNetworkState()
* *
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM; mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
else if (!mStunProxyStable) else if (!mStunProxyStable)
{ {
/* both unstable, Symmetric NAT, Firewalled, No UDP Hole */ /* both unstable, Symmetric NAT, Firewalled, No UDP Hole */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC; mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NATSYM; mNetStateMode = RsNetState::BAD_NATSYM;
} }
else else
{ {
@ -366,10 +365,10 @@ void pqiNetStateBox::determineNetworkState()
* but that label is really fully accurate. (gray area). * but that label is really fully accurate. (gray area).
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_RESTRICTED_CONE; mNatTypeMode = RsNatTypeMode::RESTRICTED_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
} }
else // Dht Stable. else // Dht Stable.
@ -392,47 +391,47 @@ void pqiNetStateBox::determineNetworkState()
if (mStunProxySemiStable) if (mStunProxySemiStable)
{ {
/* must be a forwarded port/ext or something similar */ /* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_DETERM_SYM; mNatTypeMode = RsNatTypeMode::DETERM_SYM;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
} }
else if (!mStunProxyStable) else if (!mStunProxyStable)
{ {
/* must be a forwarded port/ext or something similar */ /* must be a forwarded port/ext or something similar */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_SYMMETRIC; mNatTypeMode = RsNatTypeMode::SYMMETRIC;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
} }
else else
{ {
/* fallback is FULL CONE NAT */ /* fallback is FULL CONE NAT */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_FULL_CONE; mNatTypeMode = RsNatTypeMode::FULL_CONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_WARNING_NATTED; mNetStateMode = RsNetState::WARNING_NATTED;
} }
if (mUPnPActive) if (mUPnPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP; mNatHoleMode = RsNatHoleMode::UPNP;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddress = ... from UPnP, should match StunDht. //mExtAddress = ... from UPnP, should match StunDht.
//mExtAddrStable = true; //mExtAddrStable = true;
} }
else if (mNatPMPActive) else if (mNatPMPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP; mNatHoleMode = RsNatHoleMode::NATPMP;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddress = ... from NatPMP, should match NatPMP //mExtAddress = ... from NatPMP, should match NatPMP
//mExtAddrStable = true; //mExtAddrStable = true;
} }
@ -442,20 +441,20 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress) if (isExtAddress)
{ {
mNetworkMode = RSNET_NETWORK_EXTERNALIP; mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE; mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_GOOD; mNetStateMode = RsNetState::GOOD;
//mExtAddrStable = true; //mExtAddrStable = true;
} }
else if (mPortForwardSet) else if (mPortForwardSet)
{ {
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
// Use Fallback Guess. // Use Fallback Guess.
//mNatTypeMode = RSNET_NATTYPE_UNKNOWN; //mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
mNetStateMode = RSNET_NETSTATE_ADV_FORWARD; mNetStateMode = RsNetState::ADV_FORWARD;
//mExtAddrStable = true; // Probably, makin assumption. //mExtAddrStable = true; // Probably, makin assumption.
} }
@ -479,22 +478,22 @@ void pqiNetStateBox::determineNetworkState()
if (mUPnPActive) if (mUPnPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_UPNP; mNatHoleMode = RsNatHoleMode::UPNP;
//mExtAddress = ... from UPnP. //mExtAddress = ... from UPnP.
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else if (mNatPMPActive) else if (mNatPMPActive)
{ {
// This Mode is OKAY. // This Mode is OKAY.
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NATPMP; mNatHoleMode = RsNatHoleMode::NATPMP;
//mExtAddress = ... from NatPMP. //mExtAddress = ... from NatPMP.
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else else
{ {
@ -506,21 +505,21 @@ void pqiNetStateBox::determineNetworkState()
if (isExtAddress) if (isExtAddress)
{ {
mNetworkMode = RSNET_NETWORK_EXTERNALIP; mNetworkMode = RsNetworkMode::EXTERNALIP;
mNatTypeMode = RSNET_NATTYPE_NONE; mNatTypeMode = RsNatTypeMode::NONE;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
//mExtAddrStable = true; //mExtAddrStable = true;
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else if (mPortForwardSet) else if (mPortForwardSet)
{ {
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_FORWARDED; mNatHoleMode = RsNatHoleMode::FORWARDED;
//mExtAddrStable = true; // Probably, makin assumption. //mExtAddrStable = true; // Probably, makin assumption.
mNetStateMode = RSNET_NETSTATE_WARNING_NODHT; mNetStateMode = RsNetState::WARNING_NODHT;
} }
else else
{ {
@ -528,10 +527,10 @@ void pqiNetStateBox::determineNetworkState()
* These people have destroyed the possibility of making connections ;( * These people have destroyed the possibility of making connections ;(
* Should WARN about this. * Should WARN about this.
*/ */
mNetworkMode = RSNET_NETWORK_BEHINDNAT; mNetworkMode = RsNetworkMode::BEHINDNAT;
mNatTypeMode = RSNET_NATTYPE_UNKNOWN; mNatTypeMode = RsNatTypeMode::UNKNOWN;
mNatHoleMode = RSNET_NATHOLE_NONE; mNatHoleMode = RsNatHoleMode::NONE;
mNetStateMode = RSNET_NETSTATE_BAD_NODHT_NAT; mNetStateMode = RsNetState::BAD_NODHT_NAT;
//mExtAddrStable = false; // Unlikely to be stable. //mExtAddrStable = false; // Unlikely to be stable.
} }
@ -553,42 +552,43 @@ void pqiNetStateBox::determineNetworkState()
void pqiNetStateBox::workoutNetworkMode() void pqiNetStateBox::workoutNetworkMode()
{ {
/* connectModes are dependent on the other modes */ /* connectModes are dependent on the other modes */
mConnectModes = RSNET_CONNECT_NONE; mConnectModes = RsConnectModes::NONE;
switch(mNetworkMode) switch(mNetworkMode)
{ {
case RSNET_NETWORK_UNKNOWN: case RsNetworkMode::UNKNOWN:
case RSNET_NETWORK_OFFLINE: case RsNetworkMode::OFFLINE:
case RSNET_NETWORK_LOCALNET: case RsNetworkMode::LOCALNET:
case RsNetworkMode::RESTARTING:
/* nothing here */ /* nothing here */
break; break;
case RSNET_NETWORK_EXTERNALIP: case RsNetworkMode::EXTERNALIP:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP; mConnectModes = RsConnectModes::OUTGOING_TCP;
mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; mConnectModes |= RsConnectModes::ACCEPT_TCP;
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
/* if open port. don't want PROXY or RELAY connect /* if open port. don't want PROXY or RELAY connect
* because we should be able to do direct with EVERYONE. * because we should be able to do direct with EVERYONE.
* Ability to do Proxy is dependent on FIREWALL status. * Ability to do Proxy is dependent on FIREWALL status.
* Technically could do RELAY, but disable both. * Technically could do RELAY, but disable both.
*/ */
//mConnectModes |= RSNET_CONNECT_PROXY_UDP; //mConnectModes |= RsConnectModes::PROXY_UDP;
//mConnectModes |= RSNET_CONNECT_RELAY_UDP; //mConnectModes |= RsConnectModes::RELAY_UDP;
} }
break; break;
case RSNET_NETWORK_BEHINDNAT: case RsNetworkMode::BEHINDNAT:
mConnectModes = RSNET_CONNECT_OUTGOING_TCP; mConnectModes = RsConnectModes::OUTGOING_TCP;
/* we're okay if there's a NAT HOLE */ /* we're okay if there's a NAT HOLE */
if ((mNatHoleMode == RSNET_NATHOLE_UPNP) || if ((mNatHoleMode == RsNatHoleMode::UPNP) ||
(mNatHoleMode == RSNET_NATHOLE_NATPMP) || (mNatHoleMode == RsNatHoleMode::NATPMP) ||
(mNatHoleMode == RSNET_NATHOLE_FORWARDED)) (mNatHoleMode == RsNatHoleMode::FORWARDED))
{ {
mConnectModes |= RSNET_CONNECT_ACCEPT_TCP; mConnectModes |= RsConnectModes::ACCEPT_TCP;
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
/* dont want PROXY | RELAY with open ports */ /* dont want PROXY | RELAY with open ports */
} }
} }
@ -600,175 +600,17 @@ void pqiNetStateBox::workoutNetworkMode()
*/ */
if (mDhtActive) if (mDhtActive)
{ {
mConnectModes |= RSNET_CONNECT_DIRECT_UDP; mConnectModes |= RsConnectModes::DIRECT_UDP;
mConnectModes |= RSNET_CONNECT_RELAY_UDP; mConnectModes |= RsConnectModes::RELAY_UDP;
if ((mNatTypeMode == RSNET_NATTYPE_RESTRICTED_CONE) || if ((mNatTypeMode == RsNatTypeMode::RESTRICTED_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_FULL_CONE) || (mNatTypeMode == RsNatTypeMode::FULL_CONE) ||
(mNatTypeMode == RSNET_NATTYPE_DETERM_SYM)) (mNatTypeMode == RsNatTypeMode::DETERM_SYM))
{ {
mConnectModes |= RSNET_CONNECT_PROXY_UDP; mConnectModes |= RsConnectModes::PROXY_UDP;
} }
} }
} }
break; break;
} }
} }
std::string NetStateNetworkModeString(uint32_t netMode)
{
std::string str;
switch(netMode)
{
default:
case RSNET_NETWORK_UNKNOWN:
str = "Unknown NetState";
break;
case RSNET_NETWORK_OFFLINE:
str = "Offline";
break;
case RSNET_NETWORK_LOCALNET:
str = "Local Net";
break;
case RSNET_NETWORK_BEHINDNAT:
str = "Behind NAT";
break;
case RSNET_NETWORK_EXTERNALIP:
str = "External IP";
break;
}
return str;
}
std::string NetStateNatTypeString(uint32_t natType)
{
std::string str;
switch(natType)
{
default:
case RSNET_NATTYPE_UNKNOWN:
str = "UNKNOWN NAT STATE";
break;
case RSNET_NATTYPE_SYMMETRIC:
str = "SYMMETRIC NAT";
break;
case RSNET_NATTYPE_DETERM_SYM:
str = "DETERMINISTIC SYM NAT";
break;
case RSNET_NATTYPE_RESTRICTED_CONE:
str = "RESTRICTED CONE NAT";
break;
case RSNET_NATTYPE_FULL_CONE:
str = "FULL CONE NAT";
break;
case RSNET_NATTYPE_OTHER:
str = "OTHER NAT";
break;
case RSNET_NATTYPE_NONE:
str = "NO NAT";
break;
}
return str;
}
std::string NetStateNatHoleString(uint32_t natHole)
{
std::string str;
switch(natHole)
{
default:
case RSNET_NATHOLE_UNKNOWN:
str = "UNKNOWN NAT HOLE STATUS";
break;
case RSNET_NATHOLE_NONE:
str = "NO NAT HOLE";
break;
case RSNET_NATHOLE_UPNP:
str = "UPNP FORWARD";
break;
case RSNET_NATHOLE_NATPMP:
str = "NATPMP FORWARD";
break;
case RSNET_NATHOLE_FORWARDED:
str = "MANUAL FORWARD";
break;
}
return str;
}
std::string NetStateConnectModesString(uint32_t connect)
{
std::string connOut;
if (connect & RSNET_CONNECT_OUTGOING_TCP)
{
connOut += "TCP_OUT ";
}
if (connect & RSNET_CONNECT_ACCEPT_TCP)
{
connOut += "TCP_IN ";
}
if (connect & RSNET_CONNECT_DIRECT_UDP)
{
connOut += "DIRECT_UDP ";
}
if (connect & RSNET_CONNECT_PROXY_UDP)
{
connOut += "PROXY_UDP ";
}
if (connect & RSNET_CONNECT_RELAY_UDP)
{
connOut += "RELAY_UDP ";
}
return connOut;
}
std::string NetStateNetStateString(uint32_t netstate)
{
std::string str;
switch(netstate)
{
case RSNET_NETSTATE_BAD_UNKNOWN:
str = "NET BAD: Unknown State";
break;
case RSNET_NETSTATE_BAD_OFFLINE:
str = "NET BAD: Offline";
break;
case RSNET_NETSTATE_BAD_NATSYM:
str = "NET BAD: Behind Symmetric NAT";
break;
case RSNET_NETSTATE_BAD_NODHT_NAT:
str = "NET BAD: Behind NAT & No DHT";
break;
case RSNET_NETSTATE_WARNING_RESTART:
str = "NET WARNING: NET Restart";
break;
case RSNET_NETSTATE_WARNING_NATTED:
str = "NET WARNING: Behind NAT";
break;
case RSNET_NETSTATE_WARNING_NODHT:
str = "NET WARNING: No DHT";
break;
case RSNET_NETSTATE_GOOD:
str = "NET STATE GOOD!";
break;
case RSNET_NETSTATE_ADV_FORWARD:
str = "CAUTION: UNVERIFABLE FORWARD!";
break;
case RSNET_NETSTATE_ADV_DARK_FORWARD:
str = "CAUTION: UNVERIFABLE FORWARD & NO DHT";
break;
}
return str;
}

View file

@ -27,6 +27,9 @@
#include <string> #include <string>
#include <list> #include <list>
#include <util/rstime.h>
#include <retroshare/rsconfig.h>
/*** Network state /*** Network state
* Want this to be all encompassing. * Want this to be all encompassing.
* *
@ -51,11 +54,11 @@ class pqiNetStateBox
void setDhtState(bool dhtOn, bool dhtActive); void setDhtState(bool dhtOn, bool dhtActive);
uint32_t getNetStateMode(); RsNetState getNetStateMode();
uint32_t getNetworkMode(); RsNetworkMode getNetworkMode();
uint32_t getNatTypeMode(); RsNatTypeMode getNatTypeMode();
uint32_t getNatHoleMode(); RsNatHoleMode getNatHoleMode();
uint32_t getConnectModes(); RsConnectModes getConnectModes();
private: private:
@ -71,11 +74,11 @@ class pqiNetStateBox
bool mStatusOkay; bool mStatusOkay;
rstime_t mStatusTS; rstime_t mStatusTS;
uint32_t mNetworkMode; RsNetworkMode mNetworkMode;
uint32_t mNatTypeMode; RsNatTypeMode mNatTypeMode;
uint32_t mNatHoleMode; RsNatHoleMode mNatHoleMode;
uint32_t mConnectModes; RsConnectModes mConnectModes;
uint32_t mNetStateMode; RsNetState mNetStateMode;
/* Parameters set externally */ /* Parameters set externally */
@ -114,13 +117,4 @@ class pqiNetStateBox
uint16_t mPortForwarded; uint16_t mPortForwarded;
}; };
std::string NetStateNetStateString(uint32_t netstate);
std::string NetStateConnectModesString(uint32_t connect);
std::string NetStateNatHoleString(uint32_t natHole);
std::string NetStateNatTypeString(uint32_t natType);
std::string NetStateNetworkModeString(uint32_t netMode);
#endif #endif

View file

@ -37,77 +37,82 @@ class RsServerConfig;
*/ */
extern RsServerConfig *rsConfig; extern RsServerConfig *rsConfig;
#define RSNET_NETWORK_UNKNOWN 1 enum class RsNetworkMode : uint8_t
#define RSNET_NETWORK_RESTARTING 2 {
#define RSNET_NETWORK_OFFLINE 3 UNKNOWN = 1,
#define RSNET_NETWORK_LOCALNET 4 RESTARTING = 2,
#define RSNET_NETWORK_BEHINDNAT 5 OFFLINE = 3,
#define RSNET_NETWORK_EXTERNALIP 6 LOCALNET = 4,
BEHINDNAT = 5,
EXTERNALIP = 6
};
// WHAT TYPE OF FIREWALL? enum class RsNatTypeMode : uint8_t
#define RSNET_NATTYPE_NONE 1 {
#define RSNET_NATTYPE_UNKNOWN 2 NONE = 1,
#define RSNET_NATTYPE_SYMMETRIC 3 UNKNOWN = 2,
#define RSNET_NATTYPE_DETERM_SYM 4 SYMMETRIC = 3,
#define RSNET_NATTYPE_RESTRICTED_CONE 5 DETERM_SYM = 4,
#define RSNET_NATTYPE_FULL_CONE 6 RESTRICTED_CONE = 5,
#define RSNET_NATTYPE_OTHER 7 FULL_CONE = 6,
OTHER = 7
};
// WHAT TYPE OF HOLE? enum class RsNatHoleMode : uint8_t
#define RSNET_NATHOLE_UNKNOWN 0 {
#define RSNET_NATHOLE_NONE 1 UNKNOWN = 0,
#define RSNET_NATHOLE_UPNP 2 NONE = 1,
#define RSNET_NATHOLE_NATPMP 3 UPNP = 2,
#define RSNET_NATHOLE_FORWARDED 4 NATPMP = 3,
FORWARDED = 4
};
// Types of Connections. enum class RsConnectModes : uint16_t
#define RSNET_CONNECT_NONE 0x0000 {
#define RSNET_CONNECT_ACCEPT_TCP 0x0001 NONE = 0x0000,
#define RSNET_CONNECT_OUTGOING_TCP 0x0002 ACCEPT_TCP = 0x0001,
#define RSNET_CONNECT_DIRECT_UDP 0x0100 OUTGOING_TCP= 0x0002,
#define RSNET_CONNECT_PROXY_UDP 0x0200 DIRECT_UDP = 0x0100,
#define RSNET_CONNECT_RELAY_UDP 0x0400 PROXY_UDP = 0x0200,
RELAY_UDP = 0x0400
};
RS_REGISTER_ENUM_FLAGS_TYPE(RsConnectModes)
// net state (good, okay, bad) enum class RsNetState : uint8_t
{
// BAD. (RED) // BAD. (RED)
#define RSNET_NETSTATE_BAD_UNKNOWN 1 BAD_UNKNOWN = 1,
#define RSNET_NETSTATE_BAD_OFFLINE 2 BAD_OFFLINE = 2,
#define RSNET_NETSTATE_BAD_NATSYM 3 BAD_NATSYM = 3,
#define RSNET_NETSTATE_BAD_NODHT_NAT 4 BAD_NODHT_NAT = 4,
// CAUTION. (ORANGE) // CAUTION. (ORANGE)
#define RSNET_NETSTATE_WARNING_RESTART 5 WARNING_RESTART = 5,
#define RSNET_NETSTATE_WARNING_NATTED 6 WARNING_NATTED = 6,
#define RSNET_NETSTATE_WARNING_NODHT 7 WARNING_NODHT = 7,
// GOOD (GREEN) // GOOD (GREEN)
// NAT with forwarded port, or EXT port. // NAT with forwarded port, or EXT port.
#define RSNET_NETSTATE_GOOD 8 GOOD = 8,
// ADVANCED MODE (BLUE) // ADVANCED MODE (BLUE)
// If the user knows what they are doing... we cannot confirm this. // If the user knows what they are doing... we cannot confirm this.
#define RSNET_NETSTATE_ADV_FORWARD 9 ADV_FORWARD = 9,
#define RSNET_NETSTATE_ADV_DARK_FORWARD 10 ADV_DARK_FORWARD= 10
};
/* matched to the uPnP states */
#define UPNP_STATE_UNINITIALISED 0
#define UPNP_STATE_UNAVAILABILE 1
#define UPNP_STATE_READY 2
#define UPNP_STATE_FAILED_TCP 3
#define UPNP_STATE_FAILED_UDP 4
#define UPNP_STATE_ACTIVE 5
/************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/ /************************** Indicate How experienced the RsUser is... based on Friends / Firewall status ******/
#define RSCONFIG_USER_LEVEL_NEW 0x0001 /* no friends */ enum class RsConfigUserLvl : uint8_t
#define RSCONFIG_USER_LEVEL_BASIC 0x0002 /* no connections */ {
#define RSCONFIG_USER_LEVEL_CASUAL 0x0003 /* firewalled */ NEW = 1, /* no friends */
#define RSCONFIG_USER_LEVEL_POWER 0x0004 /* good! */ BASIC = 2, /* no connections */
#define RSCONFIG_USER_LEVEL_OVERRIDE 0x0005 /* forced to POWER level */ CASUAL = 3, /* firewalled */
POWER = 4, /* good! */
OVERRIDE= 5 /* forced to POWER level */
};
@ -115,10 +120,13 @@ extern RsServerConfig *rsConfig;
#define RS_CONFIG_ADVANCED 0x0101 #define RS_CONFIG_ADVANCED 0x0101
#define RS_OPMODE_FULL 0x0001 enum class RsOpMode : uint8_t
#define RS_OPMODE_NOTURTLE 0x0002 {
#define RS_OPMODE_GAMING 0x0003 FULL = 1,
#define RS_OPMODE_MINIMAL 0x0004 NOTURTLE= 2,
GAMING = 3,
MINIMAL = 4
};
class RsConfigStartup class RsConfigStartup
@ -348,13 +356,13 @@ public:
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel() = 0; virtual RsConfigUserLvl getUserLevel() = 0;
virtual uint32_t getNetState() = 0; virtual RsNetState getNetState() = 0;
virtual uint32_t getNetworkMode() = 0; virtual RsNetworkMode getNetworkMode() = 0;
virtual uint32_t getNatTypeMode() = 0; virtual RsNatTypeMode getNatTypeMode() = 0;
virtual uint32_t getNatHoleMode() = 0; virtual RsNatHoleMode getNatHoleMode() = 0;
virtual uint32_t getConnectModes() = 0; virtual RsConnectModes getConnectModes() = 0;
virtual bool getConfigurationOption(uint32_t key, std::string &opt) = 0; virtual bool getConfigurationOption(uint32_t key, std::string &opt) = 0;
virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0; virtual bool setConfigurationOption(uint32_t key, const std::string &opt) = 0;
@ -366,7 +374,7 @@ public:
* @jsonapi{development} * @jsonapi{development}
* @return return the current operating mode * @return return the current operating mode
*/ */
virtual uint32_t getOperatingMode() = 0; virtual RsOpMode getOperatingMode() = 0;
/** /**
* @brief setOperatingMode set the current oprating mode * @brief setOperatingMode set the current oprating mode
@ -374,7 +382,7 @@ public:
* @param[in] opMode new opearting mode * @param[in] opMode new opearting mode
* @return * @return
*/ */
virtual bool setOperatingMode(uint32_t opMode) = 0; virtual bool setOperatingMode(RsOpMode opMode) = 0;
/** /**
* @brief setOperatingMode set the current operating mode from string * @brief setOperatingMode set the current operating mode from string

View file

@ -27,6 +27,7 @@
#include <list> #include <list>
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include "util/rsnet.h" #include "util/rsnet.h"
#include "retroshare/rsflags.h"
/* The Main Interface Class - for information about your Peers */ /* The Main Interface Class - for information about your Peers */
class RsDht; class RsDht;
@ -35,55 +36,66 @@ extern RsDht *rsDht;
//std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
//std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail); //std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
#define RSDHT_NETSTART_NETWORKMODE 0x0001 enum class RsDhtPeerType : uint8_t
#define RSDHT_NETSTART_NATTYPE 0x0002 {
#define RSDHT_NETSTART_NATHOLE 0x0003 ANY = 0,
#define RSDHT_NETSTART_CONNECTMODES 0x0004 OTHER = 1,
#define RSDHT_NETSTART_NETSTATE 0x0005 FOF = 2,
FRIEND = 3
};
enum class RsDhtPeerDht : uint8_t
{
NOT_ACTIVE = 0,
SEARCHING = 1,
FAILURE = 2,
OFFLINE = 3,
UNREACHABLE = 4,
ONLINE = 5
};
enum class RsDhtPeerConnectState : uint8_t
{
DISCONNECTED = 1,
UDP_STARTED = 2,
CONNECTED = 3
};
#define RSDHT_PEERTYPE_ANY 0x0000 enum class RsDhtPeerRequest : uint8_t
#define RSDHT_PEERTYPE_OTHER 0x0001 {
#define RSDHT_PEERTYPE_FOF 0x0002 STOPPED = 1,
#define RSDHT_PEERTYPE_FRIEND 0x0003 RUNNING = 2
};
#define RSDHT_PEERDHT_NOT_ACTIVE 0x0000 enum class RsDhtTouMode : uint8_t
#define RSDHT_PEERDHT_SEARCHING 0x0001 {
#define RSDHT_PEERDHT_FAILURE 0x0002 NONE = 0,
#define RSDHT_PEERDHT_OFFLINE 0x0003 DIRECT = 1,
#define RSDHT_PEERDHT_UNREACHABLE 0x0004 PROXY = 2,
#define RSDHT_PEERDHT_ONLINE 0x0005 RELAY = 3
};
#define RSDHT_PEERCONN_DISCONNECTED 1 enum class RsDhtRelayClass : uint8_t
#define RSDHT_PEERCONN_UDP_STARTED 2 {
#define RSDHT_PEERCONN_CONNECTED 3 ALL = 0,
GENERAL = 1,
FOF = 2,
FRIENDS = 3,
#define RSDHT_PEERREQ_STOPPED 1 NUM_CLASS = 4
#define RSDHT_PEERREQ_RUNNING 2 };
#define RSDHT_TOU_MODE_NONE 0 enum class RsDhtRelayMode : uint16_t
#define RSDHT_TOU_MODE_DIRECT 1 {
#define RSDHT_TOU_MODE_PROXY 2 DISABLED= 0x0000,
#define RSDHT_TOU_MODE_RELAY 3 ENABLED = 0x0001,
#define RSDHT_RELAY_NUM_CLASS 4
#define RSDHT_RELAY_CLASS_ALL 0
#define RSDHT_RELAY_CLASS_GENERAL 1
#define RSDHT_RELAY_CLASS_FOF 2
#define RSDHT_RELAY_CLASS_FRIENDS 3
#define RSDHT_RELAY_MODE_MASK 0x00f0
#define RSDHT_RELAY_ENABLED 0x0001
#define RSDHT_RELAY_MODE_OFF 0x0010
#define RSDHT_RELAY_MODE_ON 0x0020
#define RSDHT_RELAY_MODE_SERVER 0x0040
MASK = 0x00f0,
OFF = 0x0010,
ON = 0x0020,
SERVER = 0x0040
};
RS_REGISTER_ENUM_FLAGS_TYPE(RsDhtRelayMode)
class RsDhtPeer class RsDhtPeer
{ {
@ -108,18 +120,18 @@ class RsDhtNetPeer
std::string mDhtId; std::string mDhtId;
RsPeerId mRsId; RsPeerId mRsId;
uint32_t mPeerType; RsDhtPeerType mPeerType;
uint32_t mDhtState; RsDhtPeerDht mDhtState;
std::string mConnectState; // connectLogic. std::string mConnectState; // connectLogic.
uint32_t mPeerConnectState; // connect Status RsDhtPeerConnectState mPeerConnectState;
uint32_t mPeerConnectMode; // connect mode RsDhtTouMode mPeerConnectMode;
bool mExclusiveProxyLock; bool mExclusiveProxyLock;
std::string mPeerConnectProxyId; std::string mPeerConnectProxyId;
uint32_t mPeerReqState; // Req Status. RsDhtPeerRequest mPeerReqState;
std::string mCbPeerMsg; // Peer Cb Mgs. std::string mCbPeerMsg; // Peer Cb Mgs.
}; };
@ -188,11 +200,11 @@ virtual int getRelayServerList(std::list<std::string> &ids) = 0;
virtual int addRelayServer(std::string ids) = 0; virtual int addRelayServer(std::string ids) = 0;
virtual int removeRelayServer(std::string ids) = 0; virtual int removeRelayServer(std::string ids) = 0;
virtual uint32_t getRelayMode() = 0; virtual RsDhtRelayMode getRelayMode() = 0;
virtual int setRelayMode(uint32_t mode) = 0; virtual int setRelayMode(RsDhtRelayMode mode) = 0;
virtual int getRelayAllowance(int classIdx, uint32_t &count, uint32_t &bandwidth) = 0; virtual int getRelayAllowance(RsDhtRelayClass classIdx, uint32_t &count, uint32_t &bandwidth) = 0;
virtual int setRelayAllowance(int classIdx, uint32_t count, uint32_t bandwidth) = 0; virtual int setRelayAllowance(RsDhtRelayClass classIdx, uint32_t count, uint32_t bandwidth) = 0;
// So we can provide to clients. // So we can provide to clients.
virtual bool getOwnDhtId(std::string &ownDhtId) = 0; virtual bool getOwnDhtId(std::string &ownDhtId) = 0;

View file

@ -37,7 +37,13 @@ using rs_is_scoped_enum = std::integral_constant< bool,
* it as flags type passing it as parameter of this macro. * it as flags type passing it as parameter of this macro.
* The result will be type safe flags, that cannot be mixed up with flag of a * The result will be type safe flags, that cannot be mixed up with flag of a
* different type, but that are very comfortable to operate like plain old * different type, but that are very comfortable to operate like plain old
* integers. * integers. All commom operation like &, | or ! can be used. To convert
* the result of such operation to boolean use !!:
@code{.cpp}
RsConnectModes connect = rsConfig->getConnectModes();
if (!!(connect & RsConnectModes::OUTGOING_TCP))
@endcode
*
* This macro support flag fields of different lenght depending on what * This macro support flag fields of different lenght depending on what
* underlining type (usually from uint8_t up to uint64_t) has been declared for * underlining type (usually from uint8_t up to uint64_t) has been declared for
* the enum class. * the enum class.
@ -45,6 +51,7 @@ using rs_is_scoped_enum = std::integral_constant< bool,
* underlining type of the enum otherwise different compilers may serialize a * underlining type of the enum otherwise different compilers may serialize a
* flag variable with different lenght, potentially causing interoperability * flag variable with different lenght, potentially causing interoperability
* issues between differents builds. * issues between differents builds.
*
* Usage example: * Usage example:
@code{.cpp} @code{.cpp}
enum class RsGrouterItemFlags : uint32_t enum class RsGrouterItemFlags : uint32_t

View file

@ -38,7 +38,7 @@
class RsGxsForums; class RsGxsForums;
/** /**
* Pointer to global instance of RsGxsChannels service implementation * Pointer to global instance of RsGxsForums service implementation
* @jsonapi{development} * @jsonapi{development}
*/ */
extern RsGxsForums* rsGxsForums; extern RsGxsForums* rsGxsForums;

View file

@ -115,6 +115,7 @@ enum class RsPostedEventCode: uint8_t
UPDATED_MESSAGE = 0x05, UPDATED_MESSAGE = 0x05,
READ_STATUS_CHANGED = 0x06, READ_STATUS_CHANGED = 0x06,
STATISTICS_CHANGED = 0x07, STATISTICS_CHANGED = 0x07,
MESSAGE_VOTES_UPDATED = 0x08,
}; };
@ -127,6 +128,7 @@ struct RsGxsPostedEvent: RsEvent
RsPostedEventCode mPostedEventCode; RsPostedEventCode mPostedEventCode;
RsGxsGroupId mPostedGroupId; RsGxsGroupId mPostedGroupId;
RsGxsMessageId mPostedMsgId; RsGxsMessageId mPostedMsgId;
RsGxsMessageId mPostedThreadId;
///* @see RsEvent @see RsSerializable ///* @see RsEvent @see RsSerializable
void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override void serial_process( RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) override
@ -172,6 +174,10 @@ public:
virtual bool getBoardsServiceStatistics(GxsServiceStatistic& stat) =0; virtual bool getBoardsServiceStatistics(GxsServiceStatistic& stat) =0;
virtual bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) =0;
virtual bool setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType }; enum RS_DEPRECATED RankType {TopRankType, HotRankType, NewRankType };
RS_DEPRECATED_FOR(getBoardsInfo) RS_DEPRECATED_FOR(getBoardsInfo)
@ -201,8 +207,9 @@ public:
//virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0; //virtual bool createNewComment(uint32_t &token, RsGxsComment &comment) = 0;
//virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0; //virtual bool createNewVote(uint32_t &token, RsGxsVote &vote) = 0;
////////////////////////////////////////////////////////////////////////////// RS_DEPRECATED_FOR(setPostReadStatus)
virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0; virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) = 0;
//////////////////////////////////////////////////////////////////////////////
virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0; virtual bool createGroup(uint32_t &token, RsPostedGroup &group) = 0;
virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0; virtual bool createPost(uint32_t &token, RsPostedPost &post) = 0;

View file

@ -1392,7 +1392,7 @@ bool p3Peers::parseShortInvite(const std::string& inviteStrUrl, RsPeerDetails& d
case RsShortInviteFieldType::HIDDEN_LOCATOR: case RsShortInviteFieldType::HIDDEN_LOCATOR:
details.hiddenType = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3]; details.hiddenType = (((uint32_t)buf[0]) << 24)+(((uint32_t)buf[1])<<16)+(((uint32_t)buf[2])<<8) + (uint32_t)buf[3];
details.hiddenNodePort = (((uint32_t)buf[4]) << 8)+ (uint32_t)buf[5]; details.hiddenNodePort = (((uint32_t)buf[4]) << 8)+ (uint32_t)buf[5];
details.isHiddenNode = true;
details.hiddenNodeAddress = std::string((char*)&buf[6],s-6); details.hiddenNodeAddress = std::string((char*)&buf[6],s-6);
break; break;
@ -1538,7 +1538,7 @@ std::string p3Peers::GetRetroshareInvite(
if (getPeerDetails(ssl_id, detail)) if (getPeerDetails(ssl_id, detail))
{ {
if(!includeExtraLocators) detail.ipAddressList.clear(); if(!includeExtraLocators && !detail.isHiddenNode) detail.ipAddressList.clear();
unsigned char *mem_block = nullptr; unsigned char *mem_block = nullptr;
size_t mem_block_size = 0; size_t mem_block_size = 0;

View file

@ -48,11 +48,11 @@ p3ServerConfig::p3ServerConfig(p3PeerMgr *peerMgr, p3LinkMgr *linkMgr, p3NetMgr
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
mUserLevel = RSCONFIG_USER_LEVEL_NEW; /* START LEVEL */ mUserLevel = RsConfigUserLvl::NEW; /* START LEVEL */
mRateDownload = DEFAULT_DOWNLOAD_KB_RATE; mRateDownload = DEFAULT_DOWNLOAD_KB_RATE;
mRateUpload = DEFAULT_UPLOAD_KB_RATE; mRateUpload = DEFAULT_UPLOAD_KB_RATE;
mOpMode = RS_OPMODE_FULL; mOpMode = RsOpMode::FULL;
rsConfig = this; rsConfig = this;
} }
@ -86,7 +86,7 @@ void p3ServerConfig::load_config()
} }
/* enable operating mode */ /* enable operating mode */
uint32_t opMode = getOperatingMode(); RsOpMode opMode = getOperatingMode();
switchToOperatingMode(opMode); switchToOperatingMode(opMode);
} }
@ -264,9 +264,9 @@ std::string p3ServerConfig::getRetroshareDataDirectory()
/* New Stuff */ /* New Stuff */
uint32_t p3ServerConfig::getUserLevel() RsConfigUserLvl p3ServerConfig::getUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
{ {
RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/ RsStackMutex stack(configMtx); /******* LOCKED MUTEX *****/
userLevel = mUserLevel; userLevel = mUserLevel;
@ -274,47 +274,47 @@ uint32_t p3ServerConfig::getUserLevel()
switch(userLevel) switch(userLevel)
{ {
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
break; break;
#define MIN_BASIC_FRIENDS 2 #define MIN_BASIC_FRIENDS 2
// FALL THROUGH EVERYTHING. // FALL THROUGH EVERYTHING.
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
{ {
if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS) if (mPeerMgr->getFriendCount(true, false) > MIN_BASIC_FRIENDS)
{ {
userLevel = RSCONFIG_USER_LEVEL_BASIC; userLevel = RsConfigUserLvl::BASIC;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
{ {
/* check that we have some lastConnect > 0 */ /* check that we have some lastConnect > 0 */
if (mPeerMgr->haveOnceConnected()) if (mPeerMgr->haveOnceConnected())
{ {
userLevel = RSCONFIG_USER_LEVEL_CASUAL; userLevel = RsConfigUserLvl::CASUAL;
} }
} }
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
{ {
/* check that the firewall is open */ /* check that the firewall is open */
uint32_t netMode = mNetMgr->getNetworkMode(); RsNetworkMode netMode = mNetMgr->getNetworkMode();
uint32_t firewallMode = mNetMgr->getNatHoleMode(); RsNatHoleMode firewallMode = mNetMgr->getNatHoleMode();
if ((RSNET_NETWORK_EXTERNALIP == netMode) || if ((RsNetworkMode::EXTERNALIP == netMode) ||
((RSNET_NETWORK_BEHINDNAT == netMode) && ((RsNetworkMode::BEHINDNAT == netMode) &&
((RSNET_NATHOLE_UPNP == firewallMode) || (RsNatHoleMode::UPNP == firewallMode ||
(RSNET_NATHOLE_NATPMP == firewallMode) || (RsNatHoleMode::NATPMP == firewallMode) ||
(RSNET_NATHOLE_FORWARDED == firewallMode)))) (RsNatHoleMode::FORWARDED == firewallMode))))
{ {
userLevel = RSCONFIG_USER_LEVEL_POWER; userLevel = RsConfigUserLvl::POWER;
} }
} }
break; /* for all */ break; /* for all */
@ -329,27 +329,27 @@ uint32_t p3ServerConfig::getUserLevel()
} }
uint32_t p3ServerConfig::getNetState() RsNetState p3ServerConfig::getNetState()
{ {
return mNetMgr->getNetStateMode(); return mNetMgr->getNetStateMode();
} }
uint32_t p3ServerConfig::getNetworkMode() RsNetworkMode p3ServerConfig::getNetworkMode()
{ {
return mNetMgr->getNetworkMode(); return mNetMgr->getNetworkMode();
} }
uint32_t p3ServerConfig::getNatTypeMode() RsNatTypeMode p3ServerConfig::getNatTypeMode()
{ {
return mNetMgr->getNatTypeMode(); return mNetMgr->getNatTypeMode();
} }
uint32_t p3ServerConfig::getNatHoleMode() RsNatHoleMode p3ServerConfig::getNatHoleMode()
{ {
return mNetMgr->getNatHoleMode(); return mNetMgr->getNatHoleMode();
} }
uint32_t p3ServerConfig::getConnectModes() RsConnectModes p3ServerConfig::getConnectModes()
{ {
return mNetMgr->getConnectModes(); return mNetMgr->getConnectModes();
} }
@ -357,27 +357,27 @@ uint32_t p3ServerConfig::getConnectModes()
/* Operating Mode */ /* Operating Mode */
#define RS_CONFIG_OPERATING_STRING "OperatingMode" #define RS_CONFIG_OPERATING_STRING "OperatingMode"
uint32_t p3ServerConfig::getOperatingMode() RsOpMode p3ServerConfig::getOperatingMode()
{ {
#ifdef SAVE_OPERATING_MODE #ifdef SAVE_OPERATING_MODE
std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING); std::string modestr = mGeneralConfig->getSetting(RS_CONFIG_OPERATING_STRING);
uint32_t mode = RS_OPMODE_FULL; uint32_t mode = RsOpMode::FULL;
if (modestr == "FULL") if (modestr == "FULL")
{ {
mode = RS_OPMODE_FULL; mode = RsOpMode::FULL;
} }
else if (modestr == "NOTURTLE") else if (modestr == "NOTURTLE")
{ {
mode = RS_OPMODE_NOTURTLE; mode = RsOpMode::NOTURTLE;
} }
else if (modestr == "GAMING") else if (modestr == "GAMING")
{ {
mode = RS_OPMODE_GAMING; mode = RsOpMode::GAMING;
} }
else if (modestr == "MINIMAL") else if (modestr == "MINIMAL")
{ {
mode = RS_OPMODE_MINIMAL; mode = RsOpMode::MINIMAL;
} }
return mode; return mode;
#else #else
@ -387,24 +387,24 @@ uint32_t p3ServerConfig::getOperatingMode()
} }
bool p3ServerConfig::setOperatingMode(uint32_t opMode) bool p3ServerConfig::setOperatingMode(RsOpMode opMode)
{ {
#ifdef SAVE_OPERATING_MODE #ifdef SAVE_OPERATING_MODE
std::string modestr = "FULL"; std::string modestr = "FULL";
switch(opMode) switch(opMode)
{ {
case RS_OPMODE_FULL: case RsOpMode::FULL:
modestr = "FULL"; modestr = "FULL";
break; break;
case RS_OPMODE_NOTURTLE: case RsOpMode::NOTURTLE:
modestr = "NOTURTLE"; modestr = "NOTURTLE";
break; break;
case RS_OPMODE_GAMING: case RsOpMode::GAMING:
modestr = "GAMING"; modestr = "GAMING";
break; break;
case RS_OPMODE_MINIMAL: case RsOpMode::MINIMAL:
modestr = "MINIMAL"; modestr = "MINIMAL";
break; break;
} }
@ -420,31 +420,31 @@ bool p3ServerConfig::setOperatingMode(uint32_t opMode)
bool p3ServerConfig::setOperatingMode(const std::string &opModeStr) bool p3ServerConfig::setOperatingMode(const std::string &opModeStr)
{ {
uint32_t opMode = RS_OPMODE_FULL; RsOpMode opMode = RsOpMode::FULL;
std::string upper; std::string upper;
stringToUpperCase(opModeStr, upper); stringToUpperCase(opModeStr, upper);
if (upper == "NOTURTLE") if (upper == "NOTURTLE")
{ {
opMode = RS_OPMODE_NOTURTLE; opMode = RsOpMode::NOTURTLE;
} }
else if (upper == "GAMING") else if (upper == "GAMING")
{ {
opMode = RS_OPMODE_GAMING; opMode = RsOpMode::GAMING;
} }
else if (upper == "MINIMAL") else if (upper == "MINIMAL")
{ {
opMode = RS_OPMODE_MINIMAL; opMode = RsOpMode::MINIMAL;
} }
else // "FULL" by default else // "FULL" by default
{ {
opMode = RS_OPMODE_FULL; opMode = RsOpMode::FULL;
} }
return setOperatingMode(opMode); return setOperatingMode(opMode);
} }
bool p3ServerConfig::switchToOperatingMode(uint32_t opMode) bool p3ServerConfig::switchToOperatingMode(RsOpMode opMode)
{ {
float dl_rate = 0; float dl_rate = 0;
float ul_rate = 0; float ul_rate = 0;
@ -456,13 +456,13 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
ul_rate = mRateUpload; ul_rate = mRateUpload;
} }
std::cerr << "p3ServerConfig::switchToOperatingMode(" << opMode << ")"; std::cerr << "p3ServerConfig::switchToOperatingMode(" << static_cast<typename std::underlying_type<RsOpMode>::type>(opMode) << ")";
std::cerr << std::endl; std::cerr << std::endl;
switch (opMode) switch (opMode)
{ {
default: default:
case RS_OPMODE_FULL: case RsOpMode::FULL:
/* switch on all transfers */ /* switch on all transfers */
/* 100% bandwidth */ /* 100% bandwidth */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */
@ -470,14 +470,14 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
//setMaxRate(false, mro); // Out / Upload. //setMaxRate(false, mro); // Out / Upload.
turtle_enabled = true; turtle_enabled = true;
break; break;
case RS_OPMODE_NOTURTLE: case RsOpMode::NOTURTLE:
/* switch on all transfers - except turtle, enable hashing */ /* switch on all transfers - except turtle, enable hashing */
/* 100% bandwidth */ /* 100% bandwidth */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */
turtle_enabled = false; turtle_enabled = false;
break; break;
case RS_OPMODE_GAMING: case RsOpMode::GAMING:
/* switch on all transfers */ /* switch on all transfers */
/* reduce bandwidth to 25% */ /* reduce bandwidth to 25% */
/* switch off popups, enable hashing */ /* switch off popups, enable hashing */
@ -486,7 +486,7 @@ bool p3ServerConfig::switchToOperatingMode(uint32_t opMode)
dl_rate *= 0.25; dl_rate *= 0.25;
ul_rate *= 0.25; ul_rate *= 0.25;
break; break;
case RS_OPMODE_MINIMAL: case RsOpMode::MINIMAL:
/* switch off all transfers */ /* switch off all transfers */
/* reduce bandwidth to 10%, but make sure there is enough for VoIP */ /* reduce bandwidth to 10%, but make sure there is enough for VoIP */
/* switch on popups, enable hashing */ /* switch on popups, enable hashing */

View file

@ -72,20 +72,20 @@ virtual std::string getRetroshareDataDirectory();
/* New Stuff */ /* New Stuff */
virtual uint32_t getUserLevel(); virtual RsConfigUserLvl getUserLevel();
virtual uint32_t getNetState(); virtual RsNetState getNetState();
virtual uint32_t getNetworkMode(); virtual RsNetworkMode getNetworkMode();
virtual uint32_t getNatTypeMode(); virtual RsNatTypeMode getNatTypeMode();
virtual uint32_t getNatHoleMode(); virtual RsNatHoleMode getNatHoleMode();
virtual uint32_t getConnectModes(); virtual RsConnectModes getConnectModes();
virtual bool getConfigurationOption(uint32_t key, std::string &opt); virtual bool getConfigurationOption(uint32_t key, std::string &opt);
virtual bool setConfigurationOption(uint32_t key, const std::string &opt); virtual bool setConfigurationOption(uint32_t key, const std::string &opt);
/* Operating Mode */ /* Operating Mode */
virtual uint32_t getOperatingMode(); virtual RsOpMode getOperatingMode();
virtual bool setOperatingMode(uint32_t opMode); virtual bool setOperatingMode(RsOpMode opMode);
virtual bool setOperatingMode(const std::string &opModeStr); virtual bool setOperatingMode(const std::string &opModeStr);
virtual int SetMaxDataRates( int downKb, int upKb ); virtual int SetMaxDataRates( int downKb, int upKb );
@ -97,7 +97,7 @@ virtual int GetTrafficSum( uint64_t &inb, uint64_t &outb );
private: private:
bool switchToOperatingMode(uint32_t opMode); bool switchToOperatingMode(RsOpMode opMode);
bool findConfigurationOption(uint32_t key, std::string &keystr); bool findConfigurationOption(uint32_t key, std::string &keystr);
@ -108,11 +108,11 @@ bool findConfigurationOption(uint32_t key, std::string &keystr);
p3GeneralConfig *mGeneralConfig; p3GeneralConfig *mGeneralConfig;
RsMutex configMtx; RsMutex configMtx;
uint32_t mUserLevel; // store last one... will later be a config Item too. RsConfigUserLvl mUserLevel; // store last one... will later be a config Item too.
float mRateDownload; float mRateDownload;
float mRateUpload; float mRateUpload;
uint32_t mOpMode; RsOpMode mOpMode;
}; };
#endif #endif

View file

@ -38,6 +38,7 @@
/**** /****
* #define POSTBASE_DEBUG 1 * #define POSTBASE_DEBUG 1
****/ ****/
#define POSTBASE_DEBUG 1
#define POSTBASE_BACKGROUND_PROCESSING 0x0002 #define POSTBASE_BACKGROUND_PROCESSING 0x0002
#define PROCESSING_START_PERIOD 30 #define PROCESSING_START_PERIOD 30
@ -93,27 +94,49 @@ void p3PostBase::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(msgChange) if(msgChange)
{ {
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification";
std::cerr << std::endl;
#endif
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Msgs for Group: " << mit->first;
std::cerr << std::endl;
#endif
// To start with we are just going to trigger updates on these groups. // To start with we are just going to trigger updates on these groups.
// FUTURE OPTIMISATION. // FUTURE OPTIMISATION.
// It could be taken a step further and directly request these msgs for an update. // It could be taken a step further and directly request these msgs for an update.
addGroupForProcessing(msgChange->mGroupId); addGroupForProcessing(msgChange->mGroupId);
if (rsEvents && (msgChange->getType() == RsGxsNotify::TYPE_RECEIVED_NEW || msgChange->getType() == RsGxsNotify::TYPE_PUBLISHED)) if (rsEvents)
{
switch(msgChange->getType())
{
case RsGxsNotify::TYPE_RECEIVED_NEW:
case RsGxsNotify::TYPE_PUBLISHED:
{
auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedThreadId = msgChange->mNewMsgItem->meta.mThreadId;
ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE;
rsEvents->postEvent(ev);
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: NEW/PUBLISHED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << ", thread ID = " << msgChange->mNewMsgItem->meta.mThreadId << std::endl;
#endif
}
break;
case RsGxsNotify::TYPE_PROCESSED:
{ {
auto ev = std::make_shared<RsGxsPostedEvent>(); auto ev = std::make_shared<RsGxsPostedEvent>();
ev->mPostedMsgId = msgChange->mMsgId; ev->mPostedMsgId = msgChange->mMsgId;
ev->mPostedGroupId = msgChange->mGroupId; ev->mPostedGroupId = msgChange->mGroupId;
ev->mPostedEventCode = RsPostedEventCode::NEW_MESSAGE; ev->mPostedEventCode = RsPostedEventCode::MESSAGE_VOTES_UPDATED;
rsEvents->postEvent(ev); rsEvents->postEvent(ev);
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: PROCESSED ID=" << msgChange->mMsgId << " in group " << msgChange->mGroupId << std::endl;
#endif
}
break;
default:
#ifdef POSTBASE_DEBUG
std::cerr << "p3PostBase::notifyChanges() Found Message Change Notification: type " << msgChange->getType() << " (ignored) " << msgChange->mMsgId << std::endl;
#endif
break;
}
} }
} }

View file

@ -442,6 +442,57 @@ bool p3Posted::createBoard(RsPostedGroup& board)
return true; return true;
} }
bool p3Posted::voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& authorId)
{
// Do some basic tests
if(!rsIdentity->isOwnId(authorId)) // This is ruled out before waitToken complains. Not sure it's needed.
{
std::cerr << __PRETTY_FUNCTION__ << ": vote submitted with an ID that is not yours! This cannot work." << std::endl;
return false;
}
RsGxsVote vote;
vote.mMeta.mGroupId = postGrpId;
vote.mMeta.mThreadId = postMsgId;
vote.mMeta.mParentId = postMsgId;
vote.mMeta.mAuthorId = authorId;
if (up)
vote.mVoteType = GXS_VOTE_UP;
else
vote.mVoteType = GXS_VOTE_DOWN;
uint32_t token;
if(!createNewVote(token, vote))
{
std::cerr << __PRETTY_FUNCTION__ << " Error! Failed submitting vote to (group,msg) " << postGrpId << "," << postMsgId << " from author " << authorId << std::endl;
return false;
}
if(waitToken(token) != RsTokenService::COMPLETE)
{
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed." << std::endl;
return false;
}
return true;
}
bool p3Posted::setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read)
{
uint32_t token;
setMessageReadStatus(token,msgId,read);
if(waitToken(token) != RsTokenService::COMPLETE)
{
std::cerr << __PRETTY_FUNCTION__ << " Error! GXS operation failed." << std::endl;
return false;
}
return true;
}
bool p3Posted::editBoard(RsPostedGroup& board) bool p3Posted::editBoard(RsPostedGroup& board)
{ {
uint32_t token; uint32_t token;

View file

@ -84,6 +84,10 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
bool createBoard(RsPostedGroup& board) override; bool createBoard(RsPostedGroup& board) override;
bool voteForPost(bool up,const RsGxsGroupId& postGrpId,const RsGxsMessageId& postMsgId,const RsGxsId& voterId) override;
bool setPostReadStatus(const RsGxsGrpMsgIdPair& msgId, bool read) override;
virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) override; virtual bool getGroupData(const uint32_t &token, std::vector<RsPostedGroup> &groups) override;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts, std::vector<RsGxsVote> &vots) override; virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts, std::vector<RsGxsVote> &vots) override;
virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) override; virtual bool getPostData(const uint32_t &token, std::vector<RsPostedPost> &posts, std::vector<RsGxsComment> &cmts) override;
@ -126,17 +130,17 @@ virtual void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgI
return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ; return mCommentService->createGxsComment(token, msg) && waitToken(token) == RsTokenService::COMPLETE ;
} }
virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) virtual bool createNewVote(uint32_t &token, RsGxsVote &msg) override
{ {
return mCommentService->createGxsVote(token, msg); return mCommentService->createGxsVote(token, msg);
} }
virtual bool acknowledgeComment( virtual bool acknowledgeComment(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) override
{ return acknowledgeMsg(token, msgId); } { return acknowledgeMsg(token, msgId); }
virtual bool acknowledgeVote( virtual bool acknowledgeVote(
uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) uint32_t token, std::pair<RsGxsGroupId, RsGxsMessageId>& msgId ) override
{ {
if (mCommentService->acknowledgeVote(token, msgId)) return true; if (mCommentService->acknowledgeVote(token, msgId)) return true;
return acknowledgeMsg(token, msgId); return acknowledgeMsg(token, msgId);

View file

@ -101,12 +101,14 @@ std::ostream &operator<<(std::ostream &out, const UdpRelayEnd &ure);
/**** DEFINED IN EXTERNAL HEADER FILE ***/ /**** DEFINED IN EXTERNAL HEADER FILE ***/
#define UDP_RELAY_NUM_CLASS RSDHT_RELAY_NUM_CLASS // sehraf: this is a bit ugly but since the int is used as an integer i'lll stick to this hack for now
/// TODO fix me!
#define UDP_RELAY_NUM_CLASS static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::NUM_CLASS)
#define UDP_RELAY_CLASS_ALL RSDHT_RELAY_CLASS_ALL #define UDP_RELAY_CLASS_ALL static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::ALL)
#define UDP_RELAY_CLASS_GENERAL RSDHT_RELAY_CLASS_GENERAL #define UDP_RELAY_CLASS_GENERAL static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::GENERAL)
#define UDP_RELAY_CLASS_FOF RSDHT_RELAY_CLASS_FOF #define UDP_RELAY_CLASS_FOF static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::FOF)
#define UDP_RELAY_CLASS_FRIENDS RSDHT_RELAY_CLASS_FRIENDS #define UDP_RELAY_CLASS_FRIENDS static_cast<typename std::underlying_type<RsDhtRelayClass>::type>(RsDhtRelayClass::FRIENDS)
// Just for some testing fun! // Just for some testing fun!
//#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes //#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes

View file

@ -53,10 +53,12 @@ QByteArray AddOnionCommand::build()
QByteArray out("ADD_ONION"); QByteArray out("ADD_ONION");
if (m_service->privateKey().isLoaded()) { if (m_service->privateKey().isLoaded()) {
out += " RSA1024:"; out += " ";
out += m_service->privateKey().encodedPrivateKey(CryptoKey::DER).toBase64(); out += m_service->privateKey().bytes();
} else { } else {
out += " NEW:RSA1024"; //out += " NEW:RSA1024"; // this is v2. For v3, use NEW:BEST, or NEW:ED25519-V3
//out += " NEW:ED25519-V3"; // this is v3.
out += " NEW:BEST"; // this is v3, but without control of key type. Generates a RSA1024 key on older Tor versions.
} }
foreach (const HiddenService::Target &target, m_service->targets()) { foreach (const HiddenService::Target &target, m_service->targets()) {
@ -80,12 +82,21 @@ void AddOnionCommand::onReply(int statusCode, const QByteArray &data)
return; return;
} }
const QByteArray keyPrefix("PrivateKey=RSA1024:"); const QByteArray keyPrefix("PrivateKey=");
const QByteArray sidPrefix("ServiceID=");
if(data.startsWith("ServiceID=")){
QByteArray service_id = data.mid(sidPrefix.size());
m_service->setServiceId(service_id);
}
if (data.startsWith(keyPrefix)) { if (data.startsWith(keyPrefix)) {
QByteArray keyData(QByteArray::fromBase64(data.mid(keyPrefix.size())));
QByteArray keyData(data.mid(keyPrefix.size()));
CryptoKey key; CryptoKey key;
if (!key.loadFromData(keyData, CryptoKey::PrivateKey, CryptoKey::DER)) {
m_errorMessage = QStringLiteral("Key decoding failed"); if (!key.loadFromTorMessage(keyData)) {
m_errorMessage = QStringLiteral("Key structure check failed");
return; return;
} }

View file

@ -30,11 +30,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <iostream>
#include "CryptoKey.h" #include "CryptoKey.h"
#include "SecureRNG.h" #include "SecureRNG.h"
#include "Useful.h" #include "Useful.h"
#include <QtDebug> #include <QtDebug>
#include <QFile> #include <QFile>
#include <QByteArray>
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/pem.h> #include <openssl/pem.h>
@ -48,8 +51,10 @@ void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
#define RSA_bits(o) (BN_num_bits((o)->n)) #define RSA_bits(o) (BN_num_bits((o)->n))
#endif #endif
#ifdef TO_REMOVE
void base32_encode(char *dest, unsigned destlen, const char *src, unsigned srclen); void base32_encode(char *dest, unsigned destlen, const char *src, unsigned srclen);
bool base32_decode(char *dest, unsigned destlen, const char *src, unsigned srclen); bool base32_decode(char *dest, unsigned destlen, const char *src, unsigned srclen);
#endif
CryptoKey::CryptoKey() CryptoKey::CryptoKey()
{ {
@ -60,6 +65,7 @@ CryptoKey::~CryptoKey()
clear(); clear();
} }
#ifdef TO_REMOVE
CryptoKey::Data::~Data() CryptoKey::Data::~Data()
{ {
if (key) if (key)
@ -68,12 +74,14 @@ CryptoKey::Data::~Data()
key = 0; key = 0;
} }
} }
#endif
void CryptoKey::clear() void CryptoKey::clear()
{ {
d = 0; key_data.clear();
} }
#ifdef TO_REMOVE
bool CryptoKey::loadFromData(const QByteArray &data, KeyType type, KeyFormat format) bool CryptoKey::loadFromData(const QByteArray &data, KeyType type, KeyFormat format)
{ {
RSA *key = NULL; RSA *key = NULL;
@ -110,23 +118,91 @@ bool CryptoKey::loadFromData(const QByteArray &data, KeyType type, KeyFormat for
d = new Data(key); d = new Data(key);
return true; return true;
} }
#endif
bool CryptoKey::loadFromFile(const QString &path, KeyType type, KeyFormat format) bool CryptoKey::loadFromFile(const QString& path)
{ {
QFile file(path); QFile file(path);
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
{ {
qWarning() << "Failed to open" << (type == PrivateKey ? "private" : "public") << "key from" qWarning() << "Failed to open Tor key file " << path << ": " << file.errorString();
<< path << "-" << file.errorString();
return false; return false;
} }
QByteArray data = file.readAll(); QByteArray data = file.readAll();
file.close(); file.close();
return loadFromData(data, type, format); if(data.contains("-----BEGIN RSA PRIVATE KEY-----"))
{
std::cerr << "Note: Reading/converting Tor v2 key format." << std::endl;
// This to be compliant with old format. New format is oblivious to the type of key so we dont need a header
data = data.replace("-----BEGIN RSA PRIVATE KEY-----",nullptr);
data = data.replace("-----END RSA PRIVATE KEY-----",nullptr);
data = data.replace("\n",nullptr);
data = data.replace("\t",nullptr);
data = "RSA1024:"+data;
} }
std::cerr << "Have read the following key: " << std::endl;
std::cerr << QString(data).toStdString() << std::endl;
key_data = data;
return true;
}
bool CryptoKey::loadFromTorMessage(const QByteArray& b)
{
// note: We should probably check the structure a bit more, for security.
std::cerr << "Loading new key:" << std::endl;
if(b.startsWith("RSA1024"))
std::cerr << " type: RSA-1024 (Tor v2)" << std::endl;
else if(b.startsWith("ED25519-V3"))
std::cerr << " type: ED25519-V3 (Tor v3)" << std::endl;
else if(b.indexOf(':'))
{
std::cerr << " unknown type, or bad syntax in key: \"" << b.left(b.indexOf(':')).toStdString() << "\". Not accepted." << std::endl;
return false;
}
key_data = b;
return true;
}
/* Cryptographic hash of a password as expected by Tor's HashedControlPassword */
QByteArray torControlHashedPassword(const QByteArray &password)
{
QByteArray salt = SecureRNG::random(8);
if (salt.isNull())
return QByteArray();
int count = ((quint32)16 + (96 & 15)) << ((96 >> 4) + 6);
SHA_CTX hash;
SHA1_Init(&hash);
QByteArray tmp = salt + password;
while (count)
{
int c = qMin(count, tmp.size());
SHA1_Update(&hash, reinterpret_cast<const void*>(tmp.constData()), c);
count -= c;
}
unsigned char md[20];
SHA1_Final(md, &hash);
/* 60 is the hex-encoded value of 96, which is a constant used by Tor's algorithm. */
return QByteArray("16:") + salt.toHex().toUpper() + QByteArray("60") +
QByteArray::fromRawData(reinterpret_cast<const char*>(md), 20).toHex().toUpper();
}
#ifdef TO_REMOVE
bool CryptoKey::isPrivate() const bool CryptoKey::isPrivate() const
{ {
if (!isLoaded()) { if (!isLoaded()) {
@ -326,34 +402,6 @@ bool CryptoKey::verifySHA256(const QByteArray &digest, QByteArray signature) con
return true; return true;
} }
/* Cryptographic hash of a password as expected by Tor's HashedControlPassword */
QByteArray torControlHashedPassword(const QByteArray &password)
{
QByteArray salt = SecureRNG::random(8);
if (salt.isNull())
return QByteArray();
int count = ((quint32)16 + (96 & 15)) << ((96 >> 4) + 6);
SHA_CTX hash;
SHA1_Init(&hash);
QByteArray tmp = salt + password;
while (count)
{
int c = qMin(count, tmp.size());
SHA1_Update(&hash, reinterpret_cast<const void*>(tmp.constData()), c);
count -= c;
}
unsigned char md[20];
SHA1_Final(md, &hash);
/* 60 is the hex-encoded value of 96, which is a constant used by Tor's algorithm. */
return QByteArray("16:") + salt.toHex().toUpper() + QByteArray("60") +
QByteArray::fromRawData(reinterpret_cast<const char*>(md), 20).toHex().toUpper();
}
/* Copyright (c) 2001-2004, Roger Dingledine /* Copyright (c) 2001-2004, Roger Dingledine
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
* Copyright (c) 2007-2010, The Tor Project, Inc. * Copyright (c) 2007-2010, The Tor Project, Inc.
@ -475,3 +523,5 @@ bool base32_decode(char *dest, unsigned destlen, const char *src, unsigned srcle
delete[] tmp; delete[] tmp;
return true; return true;
} }
#endif

View file

@ -51,14 +51,19 @@ public:
}; };
CryptoKey(); CryptoKey();
CryptoKey(const CryptoKey &other) : d(other.d) { }
~CryptoKey(); ~CryptoKey();
#ifdef TO_REMOVE
bool loadFromData(const QByteArray &data, KeyType type, KeyFormat format = PEM); bool loadFromData(const QByteArray &data, KeyType type, KeyFormat format = PEM);
bool loadFromFile(const QString &path, KeyType type, KeyFormat format = PEM); bool loadFromFile(const QString &path, KeyType type, KeyFormat format = PEM);
#endif
bool loadFromFile(const QString &path);
void clear(); void clear();
bool isLoaded() const { return d.data() && d->key != 0; } const QByteArray bytes() const { return key_data; }
bool loadFromTorMessage(const QByteArray& b);
bool isLoaded() const { return !key_data.isNull(); }
#ifdef TO_REMOVE
bool isPrivate() const; bool isPrivate() const;
QByteArray publicKeyDigest() const; QByteArray publicKeyDigest() const;
@ -76,8 +81,10 @@ public:
QByteArray signSHA256(const QByteArray &digest) const; QByteArray signSHA256(const QByteArray &digest) const;
// Verify a signature as per signSHA256 // Verify a signature as per signSHA256
bool verifySHA256(const QByteArray &digest, QByteArray signature) const; bool verifySHA256(const QByteArray &digest, QByteArray signature) const;
#endif
private: private:
#ifdef TO_REMOVE
struct Data : public QSharedData struct Data : public QSharedData
{ {
typedef struct rsa_st RSA; typedef struct rsa_st RSA;
@ -86,8 +93,12 @@ private:
Data(RSA *k = 0) : key(k) { } Data(RSA *k = 0) : key(k) { }
~Data(); ~Data();
}; };
#endif
QByteArray key_data;
#ifdef TO_REMOVE
QExplicitlySharedDataPointer<Data> d; QExplicitlySharedDataPointer<Data> d;
#endif
}; };
QByteArray torControlHashedPassword(const QByteArray &password); QByteArray torControlHashedPassword(const QByteArray &password);

View file

@ -90,6 +90,13 @@ void HiddenService::addTarget(quint16 servicePort, QHostAddress targetAddress, q
m_targets.append(t); m_targets.append(t);
} }
void HiddenService::setServiceId(const QByteArray& sid)
{
m_service_id = sid;
m_hostname = sid + ".onion";
emit hostnameChanged();
}
void HiddenService::setPrivateKey(const CryptoKey &key) void HiddenService::setPrivateKey(const CryptoKey &key)
{ {
if (m_privateKey.isLoaded()) { if (m_privateKey.isLoaded()) {
@ -97,13 +104,15 @@ void HiddenService::setPrivateKey(const CryptoKey &key)
return; return;
} }
#ifdef TO_REMOVE
if (!key.isPrivate()) { if (!key.isPrivate()) {
BUG() << "Cannot create a hidden service with a public key"; BUG() << "Cannot create a hidden service with a public key";
return; return;
} }
#endif
m_privateKey = key; m_privateKey = key;
m_hostname = m_privateKey.torServiceID() + QStringLiteral(".onion");
emit privateKeyChanged(); emit privateKeyChanged();
} }
@ -112,13 +121,13 @@ void HiddenService::loadPrivateKey()
if (m_privateKey.isLoaded() || m_dataPath.isEmpty()) if (m_privateKey.isLoaded() || m_dataPath.isEmpty())
return; return;
bool ok = m_privateKey.loadFromFile(m_dataPath + QLatin1String("/private_key"), CryptoKey::PrivateKey); bool ok = m_privateKey.loadFromFile(m_dataPath + QLatin1String("/private_key"));
if (!ok) { if (!ok) {
qWarning() << "Failed to load hidden service key"; qWarning() << "Failed to load hidden service key";
return; return;
} }
m_hostname = m_privateKey.torServiceID();
emit privateKeyChanged(); emit privateKeyChanged();
} }

View file

@ -71,10 +71,12 @@ public:
Status status() const { return m_status; } Status status() const { return m_status; }
const QString& hostname() const { return m_hostname; } const QString& hostname() const { return m_hostname; }
const QString serviceId() const { return QString(m_service_id); }
const QString& dataPath() const { return m_dataPath; } const QString& dataPath() const { return m_dataPath; }
CryptoKey privateKey() { return m_privateKey; } CryptoKey privateKey() { return m_privateKey; }
void setPrivateKey(const CryptoKey &privateKey); void setPrivateKey(const CryptoKey &privateKey);
void setServiceId(const QByteArray& sid);
const QList<Target> &targets() const { return m_targets; } const QList<Target> &targets() const { return m_targets; }
void addTarget(const Target &target); void addTarget(const Target &target);
@ -84,6 +86,7 @@ signals:
void statusChanged(int newStatus, int oldStatus); void statusChanged(int newStatus, int oldStatus);
void serviceOnline(); void serviceOnline();
void privateKeyChanged(); void privateKeyChanged();
void hostnameChanged();
private slots: private slots:
void servicePublished(); void servicePublished();
@ -94,6 +97,7 @@ private:
QString m_hostname; QString m_hostname;
Status m_status; Status m_status;
CryptoKey m_privateKey; CryptoKey m_privateKey;
QByteArray m_service_id;
void loadPrivateKey(); void loadPrivateKey();
void setStatus(Status newStatus); void setStatus(Status newStatus);

View file

@ -174,17 +174,16 @@ bool TorManager::setupHiddenService()
std::cerr << "Attempting to load key from legacy filesystem format in " << legacyDir.toStdString() << std::endl; std::cerr << "Attempting to load key from legacy filesystem format in " << legacyDir.toStdString() << std::endl;
CryptoKey key; CryptoKey key;
if (!key.loadFromFile(legacyDir + QLatin1String("/private_key"), CryptoKey::PrivateKey)) if (!key.loadFromFile(legacyDir + QLatin1String("/private_key")))
{ {
qWarning() << "Cannot load legacy format key from" << legacyDir << "for conversion"; qWarning() << "Cannot load legacy format key from" << legacyDir << "for conversion";
return false; return false;
} }
keyData = QString::fromLatin1(key.encodedPrivateKey(CryptoKey::DER).toBase64());
d->hiddenService = new Tor::HiddenService(key, legacyDir, this); d->hiddenService = new Tor::HiddenService(key, legacyDir, this);
std::cerr << "Got key from legacy dir: " << std::endl; std::cerr << "Got key from legacy dir: " << std::endl;
std::cerr << keyData.toStdString() << std::endl; std::cerr << key.bytes().toStdString() << std::endl;
} }
else else
{ {
@ -193,6 +192,7 @@ bool TorManager::setupHiddenService()
std::cerr << "Creating new hidden service." << std::endl; std::cerr << "Creating new hidden service." << std::endl;
connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ; connect(d->hiddenService, SIGNAL(privateKeyChanged()), this, SLOT(hiddenServicePrivateKeyChanged())) ;
connect(d->hiddenService, SIGNAL(hostnameChanged()), this, SLOT(hiddenServiceHostnameChanged())) ;
} }
Q_ASSERT(d->hiddenService); Q_ASSERT(d->hiddenService);
@ -230,31 +230,40 @@ void TorManager::hiddenServiceStatusChanged(int old_status,int new_status)
void TorManager::hiddenServicePrivateKeyChanged() void TorManager::hiddenServicePrivateKeyChanged()
{ {
QString key = QString::fromLatin1(d->hiddenService->privateKey().encodedPrivateKey(CryptoKey::DER).toBase64()); QString key = QString::fromLatin1(d->hiddenService->privateKey().bytes());
QFile outfile(d->hiddenServiceDir + QLatin1String("/private_key")) ; QFile outfile(d->hiddenServiceDir + QLatin1String("/private_key")) ;
outfile.open( QIODevice::WriteOnly | QIODevice::Text ); outfile.open( QIODevice::WriteOnly | QIODevice::Text );
QTextStream s(&outfile); QTextStream s(&outfile);
#ifdef TO_REMOVE
s << "-----BEGIN RSA PRIVATE KEY-----" << endl; s << "-----BEGIN RSA PRIVATE KEY-----" << endl;
for(uint32_t i=0;i<key.length();i+=64) for(int i=0;i<key.length();i+=64)
s << key.mid(i,64) << endl ; s << key.mid(i,64) << endl ;
s << "-----END RSA PRIVATE KEY-----" << endl; s << "-----END RSA PRIVATE KEY-----" << endl;
#endif
s << key ;
outfile.close(); outfile.close();
std::cerr << "Hidden service private key changed!" << std::endl; std::cerr << "Hidden service private key changed!" << std::endl;
std::cerr << key.toStdString() << std::endl; std::cerr << key.toStdString() << std::endl;
}
void TorManager::hiddenServiceHostnameChanged()
{
QFile outfile2(d->hiddenServiceDir + QLatin1String("/hostname")) ; QFile outfile2(d->hiddenServiceDir + QLatin1String("/hostname")) ;
outfile2.open( QIODevice::WriteOnly | QIODevice::Text ); outfile2.open( QIODevice::WriteOnly | QIODevice::Text );
QTextStream t(&outfile2); QTextStream t(&outfile2);
t << d->hiddenService->hostname() << endl; QString hostname(d->hiddenService->hostname());
t << hostname << endl;
outfile2.close(); outfile2.close();
std::cerr << "Hidden service hostname changed: " << hostname.toStdString() << std::endl;
} }
bool TorManager::configurationNeeded() const bool TorManager::configurationNeeded() const
@ -381,7 +390,7 @@ bool TorManager::getHiddenServiceInfo(QString& service_id,QString& service_onion
for(auto it(hidden_services.begin());it!=hidden_services.end();++it) for(auto it(hidden_services.begin());it!=hidden_services.end();++it)
{ {
service_onion_address = (*it)->hostname(); service_onion_address = (*it)->hostname();
service_id = (*it)->privateKey().torServiceID(); service_id = (*it)->serviceId();
for(auto it2((*it)->targets().begin());it2!=(*it)->targets().end();++it2) for(auto it2((*it)->targets().begin());it2!=(*it)->targets().end();++it2)
{ {

View file

@ -93,6 +93,7 @@ public slots:
private slots: private slots:
void hiddenServicePrivateKeyChanged(); void hiddenServicePrivateKeyChanged();
void hiddenServiceHostnameChanged();
void hiddenServiceStatusChanged(int old_status,int new_status); void hiddenServiceStatusChanged(int old_status,int new_status);
signals: signals:

View file

@ -30,6 +30,7 @@
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/common/FilesDefs.h"
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "gui/Circles/CreateCircleDialog.h" #include "gui/Circles/CreateCircleDialog.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
@ -53,7 +54,7 @@ CreateCircleDialog::CreateCircleDialog()
ui.setupUi(this); ui.setupUi(this);
/* Setup Queue */ /* Setup Queue */
ui.headerFrame->setHeaderImage(QPixmap(":/icons/png/circles.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/circles.png"));
// connect up the buttons. // connect up the buttons.
connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addMember())); connect(ui.addButton, SIGNAL(clicked()), this, SLOT(addMember()));

View file

@ -23,11 +23,12 @@
#include <math.h> #include <math.h>
#include <QStylePainter> #include <QStylePainter>
#include <QDebug> #include <QDebug>
#include <retroshare/rsfiles.h> #include "retroshare/rsfiles.h"
#include <retroshare/rstypes.h> #include "retroshare/rstypes.h"
#include "util/misc.h" #include "util/misc.h"
#include "FileTransferInfoWidget.h" #include "FileTransferInfoWidget.h"
#include <gui/RetroShareLink.h> #include "gui/RetroShareLink.h"
#include "gui/common/FilesDefs.h"
// Variables to decide of display behaviour. All variables are expressed as a factor of font height // Variables to decide of display behaviour. All variables are expressed as a factor of font height
// //
@ -49,10 +50,10 @@ FileTransferInfoWidget::FileTransferInfoWidget(QWidget * /*parent*/, Qt::WindowF
int S = 0.9*QFontMetricsF(font()).height(); int S = 0.9*QFontMetricsF(font()).height();
downloadedPixmap = QPixmap(":/icons/tile_downloaded_48.png").scaledToHeight(S,Qt::SmoothTransformation); downloadedPixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/tile_downloaded_48.png").scaledToHeight(S,Qt::SmoothTransformation);
downloadingPixmap = QPixmap(":/icons/tile_downloading_48.png").scaledToHeight(S,Qt::SmoothTransformation); downloadingPixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/tile_downloading_48.png").scaledToHeight(S,Qt::SmoothTransformation);
notDownloadPixmap = QPixmap(":/icons/tile_inactive_48.png").scaledToHeight(S,Qt::SmoothTransformation); notDownloadPixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/tile_inactive_48.png").scaledToHeight(S,Qt::SmoothTransformation);
checkingPixmap = QPixmap(":/icons/tile_checking_48.png").scaledToHeight(S,Qt::SmoothTransformation); checkingPixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/tile_checking_48.png").scaledToHeight(S,Qt::SmoothTransformation);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
} }

View file

@ -43,7 +43,8 @@
#include <retroshare/rsexpr.h> #include <retroshare/rsexpr.h>
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_START ":/images/download.png" #define IMAGE_START ":/icons/png/download.png"
#define IMAGE_SEARCHAGAIN ":/images/update.png"
#define IMAGE_REMOVE ":/images/delete.png" #define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_REMOVEALL ":/images/deleteall.png" #define IMAGE_REMOVEALL ":/images/deleteall.png"
#define IMAGE_DIRECTORY ":/images/folder16.png" #define IMAGE_DIRECTORY ":/images/folder16.png"
@ -670,14 +671,14 @@ void SearchDialog::searchSummaryWidgetCustomPopupMenu( QPoint /*point*/ )
QMenu contextMnu(this); QMenu contextMnu(this);
QTreeWidgetItem* ci = ui.searchSummaryWidget->currentItem(); QTreeWidgetItem* ci = ui.searchSummaryWidget->currentItem();
QAction* action = contextMnu.addAction(tr("Search again"), this, SLOT(searchAgain())); QAction* action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_SEARCHAGAIN),tr("Search again"), this, SLOT(searchAgain()));
if (!ci || ci->data(SS_DATA_COL, ROLE_KEYWORDS).toString().isEmpty()) { if (!ci || ci->data(SS_DATA_COL, ROLE_KEYWORDS).toString().isEmpty()) {
action->setDisabled(true); action->setDisabled(true);
} }
contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove"), this, SLOT(searchRemove())); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVE), tr("Remove"), this, SLOT(searchRemove()));
contextMnu.addAction(QIcon(IMAGE_REMOVE), tr("Remove All"), this, SLOT(searchRemoveAll())); contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_REMOVEALL), tr("Remove All"), this, SLOT(searchRemoveAll()));
contextMnu.addSeparator(); contextMnu.addSeparator();
action = contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copySearchLink())); action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copySearchLink()));
if (!ci || ci->data(SS_DATA_COL, ROLE_KEYWORDS).toString().isEmpty()) { if (!ci || ci->data(SS_DATA_COL, ROLE_KEYWORDS).toString().isEmpty()) {
action->setDisabled(true); action->setDisabled(true);
} }

View file

@ -37,6 +37,7 @@
#include "util/RsAction.h" #include "util/RsAction.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/rstime.h" #include "util/rstime.h"
#include "util/rsdir.h"
#include <retroshare/rsexpr.h> #include <retroshare/rsexpr.h>
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
@ -55,7 +56,7 @@
#include <set> #include <set>
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_DOWNLOAD ":/images/download16.png" #define IMAGE_DOWNLOAD ":/icons/png/download.png"
#define IMAGE_PLAY ":/images/start.png" #define IMAGE_PLAY ":/images/start.png"
#define IMAGE_HASH_BUSY ":/images/settings.png" #define IMAGE_HASH_BUSY ":/images/settings.png"
#define IMAGE_HASH_DONE ":/images/accepted16.png" #define IMAGE_HASH_DONE ":/images/accepted16.png"
@ -72,8 +73,9 @@
#define IMAGE_COLLMODIF ":/icons/png/pencil-edit-button.png" #define IMAGE_COLLMODIF ":/icons/png/pencil-edit-button.png"
#define IMAGE_COLLVIEW ":/images/find.png" #define IMAGE_COLLVIEW ":/images/find.png"
#define IMAGE_COLLOPEN ":/icons/collections.png" #define IMAGE_COLLOPEN ":/icons/collections.png"
#define IMAGE_EDITSHARE ":/images/edit_16.png" #define IMAGE_EDITSHARE ":/icons/png/pencil-edit-button.png"
#define IMAGE_MYFILES ":/icons/svg/folders1.svg" #define IMAGE_MYFILES ":/icons/svg/folders1.svg"
#define IMAGE_UNSHAREEXTRA ":/images/button_cancel.png"
/*define viewType_CB value */ /*define viewType_CB value */
#define VIEW_TYPE_TREE 0 #define VIEW_TYPE_TREE 0
@ -232,7 +234,7 @@ SharedFilesDialog::SharedFilesDialog(bool remote_mode, QWidget *parent)
sendlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links" ), this ); sendlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Links" ), this );
connect( sendlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) ); connect( sendlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) );
removeExtraFileAct = new QAction(QIcon(), tr( "Stop sharing this file" ), this ); removeExtraFileAct = new QAction(QIcon(IMAGE_UNSHAREEXTRA), tr( "Stop sharing this file" ), this );
connect( removeExtraFileAct , SIGNAL( triggered() ), this, SLOT( removeExtraFile() ) ); connect( removeExtraFileAct , SIGNAL( triggered() ), this, SLOT( removeExtraFile() ) );
collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this) ; collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this) ;
@ -266,7 +268,7 @@ LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent)
openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this) ; openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this) ;
connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder())) ; connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder())) ;
ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ; ui.titleBarPixmap->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_MYFILES)) ;
ui.dirTreeView->setItemDelegateForColumn(COLUMN_FRIEND_ACCESS,new ShareFlagsItemDelegate()) ; ui.dirTreeView->setItemDelegateForColumn(COLUMN_FRIEND_ACCESS,new ShareFlagsItemDelegate()) ;
} }
@ -498,7 +500,7 @@ void LocalSharedFilesDialog::checkUpdate()
else else
{ {
ui.checkButton->setText(tr("Check files")); ui.checkButton->setText(tr("Check files"));
ui.hashLabel->setPixmap(QPixmap(IMAGE_HASH_DONE)); ui.hashLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_HASH_DONE));
ui.hashLabel->setToolTip("") ; ui.hashLabel->setToolTip("") ;
} }
@ -644,7 +646,16 @@ void SharedFilesDialog::copyLinks(const QModelIndexList& lst, bool remote,QList<
has_unhashed_files = true; has_unhashed_files = true;
continue; continue;
} }
RetroShareLink link = RetroShareLink::createFile(QString::fromUtf8(details.name.c_str()), details.count, details.hash.toStdString().c_str()); QString name;
if(details.type == DIR_TYPE_EXTRA_FILE)
{
std::string dir,file;
RsDirUtil::splitDirFromFile(details.name,dir,file) ;
name = QString::fromStdString(file);
}
else
name = QString::fromUtf8(details.name.c_str());
RetroShareLink link = RetroShareLink::createFile(name, details.count, details.hash.toStdString().c_str());
if (link.valid()) { if (link.valid()) {
urls.push_back(link) ; urls.push_back(link) ;
} }
@ -876,7 +887,7 @@ void LocalSharedFilesDialog::openfolder()
std::cerr << "SharedFilesDialog::openfolder" << std::endl; std::cerr << "SharedFilesDialog::openfolder" << std::endl;
QModelIndexList qmil = getSelected(); QModelIndexList qmil = getSelected();
model->openSelected(qmil); model->openSelected(qmil, true);
} }
void SharedFilesDialog::preModDirectories(bool local) void SharedFilesDialog::preModDirectories(bool local)
@ -1144,6 +1155,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
case DIR_TYPE_EXTRA_FILE: case DIR_TYPE_EXTRA_FILE:
contextMnu.addAction(openfileAct) ; contextMnu.addAction(openfileAct) ;
contextMnu.addAction(openfolderAct) ;
contextMnu.addSeparator() ;//------------------------------------ contextMnu.addSeparator() ;//------------------------------------
contextMnu.addAction(copylinkAct) ; contextMnu.addAction(copylinkAct) ;
contextMnu.addAction(sendlinkAct) ; contextMnu.addAction(sendlinkAct) ;

View file

@ -88,10 +88,6 @@
<property name="text"> <property name="text">
<string>Configure shared directories</string> <string>Configure shared directories</string>
</property> </property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View file

@ -35,6 +35,7 @@
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "TorControl/TorManager.h" #include "TorControl/TorManager.h"
#include "util/misc.h" #include "util/misc.h"
#include "gui/common/FilesDefs.h"
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
#include <retroshare/rsinit.h> #include <retroshare/rsinit.h>
@ -132,7 +133,7 @@ GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent)
/* Invoke Qt Designer generated QObject setup routine */ /* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this); ui.setupUi(this);
//ui.headerFrame->setHeaderImage(QPixmap(":/icons/svg/profile.svg")); //ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/svg/profile.svg"));
//ui.headerFrame->setHeaderText(tr("Create a new profile")); //ui.headerFrame->setHeaderText(tr("Create a new profile"));
connect(ui.reuse_existing_node_CB, SIGNAL(triggered()), this, SLOT(switchReuseExistingNode())); connect(ui.reuse_existing_node_CB, SIGNAL(triggered()), this, SLOT(switchReuseExistingNode()));
@ -432,9 +433,9 @@ void GenCertDialog::updateCheckLabels()
} }
if(mEntropyOk) if(mEntropyOk)
ui.randomness_check_LB->setPixmap(QPixmap(IMAGE_GOOD)) ; ui.randomness_check_LB->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_GOOD)) ;
else else
ui.randomness_check_LB->setPixmap(QPixmap(IMAGE_BAD)) ; ui.randomness_check_LB->setPixmap(FilesDefs::getPixmapFromQtResourcePath(IMAGE_BAD)) ;
setupState(); setupState();
} }

View file

@ -105,7 +105,7 @@ void GetStartedDialog::showEvent ( QShowEvent * /*event*/ )
void GetStartedDialog::updateFromUserLevel() void GetStartedDialog::updateFromUserLevel()
{ {
uint32_t userLevel = RSCONFIG_USER_LEVEL_NEW; RsConfigUserLvl userLevel = RsConfigUserLvl::NEW;
userLevel = rsConfig->getUserLevel(); userLevel = rsConfig->getUserLevel();
ui.inviteCheckBox->setChecked(false); ui.inviteCheckBox->setChecked(false);
@ -116,19 +116,19 @@ void GetStartedDialog::updateFromUserLevel()
switch(userLevel) switch(userLevel)
{ {
// FALLS THROUGH EVERYWHERE. // FALLS THROUGH EVERYWHERE.
case RSCONFIG_USER_LEVEL_POWER: case RsConfigUserLvl::POWER:
case RSCONFIG_USER_LEVEL_OVERRIDE: case RsConfigUserLvl::OVERRIDE:
ui.firewallCheckBox->setChecked(true); ui.firewallCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_CASUAL: case RsConfigUserLvl::CASUAL:
ui.connectCheckBox->setChecked(true); ui.connectCheckBox->setChecked(true);
/* fallthrough */ /* fallthrough */
case RSCONFIG_USER_LEVEL_BASIC: case RsConfigUserLvl::BASIC:
ui.addCheckBox->setChecked(true); ui.addCheckBox->setChecked(true);
ui.inviteCheckBox->setChecked(true); ui.inviteCheckBox->setChecked(true);
default: default:
case RSCONFIG_USER_LEVEL_NEW: case RsConfigUserLvl::NEW:
break; break;
} }
@ -325,7 +325,7 @@ void GetStartedDialog::emailSupport()
return; return;
} }
uint32_t userLevel; RsConfigUserLvl userLevel;
{ {
RsAutoUpdatePage::lockAllEvents(); RsAutoUpdatePage::lockAllEvents();
@ -427,7 +427,7 @@ void GetStartedDialog::emailSupport()
sysVersion = "Linux"; sysVersion = "Linux";
#endif #endif
#endif #endif
text += QString("My RetroShare Configuration is: (%1, %2, 0x60%3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(userLevel) + "\n"; text += QString("My RetroShare Configuration is: (%1, %2, %3)").arg(Rshare::retroshareVersion(true)).arg(sysVersion).arg(static_cast<typename std::underlying_type<RsConfigUserLvl>::type>(userLevel)) + "\n";
text += "\n"; text += "\n";
text += QString("I am having trouble with RetroShare."); text += QString("I am having trouble with RetroShare.");

View file

@ -189,8 +189,6 @@ void HomePage::updateOwnCert()
void HomePage::updateOwnId() void HomePage::updateOwnId()
{ {
bool include_extra_locators = mIncludeAllIPs;
RsPeerDetails detail; RsPeerDetails detail;
if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail)) if (!rsPeers->getPeerDetails(rsPeers->getOwnId(), detail))
@ -199,10 +197,29 @@ void HomePage::updateOwnId()
return ; return ;
} }
bool include_extra_locators = mIncludeAllIPs || detail.isHiddenNode;
std::string invite ; std::string invite ;
rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!mIncludeAllIPs); rsPeers->getShortInvite(invite,rsPeers->getOwnId(),true,!include_extra_locators);
#ifdef TODO
QString S;
QString txt;
int i=0;
for(uint32_t i=0;i<invite.size();)
if(QFontMetricsF(font()).width(S) < ui->retroshareid->width())
S += invite[i++];
else
{
txt += S + "\n";
S.clear();
}
txt += S;
ui->retroshareid->setText(txt);
#endif
ui->retroshareid->setText(QString::fromUtf8(invite.c_str())); ui->retroshareid->setText(QString::fromUtf8(invite.c_str()));
} }
static void sendMail(QString sAddress, QString sSubject, QString sBody) static void sendMail(QString sAddress, QString sSubject, QString sBody)

View file

@ -174,7 +174,7 @@ private and secure decentralized communication platform.
<string>...</string> <string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="images.qrc"> <iconset resource="icons.qrc">
<normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset> <normaloff>:/icons/help_64.png</normaloff>:/icons/help_64.png</iconset>
</property> </property>
<property name="checkable"> <property name="checkable">
@ -186,22 +186,16 @@ private and secure decentralized communication platform.
</widget> </widget>
</item> </item>
<item row="1" column="4"> <item row="1" column="4">
<widget class="QToolButton" name="shareButton"> <widget class="QToolButton" name="expandButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Share your RetroShare ID&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>Show full certificate (old format)</string>
</property>
<property name="text">
<string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="icons.qrc">
<normaloff>:/icons/svg/share.svg</normaloff>:/icons/svg/share.svg</iconset> <normaloff>:/icons/png/cert.png</normaloff>:/icons/png/cert.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -209,8 +203,8 @@ private and secure decentralized communication platform.
<height>24</height> <height>24</height>
</size> </size>
</property> </property>
<property name="popupMode"> <property name="checkable">
<enum>QToolButton::InstantPopup</enum> <bool>true</bool>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
<bool>true</bool> <bool>true</bool>
@ -218,7 +212,7 @@ private and secure decentralized communication platform.
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QLabel" name="retroshareid"> <widget class="ElidedLabel" name="retroshareid">
<property name="font"> <property name="font">
<font> <font>
<pointsize>10</pointsize> <pointsize>10</pointsize>
@ -232,12 +226,36 @@ private and secure decentralized communication platform.
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="5"> <item row="0" column="2">
<widget class="QLabel" name="userCertLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="text">
<string>This is your Retroshare ID. Copy and share with your friends!</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="0" colspan="6">
<widget class="QPlainTextEdit" name="userCertEdit"> <widget class="QPlainTextEdit" name="userCertEdit">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -273,38 +291,23 @@ private and secure decentralized communication platform.
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item row="1" column="3">
<widget class="QLabel" name="userCertLabel"> <widget class="QToolButton" name="shareButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="font"> <property name="focusPolicy">
<font> <enum>Qt::NoFocus</enum>
<pointsize>11</pointsize>
</font>
</property> </property>
<property name="text">
<string>This is your Retroshare ID. Copy and share with your friends!</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="expandButton">
<property name="toolTip"> <property name="toolTip">
<string>Show full certificate (old format)</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Share your RetroShare ID&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="icons.qrc"> <iconset resource="icons.qrc">
<normaloff>:/icons/png/cert.png</normaloff>:/icons/png/cert.png</iconset> <normaloff>:/icons/svg/share.svg</normaloff>:/icons/svg/share.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -312,8 +315,8 @@ private and secure decentralized communication platform.
<height>24</height> <height>24</height>
</size> </size>
</property> </property>
<property name="checkable"> <property name="popupMode">
<bool>true</bool> <enum>QToolButton::InstantPopup</enum>
</property> </property>
<property name="autoRaise"> <property name="autoRaise">
<bool>true</bool> <bool>true</bool>
@ -337,9 +340,17 @@ private and secure decentralized communication platform.
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ElidedLabel</class>
<extends>QLabel</extends>
<header location="global">gui/common/ElidedLabel.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="images.qrc"/>
<include location="icons.qrc"/> <include location="icons.qrc"/>
<include location="images.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View file

@ -25,6 +25,7 @@
#include "util/qtthreadsutils.h" #include "util/qtthreadsutils.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include "gui/common/FilesDefs.h"
#include "gui/msgs/MessageComposer.h" #include "gui/msgs/MessageComposer.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
@ -82,7 +83,7 @@ IdDetailsDialog::IdDetailsDialog(const RsGxsGroupId& id, QWidget *parent) :
Settings->loadWidgetInformation(this); Settings->loadWidgetInformation(this);
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/person.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/person.png"));
ui->headerFrame->setHeaderText(tr("Person Details")); ui->headerFrame->setHeaderText(tr("Person Details"));
//connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(changeGroup())); //connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(changeGroup()));

View file

@ -110,7 +110,7 @@
#define RSID_FILTER_BANNED 0x0020 #define RSID_FILTER_BANNED 0x0020
#define RSID_FILTER_ALL 0xffff #define RSID_FILTER_ALL 0xffff
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/icons/png/pencil-edit-button.png"
#define IMAGE_CREATE ":/icons/circle_new_128.png" #define IMAGE_CREATE ":/icons/circle_new_128.png"
#define IMAGE_INVITED ":/icons/bullet_yellow_128.png" #define IMAGE_INVITED ":/icons/bullet_yellow_128.png"
#define IMAGE_MEMBER ":/icons/bullet_green_128.png" #define IMAGE_MEMBER ":/icons/bullet_green_128.png"
@ -255,7 +255,7 @@ IdDialog::IdDialog(QWidget *parent) : MainPage(parent), ui(new Ui::IdDialog)
this, &IdDialog::chatIdentityItem ); this, &IdDialog::chatIdentityItem );
ui->avlabel_Circles->setPixmap(QPixmap(":/icons/png/circles.png")); ui->avlabel_Circles->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/circles.png"));
ui->headerTextLabel_Circles->setText(tr("Circles")); ui->headerTextLabel_Circles->setText(tr("Circles"));
@ -459,7 +459,7 @@ void IdDialog::clearPerson()
{ {
QFontMetricsF f(ui->avLabel_Person->font()) ; QFontMetricsF f(ui->avLabel_Person->font()) ;
ui->avLabel_Person->setPixmap(QPixmap(":/icons/png/people.png").scaled(f.height()*4,f.height()*4,Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); ui->avLabel_Person->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/people.png").scaled(f.height()*4,f.height()*4,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
ui->headerTextLabel_Person->setText(tr("People")); ui->headerTextLabel_Person->setText(tr("People"));
ui->inviteFrame->hide(); ui->inviteFrame->hide();
@ -2174,7 +2174,7 @@ void IdDialog::IdListCustomPopupMenu( QPoint )
hbox->setSpacing(6); hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix); iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel); hbox->addWidget(iconLabel);

View file

@ -268,7 +268,7 @@
</widget> </widget>
<widget class="QTabWidget" name="rightTabWidget"> <widget class="QTabWidget" name="rightTabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="personTab"> <widget class="QWidget" name="personTab">
<attribute name="icon"> <attribute name="icon">
@ -289,8 +289,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1372</width> <width>634</width>
<height>719</height> <height>523</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="scrollAreaWidgetContentsVLayout"> <layout class="QVBoxLayout" name="scrollAreaWidgetContentsVLayout">
@ -1031,7 +1031,7 @@ border-image: url(:/images/closepressed.png)
</layout> </layout>
<action name="editIdentity"> <action name="editIdentity">
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset>
<normaloff>:/images/edit_16.png</normaloff>:/images/edit_16.png</iconset> <normaloff>:/images/edit_16.png</normaloff>:/images/edit_16.png</iconset>
</property> </property>
<property name="text"> <property name="text">

View file

@ -32,6 +32,7 @@
#include <retroshare/rsidentity.h> #include <retroshare/rsidentity.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include "gui/common/FilesDefs.h"
#include <iostream> #include <iostream>
@ -47,7 +48,7 @@ IdEditDialog::IdEditDialog(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/person.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/person.png"));
ui->headerFrame->setHeaderText(tr("Create New Identity")); ui->headerFrame->setHeaderText(tr("Create New Identity"));
/* Setup UI helper */ /* Setup UI helper */
@ -199,7 +200,7 @@ void IdEditDialog::setAvatar(const QPixmap &avatar)
void IdEditDialog::setupExistingId(const RsGxsGroupId& keyId) void IdEditDialog::setupExistingId(const RsGxsGroupId& keyId)
{ {
setWindowTitle(tr("Edit identity")); setWindowTitle(tr("Edit identity"));
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/person.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/person.png"));
ui->headerFrame->setHeaderText(tr("Edit identity")); ui->headerFrame->setHeaderText(tr("Edit identity"));
mStateHelper->setLoading(IDEDITDIALOG_LOADID, true); mStateHelper->setLoading(IDEDITDIALOG_LOADID, true);

View file

@ -20,8 +20,9 @@
#include "LogoBar.h" #include "LogoBar.h"
#include <util/RetroStyleLabel.h> #include "util/RetroStyleLabel.h"
#include <util/MouseEventFilter.h> #include "util/MouseEventFilter.h"
#include "gui/common/FilesDefs.h"
#include <QGridLayout> #include <QGridLayout>
@ -42,11 +43,11 @@ void LogoBar::init() {
//LogoButton //LogoButton
_logoButton = new RetroStyleLabel(this); _logoButton = new RetroStyleLabel(this);
_logoButton->setPixmaps( _logoButton->setPixmaps(
QPixmap(":/images/logobar/rslogo2.png"), //Start FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/rslogo2.png"), //Start
QPixmap(), //End QPixmap(), //End
QPixmap(), //Fill QPixmap(), //Fill
QPixmap(":/images/logobar/rslogo2.png"), //Start FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/rslogo2.png"), //Start
QPixmap(), //End QPixmap(), //End
QPixmap() //Fill QPixmap() //Fill
); );
@ -59,11 +60,11 @@ void LogoBar::init() {
FillLabel1->setPixmaps( FillLabel1->setPixmaps(
QPixmap(), //Start QPixmap(), //Start
QPixmap(), //End QPixmap(), //End
QPixmap(":/images/logobar/logo_bar_fill.png"), //Fill FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/logo_bar_fill.png"), //Fill
QPixmap(), //Start QPixmap(), //Start
QPixmap(), //End QPixmap(), //End
QPixmap(":/images/logobar/logo_bar_fill.png") //Fill FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/logo_bar_fill.png") //Fill
); );
//FillLabel2 //FillLabel2
@ -71,11 +72,11 @@ void LogoBar::init() {
FillLabel2->setPixmaps( FillLabel2->setPixmaps(
QPixmap(), //Start QPixmap(), //Start
QPixmap(), //End QPixmap(), //End
QPixmap(":/images/logobar/logo_bar_fill.png"), //Fill FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/logo_bar_fill.png"), //Fill
QPixmap(), //Start QPixmap(), //Start
QPixmap(), //End QPixmap(), //End
QPixmap(":/images/logobar/logo_bar_fill.png") //Fill FilesDefs::getPixmapFromQtResourcePath(":/images/logobar/logo_bar_fill.png") //Fill
); );
QGridLayout * layout = new QGridLayout(this); QGridLayout * layout = new QGridLayout(this);

View file

@ -146,8 +146,8 @@
#define IMAGE_ADDSHARE ":/images/directoryadd_24x24_shadow.png" #define IMAGE_ADDSHARE ":/images/directoryadd_24x24_shadow.png"
#define IMAGE_OPTIONS ":/images/settings.png" #define IMAGE_OPTIONS ":/images/settings.png"
#define IMAGE_UNFINISHED ":/images/underconstruction.png" #define IMAGE_UNFINISHED ":/images/underconstruction.png"
#define IMAGE_MINIMIZE ":/images/window_nofullscreen.png" #define IMAGE_MINIMIZE ":/icons/fullscreen.png"
#define IMAGE_MAXIMIZE ":/images/window_fullscreen.png" #define IMAGE_MAXIMIZE ":/icons/fullscreen-exit.png"
#define IMAGE_PLUGINS ":/images/extension_32.png" #define IMAGE_PLUGINS ":/images/extension_32.png"
@ -1563,13 +1563,13 @@ void MainWindow::processLastArgs()
if (opModeStatus) { if (opModeStatus) {
QString opmode = Rshare::opmode().toLower(); QString opmode = Rshare::opmode().toLower();
if (opmode == "noturtle") { if (opmode == "noturtle") {
opModeStatus->setCurrentIndex(RS_OPMODE_NOTURTLE - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::NOTURTLE) - 1);
} else if (opmode == "gaming") { } else if (opmode == "gaming") {
opModeStatus->setCurrentIndex(RS_OPMODE_GAMING - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::GAMING) - 1);
} else if (opmode == "minimal") { } else if (opmode == "minimal") {
opModeStatus->setCurrentIndex(RS_OPMODE_MINIMAL - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::MINIMAL) - 1);
} else if (opmode != "") { } else if (opmode != "") {
opModeStatus->setCurrentIndex(RS_OPMODE_FULL - 1); opModeStatus->setCurrentIndex(static_cast<typename std::underlying_type<RsOpMode>::type>(RsOpMode::FULL) - 1);
} }
opModeStatus->setOpMode(); opModeStatus->setOpMode();
} else { } else {

View file

@ -29,6 +29,7 @@
#include "gui/Identity/IdDetailsDialog.h" #include "gui/Identity/IdDetailsDialog.h"
#include "gui/Identity/IdDialog.h" #include "gui/Identity/IdDialog.h"
#include "gui/MainWindow.h" #include "gui/MainWindow.h"
#include "gui/common/FilesDefs.h"
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsidentity.h" #include "retroshare/rsidentity.h"
@ -440,7 +441,7 @@ void PeopleDialog::iw_AddButtonClickedExt()
{ {
QMenu contextMnu( this ); QMenu contextMnu( this );
QMenu *mnu = contextMnu.addMenu(QIcon(":/icons/png/circles.png"),tr("Invite to Circle")) ; QMenu *mnu = contextMnu.addMenu(FilesDefs::getIconFromQtResourcePath(":/icons/png/circles.png"),tr("Invite to Circle")) ;
std::map<RsGxsGroupId, CircleWidget*>::iterator itCurs; std::map<RsGxsGroupId, CircleWidget*>::iterator itCurs;
for( itCurs =_ext_circles_widgets.begin(); itCurs != _ext_circles_widgets.end(); ++itCurs) for( itCurs =_ext_circles_widgets.begin(); itCurs != _ext_circles_widgets.end(); ++itCurs)
@ -459,7 +460,7 @@ void PeopleDialog::iw_AddButtonClickedExt()
if(own_identities.size() <= 1) if(own_identities.size() <= 1)
{ {
QAction *action = contextMnu.addAction(QIcon(":/images/chat_24.png"), tr("Chat with this person"), this, SLOT(chatIdentity())); QAction *action = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"), tr("Chat with this person"), this, SLOT(chatIdentity()));
if(own_identities.empty()) if(own_identities.empty())
action->setEnabled(false) ; action->setEnabled(false) ;
@ -468,7 +469,7 @@ void PeopleDialog::iw_AddButtonClickedExt()
} }
else else
{ {
QMenu *mnu = contextMnu.addMenu(QIcon(":/icons/png/chats.png"),tr("Chat with this person as...")) ; QMenu *mnu = contextMnu.addMenu(FilesDefs::getIconFromQtResourcePath(":/icons/png/chats.png"),tr("Chat with this person as...")) ;
for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it) for(std::list<RsGxsId>::const_iterator it=own_identities.begin();it!=own_identities.end();++it)
{ {
@ -485,20 +486,20 @@ void PeopleDialog::iw_AddButtonClickedExt()
} }
} }
QAction *actionsendmsg = contextMnu.addAction(QIcon(":/icons/mail/write-mail.png"), tr("Send message"), this, SLOT(sendMessage())); QAction *actionsendmsg = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/icons/mail/write-mail.png"), tr("Send message"), this, SLOT(sendMessage()));
actionsendmsg->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString())); actionsendmsg->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString()));
QAction *actionsendinvite = contextMnu.addAction(QIcon(":/icons/mail/write-mail.png"), tr("Send invite"), this, SLOT(sendInvite())); QAction *actionsendinvite = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/icons/mail/write-mail.png"), tr("Send invite"), this, SLOT(sendInvite()));
actionsendinvite->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString())); actionsendinvite->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString()));
contextMnu.addSeparator(); contextMnu.addSeparator();
QAction *actionaddcontact = contextMnu.addAction(QIcon(""), tr("Add to Contacts"), this, SLOT(addtoContacts())); QAction *actionaddcontact = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(""), tr("Add to Contacts"), this, SLOT(addtoContacts()));
actionaddcontact->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString())); actionaddcontact->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString()));
contextMnu.addSeparator(); contextMnu.addSeparator();
QAction *actionDetails = contextMnu.addAction(QIcon(":/images/info16.png"), tr("Person details"), this, SLOT(personDetails())); QAction *actionDetails = contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/info16.png"), tr("Person details"), this, SLOT(personDetails()));
actionDetails->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString())); actionDetails->setData( QString::fromStdString(dest->groupInfo().mMeta.mGroupId.toStdString()));
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());

View file

@ -31,7 +31,7 @@ AlbumDialog::AlbumDialog(const RsPhotoAlbum& album, TokenQueue* photoQueue, RsPh
{ {
ui->setupUi(this); ui->setupUi(this);
ui->headerFrame->setHeaderImage(QPixmap(":/images/kview_64.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/kview_64.png"));
ui->headerFrame->setHeaderText(tr("Album")); ui->headerFrame->setHeaderText(tr("Album"));
connect(ui->pushButton_PublishPhotos, SIGNAL(clicked()), this, SLOT(updateAlbumPhotos())); connect(ui->pushButton_PublishPhotos, SIGNAL(clicked()), this, SLOT(updateAlbumPhotos()));
@ -69,7 +69,7 @@ void AlbumDialog::setUp()
else else
{ {
// display a default Album icon when album has no Thumbnail // display a default Album icon when album has no Thumbnail
ui->label_thumbNail->setPixmap(QPixmap(":/images/album_default_128.png")); ui->label_thumbNail->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/album_default_128.png"));
} }
} }

View file

@ -99,7 +99,7 @@ void AlbumGroupDialog::initUi()
QPixmap AlbumGroupDialog::serviceImage() QPixmap AlbumGroupDialog::serviceImage()
{ {
return QPixmap(":/images/album_create_64.png"); return FilesDefs::getPixmapFromQtResourcePath(":/images/album_create_64.png");
} }
void AlbumGroupDialog::prepareAlbumGroup(RsPhotoAlbum &group, const RsGroupMetaData &meta) void AlbumGroupDialog::prepareAlbumGroup(RsPhotoAlbum &group, const RsGroupMetaData &meta)
@ -175,7 +175,7 @@ bool AlbumGroupDialog::service_loadGroup(const RsGxsGenericGroupData *data, Mode
setLogo(pixmap); setLogo(pixmap);
} }
} else { } else {
setLogo(QPixmap(":/images/album_create_64.png")); setLogo(FilesDefs::getPixmapFromQtResourcePath(":/images/album_create_64.png"));
} }
// Load additional data.... // Load additional data....

View file

@ -51,7 +51,7 @@ void AlbumItem::setUp()
else else
{ {
// display a default Album icon when album has no Thumbnail // display a default Album icon when album has no Thumbnail
ui->label_Thumbnail->setPixmap(QPixmap(":/images/album_default_128.png")); ui->label_Thumbnail->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/album_default_128.png"));
} }
} }

View file

@ -59,7 +59,7 @@ PhotoItem::PhotoItem(PhotoShareItemHolder *holder, const QString& path, uint32_t
mPhotoDetails.mOrder = order; mPhotoDetails.mOrder = order;
QPixmap qtn = QPixmap(path); QPixmap qtn = FilesDefs::getPixmapFromQtResourcePath(path);
mLowResImage = qtn.scaled(512,512, Qt::KeepAspectRatio, Qt::SmoothTransformation); mLowResImage = qtn.scaled(512,512, Qt::KeepAspectRatio, Qt::SmoothTransformation);
ui->label_Thumbnail->setPixmap(qtn.scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)); ui->label_Thumbnail->setPixmap(qtn.scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation));

View file

@ -0,0 +1,511 @@
/*******************************************************************************
* retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp *
* *
* Copyright (C) 2019 Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <QDateTime>
#include <QMenu>
#include <QStyle>
#include <QTextDocument>
#include <QToolButton>
#include "rshare.h"
#include "BoardPostDisplayWidget.h"
#include "PhotoView.h"
#include "gui/gxs/GxsIdDetails.h"
#include "util/misc.h"
#include "gui/common/FilesDefs.h"
#include "util/qtthreadsutils.h"
#include "util/HandleRichText.h"
#include "gui/Identity/IdDialog.h"
#include "gui/MainWindow.h"
#include "ui_BoardPostDisplayWidget_compact.h"
#include "ui_BoardPostDisplayWidget_card.h"
#include <retroshare/rsposted.h>
#include <iostream>
#define LINK_IMAGE ":/images/thumb-link.png"
// #ifdef DEBUG_BOARDPOSTDISPLAYWIDGET 1
/** Constructor */
const char *BoardPostDisplayWidget_compact::DEFAULT_BOARD_IMAGE = ":/icons/png/newsfeed2.png";
//===================================================================================================================================
//== Base class BoardPostDisplayWidgetBase ==
//===================================================================================================================================
BoardPostDisplayWidgetBase::BoardPostDisplayWidgetBase(const RsPostedPost& post,uint8_t display_flags,QWidget *parent)
: QWidget(parent), mPost(post),mDisplayFlags(display_flags)
{
}
void BoardPostDisplayWidgetBase::setCommentsSize(int comNb)
{
QString sComButText ;
if (comNb == 1)
sComButText = tr("1 comment");
else if(comNb > 1)
sComButText = tr("%1 comments").arg(comNb);
else
sComButText = tr("No comments yet. Click to add one.");
commentButton()->setToolTip(sComButText);
if(comNb > 0)
commentButton()->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/comments_blue.png"));
else
commentButton()->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/comments.png"));
// QString sComButText = tr("Comment");
// if (comNb == 1)
// sComButText = sComButText.append("(1)");
// else if(comNb > 1)
// sComButText = tr("Comments ").append("(%1)").arg(comNb);
//
commentButton()->setText(tr("Comments"));
}
void BoardPostDisplayWidgetBase::makeDownVote()
{
RsGxsGrpMsgIdPair msgId;
msgId.first = mPost.mMeta.mGroupId;
msgId.second = mPost.mMeta.mMsgId;
voteUpButton()->setEnabled(false);
voteDownButton()->setEnabled(false);
emit vote(msgId, false);
}
void BoardPostDisplayWidgetBase::makeUpVote()
{
RsGxsGrpMsgIdPair msgId;
msgId.first = mPost.mMeta.mGroupId;
msgId.second = mPost.mMeta.mMsgId;
voteUpButton()->setEnabled(false);
voteDownButton()->setEnabled(false);
emit vote(msgId, true);
}
void BoardPostDisplayWidgetBase::setReadStatus(bool isNew, bool isUnread)
{
if (isUnread)
readButton()->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-unread.png"));
else
readButton()->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/message-state-read.png"));
newLabel()->setVisible(isNew);
mainFrame()->setProperty("new", isNew);
mainFrame()->style()->unpolish(mainFrame());
mainFrame()->style()->polish(mainFrame());
}
void BoardPostDisplayWidget_compact::doExpand(bool e)
{
#ifdef DEBUG_BOARDPOSTDISPLAYWIDGET
std::cerr << "Expanding" << std::endl;
#endif
if(e)
ui->frame_notes->show();
else
ui->frame_notes->hide();
emit expand(mPost.mMeta.mMsgId,e);
}
void BoardPostDisplayWidgetBase::loadComments(bool e)
{
emit commentsRequested(mPost.mMeta.mMsgId,e);
}
void BoardPostDisplayWidgetBase::readToggled()
{
bool s = IS_MSG_UNREAD(mPost.mMeta.mMsgStatus);
emit changeReadStatusRequested(mPost.mMeta.mMsgId,s);
}
void BoardPostDisplayWidgetBase::setup()
{
// show/hide things based on the view type
if(!(mDisplayFlags & SHOW_COMMENTS))
commentButton()->setChecked(false);
else
commentButton()->setChecked(true);
/* clear ui */
titleLabel()->setText(tr("Loading"));
dateLabel()->clear();
fromLabel()->clear();
siteLabel()->clear();
QObject::connect(commentButton(), SIGNAL(toggled(bool)), this, SLOT(loadComments(bool)));
QObject::connect(voteUpButton(), SIGNAL(clicked()), this, SLOT(makeUpVote()));
QObject::connect(voteDownButton(), SIGNAL(clicked()), this, SLOT(makeDownVote()));
QObject::connect(readButton(), SIGNAL(clicked()), this, SLOT(readToggled()));
QAction *CopyLinkAction = new QAction(QIcon(""),tr("Copy RetroShare Link"), this);
connect(CopyLinkAction, SIGNAL(triggered()), this, SLOT(handleCopyLinkClicked()));
int S = QFontMetricsF(font()).height() ;
readButton()->setChecked(false);
QMenu *menu = new QMenu();
menu->addAction(CopyLinkAction);
menu->addSeparator();
shareButton()->setMenu(menu);
connect(shareButton(),SIGNAL(pressed()),this,SLOT(handleShareButtonClicked()));
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
if(redacted)
{
commentButton()->setDisabled(true);
voteUpButton()->setDisabled(true);
voteDownButton()->setDisabled(true);
fromLabel()->setId(mPost.mMeta.mAuthorId);
titleLabel()->setText(tr( "<p><font color=\"#ff0000\"><b>The author of this message (with ID %1) is banned.</b>").arg(QString::fromStdString(mPost.mMeta.mAuthorId.toStdString()))) ;
QDateTime qtime;
qtime.setTime_t(mPost.mMeta.mPublishTs);
QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy");
dateLabel()->setText(timestamp);
pictureLabel()->setDisabled(true);
}
else
{
QPixmap sqpixmap2 = FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-default.png");
QDateTime qtime;
qtime.setTime_t(mPost.mMeta.mPublishTs);
QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy");
QString timestamp2 = misc::timeRelativeToNow(mPost.mMeta.mPublishTs) + " " + tr("ago");
dateLabel()->setText(timestamp2);
dateLabel()->setToolTip(timestamp);
fromLabel()->setId(mPost.mMeta.mAuthorId);
// Use QUrl to check/parse our URL
// The only combination that seems to work: load as EncodedUrl, extract toEncoded().
QByteArray urlarray(mPost.mLink.c_str());
QUrl url = QUrl::fromEncoded(urlarray.trimmed());
QString urlstr = "Invalid Link";
QString sitestr = "Invalid Link";
bool urlOkay = url.isValid();
if (urlOkay)
{
QString scheme = url.scheme();
if ((scheme != "https")
&& (scheme != "http")
&& (scheme != "ftp")
&& (scheme != "retroshare"))
{
urlOkay = false;
sitestr = "Invalid Link Scheme";
}
}
if (urlOkay)
{
urlstr = QString("<a href=\"");
urlstr += QString(url.toEncoded());
urlstr += QString("\" ><span style=\" text-decoration: underline; color:#2255AA;\"> ");
urlstr += QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
urlstr += QString(" </span></a>");
QString siteurl = url.toEncoded();
sitestr = QString("<a href=\"%1\" ><span style=\" text-decoration: underline; color:#0079d3;\"> %2 </span></a>").arg(siteurl).arg(siteurl);
titleLabel()->setText(urlstr);
}
else
titleLabel()->setText( QString::fromUtf8(mPost.mMeta.mMsgName.c_str()) );
if (urlarray.isEmpty())
siteLabel()->hide();
siteLabel()->setText(sitestr);
}
//QString score = "Hot" + QString::number(post.mHotScore);
//score += " Top" + QString::number(post.mTopScore);
//score += " New" + QString::number(post.mNewScore);
QString score = QString::number(mPost.mTopScore);
scoreLabel()->setText(score);
// FIX THIS UP LATER.
notes()->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
pictureLabel()->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
// feed.
//frame_comment->show();
commentButton()->show();
setCommentsSize(mPost.mComments);
setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus));
// disable voting buttons - if they have already voted.
if (mPost.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
{
voteUpButton()->setEnabled(false);
voteDownButton()->setEnabled(false);
}
connect(pictureLabel(), SIGNAL(clicked()), this, SLOT(viewPicture()));
#ifdef TODO
emit sizeChanged(this);
#endif
}
void BoardPostDisplayWidgetBase::handleShareButtonClicked()
{
emit shareButtonClicked();
}
void BoardPostDisplayWidgetBase::handleCopyLinkClicked()
{
emit copylinkClicked();
}
//===================================================================================================================================
//== class BoardPostDisplayWidget ==
//===================================================================================================================================
BoardPostDisplayWidget_compact::BoardPostDisplayWidget_compact(const RsPostedPost& post, uint8_t display_flags,QWidget *parent=nullptr)
: BoardPostDisplayWidgetBase(post,display_flags,parent), ui(new Ui::BoardPostDisplayWidget_compact())
{
ui->setupUi(this);
setup();
ui->verticalLayout->addStretch();
ui->verticalLayout->setAlignment(Qt::AlignTop);
ui->topLayout->setAlignment(Qt::AlignTop);
ui->arrowsLayout->addStretch();
ui->arrowsLayout->setAlignment(Qt::AlignTop);
ui->verticalLayout_2->addStretch();
adjustSize();
}
BoardPostDisplayWidget_compact::~BoardPostDisplayWidget_compact()
{
delete ui;
}
void BoardPostDisplayWidget_compact::setup()
{
BoardPostDisplayWidgetBase::setup();
// show/hide things based on the view type
setAttribute(Qt::WA_DeleteOnClose, true);
ui->pictureLabel->setEnableZoom(false);
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
int desired_height = QFontMetricsF(font()).height() * 5;
ui->pictureLabel->setFixedSize(16/9.0*desired_height,desired_height);
if(redacted)
{
ui->pictureLabel->setPicture( FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-blocked.png") );
}
else
{
if(mPost.mImage.mData != NULL)
{
QPixmap pixmap;
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
// Wiping data - as its been passed to thumbnail.
#ifdef DEBUG_BOARDPOSTDISPLAYWIDGET
std::cerr << "Got pixmap of size " << pixmap.width() << " x " << pixmap.height() << std::endl;
std::cerr << "Saving to pix.png" << std::endl;
pixmap.save("pix.png","PNG");
#endif
ui->pictureLabel->setPicture(pixmap);
}
else
ui->pictureLabel->setPicture( FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-default.png") );
}
ui->notes->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
QObject::connect(ui->expandButton, SIGNAL(toggled(bool)), this, SLOT(doExpand(bool)));
QTextDocument doc;
doc.setHtml(notes()->text());
if(mDisplayFlags & SHOW_NOTES)
{
ui->frame_notes->show();
ui->expandButton->setChecked(true);
}
else
{
ui->frame_notes->hide();
ui->expandButton->setChecked(false);
}
if(doc.toPlainText().trimmed().isEmpty())
{
ui->frame_notes->hide();
ui->expandButton->hide();
}
updateGeometry();
#ifdef TODO
emit sizeChanged(this);
#endif
}
void BoardPostDisplayWidget_compact::viewPicture()
{
if(mPost.mImage.mData == NULL)
return;
QString timestamp = misc::timeRelativeToNow(mPost.mMeta.mPublishTs);
QPixmap pixmap;
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
RsGxsId authorID = mPost.mMeta.mAuthorId;
PhotoView *PView = new PhotoView();
PView->setPixmap(pixmap);
PView->setTitle(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));
PView->setName(authorID);
PView->setTime(timestamp);
PView->setGroupId(mPost.mMeta.mGroupId);
PView->setMessageId(mPost.mMeta.mMsgId);
PView->show();
emit thumbnailOpenned();
}
QToolButton *BoardPostDisplayWidget_compact::voteUpButton() { return ui->voteUpButton; }
QToolButton *BoardPostDisplayWidget_compact::commentButton() { return ui->commentButton; }
QToolButton *BoardPostDisplayWidget_compact::voteDownButton() { return ui->voteDownButton; }
QLabel *BoardPostDisplayWidget_compact::newLabel() { return ui->newLabel; }
QToolButton *BoardPostDisplayWidget_compact::readButton() { return ui->readButton; }
QLabel *BoardPostDisplayWidget_compact::siteLabel() { return ui->siteLabel; }
GxsIdLabel *BoardPostDisplayWidget_compact::fromLabel() { return ui->fromLabel; }
QLabel *BoardPostDisplayWidget_compact::dateLabel() { return ui->dateLabel; }
QLabel *BoardPostDisplayWidget_compact::titleLabel() { return ui->titleLabel; }
QLabel *BoardPostDisplayWidget_compact::scoreLabel() { return ui->scoreLabel; }
QLabel *BoardPostDisplayWidget_compact::notes() { return ui->notes; }
QPushButton *BoardPostDisplayWidget_compact::shareButton() { return ui->shareButton; }
QLabel *BoardPostDisplayWidget_compact::pictureLabel() { return ui->pictureLabel; }
QFrame *BoardPostDisplayWidget_compact::mainFrame() { return ui->mainFrame; }
//===================================================================================================================================
//== class BoardPostDisplayWidget_card ==
//===================================================================================================================================
BoardPostDisplayWidget_card::BoardPostDisplayWidget_card(const RsPostedPost& post, uint8_t display_flags, QWidget *parent)
: BoardPostDisplayWidgetBase(post,display_flags,parent), ui(new Ui::BoardPostDisplayWidget_card())
{
ui->setupUi(this);
setup();
ui->verticalLayout->addStretch();
ui->verticalLayout->setAlignment(Qt::AlignTop);
ui->topLayout->setAlignment(Qt::AlignTop);
ui->arrowsLayout->addStretch();
ui->arrowsLayout->setAlignment(Qt::AlignTop);
ui->verticalLayout_2->addStretch();
adjustSize();
}
BoardPostDisplayWidget_card::~BoardPostDisplayWidget_card()
{
delete ui;
}
void BoardPostDisplayWidget_card::setup()
{
BoardPostDisplayWidgetBase::setup();
RsReputationLevel overall_reputation = rsReputations->overallReputationLevel(mPost.mMeta.mAuthorId);
bool redacted = (overall_reputation == RsReputationLevel::LOCALLY_NEGATIVE);
if(redacted)
{
ui->pictureLabel->setPixmap( FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-blocked.png") );
}
else
{
if(mPost.mImage.mData != NULL)
{
QPixmap pixmap;
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
// Wiping data - as its been passed to thumbnail.
QPixmap scaledpixmap;
if(pixmap.width() > 800){
QPixmap scaledpixmap = pixmap.scaledToWidth(800, Qt::SmoothTransformation);
ui->pictureLabel->setPixmap(scaledpixmap);
}else{
ui->pictureLabel->setPixmap(pixmap);
}
ui->pictureLabel->show();
}
else
ui->pictureLabel->hide();
}
QTextDocument doc;
doc.setHtml(notes()->text());
if(doc.toPlainText().trimmed().isEmpty())
notes()->hide();
}
QToolButton *BoardPostDisplayWidget_card::voteUpButton() { return ui->voteUpButton; }
QToolButton *BoardPostDisplayWidget_card::commentButton() { return ui->commentButton; }
QToolButton *BoardPostDisplayWidget_card::voteDownButton() { return ui->voteDownButton; }
QLabel *BoardPostDisplayWidget_card::newLabel() { return ui->newLabel; }
QToolButton *BoardPostDisplayWidget_card::readButton() { return ui->readButton; }
QLabel *BoardPostDisplayWidget_card::siteLabel() { return ui->siteLabel; }
GxsIdLabel *BoardPostDisplayWidget_card::fromLabel() { return ui->fromLabel; }
QLabel *BoardPostDisplayWidget_card::dateLabel() { return ui->dateLabel; }
QLabel *BoardPostDisplayWidget_card::titleLabel() { return ui->titleLabel; }
QLabel *BoardPostDisplayWidget_card::scoreLabel() { return ui->scoreLabel; }
QLabel *BoardPostDisplayWidget_card::notes() { return ui->notes; }
QPushButton *BoardPostDisplayWidget_card::shareButton() { return ui->shareButton; }
QLabel *BoardPostDisplayWidget_card::pictureLabel() { return ui->pictureLabel; }
QFrame *BoardPostDisplayWidget_card::mainFrame() { return ui->mainFrame; }

View file

@ -0,0 +1,183 @@
/*******************************************************************************
* retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.h *
* *
* Copyright (C) 2019 by Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#pragma once
#include <QMetaType>
#include <QWidget>
#include <retroshare/rsposted.h>
namespace Ui {
class BoardPostDisplayWidget_card;
class BoardPostDisplayWidget_compact;
}
class QPushButton;
class QFrame;
class QLabel;
class QToolButton;
class QTextEdit;
class ClickableLabel;
class GxsIdLabel;
struct RsPostedPost;
class BoardPostDisplayWidgetBase: public QWidget
{
Q_OBJECT
public:
enum DisplayFlags: uint8_t {
SHOW_NONE = 0x00,
SHOW_COMMENTS = 0x01,
SHOW_NOTES = 0x02,
};
enum DisplayMode: uint8_t {
DISPLAY_MODE_UNKNOWN = 0x00,
DISPLAY_MODE_COMPACT = 0x01,
DISPLAY_MODE_CARD = 0x02,
};
BoardPostDisplayWidgetBase(const RsPostedPost& post,uint8_t display_flags,QWidget *parent);
virtual ~BoardPostDisplayWidgetBase() {}
static const char *DEFAULT_BOARD_IMAGE;
protected slots:
/* GxsGroupFeedItem */
virtual void setup(); // to be overloaded by the different views
virtual QToolButton *voteUpButton() =0;
virtual QToolButton *commentButton() =0;
virtual QToolButton *voteDownButton() =0;
virtual QLabel *newLabel() =0;
virtual QLabel *titleLabel()=0;
virtual QLabel *siteLabel()=0;
virtual GxsIdLabel *fromLabel()=0;
virtual QLabel *dateLabel()=0;
virtual QLabel *scoreLabel() =0;
virtual QLabel *notes() =0;
virtual QLabel *pictureLabel()=0;
virtual QToolButton *readButton() =0;
virtual QPushButton *shareButton() =0;
virtual QFrame *mainFrame() =0;
void loadComments(bool e);
void readToggled();
void setReadStatus(bool isNew, bool isUnread) ;
void makeUpVote() ;
void makeDownVote() ;
void setCommentsSize(int comNb) ;
void handleShareButtonClicked() ;
void handleCopyLinkClicked() ;
signals:
void changeReadStatusRequested(const RsGxsMessageId&,bool);
void vote(const RsGxsGrpMsgIdPair& msgId, bool up_or_down);
void expand(RsGxsMessageId,bool);
void commentsRequested(const RsGxsMessageId&,bool);
void thumbnailOpenned();
void shareButtonClicked();
void copylinkClicked();
protected:
RsPostedPost mPost;
uint8_t mDisplayFlags;
};
class BoardPostDisplayWidget_compact : public BoardPostDisplayWidgetBase
{
Q_OBJECT
public:
BoardPostDisplayWidget_compact(const RsPostedPost& post, uint8_t display_flags, QWidget *parent);
virtual ~BoardPostDisplayWidget_compact();
static const char *DEFAULT_BOARD_IMAGE;
QToolButton *voteUpButton() override;
QToolButton *commentButton() override;
QToolButton *voteDownButton() override;
QLabel *newLabel() override;
QLabel *siteLabel() override;
GxsIdLabel *fromLabel() override;
QLabel *dateLabel() override;
QLabel *titleLabel() override;
QLabel *scoreLabel() override;
QLabel *notes() override;
QLabel *pictureLabel() override;
QToolButton *readButton() override;
QPushButton *shareButton() override;
QFrame *mainFrame() override;
public slots:
void viewPicture() ;
protected slots:
/* GxsGroupFeedItem */
void doExpand(bool) ;
protected:
void setup() override; // to be overloaded by the different views
private:
/** Qt Designer generated object */
Ui::BoardPostDisplayWidget_compact *ui;
};
class BoardPostDisplayWidget_card : public BoardPostDisplayWidgetBase
{
Q_OBJECT
public:
BoardPostDisplayWidget_card(const RsPostedPost& post,uint8_t display_flags,QWidget *parent=nullptr);
virtual ~BoardPostDisplayWidget_card();
static const char *DEFAULT_BOARD_IMAGE;
QToolButton *voteUpButton() override;
QToolButton *commentButton() override;
QToolButton *voteDownButton() override;
QLabel *newLabel() override;
QLabel *siteLabel() override;
GxsIdLabel *fromLabel() override;
QLabel *dateLabel() override;
QLabel *titleLabel() override;
QLabel *scoreLabel() override;
QLabel *notes() override;
QToolButton *readButton() override;
QPushButton *shareButton() override;
QLabel *pictureLabel() override;
QFrame *mainFrame() override;
protected slots:
/* GxsGroupFeedItem */
protected:
void setup() override; // to be overloaded by the different views
private:
/** Qt Designer generated object */
Ui::BoardPostDisplayWidget_card *ui;
};

View file

@ -0,0 +1,463 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoardPostDisplayWidget_card</class>
<widget class="QWidget" name="BoardPostDisplayWidget_card">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>558</width>
<height>202</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QFrame" name="mainFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="topLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QFrame" name="voteFrame">
<layout class="QVBoxLayout" name="arrowsLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="voteUpButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Vote up</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/up-arrow.png</normaloff>:/images/up-arrow.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="StyledLabel" name="scoreLabel">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="voteDownButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Vote down</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>\/</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/down-arrow.png</normaloff>:/images/down-arrow.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>5</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="fromBoldLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Posted by</string>
</property>
</widget>
</item>
<item>
<widget class="GxsIdLabel" name="fromLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Signed by</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="dateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">You eyes only</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="readButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Toggle Message Read Status</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/message-state-unread.png</normaloff>:/images/message-state-unread.png</iconset>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="newLabel">
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>70</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="StyledLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">This is a very very very very loooooooooooooooonnnnnnnnnnnnnnnnng title don't you think? Yes it is and should wrap around I hope</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="siteLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">site</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="pictureLabelLayout">
<item>
<widget class="QLabel" name="pictureLabel">
<property name="text">
<string>PictureLabel</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>268</width>
<height>17</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="notes">
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="commentButton">
<property name="text">
<string>Comments</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/comments.png</normaloff>:/images/comments.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="shareButton">
<property name="text">
<string>Share</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/share.png</normaloff>:/images/share.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget>
<class>StyledLabel</class>
<extends>QLabel</extends>
<header>gui/common/StyledLabel.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Posted_images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,511 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BoardPostDisplayWidget_compact</class>
<widget class="QWidget" name="BoardPostDisplayWidget_compact">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>172</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QFrame" name="mainFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="topLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QVBoxLayout" name="arrowsLayout">
<item>
<widget class="QToolButton" name="voteUpButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Vote up</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/up-arrow.png</normaloff>:/images/up-arrow.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="StyledLabel" name="scoreLabel">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="voteDownButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Vote down</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>\/</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/down-arrow.png</normaloff>:/images/down-arrow.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="ZoomableLabel" name="pictureLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Click to view picture</string>
</property>
<property name="text">
<string>PictureLabel_compact</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<item>
<widget class="StyledLabel" name="titleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">This is a very very very very loooooooooooooooonnnnnnnnnnnnnnnnng title don't you think? Yes it is and should wrap around I hope</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<item>
<widget class="QLabel" name="fromBoldLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Posted by</string>
</property>
</widget>
</item>
<item>
<widget class="GxsIdLabel" name="fromLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Signed by</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="dateLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">You eyes only</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>70</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="siteLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">site</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="commentButton">
<property name="text">
<string>Comments</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/comments.png</normaloff>:/images/comments.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="expandButton">
<property name="toolTip">
<string>Expand</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/expand.png</normaloff>:/images/expand.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="shareButton">
<property name="text">
<string>Share</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/share.png</normaloff>:/images/share.png</iconset>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="readButton">
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Toggle Message Read Status</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/message-state-unread.png</normaloff>:/images/message-state-unread.png</iconset>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="newLabel">
<property name="text">
<string>New</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="frame_notes">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing">
<number>2</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="notes">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget>
<class>StyledLabel</class>
<extends>QLabel</extends>
<header>gui/common/StyledLabel.h</header>
</customwidget>
<customwidget>
<class>ZoomableLabel</class>
<extends>QLabel</extends>
<header>gui/gxschannels/GxsChannelPostThumbnail.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="Posted_images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -31,7 +31,7 @@ class PostedCardView;
} }
class FeedHolder; class FeedHolder;
class RsPostedPost; struct RsPostedPost;
class PostedCardView : public BasePostedItem class PostedCardView : public BasePostedItem
{ {
@ -47,7 +47,7 @@ protected:
void setup() override; void setup() override;
void fill() override; void fill() override;
void doExpand(bool open) override {} void doExpand(bool) override {}
void setComment(const RsGxsComment&) override; void setComment(const RsGxsComment&) override;
void setReadStatus(bool isNew, bool isUnread) override; void setReadStatus(bool isNew, bool isUnread) override;
void toggle() override {} void toggle() override {}

View file

@ -38,13 +38,14 @@
#include <iostream> #include <iostream>
#include <gui/RetroShareLink.h> #include <gui/RetroShareLink.h>
#include <util/imageutil.h> #include <util/imageutil.h>
#include "gui/common/FilesDefs.h"
/* View Page */ /* View Page */
#define VIEW_POST 1 #define VIEW_POST 1
#define VIEW_IMAGE 2 #define VIEW_IMAGE 2
#define VIEW_LINK 3 #define VIEW_LINK 3
PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent): PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGroupId& grpId, const RsGxsId& default_author, QWidget *parent):
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
mPosted(posted), mGrpId(grpId), mPosted(posted), mGrpId(grpId),
ui(new Ui::PostedCreatePostDialog) ui(new Ui::PostedCreatePostDialog)
@ -56,7 +57,7 @@ PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGrou
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->addPicButton, SIGNAL(clicked() ), this , SLOT(addPicture())); connect(ui->addPicButton, SIGNAL(clicked() ), this , SLOT(addPicture()));
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/postedlinks.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/postedlinks.png"));
ui->headerFrame->setHeaderText(tr("Create a new Post")); ui->headerFrame->setHeaderText(tr("Create a new Post"));
setAttribute ( Qt::WA_DeleteOnClose, true ); setAttribute ( Qt::WA_DeleteOnClose, true );
@ -69,7 +70,7 @@ PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGrou
ui->sizeWarningLabel->setText(QString("Post size is limited to %1 KB, pictures will be downscaled.").arg(MAXMESSAGESIZE / 1024)); ui->sizeWarningLabel->setText(QString("Post size is limited to %1 KB, pictures will be downscaled.").arg(MAXMESSAGESIZE / 1024));
/* fill in the available OwnIds for signing */ /* fill in the available OwnIds for signing */
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId()); ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, default_author);
QSignalMapper *signalMapper = new QSignalMapper(this); QSignalMapper *signalMapper = new QSignalMapper(this);
connect(ui->postButton, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(ui->postButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
@ -85,6 +86,15 @@ PostedCreatePostDialog::PostedCreatePostDialog(RsPosted *posted, const RsGxsGrou
/* load settings */ /* load settings */
processSettings(true); processSettings(true);
// Override the default ID, if supplied, since it is changed by processSettings
if(!default_author.isNull())
{
ui->idChooser->setChosenId(default_author);
// should we save the ID in the settings here? I'm not sure we want this.
}
} }
PostedCreatePostDialog::~PostedCreatePostDialog() PostedCreatePostDialog::~PostedCreatePostDialog()

View file

@ -39,7 +39,7 @@ public:
* @param tokenQ parent callee token * @param tokenQ parent callee token
* @param posted * @param posted
*/ */
explicit PostedCreatePostDialog(RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0); explicit PostedCreatePostDialog(RsPosted* posted, const RsGxsGroupId& grpId, const RsGxsId& default_author=RsGxsId(),QWidget *parent = 0);
~PostedCreatePostDialog(); ~PostedCreatePostDialog();
private: private:

View file

@ -21,7 +21,7 @@
#include "PostedDialog.h" #include "PostedDialog.h"
#include "PostedItem.h" #include "PostedItem.h"
#include "PostedGroupDialog.h" #include "PostedGroupDialog.h"
#include "PostedListWidget.h" #include "PostedListWidgetWithModel.h"
#include "PostedUserNotify.h" #include "PostedUserNotify.h"
#include "gui/gxs/GxsGroupShareKey.h" #include "gui/gxs/GxsGroupShareKey.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
@ -195,7 +195,7 @@ int PostedDialog::shareKeyType()
GxsMessageFrameWidget *PostedDialog::createMessageFrameWidget(const RsGxsGroupId &groupId) GxsMessageFrameWidget *PostedDialog::createMessageFrameWidget(const RsGxsGroupId &groupId)
{ {
return new PostedListWidget(groupId); return new PostedListWidgetWithModel(groupId);
} }
RsGxsCommentService *PostedDialog::getCommentService() RsGxsCommentService *PostedDialog::getCommentService()

View file

@ -21,6 +21,7 @@
#include "PostedGroupDialog.h" #include "PostedGroupDialog.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/common/FilesDefs.h"
#include <retroshare/rswiki.h> #include <retroshare/rswiki.h>
#include <iostream> #include <iostream>
@ -89,7 +90,7 @@ void PostedGroupDialog::initUi()
QPixmap PostedGroupDialog::serviceImage() QPixmap PostedGroupDialog::serviceImage()
{ {
return QPixmap(":/icons/png/posted.png"); return FilesDefs::getPixmapFromQtResourcePath(":/icons/png/posted.png");
} }
void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMetaData &meta) void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMetaData &meta)
@ -159,7 +160,7 @@ bool PostedGroupDialog::service_loadGroup(const RsGxsGenericGroupData *data, Mod
} }
else else
setLogo(QPixmap(":/icons/png/posted.png")); setLogo(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/posted.png"));
return true; return true;
} }

View file

@ -490,7 +490,7 @@ void PostedItem::fill()
ui->voteUpButton->setDisabled(true); ui->voteUpButton->setDisabled(true);
ui->voteDownButton->setDisabled(true); ui->voteDownButton->setDisabled(true);
ui->thumbnailLabel->setPixmap( QPixmap(":/images/thumb-default.png")); ui->thumbnailLabel->setPixmap( FilesDefs::getPixmapFromQtResourcePath(":/images/thumb-default.png"));
ui->fromLabel->setId(mPost.mMeta.mAuthorId); ui->fromLabel->setId(mPost.mMeta.mAuthorId);
ui->titleLabel->setText(tr( "<p><font color=\"#ff0000\"><b>The author of this message (with ID %1) is banned.</b>").arg(QString::fromStdString(mPost.mMeta.mAuthorId.toStdString()))) ; ui->titleLabel->setText(tr( "<p><font color=\"#ff0000\"><b>The author of this message (with ID %1) is banned.</b>").arg(QString::fromStdString(mPost.mMeta.mAuthorId.toStdString()))) ;
QDateTime qtime; QDateTime qtime;

View file

@ -30,6 +30,7 @@
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "PostedItem.h" #include "PostedItem.h"
#include "PostedCardView.h" #include "PostedCardView.h"
#include "gui/common/FilesDefs.h"
#include "gui/common/UIStateHelper.h" #include "gui/common/UIStateHelper.h"
#include "gui/RetroShareLink.h" #include "gui/RetroShareLink.h"
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
@ -406,7 +407,7 @@ void PostedListWidget::insertPostedDetails(const RsPostedGroup &group)
if (group.mGroupImage.mData != NULL) { if (group.mGroupImage.mData != NULL) {
GxsIdDetails::loadPixmapFromData(group.mGroupImage.mData, group.mGroupImage.mSize, boardImage,GxsIdDetails::ORIGINAL); GxsIdDetails::loadPixmapFromData(group.mGroupImage.mData, group.mGroupImage.mSize, boardImage,GxsIdDetails::ORIGINAL);
} else { } else {
boardImage = QPixmap(BOARD_DEFAULT_IMAGE); boardImage = FilesDefs::getPixmapFromQtResourcePath(BOARD_DEFAULT_IMAGE);
} }
ui->logoLabel->setPixmap(boardImage); ui->logoLabel->setPixmap(boardImage);
ui->namelabel->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str())); ui->namelabel->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str()));

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,175 @@
/*******************************************************************************
* retroshare-gui/src/gui/gxschannels/BoardPostsWidget.h *
* *
* Copyright 2013 by Robert Fernie <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef _GXS_CHANNELPOSTSWIDGET_H
#define _GXS_CHANNELPOSTSWIDGET_H
#include <map>
#include <QStyledItemDelegate>
#include "retroshare/rsposted.h"
#include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h"
#include "gui/Posted/BoardPostDisplayWidget.h"
namespace Ui {
class PostedListWidgetWithModel;
}
class QTreeWidgetItem;
class QSortFilterProxyModel;
class RsPostedPostsModel;
class PostedListWidgetWithModel;
class PostedPostDelegate: public QAbstractItemDelegate
{
Q_OBJECT
public:
PostedPostDelegate(PostedListWidgetWithModel *p,QObject *parent=0) : QAbstractItemDelegate(parent),mCellWidthPix(100),mPostListWidget(p),mDisplayMode(BoardPostDisplayWidget_compact::DISPLAY_MODE_COMPACT){}
virtual ~PostedPostDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setCellWidth(int pix) { mCellWidthPix = pix; }
void setDisplayMode(BoardPostDisplayWidget_compact::DisplayMode dm) { mDisplayMode = dm; }
BoardPostDisplayWidget_compact::DisplayMode getDisplayMode() const { return mDisplayMode; }
public slots:
void expandItem(RsGxsMessageId msgId,bool expanded);
//void commentItem(RsGxsMessageId msgId,bool comment);
private:
// The class keeps a list of expanded items. Because items are constantly re-created, it is not possible
// to let the items themselves hold that information.
uint8_t displayFlags(const RsGxsMessageId& id) const;
int mCellWidthPix;
PostedListWidgetWithModel *mPostListWidget; // used for sending vote signals and so on.
BoardPostDisplayWidget_compact::DisplayMode mDisplayMode;
std::set<RsGxsMessageId> mExpandedItems;
std::set<RsGxsMessageId> mShowCommentItems;
};
class PostedListWidgetWithModel: public GxsMessageFrameWidget
{
Q_OBJECT
public:
/* Filters */
enum Filter {
SORT_TITLE = 1,
SORT_MSG = 2,
SORT_FILE_NAME = 3
};
public:
/** Default Constructor */
PostedListWidgetWithModel(const RsGxsGroupId &postedId, QWidget *parent = 0);
/** Default Destructor */
~PostedListWidgetWithModel();
/* GxsMessageFrameWidget */
virtual QIcon groupIcon() override;
virtual void groupIdChanged() override { updateDisplay(true); }
virtual QString groupName(bool) override ;
virtual bool navigate(const RsGxsMessageId&) override;
void updateDisplay(bool complete) ;
void forceRedraw(); // does not re-load the data, but makes sure the underlying model triggers a full redraw, recomputes sizes, etc.
#ifdef TODO
/* FeedHolder */
virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(FeedItem *feedItem, uint32_t type);
virtual void openChat(const RsPeerId& peerId);
#endif
public slots:
virtual void openComments(const RsGxsMessageId &msgId);
virtual void changeReadStatus(const RsGxsMessageId& msgId,bool b);
protected:
/* GxsMessageFramePostWidget */
virtual void groupNameChanged(const QString &name);
#ifdef TODO
virtual bool insertGroupData(const RsGxsGenericGroupData *data) override;
#endif
virtual void blank() override;
#ifdef TODO
virtual bool getGroupData(RsGxsGenericGroupData *& data) override;
virtual void getMsgData(const std::set<RsGxsMessageId>& msgIds,std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void getAllMsgData(std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void insertPosts(const std::vector<RsGxsGenericMsgData*>& posts) override;
virtual void insertAllPosts(const std::vector<RsGxsGenericMsgData*>& posts, GxsMessageFramePostThread *thread) override;
#endif
/* GxsMessageFrameWidget */
virtual void setAllMessagesReadDo(bool read, uint32_t &token) override;
private slots:
void showAuthorInPeople();
void tabCloseRequested(int index);
void updateSorting(int);
void switchDisplayMode();
void updateGroupData();
void createMsg();
void subscribeGroup(bool subscribe);
void settingsChanged();
void postPostLoad();
void postContextMenu(const QPoint&);
void copyMessageLink();
void next10Posts();
void prev10Posts();
void filterItems(QString s);
public slots:
void handlePostsTreeSizeChange(QSize size);
void voteMsg(RsGxsGrpMsgIdPair msg,bool up_or_down);
void markCurrentPostAsRead();
private:
void processSettings(bool load);
int viewMode();
void insertBoardDetails(const RsPostedGroup &group);
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
private:
RsPostedGroup mGroup;
RsEventsHandlerId_t mEventHandlerId ;
RsPostedPostsModel *mPostedPostsModel;
PostedPostDelegate *mPostedPostsDelegate;
RsGxsMessageId mSelectedPost;
/* UI - from Designer */
Ui::PostedListWidgetWithModel *ui;
};
#endif

View file

@ -0,0 +1,560 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PostedListWidgetWithModel</class>
<widget class="QWidget" name="PostedListWidgetWithModel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>731</width>
<height>593</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="RSTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<property name="tabsClosable">
<bool>true</bool>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Details</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="infoGroupBox">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="title">
<string>Board Details</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="topMargin">
<number>6</number>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="topMargin">
<number>0</number>
</property>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Popularity</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="poplabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="infoPostsLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Posts</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="infoPosts">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">0</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="createdlabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Created</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="createdinfolabel">
<property name="text">
<string>unknown</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Administrator:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="GxsIdLabel" name="infoAdministrator">
<property name="text">
<string>unknown</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Distribution:</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLabel" name="infoDistribution">
<property name="text">
<string>unknown</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="infoLastPostLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Last Post:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="infoLastPost">
<property name="text">
<string notr="true">unknown</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="logoLabel">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../icons.qrc">:/icons/png/postedlinks.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="namelabel">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="SubscribeToolButton" name="subscribeToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string notr="true">Subscribe</string>
</property>
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="infoDescription">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Description&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Posts</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QFrame" name="headerFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="submitPostButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Create Post</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/write.png</normaloff>:/images/write.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="sortStrategy_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-family:'-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol'; font-size:14px; color:#24292e; background-color:#ffffff;&quot;&gt;Select sorting&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<item>
<property name="text">
<string>New</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/new.png</normaloff>:/icons/png/new.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Top</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/top.png</normaloff>:/icons/png/top.png</iconset>
</property>
</item>
<item>
<property name="text">
<string>Hot</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/flame.png</normaloff>:/icons/png/flame.png</iconset>
</property>
</item>
</widget>
</item>
<item>
<widget class="LineEditClear" name="filter_LE">
<property name="placeholderText">
<string>Search</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="viewModeButton">
<property name="font">
<font>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Classic view</string>
</property>
<property name="icon">
<iconset resource="Posted_images.qrc">
<normaloff>:/images/classic.png</normaloff>:/images/classic.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="prevButton">
<property name="toolTip">
<string>Previous</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/arrow-left.png</normaloff>:/icons/png/arrow-left.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="showLabel">
<property name="text">
<string>1-10</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="toolTip">
<string>Next</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/arrow-right.png</normaloff>:/icons/png/arrow-right.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="GxsIdChooser" name="idChooser">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Default identity used when voting&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="RSTreeView" name="postsTree">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
</property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget>
<class>SubscribeToolButton</class>
<extends>QToolButton</extends>
<header>gui/common/SubscribeToolButton.h</header>
</customwidget>
<customwidget>
<class>RSTreeView</class>
<extends>QTreeView</extends>
<header>gui/common/RSTreeView.h</header>
</customwidget>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
</customwidget>
<customwidget>
<class>GxsIdChooser</class>
<extends>QComboBox</extends>
<header>gui/gxs/GxsIdChooser.h</header>
</customwidget>
<customwidget>
<class>RSTabWidget</class>
<extends>QTabWidget</extends>
<header>gui/common/RSTabWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="Posted_images.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,794 @@
/*******************************************************************************
* retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp *
* *
* Copyright 2020 by Cyril Soler <csoler@users.sourceforge.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include <QApplication>
#include <QFontMetrics>
#include <QModelIndex>
#include <QIcon>
#include "retroshare/rsgxsflags.h"
#include "retroshare/rsexpr.h"
#include "gui/common/FilesDefs.h"
#include "util/qtthreadsutils.h"
#include "util/HandleRichText.h"
#include "util/DateTime.h"
#include "PostedPostsModel.h"
//#define DEBUG_CHANNEL_MODEL
Q_DECLARE_METATYPE(RsMsgMetaData)
Q_DECLARE_METATYPE(RsPostedPost)
const uint32_t RsPostedPostsModel::DEFAULT_DISPLAYED_NB_POSTS = 10;
std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere
RsPostedPostsModel::RsPostedPostsModel(QObject *parent)
: QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN)
{
initEmptyHierarchy();
mEventHandlerId = 0;
mSortingStrategy = SORT_NEW_SCORE;
// Needs to be asynced because this function is called by another thread!
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
{
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
}, mEventHandlerId, RsEventType::GXS_POSTED);
}
RsPostedPostsModel::~RsPostedPostsModel()
{
rsEvents->unregisterEventsHandler(mEventHandlerId);
}
void RsPostedPostsModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
{
const RsGxsPostedEvent *e = dynamic_cast<const RsGxsPostedEvent*>(event.get());
if(!e)
return;
switch(e->mPostedEventCode)
{
case RsPostedEventCode::UPDATED_MESSAGE:
case RsPostedEventCode::READ_STATUS_CHANGED:
case RsPostedEventCode::MESSAGE_VOTES_UPDATED:
case RsPostedEventCode::NEW_MESSAGE:
{
// Normally we should just emit dataChanged() on the index of the data that has changed:
//
// We need to update the data!
if(e->mPostedGroupId == mPostedGroup.mMeta.mGroupId)
RsThread::async([this, e]()
{
// 1 - get message data from p3GxsChannels
std::vector<RsPostedPost> posts;
std::vector<RsGxsComment> comments;
std::vector<RsGxsVote> votes;
if(!rsPosted->getBoardContent(mPostedGroup.mMeta.mGroupId,std::set<RsGxsMessageId>{ e->mPostedMsgId }, posts,comments,votes))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel message data for channel/msg " << e->mPostedGroupId << "/" << e->mPostedMsgId << std::endl;
return;
}
// 2 - update the model in the UI thread.
RsQThreadUtils::postToObject( [posts,comments,votes,this]()
{
for(uint32_t i=0;i<posts.size();++i)
{
// linear search. Not good at all, but normally this is for a single post.
for(uint32_t j=0;j<mPosts.size();++j)
if(mPosts[j].mMeta.mMsgId == posts[i].mMeta.mMsgId)
{
mPosts[j] = posts[i];
//emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mFilteredPosts.size(),0,(void*)NULL));
preMods();
postMods();
}
}
},this);
});
default:
break;
}
}
}
void RsPostedPostsModel::initEmptyHierarchy()
{
preMods();
mPosts.clear();
mFilteredPosts.clear();
mDisplayedNbPosts = DEFAULT_DISPLAYED_NB_POSTS;
mDisplayedStartIndex = 0;
postMods();
}
void RsPostedPostsModel::preMods()
{
beginResetModel();
}
void RsPostedPostsModel::postMods()
{
endResetModel();
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL));
}
void RsPostedPostsModel::update()
{
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mDisplayedNbPosts,0,(void*)NULL));
}
void RsPostedPostsModel::triggerRedraw()
{
preMods();
postMods();
}
void RsPostedPostsModel::setFilter(const QStringList& strings, uint32_t& count)
{
preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1);
endRemoveRows();
if(strings.empty())
{
mFilteredPosts.clear();
for(int i=0;i<mPosts.size();++i)
mFilteredPosts.push_back(i);
}
else
{
mFilteredPosts.clear();
//mFilteredPosts.push_back(0);
for(int i=0;i<mPosts.size();++i)
{
bool passes_strings = true;
for(auto& s:strings)
passes_strings = passes_strings && QString::fromStdString(mPosts[i].mMeta.mMsgName).contains(s,Qt::CaseInsensitive);
if(passes_strings)
mFilteredPosts.push_back(i);
}
}
count = mFilteredPosts.size();
mDisplayedStartIndex = 0;
mDisplayedNbPosts = std::min(count,DEFAULT_DISPLAYED_NB_POSTS) ;
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
postMods();
}
int RsPostedPostsModel::rowCount(const QModelIndex& parent) const
{
if(parent.column() > 0)
return 0;
if(mFilteredPosts.empty()) // security. Should never happen.
return 0;
if(!parent.isValid())
return mDisplayedNbPosts;
RsErr() << __PRETTY_FUNCTION__ << " rowCount cannot figure out the porper number of rows." << std::endl;
return 0;
}
int RsPostedPostsModel::columnCount(const QModelIndex &/*parent*/) const
{
return 1;
}
bool RsPostedPostsModel::getPostData(const QModelIndex& i,RsPostedPost& fmpe) const
{
if(!i.isValid())
return true;
quintptr ref = i.internalId();
uint32_t entry = 0;
if(!convertRefPointerToTabEntry(ref,entry))
return false ;
fmpe = mPosts[mFilteredPosts[entry]];
return true;
}
bool RsPostedPostsModel::hasChildren(const QModelIndex &parent) const
{
if(!parent.isValid())
return true;
return false; // by default, no post has children
}
bool RsPostedPostsModel::convertTabEntryToRefPointer(uint32_t entry,quintptr& ref)
{
// the pointer is formed the following way:
//
// [ 32 bits ]
//
// This means that the whole software has the following build-in limitation:
// * 4 B simultaenous posts. Should be enough !
ref = (intptr_t)(entry+1);
return true;
}
bool RsPostedPostsModel::convertRefPointerToTabEntry(quintptr ref, uint32_t& entry)
{
intptr_t val = (intptr_t)ref;
if(val > (1<<30)) // make sure the pointer is an int that fits in 32bits and not too big which would look suspicious
{
RsErr() << "(EE) trying to make a ChannelPostsModelIndex out of a number that is larger than 2^32-1 !" << std::endl;
return false ;
}
if(val==0)
{
RsErr() << "(EE) trying to make a ChannelPostsModelIndex out of index 0." << std::endl;
return false;
}
entry = val - 1;
return true;
}
QModelIndex RsPostedPostsModel::index(int row, int column, const QModelIndex & parent) const
{
if(row < 0 || column < 0)
return QModelIndex();
quintptr ref = getChildRef(parent.internalId(),row);
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "index-3(" << row << "," << column << " parent=" << parent << ") : " << createIndex(row,column,ref) << std::endl;
#endif
return createIndex(row,column,ref) ;
}
QModelIndex RsPostedPostsModel::parent(const QModelIndex& index) const
{
if(!index.isValid())
return QModelIndex();
return QModelIndex(); // there's no hierarchy here. So nothing to do!
}
quintptr RsPostedPostsModel::getChildRef(quintptr ref,int index) const
{
if (index < 0)
return 0;
if(ref == quintptr(0))
{
quintptr new_ref;
convertTabEntryToRefPointer(index+mDisplayedStartIndex,new_ref);
return new_ref;
}
else
return 0 ;
}
quintptr RsPostedPostsModel::getParentRow(quintptr ref,int& row) const
{
PostedPostsModelIndex ref_entry;
if(!convertRefPointerToTabEntry(ref,ref_entry) || ref_entry >= mFilteredPosts.size())
return 0 ;
if(ref_entry == 0)
{
RsErr() << "getParentRow() shouldn't be asked for the parent of NULL" << std::endl;
row = 0;
}
else
row = ref_entry-1;
return 0;
}
int RsPostedPostsModel::getChildrenCount(quintptr ref) const
{
uint32_t entry = 0 ;
if(ref == quintptr(0))
return rowCount()-1;
return 0;
}
QVariant RsPostedPostsModel::data(const QModelIndex& index, int role) const
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "calling data(" << index << ") role=" << role << std::endl;
#endif
if(!index.isValid())
return QVariant();
switch(role)
{
case Qt::SizeHintRole: return sizeHintRole(index.column()) ;
case Qt::StatusTipRole:return QVariant();
default: break;
}
quintptr ref = (index.isValid())?index.internalId():0 ;
uint32_t entry = 0;
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "data(" << index << ")" ;
#endif
if(!ref)
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " [empty]" << std::endl;
#endif
return QVariant() ;
}
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "Bad pointer: " << (void*)ref << std::endl;
#endif
return QVariant() ;
}
const RsPostedPost& fmpe(mPosts[mFilteredPosts[entry]]);
switch(role)
{
case Qt::DisplayRole: return displayRole (fmpe,index.column()) ;
case Qt::UserRole: return userRole (fmpe,index.column()) ;
default:
return QVariant();
}
}
QVariant RsPostedPostsModel::sizeHintRole(int col) const
{
float factor = QFontMetricsF(QApplication::font()).height()/14.0f ;
return QVariant( QSize(factor * 170, factor*14 ));
}
QVariant RsPostedPostsModel::displayRole(const RsPostedPost& fmpe,int col) const
{
switch(col)
{
default:
return QString::fromUtf8(fmpe.mMeta.mMsgName.c_str());
}
return QVariant("[ERROR]");
}
QVariant RsPostedPostsModel::userRole(const RsPostedPost& fmpe,int col) const
{
switch(col)
{
default:
return QVariant::fromValue(fmpe);
}
}
const RsGxsGroupId& RsPostedPostsModel::currentGroupId() const
{
return mPostedGroup.mMeta.mGroupId;
}
void RsPostedPostsModel::updateBoard(const RsGxsGroupId& board_group_id)
{
if(board_group_id.isNull())
return;
update_posts(board_group_id);
}
void RsPostedPostsModel::clear()
{
preMods();
initEmptyHierarchy();
postMods();
emit boardPostsLoaded();
}
class PostSorter
{
public:
PostSorter(RsPostedPostsModel::SortingStrategy s) : mSortingStrategy(s) {}
bool operator()(const RsPostedPost& p1,const RsPostedPost& p2) const
{
switch(mSortingStrategy)
{
default:
case RsPostedPostsModel::SORT_NEW_SCORE : return p1.mNewScore > p2.mNewScore;
case RsPostedPostsModel::SORT_TOP_SCORE : return p1.mTopScore > p2.mTopScore;
case RsPostedPostsModel::SORT_HOT_SCORE : return p1.mHotScore > p2.mHotScore;
}
}
private:
RsPostedPostsModel::SortingStrategy mSortingStrategy;
};
Qt::ItemFlags RsPostedPostsModel::flags(const QModelIndex& index) const
{
if (!index.isValid())
return 0;
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
}
void RsPostedPostsModel::setSortingStrategy(RsPostedPostsModel::SortingStrategy s)
{
preMods();
mSortingStrategy = s;
std::sort(mPosts.begin(),mPosts.end(), PostSorter(s));
postMods();
}
void RsPostedPostsModel::setPostsInterval(int start,int nb_posts)
{
if(start >= mFilteredPosts.size())
return;
preMods();
uint32_t old_nb_rows = rowCount() ;
mDisplayedNbPosts = (uint32_t)std::min(nb_posts,(int)mFilteredPosts.size() - (start+1));
mDisplayedStartIndex = start;
beginRemoveRows(QModelIndex(),mDisplayedNbPosts,old_nb_rows);
endRemoveRows();
beginInsertRows(QModelIndex(),old_nb_rows,mDisplayedNbPosts);
endInsertRows();
postMods();
}
void RsPostedPostsModel::deepUpdate()
{
auto posts(mPosts);
setPosts(mPostedGroup,posts);
}
void RsPostedPostsModel::setPosts(const RsPostedGroup& group, std::vector<RsPostedPost>& posts)
{
preMods();
beginRemoveRows(QModelIndex(),0,rowCount()-1);
endRemoveRows();
mPosts.clear();
mPostedGroup = group;
createPostsArray(posts);
std::sort(mPosts.begin(),mPosts.end(), PostSorter(mSortingStrategy));
uint32_t tmpval;
setFilter(QStringList(),tmpval);
mDisplayedNbPosts = std::min((uint32_t)mFilteredPosts.size(),DEFAULT_DISPLAYED_NB_POSTS);
mDisplayedStartIndex = 0;
beginInsertRows(QModelIndex(),0,rowCount()-1);
endInsertRows();
postMods();
emit boardPostsLoaded();
}
void RsPostedPostsModel::update_posts(const RsGxsGroupId& group_id)
{
if(group_id.isNull())
return;
RsThread::async([this, group_id]()
{
// 1 - get message data from p3GxsChannels
std::list<RsGxsGroupId> groupIds;
std::vector<RsMsgMetaData> msg_metas;
std::vector<RsPostedGroup> groups;
groupIds.push_back(group_id);
if(!rsPosted->getBoardsInfo(groupIds,groups) || groups.size() != 1)
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel group info for channel " << group_id << std::endl;
return;
}
RsPostedGroup group = groups[0];
// We use the heap because the arrays need to be stored accross async
std::vector<RsPostedPost> *posts = new std::vector<RsPostedPost>();
std::vector<RsGxsComment> *comments = new std::vector<RsGxsComment>();
std::vector<RsGxsVote> *votes = new std::vector<RsGxsVote>();
if(!rsPosted->getBoardAllContent(group_id, *posts,*comments,*votes))
{
std::cerr << __PRETTY_FUNCTION__ << " failed to retrieve channel messages for channel " << group_id << std::endl;
return;
}
// 2 - update the model in the UI thread.
RsQThreadUtils::postToObject( [group,posts,comments,votes,this]()
{
/* Here it goes any code you want to be executed on the Qt Gui
* thread, for example to update the data model with new information
* after a blocking call to RetroShare API complete, note that
* Qt::QueuedConnection is important!
*/
setPosts(group,*posts) ;
delete posts;
delete comments;
delete votes;
}, this );
});
}
static bool decreasing_time_comp(const std::pair<time_t,RsGxsMessageId>& e1,const std::pair<time_t,RsGxsMessageId>& e2) { return e2.first < e1.first ; }
void RsPostedPostsModel::createPostsArray(std::vector<RsPostedPost>& posts)
{
#ifdef TODO
// Collect new versions of posts if any. For now Boards do not have versions, but if that ever happens, we'll be handlign it already. This code
// is a blind copy of the channel code.
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "Inserting channel posts" << std::endl;
#endif
std::vector<uint32_t> new_versions ;
for (uint32_t i=0;i<posts.size();++i)
{
if(posts[i].mMeta.mOrigMsgId == posts[i].mMeta.mMsgId)
posts[i].mMeta.mOrigMsgId.clear();
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " " << i << ": name=\"" << posts[i].mMeta.mMsgName << "\" msg_id=" << posts[i].mMeta.mMsgId << ": orig msg id = " << posts[i].mMeta.mOrigMsgId << std::endl;
#endif
if(!posts[i].mMeta.mOrigMsgId.isNull())
new_versions.push_back(i) ;
}
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "New versions: " << new_versions.size() << std::endl;
#endif
if(!new_versions.empty())
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " New versions present. Replacing them..." << std::endl;
std::cerr << " Creating search map." << std::endl;
#endif
// make a quick search map
std::map<RsGxsMessageId,uint32_t> search_map ;
for (uint32_t i=0;i<posts.size();++i)
search_map[posts[i].mMeta.mMsgId] = i ;
for(uint32_t i=0;i<new_versions.size();++i)
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " Taking care of new version at index " << new_versions[i] << std::endl;
#endif
uint32_t current_index = new_versions[i] ;
uint32_t source_index = new_versions[i] ;
#ifdef DEBUG_CHANNEL_MODEL
RsGxsMessageId source_msg_id = posts[source_index].mMeta.mMsgId ;
#endif
// What we do is everytime we find a replacement post, we climb up the replacement graph until we find the original post
// (or the most recent version of it). When we reach this post, we replace it with the data of the source post.
// In the mean time, all other posts have their MsgId cleared, so that the posts are removed from the list.
//std::vector<uint32_t> versions ;
std::map<RsGxsMessageId,uint32_t>::const_iterator vit ;
while(search_map.end() != (vit=search_map.find(posts[current_index].mMeta.mOrigMsgId)))
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " post at index " << current_index << " replaces a post at position " << vit->second ;
#endif
// Now replace the post only if the new versionis more recent. It may happen indeed that the same post has been corrected multiple
// times. In this case, we only need to replace the post with the newest version
//uint32_t prev_index = current_index ;
current_index = vit->second ;
if(posts[current_index].mMeta.mMsgId.isNull()) // This handles the branching situation where this post has been already erased. No need to go down further.
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " already erased. Stopping." << std::endl;
#endif
break ;
}
if(posts[current_index].mMeta.mPublishTs < posts[source_index].mMeta.mPublishTs)
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " and is more recent => following" << std::endl;
#endif
for(std::set<RsGxsMessageId>::const_iterator itt(posts[current_index].mOlderVersions.begin());itt!=posts[current_index].mOlderVersions.end();++itt)
posts[source_index].mOlderVersions.insert(*itt);
posts[source_index].mOlderVersions.insert(posts[current_index].mMeta.mMsgId);
posts[current_index].mMeta.mMsgId.clear(); // clear the msg Id so the post will be ignored
}
#ifdef DEBUG_CHANNEL_MODEL
else
std::cerr << " but is older -> Stopping" << std::endl;
#endif
}
}
}
#endif
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << "Now adding " << posts.size() << " posts into array structure..." << std::endl;
#endif
mPosts.clear();
for (std::vector<RsPostedPost>::const_reverse_iterator it = posts.rbegin(); it != posts.rend(); ++it)
{
if(!(*it).mMeta.mMsgId.isNull())
{
#ifdef DEBUG_CHANNEL_MODEL
std::cerr << " adding post \"" << (*it).mMeta.mMsgName << "\"" << std::endl;
#endif
mPosts.push_back(*it);
}
#ifdef DEBUG_CHANNEL_MODEL
else
std::cerr << " skipped older version post \"" << (*it).mMeta.mMsgName << "\"" << std::endl;
#endif
}
}
void RsPostedPostsModel::setAllMsgReadStatus(bool read)
{
// make a temporary listof pairs
std::list<RsGxsGrpMsgIdPair> pairs;
for(uint32_t i=0;i<mPosts.size();++i)
pairs.push_back(RsGxsGrpMsgIdPair(mPosts[i].mMeta.mGroupId,mPosts[i].mMeta.mMsgId));
RsThread::async([read,pairs]()
{
// Call blocking API
for(auto& p:pairs)
rsPosted->setPostReadStatus(p,read);
} );
}
void RsPostedPostsModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
{
if(!i.isValid())
return ;
// no need to call preMods()/postMods() here because we'renot changing the model
quintptr ref = i.internalId();
uint32_t entry = 0;
if(!convertRefPointerToTabEntry(ref,entry) || entry >= mFilteredPosts.size())
return ;
RsGxsGroupId grpId = mPosts[entry].mMeta.mGroupId;
RsGxsMessageId msgId = mPosts[entry].mMeta.mMsgId;
bool current_read_status = !(IS_MSG_UNREAD(mPosts[entry].mMeta.mMsgStatus) || IS_MSG_NEW(mPosts[entry].mMeta.mMsgStatus));
if(current_read_status != read_status)
RsThread::async([msgId,grpId,read_status]()
{
// Call blocking API
rsPosted->setPostReadStatus(RsGxsGrpMsgIdPair(grpId,msgId),read_status);
} );
}
QModelIndex RsPostedPostsModel::getIndexOfMessage(const RsGxsMessageId& mid) const
{
// Brutal search. This is not so nice, so dont call that in a loop! If too costly, we'll use a map.
RsGxsMessageId postId = mid;
for(uint32_t i=mDisplayedStartIndex;i<mDisplayedStartIndex+mDisplayedNbPosts;++i)
{
// First look into msg versions, in case the msg is a version of an existing message
#ifdef TODO
for(auto& msg_id:mPosts[mFilteredPosts[i]].mOlderVersions)
if(msg_id == postId)
{
quintptr ref ;
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
return createIndex(i,0, ref);
}
#endif
if(mPosts[mFilteredPosts[i]].mMeta.mMsgId == postId)
{
quintptr ref ;
convertTabEntryToRefPointer(i,ref); // we dont use i+1 here because i is not a row, but an index in the mPosts tab
return createIndex(i,0, ref);
}
}
return QModelIndex();
}

View file

@ -0,0 +1,252 @@
/*******************************************************************************
* retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h *
* *
* Copyright 2020 by Cyril Soler <csoler@users.sourceforge.net> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include "retroshare/rsposted.h"
#include "retroshare/rsgxsifacetypes.h"
#include "retroshare/rsevents.h"
#include <QModelIndex>
#include <QColor>
// This class holds the actual hierarchy of posts, represented by identifiers
// It is responsible for auto-updating when necessary and holds a mutex to allow the Model to
// safely access the data.
// The model contains a post in place 0 that is the parent of all posts.
// The model contains 3 layers:
//
// Layer 1: list of all posts
//
// * this list is sorted according to the current sorting strategy
// * Variables: mPosts
//
// Layer 2: list of post filtered by search
//
// * depending on which chunk of posts are actually displayed, this list contains
// the subset of the general list of posts
// * Variables: mFilteredPosts
//
// Layer 3: start and end of posts actually displayed in the previous list
//
// * Variables: mDisplayedStartIndex, mDisplayedNbPosts
//
// The array below indicates which variables are updated depending on the type of data/view change:
//
// | Global list (mPosts) | Filtered List | Displayed list (mDisplayedStartIndex, mDisplayedNbPosts)
// -----------+-----------------------+------------------+----------------------------------------------------------
// New group | X | X | X (updated because FilteredList may change)
// Sort order | X | |
// Filter Str | | X | X (updated because FilteredList may change)
// Chunk chng | | X | X
//
// In the model, indexes internal refs are pointer casts of the index in the mFilteredPosts tab. Another possible choice
// was to use indexes in the tab of displayed indices, but this leads to a more complex impleemntation.
typedef uint32_t PostedPostsModelIndex;
// struct ChannelPostsModelPostEntry
// {
// ChannelPostsModelPostEntry() : mPublishTs(0),mPostFlags(0),mMsgStatus(0),prow(0) {}
//
// enum { // flags for display of posts. To be used in mPostFlags
// FLAG_POST_IS_PINNED = 0x0001,
// FLAG_POST_IS_MISSING = 0x0002,
// FLAG_POST_IS_REDACTED = 0x0004,
// FLAG_POST_HAS_UNREAD_CHILDREN = 0x0008,
// FLAG_POST_HAS_READ_CHILDREN = 0x0010,
// FLAG_POST_PASSES_FILTER = 0x0020,
// FLAG_POST_CHILDREN_PASSES_FILTER = 0x0040,
// };
//
// std::string mTitle ;
// RsGxsMessageId mMsgId;
// uint32_t mPublishTs;
// uint32_t mPostFlags;
// int mMsgStatus;
//
// int prow ;// parent row, which basically means position in the array of posts
// };
// This class is the item model used by Qt to display the information
class RsPostedPostsModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit RsPostedPostsModel(QObject *parent = NULL);
virtual ~RsPostedPostsModel() override;
static const uint32_t COLUMN_THREAD_NB_COLUMNS = 0x01;
static const uint32_t DEFAULT_DISPLAYED_NB_POSTS ;
enum SortingStrategy {
SORT_UNKNOWN = 0x00,
SORT_NEW_SCORE = 0x01,
SORT_TOP_SCORE = 0x02,
SORT_HOT_SCORE = 0x03
};
enum Columns {
COLUMN_POSTS =0x00,
COLUMN_THREAD_MSGID =0x01,
COLUMN_THREAD_DATA =0x02,
};
enum Roles{ SortRole = Qt::UserRole+1,
StatusRole = Qt::UserRole+2,
FilterRole = Qt::UserRole+3,
};
enum TreeMode{ TREE_MODE_UNKWN = 0x00,
TREE_MODE_PLAIN = 0x01,
TREE_MODE_FILES = 0x02,
};
#ifdef TODO
enum SortMode{ SORT_MODE_PUBLISH_TS = 0x00,
SORT_MODE_CHILDREN_PUBLISH_TS = 0x01,
};
#endif
QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;}
QModelIndex getIndexOfMessage(const RsGxsMessageId& mid) const;
// This method will asynchroneously update the data
void updateBoard(const RsGxsGroupId& posted_group_id);
const RsGxsGroupId& currentGroupId() const;
// Triggers a data change for all items. This can be used to redraw the view without re-loading the data.
void update();
// Triggers a preMod, begin/end remove rows and data update. Could be useful if update is not enough to reset cell sizes.
void deepUpdate();
// same without data update, which is far less costly
void triggerRedraw();
#ifdef TODO
void setSortMode(SortMode mode) ;
void setTextColorRead (QColor color) { mTextColorRead = color;}
void setTextColorUnread (QColor color) { mTextColorUnread = color;}
void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;}
void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;}
void setTextColorMissing (QColor color) { mTextColorMissing = color;}
#endif
void setAllMsgReadStatus(bool read);
void setMsgReadStatus(const QModelIndex &i, bool read_status);
void setFilter(const QStringList &strings, uint32_t &count) ;
void setSortingStrategy(SortingStrategy s);
void setPostsInterval(int start,int nb_posts);
#ifdef TODO
void setAuthorOpinion(const QModelIndex& indx,RsOpinion op);
#endif
// Helper functions
bool getPostData(const QModelIndex& i,RsPostedPost& fmpe) const ;
uint32_t totalPostsCount() const { return mPosts.size() ; }
uint32_t filteredPostsCount() const { return mFilteredPosts.size() ; }
uint32_t displayedStartPostIndex() const { return mDisplayedStartIndex ; }
void clear() ;
// AbstractItemModel functions.
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex& child) const override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Custom item roles
QVariant sizeHintRole (int col) const;
QVariant displayRole (const RsPostedPost& fmpe, int col) const;
QVariant toolTipRole (const RsPostedPost& fmpe, int col) const;
QVariant userRole (const RsPostedPost& fmpe, int col) const;
#ifdef TODO
QVariant decorationRole(const RsPostedPost& fmpe, int col) const;
QVariant pinnedRole (const RsPostedPost& fmpe, int col) const;
QVariant missingRole (const RsPostedPost& fmpe, int col) const;
QVariant statusRole (const RsPostedPost& fmpe, int col) const;
QVariant authorRole (const RsPostedPost& fmpe, int col) const;
QVariant sortRole (const RsPostedPost& fmpe, int col) const;
QVariant fontRole (const RsPostedPost& fmpe, int col) const;
QVariant filterRole (const RsPostedPost& fmpe, int col) const;
QVariant textColorRole (const RsPostedPost& fmpe, int col) const;
QVariant backgroundRole(const RsPostedPost& fmpe, int col) const;
#endif
/*!
* \brief debug_dump
* Dumps the hierarchy of posts in the terminal, to allow checking whether the internal representation is correct.
*/
void debug_dump();
signals:
void boardPostsLoaded(); // emitted after the posts have been loaded.
private:
RsPostedGroup mPostedGroup;
TreeMode mTreeMode;
void preMods() ;
void postMods() ;
quintptr getParentRow(quintptr ref,int& row) const;
quintptr getChildRef(quintptr ref, int index) const;
int getChildrenCount(quintptr ref) const;
static bool convertTabEntryToRefPointer(uint32_t entry, quintptr &ref);
static bool convertRefPointerToTabEntry(quintptr ref,uint32_t& entry);
static void computeReputationLevel(uint32_t forum_sign_flags, RsPostedPost& entry);
void update_posts(const RsGxsGroupId& group_id);
#ifdef TODO
void setForumMessageSummary(const std::vector<RsGxsForumMsg>& messages);
void recursUpdateReadStatusAndTimes(ChannelPostsModelIndex i,bool& has_unread_below,bool& has_read_below);
uint32_t recursUpdateFilterStatus(ChannelPostsModelIndex i,int column,const QStringList& strings);
void recursSetMsgReadStatus(ChannelPostsModelIndex i,bool read_status,bool with_children);
#endif
void createPostsArray(std::vector<RsPostedPost> &posts);
void setPosts(const RsPostedGroup& group, std::vector<RsPostedPost> &posts);
void initEmptyHierarchy();
void handleEvent_main_thread(std::shared_ptr<const RsEvent> event);
std::vector<RsPostedPost> mPosts ;
std::vector<int> mFilteredPosts;
uint32_t mDisplayedStartIndex;
uint32_t mDisplayedNbPosts;
SortingStrategy mSortingStrategy;
RsEventsHandlerId_t mEventHandlerId ;
};

View file

@ -5,6 +5,8 @@
<file>images/down-arrow.png</file> <file>images/down-arrow.png</file>
<file>images/up-arrow.png</file> <file>images/up-arrow.png</file>
<file>images/comments.png</file> <file>images/comments.png</file>
<file>images/comments_blue.png</file>
<file>images/thumb-blocked.png</file>
<file>images/thumb-default.png</file> <file>images/thumb-default.png</file>
<file>images/thumb-link.png</file> <file>images/thumb-link.png</file>
<file>images/share.png</file> <file>images/share.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -33,13 +33,14 @@
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "gui/common/FilesDefs.h"
QuickStartWizard::QuickStartWizard(QWidget *parent) : QuickStartWizard::QuickStartWizard(QWidget *parent) :
QDialog(parent) QDialog(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
ui.headerFrame->setHeaderImage(QPixmap(":/images/rs_wizard.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/rs_wizard.png"));
ui.headerFrame->setHeaderText("RetroShare"); ui.headerFrame->setHeaderText("RetroShare");
ui.pagesWizard->setCurrentIndex(0); ui.pagesWizard->setCurrentIndex(0);

View file

@ -521,7 +521,19 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const
case COLUMN_SIZE: case COLUMN_SIZE:
return misc::friendlyUnit(details.count); return misc::friendlyUnit(details.count);
case COLUMN_AGE: case COLUMN_AGE:
return (details.type == DIR_TYPE_FILE)?(misc::timeRelativeToNow(details.max_mtime)):QString(); {
if(details.type == DIR_TYPE_FILE)
return misc::timeRelativeToNow(details.max_mtime);
else if(details.type == DIR_TYPE_EXTRA_FILE)
{
FileInfo fi;
if (rsFiles->FileDetails(details.hash, RS_FILE_HINTS_EXTRA , fi))
return misc::timeRelativeToNow((rstime_t)fi.age-(30 * 3600 * 24)); // AFI_DEFAULT_PERIOD
return QString();
}
else
return QString();
}
case COLUMN_FRIEND_ACCESS: case COLUMN_FRIEND_ACCESS:
return QVariant(); return QVariant();
case COLUMN_WN_VISU_DIR: case COLUMN_WN_VISU_DIR:
@ -1370,7 +1382,7 @@ void RetroshareDirModel::getFileInfoFromIndexList(const QModelIndexList& list, s
* OLD RECOMMEND SYSTEM - DISABLED * OLD RECOMMEND SYSTEM - DISABLED
******/ ******/
void RetroshareDirModel::openSelected(const QModelIndexList &qmil) void RetroshareDirModel::openSelected(const QModelIndexList &qmil, bool openDir)
{ {
#ifdef RDM_DEBUG #ifdef RDM_DEBUG
std::cerr << "RetroshareDirModel::openSelected()" << std::endl; std::cerr << "RetroshareDirModel::openSelected()" << std::endl;
@ -1393,12 +1405,15 @@ void RetroshareDirModel::openSelected(const QModelIndexList &qmil)
QDir dir(QString::fromUtf8((*it).path.c_str())); QDir dir(QString::fromUtf8((*it).path.c_str()));
QString dest; QString dest;
if ((*it).type & DIR_TYPE_FILE || (*it).type & DIR_TYPE_EXTRA_FILE) { if ((*it).type & DIR_TYPE_FILE || (!openDir && (*it).type & DIR_TYPE_EXTRA_FILE)) {
dest = dir.absoluteFilePath(QString::fromUtf8(it->name.c_str())); dest = dir.absoluteFilePath(QString::fromUtf8(it->name.c_str()));
} else if ((*it).type & DIR_TYPE_DIR) { } else if ((*it).type & DIR_TYPE_DIR) {
dest = dir.absolutePath(); dest = dir.absolutePath();
} else if (openDir) // extra
{
QDir d = QFileInfo(it->name.c_str()).absoluteDir();
dest = d.absolutePath();
} }
std::cerr << "Opening this file: " << dest.toStdString() << std::endl ; std::cerr << "Opening this file: " << dest.toStdString() << std::endl ;
RsUrlHandler::openUrl(QUrl::fromLocalFile(dest)); RsUrlHandler::openUrl(QUrl::fromLocalFile(dest));

View file

@ -82,7 +82,7 @@ class RetroshareDirModel : public QAbstractItemModel
int getType ( const QModelIndex & index ) const ; int getType ( const QModelIndex & index ) const ;
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ; void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
void openSelected(const QModelIndexList &list); void openSelected(const QModelIndexList &list, bool openDir = false);
void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths); void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths);
void getFilePath(const QModelIndex& index, std::string& fullpath); void getFilePath(const QModelIndex& index, std::string& fullpath);
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }

View file

@ -23,6 +23,7 @@
#include "ServicePermissionDialog.h" #include "ServicePermissionDialog.h"
#include "ui_ServicePermissionDialog.h" #include "ui_ServicePermissionDialog.h"
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "gui/common/FilesDefs.h"
static ServicePermissionDialog *servicePermissionDialog = NULL; static ServicePermissionDialog *servicePermissionDialog = NULL;
@ -36,7 +37,7 @@ ServicePermissionDialog::ServicePermissionDialog() :
Settings->loadWidgetInformation(this); Settings->loadWidgetInformation(this);
ui->headerFrame->setHeaderImage(QPixmap(":/images/user/servicepermissions64.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/user/servicepermissions64.png"));
ui->headerFrame->setHeaderText(tr("Service Permissions")); ui->headerFrame->setHeaderText(tr("Service Permissions"));
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(setPermissions())); connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(setPermissions()));

View file

@ -38,10 +38,11 @@
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "util/misc.h" #include "util/misc.h"
#include "gui/common/FilesDefs.h"
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_CANCEL ":/images/delete.png" #define IMAGE_CANCEL ":/images/delete.png"
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/icons/png/pencil-edit-button.png"
#define COLUMN_PATH 0 #define COLUMN_PATH 0
#define COLUMN_VIRTUALNAME 1 #define COLUMN_VIRTUALNAME 1
@ -57,7 +58,7 @@ ShareManager::ShareManager()
/* Invoke Qt Designer generated QObject setup routine */ /* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this); ui.setupUi(this);
ui.headerFrame->setHeaderImage(QPixmap(":/images/fileshare64.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/fileshare64.png"));
ui.headerFrame->setHeaderText(tr("Share Manager")); ui.headerFrame->setHeaderText(tr("Share Manager"));
isLoading = false; isLoading = false;

View file

@ -22,6 +22,7 @@
#include <QtGui> #include <QtGui>
#include "PulseReply.h" #include "PulseReply.h"
#include "gui/common/FilesDefs.h"
#include "PulseAddDialog.h" #include "PulseAddDialog.h"
@ -409,7 +410,7 @@ void PulseAddDialog::addImage(const QString &path)
std::cerr << "PulseAddDialog::addImage() loading image from: " << path.toStdString(); std::cerr << "PulseAddDialog::addImage() loading image from: " << path.toStdString();
std::cerr << std::endl; std::cerr << std::endl;
QPixmap qtn = QPixmap(path); QPixmap qtn = FilesDefs::getPixmapFromQtResourcePath(path);
if (qtn.isNull()) { if (qtn.isNull()) {
std::cerr << "PulseAddDialog::addImage() Invalid Image"; std::cerr << "PulseAddDialog::addImage() Invalid Image";
std::cerr << std::endl; std::cerr << std::endl;

View file

@ -24,6 +24,7 @@
#include <QBuffer> #include <QBuffer>
#include "PulseTopLevel.h" #include "PulseTopLevel.h"
#include "gui/common/FilesDefs.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -126,9 +127,9 @@ void PulseTopLevel::setReferenceString(QString ref)
// set ref icon // set ref icon
if (mPulse->mPulseType & WIRE_PULSE_TYPE_REPUBLISH) { if (mPulse->mPulseType & WIRE_PULSE_TYPE_REPUBLISH) {
label_reficon->setPixmap(QPixmap(":/images/retweet.png")); label_reficon->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/retweet.png"));
} else { } else {
label_reficon->setPixmap(QPixmap(":/images/reply.png")); label_reficon->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/reply.png"));
} }
} }

View file

@ -26,6 +26,7 @@
#include "PulseViewGroup.h" #include "PulseViewGroup.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/common/FilesDefs.h"
#include "util/DateTime.h" #include "util/DateTime.h"
/** Constructor */ /** Constructor */
@ -67,7 +68,7 @@ void PulseViewGroup::setup()
else else
{ {
// default. // default.
QPixmap pixmap = QPixmap(":/icons/png/posted.png").scaled(50,50); QPixmap pixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/png/posted.png").scaled(50,50);
label_headshot->setPixmap(pixmap); label_headshot->setPixmap(pixmap);
} }

View file

@ -26,6 +26,7 @@
#include "PulseViewItem.h" #include "PulseViewItem.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/common/FilesDefs.h"
#include "util/DateTime.h" #include "util/DateTime.h"
/** Constructor */ /** Constructor */
@ -281,7 +282,7 @@ void PulseDataItem::showPulse()
if (!headshotOkay) if (!headshotOkay)
{ {
// default. // default.
QPixmap pixmap = QPixmap(":/icons/png/posted.png").scaled(50,50); QPixmap pixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/png/posted.png").scaled(50,50);
setHeadshot(pixmap); setHeadshot(pixmap);
} }
@ -346,7 +347,7 @@ void PulseDataItem::showPulse()
if (!headshotOkay) if (!headshotOkay)
{ {
// default. // default.
QPixmap pixmap = QPixmap(":/icons/png/posted.png").scaled(50,50); QPixmap pixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/png/posted.png").scaled(50,50);
setHeadshot(pixmap); // QPixmap(":/icons/png/posted.png")); setHeadshot(pixmap); // QPixmap(":/icons/png/posted.png"));
} }

View file

@ -22,6 +22,7 @@
#include "WireGroupExtra.h" #include "WireGroupExtra.h"
#include "WireGroupDialog.h" #include "WireGroupDialog.h"
#include "gui/common/FilesDefs.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include <iostream> #include <iostream>
@ -94,7 +95,7 @@ void WireGroupDialog::initUi()
QPixmap WireGroupDialog::serviceImage() QPixmap WireGroupDialog::serviceImage()
{ {
return QPixmap(":/icons/wire-circle.png"); return FilesDefs::getPixmapFromQtResourcePath(":/icons/wire-circle.png");
} }
void WireGroupDialog::prepareWireGroup(RsWireGroup &group, const RsGroupMetaData &meta) void WireGroupDialog::prepareWireGroup(RsWireGroup &group, const RsGroupMetaData &meta)
@ -178,7 +179,7 @@ bool WireGroupDialog::service_loadGroup(const RsGxsGenericGroupData *data, Mode
setLogo(pixmap); setLogo(pixmap);
} }
} else { } else {
setLogo(QPixmap(":/images/album_create_64.png")); setLogo(FilesDefs::getPixmapFromQtResourcePath(":/images/album_create_64.png"));
} }
#endif #endif

View file

@ -25,6 +25,7 @@
#include "WireGroupItem.h" #include "WireGroupItem.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "gui/common/FilesDefs.h"
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
@ -66,7 +67,7 @@ void WireGroupItem::setup()
else else
{ {
// default. // default.
QPixmap pixmap = QPixmap(":/icons/wire.png").scaled(32,32); QPixmap pixmap = FilesDefs::getPixmapFromQtResourcePath(":/icons/wire.png").scaled(32,32);
label_headshot->setPixmap(pixmap); label_headshot->setPixmap(pixmap);
} }

View file

@ -74,7 +74,7 @@
#define IMAGE_FORUMAUTHD ":/images/konv_message2.png" #define IMAGE_FORUMAUTHD ":/images/konv_message2.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_WIKI ":/icons/png/wiki.png" #define IMAGE_WIKI ":/icons/png/wiki.png"
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/icons/png/pencil-edit-button.png"
/** Constructor */ /** Constructor */

View file

@ -414,7 +414,7 @@ void WikiEditDialog::setNewPage()
ui.groupBox_History->hide(); ui.groupBox_History->hide();
ui.pushButton_History->setText(tr("Show Edit History")); ui.pushButton_History->setText(tr("Show Edit History"));
ui.headerFrame->setHeaderImage(QPixmap(":/images/addpage.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/addpage.png"));
ui.headerFrame->setHeaderText(tr("Create New Wiki Page")); ui.headerFrame->setHeaderText(tr("Create New Wiki Page"));
setWindowTitle(tr("Create New Wiki Page")); setWindowTitle(tr("Create New Wiki Page"));
@ -569,7 +569,7 @@ void WikiEditDialog::setupData(const RsGxsGroupId &groupId, const RsGxsMessageId
requestPage(msgId); requestPage(msgId);
} }
ui.headerFrame->setHeaderImage(QPixmap(":/images/editpage.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/editpage.png"));
ui.headerFrame->setHeaderText(tr("Edit Wiki Page")); ui.headerFrame->setHeaderText(tr("Edit Wiki Page"));
setWindowTitle(tr("Edit Wiki Page")); setWindowTitle(tr("Edit Wiki Page"));

View file

@ -154,7 +154,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
{ {
QIcon icon ; QIcon icon ;
icon.addPixmap(QPixmap(":/icons/png/invite.png")) ; icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/invite.png")) ;
inviteFriendsButton->setIcon(icon) ; inviteFriendsButton->setIcon(icon) ;
inviteFriendsButton->setIconSize(icon_size); inviteFriendsButton->setIconSize(icon_size);
} }
@ -196,7 +196,7 @@ ChatLobbyDialog::ChatLobbyDialog(const ChatLobbyId& lid, QWidget *parent, Qt::Wi
{ {
QIcon icon ; QIcon icon ;
icon.addPixmap(QPixmap(":/icons/png/leave.png")) ; icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/leave.png")) ;
unsubscribeButton->setIcon(icon) ; unsubscribeButton->setIcon(icon) ;
unsubscribeButton->setIconSize(icon_size); unsubscribeButton->setIconSize(icon_size);
} }
@ -994,7 +994,7 @@ void ChatLobbyDialog::setWindowed(bool windowed)
mPCWindow->addDialog(this); mPCWindow->addDialog(this);
undockButton->setToolTip(tr("Redock to Main window")); undockButton->setToolTip(tr("Redock to Main window"));
icon.addPixmap(QPixmap(":/icons/png/dock.png")) ; icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/dock.png")) ;
undockButton->setIcon(icon) ; undockButton->setIcon(icon) ;
undockButton->setIconSize(icon_size); undockButton->setIconSize(icon_size);
} }
@ -1009,7 +1009,7 @@ void ChatLobbyDialog::setWindowed(bool windowed)
chatLobbyPage->addChatPage(this); chatLobbyPage->addChatPage(this);
undockButton->setToolTip(tr("Undock to a new window")); undockButton->setToolTip(tr("Undock to a new window"));
icon.addPixmap(QPixmap(":/icons/png/undock.png")) ; icon.addPixmap(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/undock.png")) ;
undockButton->setIcon(icon) ; undockButton->setIcon(icon) ;
undockButton->setIconSize(icon_size); undockButton->setIconSize(icon_size);
} }

View file

@ -1863,7 +1863,7 @@ void ChatWidget::updatePeersCustomStateString(const QString& /*peer_id*/, const
void ChatWidget::updateStatusString(const QString &statusMask, const QString &statusString, bool permanent) void ChatWidget::updateStatusString(const QString &statusMask, const QString &statusString, bool permanent)
{ {
ui->typingLabel->setText(QString(statusMask).arg(trUtf8(statusString.toUtf8()))); // displays info for 5 secs. ui->typingLabel->setText(QString(statusMask).arg(trUtf8(statusString.toUtf8()))); // displays info for 5 secs.
ui->typingPixmapLabel->setPixmap(QPixmap(":icons/png/typing.png") ); ui->typingPixmapLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":icons/png/typing.png") );
if (statusString == "is typing...") { if (statusString == "is typing...") {
typing = true; typing = true;

View file

@ -33,6 +33,7 @@
#include "gui/common/PeerDefs.h" #include "gui/common/PeerDefs.h"
#include "ChatDialog.h" #include "ChatDialog.h"
#include "gui/ChatLobbyWidget.h" #include "gui/ChatLobbyWidget.h"
#include "gui/common/FilesDefs.h"
CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int privacyLevel, QWidget *parent) : CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int privacyLevel, QWidget *parent) :
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
@ -40,7 +41,7 @@ CreateLobbyDialog::CreateLobbyDialog(const std::set<RsPeerId>& peer_list, int pr
ui = new Ui::CreateLobbyDialog() ; ui = new Ui::CreateLobbyDialog() ;
ui->setupUi(this); ui->setupUi(this);
ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/chat-lobbies.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/png/chat-lobbies.png"));
ui->headerFrame->setHeaderText(tr("Create Chat Room")); ui->headerFrame->setHeaderText(tr("Create Chat Room"));
RsGxsId default_identity ; RsGxsId default_identity ;

View file

@ -26,6 +26,7 @@
#include <gui/gxs/GxsIdDetails.h> #include <gui/gxs/GxsIdDetails.h>
#include "AvatarDefs.h" #include "AvatarDefs.h"
#include "gui/common/FilesDefs.h"
void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage) void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage)
{ {
@ -36,7 +37,7 @@ void AvatarDefs::getOwnAvatar(QPixmap &avatar, const QString& defaultImage)
rsMsgs->getOwnAvatarData(data, size); rsMsgs->getOwnAvatarData(data, size);
if (size == 0) { if (size == 0) {
avatar = QPixmap(defaultImage); avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
return; return;
} }
@ -53,7 +54,7 @@ bool AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
/* get avatar */ /* get avatar */
rsMsgs->getAvatarData(RsPeerId(sslId), data, size); rsMsgs->getAvatarData(RsPeerId(sslId), data, size);
if (size == 0) { if (size == 0) {
avatar = QPixmap(defaultImage); avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
return false; return false;
} }
@ -72,7 +73,7 @@ bool AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const
if(!rsIdentity->getIdDetails(gxsId, details)) if(!rsIdentity->getIdDetails(gxsId, details))
{ {
avatar = QPixmap(defaultImage); avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
return false; return false;
} }
@ -107,7 +108,7 @@ bool AvatarDefs::getAvatarFromGpgId(const RsPgpId& gpgId, QPixmap &avatar, const
} }
if (size == 0) { if (size == 0) {
avatar = QPixmap(defaultImage); avatar = FilesDefs::getPixmapFromQtResourcePath(defaultImage);
return false; return false;
} }

View file

@ -24,6 +24,7 @@
#include "ui_AvatarDialog.h" #include "ui_AvatarDialog.h"
#include "AvatarDefs.h" #include "AvatarDefs.h"
#include "util/misc.h" #include "util/misc.h"
#include "gui/common/FilesDefs.h"
/** Constructor */ /** Constructor */
AvatarDialog::AvatarDialog(QWidget *parent) : AvatarDialog::AvatarDialog(QWidget *parent) :
@ -33,7 +34,7 @@ AvatarDialog::AvatarDialog(QWidget *parent) :
/* Invoke Qt Designer generated QObject setup routine */ /* Invoke Qt Designer generated QObject setup routine */
ui->setupUi(this); ui->setupUi(this);
ui->headerFrame->setHeaderImage(QPixmap(":/images/no_avatar_70.png")); ui->headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/images/no_avatar_70.png"));
ui->headerFrame->setHeaderText(tr("Set your Avatar picture")); ui->headerFrame->setHeaderText(tr("Set your Avatar picture"));
connect(ui->avatarButton, SIGNAL(clicked(bool)), this, SLOT(changeAvatar())); connect(ui->avatarButton, SIGNAL(clicked(bool)), this, SLOT(changeAvatar()));

View file

@ -238,7 +238,7 @@ void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *s
QPushButton *button = new QPushButton("", tabGrpWidget); QPushButton *button = new QPushButton("", tabGrpWidget);
button->setIconSize(QSize(buttonWidth, buttonHeight)); button->setIconSize(QSize(buttonWidth, buttonHeight));
button->setFixedSize(QSize(buttonWidth, buttonHeight)); button->setFixedSize(QSize(buttonWidth, buttonHeight));
button->setIcon(QPixmap(group.value(key))); button->setIcon(FilesDefs::getIconFromQtResourcePath(group.value(key)));
button->setToolTip(key); button->setToolTip(key);
button->setStyleSheet("QPushButton:hover {border: 3px solid #0099cc; border-radius: 3px;}"); button->setStyleSheet("QPushButton:hover {border: 3px solid #0099cc; border-radius: 3px;}");
button->setFlat(true); button->setFlat(true);
@ -402,7 +402,7 @@ void Emoticons::showStickerWidget(QWidget *parent, QWidget *button, const char *
button->setFixedSize(QSize(buttonWidth, buttonHeight)); button->setFixedSize(QSize(buttonWidth, buttonHeight));
if(!iconcache.contains(fi.absoluteFilePath())) if(!iconcache.contains(fi.absoluteFilePath()))
{ {
iconcache.insert(fi.absoluteFilePath(), QPixmap(fi.absoluteFilePath()).scaled(buttonWidth, buttonHeight, Qt::KeepAspectRatio)); iconcache.insert(fi.absoluteFilePath(), FilesDefs::getPixmapFromQtResourcePath(fi.absoluteFilePath()).scaled(buttonWidth, buttonHeight, Qt::KeepAspectRatio));
} }
button->setIcon(iconcache[fi.absoluteFilePath()]); button->setIcon(iconcache[fi.absoluteFilePath()]);
button->setToolTip(fi.fileName()); button->setToolTip(fi.fileName());

View file

@ -70,7 +70,7 @@
#define IMAGE_CONNECT ":/images/connect_friend.png" #define IMAGE_CONNECT ":/images/connect_friend.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_GROUP16 ":/images/user/group16.png" #define IMAGE_GROUP16 ":/images/user/group16.png"
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/icons/png/pencil-edit-button.png"
#define IMAGE_REMOVE ":/images/delete.png" #define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_EXPAND ":/images/edit_add24.png" #define IMAGE_EXPAND ":/images/edit_add24.png"
#define IMAGE_COLLAPSE ":/images/edit_remove24.png" #define IMAGE_COLLAPSE ":/images/edit_remove24.png"
@ -306,7 +306,7 @@ void FriendList::peerTreeWidgetCustomPopupMenu()
hbox->setSpacing(6); hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix); iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel); hbox->addWidget(iconLabel);
@ -1006,7 +1006,7 @@ void FriendList::insertPeers()
sslItem->setHidden(false); sslItem->setHidden(false);
gpg_connected = true; gpg_connected = true;
sslOverlayIcon = QPixmap(StatusDefs::imageStatus(bestRSState)); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(bestRSState));
connectStateString = StatusDefs::name(rsState); connectStateString = StatusDefs::name(rsState);
@ -1024,9 +1024,9 @@ void FriendList::insertPeers()
peerState = PEER_STATE_AVAILABLE; peerState = PEER_STATE_AVAILABLE;
if (sslDetail.connectState) { if (sslDetail.connectState) {
sslOverlayIcon = QPixmap(":/images/connect_creating.png"); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(":/images/connect_creating.png");
} else { } else {
sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_ONLINE)); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(RS_STATUS_ONLINE));
} }
connectStateString = StatusDefs::name(RS_STATUS_ONLINE); connectStateString = StatusDefs::name(RS_STATUS_ONLINE);
@ -1037,9 +1037,9 @@ void FriendList::insertPeers()
peerState = PEER_STATE_OFFLINE; peerState = PEER_STATE_OFFLINE;
sslItem->setHidden(mHideUnconnected); sslItem->setHidden(mHideUnconnected);
if (sslDetail.connectState) { if (sslDetail.connectState) {
sslOverlayIcon = QPixmap(":/images/connect_creating.png"); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(":/images/connect_creating.png");
} else { } else {
sslOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_OFFLINE)); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(RS_STATUS_OFFLINE));
} }
connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail); connectStateString = StatusDefs::connectStateWithoutTransportTypeString(sslDetail);
@ -1099,7 +1099,7 @@ void FriendList::insertPeers()
if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) { if (std::find(privateChatIds.begin(), privateChatIds.end(), sslDetail.id) != privateChatIds.end()) {
// private chat is available // private chat is available
sslOverlayIcon = QPixmap(":/images/chat.png"); sslOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(":/images/chat.png");
gpg_hasPrivateChat = true; gpg_hasPrivateChat = true;
} }
sslItem->setIcon(COLUMN_NAME, createAvatar(sslAvatar, sslOverlayIcon)); sslItem->setIcon(COLUMN_NAME, createAvatar(sslAvatar, sslOverlayIcon));
@ -1138,7 +1138,7 @@ void FriendList::insertPeers()
gpgFont = StatusDefs::font(bestRSState); gpgFont = StatusDefs::font(bestRSState);
if (showInfoAtGpgItem) { if (showInfoAtGpgItem) {
gpgOverlayIcon = QPixmap(StatusDefs::imageStatus(bestRSState)); gpgOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(bestRSState));
if (mShowState) { if (mShowState) {
gpgText = StatusDefs::name(bestRSState); gpgText = StatusDefs::name(bestRSState);
@ -1164,7 +1164,7 @@ void FriendList::insertPeers()
gpgText += tr("Available"); gpgText += tr("Available");
} }
gpgOverlayIcon = QPixmap(IMAGE_AVAILABLE); gpgOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(IMAGE_AVAILABLE);
} }
} else { } else {
bestPeerState = PEER_STATE_OFFLINE; bestPeerState = PEER_STATE_OFFLINE;
@ -1178,15 +1178,15 @@ void FriendList::insertPeers()
gpgText += StatusDefs::name(RS_STATUS_OFFLINE); gpgText += StatusDefs::name(RS_STATUS_OFFLINE);
} }
gpgOverlayIcon = QPixmap(StatusDefs::imageStatus(RS_STATUS_OFFLINE)); gpgOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(StatusDefs::imageStatus(RS_STATUS_OFFLINE));
} }
} }
if (gpg_hasPrivateChat) { if (gpg_hasPrivateChat) {
gpgOverlayIcon = QPixmap(":/images/chat.png"); gpgOverlayIcon = FilesDefs::getPixmapFromQtResourcePath(":/images/chat.png");
} }
gpgItem->setIcon(COLUMN_NAME, createAvatar(bestAvatar.isNull() ? QPixmap(AVATAR_DEFAULT_IMAGE) : bestAvatar, gpgOverlayIcon)); gpgItem->setIcon(COLUMN_NAME, createAvatar(bestAvatar.isNull() ? FilesDefs::getPixmapFromQtResourcePath(AVATAR_DEFAULT_IMAGE) : bestAvatar, gpgOverlayIcon));
/* Create or get gpg label */ /* Create or get gpg label */
ElidedLabel *gpgNameLabel = NULL; ElidedLabel *gpgNameLabel = NULL;

View file

@ -527,6 +527,8 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
tooltip += "\n" + tr("Description") + ": " + itemInfo.description; tooltip += "\n" + tr("Description") + ": " + itemInfo.description;
tooltip += "\n" + tr("Id") + ": " + itemInfo.id;
item->setToolTip(COLUMN_NAME, tooltip); item->setToolTip(COLUMN_NAME, tooltip);
item->setToolTip(COLUMN_UNREAD, tooltip); item->setToolTip(COLUMN_UNREAD, tooltip);
item->setToolTip(COLUMN_POPULARITY, tooltip); item->setToolTip(COLUMN_POPULARITY, tooltip);

View file

@ -65,8 +65,8 @@
<string>Display</string> <string>Display</string>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset resource="../icons.qrc">
<normaloff>:/images/looknfeel.png</normaloff>:/images/looknfeel.png</iconset> <normaloff>:/icons/svg/design.svg</normaloff>:/icons/svg/design.svg</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -147,6 +147,7 @@
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../images.qrc"/> <include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View file

@ -69,7 +69,7 @@
#define IMAGE_CONNECT ":/images/connect_friend.png" #define IMAGE_CONNECT ":/images/connect_friend.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_GROUP16 ":/images/user/group16.png" #define IMAGE_GROUP16 ":/images/user/group16.png"
#define IMAGE_EDIT ":/images/edit_16.png" #define IMAGE_EDIT ":/icons/png/pencil-edit-button.png"
#define IMAGE_REMOVE ":/images/delete.png" #define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_EXPAND ":/images/edit_add24.png" #define IMAGE_EXPAND ":/images/edit_add24.png"
#define IMAGE_COLLAPSE ":/images/edit_remove24.png" #define IMAGE_COLLAPSE ":/images/edit_remove24.png"
@ -307,7 +307,7 @@ void NewFriendList::headerContextMenuRequested(QPoint p)
hbox->setSpacing(6); hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix); iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel); hbox->addWidget(iconLabel);
@ -534,7 +534,7 @@ void NewFriendList::peerTreeWidgetCustomPopupMenu()
hbox->setSpacing(6); hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/user/friends24.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix); iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel); hbox->addWidget(iconLabel);

View file

@ -27,6 +27,7 @@
#include "RSTextBrowser.h" #include "RSTextBrowser.h"
#include "RSImageBlockWidget.h" #include "RSImageBlockWidget.h"
#include "gui/common/FilesDefs.h"
#include <retroshare/rsinit.h> //To get RsAccounts #include <retroshare/rsinit.h> //To get RsAccounts
@ -149,7 +150,7 @@ QVariant RSTextBrowser::loadResource(int type, const QUrl &name)
QPixmap RSTextBrowser::getBlockedImage() QPixmap RSTextBrowser::getBlockedImage()
{ {
return QPixmap(":/images/imageblocked_24.png"); return FilesDefs::getPixmapFromQtResourcePath(":/images/imageblocked_24.png");
} }
void RSTextBrowser::setImageBlockWidget(RSImageBlockWidget *widget) void RSTextBrowser::setImageBlockWidget(RSImageBlockWidget *widget)

View file

@ -30,7 +30,10 @@ RSTreeView::RSTreeView(QWidget *parent) : QTreeView(parent)
void RSTreeView::wheelEvent(QWheelEvent *e) void RSTreeView::wheelEvent(QWheelEvent *e)
{ {
if(e->modifiers() == Qt::ControlModifier) if(e->modifiers() == Qt::ControlModifier)
{
emit zoomRequested(e->delta() > 0); emit zoomRequested(e->delta() > 0);
return;
}
else else
QTreeView::wheelEvent(e); QTreeView::wheelEvent(e);
} }

View file

@ -29,6 +29,7 @@
#include <QWidgetAction> #include <QWidgetAction>
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/common/FilesDefs.h"
RSTreeWidget::RSTreeWidget(QWidget *parent) : QTreeWidget(parent) RSTreeWidget::RSTreeWidget(QWidget *parent) : QTreeWidget(parent)
{ {
@ -259,7 +260,7 @@ QMenu *RSTreeWidget::createStandardContextMenu(QMenu *contextMenu)
hbox->setSpacing(6); hbox->setSpacing(6);
QLabel *iconLabel = new QLabel(widget); QLabel *iconLabel = new QLabel(widget);
QPixmap pix = QPixmap(":/images/settings.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5); QPixmap pix = FilesDefs::getPixmapFromQtResourcePath(":/images/settings.png").scaledToHeight(QFontMetricsF(iconLabel->font()).height()*1.5);
iconLabel->setPixmap(pix); iconLabel->setPixmap(pix);
iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width()); iconLabel->setMaximumSize(iconLabel->frameSize().height() + pix.height(), pix.width());
hbox->addWidget(iconLabel); hbox->addWidget(iconLabel);

View file

@ -143,7 +143,7 @@ RsCollectionDialog::RsCollectionDialog(const QString& collectionFileName
setWindowTitle(QString("%1 - %2").arg(windowTitle()).arg(QFileInfo(_fileName).completeBaseName())); setWindowTitle(QString("%1 - %2").arg(windowTitle()).arg(QFileInfo(_fileName).completeBaseName()));
ui.headerFrame->setHeaderImage(QPixmap(":/icons/collections.png")); ui.headerFrame->setHeaderImage(FilesDefs::getPixmapFromQtResourcePath(":/icons/collections.png"));
if(creation) if(creation)
{ {

Some files were not shown because too many files have changed in this diff Show more