# Path: alignak_app/backend/datamanager.py
# class DataManager(object):
#     def __init__(self):
#     def is_ready(self):
#     def update_database(self, item_type, items_list):
#     def get_item(self, item_type, key, value=None):
#     def remove_item(self, item_type, key, value=None):
#     def update_item_data(self, item_type, item_id, data):
#     def get_realm_name(self, realm):
#     def get_period_name(self, period):
#     def get_synthesis_count(self):
#     def get_all_hostnames(self):
#     def get_host_services(self, host_id):
#     def get_host_with_services(self, host_field):
#     def get_events(self):
#     def get_items_and_problems(self):
#     def update_problems(self):
#     def get_problems(self):
#     def is_problem(item_type, item_data):
# 
# Path: alignak_app/utils/config.py
# class Settings(object):
#     def __init__(self):
#     def init_config(self):
#     def get_config(self, section, option, boolean=False):
#     def set_config(self, section, option, new_value):
#     def get_image(self, name):
#     def init_css(self):
# def open_url(endpoint='login'):  # pragma: no cover
# def get_url_endpoint_from_icon_name(icon_name):
# 
# Path: alignak_app/utils/time.py
# def get_current_time():  # pragma: no cover
#     """
#     Return current formatted time
# 
#     :return: current time
#     :rtype: str
#     """
# 
#     return time.strftime("%H:%M:%S, %a %d %b ")
# 
# Path: alignak_app/qobjects/events/item.py
# class EventItem(QListWidgetItem):
#     """
#         Class who create an event QListWidgetItem
#     """
# 
#     def __init__(self):
#         super(EventItem, self).__init__()
#         self.timer = None
#         self.host = None
# 
#     def initialize(self, event_type, msg, timer=False, host=None):
#         """
#         Initialize QListWidgetItem
# 
#         :param event_type: the type of event: OK, DOWN, ACK, ...
#         :type event_type: str
#         :param msg: message of event
#         :type msg: str
#         :param timer: timer to hide event at end of time
#         :type timer: bool
#         :param host: _id of host. Only necessary if "be_spied" is True
#         :type host: None | str
#         """
# 
#         self.host = host
#         if host:
#             self.setData(Qt.UserRole, host)
# 
#         if timer:
#             self.timer = QTimer()
# 
#         self.setData(Qt.DisplayRole, "%s" % msg)
#         msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
#         self.setToolTip(msg_to_send)
# 
#         self.setData(
#             Qt.DecorationRole, QIcon(settings.get_image(self.get_icon(event_type)))
#         )
# 
#     def close_item(self):  # pragma: no cover
#         """
#         Hide items when timer is finished
# 
#         """
# 
#         self.setHidden(True)
# 
#     @staticmethod
#     def get_icon(event_type):
#         """
#         Return name of icon event
# 
#         :param event_type: type of event
#         :type event_type: str
#         :return: name of icon
#         :rtype: str
#         """
# 
#         available_icons = {
#             'event_ok': ['OK', 'UP'],
#             'event_info': ['UNKNOWN', 'INFO', 'TODO'],
#             'event_warn': ['WARNING', 'UNREACHABLE', 'WARN'],
#             'event_alert': ['DOWN', 'CRITICAL', 'ALERT'],
#             'acknowledge': ['ACK'],
#             'downtime': ['DOWNTIME', 'DOWNTIMESTART (DOWN)'],
#             'spy': ['SPY']
#         }
# 
#         for key, _ in available_icons.items():
#             if event_type in available_icons[key]:
#                 return key
# 
#         return 'error'
# 
#     @staticmethod
#     def get_event_type(data):
#         """
#         Return event type depending of data content
# 
#         :param data: data of backend item
#         :type data: dict
#         :return: event type for item
#         :rtype: str
#         """
# 
#         event_type = ''
#         if data['ls_acknowledged']:
#             event_type = 'ACK'
#         if data['ls_downtimed']:
#             event_type = 'DOWNTIME'
# 
#         if not event_type:
#             event_type = data['ls_state']
# 
#         return event_type


from logging import getLogger
from PyQt5.Qt import QWidget, QAbstractItemView, QListWidget, QTimer, QSize, QVBoxLayout, Qt
from alignak_app.backend.datamanager import data_manager
from alignak_app.utils.config import settings
from alignak_app.utils.time import get_current_time
from alignak_app.qobjects.events.item import EventItem
        for i in range(0, self.events_list.count()):
            if self.events_list.item(i).data(Qt.DisplayRole) == msg:
                item = self.events_list.takeItem(i)
                msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
                item.setToolTip(msg_to_send)
                self.events_list.insertItem(0, item)

                return True

        return False

    def remove_timer_event(self, event):
        """
        Remove EventItem with timer

        :param event: EventItem with timer
        :type event: EventItem
        """

        logger.debug('Remove Timer Event: %s', event.text())
        self.events_list.takeItem(self.events_list.row(event))

    def remove_event(self, item=None):
        """
        Remove item when user double click on an item

        :param item: item to remove, else remove the current row
        :type item: EventItem
        """


# Path: alignak_app/backend/datamanager.py
# class DataManager(object):
#     def __init__(self):
#     def is_ready(self):
#     def update_database(self, item_type, items_list):
#     def get_item(self, item_type, key, value=None):
#     def remove_item(self, item_type, key, value=None):
#     def update_item_data(self, item_type, item_id, data):
#     def get_realm_name(self, realm):
#     def get_period_name(self, period):
#     def get_synthesis_count(self):
#     def get_all_hostnames(self):
#     def get_host_services(self, host_id):
#     def get_host_with_services(self, host_field):
#     def get_events(self):
#     def get_items_and_problems(self):
#     def update_problems(self):
#     def get_problems(self):
#     def is_problem(item_type, item_data):
# 
# Path: alignak_app/utils/config.py
# class Settings(object):
#     def __init__(self):
#     def init_config(self):
#     def get_config(self, section, option, boolean=False):
#     def set_config(self, section, option, new_value):
#     def get_image(self, name):
#     def init_css(self):
# def open_url(endpoint='login'):  # pragma: no cover
# def get_url_endpoint_from_icon_name(icon_name):
# 
# Path: alignak_app/utils/time.py
# def get_current_time():  # pragma: no cover
#     """
#     Return current formatted time
# 
#     :return: current time
#     :rtype: str
#     """
# 
#     return time.strftime("%H:%M:%S, %a %d %b ")
# 
# Path: alignak_app/qobjects/events/item.py
# class EventItem(QListWidgetItem):
#     """
#         Class who create an event QListWidgetItem
#     """
# 
#     def __init__(self):
#         super(EventItem, self).__init__()
#         self.timer = None
#         self.host = None
# 
#     def initialize(self, event_type, msg, timer=False, host=None):
#         """
#         Initialize QListWidgetItem
# 
#         :param event_type: the type of event: OK, DOWN, ACK, ...
#         :type event_type: str
#         :param msg: message of event
#         :type msg: str
#         :param timer: timer to hide event at end of time
#         :type timer: bool
#         :param host: _id of host. Only necessary if "be_spied" is True
#         :type host: None | str
#         """
# 
#         self.host = host
#         if host:
#             self.setData(Qt.UserRole, host)
# 
#         if timer:
#             self.timer = QTimer()
# 
#         self.setData(Qt.DisplayRole, "%s" % msg)
#         msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
#         self.setToolTip(msg_to_send)
# 
#         self.setData(
#             Qt.DecorationRole, QIcon(settings.get_image(self.get_icon(event_type)))
#         )
# 
#     def close_item(self):  # pragma: no cover
#         """
#         Hide items when timer is finished
# 
#         """
# 
#         self.setHidden(True)
# 
#     @staticmethod
#     def get_icon(event_type):
#         """
#         Return name of icon event
# 
#         :param event_type: type of event
#         :type event_type: str
#         :return: name of icon
#         :rtype: str
#         """
# 
#         available_icons = {
#             'event_ok': ['OK', 'UP'],
#             'event_info': ['UNKNOWN', 'INFO', 'TODO'],
#             'event_warn': ['WARNING', 'UNREACHABLE', 'WARN'],
#             'event_alert': ['DOWN', 'CRITICAL', 'ALERT'],
#             'acknowledge': ['ACK'],
#             'downtime': ['DOWNTIME', 'DOWNTIMESTART (DOWN)'],
#             'spy': ['SPY']
#         }
# 
#         for key, _ in available_icons.items():
#             if event_type in available_icons[key]:
#                 return key
# 
#         return 'error'
# 
#     @staticmethod
#     def get_event_type(data):
#         """
#         Return event type depending of data content
# 
#         :param data: data of backend item
#         :type data: dict
#         :return: event type for item
#         :rtype: str
#         """
# 
#         event_type = ''
#         if data['ls_acknowledged']:
#             event_type = 'ACK'
#         if data['ls_downtimed']:
#             event_type = 'DOWNTIME'
# 
#         if not event_type:
#             event_type = data['ls_state']
# 
#         return event_type


# Path: alignak_app/qobjects/events/events.py
from logging import getLogger
from PyQt5.Qt import QWidget, QAbstractItemView, QListWidget, QTimer, QSize, QVBoxLayout, Qt
from alignak_app.backend.datamanager import data_manager
from alignak_app.utils.config import settings
from alignak_app.utils.time import get_current_time
from alignak_app.qobjects.events.item import EventItem

        for i in range(0, self.events_list.count()):
            if self.events_list.item(i).data(Qt.DisplayRole) == msg:
                item = self.events_list.takeItem(i)
                msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
                item.setToolTip(msg_to_send)
                self.events_list.insertItem(0, item)

                return True

        return False

    def remove_timer_event(self, event):
        """
        Remove EventItem with timer

        :param event: EventItem with timer
        :type event: EventItem
        """

        logger.debug('Remove Timer Event: %s', event.text())
        self.events_list.takeItem(self.events_list.row(event))

    def remove_event(self, item=None):
        """
        Remove item when user double click on an item

        :param item: item to remove, else remove the current row
        :type item: EventItem
        """


        if isinstance(item, EventItem):