Commit 4e2f00e5 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Move ManageProxies into own module

parent c109db6e
......@@ -21,7 +21,6 @@
from gajim.common import helpers
from gajim.common.app import interface
from gajim.common.exceptions import GajimGeneralException
from gajim import config
from gajim import dialogs
from gajim import disco
......@@ -44,6 +43,7 @@
from gajim.gtk.account_wizard import AccountCreationWizard
from gajim.gtk.history import HistoryWindow
from gajim.gtk.accounts import AccountsWindow
from gajim.gtk.proxies import ManageProxies
# General Actions
......@@ -252,7 +252,7 @@ def on_manage_proxies(action, param):
app.interface.instances['manage_proxies'].window.present()
else:
app.interface.instances['manage_proxies'] = \
config.ManageProxiesWindow(interface.roster.window)
ManageProxies(interface.roster.window)
# Admin Actions
......
......@@ -47,254 +47,6 @@
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import InputDialog
#---------- ManageProxiesWindow class -------------#
class ManageProxiesWindow:
def __init__(self, transient_for=None):
self.xml = gtkgui_helpers.get_gtk_builder('manage_proxies_window.ui')
self.window = self.xml.get_object('manage_proxies_window')
self.window.set_transient_for(transient_for)
self.proxies_treeview = self.xml.get_object('proxies_treeview')
self.proxyname_entry = self.xml.get_object('proxyname_entry')
self.proxytype_combobox = self.xml.get_object('proxytype_combobox')
self.init_list()
self.block_signal = False
self.xml.connect_signals(self)
self.window.show_all()
# hide the BOSH fields by default
self.show_bosh_fields()
def show_bosh_fields(self, show=True):
if show:
self.xml.get_object('boshuri_entry').show()
self.xml.get_object('boshuri_label').show()
self.xml.get_object('boshuseproxy_checkbutton').show()
else:
cb = self.xml.get_object('boshuseproxy_checkbutton')
cb.hide()
cb.set_active(True)
self.on_boshuseproxy_checkbutton_toggled(cb)
self.xml.get_object('boshuri_entry').hide()
self.xml.get_object('boshuri_label').hide()
def fill_proxies_treeview(self):
model = self.proxies_treeview.get_model()
model.clear()
iter_ = model.append()
model.set(iter_, 0, _('None'))
for p in app.config.get_per('proxies'):
iter_ = model.append()
model.set(iter_, 0, p)
def init_list(self):
self.xml.get_object('remove_proxy_button').set_sensitive(False)
self.proxytype_combobox.set_sensitive(False)
self.xml.get_object('proxy_table').set_sensitive(False)
model = Gtk.ListStore(str)
self.proxies_treeview.set_model(model)
col = Gtk.TreeViewColumn('Proxies')
self.proxies_treeview.append_column(col)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', 0)
self.fill_proxies_treeview()
self.xml.get_object('proxytype_combobox').set_active(0)
def on_manage_proxies_window_destroy(self, widget):
window = app.get_app_window('AccountsWindow')
if window is not None:
window.update_proxy_list()
del app.interface.instances['manage_proxies']
def on_add_proxy_button_clicked(self, widget):
model = self.proxies_treeview.get_model()
proxies = app.config.get_per('proxies')
i = 1
while 'proxy' + str(i) in proxies:
i += 1
iter_ = model.append()
model.set(iter_, 0, 'proxy' + str(i))
app.config.add_per('proxies', 'proxy' + str(i))
self.proxies_treeview.set_cursor(model.get_path(iter_))
def on_remove_proxy_button_clicked(self, widget):
sel = self.proxies_treeview.get_selection()
if not sel:
return
(model, iter_) = sel.get_selected()
if not iter_:
return
proxy = model[iter_][0]
model.remove(iter_)
app.config.del_per('proxies', proxy)
self.xml.get_object('remove_proxy_button').set_sensitive(False)
self.block_signal = True
self.on_proxies_treeview_cursor_changed(self.proxies_treeview)
self.block_signal = False
def on_close_button_clicked(self, widget):
self.window.destroy()
def on_useauth_checkbutton_toggled(self, widget):
if self.block_signal:
return
act = widget.get_active()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'useauth', act)
self.xml.get_object('proxyuser_entry').set_sensitive(act)
self.xml.get_object('proxypass_entry').set_sensitive(act)
def on_boshuseproxy_checkbutton_toggled(self, widget):
if self.block_signal:
return
act = widget.get_active()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'bosh_useproxy', act)
self.xml.get_object('proxyhost_entry').set_sensitive(act)
self.xml.get_object('proxyport_entry').set_sensitive(act)
def on_proxies_treeview_cursor_changed(self, widget):
#FIXME: check if off proxy settings are correct (see
# http://trac.gajim.org/changeset/1921#file2 line 1221
proxyhost_entry = self.xml.get_object('proxyhost_entry')
proxyport_entry = self.xml.get_object('proxyport_entry')
proxyuser_entry = self.xml.get_object('proxyuser_entry')
proxypass_entry = self.xml.get_object('proxypass_entry')
boshuri_entry = self.xml.get_object('boshuri_entry')
useauth_checkbutton = self.xml.get_object('useauth_checkbutton')
boshuseproxy_checkbutton = self.xml.get_object('boshuseproxy_checkbutton')
self.block_signal = True
proxyhost_entry.set_text('')
proxyport_entry.set_text('')
proxyuser_entry.set_text('')
proxypass_entry.set_text('')
boshuri_entry.set_text('')
#boshuseproxy_checkbutton.set_active(False)
#self.on_boshuseproxy_checkbutton_toggled(boshuseproxy_checkbutton)
#useauth_checkbutton.set_active(False)
#self.on_useauth_checkbutton_toggled(useauth_checkbutton)
sel = widget.get_selection()
if sel:
(model, iter_) = sel.get_selected()
else:
iter_ = None
if not iter_:
self.xml.get_object('proxyname_entry').set_text('')
self.xml.get_object('proxytype_combobox').set_sensitive(False)
self.xml.get_object('proxy_table').set_sensitive(False)
self.block_signal = False
return
proxy = model[iter_][0]
self.xml.get_object('proxyname_entry').set_text(proxy)
if proxy == _('None'): # special proxy None
self.show_bosh_fields(False)
self.proxyname_entry.set_editable(False)
self.xml.get_object('remove_proxy_button').set_sensitive(False)
self.xml.get_object('proxytype_combobox').set_sensitive(False)
self.xml.get_object('proxy_table').set_sensitive(False)
else:
proxytype = app.config.get_per('proxies', proxy, 'type')
self.show_bosh_fields(proxytype == 'bosh')
self.proxyname_entry.set_editable(True)
self.xml.get_object('remove_proxy_button').set_sensitive(True)
self.xml.get_object('proxytype_combobox').set_sensitive(True)
self.xml.get_object('proxy_table').set_sensitive(True)
proxyhost_entry.set_text(app.config.get_per('proxies', proxy,
'host'))
proxyport_entry.set_text(str(app.config.get_per('proxies',
proxy, 'port')))
proxyuser_entry.set_text(app.config.get_per('proxies', proxy,
'user'))
proxypass_entry.set_text(app.config.get_per('proxies', proxy,
'pass'))
boshuri_entry.set_text(app.config.get_per('proxies', proxy,
'bosh_uri'))
types = ['http', 'socks5', 'bosh']
self.proxytype_combobox.set_active(types.index(proxytype))
boshuseproxy_checkbutton.set_active(
app.config.get_per('proxies', proxy, 'bosh_useproxy'))
useauth_checkbutton.set_active(
app.config.get_per('proxies', proxy, 'useauth'))
self.block_signal = False
def on_proxies_treeview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_Delete:
self.on_remove_proxy_button_clicked(widget)
def on_proxyname_entry_changed(self, widget):
if self.block_signal:
return
sel = self.proxies_treeview.get_selection()
if not sel:
return
(model, iter_) = sel.get_selected()
if not iter_:
return
old_name = model.get_value(iter_, 0)
new_name = widget.get_text()
if new_name == '':
return
if new_name == old_name:
return
config = app.config.get_per('proxies', old_name)
app.config.del_per('proxies', old_name)
app.config.add_per('proxies', new_name)
for option in config:
app.config.set_per('proxies', new_name, option, config[option])
model.set_value(iter_, 0, new_name)
def on_proxytype_combobox_changed(self, widget):
if self.block_signal:
return
types = ['http', 'socks5', 'bosh']
type_ = self.proxytype_combobox.get_active()
self.show_bosh_fields(types[type_] == 'bosh')
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'type', types[type_])
def on_proxyhost_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'host', value)
def on_proxyport_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'port', value)
def on_proxyuser_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'user', value)
def on_boshuri_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'bosh_uri', value)
def on_proxypass_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'pass', value)
class FakeDataForm(Gtk.Table):
"""
......
......@@ -30,12 +30,11 @@
from gajim import dataforms_widget
from gajim import gui_menu_builder
from gajim.config import ManageProxiesWindow
from gajim.config import FakeDataForm
from gajim.gtk.util import get_builder
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.proxies import ManageProxies
class AccountCreationWizard:
......@@ -352,8 +351,7 @@ def on_manage_proxies_button_clicked(self, widget):
if 'manage_proxies' in app.interface.instances:
app.interface.instances['manage_proxies'].window.present()
else:
app.interface.instances['manage_proxies'] = \
ManageProxiesWindow()
app.interface.instances['manage_proxies'] = ManageProxies()
def on_custom_host_port_checkbutton_toggled(self, widget):
self.xml.get_object('custom_host_hbox').set_sensitive(
......
......@@ -31,7 +31,6 @@
from gajim.chat_control_base import ChatControlBase
from gajim.config import ManageProxiesWindow
from gajim.config import ManageSoundsWindow
from gajim.gtk.util import get_builder
......@@ -39,6 +38,7 @@
from gajim.gtk.dialogs import AspellDictError
from gajim.gtk.themes import Themes
from gajim.gtk.advanced_config import AdvancedConfig
from gajim.gtk.proxies import ManageProxies
try:
from gajim.common.multimedia_helpers import AudioInputManager, AudioOutputManager
......@@ -1024,7 +1024,7 @@ def on_manage_proxies_button_clicked(self, widget):
if 'manage_proxies' in app.interface.instances:
app.interface.instances['manage_proxies'].window.present()
else:
app.interface.instances['manage_proxies'] = ManageProxiesWindow(self)
app.interface.instances['manage_proxies'] = ManageProxies(self)
def update_proxy_list(self):
our_proxy = app.config.get('global_proxy')
......
# 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; 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
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from gi.repository import Gtk
from gi.repository import Gdk
from gajim.common import app
from gajim.common.i18n import _
from gajim.gtk.util import get_builder
class ManageProxies:
def __init__(self, transient_for=None):
self._ui = get_builder('manage_proxies_window.ui')
self.window = self._ui.manage_proxies_window
self.window.set_transient_for(transient_for)
self.init_list()
self.block_signal = False
self._ui.connect_signals(self)
self.window.show_all()
# hide the BOSH fields by default
self.show_bosh_fields()
def show_bosh_fields(self, show=True):
if show:
self._ui.boshuri_entry.show()
self._ui.boshuri_label.show()
self._ui.boshuseproxy_checkbutton.show()
else:
cb = self._ui.boshuseproxy_checkbutton
cb.hide()
cb.set_active(True)
self.on_boshuseproxy_checkbutton_toggled(cb)
self._ui.boshuri_entry.hide()
self._ui.boshuri_label.hide()
def fill_proxies_treeview(self):
model = self._ui.proxies_treeview.get_model()
model.clear()
iter_ = model.append()
model.set(iter_, 0, _('None'))
for proxy in app.config.get_per('proxies'):
iter_ = model.append()
model.set(iter_, 0, proxy)
def init_list(self):
self._ui.remove_proxy_button.set_sensitive(False)
self._ui.proxytype_combobox.set_sensitive(False)
self._ui.proxy_table.set_sensitive(False)
model = Gtk.ListStore(str)
self._ui.proxies_treeview.set_model(model)
col = Gtk.TreeViewColumn('Proxies')
self._ui.proxies_treeview.append_column(col)
renderer = Gtk.CellRendererText()
col.pack_start(renderer, True)
col.add_attribute(renderer, 'text', 0)
self.fill_proxies_treeview()
self._ui.proxytype_combobox.set_active(0)
def on_manage_proxies_window_destroy(self, _widget):
window = app.get_app_window('AccountsWindow')
if window is not None:
window.update_proxy_list()
del app.interface.instances['manage_proxies']
def on_add_proxy_button_clicked(self, _widget):
model = self._ui.proxies_treeview.get_model()
proxies = app.config.get_per('proxies')
i = 1
while 'proxy' + str(i) in proxies:
i += 1
iter_ = model.append()
model.set(iter_, 0, 'proxy' + str(i))
app.config.add_per('proxies', 'proxy' + str(i))
self._ui.proxies_treeview.set_cursor(model.get_path(iter_))
def on_remove_proxy_button_clicked(self, _widget):
sel = self._ui.proxies_treeview.get_selection()
if not sel:
return
(model, iter_) = sel.get_selected()
if not iter_:
return
proxy = model[iter_][0]
model.remove(iter_)
app.config.del_per('proxies', proxy)
self._ui.remove_proxy_button.set_sensitive(False)
self.block_signal = True
self.on_proxies_treeview_cursor_changed(self._ui.proxies_treeview)
self.block_signal = False
def on_close_button_clicked(self, _widget):
self.window.destroy()
def on_useauth_checkbutton_toggled(self, widget):
if self.block_signal:
return
act = widget.get_active()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'useauth', act)
self._ui.proxyuser_entry.set_sensitive(act)
self._ui.proxypass_entry.set_sensitive(act)
def on_boshuseproxy_checkbutton_toggled(self, widget):
if self.block_signal:
return
act = widget.get_active()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'bosh_useproxy', act)
self._ui.proxyhost_entry.set_sensitive(act)
self._ui.proxyport_entry.set_sensitive(act)
def on_proxies_treeview_cursor_changed(self, widget):
#FIXME: check if off proxy settings are correct (see
# http://trac.gajim.org/changeset/1921#file2 line 1221
self.block_signal = True
self._ui.proxyhost_entry.set_text('')
self._ui.proxyport_entry.set_text('')
self._ui.proxyuser_entry.set_text('')
self._ui.proxypass_entry.set_text('')
self._ui.boshuri_entry.set_text('')
sel = widget.get_selection()
if sel:
(model, iter_) = sel.get_selected()
else:
iter_ = None
if not iter_:
self._ui.proxyname_entry.set_text('')
self._ui.proxytype_combobox.set_sensitive(False)
self._ui.proxy_table.set_sensitive(False)
self.block_signal = False
return
proxy = model[iter_][0]
self._ui.proxyname_entry.set_text(proxy)
if proxy == _('None'): # special proxy None
self.show_bosh_fields(False)
self._ui.proxyname_entry.set_editable(False)
self._ui.remove_proxy_button.set_sensitive(False)
self._ui.proxytype_combobox.set_sensitive(False)
self._ui.proxy_table.set_sensitive(False)
else:
proxytype = app.config.get_per('proxies', proxy, 'type')
self.show_bosh_fields(proxytype == 'bosh')
self._ui.proxyname_entry.set_editable(True)
self._ui.remove_proxy_button.set_sensitive(True)
self._ui.proxytype_combobox.set_sensitive(True)
self._ui.proxy_table.set_sensitive(True)
self._ui.proxyhost_entry.set_text(
app.config.get_per('proxies', proxy, 'host'))
self._ui.proxyport_entry.set_text(
str(app.config.get_per('proxies', proxy, 'port')))
self._ui.proxyuser_entry.set_text(
app.config.get_per('proxies', proxy, 'user'))
self._ui.proxypass_entry.set_text(
app.config.get_per('proxies', proxy, 'pass'))
self._ui.boshuri_entry.set_text(
app.config.get_per('proxies', proxy, 'bosh_uri'))
types = ['http', 'socks5', 'bosh']
self._ui.proxytype_combobox.set_active(types.index(proxytype))
self._ui.boshuseproxy_checkbutton.set_active(
app.config.get_per('proxies', proxy, 'bosh_useproxy'))
self._ui.useauth_checkbutton.set_active(
app.config.get_per('proxies', proxy, 'useauth'))
self.block_signal = False
def on_proxies_treeview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_Delete:
self.on_remove_proxy_button_clicked(widget)
def on_proxyname_entry_changed(self, widget):
if self.block_signal:
return
sel = self._ui.proxies_treeview.get_selection()
if not sel:
return
(model, iter_) = sel.get_selected()
if not iter_:
return
old_name = model.get_value(iter_, 0)
new_name = widget.get_text()
if new_name == '':
return
if new_name == old_name:
return
config = app.config.get_per('proxies', old_name)
app.config.del_per('proxies', old_name)
app.config.add_per('proxies', new_name)
for option in config:
app.config.set_per('proxies', new_name, option, config[option])
model.set_value(iter_, 0, new_name)
def on_proxytype_combobox_changed(self, _widget):
if self.block_signal:
return
types = ['http', 'socks5', 'bosh']
type_ = self._ui.proxytype_combobox.get_active()
self.show_bosh_fields(types[type_] == 'bosh')
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'type', types[type_])
def on_proxyhost_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'host', value)
def on_proxyport_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'port', value)
def on_proxyuser_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'user', value)
def on_boshuri_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'bosh_uri', value)
def on_proxypass_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text()
proxy = self._ui.proxyname_entry.get_text()
app.config.set_per('proxies', proxy, 'pass', value)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment