<commit_before>#pragma warning( push )
#pragma warning( disable : 4250 )
#undef max
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
#include <gtkmm/actiongroup.h>

#include <libglademm.h>
#include <glade/glade.h>
#pragma warning( pop )

#include <Poco/ClassLibrary.h>

#include "StableHeaders.h"
#include "Foundation.h"



#include "ConfigureDlg.h"
#include "SelectionDialog.h"
#include "DialogCallbackInterface.h"

#include "ScriptServiceInterface.h"
#include "CommunicationUIModule.h"



namespace CommunicationUI
{
	CommunicationUIModule* CommunicationUIModule::instance_;

	CommunicationUIModule::CommunicationUIModule(void):ModuleInterfaceImpl("CommunicationUIModule")
	{
	}

	CommunicationUIModule::~CommunicationUIModule(void)
	{
	}

	void CommunicationUIModule::Load()
	{
	}
	
	void CommunicationUIModule::Unload()
	{
	}

	void CommunicationUIModule::Initialize() 
	{
	}

	void CommunicationUIModule::PostInitialize()
	{
		initializeMainCommWindow();
		//commManager = (framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager)).lock();
        //commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager);
//                      (framework_->GetService<Scene::SceneManager>(Foundation::Service::ST_SceneManager)).lock();
		//commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager).lock();

        commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager).lock();

		CommunicationUIModule::instance_= this;		
        
        //setupSciptInterface();		
		SetupCommunicationServiceUsage();
	}

	void CommunicationUIModule::Uninitialize()
	{
        SAFE_DELETE(wndCommMain);
	}

	void CommunicationUIModule::Update()
	{
	}

	void CommunicationUIModule::initializeMainCommWindow()
	{
		commUI_XML = Gnome::Glade::Xml::create("data/communicationUI.glade");
		if (!commUI_XML)
			return;
		wndCommMain = 0;
		                        
		commUI_XML->get_widget("wndCMain", wndCommMain);
        commUI_XML->get_widget("fxdContainer", fxdContainer);
        commUI_XML->get_widget("btnAddContact", btnAddContact);
        commUI_XML->get_widget("btnRemoveContact", btnRemoveContact);
        commUI_XML->get_widget("btnSetPresenceMessage", btnSetPresenceMessage);
        commUI_XML->get_widget("entryPresenceMessage", entryPresenceMessage);
        commUI_XML->get_widget("lblPresenceStatus", lblPresenceStatus);



        cmbPresence.set_size_request(240, 25);
        fxdContainer->put(cmbPresence, 25, 40);
        


        if(!wndCommMain||!fxdContainer)//||!wndSelection)
			return;

        lstContacts.set_size_request(240,182);
        fxdContainer->put(lstContacts, 25, 80);
        lstContacts.SetModule(*this);

	    commUI_XML->connect_clicked("mi_connect", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuConnect));
		commUI_XML->connect_clicked("mi_disconnect", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuDisconnect));
		commUI_XML->connect_clicked("mi_setaccount", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuSetAccountAndPassword));
		commUI_XML->connect_clicked("mi_settings", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuSettings));
        commUI_XML->connect_clicked("mi_createaccount", sigc::mem_fun(*this, &CommunicationUIModule::OnCreateAccount));

		commUI_XML->connect_clicked("mi_directchat", sigc::mem_fun(*this, &CommunicationUIModule::OnDirectChatMenuStartChat));
        
        commUI_XML->connect_clicked("mi_online", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusOnline));
        commUI_XML->connect_clicked("mi_away", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusAway));
        commUI_XML->connect_clicked("mi_busy", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusBusy));
        commUI_XML->connect_clicked("mi_offline", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusOffline));

		//commUI_XML->connect_clicked("btnTest", sigc::mem_fun(*this, &CommunicationUIModule::reloadIMScript));
        commUI_XML->connect_clicked("btnTest", sigc::mem_fun(*this, &CommunicationUIModule::testDialog));
        commUI_XML->connect_clicked("btnAddContact", sigc::mem_fun(*this, &CommunicationUIModule::OnContactAdd));
        commUI_XML->connect_clicked("btnRemoveContact", sigc::mem_fun(*this, &CommunicationUIModule::OnContactRemove));
        commUI_XML->connect_clicked("btnRefresh", sigc::mem_fun(*this, &CommunicationUIModule::OnRefresh));
        commUI_XML->connect_clicked("btnSetPresenceMessage", sigc::mem_fun(*this, &CommunicationUIModule::OnSetPresenceMessage));



        //commUI_XML->connect_property_changed("cmbPresence", sigc::mem_fun(*this, &CommunicationUIModule::OnComboChange));
        cmbPresence.signal_changed().connect(sigc::mem_fun(*this, &CommunicationUIModule::OnComboChange) );


		// entry dialog
		commUI_XML->connect_clicked("btnEntryOk", sigc::mem_fun(*this, &CommunicationUIModule::OnEntryDlgOk));
		commUI_XML->connect_clicked("btnEntryCancel", sigc::mem_fun(*this, &CommunicationUIModule::OnEntryDlgCancel));
        
        //wndCommMain->set_name("Comms UI");
        wndCommMain->set_title("Comms UI");
		wndCommMain->show();
        lstContacts.show();
        cmbPresence.show();
	}

    void CommunicationUIModule::testDialog()
    {
        //SelectionDialog sd("test", "Go home", "_Yep", "_No Way!", this);
        //Gtk::Main::run(sd);
		std::string str = "CTest";
		std::string syntax = "";
        Foundation::ScriptObject* ret = imScriptObject->CallMethod(str, syntax, NULL);
    }

    void CommunicationUIModule::reloadIMScript()
    {
        delete this->imScriptObject;
        this->imScriptObject = NULL;
        setupSciptInterface();
    }

	
		
	/*
	 *  - Fetches communication service object
	 *  - Subscribes communication events
	 *  - Get contact list 
	 */
	void CommunicationUIModule::SetupCommunicationServiceUsage()
	{
		communication_service_ = framework_->GetService<Communication::CommunicationServiceInterface>(Foundation::Service::ST_Communication).lock();

		framework_->GetEventManager()->RegisterEventSubscriber( framework_->GetModuleManager()->GetModule(this->Name()), 0, Foundation::ModuleWeakPtr() );
        communication_event_category_id_ = framework_->GetEventManager()->QueryEventCategory("Communication");
        
        if (communication_event_category_id_ == 0 )
            LogWarning("Unable to find event category for Communication events!");

		contact_list_ = communication_service_->GetContactList();

	}<commit_msg>Fix: viewer crashes if comm ui is stared without comm service<commit_after>#pragma warning( push )
#pragma warning( disable : 4250 )
#undef max
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treestore.h>
#include <gtkmm/actiongroup.h>

#include <libglademm.h>
#include <glade/glade.h>
#pragma warning( pop )

#include <Poco/ClassLibrary.h>

#include "StableHeaders.h"
#include "Foundation.h"



#include "ConfigureDlg.h"
#include "SelectionDialog.h"
#include "DialogCallbackInterface.h"

#include "ScriptServiceInterface.h"
#include "CommunicationUIModule.h"



namespace CommunicationUI
{
	CommunicationUIModule* CommunicationUIModule::instance_;

	CommunicationUIModule::CommunicationUIModule(void):ModuleInterfaceImpl("CommunicationUIModule")
	{
	}

	CommunicationUIModule::~CommunicationUIModule(void)
	{
	}

	void CommunicationUIModule::Load()
	{
	}
	
	void CommunicationUIModule::Unload()
	{
	}

	void CommunicationUIModule::Initialize() 
	{
	}

	void CommunicationUIModule::PostInitialize()
	{
		initializeMainCommWindow();
		//commManager = (framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager)).lock();
        //commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager);
//                      (framework_->GetService<Scene::SceneManager>(Foundation::Service::ST_SceneManager)).lock();
		//commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager).lock();

        commManager = framework_->GetService<Foundation::Comms::CommunicationManagerServiceInterface>(Foundation::Service::ST_CommunicationManager).lock();

		CommunicationUIModule::instance_= this;		
        
        //setupSciptInterface();		
		SetupCommunicationServiceUsage();
	}

	void CommunicationUIModule::Uninitialize()
	{
        SAFE_DELETE(wndCommMain);
	}

	void CommunicationUIModule::Update()
	{
	}

	void CommunicationUIModule::initializeMainCommWindow()
	{
		commUI_XML = Gnome::Glade::Xml::create("data/communicationUI.glade");
		if (!commUI_XML)
			return;
		wndCommMain = 0;
		                        
		commUI_XML->get_widget("wndCMain", wndCommMain);
        commUI_XML->get_widget("fxdContainer", fxdContainer);
        commUI_XML->get_widget("btnAddContact", btnAddContact);
        commUI_XML->get_widget("btnRemoveContact", btnRemoveContact);
        commUI_XML->get_widget("btnSetPresenceMessage", btnSetPresenceMessage);
        commUI_XML->get_widget("entryPresenceMessage", entryPresenceMessage);
        commUI_XML->get_widget("lblPresenceStatus", lblPresenceStatus);



        cmbPresence.set_size_request(240, 25);
        fxdContainer->put(cmbPresence, 25, 40);
        


        if(!wndCommMain||!fxdContainer)//||!wndSelection)
			return;

        lstContacts.set_size_request(240,182);
        fxdContainer->put(lstContacts, 25, 80);
        lstContacts.SetModule(*this);

	    commUI_XML->connect_clicked("mi_connect", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuConnect));
		commUI_XML->connect_clicked("mi_disconnect", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuDisconnect));
		commUI_XML->connect_clicked("mi_setaccount", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuSetAccountAndPassword));
		commUI_XML->connect_clicked("mi_settings", sigc::mem_fun(*this, &CommunicationUIModule::OnAccountMenuSettings));
        commUI_XML->connect_clicked("mi_createaccount", sigc::mem_fun(*this, &CommunicationUIModule::OnCreateAccount));

		commUI_XML->connect_clicked("mi_directchat", sigc::mem_fun(*this, &CommunicationUIModule::OnDirectChatMenuStartChat));
        
        commUI_XML->connect_clicked("mi_online", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusOnline));
        commUI_XML->connect_clicked("mi_away", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusAway));
        commUI_XML->connect_clicked("mi_busy", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusBusy));
        commUI_XML->connect_clicked("mi_offline", sigc::mem_fun(*this, &CommunicationUIModule::OnSetStatusOffline));

		//commUI_XML->connect_clicked("btnTest", sigc::mem_fun(*this, &CommunicationUIModule::reloadIMScript));
        commUI_XML->connect_clicked("btnTest", sigc::mem_fun(*this, &CommunicationUIModule::testDialog));
        commUI_XML->connect_clicked("btnAddContact", sigc::mem_fun(*this, &CommunicationUIModule::OnContactAdd));
        commUI_XML->connect_clicked("btnRemoveContact", sigc::mem_fun(*this, &CommunicationUIModule::OnContactRemove));
        commUI_XML->connect_clicked("btnRefresh", sigc::mem_fun(*this, &CommunicationUIModule::OnRefresh));
        commUI_XML->connect_clicked("btnSetPresenceMessage", sigc::mem_fun(*this, &CommunicationUIModule::OnSetPresenceMessage));



        //commUI_XML->connect_property_changed("cmbPresence", sigc::mem_fun(*this, &CommunicationUIModule::OnComboChange));
        cmbPresence.signal_changed().connect(sigc::mem_fun(*this, &CommunicationUIModule::OnComboChange) );


		// entry dialog
		commUI_XML->connect_clicked("btnEntryOk", sigc::mem_fun(*this, &CommunicationUIModule::OnEntryDlgOk));
		commUI_XML->connect_clicked("btnEntryCancel", sigc::mem_fun(*this, &CommunicationUIModule::OnEntryDlgCancel));
        
        //wndCommMain->set_name("Comms UI");
        wndCommMain->set_title("Comms UI");
		wndCommMain->show();
        lstContacts.show();
        cmbPresence.show();
	}

    void CommunicationUIModule::testDialog()
    {
        //SelectionDialog sd("test", "Go home", "_Yep", "_No Way!", this);
        //Gtk::Main::run(sd);
		std::string str = "CTest";
		std::string syntax = "";
        Foundation::ScriptObject* ret = imScriptObject->CallMethod(str, syntax, NULL);
    }

    void CommunicationUIModule::reloadIMScript()
    {
        delete this->imScriptObject;
        this->imScriptObject = NULL;
        setupSciptInterface();
    }

	
		
	/*
	 *  - Fetches communication service object
	 *  - Subscribes communication events
	 *  - Get contact list 
	 */
	void CommunicationUIModule::SetupCommunicationServiceUsage()
	{
		communication_service_ = framework_->GetService<Communication::CommunicationServiceInterface>(Foundation::Service::ST_Communication).lock();
		if (communication_service_.get() == NULL)
		{
			LogError("Cannot find communication service!");
			return;
		}

		framework_->GetEventManager()->RegisterEventSubscriber( framework_->GetModuleManager()->GetModule(this->Name()), 0, Foundation::ModuleWeakPtr() );
        communication_event_category_id_ = framework_->GetEventManager()->QueryEventCategory("Communication");
        
        if (communication_event_category_id_ == 0 )
            LogWarning("Unable to find event category for Communication events!");

		contact_list_ = communication_service_->GetContactList();

	}
{'fraction_non_alphanumeric': 0.13426664732337154, 'fraction_numerical': 0.003771942550413463, 'mean_word_length': 5.709002433090024, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '245808', 'n_tokens_mistral': 4415, 'n_tokens_neox': 4229, 'n_words': 496}