tahoma2d/toonz/sources/toonzfarm/tfarmclient/appmainshell.cpp

252 lines
6.6 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "appmainshell.h"
#include "application.h"
#include "tfarmcontroller.h"
#include "tw/colors.h"
#include "tw/menubar.h"
#include "tw/event.h"
#include "tw/action.h"
#include "traster.h"
#include "tsystem.h"
#include "tenv.h"
#include "tgrid.h"
#include "tw/tabbedwindow.h"
#include "taskstatuspage.h"
#include "serverstatuspage.h"
#include "casmsubmitpage.h"
#include "submitpage.h"
#include "filebrowserpopup.h"
#include "tw/message.h"
using namespace TwConsts;
//========================================================================
2016-06-15 18:43:10 +12:00
class MyTabbedWindow : public TTabbedWindow {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
MyTabbedWindow(TWidget *parent) : TTabbedWindow(parent) {}
void leftButtonDown(const TMouseEvent &e) {
TabPage *page1 = dynamic_cast<TabPage *>(getCurrentPanel());
TTabbedWindow::leftButtonDown(e);
TabPage *page2 = dynamic_cast<TabPage *>(getCurrentPanel());
if (page1 != page2)
if (page1) page1->onDeactivate();
if (page2) page2->onActivate();
}
2016-03-19 06:57:51 +13:00
};
//==============================================================================
2016-06-15 18:43:10 +12:00
class AppMainshell::Data {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Data()
: m_tabbedWindow(0)
, m_menubar(0)
, m_updatePeriod(3000)
, m_retryCount(0)
, m_retryPeriod(15000) {}
MyTabbedWindow *m_tabbedWindow;
TMenubar *m_menubar;
int m_updatePeriod;
int m_retryCount;
int m_retryPeriod;
2016-03-19 06:57:51 +13:00
};
//========================================================================
2016-06-15 18:43:10 +12:00
namespace {
2016-03-19 06:57:51 +13:00
//========================================================================
2016-06-15 18:43:10 +12:00
TEnv::RootSystemVar systemVar(
TFilePath("SOFTWARE\\Digital Video\\ToonzFarm\\1.0\\LOCALROOT"));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
inline void errorMessage(const string &msg) { TMessage::error(msg); }
2016-03-19 06:57:51 +13:00
const int menuBarLy = 21;
2016-06-15 18:43:10 +12:00
} // anonymous namespace
2016-03-19 06:57:51 +13:00
//========================================================================
2016-06-15 18:43:10 +12:00
AppMainshell::AppMainshell() : TMainshell("mainshell") {
m_name = "TFarmClient, v1.0 alfa - " + TSystem::getUserName() + "@" +
TSystem::getHostName();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data = new Data;
m_data->m_tabbedWindow = new MyTabbedWindow(this);
m_data->m_tabbedWindow->addPanel(new TaskStatusPage(m_data->m_tabbedWindow));
m_data->m_tabbedWindow->addPanel(
new ServerStatusPage(m_data->m_tabbedWindow));
// m_data->m_tabbedWindow->addPanel(new
// CasmSubmitPage(m_data->m_tabbedWindow));
m_data->m_tabbedWindow->addPanel(new SubmitPage(m_data->m_tabbedWindow));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->m_menubar = new TMenubar(this);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TMenubarItem *menu = new TMenubarItem(m_data->m_menubar, "File");
menu->addItem("Quit");
TGuiCommand("Quit").setAction(new TCommandAction<AppMainshell>(this, close));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*
menu = new TMenubarItem(m_data->m_menubar, "Tasks");
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
menu->addItem("Casm");
TGuiCommand("Casm").setAction(new TCommandAction<AppMainshell>(this,
onTaskCasm));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
menu->addItem("Notepad");
TGuiCommand("Notepad").setAction(new TCommandAction<AppMainshell>(this,
onTaskNotepad));
2016-03-19 06:57:51 +13:00
*/
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
AppMainshell::~AppMainshell() {}
2016-03-19 06:57:51 +13:00
//-------------------------------------------------------------------
HANDLE HFile;
2016-06-15 18:43:10 +12:00
void AppMainshell::init() {
TSystem::loadStandardPlugins();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
try {
Application::instance()->init();
} catch (TException &e) {
TMessage::error(toString(e.getMessage()));
return;
}
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
bool AppMainshell::beforeShow() {
if (!Application::instance()->testControllerConnection()) {
string hostName, addr;
int port;
Application::instance()->getControllerData(hostName, addr, port);
string msg("Unable to connect to the ToonzFarm Controller\n");
msg += "The Controller should run on " + hostName + " at port ";
msg += toString(port) + "\n";
msg += "Please start the Controller before running this application";
TMessage::error(msg);
return false;
}
TWidget *w = m_data->m_tabbedWindow->getCurrentPanel();
TabPage *page = dynamic_cast<TabPage *>(w);
if (page) page->onActivate();
startTimer(m_data->m_updatePeriod);
return true;
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void AppMainshell::configureNotify(const TDimension &size) {
TMainshell::configureNotify(size);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->m_tabbedWindow->setGeometry(0, 0, size.lx - 1,
size.ly - menuBarLy - 1);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_data->m_menubar->setGeometry(0, size.ly - menuBarLy, size.lx - 1,
size.ly - 1);
m_data->m_menubar->invalidate();
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void AppMainshell::close() {
if (TMessage::question("Are you sure?") == TMessage::YES) {
TMainshell::close();
}
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void AppMainshell::repaint() {
TDimension size = getSize();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int y = size.ly - 1;
int x = 20;
setColor(White);
fillRect(x, 0, size.lx - 1, y);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
setColor(Gray60);
fillRect(0, 0, x - 1, y);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
y -= 21;
drawLine(x, y, x, y - 3);
drawLine(x + 1, y, x + 1, y - 1);
drawLine(x + 2, y, x + 3, y);
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TDimension AppMainshell::getPreferredSize() { return TDimension(1200, 500); }
2016-03-19 06:57:51 +13:00
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int AppMainshell::getMainIconId() { return 101 /*IDI_ZCOMP*/; }
2016-03-19 06:57:51 +13:00
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void AppMainshell::onTimer(int) {
if (false && !Application::instance()->testControllerConnection()) {
if (m_data->m_retryCount == 0) {
stopTimer();
startTimer(m_data->m_retryPeriod);
}
++m_data->m_retryCount;
if (m_data->m_retryCount == 3) {
stopTimer();
startTimer(4 * m_data->m_retryPeriod);
string hostName, addr;
int port;
Application::instance()->getControllerData(hostName, addr, port);
string msg("The connection to the ToonzFarm Controller has been lost\n");
msg += "The Controller should run on " + hostName + " at port ";
msg += toString(port) + "\n";
msg += "Please check the Controller state";
TMessage::error(msg);
}
} else {
if (m_data->m_retryCount > 0) {
m_data->m_retryCount = 0;
string msg("Reconnected to the ToonzFarm Controller\n");
TMessage::error(msg);
stopTimer();
startTimer(m_data->m_updatePeriod);
}
TWidget *w = m_data->m_tabbedWindow->getCurrentPanel();
TabPage *page = dynamic_cast<TabPage *>(w);
if (page) page->update();
}
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
//-------------------------------------------------------------------
AppMainshell mainshell;