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