├── services ├── simpleserialiser.cpp ├── sync.h ├── imageresource.cpp ├── simpleserialiser.h ├── p3paintchatservice.cpp ├── paintchatitems.h ├── p3paintchatservice.h ├── imageresource.h ├── paintchatitems.cpp └── sync.cpp ├── paintchat-1.png ├── gui ├── images │ └── colors.png ├── paintchatwindow.cpp ├── images.qrc ├── paintchatpopupchatdialog.h ├── paintwidget.h ├── paintchatwindow.h ├── paintwidget.cpp ├── paintchatpopupchatdialog.cpp └── paintchatwindow.ui ├── interface └── paintchatservice.h ├── README.md ├── PaintChat.pro ├── paintchatplugin.h └── paintchatplugin.cpp /services/simpleserialiser.cpp: -------------------------------------------------------------------------------- 1 | #include "simpleserialiser.h" 2 | 3 | -------------------------------------------------------------------------------- /paintchat-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/paintchat-1.png -------------------------------------------------------------------------------- /services/sync.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/services/sync.h -------------------------------------------------------------------------------- /gui/images/colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/gui/images/colors.png -------------------------------------------------------------------------------- /gui/paintchatwindow.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/gui/paintchatwindow.cpp -------------------------------------------------------------------------------- /services/imageresource.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/services/imageresource.cpp -------------------------------------------------------------------------------- /services/simpleserialiser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/services/simpleserialiser.h -------------------------------------------------------------------------------- /gui/images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/colors.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /services/p3paintchatservice.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chozabu/Retroshare-Paintchat-Plugin/master/services/p3paintchatservice.cpp -------------------------------------------------------------------------------- /gui/paintchatpopupchatdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTCHATPOPUPCHATDIALOG_H 2 | #define PAINTCHATPOPUPCHATDIALOG_H 3 | 4 | #include 5 | #include "paintchatwindow.h" 6 | 7 | class PaintChatPopupChatDialog : public PopupChatDialog 8 | { 9 | Q_OBJECT 10 | public: 11 | PaintChatPopupChatDialog(QWidget *parent = NULL); 12 | 13 | private slots: 14 | void togglePaintChatWindow(); 15 | 16 | protected: 17 | virtual void init(const std::string &peerId, const QString &title); 18 | 19 | private: 20 | QPushButton *paintChatWindowToggleButton; 21 | PaintChatWindow *paintChatWindow; 22 | }; 23 | 24 | #endif // PAINTCHATPOPUPCHATDIALOG_H 25 | -------------------------------------------------------------------------------- /interface/paintchatservice.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTCHATSERVICE_H 2 | #define PAINTCHATSERVICE_H 3 | 4 | #include "services/sync.h" 5 | #include "services/imageresource.h" 6 | 7 | class PaintChatService; 8 | extern PaintChatService *paintChatService; 9 | 10 | class PaintChatService{ 11 | public: 12 | virtual void init(std::string id, ImageResource res)=0; 13 | // tell remote end to init 14 | virtual void sendInit(std::string id, ImageResource res)=0; 15 | virtual bool haveUpdate(std::string id)=0; 16 | virtual bool receivedInit(std::string id)=0; 17 | virtual ImageResource update(std::string id, ImageResource res)=0; 18 | }; 19 | 20 | #endif // PAINTCHATSERVICE_H 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Retroshare-Paintchat-Plugin # 2 | 3 | Draw a quick sketch to explain things. 4 | 5 | ![screenshot](https://github.com/electron128/Retroshare-Paintchat-Plugin/raw/master/paintchat-1.png "Paintchat Plugin for Retroshare") 6 | 7 | ## How to compile ## 8 | 9 | 1. Prepare Retroshare build environment [http://retroshare.sourceforge.net/wiki/index.php/Developers_Corner](http://retroshare.sourceforge.net/wiki/index.php/Developers_Corner) 10 | 2. clone this Repository into **retroshare/plugins** 11 | 3. add **Retroshare-Paintchat-Plugin** to **retroshare/plugins/plugins.pro** 12 | 13 | ## What is Retroshare? ## 14 | 15 | [Retroshare](http://retroshare.sourceforge.net) is a secure friend-2-friend social network. -------------------------------------------------------------------------------- /gui/paintwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTWIDGET_H 2 | #define PAINTWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class PaintWidget : public QWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | explicit PaintWidget(QWidget *parent = 0); 14 | void setImage(const QImage&); 15 | QImage getImage(); 16 | 17 | void fillImage(QColor color); 18 | 19 | QColor color; 20 | uint8_t penWidth; 21 | 22 | signals: 23 | void haveUpdate(); 24 | 25 | public slots: 26 | 27 | protected: 28 | virtual void mouseMoveEvent(QMouseEvent *); 29 | virtual void mouseReleaseEvent(QMouseEvent * event); 30 | virtual void paintEvent(QPaintEvent *); 31 | 32 | private: 33 | QImage image; 34 | 35 | }; 36 | 37 | #endif // PAINTWIDGET_H 38 | -------------------------------------------------------------------------------- /PaintChat.pro: -------------------------------------------------------------------------------- 1 | !include("../Common/retroshare_plugin.pri"): error("Could not include file ../Common/retroshare_plugin.pri") 2 | 3 | CONFIG += qt uic qrc 4 | 5 | INCLUDEPATH += ../../retroshare-gui/src/temp/ui 6 | 7 | SOURCES = \ 8 | paintchatplugin.cpp \ 9 | gui/paintchatwindow.cpp \ 10 | gui/paintchatpopupchatdialog.cpp \ 11 | services/paintchatitems.cpp \ 12 | services/p3paintchatservice.cpp \ 13 | gui/paintwidget.cpp \ 14 | services/imageresource.cpp 15 | HEADERS = \ 16 | paintchatplugin.h \ 17 | gui/paintchatwindow.h \ 18 | gui/paintchatpopupchatdialog.h \ 19 | services/paintchatitems.h \ 20 | services/sync.h \ 21 | services/p3paintchatservice.h \ 22 | interface/paintchatservice.h \ 23 | gui/paintwidget.h \ 24 | services/imageresource.h 25 | FORMS = \ 26 | gui/paintchatwindow.ui 27 | 28 | TARGET = PaintChat 29 | 30 | RESOURCES += \ 31 | gui/images.qrc 32 | -------------------------------------------------------------------------------- /gui/paintchatwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTCHATWINDOW_H 2 | #define PAINTCHATWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class PaintChatWindow; 9 | } 10 | 11 | class PaintChatWindow : public QMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit PaintChatWindow(QWidget *parent = 0); 17 | ~PaintChatWindow(); 18 | 19 | void setPeerId(std::string peerId); 20 | 21 | private slots: 22 | void on_haveUpdate(); 23 | void on_timer(); 24 | 25 | void on_pushButtonBlack_clicked(); 26 | 27 | void on_pushButtonWhite_clicked(); 28 | 29 | void on_pushButton1px_clicked(); 30 | 31 | void on_pushButton4px_clicked(); 32 | 33 | void on_pushButton8px_clicked(); 34 | 35 | void on_pushButtonClear_clicked(); 36 | 37 | void on_pushButtonCopy_clicked(); 38 | 39 | private: 40 | void updateImage(); 41 | void resetPenButtons(); 42 | Ui::PaintChatWindow *ui; 43 | std::string peerId; 44 | 45 | QTimer *timer; 46 | }; 47 | 48 | #endif // PAINTCHATWINDOW_H 49 | -------------------------------------------------------------------------------- /paintchatplugin.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTCHATPLUGIN_H 2 | #define PAINTCHATPLUGIN_H 3 | 4 | #include 5 | #include "services/paintchatitems.h" 6 | #include "services/p3paintchatservice.h" 7 | 8 | class PaintChatPlugin : public RsPlugin 9 | { 10 | public: 11 | PaintChatPlugin(); 12 | virtual ~PaintChatPlugin(); 13 | 14 | virtual void getPluginVersion(int& major,int& minor,int& svn_rev) const ; 15 | virtual void setPlugInHandler(RsPluginHandler *pgHandler); 16 | 17 | 18 | virtual std::string getShortPluginDescription() const ; 19 | virtual std::string getPluginName() const; 20 | virtual void setInterfaces(RsPlugInInterfaces& interfaces); 21 | 22 | virtual RsPQIService *rs_pqi_service() const ; 23 | virtual uint16_t rs_service_id() const { return RS_SERVICE_TYPE_PAINTCHAT_PLUGIN ; } 24 | 25 | virtual PopupChatDialog *qt_allocate_new_popup_chat_dialog() const ; 26 | 27 | private: 28 | RsPluginHandler *mPlugInHandler; 29 | // keine ahnung warum mutable 30 | mutable p3PaintChatService *mService; 31 | }; 32 | 33 | #endif // PAINTCHATPLUGIN_H 34 | -------------------------------------------------------------------------------- /gui/paintwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "paintwidget.h" 2 | 3 | #include 4 | #include 5 | 6 | PaintWidget::PaintWidget(QWidget *parent) : 7 | QWidget(parent),image(500,500,QImage::Format_RGB32),color(Qt::black),penWidth(1) 8 | { 9 | image.fill(Qt::white); 10 | } 11 | 12 | void PaintWidget::setImage(const QImage &img){ 13 | image=img.copy(); 14 | update(); 15 | } 16 | 17 | QImage PaintWidget::getImage(){ 18 | return image; 19 | } 20 | 21 | void PaintWidget::fillImage(QColor color){ 22 | image.fill(color); 23 | update(); 24 | } 25 | 26 | void PaintWidget::mouseMoveEvent(QMouseEvent *event) 27 | { 28 | QPainter p(&image); 29 | p.setPen(color); 30 | p.setBrush(color); 31 | if(penWidth==1){ 32 | p.drawPoint(event->pos()); 33 | }else{ 34 | p.drawEllipse(event->pos(),penWidth/2,penWidth/2); 35 | } 36 | // trigger repaint of widget 37 | update(); 38 | } 39 | 40 | void PaintWidget::mouseReleaseEvent(QMouseEvent *event){ 41 | std::cout<<"PaintWidgte::mouseReleseEvent()"<hide(); 9 | 10 | paintChatWindowToggleButton = new QPushButton ; 11 | paintChatWindowToggleButton->setMinimumSize(QSize(28,28)) ; 12 | paintChatWindowToggleButton->setMaximumSize(QSize(28,28)) ; 13 | paintChatWindowToggleButton->setText(QString()) ; 14 | paintChatWindowToggleButton->setToolTip(tr("PaintChat")); 15 | 16 | QIcon icon ; 17 | icon.addPixmap(QPixmap(":/images/colors.png")); 18 | paintChatWindowToggleButton->setIcon(icon); 19 | 20 | connect(paintChatWindowToggleButton,SIGNAL(clicked()),this,SLOT(togglePaintChatWindow())); 21 | 22 | addChatBarWidget(paintChatWindowToggleButton); 23 | } 24 | 25 | void PaintChatPopupChatDialog::togglePaintChatWindow(){ 26 | if(paintChatWindow->isHidden()){ 27 | paintChatWindow->show(); 28 | }else{ 29 | paintChatWindow->hide(); 30 | } 31 | } 32 | 33 | void PaintChatPopupChatDialog::init(const std::string &peerId, const QString &title){ 34 | PopupChatDialog::init(peerId,title); 35 | paintChatWindow->setPeerId(getPeerId()); 36 | } 37 | -------------------------------------------------------------------------------- /services/paintchatitems.h: -------------------------------------------------------------------------------- 1 | #ifndef PAINTCHATITEMS_H 2 | #define PAINTCHATITEMS_H 3 | 4 | #include "serialiser/rsserviceids.h" 5 | #include "serialiser/rsserial.h" 6 | #include "serialiser/rstlvtypes.h" 7 | 8 | // --------TODO------------ 9 | const uint16_t RS_SERVICE_TYPE_PAINTCHAT_PLUGIN=RS_SERVICE_TYPE_PLUGIN_ARADO_TEST_ID1; 10 | 11 | 12 | class RsPaintChatItem: public RsItem{ 13 | public: 14 | RsPaintChatItem():RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PAINTCHAT_PLUGIN, 0),binData(0){ 15 | setPriorityLevel(QOS_PRIORITY_DEFAULT); 16 | } 17 | virtual ~RsPaintChatItem(){} 18 | virtual void clear(){} 19 | 20 | virtual std::ostream& print(std::ostream &out, uint16_t indent = 0); 21 | 22 | uint8_t command; 23 | RsTlvBinaryData binData; 24 | }; 25 | 26 | class RsPaintChatSerialiser: public RsSerialType 27 | { 28 | public: 29 | RsPaintChatSerialiser() 30 | :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_PAINTCHAT_PLUGIN) 31 | { 32 | } 33 | virtual ~RsPaintChatSerialiser() {} 34 | 35 | virtual uint32_t size (RsItem *item); 36 | virtual bool serialise (RsItem *item, void *data, uint32_t *pktsize); 37 | virtual RsItem *deserialise(void *data, uint32_t *pktsize); 38 | }; 39 | 40 | #endif // PAINTCHATITEMS_H 41 | -------------------------------------------------------------------------------- /services/p3paintchatservice.h: -------------------------------------------------------------------------------- 1 | #ifndef P3PAINTCHATSERVICE_H 2 | #define P3PAINTCHATSERVICE_H 3 | 4 | #include "plugins/rspqiservice.h" 5 | #include "interface/paintchatservice.h" 6 | 7 | #include 8 | 9 | class p3PaintChatService : public RsPQIService, public PaintChatService 10 | { 11 | public: 12 | p3PaintChatService(RsPluginHandler *handler); 13 | ~p3PaintChatService(); 14 | 15 | virtual int tick(); 16 | 17 | virtual void init(std::string id, ImageResource res); 18 | // tell remote end to init 19 | virtual void sendInit(std::string id, ImageResource res); 20 | virtual bool haveUpdate(std::string id); 21 | virtual bool receivedInit(std::string id); 22 | virtual ImageResource update(std::string id, ImageResource res); 23 | 24 | private: 25 | 26 | SyncEngine* addPeer(std::string peerId); 27 | 28 | static const uint8_t COMMAND_INIT=0; 29 | static const uint8_t COMMAND_SYNC=1; 30 | 31 | class PaintChatConnection: public Connection{ 32 | public: 33 | PaintChatConnection(std::string connId, p3PaintChatService *service ); 34 | void sendData(void *data, const uint32_t &size); 35 | std::string connId; 36 | p3PaintChatService *service; 37 | }; 38 | 39 | std::mapconnections; 40 | std::map*> syncEngines; 41 | std::list receivedInits; 42 | }; 43 | 44 | #endif // P3PAINTCHATSERVICE_H 45 | -------------------------------------------------------------------------------- /services/imageresource.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGERESOURCE_H 2 | #define IMAGERESOURCE_H 3 | 4 | #include 5 | #include 6 | 7 | class ImageDiff; 8 | 9 | class ImageResource{ 10 | public: 11 | ImageResource(); 12 | ImageResource(const ImageResource &other); 13 | ~ImageResource(); 14 | ImageResource& operator= (ImageResource other); 15 | 16 | // serialisation methods 17 | uint32_t serial_size(); 18 | bool serialise(void *pktdata, uint32_t pktsize); 19 | bool deserialise(void *pktdata, uint32_t pktsize); 20 | 21 | ImageDiff diff(ImageResource modifiedResource, bool &resourceIsModified); 22 | void patch(ImageDiff d); 23 | 24 | QImage toQImage(); 25 | void fromQImage(const QImage &other); 26 | 27 | private: 28 | uint32_t width; 29 | uint32_t height; 30 | 31 | void *data; 32 | uint32_t size; 33 | }; 34 | 35 | class ImageDiff{ 36 | public: 37 | ImageDiff(); 38 | ImageDiff(const ImageDiff &other); 39 | ~ImageDiff(); 40 | ImageDiff& operator=(ImageDiff other); 41 | 42 | uint32_t serial_size(); 43 | bool serialise(void *pktdata, uint32_t pktsize); 44 | bool deserialise(void *pktdata, uint32_t pktsize); 45 | 46 | void *data; 47 | uint32_t size; 48 | }; 49 | 50 | // serialisation helpers 51 | void serialise_uint32(void *data,uint32_t val); 52 | uint32_t deserialise_uint32(void *data); 53 | void* shiftVoidPointer(void *p, uint8_t offset); 54 | 55 | void compress(uint8_t *&,uint32_t &); 56 | void decompress(uint8_t *&,uint32_t &); 57 | 58 | // alt und tut 59 | /* 60 | class ImageDiff 61 | { 62 | public: 63 | ImageDiff(); 64 | 65 | ImageDiff(const ImageDiff &other); 66 | ~ImageDiff(); 67 | ImageDiff& operator= (const ImageDiff other); 68 | 69 | bool diff(const QImage& oldimg, const QImage &newimg); 70 | bool patch(QImage &); 71 | 72 | bool serialize(void *,const uint32_t&); 73 | void serial_size(uint32_t&); 74 | 75 | bool deserialize(void *,const uint32_t&); 76 | 77 | private: 78 | void compress(uint8_t *&,uint32_t &); 79 | void decompress(uint8_t *&,uint32_t &); 80 | 81 | uint8_t *data; 82 | uint32_t size; 83 | bool compressed; 84 | }; 85 | */ 86 | #endif // IMAGERESOURCE_H 87 | -------------------------------------------------------------------------------- /paintchatplugin.cpp: -------------------------------------------------------------------------------- 1 | #include "paintchatplugin.h" 2 | 3 | #include "gui/paintchatpopupchatdialog.h" 4 | 5 | extern "C" { 6 | 7 | // This is *the* functions required by RS plugin system to give RS access to the plugin. 8 | // Be careful to: 9 | // - always respect the C linkage convention 10 | // - always return an object of type RsPlugin* 11 | // 12 | void *RETROSHARE_PLUGIN_provide() 13 | { 14 | static PaintChatPlugin *p = new PaintChatPlugin() ; 15 | 16 | return (void*)p ; 17 | } 18 | 19 | // This symbol contains the svn revision number grabbed from the executable. 20 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 21 | // with same revision numbers, assuming that the revision numbers are up-to-date. 22 | // 23 | uint32_t RETROSHARE_PLUGIN_revision = SVN_REVISION_NUMBER ; 24 | 25 | // This symbol contains the svn revision number grabbed from the executable. 26 | // It will be tested by RS to load the plugin automatically, since it is safe to load plugins 27 | // with same revision numbers, assuming that the revision numbers are up-to-date. 28 | // 29 | uint32_t RETROSHARE_PLUGIN_api = RS_PLUGIN_API_VERSION ; 30 | } 31 | 32 | PaintChatPlugin::PaintChatPlugin():mService(NULL){ 33 | std::cerr<<"PaintChatPlugin::PaintChatPlugin()"< 4 | 5 | std::ostream& RsPaintChatItem::print(std::ostream &out, uint16_t indent){ 6 | printRsItemBase(out, "RsPaintChatItem", indent); 7 | uint16_t int_Indent = indent + 2; 8 | printIndent(out, int_Indent); 9 | out << "Nothing here: " << 0 << std::endl; 10 | 11 | printRsItemEnd(out, "RsPaintChatItem", indent); 12 | return out; 13 | } 14 | 15 | 16 | uint32_t RsPaintChatSerialiser::size(RsItem *item){ 17 | RsPaintChatItem *paintChatItem= dynamic_cast(item); 18 | uint32_t size=0; 19 | // header 20 | size+=8; 21 | 22 | // command 23 | size+=1; 24 | 25 | size+=paintChatItem->binData.TlvSize(); 26 | 27 | std::cerr<<"RsPaintChatSerialiser::size():"<(item); 52 | 53 | *(((uint8_t*)data)+offset)=paintChatItem->command; 54 | offset+=1; 55 | 56 | ok &= paintChatItem->binData.SetTlv(data,*pktsize,&offset); 57 | 58 | if (offset != tlvsize) 59 | { 60 | ok = false; 61 | std::cerr << "RsPaintChatSerialiser::serialise()) Size Error! " << std::endl; 62 | } 63 | 64 | return ok; 65 | } 66 | 67 | RsItem *RsPaintChatSerialiser::deserialise(void *data, uint32_t *pktsize){ 68 | std::cerr << "RsPaintChatSerialiser::deserialise()" << std::endl; 69 | 70 | /* get the type and size */ 71 | uint32_t rstype = getRsItemId(data); 72 | uint32_t rssize = getRsItemSize(data); 73 | 74 | if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_PAINTCHAT_PLUGIN != getRsItemService(rstype))) 75 | return NULL ; 76 | 77 | uint32_t offset = 0; 78 | 79 | if (*pktsize < rssize){ /* check size */ 80 | //throw std::runtime_error("Not enough space") ; 81 | std::cerr << "RsPaintChatSerialiser::deserialise() Not enough space! " << std::endl; 82 | return NULL; 83 | } 84 | 85 | bool ok = true; 86 | 87 | /* skip the header */ 88 | offset += 8; 89 | 90 | RsPaintChatItem *paintChatItem=new RsPaintChatItem(); 91 | 92 | paintChatItem->command=*(((uint8_t*)data)+offset); 93 | offset +=1; 94 | 95 | ok &= paintChatItem->binData.GetTlv(data,*pktsize,&offset); 96 | 97 | if (offset != rssize){ 98 | //throw std::runtime_error("Serialization error.") ; 99 | std::cerr << "RsPaintChatSerialiser::deserialise() Serialization error. " << std::endl; 100 | delete paintChatItem; 101 | return NULL; 102 | } 103 | 104 | if (!ok){ 105 | //throw std::runtime_error("Serialization error.") ; 106 | std::cerr << "RsPaintChatSerialiser::deserialise() Serialization error: ok=false " << std::endl; 107 | delete paintChatItem; 108 | return NULL; 109 | } 110 | 111 | return paintChatItem; 112 | } 113 | -------------------------------------------------------------------------------- /services/sync.cpp: -------------------------------------------------------------------------------- 1 | #include "sync.h" 2 | 3 | // alter code 4 | 5 | SyncEngineImpl::SyncEngineImpl(Connection *c, Diff *d, Resource *r):connection(c),diff(d),resource(r){ 6 | 7 | } 8 | 9 | void SyncEngineImpl::tick(){ 10 | 11 | } 12 | 13 | Resource SyncEngineImpl::update(const Resource &res){ 14 | Diff *diff; 15 | res.diff(currentRessourceState,res,diff); 16 | SyncItem item; 17 | item.type=SyncItem::TYPE_DIFF; 18 | item.timestamp=time(); 19 | item.diff=diff; 20 | 21 | void *buf; 22 | uint32_t size; 23 | item.serial_size(size); 24 | buf=malloc(size); 25 | item.serialize(data,size); 26 | connection->sendData(data,size); 27 | processData(data,size); 28 | free(buf); 29 | 30 | calcCurrentRessourceState(); 31 | return currentRessourceState; 32 | } 33 | 34 | void SyncEngineImpl::processData(void *data, const uint32_t &size){ 35 | SyncItem item(data,size); 36 | 37 | //first item in history should be resource 38 | if((history.size()>0)&&(item.type==SyncItem::TYPE_RES)&&(history.front.type==SyncItem::TYPE_DIFF)){ 39 | item.timestamp=0; 40 | } 41 | 42 | history.push_back(item); 43 | history.sort(SyncItem.compare); 44 | } 45 | 46 | bool SyncEngineImpl::calcCurrentRessourceState(){ 47 | if(history.size()==0){ 48 | return false; 49 | } 50 | if(history.front.type==SyncItem::TYPE_DIFF){ 51 | return false; 52 | } 53 | currentRessourceState=history.front(); 54 | for(std::list::iterator it=(history.begin())+1;it!=history.end();it++){ 55 | if(it->first.type==SyncItem::TYPE_DIFF){ 56 | currentRessourceState.patch(*(it->first.diff)); 57 | } 58 | } 59 | } 60 | 61 | void SyncEngineImpl::SyncItem::SyncItem(void *data, const &size){ 62 | type=*((uint8_t*)data); 63 | data++; 64 | timestamp=((*((uint8_t*)data+0))<<0)| 65 | ((*((uint8_t*)data+1))<<8)| 66 | ((*((uint8_t*)data+2))<<16)| 67 | ((*((uint8_t*)data+3))<<24); 68 | data+=4; 69 | switch(type){ 70 | case TYPE_DIFF: 71 | SyncEngineImpl::diff->deserialise(data,size,diff); 72 | break; 73 | case TYPE_RES: 74 | SyncEngineImpl::resource->deserialise(data,size,resource); 75 | break; 76 | default: 77 | std::cerr<<"Error in SyncEngineImpl::SyncItem::SyncItem(): no type"; 78 | } 79 | } 80 | 81 | void SyncEngineImpl::SyncItem::serial_size(uint32_t &size){ 82 | switch(type){ 83 | case TYPE_DIFF: 84 | diff->serial_size(size); 85 | size+=5; 86 | break; 87 | case TYPE_RES: 88 | resource->serial_size(size); 89 | size+=5; 90 | break; 91 | default: 92 | size=0; 93 | std::cerr<<"Error in SyncEngineImpl::SyncItem::serial_size(): no type"; 94 | } 95 | } 96 | 97 | void SyncEngineImpl::SyncItem::serialize(void *data, const uint32_t &size){ 98 | *((uint8_t*)data)=type; 99 | data++; 100 | *((uint8_t*)(data+0))=(uint8_t)(timestamp>>0); 101 | *((uint8_t*)(data+1))=(uint8_t)(timestamp>>8); 102 | *((uint8_t*)(data+2))=(uint8_t)(timestamp>>16); 103 | *((uint8_t*)(data+3))=(uint8_t)(timestamp>>24); 104 | data+=4; 105 | switch(type){ 106 | case TYPE_DIFF: 107 | diff->serialize(data,size); 108 | break; 109 | case TYPE_RES: 110 | resource->serialize(data,size); 111 | break; 112 | default: 113 | std::cerr<<"Error in SyncEngineImpl::SyncItem::serialize(): no type"; 114 | } 115 | } 116 | 117 | void SyncEngineImpl::SyncItem::deserialise(void *data, const uint32_t &size, t *&obj){ 118 | 119 | } 120 | 121 | static bool SyncEngineImpl::SyncItem::compare(const SyncItem &first, const SyncItem &second){ 122 | if(first.timestamp==second.timestamp){ 123 | // todo: compare checksum 124 | return true; 125 | }else{ 126 | return (first.timestamp 2 | 3 | PaintChatWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 601 10 | 571 11 | 12 | 13 | 14 | PaintChat 15 | 16 | 17 | 18 | 19 | 20 | 10 21 | 10 22 | 611 23 | 16 24 | 25 | 26 | 27 | peername here 28 | 29 | 30 | 31 | 32 | 33 | 90 34 | 40 35 | 501 36 | 501 37 | 38 | 39 | 40 | 41 | 42 | 43 | 10 44 | 40 45 | 75 46 | 23 47 | 48 | 49 | 50 | black 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | 59 | 10 60 | 70 61 | 75 62 | 23 63 | 64 | 65 | 66 | white 67 | 68 | 69 | true 70 | 71 | 72 | 73 | 74 | 75 | 10 76 | 110 77 | 75 78 | 23 79 | 80 | 81 | 82 | 1px 83 | 84 | 85 | true 86 | 87 | 88 | 89 | 90 | 91 | 10 92 | 140 93 | 75 94 | 23 95 | 96 | 97 | 98 | 4px 99 | 100 | 101 | true 102 | 103 | 104 | 105 | 106 | 107 | 10 108 | 170 109 | 75 110 | 23 111 | 112 | 113 | 114 | 8px 115 | 116 | 117 | true 118 | 119 | 120 | 121 | 122 | 123 | 10 124 | 400 125 | 75 126 | 23 127 | 128 | 129 | 130 | clear 131 | 132 | 133 | 134 | 135 | 136 | 10 137 | 240 138 | 75 139 | 23 140 | 141 | 142 | 143 | copy 144 | 145 | 146 | 147 | 148 | 149 | 150 | 0 151 | 0 152 | 601 153 | 21 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | PaintWidget 162 | QWidget 163 |
gui/paintwidget.h
164 | 1 165 |
166 |
167 | 168 | 169 |
170 | --------------------------------------------------------------------------------