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:
2015-04-11 14:13:03 +00:00
parent b82453d845
commit 493d8ba0c7
8 changed files with 151 additions and 43 deletions

View File

@@ -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;
piForeach (PIString & s, _fl)
s.prepend(dir);
piCout << "send" << _fl;
if (!dir.isEmpty())
piForeach (PIString & s, _fl)
s.prepend(dir);
//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,16 +575,21 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
if (r) r->received(ba);
break;
};
if (answer_dirs) {
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);
}
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();
PIByteArray ba;
ba << int(ReplyChangeDir) << r->dir_my.absolutePath() << fil;
send(r->name(), ba);
}
void Daemon::makeMyHostInfo() {
info_my.execCommand = PISystemInfo::instance()->execCommand;
info_my.hostname = PISystemInfo::instance()->hostname;

View File

@@ -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;

View File

@@ -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);

View File

@@ -7,6 +7,8 @@
using namespace PIScreenTypes;
PIString readableTime(const PITime & t);
PIString askNewDir();
bool askQuestion(const PIString & t);
void showInfo(const PIString & t);