Ejemplo n.º 1
0
    def __init__(self, filename):
        self.filename = filename

        self.database = db.Database(self.filename)
        self.database.close()

        self.settings = Config()

        self.label = self.settings.label
        self.time = datetimeutil.time_to_local(self.settings.time)
        self.date = datetimeutil.date_to_local(self.settings.date)
        self.command = self.settings.command
        self.notes = ""
        self.popup = self.settings.popup
        self.dialog = self.settings.dialog
        self.boxcar = self.settings.boxcar_notify
        self.boxcar_ok = self.settings.boxcar_token != ''
        self.pushbullet_api_key = self.settings.pushbullet_api_key
        self.pushbullet_device = self.settings.pushbullet_device
        self.pushbullet_devices = self.settings.pushbullet_devices
        self.pushbullet_ok = self.settings.pushbullet_api_key != ''
        self.pushbullet_device_index = self.get_pushbullet_index()
        self.sound_file = self.settings.sound_file
        self.sound_length = self.settings.sound_play_length
        self.sound_loop = self.settings.sound_loop
        self.sound_loop_times = self.settings.sound_loop_times

        self.time_format = self.settings.time_format
        self.date_format = self.settings.date_format

        self.play_sound = False
        if self.sound_file is not None and not self.sound_file == "":
            self.play_sound = True
Ejemplo n.º 2
0
    def __init__(self, file):
        self.file = file

        self.database = db.Database(self.file)
        self.result_list = self.database.all_alarms()
        self.database.close()

        self.settings = Config()
        self.new_news = self.settings.new_news
        self.settings.new_news = False
        self.settings.dump()

        if self.new_news == None:
            self.new_news = False
        else:
            self.new_news = bool(self.new_news)

        self.hide_indicator = self.settings.hide_indicator
        self.indicator_icon = self.settings.indicator_icon
        self.show_news = self.settings.show_news

        self.missed_reminders = []
        self.potentially_missed_reminders = {}

        try:
            scheduled_reminders = json.load(open(constants.scheduled_file))
            for reminder in scheduled_reminders:
                self.potentially_missed_reminders[reminder['id']] = datetime.strptime(reminder['date_time'], self.scheduled_format)
        except:
            logger.error('Could not load scheduled reminders')

        self.update(None, True)
Ejemplo n.º 3
0
class PreferencesDialogInfo(PushbulletInfo):
    ok = 0
    time_error = 1
    date_error = 2

    boxcar_delete = 0
    boxcar_add = 1
    boxcar_subscribe = 2
    boxcar_error = 3

    def __init__(self, filename):
        self.filename = filename
        self.settings = Config()

        self.today_color_rgb = hex_to_rgb(self.settings.today_color)
        self.future_color_rgb = hex_to_rgb(self.settings.future_color)
        self.past_color_rgb = hex_to_rgb(self.settings.past_color)

        self.time_format = time_formats[self.settings.time_format]
        self.qt_time_format = qt_time_formats[self.settings.time_format]
        self.time_format_num = self.settings.time_format

        self.date_format = date_formats[self.settings.date_format]
        self.qt_date_format = qt_date_formats[self.settings.date_format]
        self.date_format_num = self.settings.date_format

        self.pushbullet_device_index = self.get_pushbullet_index()

    def preferences(self, settings):
        if not valid_time(settings.time):
            return self.time_error
        if not valid_date(settings.date, settings.date_format):
            return self.date_error

        self.settings.dump()

        return self.ok

    '''
Ejemplo n.º 4
0
    def __init__(self, filename):
        self.filename = filename
        self.settings = Config()

        self.today_color_rgb = hex_to_rgb(self.settings.today_color)
        self.future_color_rgb = hex_to_rgb(self.settings.future_color)
        self.past_color_rgb = hex_to_rgb(self.settings.past_color)

        self.time_format = time_formats[self.settings.time_format]
        self.qt_time_format = qt_time_formats[self.settings.time_format]
        self.time_format_num = self.settings.time_format

        self.date_format = date_formats[self.settings.date_format]
        self.qt_date_format = qt_date_formats[self.settings.date_format]
        self.date_format_num = self.settings.date_format

        self.pushbullet_device_index = self.get_pushbullet_index()
Ejemplo n.º 5
0
class ReminderDialogInfo(PushbulletInfo):
    ok = 0
    time_error = 1
    date_error = 2
    file_error = 3
    notify_warn = 4

    def __init__(self, filename):
        self.filename = filename

        self.database = db.Database(self.filename)
        self.database.close()

        self.settings = Config()

        self.label = self.settings.label
        self.time = datetimeutil.time_to_local(self.settings.time)
        self.date = datetimeutil.date_to_local(self.settings.date)
        self.command = self.settings.command
        self.notes = ""
        self.popup = self.settings.popup
        self.dialog = self.settings.dialog
        self.boxcar = self.settings.boxcar_notify
        self.boxcar_ok = self.settings.boxcar_token != ''
        self.pushbullet_api_key = self.settings.pushbullet_api_key
        self.pushbullet_device = self.settings.pushbullet_device
        self.pushbullet_devices = self.settings.pushbullet_devices
        self.pushbullet_ok = self.settings.pushbullet_api_key != ''
        self.pushbullet_device_index = self.get_pushbullet_index()
        self.sound_file = self.settings.sound_file
        self.sound_length = self.settings.sound_play_length
        self.sound_loop = self.settings.sound_loop
        self.sound_loop_times = self.settings.sound_loop_times

        self.time_format = self.settings.time_format
        self.date_format = self.settings.date_format

        self.play_sound = False
        if self.sound_file is not None and not self.sound_file == "":
            self.play_sound = True

    def reminder(self, label, time, date, command, notes, popup, dialog, boxcar, play,
                sound_file, sound_length, sound_loop, pushbullet_device, delete_id, check_warning = False):
        time = datetimeutil.str_time_simplify(time)
        if time == None:
            return (self.time_error, -1)

        date = datetimeutil.str_date_simplify(date, self.settings.date_format)
        if date == None:
            return (self.date_error, -1)

        if play:
            if sound_file == None:
                return (self.file_error, -1)
            else:
                try:
                    with open(sound_file) as f: pass
                except IOError as e:
                    return (self.file_error, -1)

        if label == "" and notes == "" and check_warning and (boxcar or popup or dialog or pushbullet_device):
            return (self.notify_warn, -1)

        if not play:
            sound_file = ""
        if sound_loop:
            sound_length = 0

        r = db.Alarm(-1)
        r.set_data(label, notes, time, date, sound_file, sound_length, sound_loop,
                popup, command, boxcar, dialog, pushbullet_device)

        self.database = db.Database(self.filename)
        id = self.database.insert_alarm(r)

        if delete_id != -1:
            self.database.delete_alarm(delete_id)

        self.database.close()

        if self.pushbullet_devices_updated:
            self.settings.dump()

        return (self.ok, id)
Ejemplo n.º 6
0
class ManageWindowInfo():
    today = 0
    future = 1
    past = 2

    scheduled_format = '%Y-%m-%d %H:%M:%S'

    def __init__(self, file):
        self.file = file

        self.database = db.Database(self.file)
        self.result_list = self.database.all_alarms()
        self.database.close()

        self.settings = Config()
        self.new_news = self.settings.new_news
        self.settings.new_news = False
        self.settings.dump()

        if self.new_news == None:
            self.new_news = False
        else:
            self.new_news = bool(self.new_news)

        self.hide_indicator = self.settings.hide_indicator
        self.indicator_icon = self.settings.indicator_icon
        self.show_news = self.settings.show_news

        self.missed_reminders = []
        self.potentially_missed_reminders = {}

        try:
            scheduled_reminders = json.load(open(constants.scheduled_file))
            for reminder in scheduled_reminders:
                self.potentially_missed_reminders[reminder['id']] = datetime.strptime(reminder['date_time'], self.scheduled_format)
        except:
            logger.error('Could not load scheduled reminders')

        self.update(None, True)

    def postpone(self, id):
        self.database = db.Database(self.file)
        self.settings.load()
        alarm = self.database.alarm(id)

        message = False
        if int(alarm.id) == int(id):
            if is_time_repeating(alarm.time):
                message = True
            else:
                d = str_to_date(alarm.time, alarm.date) + timedelta(minutes=self.settings.postpone)
                alarm.time = d.strftime(internal_time_format)
                if not is_date_repeating(alarm.date):
                    alarm.date = d.strftime(internal_date_format)

                self.database.insert_alarm(alarm)
                self.database.delete_alarm(id)

        self.database.close()
        return message

    def delete(self, id):
        self.database = db.Database(self.file)
        self.database.delete_alarm(id)
        self.database.close()

    def update(self, scheduler, check_missing=False):
        self.database = db.Database(self.file)
        self.result_list = self.database.all_alarms()
        self.database.close()

        self.settings.load()
        self.new_news = self.settings.new_news
        self.settings.new_news = False
        self.settings.dump()

        if self.new_news == None:
            self.new_news = False
        else:
            self.new_news = bool(self.new_news)

        self.hide_indicator = self.settings.hide_indicator
        self.indicator_icon = self.settings.indicator_icon
        self.show_news = self.settings.show_news

        self.today_color = hex_to_rgb(self.settings.today_color)
        self.future_color = hex_to_rgb(self.settings.future_color)
        self.past_color = hex_to_rgb(self.settings.past_color)

        self.today_color_hex = self.settings.today_color
        self.future_color_hex = self.settings.future_color
        self.past_color_hex = self.settings.past_color

        self.reminder_list = []
        self.scheduled_reminders = []
        for a in self.result_list:
            dt = str_to_date(a.time, a.date)
            t = timestamp(dt)
            d = str_to_date(None, a.date)
            compare_date = str_to_date(a.time, a.date, 1).date() #check returns when reminder runs based on tomorrows date

            if scheduler != None:
                scheduler.add_reminder(a.id)

            notify = _("Yes")
            if not a.notification:
                notify = _("No")

            dialog = _("Yes")
            if not a.dialog:
                dialog = _("No")

            boxcar_notify = _("Yes")
            if not a.boxcar:
                boxcar_notify = _("No")

            pushbullet_device = 'None'
            if a.pushbullet_device != '':
                for device in self.settings.pushbullet_devices:
                    if str(device['id']) == str(a.pushbullet_device):
                        pushbullet_device = device['name']

            note = a.notes.replace("\n", "/ ")
            if len(a.notes) > 50:
                note = a.notes[:50] + "..."

            sound = _("None")
            if a.sound_file != "" and a.sound_file != None:
                sound = basename(a.sound_file)

            command = a.command
            if a.command == "" or a.command == None:
                command = _("None")

            tooltip = "%s: %s\n%s: %s\n%s: %s\nBoxcar: %s\nPushbullet: %s\n%s: %s" % (_("Sound"), sound, _("Notification"), notify, _("Dialog"), dialog, boxcar_notify, pushbullet_device, _("Command"), command)

            time_s2 = fix_time_format(a.time, self.settings.time_format)
            date_s2 = fix_date_format(a.date, self.settings.date_format)

            parent = None
            today_date = date.today()
            now_datetime = datetime.now()
            now_datetime.replace(microsecond=0)

            if dt >= now_datetime and d.date() == today_date:
                parent = self.today
            elif compare_date > today_date:
                parent = self.future
            else:
                parent = self.past

            self.reminder_list.append(ReminderInfo(a.id, a.label, time_s2, date_s2, note, tooltip, parent))

            if dt > now_datetime:
                self.scheduled_reminders.append({
                    'id': a.id,
                    'date_time': dt.strftime(self.scheduled_format)
                })

            if check_missing and a.id in self.potentially_missed_reminders:
                if dt >= self.potentially_missed_reminders[a.id] and self.potentially_missed_reminders[a.id] < now_datetime:
                    self.missed_reminders.append(a.id)

        try:
            json.dump(self.scheduled_reminders, open(constants.scheduled_file, 'w'))
        except:
            logger.error('Could not save scheduled reminders')