Created V0.3.x branch and moved the head into the trunk directory.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@246 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2007-11-15 03:18:48 +00:00
commit 935745a08e
1318 changed files with 348809 additions and 0 deletions

View file

@ -0,0 +1,694 @@
#include "RemoteDirModel.h"
#include "rsiface.h"
#include <QPalette>
#include <iostream>
#include <sstream>
#include <math.h>
bool RemoteDirModel::hasChildren(const QModelIndex &parent) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::hasChildren() :" << parent.internalPointer();
std::cerr << ": ";
#endif
if (!parent.isValid())
{
#ifdef RDM_DEBUG
std::cerr << "root -> true ";
std::cerr << std::endl;
#endif
return true;
}
void *ref = parent.internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_CHILDREN;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
/* error */
#ifdef RDM_DEBUG
std::cerr << "lookup failed -> false";
std::cerr << std::endl;
#endif
return false;
}
if (details.type == DIR_TYPE_FILE)
{
#ifdef RDM_DEBUG
std::cerr << "lookup FILE -> false";
std::cerr << std::endl;
#endif
return false;
}
/* PERSON/DIR*/
#ifdef RDM_DEBUG
std::cerr << "lookup PER/DIR #" << details.count;
std::cerr << std::endl;
#endif
return (details.count > 0); /* do we have children? */
}
int RemoteDirModel::rowCount(const QModelIndex &parent) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::rowCount(): " << parent.internalPointer();
std::cerr << ": ";
#endif
void *ref = NULL;
if (parent.isValid())
{
ref = parent.internalPointer();
}
DirDetails details;
uint32_t flags = DIR_FLAGS_CHILDREN;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "lookup failed -> 0";
std::cerr << std::endl;
#endif
return 0;
}
if (details.type == DIR_TYPE_FILE)
{
#ifdef RDM_DEBUG
std::cerr << "lookup FILE: 0";
std::cerr << std::endl;
#endif
return 0;
}
/* else PERSON/DIR*/
#ifdef RDM_DEBUG
std::cerr << "lookup PER/DIR #" << details.count;
std::cerr << std::endl;
#endif
return details.count;
}
int RemoteDirModel::columnCount(const QModelIndex &parent) const
{
return 4;
}
QVariant RemoteDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::data(): " << index.internalPointer();
std::cerr << ": ";
std::cerr << std::endl;
#endif
if (!index.isValid())
return QVariant();
/* get the data from the index */
void *ref = index.internalPointer();
int coln = index.column();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
return QVariant();
}
if (role == Qt::BackgroundRole)
{
/*** colour entries based on rank/age/count **/
/*** rank (0-10) ***/
uint32_t r = details.rank;
if (r > 10) r = 10;
r = 200 + r * 5; /* 0->250 */
/*** age: log2(age) ***
* 1 hour = 3,600 - 250
* 1 day = 86,400 - 200
* 1 week = 604,800 - 100
* 1 month = 2,419,200 - 50
*
*
* 250 - log2( 1 + (age / 100) ) * 10
* 0 => 1 => 0 => 0 => 250
* 900 => 10 => 3.2 => 32 => 220
* 3600 => 37 => 5.2 => 52 => 200
* 86400 => 865 => 9.2 => 92 => 160
* 604800 => 6049 => 12.3 => 120 => 130
* 2419200 => 24193 => 14.4 => 140 => 110
*
* value log2
*
* 1 0
* 2 1
* 4 2
* 8 3
* 16 4
* 32 5
* 64 6
* 128 7
* 256 8
* 512 9
* 1024 10
* 2048 11
* 4096 12
* 8192 13
* 16384 14
* 32K 15
*
*/
uint32_t g = (uint32_t) log2 ( 1.0 + ( details.age / 100 ) ) * 4;
if (g > 250) g = 250;
g = 250 - g;
if (details.type == DIR_TYPE_PERSON)
{
return QVariant();
}
else if (details.type == DIR_TYPE_DIR)
{
uint32_t b = 200 + details.count;
if (b > 250) b = 250;
QBrush brush(QColor(r,g,b));
return brush;
}
else if (details.type == DIR_TYPE_FILE)
{
uint32_t b = (uint32_t) (200 + 2 * log2(details.count));
if (b > 250) b = 250;
QBrush brush(QColor(r,g,b));
return brush;
}
else
{
return QVariant();
}
}
/*************
Qt::EditRole
Qt::ToolTipRole
Qt::StatusTipRole
Qt::WhatsThisRole
Qt::SizeHintRole
****************/
if (role == Qt::DisplayRole)
{
/*
* Person: name, id, 0, 0;
* File : name, size, rank, (0) ts
* Dir : name, (0) count, (0) path, (0) ts
*/
if (details.type == DIR_TYPE_PERSON) /* Person */
{
switch(coln)
{
case 0:
return QString::fromStdString(details.name);
break;
case 1:
//return QString("");
return QString::fromStdString(details.id);
break;
default:
//return QString("");
return QString::fromStdString("P");
break;
}
}
else if (details.type == DIR_TYPE_FILE) /* File */
{
switch(coln)
{
case 0:
return QString::fromStdString(details.name);
break;
case 1:
{
std::ostringstream out;
out << details.count;
return QString::fromStdString(out.str());
}
break;
case 2:
{
std::ostringstream out;
out << details.rank;
return QString::fromStdString(out.str());
}
break;
case 3:
{
std::ostringstream out;
out << details.age;
return QString::fromStdString(out.str());
}
break;
default:
return QString::fromStdString("FILE");
break;
}
}
else if (details.type == DIR_TYPE_DIR) /* Dir */
{
switch(coln)
{
case 0:
return QString::fromStdString(details.name);
break;
case 1:
//return QString("");
{
std::ostringstream out;
out << details.count;
return QString::fromStdString(out.str());
}
break;
case 2:
//return QString("");
return QString::fromStdString(details.path);
break;
default:
return QString::fromStdString("DIR");
break;
}
}
} /* end of DisplayRole */
return QVariant();
}
QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation,
int role) const
{
if (role == Qt::SizeHintRole)
{
int defw = 50;
int defh = 30;
if (section < 2)
{
defw = 200;
}
return QSize(defw, defh);
}
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
{
switch(section)
{
case 0:
if (RemoteMode)
{
return QString("Remote Directories");
}
else
{
return QString("Local Directories");
}
break;
case 1:
return QString("Size");
break;
case 2:
return QString("Rank");
break;
case 3:
return QString("Age");
break;
}
return QString("Column %1").arg(section);
}
else
return QString("Row %1").arg(section);
}
QModelIndex RemoteDirModel::index(int row, int column,
const QModelIndex & parent) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
std::cerr << ": row:" << row << " col:" << column << " ";
#endif
void *ref = NULL;
if (parent.isValid())
{
ref = parent.internalPointer();
}
/********
if (!RemoteMode)
{
remote = &(rsiface->getLocalDirectoryList());
}
********/
DirDetails details;
uint32_t flags = DIR_FLAGS_CHILDREN;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "lookup failed -> invalid";
std::cerr << std::endl;
#endif
return QModelIndex();
}
/* now iterate through the details to
* get the reference number
*/
std::list<DirStub>::iterator it;
int i = 0;
for(it = details.children.begin();
(i < row) && (it != details.children.end()); it++, i++);
if (it == details.children.end())
{
#ifdef RDM_DEBUG
std::cerr << "wrong number of children -> invalid";
std::cerr << std::endl;
#endif
return QModelIndex();
}
#ifdef RDM_DEBUG
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
std::cerr << std::endl;
#endif
/* we can just grab the reference now */
QModelIndex qmi = createIndex(row, column, it->ref);
return qmi;
}
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer();
std::cerr << ": ";
#endif
/* create the index */
if (!index.isValid())
{
#ifdef RDM_DEBUG
std::cerr << "Invalid Index -> invalid";
std::cerr << std::endl;
#endif
/* Parent is invalid too */
return QModelIndex();
}
void *ref = index.internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_PARENT;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
#ifdef RDM_DEBUG
std::cerr << "Failed Lookup -> invalid";
std::cerr << std::endl;
#endif
return QModelIndex();
}
if (!(details.parent))
{
#ifdef RDM_DEBUG
std::cerr << "success. parent is Root/NULL --> invalid";
std::cerr << std::endl;
#endif
return QModelIndex();
}
#ifdef RDM_DEBUG
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
std::cerr << std::endl;
#endif
return createIndex(details.prow, 0, details.parent);
}
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
{
#ifdef RDM_DEBUG
std::cerr << "RemoteDirModel::flags()";
std::cerr << std::endl;
#endif
if (!index.isValid())
return (Qt::ItemIsSelectable); // Error.
void *ref = index.internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
flags |= DIR_FLAGS_REMOTE;
else
flags |= DIR_FLAGS_LOCAL;
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
return (Qt::ItemIsSelectable); // Error.
}
if (details.type == DIR_TYPE_PERSON)
{
return (Qt::ItemIsEnabled);
}
else if (details.type == DIR_TYPE_DIR)
{
return ( Qt::ItemIsSelectable |
Qt::ItemIsEnabled);
// Qt::ItemIsDragEnabled |
// Qt::ItemIsDropEnabled |
}
else // (details.type == DIR_TYPE_FILE)
{
return ( Qt::ItemIsSelectable |
Qt::ItemIsEnabled);
// Qt::ItemIsDragEnabled |
}
}
// The other flags...
//Qt::ItemIsUserCheckable
//Qt::ItemIsEditable
//Qt::ItemIsDropEnabled
//Qt::ItemIsTristate
/* Callback from */
void RemoteDirModel::preMods()
{
std::cerr << "RemoteDirModel::preMods()" << std::endl;
//modelAboutToBeReset();
reset();
layoutAboutToBeChanged();
}
/* Callback from */
void RemoteDirModel::postMods()
{
std::cerr << "RemoteDirModel::postMods()" << std::endl;
//modelReset();
layoutChanged();
//reset();
}
void RemoteDirModel::update (const QModelIndex &index )
{
//std::cerr << "Directory Request(" << id << ") : ";
//std::cerr << path << std::endl;
//rsicontrol -> RequestDirectories(id, path, 1);
}
void RemoteDirModel::downloadSelected(QModelIndexList list)
{
if (!RemoteMode)
{
std::cerr << "Cannot download from local" << std::endl;
}
/* so for all the selected .... get the name out,
* make it into something the RsControl can understand
*/
/* Fire off requests */
QModelIndexList::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
void *ref = it -> internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
{
flags |= DIR_FLAGS_REMOTE;
}
else
{
flags |= DIR_FLAGS_LOCAL;
continue; /* don't try to download local stuff */
}
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
continue;
}
/* only request if it is a file */
if (details.type == DIR_TYPE_FILE)
{
rsicontrol -> FileRequest(details.name, details.hash,
details.count, "");
}
}
}
void RemoteDirModel::recommendSelected(QModelIndexList list)
{
std::cerr << "recommendSelected()" << std::endl;
if (RemoteMode)
{
std::cerr << "Cannot recommend remote! (should download)" << std::endl;
}
/* Fire off requests */
QModelIndexList::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
void *ref = it -> internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
{
flags |= DIR_FLAGS_REMOTE;
continue; /* don't recommend remote stuff */
}
else
{
flags |= DIR_FLAGS_LOCAL;
}
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
continue;
}
std::cerr << "::::::::::::FileRecommend:::: " << std::endl;
std::cerr << "Name: " << details.name << std::endl;
std::cerr << "Hash: " << details.hash << std::endl;
std::cerr << "Size: " << details.count << std::endl;
std::cerr << "Path: " << details.path << std::endl;
rsicontrol -> FileRecommend(details.name, details.hash, details.count);
}
std::cerr << "::::::::::::Done FileRecommend" << std::endl;
}
void RemoteDirModel::recommendSelectedOnly(QModelIndexList list)
{
std::cerr << "recommendSelectedOnly()" << std::endl;
if (RemoteMode)
{
std::cerr << "Cannot recommend remote! (should download)" << std::endl;
}
rsicontrol->ClearInRecommend();
/* Fire off requests */
QModelIndexList::iterator it;
for(it = list.begin(); it != list.end(); it++)
{
void *ref = it -> internalPointer();
DirDetails details;
uint32_t flags = DIR_FLAGS_DETAILS;
if (RemoteMode)
{
flags |= DIR_FLAGS_REMOTE;
continue; /* don't recommend remote stuff */
}
else
{
flags |= DIR_FLAGS_LOCAL;
}
if (!rsicontrol->RequestDirDetails(ref, details, flags))
{
continue;
}
std::cerr << "::::::::::::FileRecommend:::: " << std::endl;
std::cerr << "Name: " << details.name << std::endl;
std::cerr << "Hash: " << details.hash << std::endl;
std::cerr << "Size: " << details.count << std::endl;
std::cerr << "Path: " << details.path << std::endl;
rsicontrol -> FileRecommend(details.name, details.hash, details.count);
rsicontrol -> SetInRecommend(details.name, true);
}
std::cerr << "::::::::::::Done FileRecommend" << std::endl;
}
void RemoteDirModel::openSelected(QModelIndexList list)
{
recommendSelected(list);
}

View file

@ -0,0 +1,93 @@
#ifndef REMOTE_DIR_MODEL
#define REMOTE_DIR_MODEL
#include <QAbstractItemModel>
#include <vector>
class RemoteDirModel : public QAbstractItemModel
{
Q_OBJECT
public:
RemoteDirModel(bool mode, QObject *parent = 0)
: QAbstractItemModel(parent),
RemoteMode(mode),
nIndex(1), indexSet(1) /* ass zero index cant be used */
{}
/* These are all overloaded Virtual Functions */
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column,
const QModelIndex & parent = QModelIndex() ) const;
QModelIndex parent ( const QModelIndex & index ) const;
Qt::ItemFlags flags ( const QModelIndex & index ) const;
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
/* Callback from Core */
void preMods();
void postMods();
/* Callback from GUI */
void downloadSelected(QModelIndexList list);
void recommendSelected(QModelIndexList list);
void recommendSelectedOnly(QModelIndexList list);
void openSelected(QModelIndexList list);
public slots:
void collapsed ( const QModelIndex & index ) { update(index); }
void expanded ( const QModelIndex & index ) { update(index); }
private:
void update (const QModelIndex &index );
class RemoteIndex
{
public:
RemoteIndex() {}
RemoteIndex(std::string in_person,
std::string in_path,
int in_idx,
int in_row,
int in_column,
std::string in_name,
int in_size,
int in_type,
int in_ts, int in_rank)
:id(in_person), path(in_path), parent(in_idx),
row(in_row), column(in_column),
name(in_name), size(in_size),
type(in_type), timestamp(in_ts), rank(in_rank)
{
return;
}
std::string id;
std::string path;
int parent;
int row;
int column;
/* display info */
std::string name;
int size;
int type;
int timestamp;
int rank;
};
bool RemoteMode;
mutable int nIndex;
mutable std::vector<RemoteIndex> indexSet;
};
#endif

View file

@ -0,0 +1,372 @@
#include "rsiface/notifyqt.h"
#include "gui/NetworkDialog.h"
#include "gui/PeersDialog.h"
#include "gui/SharedFilesDialog.h"
#include "gui/TransfersDialog.h"
#include "gui/ChatDialog.h"
#include "gui/MessagesDialog.h"
#include "gui/ChannelsDialog.h"
#include "gui/MessengerWindow.h"
#include <iostream>
#include <sstream>
void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
{
(void) list;
(void) type;
(void) msg;
return;
}
void NotifyQt::notifyChat()
{
return;
}
void NotifyQt::notifyListChange(int list, int type)
{
(void) type;
std::cerr << "NotifyQt::notifyListChange()" << std::endl;
switch(list)
{
case NOTIFY_LIST_NEIGHBOURS:
//displayNeighbours();
break;
case NOTIFY_LIST_FRIENDS:
//displayFriends();
break;
case NOTIFY_LIST_DIRLIST:
displayDirectories();
break;
case NOTIFY_LIST_SEARCHLIST:
//displaySearch();
break;
case NOTIFY_LIST_MESSAGELIST:
//displayMessages();
break;
case NOTIFY_LIST_CHANNELLIST:
//displayChannels();
break;
case NOTIFY_LIST_TRANSFERLIST:
//displayTransfers();
break;
default:
break;
}
return;
}
void NotifyQt::notifyListPreChange(int list, int type)
{
std::cerr << "NotifyQt::notifyListPreChange()" << std::endl;
switch(list)
{
case NOTIFY_LIST_NEIGHBOURS:
//preDisplayNeighbours();
break;
case NOTIFY_LIST_FRIENDS:
//preDisplayFriends();
break;
case NOTIFY_LIST_DIRLIST:
preDisplayDirectories();
break;
case NOTIFY_LIST_SEARCHLIST:
//preDisplaySearch();
break;
case NOTIFY_LIST_MESSAGELIST:
//preDisplayMessages();
break;
case NOTIFY_LIST_CHANNELLIST:
//preDisplayChannels();
break;
case NOTIFY_LIST_TRANSFERLIST:
//preDisplayTransfers();
break;
default:
break;
}
return;
}
/* New Timer Based Update scheme ...
* means correct thread seperation
*
* uses Flags, to detect changes
*/
void NotifyQt::UpdateGUI()
{
iface->lockData(); /* Lock Interface */
/* make local -> so we can release iface */
bool uNeigh = iface->hasChanged(RsIface::Neighbour);
bool uFri = iface->hasChanged(RsIface::Friend);
bool uTrans = iface->hasChanged(RsIface::Transfer);
bool uChat = iface->hasChanged(RsIface::Chat);
bool uMsg = iface->hasChanged(RsIface::Message);
bool uChan = iface->hasChanged(RsIface::Channel);
bool uRecom = iface->hasChanged(RsIface::Recommend);
bool uConf = iface->hasChanged(RsIface::Config);
iface->unlockData(); /* UnLock Interface */
if (uNeigh)
displayNeighbours();
if (uFri)
displayFriends();
if (uTrans)
displayTransfers();
if (uChat)
displayChat();
if (uMsg)
displayMessages();
if (uChan)
displayChannels();
/* TODO
if (uRecom)
displayRecommends();
if (uConf)
displayConfig();
*/
}
void NotifyQt::displayNeighbours()
{
iface->lockData(); /* Lock Interface */
std::map<RsCertId,NeighbourInfo>::const_iterator it;
const std::map<RsCertId,NeighbourInfo> &neighs = iface->getNeighbourMap();
std::ostringstream out;
for(it = neighs.begin(); it != neighs.end(); it++)
{
out << "Neighbour: ";
out << it ->second.name << " ";
out << it ->second.status << " ";
out << it ->second.trustLvl << " ";
out << std::endl;
}
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
/* Do the GUI */
if (cDialog)
cDialog->insertConnect();
}
void NotifyQt::displayFriends()
{
iface->lockData(); /* Lock Interface */
std::map<RsCertId,NeighbourInfo>::const_iterator it;
const std::map<RsCertId,NeighbourInfo> &friends = iface->getFriendMap();
std::ostringstream out;
for(it = friends.begin(); it != friends.end(); it++)
{
out << "Friend: ";
out << it->second.name << " ";
out << it->second.status << " ";
out << it->second.trustLvl << " ";
out << std::endl;
}
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
if (pDialog)
pDialog->insertPeers();
if (mWindow)
mWindow->insertPeers();
}
void NotifyQt::preDisplayDirectories()
{
//iface->lockData(); /* Lock Interface */
std::ostringstream out;
out << "NotifyQt::preDisplayDirectories()" << std::endl;
std::cerr << out.str();
//iface->unlockData(); /* UnLock Interface */
if (dDialog)
{
dDialog->preModDirectories(false); /* Remote */
dDialog->preModDirectories(true); /* Local */
}
}
void NotifyQt::displayDirectories()
{
//iface->lockData(); /* Lock Interface */
std::ostringstream out;
out << "NotifyQt::displayDirectories()" << std::endl;
std::cerr << out.str();
//iface->unlockData(); /* UnLock Interface */
if (dDialog)
{
dDialog->ModDirectories(false); /* Remote */
dDialog->ModDirectories(true); /* Local */
}
}
void NotifyQt::displaySearch()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
}
void NotifyQt::displayMessages()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
std::list<MessageInfo>::const_iterator it;
const std::list<MessageInfo> &msgs = iface->getMessages();
std::list<FileInfo>::const_iterator fit;
int i;
for(it = msgs.begin(); it != msgs.end(); it++)
{
out << "Message: ";
out << it->title << std::endl;
out << "\t" << it->msg << std::endl;
const std::list<FileInfo> &files = it -> files;
for(fit = files.begin(), i = 1; fit != files.end(); fit++, i++)
{
out << "\t\tFile(" << i << ") " << fit->fname << std::endl;
}
out << std::endl;
}
iface->unlockData(); /* UnLock Interface */
if (mDialog)
mDialog -> insertMessages();
}
void NotifyQt::displayChat()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
if (hDialog)
hDialog -> insertChat();
}
void NotifyQt::displayChannels()
{
iface->lockData(); /* Lock Interface */
std::ostringstream out;
std::cerr << out.str();
iface->unlockData(); /* UnLock Interface */
if (sDialog)
sDialog -> insertChannels();
}
void NotifyQt::displayTransfers()
{
iface->lockData(); /* Lock Interface */
std::list<FileTransferInfo>::const_iterator it;
const std::list<FileTransferInfo> &tlist = iface->getTransferList();
for(it = tlist.begin(); it != tlist.end(); it++)
{
std::ostringstream out;
out << "Transfer: ";
out << it ->fname << " ";
out << it ->path << " ";
out << std::endl;
std::cerr << out.str();
}
iface->unlockData(); /* UnLock Interface */
/* Do the GUI */
if (tDialog)
tDialog->insertTransfers();
}
void NotifyQt::preDisplayNeighbours()
{
}
void NotifyQt::preDisplayFriends()
{
}
void NotifyQt::preDisplaySearch()
{
}
void NotifyQt::preDisplayMessages()
{
}
void NotifyQt::preDisplayChannels()
{
}
void NotifyQt::preDisplayTransfers()
{
}

View file

@ -0,0 +1,85 @@
#ifndef RSIFACE_NOTIFY_TXT_H
#define RSIFACE_NOTIFY_TXT_H
#include "rsiface/rsiface.h"
#include <QObject>
#include <string>
class NetworkDialog;
class PeersDialog;
class SharedFilesDialog;
class TransfersDialog;
class ChatDialog;
class MessagesDialog;
class ChannelsDialog;
class MessengerWindow;
//class NotifyQt: public NotifyBase, public QObject
class NotifyQt: public QObject, public NotifyBase
{
Q_OBJECT
public:
NotifyQt() : cDialog(NULL), pDialog(NULL),
dDialog(NULL), tDialog(NULL),
hDialog(NULL), mDialog(NULL),
sDialog(NULL), mWindow(NULL)
{ return; }
virtual ~NotifyQt() { return; }
void setNetworkDialog(NetworkDialog *c) { cDialog = c; }
void setPeersDialog(PeersDialog *p) { pDialog = p; }
void setDirDialog(SharedFilesDialog *d) { dDialog = d; }
void setTransfersDialog(TransfersDialog *t) { tDialog = t; }
void setChatDialog(ChatDialog *m) { hDialog = m; }
void setMessagesDialog(MessagesDialog *m) { mDialog = m; }
void setChannelsDialog(ChannelsDialog *s) { sDialog = s; }
void setMessengerWindow(MessengerWindow *mw) { mWindow = mw; }
void setRsIface(RsIface *i) { iface = i; }
virtual void notifyListPreChange(int list, int type);
virtual void notifyListChange(int list, int type);
virtual void notifyErrorMsg(int list, int sev, std::string msg);
virtual void notifyChat();
public slots:
void UpdateGUI(); /* called by timer */
private:
void displayNeighbours();
void displayFriends();
void displayDirectories();
void displaySearch();
void displayChat();
void displayMessages();
void displayChannels();
void displayTransfers();
void preDisplayNeighbours();
void preDisplayFriends();
void preDisplayDirectories();
void preDisplaySearch();
void preDisplayMessages();
void preDisplayChannels();
void preDisplayTransfers();
/* so we can update windows */
NetworkDialog *cDialog;
PeersDialog *pDialog;
SharedFilesDialog *dDialog;
TransfersDialog *tDialog;
ChatDialog *hDialog;
MessagesDialog *mDialog;
ChannelsDialog *sDialog;
MessengerWindow *mWindow;
RsIface *iface;
};
#endif

View file

@ -0,0 +1,241 @@
#ifndef RS_EXPRESSIONS_H
#define RS_EXPRESSIONS_H
/*
* rs-core/src/rsiface: rsexpr.h
*
* RetroShare C++ Interface.
*
* Copyright 2007-2008 by Kashif Kaleem.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <string>
#include <list>
/******************************************************************************************
Enumerations defining the Operators usable in the Boolean search expressions
******************************************************************************************/
enum LogicalOperator{
AndOp=0, /* exp AND exp */
OrOp, /* exp OR exp */
XorOp /* exp XOR exp */
};
/*Operators for String Queries*/
enum StringOperator{
ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */
ContainsAllStrings, /* same as above except that it contains ALL of the strings */
EqualsString /* exactly equal*/
};
/*Relational operators ( >, <, >=, <=, == and InRange )*/
enum RelOperator{
Equals = 0,
GreaterEquals,
Greater,
SmallerEquals,
Smaller,
InRange /* lower limit <= value <= upper limit*/
};
/******************************************************************************************
Boolean Search Expression
classes:
Expression: The base class of all expression typest
CompoundExpression: The expression which uses a logical operator to combine
the results of two expressions
StringExpression: An expression which uses some sort of string comparison.
RelExpression: A Relational Expression where > < >= <= == make sense.
e.g. size date etc
******************************************************************************************/
class FileEntry;
class Expression{
public:
virtual bool eval (FileEntry *file) = 0;
virtual ~Expression() {};
};
class CompoundExpression : public Expression {
public:
CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2)
: Lexp(exp1), Rexp(exp2), Op(op){ }
bool eval (FileEntry *file) {
if (Lexp == NULL or Rexp == NULL) {
return false;
}
switch (Op){
case AndOp:
return Lexp->eval(file) && Rexp->eval(file);
case OrOp:
return Lexp->eval(file) || Rexp->eval(file);
case XorOp:
return Lexp->eval(file) ^ Rexp->eval(file);
default:
return false;
}
}
virtual ~CompoundExpression(){
delete Lexp;
delete Rexp;
}
private:
Expression *Lexp;
Expression *Rexp;
enum LogicalOperator Op;
};
class StringExpression: public Expression {
public:
StringExpression(enum StringOperator op, std::list<std::string> &t,
bool ic): Op(op),terms(t), IgnoreCase(ic){}
protected:
bool evalStr(std::string &str);
private:
enum StringOperator Op;
std::list<std::string> terms;
bool IgnoreCase;
};
template <class T>
class RelExpression: public Expression {
public:
RelExpression(enum RelOperator op, T lv, T hv):
Op(op), LowerValue(lv), HigherValue(hv) {}
protected:
bool evalRel(T val);
private:
enum RelOperator Op;
T LowerValue;
T HigherValue;
};
template <class T>
bool RelExpression<T>::evalRel(T val) {
switch (Op) {
case Equals:
return LowerValue == val;
case GreaterEquals:
return LowerValue >= val;
case Greater:
return LowerValue > val;
case SmallerEquals:
return LowerValue <= val;
case Smaller:
return LowerValue < val;
case InRange:
return (LowerValue <= val) && (val <= HigherValue);
default:
return false;
}
}
/******************************************************************************************
Binary Predicate for Case Insensitive search
******************************************************************************************/
/*Binary predicate for case insensitive character comparison.*/
/*TODOS:
*Factor locales in the comparison
*/
struct CompareCharIC :
public std::binary_function< char , char , bool> {
bool operator () ( char ch1 , char ch2 ) const {
return tolower( static_cast < unsigned char > (ch1) )
== tolower( static_cast < unsigned char > (ch2) );
}
};
/******************************************************************************************
Some implementations of StringExpressions.
******************************************************************************************/
class NameExpression: public StringExpression {
public:
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class PathExpression: public StringExpression {
public:
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class ExtExpression: public StringExpression {
public:
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
StringExpression(op,t,ic) {}
bool eval(FileEntry *file);
};
class HashExpression: public StringExpression {
public:
HashExpression(enum StringOperator op, std::list<std::string> &t):
StringExpression(op,t, true) {}
bool eval(FileEntry *file);
};
/******************************************************************************************
Some implementations of Relational Expressions.
******************************************************************************************/
class DateExpression: public RelExpression<int> {
public:
DateExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
DateExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
class SizeExpression: public RelExpression<int> {
public:
SizeExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
SizeExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
class PopExpression: public RelExpression<int> {
public:
PopExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
PopExpression(enum RelOperator op, int lv, int hv):
RelExpression<int>(op,lv,hv) {}
bool eval(FileEntry *file);
};
#endif /* RS_EXPRESSIONS_H */

View file

@ -0,0 +1,349 @@
#ifndef RETROSHARE_GUI_INTERFACE_H
#define RETROSHARE_GUI_INTERFACE_H
/*
* "$Id: rsiface.h,v 1.9 2007-04-21 19:08:51 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "rstypes.h"
#include <map>
class NotifyBase;
class RsIface;
class RsControl;
//class RsServer;
class RsInit;
class Expression;
/* declare single RsIface for everyone to use! */
extern RsIface *rsiface;
extern RsControl *rsicontrol;
/* RsInit -> Configuration Parameters for RetroShare Startup
*/
RsInit *InitRsConfig();
const char *RsConfigDirectory(RsInit *config);
void CleanupRsConfig(RsInit *);
// Called First... (handles comandline options)
int InitRetroShare(int argc, char **argv, RsInit *config);
// This Functions are used for Login.
bool ValidateCertificate(RsInit *config, std::string &userName);
bool ValidateTrustedUser(RsInit *config, std::string fname, std::string &userName);
bool LoadPassword(RsInit *config, std::string passwd);
bool RsGenerateCertificate(RsInit *config, std::string name, std::string org,
std::string loc, std::string country, std::string passwd, std::string &errString);
/* Auto Login Fns */
bool RsTryAutoLogin(RsInit *config);
bool RsStoreAutoLogin(RsInit *config);
bool RsClearAutoLogin(std::string basedir);
// Handle actual Login.
int LoadCertificates(RsInit *config, bool autoLoginNT);
RsIface *createRsIface (NotifyBase &notify);
RsControl *createRsControl(RsIface &iface, NotifyBase &notify);
class RsIface /* The Main Interface Class - create a single one! */
{
public:
RsIface(NotifyBase &callback)
:cb(callback) { return; }
virtual ~RsIface() { return; }
/****************************************/
/* Stubs for Very Important Fns -> Locking Functions */
virtual void lockData() = 0;
virtual void unlockData() = 0;
const std::map<RsCertId,NeighbourInfo> &getNeighbourMap()
{ return mNeighbourMap; }
const std::map<RsCertId,NeighbourInfo> &getFriendMap()
{ return mFriendMap; }
const NeighbourInfo * getFriend(std::string id);
const std::list<FileTransferInfo> &getTransferList()
{ return mTransferList; }
const std::list<PersonInfo> &getRemoteDirectoryList()
{ return mRemoteDirList; }
const std::list<PersonInfo> &getLocalDirectoryList()
{ return mLocalDirList; }
const PersonInfo *getPerson(std::string id);
const DirInfo *getDirectory(std::string id, std::string path);
const std::list<MessageInfo> &getMessages()
{ return mMessageList; }
const std::map<RsChanId, ChannelInfo> &getChannels()
{ return mChannelMap; }
const std::map<RsChanId, ChannelInfo> &getOurChannels()
{ return mChannelOwnMap; }
const MessageInfo *getMessage(std::string cId, std::string mId);
const MessageInfo *getChannelMsg(std::string chId, std::string mId);
std::list<ChatInfo> getChatNew()
{
std::list<ChatInfo> newList = mChatList;
mChatList.clear();
return newList;
}
const std::list<FileInfo> &getRecommendList()
{ return mRecommendList; }
const RsConfig &getConfig()
{ return mConfig; }
/****************************************/
/* Flags to indicate used or not */
enum DataFlags
{
Neighbour = 0,
Friend = 1,
DirLocal = 2, /* Not Used - QModel instead */
DirRemote = 3, /* Not Used - QModel instead */
Transfer = 4,
Message = 5,
Channel = 6,
Chat = 7,
Recommend = 8,
Config = 9,
NumOfFlags = 10
};
/*
* Operations for flags
*/
bool setChanged(DataFlags set); /* set to true */
bool getChanged(DataFlags set); /* leaves it */
bool hasChanged(DataFlags set); /* resets it */
private:
/* Internal Fn for getting the Directory Entry */
PersonInfo *getPersonMod(std::string id);
DirInfo *getDirectoryMod(std::string id, std::string path);
void fillLists(); /* create some dummy data to display */
/* Internals */
std::map<RsCertId,NeighbourInfo> mNeighbourMap;
std::map<RsCertId,NeighbourInfo> mFriendMap;
std::list<PersonInfo> mRemoteDirList;
std::list<PersonInfo> mLocalDirList;
std::list<FileTransferInfo> mTransferList;
std::list<MessageInfo> mMessageList;
std::map<RsChanId, ChannelInfo> mChannelMap;
std::map<RsChanId, ChannelInfo> mChannelOwnMap;
std::list<ChatInfo> mChatList;
std::list<FileInfo> mRecommendList;
bool mChanged[NumOfFlags];
RsConfig mConfig;
NotifyBase &cb;
/* Classes which can update the Lists! */
friend class RsControl;
friend class RsServer;
};
class RsControl /* The Main Interface Class - for controlling the server */
{
public:
RsControl(RsIface &i, NotifyBase &callback)
:cb(callback), rsIface(i) { return; }
virtual ~RsControl() { return; }
/* Real Startup Fn */
virtual int StartupRetroShare(RsInit *config) = 0;
/****************************************/
/* Neighbour Operations */
virtual std::string NeighGetInvite() = 0;
virtual int NeighLoadPEMString(std::string pem, std::string &id) = 0;
virtual int NeighLoadCertificate(std::string fname, std::string &id) = 0;
virtual int NeighAuthFriend(std::string id, RsAuthId code) = 0;
virtual int NeighAddFriend(std::string id) = 0;
virtual int NeighGetSigners(std::string uid, char *out, int len) = 0;
/****************************************/
/* Friend Operations */
virtual int FriendStatus(std::string id, bool accept) = 0;
virtual int FriendRemove(std::string id) = 0;
virtual int FriendConnectAttempt(std::string id) = 0;
virtual int FriendSignCert(std::string id) = 0;
virtual int FriendTrustSignature(std::string id, bool trust) = 0;
virtual int FriendSetLocalAddress(std::string id, std::string addr,
unsigned short port) = 0;
virtual int FriendSetExtAddress(std::string id, std::string addr,
unsigned short port) = 0;
virtual int FriendSetDNSAddress(std::string id, std::string addr) = 0;
virtual int FriendSetFirewall(std::string id, bool firewalled, bool forwarded) = 0;
virtual int FriendSaveCertificate(std::string id, std::string fname) = 0;
/*
virtual int FriendSetConnectMode(std::string id, int mode) = 0;
*/
virtual int FriendSetBandwidth(std::string id, float outkB, float inkB) = 0;
/****************************************/
/* Directory Actions */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
/****************************************/
/* Search Actions */
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results) = 0;
virtual int SearchBoolExp(Expression *exp, std::list<FileDetail> &results) = 0;
/****************************************/
/* Actions For Upload/Download */
//virtual int FileDelete(std::string uId, std::string fname) = 0;
//virtual int FileMove(std::string uId, std::string src, std::string dest) = 0;
virtual int FileRecommend(std::string fname, std::string hash, int size) = 0;
virtual int FileRequest(std::string fname, std::string hash, uint32_t size, std::string dest) = 0;
virtual int FileCancel(std::string fname, std::string hash, uint32_t size) = 0;
// Transfer control.
virtual int FileClearCompleted() = 0;
virtual int FileSetBandwidthTotals(float outkB, float inkB) = 0;
/****************************************/
/* Message Items */
virtual int MessageSend(MessageInfo &info) = 0;
virtual int MessageDelete(std::string id) = 0;
virtual int MessageRead(std::string id) = 0;
/* Channel Items */
virtual int ChannelCreateNew(ChannelInfo &info) = 0;
virtual int ChannelSendMsg(ChannelInfo &info) = 0;
/****************************************/
/* Chat */
virtual int ChatSend(ChatInfo &ci) = 0;
/****************************************/
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
virtual int SetInChat(std::string id, bool in) = 0; /* friend : chat msgs */
virtual int SetInMsg(std::string id, bool in) = 0; /* friend : msg receipients */
virtual int SetInBroadcast(std::string id, bool in) = 0; /* channel : channel broadcast */
virtual int SetInSubscribe(std::string id, bool in) = 0; /* channel : subscribed channels */
virtual int SetInRecommend(std::string id, bool in) = 0; /* file : recommended file */
virtual int ClearInChat() = 0;
virtual int ClearInMsg() = 0;
virtual int ClearInBroadcast() = 0;
virtual int ClearInSubscribe() = 0;
virtual int ClearInRecommend() = 0;
/****************************************/
/* RsIface Networking */
virtual int NetworkDHTActive(bool active) = 0;
virtual int NetworkUPnPActive(bool active) = 0;
/****************************************/
/* Config */
virtual int ConfigAddSharedDir( std::string dir ) = 0;
virtual int ConfigRemoveSharedDir( std::string dir ) = 0;
virtual int ConfigSetIncomingDir( std::string dir ) = 0;
virtual int ConfigSetLocalAddr( std::string ipAddr, int port ) = 0;
virtual int ConfigSetExtAddr( std::string ipAddr, int port ) = 0;
virtual int ConfigSetExtName( std::string addr ) = 0;
virtual int ConfigSetLanConfig( bool fire, bool forw ) = 0;
virtual int ConfigSetDataRates( int total, int indiv ) = 0;
virtual int ConfigSetBootPrompt( bool on ) = 0;
virtual int ConfigSave( ) = 0;
/****************************************/
NotifyBase &getNotify() { return cb; }
RsIface &getIface() { return rsIface; }
private:
NotifyBase &cb;
RsIface &rsIface;
};
/********************** Overload this Class for callback *****************/
class NotifyBase
{
public:
NotifyBase() { return; }
virtual ~NotifyBase() { return; }
virtual void notifyListPreChange(int list, int type) { (void) list; (void) type; return; }
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
virtual void notifyChat() { return; }
};
const int NOTIFY_LIST_NEIGHBOURS = 1;
const int NOTIFY_LIST_FRIENDS = 2;
const int NOTIFY_LIST_DIRLIST = 3;
const int NOTIFY_LIST_SEARCHLIST = 4;
const int NOTIFY_LIST_MESSAGELIST = 5;
const int NOTIFY_LIST_CHANNELLIST = 6;
const int NOTIFY_LIST_TRANSFERLIST = 7;
const int NOTIFY_TYPE_SAME = 0x01;
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
const int NOTIFY_TYPE_ADD = 0x04; /* flagged additions */
const int NOTIFY_TYPE_DEL = 0x08; /* flagged deletions */
#endif

View file

@ -0,0 +1,410 @@
#ifndef RS_TYPES_GUI_INTERFACE_H
#define RS_TYPES_GUI_INTERFACE_H
/*
* "$Id: rstypes.h,v 1.7 2007-05-05 16:10:05 rmf24 Exp $"
*
* RetroShare C++ Interface.
*
* Copyright 2004-2006 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <list>
#include <iostream>
#include <string>
#define RSCERTIDLEN 16
class RsCertId
{
public:
RsCertId();
RsCertId(std::string idstr);
bool operator<(const RsCertId &ref) const;
bool operator==(const RsCertId &ref) const;
bool operator!=(const RsCertId &ref) const;
char data[RSCERTIDLEN];
};
std::ostream &operator<<(std::ostream &out, const RsCertId &id);
/* use RsCertId, (not unsigned long) because the definition will change
typedef unsigned long RsCertId;
*/
typedef RsCertId RsChanId;
typedef RsCertId RsMsgId;
typedef std::string RsAuthId;
/* forward declarations of the classes */
#define INFO_SAME 0x01
#define INFO_CHG 0x02
#define INFO_NEW 0x04
#define INFO_DEL 0x08
class BaseInfo
{
public:
BaseInfo() :flags(0), mId(0) { return; }
RsCertId id; /* key for matching everything */
int flags; /* INFO_TAG above */
/* allow this to be tweaked by the GUI Model */
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
};
class NeighbourInfo: public BaseInfo
{
public:
std::string name;
std::string org;
std::string loc;
std::string state;
std::string country;
int trustLvl;
std::string trustString;
std::list<RsCertId> signers;
std::string authCode;
int status;
std::string acceptString;
std::string statusString;
std::string connectString;
std::string lastConnect;
std::string peerAddress;
/* server settings */
std::string localAddr;
int localPort;
std::string extAddr;
int extPort;
std::string extName;
bool firewalled;
bool forwardPort;
int maxRate; /* kb */
bool ownsign;
/* Flags to indicate if they are in
* chat or msg list
*/
bool inChat;
bool inMsg;
};
/********************** For the Directory Listing *****************/
class FileInfo: public BaseInfo
{
public:
static const int kRsFiStatusNone = 0;
static const int kRsFiStatusStall = 1;
static const int kRsFiStatusProgress = 2;
static const int kRsFiStatusDone = 2;
/* FileInfo(); */
int searchId; /* 0 if none */
std::string path;
std::string fname;
std::string hash;
std::string ext;
int size;
int avail; /* how much we have */
int status;
bool inRecommend;
double rank;
int age;
};
class DirInfo: public BaseInfo
{
public:
DirInfo() :infoAge(0), nofiles(0), nobytes(0) { return; }
std::string path;
std::string dirname;
std::list<DirInfo> subdirs;
std::list<FileInfo> files;
int infoAge;
int nofiles;
int nobytes;
double rank;
int age;
int merge(const DirInfo &udir);
bool exists(const DirInfo&);
DirInfo* existsPv(const DirInfo&);
bool add(const DirInfo&);
int update(const DirInfo &udir);
bool exists(const FileInfo&);
FileInfo* existsPv(const FileInfo&);
bool add(const FileInfo&);
};
class PersonInfo: public BaseInfo
{
public:
std::string name;
bool online;
int infoAge; /* time() at when this was last updated */
DirInfo rootdir;
};
/********************** For Messages and Channels *****************/
class FileTransferInfo: public FileInfo
{
public:
std::string source;
int transfered;
double tfRate; /* kbytes */
bool download;
int downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
};
/********************** For Messages and Channels *****************/
#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */
#define RS_MSG_OUTGOING 0x0001 /* !Inbox */
#define RS_MSG_PENDING 0x0002 /* OutBox */
#define RS_MSG_DRAFT 0x0004 /* Draft */
/* ORs of above */
#define RS_MSG_INBOX 0x00 /* Inbox */
#define RS_MSG_SENTBOX 0x01 /* Sentbox */
#define RS_MSG_OUTBOX 0x03 /* Outbox */
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox */
#define RS_MSG_NEW 0x0010
class MessageInfo: public BaseInfo
{
public:
MessageInfo() {}
RsMsgId msgId;
unsigned int msgflags;
std::string srcname;
std::string title;
std::string header;
std::string msg;
std::list<FileInfo> files;
int size; /* total of files */
int count; /* file count */
int ts;
};
class ChannelInfo: public BaseInfo
{
public:
ChannelInfo() :publisher(false) {}
RsChanId chanId;
bool publisher;
std::string chanName;
std::list<MessageInfo> msglist;
/* details */
int mode;
float rank;
bool inBroadcast;
bool inSubscribe;
int size; /* total of msgs */
int count; /* msg count */
};
#define RS_CHAT_PUBLIC 0x0001
#define RS_CHAT_PRIVATE 0x0002
class ChatInfo: public BaseInfo
{
public:
std::string rsid;
unsigned int chatflags;
std::string name;
std::string msg;
};
/* 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
class RsConfig
{
public:
std::string ownId;
std::string ownName;
std::list<std::string> sharedDirList;
std::string incomingDir;
std::string localAddr;
int localPort;
std::string extAddr;
int extPort;
std::string extName;
bool firewalled;
bool forwardPort;
int maxDataRate; /* kb */
int maxIndivDataRate; /* kb */
int promptAtBoot; /* popup the password prompt */
bool DHTActive;
bool uPnPActive;
int uPnPState;
int DHTPeers;
};
/********************** For Search Interface *****************/
/* This is still rough, implement later! */
/* text based ones */
const std::string TypeExt = "ext";
const std::string TypeName = "name";
const std::string TypeHash = "hash";
const std::string TypeSize = "size";
const int OpContains = 0x001;
const int OpExactMatch = 0x002;
const int OpLessThan = 0x003;
const int OpGreaterThan = 0x004;
class Condition
{
public:
std::string type;
int op;
double value;
std::string name;
};
class SearchRequest
{
public:
int searchId;
RsCertId toId; /* all zeros for everyone! */
std::list<Condition> tests;
};
std::ostream &operator<<(std::ostream &out, const NeighbourInfo &info);
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info);
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
std::ostream &operator<<(std::ostream &out, const PersonInfo &info);
std::ostream &print(std::ostream &out, const DirInfo &info, int indentLvl);
/********************** For FileCache Interface *****************/
#define DIR_TYPE_ROOT 0x01
#define DIR_TYPE_PERSON 0x02
#define DIR_TYPE_DIR 0x04
#define DIR_TYPE_FILE 0x08
/* flags for Directry request -
* two types;
* (1) Local / Remote (top byte)
* (2) Request type: Parent / Child - allows reduction in workload.
* (TODO)
*/
#define DIR_FLAGS_LOCAL 0x1000
#define DIR_FLAGS_REMOTE 0x2000
#define DIR_FLAGS_PARENT 0x0001
#define DIR_FLAGS_DETAILS 0x0002
#define DIR_FLAGS_CHILDREN 0x0004
class DirStub
{
public:
uint8_t type;
std::string name;
void *ref;
};
class DirDetails
{
public:
void *parent;
uint32_t prow; /* parent row */
void *ref;
uint8_t type;
std::string id;
std::string name;
std::string hash;
std::string path;
uint32_t count;
uint32_t age;
uint32_t rank;
std::list<DirStub> children;
};
class FileDetail
{
public:
std::string id;
std::string name;
std::string hash;
std::string path;
uint32_t size;
uint32_t age;
uint32_t rank;
};
#endif