Пример #1
0
    def _change_date(self, widget):
        # Get day selected in calendar
        y, m, d = self._ui.calendar.get_date()
        py_m = python_month(m)
        _date = datetime.datetime(y, py_m, d)

        if widget is self._ui.button_first_day:
            gtk_m = gtk_month(self.first_day.month)
            self._ui.calendar.select_month(gtk_m, self.first_day.year)
            self._ui.calendar.select_day(self.first_day.day)
            return

        if widget is self._ui.button_last_day:
            gtk_m = gtk_month(
                self.last_day.month)
            self._ui.calendar.select_month(gtk_m, self.last_day.year)
            self._ui.calendar.select_day(self.last_day.day)
            return

        if widget is self._ui.button_previous_day:
            end_date = self.first_day
            timedelta = datetime.timedelta(days=-1)
            if end_date >= _date:
                return
        elif widget is self._ui.button_next_day:
            end_date = self.last_day
            timedelta = datetime.timedelta(days=1)
            if end_date <= _date:
                return

        # Iterate through days until log entry found or
        # supplied end_date (first_log / last_log) reached
        logs = None
        while logs is None:
            _date = _date + timedelta
            if _date == end_date:
                break
            try:
                logs = app.logger.get_date_has_logs(
                    self.account, self.jid, _date)
            except exceptions.PysqliteOperationalError as e:
                ErrorDialog(_('Disk Error'), str(e))
                return

        gtk_m = gtk_month(_date.month)
        self._ui.calendar.select_month(gtk_m, _date.year)
        self._ui.calendar.select_day(_date.day)
Пример #2
0
    def on_results_treeview_cursor_changed(self, *args):
        """
        A row was selected, get date from row, and select it in calendar
        which results to showing conversation logs for that date
        """
        if self.clearing_search:
            return

        # get currently selected date
        cur_year, cur_month, cur_day = self._ui.calendar.get_date()
        cur_month = python_month(cur_month)
        model, paths = self._ui.results_treeview.get_selection(
        ).get_selected_rows()

        if not paths:
            return

        path = paths[0]
        # make it a tuple (Y, M, D, 0, 0, 0...)
        tim = time.strptime(model[path][Column.UNIXTIME], '%Y-%m-%d')
        year = tim[0]
        gtk_m = tim[1]
        month = gtk_month(gtk_m)
        day = tim[2]

        # switch to belonging logfile if necessary
        log_jid = model[path][Column.LOG_JID]
        if log_jid != self.jid:
            self._load_history(log_jid, None)

        # avoid reruning mark days algo if same month and year!
        if year != cur_year or gtk_m != cur_month:
            self._ui.calendar.select_month(month, year)

        if year != cur_year or gtk_m != cur_month or day != cur_day:
            self._ui.calendar.select_day(day)

        self._scroll_to_message_and_highlight(model[path][Column.LOG_LINE_ID])
Пример #3
0
    def _load_history(self, jid_or_name, account=None):
        """
        Load history for the given jid/name and show it
        """
        if jid_or_name and jid_or_name in self.completion_dict:
            # a full qualified jid or a contact name was entered
            info_jid, info_account, _info_name, info_completion = self.completion_dict[jid_or_name]
            self.jids_to_search = [info_jid]
            self.jid = info_jid

            if account:
                self.account = account
            else:
                self.account = info_account
            if self.account is None:
                # We don't know account. Probably a gc not opened or an
                # account not connected.
                # Disable possibility to say if we want to log or not
                self._ui.log_history_checkbutton.set_sensitive(False)
            else:
                # Are log disabled for account ?
                if self.account in app.config.get_per(
                        'accounts', self.account, 'no_log_for').split(' '):
                    self._ui.log_history_checkbutton.set_active(False)
                    self._ui.log_history_checkbutton.set_sensitive(False)
                else:
                    # Are log disabled for jid ?
                    log = True
                    if self.jid in app.config.get_per(
                            'accounts', self.account, 'no_log_for').split(' '):
                        log = False
                    self._ui.log_history_checkbutton.set_active(log)
                    self._ui.log_history_checkbutton.set_sensitive(True)

            self.jids_to_search = [info_jid]

            # Get first/last date we have logs with contact
            self.first_log = app.logger.get_first_date_that_has_logs(
                self.account, self.jid)
            self.first_day = self._get_date_from_timestamp(self.first_log)
            self.last_log = app.logger.get_last_date_that_has_logs(
                self.account, self.jid)
            self.last_day = self._get_date_from_timestamp(self.last_log)

            # Select logs for last date we have logs with contact
            self._ui.search_menu_button.set_sensitive(True)
            month = gtk_month(self.last_day.month)
            self._ui.calendar.select_month(month, self.last_day.year)
            self._ui.calendar.select_day(self.last_day.day)

            self._ui.button_previous_day.set_sensitive(True)
            self._ui.button_next_day.set_sensitive(True)
            self._ui.button_first_day.set_sensitive(True)
            self._ui.button_last_day.set_sensitive(True)

            self._ui.search_entry.set_sensitive(True)
            self._ui.search_entry.grab_focus()

            self._ui.query_entry.get_child().set_text(info_completion)

        else:
            # neither a valid jid, nor an existing contact name was entered
            # we have got nothing to show or to search in
            self.jid = None
            self.account = None

            self.history_buffer.set_text('')  # clear the buffer
            self._ui.search_entry.set_sensitive(False)

            self._ui.log_history_checkbutton.set_sensitive(False)
            self._ui.search_menu_button.set_sensitive(False)
            self._ui.calendar.clear_marks()
            self._ui.button_previous_day.set_sensitive(False)
            self._ui.button_next_day.set_sensitive(False)
            self._ui.button_first_day.set_sensitive(False)
            self._ui.button_last_day.set_sensitive(False)

            self._ui.results_scrolledwindow.set_property('visible', False)