version 0.5.0_alpha
git-svn-id: svn://db.shs.com.ru/pip@8 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Remote console viewer
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2015 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -24,57 +24,117 @@
|
||||
#include "daemon.h"
|
||||
#include "shared.h"
|
||||
|
||||
void key_event(char key, void * );
|
||||
|
||||
class _Init {
|
||||
public:
|
||||
_Init() {srand(PISystemTime::current().toMicroseconds());}
|
||||
};
|
||||
_Init _pisd_init;
|
||||
|
||||
PIConsole console(false, key_event);
|
||||
PIScreen screen(false);
|
||||
PISystemMonitor sys_mon;
|
||||
FileManager file_manager;
|
||||
Daemon daemon_;
|
||||
int mode = 0, oldmode = -1;
|
||||
|
||||
class MenuOperator: public PIObject {
|
||||
PIOBJECT(MenuOperator)
|
||||
|
||||
class MainMenu: public PIObject {
|
||||
PIOBJECT(MainMenu)
|
||||
public:
|
||||
MenuOperator() {
|
||||
MainMenu() {
|
||||
TileSimple * tile = new TileSimple("title");
|
||||
tile->content << TileSimple::Row("pisd (PI System Daemon, PIP version " + PIPVersion() + ")", CellFormat(Black, Transparent));
|
||||
tile->back_format.color_back = Yellow;
|
||||
tile->size_policy = Fixed;
|
||||
screen.rootTile()->addTile(tile);
|
||||
|
||||
PIScreenTile * center = new PIScreenTile("center");
|
||||
center->back_format.color_back = Cyan;
|
||||
center->size_policy = Expanding;
|
||||
center->setMargins(2, 2, 1, 1);
|
||||
screen.rootTile()->addTile(center);
|
||||
|
||||
PIScreenTile * mt = tmenu = menuTile();
|
||||
mt->show(); mt->name = "main menu";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tinfo = infoTile();
|
||||
mt->hide(); mt->name = "local info";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tfm = file_manager.tile();
|
||||
mt->hide(); mt->name = "file manager";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
mt = tdaemon = daemon_.tile();
|
||||
mt->hide(); mt->name = "daemon";
|
||||
center->addTile(mt); mtiles << mt;
|
||||
|
||||
CONNECTU(&screen, tileEvent, this, tileEvent)
|
||||
CONNECTU(&screen, keyPressed, this, keyEvent)
|
||||
CONNECTU(&file_manager, menuRequest, this, menuRequest)
|
||||
CONNECTU(&daemon_, menuRequest, this, menuRequest)
|
||||
}
|
||||
EVENT_HANDLER(void, menuRequest) {mode = 0;}
|
||||
};
|
||||
|
||||
MenuOperator menu_operator;
|
||||
|
||||
void key_event(char key, void * ) {
|
||||
if (key == PIKbdListener::Esc) {
|
||||
;//mode = 0;
|
||||
} else {
|
||||
if (mode != 3) {
|
||||
if (key < '0' || key > '9') return;
|
||||
mode = key - '0';
|
||||
PIScreenTile * menuTile() {
|
||||
TileList * ret = new TileList();
|
||||
ret->content << TileList::Row("Show local info", CellFormat());
|
||||
ret->content << TileList::Row("Local file manager", CellFormat());
|
||||
ret->content << TileList::Row("Connect to another daemon", CellFormat());
|
||||
ret->selection_mode = TileList::NoSelection;
|
||||
return ret;
|
||||
}
|
||||
PIScreenTile * infoTile() {
|
||||
TileSimple * ret = new TileSimple();
|
||||
ret->content << TileSimple::Row("Exec command: " + PISystemInfo::instance()->execCommand, CellFormat());
|
||||
ret->content << TileSimple::Row(" Executed on " + PISystemInfo::instance()->execDateTime.toString(), CellFormat());
|
||||
ret->content << TileSimple::Row(" Hostname: " + PISystemInfo::instance()->hostname, CellFormat());
|
||||
ret->content << TileSimple::Row(" Username: " + PISystemInfo::instance()->user, CellFormat());
|
||||
ret->content << TileSimple::Row(" OS name: " + PISystemInfo::instance()->OS_name, CellFormat());
|
||||
ret->content << TileSimple::Row(" OS version: " + PISystemInfo::instance()->OS_version, CellFormat());
|
||||
ret->content << TileSimple::Row("Architecture: " + PISystemInfo::instance()->architecture, CellFormat());
|
||||
ret->content << TileSimple::Row(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount), CellFormat());
|
||||
return ret;
|
||||
}
|
||||
EVENT_HANDLER(void, menuRequest) {
|
||||
piForeach (PIScreenTile * t, mtiles)
|
||||
t->hide();
|
||||
tmenu->show();
|
||||
tmenu->setFocus();
|
||||
}
|
||||
EVENT_HANDLER2(void, tileEvent, PIScreenTile *, t, PIScreenTypes::TileEvent, e) {
|
||||
if (t == tmenu) {
|
||||
if (e.type == TileList::RowPressed) {
|
||||
piForeach (PIScreenTile * t, mtiles)
|
||||
t->hide();
|
||||
switch (e.data.toInt()) {
|
||||
case 0: tinfo->show(); break;
|
||||
case 1: tfm->show(); break;
|
||||
case 2: tdaemon->show(); break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, e) {
|
||||
if (e.key == PIKbdListener::Esc) menuRequest();
|
||||
//piCout << "key" << e.key;
|
||||
}
|
||||
PIScreenTile * tmenu, * tinfo, * tfm, * tdaemon;
|
||||
PIVector<PIScreenTile * > mtiles;
|
||||
};
|
||||
|
||||
|
||||
void tabMenu() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
console.addString("Select with numeric key:");
|
||||
console.addString(" 0 - this screen");
|
||||
console.addString(" 1 - show host info");
|
||||
console.addString(" 2 - local file manager");
|
||||
console.addString(" 3 - connect to another daemon");
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
void tabInfo() {
|
||||
startTab();
|
||||
/*startTab();
|
||||
console.addString("Exec command: " + PISystemInfo::instance()->execCommand);
|
||||
console.addString(" Executed on " + PISystemInfo::instance()->execDateTime.toString());
|
||||
console.addString(" Hostname: " + PISystemInfo::instance()->hostname);
|
||||
@@ -83,9 +143,8 @@ void tabInfo() {
|
||||
console.addString(" OS version: " + PISystemInfo::instance()->OS_version);
|
||||
console.addString("Architecture: " + PISystemInfo::instance()->architecture);
|
||||
console.addString(" CPU count: " + PIString::fromNumber(PISystemInfo::instance()->processorsCount));
|
||||
console.addString(" ", 2, PIConsole::Yellow | PIConsole::Inverse);
|
||||
console.addVariable("of this process", &sys_mon, 2);
|
||||
finishTab();
|
||||
finishTab();*/
|
||||
}
|
||||
|
||||
|
||||
@@ -210,15 +269,16 @@ int main(int argc, char * argv[]) {
|
||||
return 0;*/
|
||||
|
||||
//piCout << Hex << uint(ret) << tm.elapsed_m();
|
||||
piDebug = false;
|
||||
PICLI cli(argc, argv);
|
||||
//cli.addArgument("");
|
||||
sys_mon.startOnSelf();
|
||||
console.enableExitCapture();
|
||||
console.setDefaultAlignment(PIConsole::Right);
|
||||
console.start();
|
||||
//WAIT_FOR_EXIT
|
||||
screen.enableExitCapture(PIKbdListener::F10);
|
||||
MainMenu menu;
|
||||
screen.start();
|
||||
screen.waitForFinish();
|
||||
//return 0;
|
||||
while (!PIKbdListener::exiting) {
|
||||
/*while (!PIKbdListener::exiting) {
|
||||
if (oldmode != mode) {
|
||||
file_manager.disable();
|
||||
daemon_.disable();
|
||||
@@ -239,6 +299,6 @@ int main(int argc, char * argv[]) {
|
||||
}
|
||||
}
|
||||
piMSleep(100);
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user