git-svn-id: svn://db.shs.com.ru/pip@249 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -9,21 +9,65 @@ extern PIScreen * screen;
|
||||
|
||||
Daemon::Remote::Remote(const PIString & n): PIThread() {
|
||||
setName(n);
|
||||
term = 0;
|
||||
ft.setName(n);
|
||||
ft.setPacketSize(3984);
|
||||
CONNECTU(&ft, sendRequest, this, ftSendRequest)
|
||||
CONNECTU(&ft, receiveFilesFinished, this, ftReceived)
|
||||
CONNECTU(&ft, sendFilesFinished, this, ftSended)
|
||||
CONNECTU(&term_timer, tickEvent, this, termTimerTick)
|
||||
dir_my = PIDir::current();
|
||||
}
|
||||
|
||||
|
||||
Daemon::Remote::~Remote() {
|
||||
shellClose();
|
||||
ft.stop();
|
||||
stop(true);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::shellOpen() {
|
||||
if (term) return;
|
||||
term = new PITerminal();
|
||||
term->initialize();
|
||||
term_timer.start(40);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::shellClose() {
|
||||
if (!term) return;
|
||||
//piCoutObj << "shellClose ...";
|
||||
term_timer.stop();
|
||||
term_timer.waitForFinish(100);
|
||||
term->destroy();
|
||||
delete term;
|
||||
term = 0;
|
||||
//piCoutObj << "shellClose ok";
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::shellResize(int w, int h) {
|
||||
if (!term) return;
|
||||
term->resize(w, h);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::shellKeySend(PIKbdListener::KeyEvent k) {
|
||||
if (!term) return;
|
||||
term->write(k);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::termTimerTick() {
|
||||
if (!term) return;
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > cells = term->content();
|
||||
PIByteArray ba;
|
||||
ba << int(ShellContent) << cells;
|
||||
sendRequest(name(), ba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::startAction(Daemon::PacketType a, const PIString & dir, const PIStringList & fl) {
|
||||
_fl = fl;
|
||||
if (!dir.isEmpty())
|
||||
@@ -209,7 +253,8 @@ void Daemon::TileFileProgress::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()->hostname + "_" + PIString(rand() % 100)) {
|
||||
// setName("Daemon");
|
||||
dtimer.setName("__S__Daemon_timer");
|
||||
mode = offset = cur = height = 0;
|
||||
mode = rmNone;
|
||||
offset = cur = height = 0;
|
||||
CONNECTU(screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&dtimer, tickEvent, this, timerEvent)
|
||||
CONNECTU(&fm, tileKey, this, fmKeyEvent)
|
||||
@@ -251,13 +296,21 @@ Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()
|
||||
tile_fm->hide();
|
||||
|
||||
tile_file_progress = new TileFileProgress();
|
||||
|
||||
|
||||
tile_shell = new TileTerminal("shell");
|
||||
tile_shell->hide();
|
||||
CONNECTU(tile_shell, resizeRequest, this, shResizeRequest)
|
||||
CONNECTU(tile_shell, keyPressed, this, shKeyEvent)
|
||||
CONNECTU(tile_shell, closeRequest, this, requestCloseShell)
|
||||
CONNECTU(tile_shell, closeRequest, this, escPressed)
|
||||
|
||||
|
||||
tile_root->addTile(tile_header);
|
||||
tile_root->addTile(list_daemons);
|
||||
tile_root->addTile(list_actions);
|
||||
tile_root->addTile(tile_info);
|
||||
tile_root->addTile(tile_fm);
|
||||
tile_root->addTile(tile_shell);
|
||||
|
||||
CONNECTU(screen, tileEvent, this, tileEvent)
|
||||
reinit();
|
||||
@@ -266,9 +319,12 @@ Daemon::Daemon(): inited__(false), PIPeer(pisd_prefix + PISystemInfo::instance()
|
||||
|
||||
|
||||
Daemon::~Daemon() {
|
||||
requestCloseShell();
|
||||
PIVector<Remote*> rl = remotes.values();
|
||||
piForeach (Remote * r, rl)
|
||||
piForeach (Remote * r, rl) {
|
||||
r->shellClose();
|
||||
delete r;
|
||||
}
|
||||
remotes.clear();
|
||||
}
|
||||
|
||||
@@ -278,6 +334,40 @@ PIScreenTile * Daemon::tile() const {
|
||||
}
|
||||
|
||||
|
||||
void Daemon::escPressed() {
|
||||
if (mode == rmNone)
|
||||
menuRequest();
|
||||
else {
|
||||
if (mode > rmSelectMode) {
|
||||
mode = rmSelectMode;
|
||||
screen->lock();
|
||||
tile_info->content.clear();
|
||||
screen->unlock();
|
||||
showActionList();
|
||||
} else
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Daemon::shResizeRequest() {
|
||||
Remote * r = remotes.value(conn_name, 0);
|
||||
if (!r) return;
|
||||
PIByteArray ba;
|
||||
ba << int(ShellResizeRequest) << int(tile_shell->width()) << int(tile_shell->height());
|
||||
send(conn_name, ba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::shKeyEvent(PIKbdListener::KeyEvent k) {
|
||||
Remote * r = remotes.value(conn_name, 0);
|
||||
if (!r) return;
|
||||
PIByteArray ba;
|
||||
ba << int(ShellKeyEvent) << k;
|
||||
send(conn_name, ba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::localSend(const PIString & p_name, const PIByteArray & data) {
|
||||
//piCoutObj << "localSend" << localft.stateString();
|
||||
PIByteArray h; h << int(FileTransfer);
|
||||
@@ -292,6 +382,7 @@ void Daemon::hideAll() {
|
||||
tile_info->hide();
|
||||
list_daemons->hide();
|
||||
tile_fm->hide();
|
||||
tile_shell->hide();
|
||||
}
|
||||
|
||||
|
||||
@@ -344,12 +435,20 @@ void Daemon::tileEvent(PIScreenTile * t, TileEvent e) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
PIMutexLocker ml(remote_mutex);
|
||||
switch (e.data.toInt()) {
|
||||
case 0: mode = 2; showTile(tile_info, "Information"); break;
|
||||
case 0:
|
||||
mode = rmInformation;
|
||||
showTile(tile_info, "Information");
|
||||
break;
|
||||
case 1:
|
||||
mode = 3;
|
||||
mode = rmFileManager;
|
||||
showTile(tile_fm, "File manager");
|
||||
requestChDir(".");
|
||||
break;
|
||||
case 2:
|
||||
mode = rmShell;
|
||||
showTile(tile_shell, "Shell");
|
||||
requestOpenShell();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -363,18 +462,7 @@ void Daemon::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
if (screen->dialogTile()) return;
|
||||
switch (key.key) {
|
||||
case PIKbdListener::Esc:
|
||||
if (mode == 0)
|
||||
menuRequest();
|
||||
else {
|
||||
if (mode > 1) {
|
||||
mode = 1;
|
||||
screen->lock();
|
||||
tile_info->content.clear();
|
||||
screen->unlock();
|
||||
showActionList();
|
||||
} else
|
||||
disconnect();
|
||||
}
|
||||
escPressed();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@@ -478,7 +566,7 @@ void Daemon::timerEvent(void * _d, int delim) {
|
||||
piForeachC (PIString & i, available_daemons)
|
||||
list_daemons->content << TileList::Row(i, CellFormat());
|
||||
screen->unlock();
|
||||
if (delim == 5 && mode == 2) {
|
||||
if (delim == 5 && mode == rmInformation) {
|
||||
if (conn_name.isEmpty()) return;
|
||||
PIByteArray ba; ba << int(RequestHostInfo);
|
||||
send(conn_name, ba);
|
||||
@@ -502,13 +590,13 @@ PIStringList Daemon::availableDaemons() {
|
||||
void Daemon::connectToDaemon(const PIString & dn) {
|
||||
if (dn.isEmpty()) return;
|
||||
conn_name = pisd_prefix + dn;
|
||||
mode = 1;
|
||||
mode = rmSelectMode;
|
||||
}
|
||||
|
||||
|
||||
void Daemon::disconnect() {
|
||||
conn_name.clear();
|
||||
mode = 0;
|
||||
mode = rmNone;
|
||||
showMainList();
|
||||
}
|
||||
|
||||
@@ -547,6 +635,7 @@ void Daemon::peerDisconnected(const PIString & p_name) {
|
||||
PIMutexLocker ml(remote_mutex);
|
||||
Remote * dt = remotes.value(p_name, 0);
|
||||
if (!dt) return;
|
||||
dt->shellClose();
|
||||
if (tile_file_progress->ft == &(dt->ft)) {
|
||||
tile_file_progress->close(false);
|
||||
}
|
||||
@@ -615,7 +704,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
Remote * r = remotes.value(from);
|
||||
PIString dir;
|
||||
int type; ba >> type;
|
||||
// piCout << "rec from " << from << type << r;
|
||||
//piCout << "rec from " << from << type << r;
|
||||
switch (type) {
|
||||
case RequestHostInfo:
|
||||
makeMyHostInfo();
|
||||
@@ -689,6 +778,32 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
r->cryptFiles(files);
|
||||
}
|
||||
break;
|
||||
case ShellOpen:
|
||||
if (!r) return;
|
||||
r->shellOpen();
|
||||
break;
|
||||
case ShellClose:
|
||||
if (!r) return;
|
||||
r->shellClose();
|
||||
break;
|
||||
case ShellContent: {
|
||||
if (!r) return;
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > cells;
|
||||
ba >> cells;
|
||||
tile_shell->setContent(cells);
|
||||
} break;
|
||||
case ShellResizeRequest: {
|
||||
if (!r) return;
|
||||
int w, h;
|
||||
ba >> w >> h;
|
||||
r->shellResize(w, h);
|
||||
} break;
|
||||
case ShellKeyEvent: {
|
||||
if (!r) return;
|
||||
PIKbdListener::KeyEvent k;
|
||||
ba >> k;
|
||||
r->shellKeySend(k);
|
||||
} break;
|
||||
};
|
||||
if (!rba.isEmpty()) send(from, rba);
|
||||
}
|
||||
@@ -703,6 +818,24 @@ void Daemon::sendDirToRemote(Remote * r) {
|
||||
}
|
||||
|
||||
|
||||
void Daemon::requestOpenShell() {
|
||||
Remote * r = remotes.value(conn_name, 0);
|
||||
if (!r) return;
|
||||
PIByteArray ba;
|
||||
ba << int(ShellOpen);
|
||||
send(conn_name, ba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::requestCloseShell() {
|
||||
Remote * r = remotes.value(conn_name, 0);
|
||||
if (!r) return;
|
||||
PIByteArray ba;
|
||||
ba << int(ShellClose);
|
||||
send(conn_name, ba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::makeMyHostInfo() {
|
||||
info_my.execCommand = PISystemInfo::instance()->execCommand;
|
||||
info_my.hostname = PISystemInfo::instance()->hostname;
|
||||
|
||||
Reference in New Issue
Block a user