PIFile: applyFileInfo
PIPeer: fixed pisd work progress ... git-svn-id: svn://db.shs.com.ru/pip@20 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -2,89 +2,121 @@
|
||||
#include "shared.h"
|
||||
#include "pisysteminfo.h"
|
||||
|
||||
extern PIScreen screen;
|
||||
|
||||
Daemon::Daemon(): PIPeer("_pisd_" + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
||||
setName("Daemon");
|
||||
timer.setName("__S__Daemon_timer");
|
||||
enabled = false;
|
||||
mode = offset = cur = height = 0;
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&timer, tickEvent, this, timerEvent)
|
||||
timer.addDelimiter(5);
|
||||
timer.start(200);
|
||||
|
||||
//CONNECTU(&console, keyPressed, this, keyEvent)
|
||||
//dir.setDir("/home/peri4/Documents");
|
||||
//TileSimple * tl;
|
||||
|
||||
tile_root = new PIScreenTile();
|
||||
tile_root->direction = Vertical;
|
||||
|
||||
tile_header = new TileSimple("daemon header");
|
||||
tile_header->size_policy = Fixed;
|
||||
|
||||
list_daemons = new TileList("daemons list");
|
||||
list_daemons->hide();
|
||||
|
||||
list_actions = new TileList("actions list");
|
||||
list_actions->hide();
|
||||
list_actions->content << TileList::Row("Information", CellFormat());
|
||||
list_actions->content << TileList::Row("File manager", CellFormat());
|
||||
list_actions->content << TileList::Row("Shell", CellFormat());
|
||||
|
||||
tile_info = new TileSimple("daemon info");
|
||||
tile_info->hide();
|
||||
|
||||
tile_root->addTile(tile_header);
|
||||
tile_root->addTile(list_daemons);
|
||||
tile_root->addTile(list_actions);
|
||||
tile_root->addTile(tile_info);
|
||||
|
||||
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||
|
||||
}
|
||||
|
||||
|
||||
PIScreenTile * Daemon::tile() const {
|
||||
return new PIScreenTile();
|
||||
return tile_root;
|
||||
}
|
||||
|
||||
|
||||
void Daemon::hideAll() {
|
||||
list_actions->hide();
|
||||
tile_info->hide();
|
||||
list_daemons->hide();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::showTile(PIScreenTile * t, const PIString & header) {
|
||||
hideAll();
|
||||
t->show();
|
||||
t->setFocus();
|
||||
tile_header->content.resize(1);
|
||||
tile_header->content[0].first = header;
|
||||
tile_header->content[0].second.flags = Bold;
|
||||
if (!conn_name.isEmpty())
|
||||
tile_header->content[0].first.insert(0, "Daemon \"" + connectedDaemon() + "\": ");
|
||||
}
|
||||
|
||||
|
||||
void Daemon::fillInfoTile(const Daemon::HostInfo & hi) {
|
||||
screen.lock();
|
||||
tile_info->content.clear();
|
||||
tile_info->content << TileSimple::Row("Exec command: " + hi.execCommand, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" Executed on " + hi.execDateTime.toString(), CellFormat());
|
||||
tile_info->content << TileSimple::Row(" Hostname: " + hi.hostname, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" Username: " + hi.user, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" OS name: " + hi.OS_name, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" OS version: " + hi.OS_version, CellFormat());
|
||||
tile_info->content << TileSimple::Row("Architecture: " + hi.architecture, CellFormat());
|
||||
tile_info->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(hi.processorsCount), CellFormat());
|
||||
screen.unlock();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
if (t == list_daemons) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
connectToDaemon(list_daemons->content[e.data.toInt()].first);
|
||||
showActionList();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (t == list_actions) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
switch (e.data.toInt()) {
|
||||
case 0: mode = 2; showTile(tile_info, "Information"); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (!enabled) return;
|
||||
int num = key.key - '0';
|
||||
switch (mode) {
|
||||
case 0:
|
||||
if (num >= 0 && num <= 9) {
|
||||
connectToDaemon(dnames.value(key.key - '0'));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (num >= 0 && num <= 9) {
|
||||
mode = num + 10;
|
||||
updateConsole();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!tile_root->visible) return;
|
||||
switch (key.key) {
|
||||
case PIKbdListener::UpArrow:
|
||||
/*cur--;
|
||||
if (cur < 0) cur = 0;
|
||||
if (cur - offset < 2) offset--;
|
||||
if (offset < 0) offset = 0;*/
|
||||
updateConsole();
|
||||
break;
|
||||
case PIKbdListener::Space:
|
||||
/*if (cur < 0 || cur >= files.size_s()) return;
|
||||
if (selected.contains(files[cur].name)) selected.removeOne(files[cur].name);
|
||||
else selected << files[cur].name;*/
|
||||
case PIKbdListener::DownArrow:
|
||||
/*cur++;
|
||||
if (cur >= files.size_s()) cur = files.size_s() - 1;
|
||||
if (cur - offset >= height - 2) offset++;
|
||||
if (offset >= files.size_s() - height) offset = files.size_s() - height;*/
|
||||
updateConsole();
|
||||
break;
|
||||
case PIKbdListener::Home:
|
||||
//cur = offset = 0;
|
||||
updateConsole();
|
||||
break;
|
||||
case PIKbdListener::End:
|
||||
//cur = files.size_s() - 1;
|
||||
//offset = files.size_s() - height;
|
||||
updateConsole();
|
||||
break;
|
||||
case PIKbdListener::Return:
|
||||
//if (cur < files.size_s() && cur >= 0) {
|
||||
//}
|
||||
break;
|
||||
case 'A':
|
||||
updateConsole();
|
||||
break;
|
||||
case 'R':
|
||||
updateConsole();
|
||||
break;
|
||||
case PIKbdListener::Esc:
|
||||
//selected.clear();
|
||||
//updateConsole();
|
||||
if (mode == 0)
|
||||
menuRequest();
|
||||
else {
|
||||
if (mode > 1) {
|
||||
mode = 1;
|
||||
updateConsole();
|
||||
screen.lock();
|
||||
tile_info->content.clear();
|
||||
screen.unlock();
|
||||
showActionList();
|
||||
} else
|
||||
disconnect();
|
||||
}
|
||||
@@ -95,16 +127,17 @@ void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
|
||||
|
||||
void Daemon::timerEvent(void * _d, int delim) {
|
||||
if (!enabled) return;
|
||||
if (delim == 1) {
|
||||
if (mode == 0)
|
||||
updateConsole();
|
||||
|
||||
}
|
||||
if (delim == 5) {
|
||||
screen.lock();
|
||||
list_daemons->content.clear();
|
||||
availableDaemons();
|
||||
piForeachC (PIString & i, available_daemons)
|
||||
list_daemons->content << TileList::Row(i, CellFormat());
|
||||
screen.unlock();
|
||||
if (delim == 5 && mode == 2) {
|
||||
if (conn_name.isEmpty()) return;
|
||||
PIByteArray ba; ba << int(RequestHostInfo);
|
||||
send(conn_name, ba);
|
||||
//std::cout << "send " << std::hex << ba;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,14 +156,13 @@ void Daemon::connectToDaemon(const PIString & dn) {
|
||||
if (dn.isEmpty()) return;
|
||||
conn_name = "_pisd_" + dn;
|
||||
mode = 1;
|
||||
updateConsole();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::disconnect() {
|
||||
conn_name.clear();
|
||||
mode = 0;
|
||||
updateConsole();
|
||||
showMainList();
|
||||
}
|
||||
|
||||
|
||||
@@ -139,10 +171,16 @@ PIString Daemon::connectedDaemon() const {
|
||||
}
|
||||
|
||||
|
||||
void Daemon::peerConnected(const PIString & name) {
|
||||
/*piCout << "connected" << name;
|
||||
mode = 2;
|
||||
conn_name = name;*/
|
||||
}
|
||||
|
||||
|
||||
void Daemon::peerDisconnected(const PIString & name) {
|
||||
if (name == conn_name) {
|
||||
conn_name.clear();
|
||||
mode = 0;
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +190,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
if (data.size() < 4) return;
|
||||
PIByteArray ba(data), rba;
|
||||
int type; ba >> type;
|
||||
//piCout << "rec from" << from << type;
|
||||
//std::cout << "rec from " << from << type;
|
||||
switch (type) {
|
||||
case RequestHostInfo:
|
||||
makeMyHostInfo();
|
||||
@@ -161,6 +199,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
case ReplyHostInfo:
|
||||
ba >> info_other;
|
||||
makeOtherHostInfo();
|
||||
fillInfoTile(info_other);
|
||||
break;
|
||||
};
|
||||
if (!rba.isEmpty()) send(from, rba);
|
||||
@@ -200,7 +239,6 @@ void Daemon::makeOtherHostInfo() {
|
||||
|
||||
|
||||
void Daemon::updateConsole() {
|
||||
if (!enabled) return;
|
||||
switch (mode) {
|
||||
case 0: tabConnect(); break;
|
||||
case 1: tabFeature(); break;
|
||||
|
||||
Reference in New Issue
Block a user