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;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "pidatatransfer.h"
|
||||
#include "pifiletransfer.h"
|
||||
#include "file_manager.h"
|
||||
#include "terminal_tile.h"
|
||||
#include "piterminal.h"
|
||||
|
||||
extern PISystemMonitor sys_mon;
|
||||
|
||||
@@ -42,7 +44,7 @@ public:
|
||||
|
||||
void showMainList() {showTile(list_daemons, "Select daemon");}
|
||||
void showActionList() {showTile(list_actions, "Select action");}
|
||||
void showLocalFilemanager() {mode = 3; showTile(tile_fm, "File manager");}
|
||||
void showLocalFilemanager() {mode = rmFileManager; showTile(tile_fm, "File manager");}
|
||||
|
||||
PIStringList availableDaemons();
|
||||
void connectToDaemon(const PIString & dn);
|
||||
@@ -73,9 +75,23 @@ private:
|
||||
MkDir,
|
||||
CryptFiles,
|
||||
|
||||
FileTransfer = 30
|
||||
FileTransfer = 30,
|
||||
|
||||
ShellOpen = 40,
|
||||
ShellClose,
|
||||
ShellContent,
|
||||
ShellResizeRequest,
|
||||
ShellKeyEvent
|
||||
|
||||
};
|
||||
|
||||
enum RemoteMode {
|
||||
rmNone,
|
||||
rmSelectMode,
|
||||
rmInformation,
|
||||
rmFileManager,
|
||||
rmShell
|
||||
};
|
||||
|
||||
class Remote: public PIThread {
|
||||
PIOBJECT_SUBCLASS(Remote, PIThread)
|
||||
@@ -87,6 +103,10 @@ private:
|
||||
void updateDir() {startAction(Daemon::RequestChangeDir, PIString(), PIStringList());}
|
||||
void makeDir(const PIString & dir) {startAction(Daemon::MkDir, dir, PIStringList() << "");}
|
||||
void cryptFiles(const PIStringList & fl) {startAction(Daemon::CryptFiles, PIString(), fl);}
|
||||
void shellOpen();
|
||||
void shellClose();
|
||||
void shellResize(int w, int h);
|
||||
void shellKeySend(PIKbdListener::KeyEvent k);
|
||||
EVENT_HANDLER1(void, ftSendRequest, PIByteArray &, data) {PIByteArray h; h << int(FileTransfer); data.insert(0, h); sendRequest(name(), data);}
|
||||
EVENT_HANDLER1(void, ftReceived, bool, ok) {receiveFinished(name(), ok);}
|
||||
EVENT_HANDLER1(void, ftSended, bool, ok) {sendFinished(name(), ok);}
|
||||
@@ -96,6 +116,7 @@ private:
|
||||
EVENT2(sendFinished, const PIString & , p_name, bool, ok)
|
||||
EVENT2(changeDirFinished, const PIString & , p_name, const PIString & , dir)
|
||||
EVENT_HANDLER1(void, received, PIByteArray & , data) {ft.received(data);}
|
||||
EVENT_HANDLER(void, termTimerTick);
|
||||
|
||||
void startAction(PacketType a, const PIString & dir, const PIStringList & fl);
|
||||
void run();
|
||||
@@ -105,6 +126,8 @@ private:
|
||||
PIFileTransfer ft;
|
||||
PIStringList _fl;
|
||||
PacketType action;
|
||||
PITimer term_timer;
|
||||
PITerminal * term;
|
||||
|
||||
private:
|
||||
void updateDirEntries();
|
||||
@@ -134,11 +157,16 @@ private:
|
||||
EVENT_HANDLER2(void, sendRequest, const PIString &, p_name, const PIByteArray &, data) {send(p_name, data);}
|
||||
EVENT_HANDLER1(void, fmKeyEvent, PIKbdListener::KeyEvent, key);
|
||||
EVENT_HANDLER3(void, fmActionRequest, bool, remote_tile, FileManager::Action, type, PIVariant, data);
|
||||
EVENT_HANDLER (void, shResizeRequest);
|
||||
EVENT_HANDLER1(void, shKeyEvent, PIKbdListener::KeyEvent, k);
|
||||
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
||||
EVENT_HANDLER2(void, filesReceived, const PIString & , p_name, bool, ok);
|
||||
EVENT_HANDLER2(void, dirChanged, const PIString & , p_name, const PIString & , dir);
|
||||
EVENT_HANDLER2(void, closeFileDialog, const PIString & , p_name, bool, ok);
|
||||
EVENT_HANDLER2(void, localSend, const PIString & , p_name, const PIByteArray &, data);
|
||||
EVENT_HANDLER (void, escPressed);
|
||||
EVENT_HANDLER (void, requestOpenShell);
|
||||
EVENT_HANDLER (void, requestCloseShell);
|
||||
EVENT(menuRequest)
|
||||
void hideAll();
|
||||
void showTile(PIScreenTile * t, const PIString & header = PIString());
|
||||
@@ -163,9 +191,11 @@ private:
|
||||
TileSimple * tile_info, * tile_header;
|
||||
TileList * list_daemons, * list_actions;
|
||||
TileFileProgress * tile_file_progress;
|
||||
TileTerminal * tile_shell;
|
||||
PIFileTransfer localft;
|
||||
Remote * _self;
|
||||
int mode, offset, cur, height;
|
||||
RemoteMode mode;
|
||||
int offset, cur, height;
|
||||
bool inited__;
|
||||
};
|
||||
|
||||
|
||||
@@ -201,9 +201,9 @@ void FileManager::TileDir::buildNames() {
|
||||
scol = scol.expandRightTo(9, ' ') + "| " + e.time_modification.toString("dd.MM hh:mm:ss") + " | "
|
||||
+ e.perm_user.toString() + " " + e.perm_group.toString() + " " + e.perm_other.toString();
|
||||
fcol = t + e.name();
|
||||
if (fcol.size_s() >= width - 2 - scol.size_s())
|
||||
fcol = fcol.left(width - 5 - scol.size_s()) + "...";
|
||||
fcol.expandRightTo(width - 1 - scol.size_s(), ' ');
|
||||
if (fcol.size_s() >= width_ - 2 - scol.size_s())
|
||||
fcol = fcol.left(width_ - 5 - scol.size_s()) + "...";
|
||||
fcol.expandRightTo(width_ - 1 - scol.size_s(), ' ');
|
||||
content << Row(fcol + scol, CellFormat(cc, Transparent, cf));
|
||||
}
|
||||
unlock();
|
||||
|
||||
44
utils/system_daemon/terminal_tile.cpp
Normal file
44
utils/system_daemon/terminal_tile.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "terminal_tile.h"
|
||||
#include "piscreendrawer.h"
|
||||
|
||||
|
||||
TileTerminal::TileTerminal(const PIString & n): PIScreenTile(n) {
|
||||
focus_flags = PIScreenTypes::CanHasFocus;
|
||||
size_policy = PIScreenTypes::Expanding;
|
||||
lastp[0] = lastp[1] = lastp[2] = 0;
|
||||
}
|
||||
|
||||
|
||||
void TileTerminal::drawEvent(PIScreenDrawer * d) {
|
||||
//piCout << "draw" << visible;
|
||||
//PIVector<PIVector<PIScreenTypes::Cell> > c = term->content();
|
||||
d->fillRect(x_, y_, x_ + width_, y_ + height_, cells);
|
||||
}
|
||||
|
||||
|
||||
bool TileTerminal::keyEvent(PIKbdListener::KeyEvent key) {
|
||||
lastp[0] = lastp[1];
|
||||
lastp[1] = lastp[2];
|
||||
lastp[2] = char(key.key);
|
||||
if (lastp[0] == '\e' && lastp[1] == '~' && lastp[2] == '.') {
|
||||
closeRequest();
|
||||
return true;
|
||||
}
|
||||
//piCout << "key";
|
||||
/*if (!term) return false;
|
||||
if (PITerminal::isSpecialKey(key.key)) term->write((PIKbdListener::SpecialKey)key.key, key.modifiers);
|
||||
else {
|
||||
PIByteArray ba;
|
||||
ba << PIChar(key.key).toConcole1Byte();
|
||||
term->write(ba);
|
||||
}*/
|
||||
keyPressed(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TileTerminal::resizeEvent(int w, int h) {
|
||||
/*if (!term) return;
|
||||
term->resize(w, h);*/
|
||||
resizeRequest();
|
||||
}
|
||||
30
utils/system_daemon/terminal_tile.h
Normal file
30
utils/system_daemon/terminal_tile.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef TERMINAL_TILE_H
|
||||
#define TERMINAL_TILE_H
|
||||
|
||||
#include "piscreentile.h"
|
||||
#include "pikbdlistener.h"
|
||||
|
||||
|
||||
class TileTerminal: public PIScreenTile {
|
||||
PIOBJECT_SUBCLASS(TileTerminal, PIScreenTile)
|
||||
public:
|
||||
TileTerminal(const PIString & n);
|
||||
|
||||
void setContent(const PIVector<PIVector<PIScreenTypes::Cell> > & c) {cells = c;}
|
||||
|
||||
EVENT(resizeRequest)
|
||||
EVENT1(keyPressed, PIKbdListener::KeyEvent, k)
|
||||
EVENT(closeRequest)
|
||||
|
||||
private:
|
||||
void drawEvent(PIScreenDrawer * d);
|
||||
bool keyEvent(PIKbdListener::KeyEvent key);
|
||||
void resizeEvent(int w, int h);
|
||||
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > cells;
|
||||
char lastp[3];
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // TERMINAL_TILE_H
|
||||
Reference in New Issue
Block a user