Newer
Older
powermon_manager_sw / gui / gui_global.h
@Razvan Turiac Razvan Turiac on 8 Jul 3 KB Initial import
/* Copyright (C) 2020 - 2024, Thornwave Labs Inc
 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
 * documentation files (the “Software”), to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 * Attribution shall be given to Thornwave Labs Inc. and shall be made visible to the final user. 
 * 
 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef _GUI_GLOBAL_H
#define _GUI_GLOBAL_H

#include <stdint.h>
#include <inttypes.h>

#include <wx/wx.h>
#include <wx/tglbtn.h>
#include <wx/listctrl.h>

#include <wx/mstream.h>
#include <wx/bitmap.h>
#include <wx/dcbuffer.h>
#include <wx/graphics.h>

#include <resource.h>
#include <version.h>

#include <functional>

#include <powermon.h>

#include <debug.h>


class GuiEvent;
wxDECLARE_EVENT(EVT_TYPE_GUI, GuiEvent);

#define GUI_EVT(func) wx__DECLARE_EVT0(EVT_TYPE_GUI, &func)



class GuiEvent: public wxCommandEvent
{
public:
	GuiEvent(const std::function<void(GuiEvent&)> &fn): wxCommandEvent(EVT_TYPE_GUI, 0), mFunction(fn)
	{
	}

	wxEvent* Clone(void) const
	{
		return new GuiEvent(*this);
	}

	void process(void)
	{
		if (mFunction)
			mFunction(*this);
	}

private:
	std::function<void(GuiEvent&)> mFunction;
};


static inline bool checkDeviceError(wxWindow* window, uint16_t status)
{
	switch(status)
	{
		case Powermon::RSP_INVALID_REQ:
		{
			wxMessageDialog msg(window, wxT("Invalid request."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;

		case Powermon::RSP_INVALID_PARAM:
		{
			wxMessageDialog msg(window, wxT("Invalid parameter."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;
		
		case Powermon::RSP_ERROR:
		{
			wxMessageDialog msg(window, wxT("Request failed."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;

		case Powermon::RSP_LOCKED_USER:
		{
			wxMessageDialog msg(window, wxT("Feature is locked by user password."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;

		case Powermon::RSP_LOCKED_MASTER:
		{
			wxMessageDialog msg(window, wxT("Feature is locked by master password."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;
		
		case Powermon::RSP_TIMEOUT:
		{
			wxMessageDialog msg(window, wxT("Request timeout."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;
		
		case Powermon::RSP_INVALID:
		{
			wxMessageDialog msg(window, wxT("Invalid device response."), wxT("Error"), wxOK | wxSTAY_ON_TOP | wxCENTRE | wxICON_ERROR);
			msg.ShowModal();
			return false;
		}break;
		
		default: return true;
	}
	
	return true;
}


#endif