PIScreen windows optimization, expanded pisd copy dialog
git-svn-id: svn://db.shs.com.ru/pip@90 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -162,14 +162,11 @@ void PIScreen::SystemConsole::resize(int w, int h) {
|
||||
pcells[i].resize(width, Cell(0));
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
PRIVATE->bs.X = width;
|
||||
PRIVATE->bs.Y = height;
|
||||
PRIVATE->sbi.srWindow = PRIVATE->csbi.srWindow;
|
||||
PRIVATE->chars.resize(width * height);
|
||||
#else
|
||||
#endif
|
||||
for (int i = 0; i < pcells.size_s(); ++i)
|
||||
pcells[i].fill(Cell());
|
||||
#endif
|
||||
clear();
|
||||
clearScreen();
|
||||
}
|
||||
@@ -177,16 +174,44 @@ void PIScreen::SystemConsole::resize(int w, int h) {
|
||||
|
||||
void PIScreen::SystemConsole::print() {
|
||||
#ifdef WINDOWS
|
||||
static int cnt = 0;
|
||||
for (int i = 0; i < width; ++i)
|
||||
//static int cnt = 0;
|
||||
PRIVATE->srect = PRIVATE->sbi.srWindow;
|
||||
int dx0 = -1, dx1 = -1, dy0 = -1, dy1 = -1;
|
||||
for (int j = 0; j < height; ++j) {
|
||||
int k = j * width + i;
|
||||
Cell & c(cells[j][i]);
|
||||
PIVector<Cell> & ccv(cells[j]);
|
||||
PIVector<Cell> & pcv(pcells[j]);
|
||||
for (int i = 0; i < width; ++i)
|
||||
if (ccv[i] != pcv[i]) {
|
||||
if (dx0 < 0) {
|
||||
dx0 = dx1 = i;
|
||||
dy0 = dy1 = j;
|
||||
} else {
|
||||
dx0 = piMini(dx0, i);
|
||||
dx1 = piMaxi(dx1, i);
|
||||
dy0 = piMini(dy0, j);
|
||||
dy1 = piMaxi(dy1, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dx0 < 0) return;
|
||||
int dw = dx1 - dx0 + 1, dh = dy1 - dy0 + 1;
|
||||
for (int i = 0; i < dw; ++i)
|
||||
for (int j = 0; j < dh; ++j) {
|
||||
int k = j * dw + i;
|
||||
Cell & c(cells[j + dy0][i + dx0]);
|
||||
PRIVATE->chars[k].Char.UnicodeChar = 0;
|
||||
PRIVATE->chars[k].Char.AsciiChar = c.symbol.toAscii();
|
||||
PRIVATE->chars[k].Attributes = attributes(c);
|
||||
}
|
||||
PRIVATE->srect = PRIVATE->sbi.srWindow;
|
||||
//PRIVATE->bc.X = dx0;
|
||||
//PRIVATE->bc.Y = dy0;
|
||||
//piCout << "draw" << dw << dh;
|
||||
PRIVATE->bs.X = dw;
|
||||
PRIVATE->bs.Y = dh;
|
||||
PRIVATE->srect.Left += dx0;
|
||||
PRIVATE->srect.Top += dy0;
|
||||
PRIVATE->srect.Right -= width - dx1 - 1;
|
||||
PRIVATE->srect.Bottom -= height - dy1 - 1;
|
||||
WriteConsoleOutput(PRIVATE->hOut, PRIVATE->chars.data(), PRIVATE->bs, PRIVATE->bc, &PRIVATE->srect);
|
||||
#else
|
||||
PIString s;
|
||||
@@ -226,11 +251,10 @@ void PIScreen::SystemConsole::print() {
|
||||
printf("%s", (formatString(cells[j][i]) + cells[j][i].symbol).data());
|
||||
}*/
|
||||
}
|
||||
for (int i = 0; i < height; ++i)
|
||||
pcells[i] = cells[i];
|
||||
printf("\e[0m");
|
||||
fflush(0);
|
||||
#endif
|
||||
pcells = cells;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -159,6 +159,18 @@ PITime PITime::current() {
|
||||
}
|
||||
|
||||
|
||||
PITime PITime::fromSystemTime(const PISystemTime & st) {
|
||||
double s = st.toSeconds();
|
||||
int v = s;
|
||||
PITime ret;
|
||||
ret.milliseconds = (s - v) * 1000;
|
||||
ret.seconds = v % 60; v = (v - ret.seconds) / 60;
|
||||
ret.minutes = v % 60; v = (v - ret.minutes) / 60;
|
||||
ret.hours = v;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIDate PIDate::current() {
|
||||
time_t rt = ::time(0);
|
||||
tm * pt = localtime(&rt);
|
||||
|
||||
@@ -190,6 +190,7 @@ struct PIP_EXPORT PITime {
|
||||
int milliseconds;
|
||||
PIString toString(const PIString & format = "h:mm:ss") const;
|
||||
static PITime current();
|
||||
static PITime fromSystemTime(const PISystemTime & st);
|
||||
};
|
||||
PIP_EXPORT bool operator ==(const PITime & t0, const PITime & t1);
|
||||
PIP_EXPORT bool operator <(const PITime & t0, const PITime & t1);
|
||||
|
||||
@@ -48,9 +48,9 @@ PIPeer::PeerData::~PeerData() {
|
||||
|
||||
|
||||
void PIPeer::PeerData::dtThread() {
|
||||
piCoutObj << "send DT ...";
|
||||
//piCoutObj << "send DT ...";
|
||||
dt_out.send(data);
|
||||
piCoutObj << "send DT done";
|
||||
//piCoutObj << "send DT done";
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ void PIPeer::PeerData::receivedPacket(uchar type, const PIByteArray & d) {
|
||||
dt = &dt_in;
|
||||
if (type == 2)
|
||||
dt = &dt_out;
|
||||
piCoutObj << "DT received" << int(type) << d.size_s();
|
||||
//piCoutObj << "DT received" << int(type) << d.size_s();
|
||||
if (dt) dt->received(d);
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ bool PIPeer::sendInternal(const PIString & to, const PIByteArray & data) {
|
||||
}
|
||||
PIByteArray ba;
|
||||
ba << int(4) << self_info.name << to << int(0) << data;
|
||||
piCoutObj << "sendInternal" << to << data.size_s() << int(data.front());
|
||||
//piCoutObj << "sendInternal" << to << data.size_s() << int(data.front());
|
||||
if (!sendToNeighbour(dp, ba)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,17 +23,29 @@ Daemon::Remote::~Remote() {
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::sendFiles(const PIString & dir, const PIStringList & fl) {
|
||||
void Daemon::Remote::startAction(Daemon::PacketType a, const PIString & dir, const PIStringList & fl) {
|
||||
_fl = fl;
|
||||
if (!dir.isEmpty())
|
||||
piForeach (PIString & s, _fl)
|
||||
s.prepend(dir);
|
||||
piCout << "send" << _fl;
|
||||
//piCout << "send" << _fl;
|
||||
action = a;
|
||||
startOnce();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::Remote::run() {
|
||||
ft.send(_fl);
|
||||
switch (action) {
|
||||
case CopyFiles: ft.send(_fl); break;
|
||||
case RemoveFiles:
|
||||
{
|
||||
PIDir d(dir_my);
|
||||
::removeFiles(d, _fl);
|
||||
removeFinished(name(), d.absolutePath());
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -45,20 +57,23 @@ Daemon::TileFileProgress::TileFileProgress(): PIScreenTile() {
|
||||
setMargins(1, 1, 1, 1);
|
||||
spacing = 1;
|
||||
back_format.color_back = Yellow;
|
||||
label_file = new TileSimple("");
|
||||
label_speed = new TileSimple("");
|
||||
label_file = new TileSimple();
|
||||
label_speed = new TileSimple();
|
||||
label_cnt = new TileSimple();
|
||||
prog_file = new TileProgress();
|
||||
prog_all = new TileProgress();
|
||||
buttons = new TileButtons("fd_buttons");
|
||||
buttons->content << TileButtons::Button("Pause", CellFormat());
|
||||
buttons->content << TileButtons::Button("Cancel", CellFormat());
|
||||
buttons->back_format.color_back = label_file->back_format.color_back = label_speed->back_format.color_back = Yellow;
|
||||
label_file->back_format.color_char = label_speed->back_format.color_char = Black;
|
||||
label_file->content.resize(1);
|
||||
label_speed->content.resize(1);
|
||||
label_file->content[0].second = label_speed->content[0].second = CellFormat(Black, Transparent);
|
||||
label_cnt->content.resize(1);
|
||||
buttons->back_format.color_back = Yellow;
|
||||
label_file->back_format.color_back = label_speed->back_format.color_back = label_cnt->back_format.color_back = Yellow;
|
||||
label_file->content[0].second = label_speed->content[0].second = label_cnt->content[0].second = CellFormat(Black, Transparent);
|
||||
addTile(label_file);
|
||||
addTile(label_speed);
|
||||
addTile(label_cnt);
|
||||
addTile(prog_file);
|
||||
addTile(prog_all);
|
||||
addTile(buttons);
|
||||
@@ -84,10 +99,29 @@ void Daemon::TileFileProgress::drawEvent(PIScreenDrawer * d) {
|
||||
label_file->content[0].first = ft->stateString() + " " + ft->curFile();
|
||||
if (!label_file->content[0].first.isEmpty())
|
||||
label_file->content[0].first[0] = label_file->content[0].first[0].toUpper();
|
||||
PIString spd;
|
||||
PIString spd("Speed: "), cnt;
|
||||
if (ft->isReceiving()) spd = ft->diagnostic().receiveSpeed();
|
||||
else spd = ft->diagnostic().sendSpeed();
|
||||
else spd = ft->diagnostic().sendSpeed().expandRightTo(10, ' ');
|
||||
spd += " ETA: ";
|
||||
if (!ft->isReceiving() && !ft->isSending()) {
|
||||
tm.reset();
|
||||
spd += "-";
|
||||
} else {
|
||||
double el = tm.elapsed_s();
|
||||
int cb = ft->bytesCur();
|
||||
if ((el <= 0.) || (cb <= 0)) spd += "-";
|
||||
else {
|
||||
double s = (el / cb) * (ft->bytesAll() - cb);
|
||||
spd += readableTime(PITime::fromSystemTime(PISystemTime::fromSeconds(s)));
|
||||
}
|
||||
}
|
||||
spd += " Elapsed: " + readableTime(PITime::fromSystemTime(PISystemTime::fromSeconds(tme.elapsed_s())));
|
||||
label_speed->content[0].first = spd;
|
||||
cnt = "File: " + PIString::readableSize(ft->bytesFileCur()).expandLeftTo(8, ' ');
|
||||
cnt += " / " + PIString::readableSize(ft->bytesFileAll()).expandLeftTo(8, ' ');
|
||||
cnt += " All: " + PIString::readableSize(ft->bytesCur()).expandLeftTo(8, ' ');
|
||||
cnt += " / " + PIString::readableSize(ft->bytesAll()).expandLeftTo(8, ' ');
|
||||
label_cnt->content[0].first = cnt;
|
||||
if (ft->bytesFileAll() > 0)
|
||||
prog_file->value = piRoundd(ft->bytesFileCur() / double(ft->bytesFileAll()) * 100.);
|
||||
if (ft->bytesAll() > 0)
|
||||
@@ -104,6 +138,8 @@ void Daemon::TileFileProgress::show(PIFileTransfer * f) {
|
||||
::screen.setDialogTile(this);
|
||||
buttons->cur = 0;
|
||||
buttons->setFocus();
|
||||
tm.reset();
|
||||
tme.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,6 +446,7 @@ void Daemon::peerConnected(const PIString & name) {
|
||||
CONNECTU(r, receiveFinished, this, filesReceived)
|
||||
CONNECTU(r, receiveFinished, this, closeFileDialog)
|
||||
CONNECTU(r, sendFinished, this, closeFileDialog)
|
||||
CONNECTU(r, removeFinished, this, filesRemoved)
|
||||
remotes.insert(name, r);
|
||||
}
|
||||
|
||||
@@ -433,6 +470,14 @@ void Daemon::filesReceived(const PIString & name, bool ok) {
|
||||
}
|
||||
|
||||
|
||||
void Daemon::filesRemoved(const PIString & name, const PIString & dir) {
|
||||
Remote * r = remotes.value(name, 0);
|
||||
if (!r) return;
|
||||
if (r->dir_my.absolutePath() != dir) return;
|
||||
sendDirToRemote(r);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::closeFileDialog(const PIString & name, bool ok) {
|
||||
//piCout << "CLOSE" << tile_file_progress->conn_name << name << ok;
|
||||
if (tile_file_progress->conn_name != name) return;
|
||||
@@ -458,7 +503,6 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
Remote * r(0);
|
||||
PIString dir;
|
||||
int type; ba >> type;
|
||||
bool answer_dirs = false;
|
||||
//piCout << "rec from " << from << type;
|
||||
switch (type) {
|
||||
case RequestHostInfo:
|
||||
@@ -472,8 +516,8 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
r->dir_my.cd(dir);
|
||||
r->ft.setDirectory(r->dir_my);
|
||||
piCout << "store to" << r->dir_my.absolutePath();
|
||||
answer_dirs = true;
|
||||
piCout << "cd to" << dir << ", abs =" << r->dir_my.absolutePath();
|
||||
sendDirToRemote(r);
|
||||
break;
|
||||
case ReplyHostInfo:
|
||||
ba >> info_other;
|
||||
@@ -495,6 +539,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
case CopyFiles:
|
||||
r = remotes.value(from);
|
||||
if (!r) return;
|
||||
if (r->isRunning()) return;
|
||||
{
|
||||
PIStringList files;
|
||||
ba >> files;
|
||||
@@ -505,12 +550,13 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
case RemoveFiles:
|
||||
r = remotes.value(from);
|
||||
if (!r) return;
|
||||
if (r->isRunning()) return;
|
||||
{
|
||||
PIStringList files;
|
||||
ba >> files;
|
||||
//piCout << "send" << files << "from" << r->dir_my.absolutePath();
|
||||
removeFiles(r->dir_my, files);
|
||||
answer_dirs = true;
|
||||
r->removeFiles(files);
|
||||
//answer_dirs = true;
|
||||
}
|
||||
break;
|
||||
case MkDir:
|
||||
@@ -521,7 +567,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
ba >> dn;
|
||||
//piCout << "send" << files << "from" << r->dir_my.absolutePath();
|
||||
PIDir::make(r->dir_my.absolutePath() + PIDir::separator + dn);
|
||||
answer_dirs = true;
|
||||
sendDirToRemote(r);
|
||||
}
|
||||
break;
|
||||
case FileTransfer:
|
||||
@@ -529,13 +575,18 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
if (r) r->received(ba);
|
||||
break;
|
||||
};
|
||||
if (answer_dirs) {
|
||||
if (!rba.isEmpty()) send(from, rba);
|
||||
}
|
||||
|
||||
|
||||
void Daemon::sendDirToRemote(Remote * r) {
|
||||
if (!r) return;
|
||||
PIVector<PIFile::FileInfo> fil = r->dir_my.entries();
|
||||
piForeach (PIFile::FileInfo & f, fil)
|
||||
f.path = f.name();
|
||||
rba << int(ReplyChangeDir) << r->dir_my.absolutePath() << fil;
|
||||
}
|
||||
if (!rba.isEmpty()) send(from, rba);
|
||||
PIByteArray ba;
|
||||
ba << int(ReplyChangeDir) << r->dir_my.absolutePath() << fil;
|
||||
send(r->name(), ba);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +72,8 @@ private:
|
||||
public:
|
||||
Remote(const PIString & n = PIString());
|
||||
~Remote();
|
||||
void sendFiles(const PIString & dir, const PIStringList & fl);
|
||||
void sendFiles(const PIString & dir, const PIStringList & fl) {startAction(Daemon::CopyFiles, dir, fl);}
|
||||
void removeFiles(const PIStringList & fl) {startAction(Daemon::RemoveFiles, PIString(), fl);}
|
||||
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);}
|
||||
@@ -80,12 +81,16 @@ private:
|
||||
EVENT2(sendRequest, const PIString & , name, const PIByteArray &, data)
|
||||
EVENT2(receiveFinished, const PIString & , name, bool, ok)
|
||||
EVENT2(sendFinished, const PIString & , name, bool, ok)
|
||||
EVENT2(removeFinished, const PIString & , name, const PIString & , dir)
|
||||
EVENT_HANDLER1(void, received, const PIByteArray & , data) {ft.received(data);}
|
||||
|
||||
void startAction(PacketType a, const PIString & dir, const PIStringList & fl);
|
||||
void run();
|
||||
|
||||
PIDir dir_my, dir_remote;
|
||||
PIFileTransfer ft;
|
||||
PIStringList _fl;
|
||||
void run();
|
||||
PacketType action;
|
||||
};
|
||||
|
||||
class TileFileProgress: public PIScreenTile {
|
||||
@@ -94,10 +99,11 @@ private:
|
||||
TileFileProgress();
|
||||
void show(PIFileTransfer * f);
|
||||
void close(bool ok = true);
|
||||
TileSimple * label_file, * label_speed;
|
||||
TileSimple * label_file, * label_speed, * label_cnt;
|
||||
TileProgress * prog_file, * prog_all;
|
||||
TileButtons * buttons;
|
||||
PIFileTransfer * ft;
|
||||
PITimeMeasurer tm, tme;
|
||||
void resizeEvent(int w, int h);
|
||||
void sizeHint(int & w, int & h) const;
|
||||
void drawEvent(PIScreenDrawer * d);
|
||||
@@ -113,6 +119,7 @@ private:
|
||||
EVENT_HANDLER3(void, fmActionRequest, bool, remote_tile, FileManager::Action, type, PIVariant, data);
|
||||
EVENT_HANDLER2(void, timerEvent, void * , _d, int, delim);
|
||||
EVENT_HANDLER2(void, filesReceived, const PIString & , name, bool, ok);
|
||||
EVENT_HANDLER2(void, filesRemoved, const PIString & , name, const PIString & , dir);
|
||||
EVENT_HANDLER2(void, closeFileDialog, const PIString & , name, bool, ok);
|
||||
EVENT(menuRequest);
|
||||
void hideAll();
|
||||
@@ -125,6 +132,7 @@ private:
|
||||
void makeOtherHostInfo();
|
||||
|
||||
void requestChDir(const PIString & d);
|
||||
void sendDirToRemote(Remote * r);
|
||||
|
||||
mutable PIStringList available_daemons;
|
||||
PITimer timer;
|
||||
|
||||
@@ -28,6 +28,16 @@ public:
|
||||
};
|
||||
|
||||
|
||||
PIString readableTime(const PITime & t) {
|
||||
PIString ret;
|
||||
bool pt = false;
|
||||
if (t.hours > 0) {ret += PIString::fromNumber(t.hours).expandLeftTo(2, '0') + " h "; pt = true;}
|
||||
if ((t.minutes > 0) || pt) {ret += PIString::fromNumber(t.minutes).expandLeftTo(2, '0') + " m "; pt = true;}
|
||||
if ((t.seconds > 0) || pt) ret += PIString::fromNumber(t.seconds).expandLeftTo(2, '0') + " s";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString askNewDir() {
|
||||
PIScreenTile dlg;
|
||||
dlg.setMargins(1, 1, 1, 1);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
using namespace PIScreenTypes;
|
||||
|
||||
PIString readableTime(const PITime & t);
|
||||
|
||||
PIString askNewDir();
|
||||
bool askQuestion(const PIString & t);
|
||||
void showInfo(const PIString & t);
|
||||
|
||||
Reference in New Issue
Block a user