Esempio n. 1
0
/* Disable panels, except the one passed as parameter */
void wxbMainFrame::DisablePanels(void* except) {
   for (int i = 0; panels[i] != NULL; i++) {
      if (panels[i] != except) {
         panels[i]->EnablePanel(false);
      }
      else {
         panels[i]->EnablePanel(true);
      }
   }
   if (this != except) {
      EnableConsole(false);
   }
}
Esempio n. 2
0
	Bool HsLogger::Init(const AString& sCfg)
	{
		if (!m_bRunning)
		{
			HawkXmlFile xmlCfg;
			HawkXmlDocument<AString> xmlDoc;
			if (!xmlCfg.Open(sCfg, xmlDoc))
			{
				HawkPrint("LogServer Open Config Error.");
				return false;
			}

			AXmlElement* pRoot  = xmlDoc.GetRoot();
			AXmlElement* pCfg   = pRoot->GetChildren("LgCfg");
			AXmlElement* pDbCfg = pRoot->GetChildren("DbCfg");

			if(!pCfg || !pDbCfg || !pCfg->GetAttribute("Addr"))
			{
				HawkPrint("LogServer Config Tag Error.");
				return false;
			}

			AString sAddr = pCfg->GetAttribute("Addr")->StringValue();

			if (pRoot->GetAttribute("Console"))
				EnableConsole(pRoot->GetAttribute("Console")->BoolValue());

			HawkDatabase::DBConn sConn(HawkDatabase::HDB_MYSQL);

			if (pDbCfg->GetAttribute("Host"))
				sConn.SetHost(pDbCfg->GetAttribute("Host")->StringValue());

			if (pDbCfg->GetAttribute("Port"))
				sConn.SetPort(pDbCfg->GetAttribute("Port")->IntValue());

			if (pDbCfg->GetAttribute("User"))
				sConn.SetUser(pDbCfg->GetAttribute("User")->StringValue());

			if (pDbCfg->GetAttribute("Pwd"))
				sConn.SetPwd(pDbCfg->GetAttribute("Pwd")->StringValue());

			sConn.SetDBName(pDbCfg->GetAttribute("DB")->StringValue());
			
			return HawkLogServer::Init(sAddr, sConn);
		}
		return false;
	}
Esempio n. 3
0
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        Console::Write("WowAddin v0.1 Alpha Loaded", ECHO_COLOR);
        EnableConsole();
        FixInvalidPtrCheck();
        InstallGameConsoleCommands();
        SetMessageHandlers();
        break;
    case DLL_THREAD_ATTACH:
        //Console::Write("DLL_THREAD_ATTACH", ECHO_COLOR);
        break;
    case DLL_THREAD_DETACH:
        //Console::Write("DLL_THREAD_DETACH", ECHO_COLOR);
        break;
    case DLL_PROCESS_DETACH:
        //Console::Write("DLL_PROCESS_DETACH", ECHO_COLOR);
        //UninstallGameConsoleCommands(); // cause client to crash at closing
        break;
    }
    return TRUE;
}
Esempio n. 4
0
/* Enable panels */
void wxbMainFrame::EnablePanels() {
   for (int i = 0; panels[i] != NULL; i++) {
      panels[i]->EnablePanel(true);
   }
   EnableConsole(true);
}
Esempio n. 5
0
/*
 *  Prints data received from director to the console, and forwards it to the panels
 */
void wxbMainFrame::Print(wxString str, int status)
{
   if (lockedbyconsole) {
      EnableConsole(false);
   }
   
   if (status == CS_REMOVEPROMPT) {
      if (consoleCtrl->GetLastPosition() > 0) {
         consoleCtrl->Remove(consoleCtrl->GetLastPosition()-1, consoleCtrl->GetLastPosition()+1);
      }
      return;
   }
   
   if (status == CS_TERMINATED) {
      consoleCtrl->AppendText(consoleBuffer);
      consoleBuffer = wxT("");
      SetStatusText(_("Console thread terminated."));
#ifdef HAVE_WIN32
      consoleCtrl->PageDown();
#else
      consoleCtrl->ScrollLines(1);
#endif
      ct = NULL;
      DisablePanels();
      int answer = wxMessageBox( _("Connection to the director lost. Quit program?"), 
                                 _("Connection lost"),
                        wxYES_NO | wxICON_EXCLAMATION, this);
      if (answer == wxYES) {
         frame = NULL;
         Close(true);
      }
      menuFile->Enable(MenuConnect, true);
      menuFile->SetLabel(MenuConnect, _("Connect"));
      menuFile->SetHelpString(MenuConnect, _("Connect to the director"));
      menuFile->Enable(MenuDisconnect, false);
      menuFile->Enable(ChangeConfigFile, true);
      menuFile->Enable(EditConfigFile, true);
      return;
   }
   
   if (status == CS_CONNECTED) {
      SetStatusText(_("Connected to the director."));
      typeCtrl->ClearCommandList();
      bool parsed = false;
      int retries = 3;
      wxbDataTokenizer* dt = wxbUtils::WaitForEnd(wxT(".help"), true);
      while (true) {
         int i, j;
         wxString str;
         for (i = 0; i < (int)dt->GetCount(); i++) {
            str = (*dt)[i];
            str.RemoveLast();
            if ((j = str.Find(' ')) > -1) {
               typeCtrl->AddCommand(str.Mid(0, j), str.Mid(j+1));
               parsed = true;
            }
         }
         retries--;
         if ((parsed) || (!retries))
            break;
         dt = wxbUtils::WaitForEnd(wxT(""), true);
      }
      EnablePanels();
      menuFile->Enable(MenuConnect, true);
      menuFile->SetLabel(MenuConnect, _("Reconnect"));
      menuFile->SetHelpString(MenuConnect, _("Reconnect to the director"));
      menuFile->Enable(MenuDisconnect, true);
      menuFile->Enable(ChangeConfigFile, true);
      menuFile->Enable(EditConfigFile, true);
      return;
   }
   if (status == CS_DISCONNECTED) {
      consoleCtrl->AppendText(consoleBuffer);
      consoleBuffer = wxT("");
#ifdef HAVE_WIN32
      consoleCtrl->PageDown();
#else
      consoleCtrl->ScrollLines(1);
#endif
      SetStatusText(_("Disconnected of the director."));
      DisablePanels();
      return;
   }
      
   // CS_DEBUG is often sent by panels, 
   // and resend it to them would sometimes cause infinite loops
   
   /* One promptcaught is normal, so we must have two true Print values to be
    * sure that the prompt has effectively been caught.
    */
   int promptcaught = -1;
   
   if (status != CS_DEBUG) {
      for (unsigned int i = 0; i < parsers.GetCount(); i++) {
         promptcaught += parsers[i]->Print(str, status) ? 1 : 0;
      }
         
      if ((status == CS_PROMPT) && (promptcaught < 1) && (promptparser->isPrompt())) {
         Print(_("Unexpected question has been received.\n"), CS_DEBUG);
//         Print(wxString("(") << promptparser->getIntroString() << "/-/" << promptparser->getQuestionString() << ")\n", CS_DEBUG);
         
         wxString message;
         if (promptparser->getIntroString() != wxT("")) {
            message << promptparser->getIntroString() << wxT("\n");
         }
         message << promptparser->getQuestionString();
         
         if (promptparser->getChoices()) {
            wxString *choices = new wxString[promptparser->getChoices()->GetCount()];
            int *numbers = new int[promptparser->getChoices()->GetCount()];
            int n = 0;
            
            for (unsigned int i = 0; i < promptparser->getChoices()->GetCount(); i++) {
               if ((*promptparser->getChoices())[i] != wxT("")) {
                  choices[n] = (*promptparser->getChoices())[i];
                  numbers[n] = i;
                  n++;
               }
            }
            
            int res = ::wxGetSingleChoiceIndex(message,
               _("bwx-console: unexpected director's question."), n, choices, this);
            if (res == -1) { //Cancel pressed
               Send(wxT(".\n"));
            }
            else {
               if (promptparser->isNumericalChoice()) {
                  Send(wxString() << numbers[res] << wxT("\n"));
               }
               else {
                  Send(wxString() << choices[res] << wxT("\n"));
               }
            }
            delete[] choices;
            delete[] numbers;
         }
         else {
            Send(::wxGetTextFromUser(message,
               _("bwx-console: unexpected director's question."),
               wxT(""), this) + wxT("\n"));
         }
      }
   }
      
   if (status == CS_END) {
      if (lockedbyconsole) {
         EnablePanels();
         lockedbyconsole = false;
      }
      str = wxT("#");
   }

   if (status == CS_DEBUG) {
      consoleCtrl->AppendText(consoleBuffer);
      consoleBuffer = wxT("");
#ifdef HAVE_WIN32
      consoleCtrl->PageDown();
#else
      consoleCtrl->ScrollLines(1);
#endif
      consoleCtrl->SetDefaultStyle(wxTextAttr(wxColour(0, 128, 0)));
   }
   else {
      consoleCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK));
   }
   consoleBuffer << wxbUtils::ConvertToPrintable(str);
   if (status == CS_PROMPT) {
      if (lockedbyconsole) {
         EnableConsole(true);
      }
      //consoleBuffer << wxT("<P>");
   }
   
   if ((status == CS_END) || (status == CS_PROMPT) || (str.Find(wxT("\n")) > -1)) {
      consoleCtrl->AppendText(consoleBuffer);
      consoleBuffer = wxT("");

#ifdef HAVE_WIN32
      consoleCtrl->PageDown();
#else
      consoleCtrl->ScrollLines(1);
#endif
   }
   
   //consoleCtrl->ShowPosition(consoleCtrl->GetLastPosition());
   
   /*if (status != CS_DEBUG) {
      consoleCtrl->AppendText("@");
   }*/
   //consoleCtrl->SetInsertionPointEnd();
}
Esempio n. 6
0
/*
 *  Private constructor
 */
wxbMainFrame::wxbMainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style)
      : wxFrame(NULL, -1, title, pos, size, style)
{
   lockedbyconsole = false;
   
   ct = NULL;
   
   promptparser = NULL;

   // set the frame icon
   SetIcon(wxIcon(wxwin16x16_xpm));

#if wxUSE_MENUS
   // create a menu bar
   menuFile = new wxMenu;

   // the "About" item should be in the help menu
   wxMenu *helpMenu = new wxMenu;
   helpMenu->Append(Minimal_About, _("&About...\tF1"), _("Show about dialog"));

   menuFile->Append(MenuConnect, _("Connect"), _("Connect to the director"));
   menuFile->Append(MenuDisconnect, _("Disconnect"), _("Disconnect of the director"));
   menuFile->AppendSeparator();
   menuFile->Append(ChangeConfigFile, _("Change of configuration file"), _("Change your default configuration file"));
   menuFile->Append(EditConfigFile, _("Edit your configuration file"), _("Edit your configuration file"));
   menuFile->AppendSeparator();
   menuFile->Append(Minimal_Quit, _("E&xit\tAlt-X"), _("Quit this program"));

   // now append the freshly created menu to the menu bar...
   wxMenuBar *menuBar = new wxMenuBar();
   menuBar->Append(menuFile, _("&File"));
   menuBar->Append(helpMenu, _("&Help"));

   // ... and attach this menu bar to the frame
   SetMenuBar(menuBar);
#endif // wxUSE_MENUS

   CreateStatusBar(1);
   
   SetStatusText(wxString::Format(_("Welcome to bacula bwx-console %s (%s)!\n"), wxT(VERSION), wxT(BDATE)));

   wxPanel* global = new wxPanel(this, -1);

   notebook = new wxNotebook(global, -1);

   /* Console */

   wxPanel* consolePanel = new wxPanel(notebook, -1);
   notebook->AddPage(consolePanel, _("Console"));

   consoleCtrl = new wxTextCtrl(consolePanel,-1,wxT(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH);
   wxFont font(10, wxMODERN, wxNORMAL, wxNORMAL);
#if defined __WXGTK12__ && !defined __WXGTK20__ // Fix for "chinese" fonts under gtk+ 1.2
   font.SetDefaultEncoding(wxFONTENCODING_ISO8859_1);
   consoleCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
   Print(_("Warning : Unicode is disabled because you are using wxWidgets for GTK+ 1.2.\n"), CS_DEBUG);
#else 
   consoleCtrl->SetDefaultStyle(wxTextAttr(*wxBLACK, wxNullColour, font));
#if (wxUSE_UNICODE == 0) && __WXGTK20__
   Print(_("Warning : There is a problem with wxWidgets for GTK+ 2.0 without Unicode support when handling non-ASCII filenames: Every non-ASCII character in such filenames will be replaced by an interrogation mark.\nIf this behaviour disturbs you, please build bwx-console against a Unicode version of wxWidgets for GTK+ 2.0.\n---\n"), CS_DEBUG);   
#endif
#endif

   helpCtrl = new wxStaticText(consolePanel, -1, _("Type your command below:"));

   wxFlexGridSizer *consoleSizer = new wxFlexGridSizer(4, 1, 0, 0);
   consoleSizer->AddGrowableCol(0);
   consoleSizer->AddGrowableRow(0);

   typeCtrl = new wxbHistoryTextCtrl(helpCtrl, consolePanel,TypeText,wxT(""),wxDefaultPosition,wxSize(200,20));
   sendButton = new wxButton(consolePanel, SendButton, _("Send"));
   
   wxFlexGridSizer *typeSizer = new wxFlexGridSizer(1, 2, 0, 0);
   typeSizer->AddGrowableCol(0);
   typeSizer->AddGrowableRow(0);

   //typeSizer->Add(new wxStaticText(consolePanel, -1, _("Command: ")), 0, wxALIGN_CENTER | wxALL, 0);
   typeSizer->Add(typeCtrl, 1, wxEXPAND | wxALL, 0);
   typeSizer->Add(sendButton, 1, wxEXPAND | wxLEFT, 5);

   consoleSizer->Add(consoleCtrl, 1, wxEXPAND | wxALL, 0);
   consoleSizer->Add(new wxStaticLine(consolePanel, -1), 0, wxEXPAND | wxALL, 0);
   consoleSizer->Add(helpCtrl, 1, wxEXPAND | wxALL, 2);
   consoleSizer->Add(typeSizer, 0, wxEXPAND | wxALL, 2);

   consolePanel->SetAutoLayout( TRUE );
   consolePanel->SetSizer( consoleSizer );
   consoleSizer->SetSizeHints( consolePanel );

   // Creates the list of panels which are included in notebook, and that need to receive director information

   panels = new wxbPanel* [2];
   panels[0] = new wxbRestorePanel(notebook);
   panels[1] = NULL;

   for (int i = 0; panels[i] != NULL; i++) {
      notebook->AddPage(panels[i], panels[i]->GetTitle());
   }

   wxBoxSizer* globalSizer = new wxBoxSizer(wxHORIZONTAL);

#if wxCHECK_VERSION(2, 6, 0)
   globalSizer->Add(notebook, 1, wxEXPAND, 0);
#else
   globalSizer->Add(new wxNotebookSizer(notebook), 1, wxEXPAND, 0);
#endif

   global->SetSizer( globalSizer );
   globalSizer->SetSizeHints( global );

   wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);

   sizer->Add(global, 1, wxEXPAND | wxALL, 0);
   SetAutoLayout(true);
   SetSizer( sizer );
   sizer->SetSizeHints( this );
   this->SetSize(size);
   EnableConsole(false);
   
   consoleBuffer = wxT("");
   
   configfile = wxT("");
}