From dd664643bd72281b2c777527db692f44338d3d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 15 Jul 2018 02:04:03 +0200 Subject: [PATCH] Move History Sync Dialog into gtk module --- gajim/app_actions.py | 2 +- gajim/{ => gtk}/history_sync.py | 34 ++++++++++++++------------------- gajim/gtk/util.py | 23 ++++++++++++++++++++++ 3 files changed, 38 insertions(+), 21 deletions(-) rename gajim/{ => gtk}/history_sync.py (92%) diff --git a/gajim/app_actions.py b/gajim/app_actions.py index 9e3bce2be..cc7b9763f 100644 --- a/gajim/app_actions.py +++ b/gajim/app_actions.py @@ -27,7 +27,7 @@ from gajim import accounts_window import gajim.plugins.gui from gajim import history_window 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.gtk.mam_preferences import MamPreferences diff --git a/gajim/history_sync.py b/gajim/gtk/history_sync.py similarity index 92% rename from gajim/history_sync.py rename to gajim/gtk/history_sync.py index b051030d1..09e0db981 100644 --- a/gajim/history_sync.py +++ b/gajim/gtk/history_sync.py @@ -1,17 +1,14 @@ -# -*- coding: utf-8 -*- -# # Copyright (C) 2017 Philipp Hörist # # This file is part of Gajim. # -# Gajim is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. # # Gajim is distributed in the hope that it will be useful, # 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. # # 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 ged -from gajim.gtkgui_helpers import get_icon_pixmap from gajim.common.const import ArchiveState +from gajim.gtk.util import load_icon log = logging.getLogger('gajim.c.message_archiving') @@ -40,7 +37,7 @@ class Pages(IntEnum): class HistorySyncAssistant(Gtk.Assistant): def __init__(self, account, parent): Gtk.Assistant.__init__(self) - self.set_title(_('Synchronise History')) + # self.set_title(_('Synchronise History')) self.set_resizable(False) self.set_default_size(300, -1) self.set_name('HistorySyncAssistant') @@ -103,10 +100,6 @@ class HistorySyncAssistant(Gtk.Assistant): self.set_current_page(Pages.SUMMARY) 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() def hide_buttons(self): @@ -162,11 +155,13 @@ class HistorySyncAssistant(Gtk.Assistant): self.set_current_page(Pages.SUMMARY) self.summary.finished() - def _nec_mam_message_received(self, obj): - if obj.conn.name != self.account: + def _nec_mam_message_received(self, event): + if event.conn.name != self.account: return - if obj.result.getAttr('queryid') != self.query_id: + result = event.stanza.getTag('result') + queryid = result.getAttr('queryid') + if queryid != self.query_id: return log.debug('received message') @@ -236,9 +231,8 @@ class DownloadHistoryPage(Gtk.Box): self.count = 0 self.received = 0 - pix = get_icon_pixmap('folder-download-symbolic', size=64) - image = Gtk.Image() - image.set_from_pixbuf(pix) + surface = load_icon('folder-download-symbolic', self, size=64) + image = Gtk.Image.new_from_surface(surface) self.progress = Gtk.ProgressBar() self.progress.set_show_text(True) @@ -304,7 +298,7 @@ class TimeOption(Gtk.Label): super().__init__(label=label) self.date = months if months: - self.date = timedelta(days=30*months) + self.date = timedelta(days=30 * months) def get_delta(self): return self.date diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py index 8c5636414..c736f0f24 100644 --- a/gajim/gtk/util.py +++ b/gajim/gtk/util.py @@ -14,13 +14,36 @@ import os import sys +import logging from gi.repository import Gtk +from gi.repository import GLib import xml.etree.ElementTree as ET from gajim.common import i18n 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): file_path = os.path.join(configpaths.get('GUI'), file_name)