diff --git a/main.cpp b/main.cpp index ecb57532..87e1751c 100644 --- a/main.cpp +++ b/main.cpp @@ -19,7 +19,7 @@ class Catcher: public PIObject { PIOBJECT(Catcher) public: EVENT_HANDLER2(void, event, PIScreenTile *, t, PIScreenTypes::TileEvent, e) { - piCout << "event from" << t->name << "type" << e.type << e.data; + piCout << "event from" << t->name() << "type" << e.type << e.data; if (e.data == 2) delete t->parentTile(); } diff --git a/src/console/piscreen.cpp b/src/console/piscreen.cpp index 4faf2e81..36d13cb5 100644 --- a/src/console/piscreen.cpp +++ b/src/console/piscreen.cpp @@ -496,7 +496,7 @@ void PIScreen::end() { PIScreenTile * PIScreen::tileByName(const PIString & name) { PIVector tl(tiles()); piForeach (PIScreenTile * t, tl) - if (t->name == name) + if (t->name() == name) return t; return 0; } diff --git a/src/console/piscreentile.cpp b/src/console/piscreentile.cpp index bf07c4c7..4824150b 100644 --- a/src/console/piscreentile.cpp +++ b/src/console/piscreentile.cpp @@ -48,8 +48,7 @@ using namespace PIScreenTypes; -PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p) { - name = n; +PIScreenTile::PIScreenTile(const PIString & n, Direction d, SizePolicy p): PIObject(n) { direction = d; size_policy = p; focus_flags = 0; diff --git a/src/console/piscreentile.h b/src/console/piscreentile.h index 5f0dda7f..112ca9e8 100644 --- a/src/console/piscreentile.h +++ b/src/console/piscreentile.h @@ -28,8 +28,9 @@ class PIScreenDrawer; -class PIScreenTile { +class PIScreenTile: public PIObject { friend class PIScreen; + PIOBJECT_SUBCLASS(PIScreenTile, PIObject) public: PIScreenTile(const PIString & n = PIString(), PIScreenTypes::Direction d = PIScreenTypes::Vertical, PIScreenTypes::SizePolicy p = PIScreenTypes::Preferred); virtual ~PIScreenTile(); @@ -45,7 +46,6 @@ public: void setMargins(int m) {marginLeft = marginRight = marginTop = marginBottom = m;} void setMargins(int l, int r, int t, int b) {marginLeft = l; marginRight = r; marginTop = t; marginBottom = b;} - PIString name; PIScreenTypes::Direction direction; PIScreenTypes::SizePolicy size_policy; PIScreenTypes::FocusFlags focus_flags; diff --git a/src/console/piscreentiles.cpp b/src/console/piscreentiles.cpp index ba750dfb..e7baaca2 100644 --- a/src/console/piscreentiles.cpp +++ b/src/console/piscreentiles.cpp @@ -383,3 +383,40 @@ void TileProgress::drawEvent(PIScreenDrawer * d) { d->drawText(x + sx + fw, y, s.cutLeft(fw), Black, Transparent); } } + + + + +TilePICout::TilePICout(const PIString & n): TileList(n) { + max_lines = 1024; + selection_mode = TileList::SingleSelection; + PICout::setBufferActive(true); +} + + +void TilePICout::drawEvent(PIScreenDrawer * d) { + PIString out = PICout::buffer(true); + if (!out.isEmpty()) { + PIStringList l = out.split("\n"); + bool scroll = (cur == content.size_s() - 1) || !has_focus; + piForeachC (PIString & s, l) + content << TileList::Row(s, format); + if (content.size_s() > max_lines) + content.remove(0, content.size_s() - max_lines); + if (scroll) { + offset = piMaxi(0, content.size_s() - lhei); + cur = content.size_s() - 1; + } + } + TileList::drawEvent(d); +} + + +bool TilePICout::keyEvent(PIKbdListener::KeyEvent key) { + if (key.key == 'C') { + content.clear(); + cur = offset = 0; + return true; + } + return TileList::keyEvent(key); +} diff --git a/src/console/piscreentiles.h b/src/console/piscreentiles.h index 3a520313..a8efd425 100644 --- a/src/console/piscreentiles.h +++ b/src/console/piscreentiles.h @@ -53,7 +53,7 @@ public: RowPressed }; typedef PIPair Row; - PIVector content; + PIDeque content; PIScreenTypes::Alignment alignment; SelectionMode selection_mode; PISet selected; @@ -135,4 +135,17 @@ protected: }; + + +class TilePICout: public TileList { +public: + TilePICout(const PIString & n = PIString()); + PIScreenTypes::CellFormat format; + int max_lines; +protected: + void drawEvent(PIScreenDrawer * d); + bool keyEvent(PIKbdListener::KeyEvent key); +}; + + #endif // PISCREENTILES_H diff --git a/src/io/piethernet.h b/src/io/piethernet.h index 694870bb..38628859 100755 --- a/src/io/piethernet.h +++ b/src/io/piethernet.h @@ -181,6 +181,9 @@ public: //! Returns if %PIEthernet connected to TCP server. Use only for TCP_Client bool isConnected() const {return connected_;} + //! Returns if %PIEthernet is connecting to TCP server. Use only for TCP_Client + bool isConnecting() const {return connecting_;} + //! Start listen for incoming TCP connections on address \a readAddress(). Use only for TCP_Server bool listen(bool threaded = false); diff --git a/src/io/pipeer.cpp b/src/io/pipeer.cpp index f93971c0..081d1e41 100755 --- a/src/io/pipeer.cpp +++ b/src/io/pipeer.cpp @@ -314,12 +314,12 @@ bool PIPeer::dataRead(uchar * readed, int size) { if (type != 4) return true; diag_d.received(size); ba >> from >> to >> cnt >> rec_size; - //piCout << "[PIPeer \"" + name_ + "\"] Received packet" << /*type << from << to << cnt <<*/ rec_size; + piCoutObj << "Received packet" << type << from << to << cnt << rec_size; if (type == 4) { // data packet if (to == self_info.name) { // my packet int msg_count, cmsg; ba >> msg_count >> cmsg; - //piCout << "[PIPeer \"" + name_ + "\"] Received packet" << type << from << to << cnt << rec_size << msg_count << cmsg; + piCoutObj << "Received packet" << type << from << to << cnt << rec_size << msg_count << cmsg; if (cmsg == 0 && msg_count == 1) { dataReceived(from, ba); dataReceivedEvent(from, ba); @@ -333,11 +333,11 @@ bool PIPeer::dataRead(uchar * readed, int size) { } PeerData & pd(fp->_data); if (cmsg == 0) { - //piCout << "[PIPeer \"" + name_ + "\"] Packet clear" << rec_size; + piCoutObj << "Packet clear" << rec_size; pd.clear(); pd.msg_count = msg_count; } - //piCout << "[PIPeer \"" + name_ + "\"] Packet add" << cmsg << ba.size_s(); + piCoutObj << "Packet add" << cmsg << ba.size_s(); pd.addData(ba); bool frec = pd.isFullReceived(); PIByteArray rba(pd.data); @@ -345,7 +345,7 @@ bool PIPeer::dataRead(uchar * readed, int size) { if (frec) { dataReceived(from, rba); dataReceivedEvent(from, rba); - //piCout << "[PIPeer \"" + name_ + "\"] Packet received" << pd.data.size_s(); + piCoutObj << "Packet received" << pd.data.size_s(); } return true; } diff --git a/utils/system_daemon/daemon.cpp b/utils/system_daemon/daemon.cpp index 208272e0..21006ad5 100644 --- a/utils/system_daemon/daemon.cpp +++ b/utils/system_daemon/daemon.cpp @@ -267,7 +267,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) { Remote * r(0); PIString dir; int type; ba >> type; - //std::cout << "rec from " << from << type; + //piCout << "rec from " << from << type; switch (type) { case RequestHostInfo: makeMyHostInfo(); diff --git a/utils/system_daemon/file_manager.cpp b/utils/system_daemon/file_manager.cpp index 5f55a434..3d95c49c 100644 --- a/utils/system_daemon/file_manager.cpp +++ b/utils/system_daemon/file_manager.cpp @@ -177,7 +177,7 @@ FileManager::FileManager(Daemon * d) { panels[i] = new TileDir(); panels[i]->fm = this; panels[i]->key_func = (void*)tileKey_s; - panels[i]->name = "file panel " + PIString(i); + panels[i]->setName("file panel " + PIString(i)); panels[i]->label_path = plabel; panel->addTile(plabel); panel->addTile(panels[i]); diff --git a/utils/system_daemon/main.cpp b/utils/system_daemon/main.cpp index c23c24e3..118b9318 100755 --- a/utils/system_daemon/main.cpp +++ b/utils/system_daemon/main.cpp @@ -55,25 +55,29 @@ public: screen.rootTile()->addTile(center); PIScreenTile * mt = tmenu = menuTile(); - mt->show(); mt->name = "main menu"; + mt->show(); mt->name() = "main menu"; center->addTile(mt); mtiles << mt; mt = tinfo = infoTile(); - mt->hide(); mt->name = "local info"; + mt->hide(); mt->name() = "local info"; center->addTile(mt); mtiles << mt; mt = tfm = file_manager.tile(); - mt->hide(); mt->name = "file manager"; + mt->hide(); mt->name() = "file manager"; center->addTile(mt); mtiles << mt; mt = tdaemon = daemon_.tile(); - mt->hide(); mt->name = "daemon"; + mt->hide(); mt->name() = "daemon"; center->addTile(mt); mtiles << mt; mt = tpeer = peerTile(); - mt->hide(); mt->name = "peer info"; + mt->hide(); mt->name() = "peer info"; center->addTile(mt); mtiles << mt; + TilePICout * outt = new TilePICout(); + outt->size_policy = PIScreenTypes::Expanding; + screen.rootTile()->addTile(outt); + CONNECTU(&screen, tileEvent, this, tileEvent) CONNECTU(&screen, keyPressed, this, keyEvent) CONNECTU(&file_manager, menuRequest, this, menuRequest)