Move History Sync Dialog into gtk module

This commit is contained in:
Philipp Hörist 2018-07-15 02:04:03 +02:00 committed by Philipp Hörist
parent ebbe06d587
commit dd664643bd
3 changed files with 38 additions and 21 deletions

View File

@ -27,7 +27,7 @@ from gajim import accounts_window
import gajim.plugins.gui import gajim.plugins.gui
from gajim import history_window from gajim import history_window
from gajim import disco from gajim import disco
from gajim.history_sync import HistorySyncAssistant from gajim.gtk.history_sync import HistorySyncAssistant
from gajim.server_info import ServerInfoDialog from gajim.server_info import ServerInfoDialog
from gajim.gtk.mam_preferences import MamPreferences from gajim.gtk.mam_preferences import MamPreferences

View File

@ -1,17 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Philipp Hörist <philipp AT hoerist.com> # Copyright (C) 2017 Philipp Hörist <philipp AT hoerist.com>
# #
# This file is part of Gajim. # This file is part of Gajim.
# #
# Gajim is free software: you can redistribute it and/or modify # Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published
# the Free Software Foundation, either version 3 of the License, or # by the Free Software Foundation; version 3 only.
# (at your option) any later version.
# #
# Gajim is distributed in the hope that it will be useful, # Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
@ -25,8 +22,8 @@ from gi.repository import Gtk, GLib
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged
from gajim.gtkgui_helpers import get_icon_pixmap
from gajim.common.const import ArchiveState from gajim.common.const import ArchiveState
from gajim.gtk.util import load_icon
log = logging.getLogger('gajim.c.message_archiving') log = logging.getLogger('gajim.c.message_archiving')
@ -40,7 +37,7 @@ class Pages(IntEnum):
class HistorySyncAssistant(Gtk.Assistant): class HistorySyncAssistant(Gtk.Assistant):
def __init__(self, account, parent): def __init__(self, account, parent):
Gtk.Assistant.__init__(self) Gtk.Assistant.__init__(self)
self.set_title(_('Synchronise History')) # self.set_title(_('Synchronise History'))
self.set_resizable(False) self.set_resizable(False)
self.set_default_size(300, -1) self.set_default_size(300, -1)
self.set_name('HistorySyncAssistant') self.set_name('HistorySyncAssistant')
@ -103,10 +100,6 @@ class HistorySyncAssistant(Gtk.Assistant):
self.set_current_page(Pages.SUMMARY) self.set_current_page(Pages.SUMMARY)
self.summary.nothing_to_do() self.summary.nothing_to_do()
# if self.con.mam_query_ids:
# self.set_current_page(Pages.SUMMARY)
# self.summary.query_already_running()
self.show_all() self.show_all()
def hide_buttons(self): def hide_buttons(self):
@ -162,11 +155,13 @@ class HistorySyncAssistant(Gtk.Assistant):
self.set_current_page(Pages.SUMMARY) self.set_current_page(Pages.SUMMARY)
self.summary.finished() self.summary.finished()
def _nec_mam_message_received(self, obj): def _nec_mam_message_received(self, event):
if obj.conn.name != self.account: if event.conn.name != self.account:
return return
if obj.result.getAttr('queryid') != self.query_id: result = event.stanza.getTag('result')
queryid = result.getAttr('queryid')
if queryid != self.query_id:
return return
log.debug('received message') log.debug('received message')
@ -236,9 +231,8 @@ class DownloadHistoryPage(Gtk.Box):
self.count = 0 self.count = 0
self.received = 0 self.received = 0
pix = get_icon_pixmap('folder-download-symbolic', size=64) surface = load_icon('folder-download-symbolic', self, size=64)
image = Gtk.Image() image = Gtk.Image.new_from_surface(surface)
image.set_from_pixbuf(pix)
self.progress = Gtk.ProgressBar() self.progress = Gtk.ProgressBar()
self.progress.set_show_text(True) self.progress.set_show_text(True)
@ -304,7 +298,7 @@ class TimeOption(Gtk.Label):
super().__init__(label=label) super().__init__(label=label)
self.date = months self.date = months
if months: if months:
self.date = timedelta(days=30*months) self.date = timedelta(days=30 * months)
def get_delta(self): def get_delta(self):
return self.date return self.date

View File

@ -14,13 +14,36 @@
import os import os
import sys import sys
import logging
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GLib
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from gajim.common import i18n from gajim.common import i18n
from gajim.common import configpaths from gajim.common import configpaths
_icon_theme = Gtk.IconTheme.get_default()
_icon_theme.append_search_path(configpaths.get('ICONS'))
log = logging.getLogger('gajim.gtk.util')
def load_icon(icon_name, widget, size=16,
flags=Gtk.IconLookupFlags.FORCE_SIZE):
scale = widget.get_scale_factor()
if not scale:
log.warning('Could not determine scale factor')
scale = 1
try:
iconinfo = _icon_theme.lookup_icon_for_scale(
icon_name, size, scale, flags)
return iconinfo.load_surface(None)
except GLib.GError as e:
log.error('Unable to load icon %s: %s', icon_name, str(e))
def get_builder(file_name, widget=None): def get_builder(file_name, widget=None):
file_path = os.path.join(configpaths.get('GUI'), file_name) file_path = os.path.join(configpaths.get('GUI'), file_name)