git-svn-id: svn://db.shs.com.ru/pip@94 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
137 lines
3.9 KiB
C++
137 lines
3.9 KiB
C++
#include "shared.h"
|
|
|
|
extern PIScreen screen;
|
|
|
|
|
|
class DlgWatcher: public PIThread {
|
|
PIOBJECT(DlgWatcher)
|
|
public:
|
|
DlgWatcher() {close = ok = false;}
|
|
EVENT_HANDLER2(void, tileEvent, PIScreenTile * , tile, PIScreenTypes::TileEvent, e) {
|
|
if (e.type == TileButtons::ButtonSelected) {
|
|
ok = e.data.toInt() == 0;
|
|
close = true;
|
|
}
|
|
}
|
|
EVENT_HANDLER1(void, keyPressed, PIKbdListener::KeyEvent, key) {
|
|
if (key.key == PIKbdListener::Return) {
|
|
ok = true;
|
|
close = true;
|
|
}
|
|
if (key.key == PIKbdListener::Esc) {
|
|
ok = false;
|
|
close = true;
|
|
}
|
|
}
|
|
bool ok;
|
|
bool close;
|
|
};
|
|
|
|
|
|
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);
|
|
dlg.spacing = 1;
|
|
dlg.back_format.color_back = Yellow;
|
|
TileSimple * lbl = new TileSimple();
|
|
TileInput * input = new TileInput();
|
|
TileButtons * btns = new TileButtons();
|
|
lbl->back_format.color_back = Yellow;
|
|
btns->back_format.color_back = Yellow;
|
|
lbl->content << TileSimple::Row("Enter new directory name:", CellFormat(Black, Transparent));
|
|
btns->content << TileButtons::Button(" Ok ", CellFormat());
|
|
btns->content << TileButtons::Button("Cancel", CellFormat());
|
|
dlg.addTile(lbl);
|
|
dlg.addTile(input);
|
|
dlg.addTile(btns);
|
|
DlgWatcher w;
|
|
CONNECTU(&screen, keyPressed, &w, keyPressed)
|
|
CONNECTU(&screen, tileEvent, &w, tileEvent)
|
|
screen.setDialogTile(&dlg);
|
|
while (!w.close) {
|
|
PIKbdListener::instance()->readKeyboard();
|
|
piMSleep(10);
|
|
}
|
|
if (!w.ok) return PIString();
|
|
return input->text;
|
|
}
|
|
|
|
|
|
bool askQuestion(const PIString & t) {
|
|
PIScreenTile dlg;
|
|
dlg.setMargins(1, 1, 1, 1);
|
|
dlg.spacing = 1;
|
|
dlg.back_format.color_back = Yellow;
|
|
TileSimple * lbl = new TileSimple();
|
|
TileButtons * btns = new TileButtons();
|
|
lbl->back_format.color_back = Yellow;
|
|
btns->back_format.color_back = Yellow;
|
|
lbl->content << TileSimple::Row(t, CellFormat(Black, Transparent));
|
|
btns->content << TileButtons::Button(" Ok ", CellFormat());
|
|
btns->content << TileButtons::Button("Cancel", CellFormat());
|
|
dlg.addTile(lbl);
|
|
dlg.addTile(btns);
|
|
DlgWatcher w;
|
|
CONNECTU(&screen, keyPressed, &w, keyPressed)
|
|
CONNECTU(&screen, tileEvent, &w, tileEvent)
|
|
screen.setDialogTile(&dlg);
|
|
while (!w.close) {
|
|
PIKbdListener::instance()->readKeyboard();
|
|
piMSleep(10);
|
|
}
|
|
return w.ok;
|
|
}
|
|
|
|
|
|
void showInfo(const PIString & t) {
|
|
PIScreenTile dlg;
|
|
dlg.setMargins(1, 1, 1, 1);
|
|
dlg.spacing = 1;
|
|
dlg.back_format.color_back = Yellow;
|
|
TileSimple * lbl = new TileSimple();
|
|
TileButtons * btns = new TileButtons();
|
|
lbl->back_format.color_back = Yellow;
|
|
btns->back_format.color_back = Yellow;
|
|
lbl->content << TileSimple::Row(t, CellFormat(Black, Transparent));
|
|
btns->content << TileButtons::Button(" Ok ", CellFormat());
|
|
dlg.addTile(lbl);
|
|
dlg.addTile(btns);
|
|
DlgWatcher w;
|
|
CONNECTU(&screen, keyPressed, &w, keyPressed)
|
|
CONNECTU(&screen, tileEvent, &w, tileEvent)
|
|
screen.setDialogTile(&dlg);
|
|
while (!w.close) {
|
|
PIKbdListener::instance()->readKeyboard();
|
|
piMSleep(10);
|
|
}
|
|
}
|
|
|
|
|
|
void removeFiles(const PIDir & dir, PIStringList l) {
|
|
l.removeOne("..");
|
|
PIString ap = dir.absolutePath();
|
|
//piCout << "remove from" << ap;
|
|
piForeachC (PIString & s, l) {
|
|
PIFile::FileInfo fi = PIFile::fileInfo(ap + PIDir::separator + s);
|
|
if (fi.isDir()) {
|
|
PIVector<PIFile::FileInfo> el = PIDir::allEntries(fi.path);
|
|
piForeachCR (PIFile::FileInfo & e, el) {
|
|
//piCout << "remove" << e.path;
|
|
PIFile::remove(e.path);
|
|
}
|
|
}
|
|
//piCout << "remove" << fi.path;
|
|
PIFile::remove(fi.path);
|
|
}
|
|
}
|