# Copyright (C) 2003, 2004 Konstantin Korikov
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import qt
import os
import chestnut_dialer
import chestnut_dialer.config
from chestnut_dialer import _
import chestnut_dialer.qt_ui.accountsconfbox
import chestnut_dialer.qt_ui.editaccountdialog
import chestnut_dialer.qt_ui.optionsdialog
import chestnut_dialer.qt_ui.editdefaccountdialog
import chestnut_dialer.qt_ui.connectinglog
from chestnut_dialer.account_set import NoAccountException
class EditAccountBaseControl:
acc = None
attr_name = None
cont = None
control_name = None
clr = None
clear_radio = None
nclear_radio = None
def_acc = None
def_toggle = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
self.acc = acc
self.cont = cont
self.control_name = control_name
self.attr_name = attr_name
self.clr = clr
if self.clr:
self.clear_radio = getattr(self.cont, self.control_name + 'Clr')
self.nclear_radio = getattr(self.cont, self.control_name + 'NotClr')
qt.QObject.connect(self.clear_radio, qt.SIGNAL("toggled(bool)"), self.clear_event)
qt.QObject.connect(self.nclear_radio, qt.SIGNAL("toggled(bool)"), self.notclear_event)
self.def_acc = def_acc
if self.def_acc != None:
self.def_toggle = getattr(self.cont, self.control_name + 'DefToggle')
qt.QObject.connect(self.def_toggle, qt.SIGNAL("toggled(bool)"), self.def_toggled_event)
def acc_get_value(self):
return self.acc[self.attr_name]
def acc_set_value(self, value):
self.acc[self.attr_name] = value
def wid_get_value(self):
pass
def wid_set_value(self, value):
pass
def load_value(self):
v = self.acc_get_value()
if v == None:
if self.def_acc != None:
self.def_toggle.setOn(1)
else:
self.wid_set_value(self.get_clear_value())
if self.clr: self.clear_radio.setOn(1)
else:
if self.clr and v == self.get_clear_value():
self.clear_radio.setOn(1)
else:
self.wid_set_value(v)
if self.clr: self.nclear_radio.setOn(1)
def save_value(self):
if self.def_acc != None and self.def_toggle.isOn():
self.acc_set_value(None)
else:
self.acc_set_value(self.wid_get_value())
def get_clear_value(self):
return 0
def clear_event(self, on):
if on:
self.wid_set_value(self.get_clear_value())
self.set_sensitive(0)
def notclear_event(self, on):
if on and not (self.def_acc != None and self.def_toggle.isOn()):
self.set_sensitive(1)
def def_toggled_event(self, on):
if on:
def_v = self.def_acc[self.attr_name]
self.wid_set_value(def_v)
self.set_sensitive(0)
if self.clr:
if def_v == self.get_clear_value():
self.clear_radio.setOn(1)
else:
self.nclear_radio.setOn(1)
self.clear_radio.setEnabled(0)
self.nclear_radio.setEnabled(0)
else:
if self.clr:
self.clear_radio.setEnabled(1)
self.nclear_radio.setEnabled(1)
self.set_sensitive(not (self.clr and self.clear_radio.isOn()))
class EditAccountEntryControl(EditAccountBaseControl):
entry = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.entry = getattr(self.cont, control_name + 'Entry')
def set_sensitive(self, sens):
self.entry.setEnabled(sens)
def wid_set_value(self, value):
self.entry.setText(value)
def wid_get_value(self):
return unicode(self.entry.text())
def get_clear_value(self):
return ""
class EditAccountSpinControl(EditAccountBaseControl):
spin = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.spin = getattr(self.cont, control_name + 'Spin')
def set_sensitive(self, sens):
self.spin.setEnabled(sens)
def wid_set_value(self, value):
self.spin.setValue(int(value))
def wid_get_value(self):
return self.spin.value()
class EditAccountListControl(EditAccountBaseControl):
lst = None
entry = None
add_btn = None
del_btn = None
up_btn = None
down_btn = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.lst = getattr(self.cont, control_name + 'List')
qt.QObject.connect(self.lst, qt.SIGNAL("currentChanged(QListBoxItem*)"),
self.select_event)
self.entry = getattr(self.cont, control_name + 'Entry')
self.add_btn = getattr(self.cont, control_name + 'AddButton')
self.del_btn = getattr(self.cont, control_name + 'RemoveButton')
try:
self.up_btn = getattr(self.cont, control_name + 'Up')
self.down_btn = getattr(self.cont, control_name + 'Down')
except AttributeError: pass
qt.QObject.connect(self.add_btn, qt.SIGNAL("clicked()"), self.add_action)
qt.QObject.connect(self.del_btn, qt.SIGNAL("clicked()"), self.remove_action)
if self.up_btn and self.down_btn:
qt.QObject.connect(self.up_btn, qt.SIGNAL("clicked()"), self.up_action)
qt.QObject.connect(self.down_btn, qt.SIGNAL("clicked()"), self.down_action)
def select_event(self, item):
self.entry.setText(item and item.text() or "")
def add_action(self):
self.lst.insertItem(self.entry.text())
self.entry.setText("")
def remove_action(self):
self.lst.removeItem(self.lst.currentItem())
def up_action(self):
i = self.lst.currentItem()
if i > 0:
v = self.lst.currentText()
self.lst.removeItem(i)
self.lst.insertItem(v, i - 1)
self.lst.setCurrentItem(i - 1)
def down_action(self):
i = self.lst.currentItem() + 1
if i > 0 and i < self.lst.count():
v = self.lst.currentText()
self.lst.removeItem(i - 1)
self.lst.insertItem(v, i)
self.lst.setCurrentItem(i)
def wid_set_value(self, value):
self.lst.clear()
for i in value: self.lst.insertItem(i)
self.entry.setText("")
def wid_get_value(self):
value = []
i = self.lst.firstItem()
while i:
value.append(unicode(i.text()))
i = i.next()
return tuple(value)
def set_sensitive(self, sens):
self.lst.setEnabled(sens)
self.add_btn.setEnabled(sens)
self.del_btn.setEnabled(sens)
if self.up_btn and self.down_btn:
self.up_btn.setEnabled(sens)
self.down_btn.setEnabled(sens)
self.entry.setEnabled(sens)
if not sens: self.entry.setText("")
def get_clear_value(self):
return ()
class EditAccountOptionControl(EditAccountBaseControl):
option = None
items = None
def __init__(self, acc, cont, control_name, attr_name, items,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.option = getattr(self.cont, control_name + 'Option')
self.items = items
def wid_set_value(self, value):
try: self.option.setCurrentItem(self.items.index(value))
except ValueError: pass
def wid_get_value(self):
return self.items[self.option.currentItem()]
def set_sensitive(self, sens):
self.option.setEnabled(sens)
def get_clear_value(self):
return self.items[0]
class EditAccountComboControl(EditAccountBaseControl):
combo = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.combo = getattr(self.cont, control_name + 'Combo')
def wid_set_value(self, value):
self.combo.setCurrentText(value)
def wid_get_value(self):
return unicode(self.combo.currentText())
def set_sensitive(self, sens):
self.combo.setEnabled(sens)
def get_clear_value(self):
return ""
class EditAccountCheckControl(EditAccountBaseControl):
check = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.check = getattr(self.cont, control_name + 'Check')
def set_sensitive(self, sens):
self.check.setEnabled(sens)
def wid_set_value(self, value):
self.check.setOn(value)
def wid_get_value(self):
return self.check.isOn()
class EditAccountCheckGroupControl(EditAccountBaseControl):
items = None
group = None
def __init__(self, acc, cont, control_name, attr_name,
items, clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.items = items
self.group = []
for i in range(0, len(items)):
self.group.append(getattr(self.cont, control_name + 'Check' + str(i)))
def set_sensitive(self, sens):
for w in self.group: w.setEnabled(sens)
def wid_set_value(self, value):
for i in range(len(self.items)):
self.group[i].setOn(self.items[i] in value)
def wid_get_value(self):
value = []
for i in range(0, len(self.items)):
if self.group[i].isOn(): value.append(self.items[i])
return tuple(value)
class EditAccountScaleControl(EditAccountBaseControl):
scale = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.scale = getattr(self.cont, control_name + 'Scale')
def set_sensitive(self, sens):
self.scale.setEnabled(sens)
def wid_set_value(self, value):
self.scale.setValue(value)
def wid_get_value(self):
return self.scale.value()
class EditAccountTextControl(EditAccountBaseControl):
text = None
def __init__(self, acc, cont, control_name, attr_name,
clr = 0, def_acc = None):
EditAccountBaseControl.__init__(self, acc, cont,
control_name, attr_name, clr, def_acc)
self.text = getattr(self.cont, control_name + 'Text')
def set_sensitive(self, sens):
self.text.setEnabled(sens)
def wid_set_value(self, value):
self.text.setText(value)
def wid_get_value(self):
return unicode(self.text.text())
def get_clear_value(self):
return ""
class EditAccountDialog(chestnut_dialer.qt_ui.editaccountdialog.EditAccountDialog):
controls = None
update_list_action = None
show_help = None
acc = None
acc_real = None
def __init__(self, acc, def_acc, update_list_action,
show_help, *args):
apply(chestnut_dialer.qt_ui.editaccountdialog.EditAccountDialog.__init__,
(self,) + args)
self.acc = acc.copy()
self.acc_real = acc
acc = self.acc
def_acc = def_acc.copy()
self.update_list_action = update_list_action
self.show_help = show_help
self.setCaption(_("Account") + " - " + acc['name'])
self.controls = [
EditAccountEntryControl( acc, self, 'AccountName', 'name'),
EditAccountListControl( acc, self, 'PhoneNumber', 'phone_numbers'),
EditAccountEntryControl( acc, self, 'DialPrefix', 'dial_prefix', 0, def_acc),
EditAccountSpinControl( acc, self, 'Redial', 'redial_attempts', 1, def_acc),
EditAccountCheckControl( acc, self, 'RedialAuto', 'redial_auto', 0, def_acc),
EditAccountSpinControl( acc, self, 'MinSpeed', 'min_speed', 0, def_acc),
EditAccountCheckGroupControl(acc,self,'RedialIf', 'redial_if',
['no-dialtone', 'auth-fail'], 0, def_acc),
EditAccountSpinControl( acc, self, 'ModemTimeout', 'modem_timeout', 0, def_acc),
EditAccountSpinControl( acc, self, 'Timeout', 'dial_timeout', 0, def_acc),
EditAccountSpinControl( acc, self, 'PPPTimeout', 'ppp_timeout', 0, def_acc),
EditAccountSpinControl( acc, self, 'PromptTimeout', 'prompt_timeout', 0, def_acc),
EditAccountTextControl( acc, self, 'Comment', 'comment'),
EditAccountOptionControl( acc, self, 'AuthType', 'auth_type',
['pap/chap', 'term']),
EditAccountOptionControl( acc, self, 'UseScript', 'use_script',
['predef-noterm', 'predef-term', 'predef-auto', 'dialin', 'custom', 'none']),
EditAccountEntryControl( acc, self, 'Login', 'user'),
EditAccountEntryControl( acc, self, 'Password', 'passwd'),
EditAccountCheckControl( acc, self, 'AskPassword', 'ask_passwd', 0, def_acc),
EditAccountCheckControl( acc, self, 'UsePasswordfd', 'use_passwordfd', 0, def_acc),
EditAccountEntryControl( acc, self, 'RemoteName', 'remotename', 0, def_acc),
EditAccountEntryControl( acc, self, 'ChatLoginPrompt', 'chat_login_prompt', 0, def_acc),
EditAccountEntryControl( acc, self, 'ChatPasswordPrompt','chat_passwd_prompt', 0, def_acc),
EditAccountTextControl( acc, self, 'ChatScript', 'chat_script', 0, def_acc),
EditAccountEntryControl( acc, self, 'LocalIP', 'ip', 1, def_acc),
EditAccountEntryControl( acc, self, 'NetMask', 'mask', 1, def_acc),
EditAccountEntryControl( acc, self, 'RemoteIP', 'remote', 1, def_acc),
EditAccountListControl( acc, self, 'DNSServer', 'dns_servers', 1, def_acc),
EditAccountComboControl( acc, self, 'Device', 'device', 0, def_acc),
EditAccountOptionControl( acc, self, 'Speed', 'speed',
['115200', '57600', '38400', '19200', '9600', '4800', '2400', '1200'], 0, def_acc),
EditAccountCheckControl( acc, self, 'Modem', 'modem', 0, def_acc),
EditAccountOptionControl( acc, self, 'FlowControl', 'flow_control',
['crtscts', 'cdtrcts', 'xonxoff', 'no-change'], 0, def_acc),
EditAccountOptionControl( acc, self, 'ModemTerm', 'modem_term',
['\\r\\n', '\\r', '\\n'], 0, def_acc),
EditAccountScaleControl( acc, self, 'Volume', 'volume_setting', 0, def_acc),
EditAccountCheckControl( acc, self, 'DefaultRoute', 'default_route', 0, def_acc),
EditAccountCheckControl( acc, self, 'LockDevice', 'lock_device', 0, def_acc),
EditAccountSpinControl( acc, self, 'MTU', 'mtu', 0, def_acc),
EditAccountSpinControl( acc, self, 'MRU', 'mru', 0, def_acc),
EditAccountCheckControl( acc, self, 'Callback', 'callback', 0, def_acc),
EditAccountEntryControl( acc, self, 'CallbackPhoneNumber','callback_phone_number',0, def_acc),
EditAccountEntryControl( acc, self, 'PPPOptions', 'ppp_options', 0, def_acc),
EditAccountEntryControl( acc, self, 'ConnectProg', 'connect_program', 0, def_acc),
EditAccountEntryControl( acc, self, 'DisconnectProg', 'disconnect_program', 0, def_acc),
EditAccountEntryControl( acc, self, 'ErrorResp', 'error_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'InitCmd', 'init_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'Init2Cmd', 'init2_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'InitResp', 'init_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'VolumeMuteCmd', 'mute_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'VolumeLowCmd', 'low_vol_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'VolumeMaxCmd', 'max_vol_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'VolumeResp', 'vol_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'DialCmd', 'dial_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'ConnectResp', 'connect_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'BusyResp', 'busy_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'NoAnswerResp', 'noanswer_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'NoCarrierResp', 'nocarrier_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'NoDialtoneResp', 'nodialtone_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'CallbackInitCmd', 'callback_init_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'CallbackInit2Cmd', 'callback_init2_cmd', 0, def_acc),
EditAccountEntryControl( acc, self, 'RingResp', 'ring_resp', 0, def_acc),
EditAccountEntryControl( acc, self, 'AnswerCmd', 'answer_cmd', 0, def_acc)
]
for c in self.controls: c.load_value()
if not chestnut_dialer.config.disable_show_passwd_button:
self.connect(self.ShowPasswordButton,
qt.SIGNAL("toggled(bool)"), self.show_passwd_toggled)
else:
self.ShowPasswordButton.setEnabled(0)
self.connect(self.ChatScriptHelp, qt.SIGNAL("clicked()"),
self.show_chat_script_help)
self.connect(self.OkButton,
qt.SIGNAL("clicked()"), self.ok_action)
self.connect(self.CancelButton,
qt.SIGNAL("clicked()"), self.cancel_action)
def closeEvent(self, e):
self.controls = None
self.update_list_action = None
self.show_help = None
self.acc = None
self.acc_real = None
e.accept()
def show_passwd_toggled(self, on):
if on: self.PasswordEntry.setEchoMode(qt.QLineEdit.Normal)
else: self.PasswordEntry.setEchoMode(qt.QLineEdit.Password)
def ok_action(self):
phone_numbers = None
use_script = None
for c in self.controls:
if c.attr_name == 'phone_numbers':
phone_numbers = c.wid_get_value()
elif c.attr_name == 'use_script':
use_script = c.wid_get_value()
if (len(phone_numbers) == 0 and
use_script not in ('dialin', 'custom', 'none')):
if qt.QMessageBox.warning(self,
_("No phone numbers specified"),
_("No phone numbers specified. Continue?"),
qt.QMessageBox.Yes, qt.QMessageBox.No,
qt.QMessageBox.NoButton) == qt.QMessageBox.No:
return
for c in self.controls: c.save_value()
self.acc_real.update(self.acc)
self.update_list_action()
self.close()
def cancel_action(self):
self.close()
def show_chat_script_help(self):
self.show_help("Chat Scripts")
class AccountsConfBox(chestnut_dialer.qt_ui.accountsconfbox.AccountsConfBox):
app = None
list_sv_pos_y = 0
list_sv_pos_y_attempt = 0
list_selection = []
list_current = -1
def __init__(self, app, *args):
apply(chestnut_dialer.qt_ui.accountsconfbox.AccountsConfBox.__init__,
(self,) + args)
self.app = app
self.RemoveButton.setEnabled(0)
self.EditButton.setEnabled(0)
self.DuplicateButton.setEnabled(0)
self.DialButton.setEnabled(0)
self.connect(self.AddButton, qt.SIGNAL("clicked()"), self.add_action)
self.connect(self.RemoveButton, qt.SIGNAL("clicked()"), self.remove_action)
self.connect(self.EditButton, qt.SIGNAL("clicked()"), self.edit_action)
self.connect(self.ImportButton, qt.SIGNAL("clicked()"), self.import_action)
self.connect(self.DuplicateButton, qt.SIGNAL("clicked()"), self.duplicate_action)
self.connect(self.DialButton, qt.SIGNAL("clicked()"), self.dial_action)
self.AccountList.setSorting(1)
self.connect(self.AccountList,
qt.SIGNAL("doubleClicked(QListViewItem*)"), self.double_clicked_event)
self.connect(self.AccountList,
qt.SIGNAL("selectionChanged()"), self.selection_changed_event)
self.refresh(prev_session = 1)
self.timerid = self.startTimer(100)
def closeEvent(self, e):
AccountsConfBox.list_sv_pos_y = self.AccountList.contentsY()
AccountsConfBox.list_selection = self.get_selection()
if self.AccountList.currentItem():
AccountsConfBox.list_current = int(
str(self.AccountList.currentItem().text(0)))
else: AccountsConfBox.list_current = -1
self.app = None
self.AccountList = None
e.accept()
def timerEvent(self, e):
self.AccountList.setContentsPos(0, AccountsConfBox.list_sv_pos_y)
self.list_sv_pos_y_attempt += 1
if (self.AccountList.contentsY() == AccountsConfBox.list_sv_pos_y or
self.list_sv_pos_y_attempt > 5):
self.killTimer(self.timerid)
def double_clicked_event(self, item):
self.edit(int(str(item.text(0))))
def get_selection(self, need_first = 0):
selection = []
i = self.AccountList.firstChild()
while i:
if self.AccountList.isSelected(i):
selection.append(int(str(i.text(0))))
if need_first: break
i = i.nextSibling()
return selection
def selection_changed_event(self):
has_selection = len(self.get_selection(need_first = 1)) > 0
self.RemoveButton.setEnabled(has_selection)
self.EditButton.setEnabled(has_selection)
self.DuplicateButton.setEnabled(has_selection)
self.DialButton.setEnabled(has_selection and
not self.app.is_connection_init())
def refresh(self, prev_session = 0):
if self.AccountList == None: return
if prev_session:
selection = AccountsConfBox.list_selection
list_sv_pos_x = 0
list_sv_pos_y = AccountsConfBox.list_sv_pos_y
cur_acc = AccountsConfBox.list_current
else:
selection = self.get_selection()
list_sv_pos_x = self.AccountList.contentsX()
list_sv_pos_y = self.AccountList.contentsY()
if self.AccountList.currentItem():
cur_acc = int(str(self.AccountList.currentItem().text(0)))
else:cur_acc = -1
self.AccountList.clear()
for name, accid in self.app.accounts.ls_accounts():
i = qt.QListViewItem(self.AccountList, "%03d" % accid, name)
if accid in selection: self.AccountList.setSelected(i, 1)
if accid == cur_acc: self.AccountList.setCurrentItem(i)
self.AccountList.setContentsPos(list_sv_pos_x, list_sv_pos_y)
def edit(self, acc_id):
try: acc = self.app.accounts.get_account(acc_id)
except NoAccountException:
self.refresh()
return
dlg = EditAccountDialog(acc,
self.app.config.default_account, self.refresh,
self.app.show_help, self, None, 1)
dlg.show()
def edit_action(self):
selection = self.get_selection(need_first = 1)
if len(selection) == 0: return
self.edit(selection[0])
def add_action(self):
acc = self.app.accounts.new_account()
self.refresh()
dlg = EditAccountDialog(acc,
self.app.config.default_account, self.refresh,
self.app.show_help, self, None, 1)
dlg.show()
def remove_action(self):
selection = self.get_selection()
if len(selection) == 0: return
if not self.app.config.confirm_delete_account or qt.QMessageBox.warning(
self, _("Confirmation"),
len(selection) == 1 and (
_("Delete account %s?") %
self.app.accounts.get_account(selection[0]).name) or
(_("Delete %d accounts?") % len(selection)),
qt.QMessageBox.Yes, qt.QMessageBox.No,
qt.QMessageBox.NoButton) == qt.QMessageBox.Yes:
self.app.accounts.remove_accounts(selection)
self.refresh()
def duplicate_action(self):
selection = self.get_selection(need_first = 1)
if len(selection) == 0: return
aid = selection[0]
try: acc = self.app.accounts.duplicate_account(aid)
except NoAccountException:
self.refresh()
return
self.refresh()
dlg = EditAccountDialog(acc,
self.app.config.default_account, self.refresh,
self.app.show_help, self, None, 1)
dlg.show()
def import_action(self):
import chestnut_dialer.qt_ui.accimport
dlg = chestnut_dialer.qt_ui.accimport.ImportDialog(
self.app.accounts, self.refresh, self, None, 1)
dlg.show()
def dial_action(self):
selection = self.get_selection(need_first = 1)
if len(selection) == 0: return
try: acc = self.app.accounts.get_account(selection[0])
except NoAccountException:
self.refresh()
return
self.app.connect(acc)
class KeyDialog(qt.QDialog):
key = None
def __init__(self, *args):
apply(qt.QDialog.__init__, (self,) + args)
self.setCaption(_("Press a key"))
box = qt.QVBoxLayout(self, 10, 5)
l = qt.QLabel(_("Press a key"), self, None, 0)
l.setAlignment(qt.Qt.AlignCenter)
box.addWidget(l)
b = qt.QPushButton(_("Close"), self)
box.addWidget(b)
self.connect(b, qt.SIGNAL("clicked()"),
self, qt.SLOT("reject()"))
self.resize(180, 120)
def keyPressEvent(self, event):
key = event.key()
if key >= qt.Qt.Key_A and key <= qt.Qt.Key_Z:
if event.state() & qt.Qt.ShiftButton: key |= qt.Qt.SHIFT
if event.state() & qt.Qt.MetaButton: key |= qt.Qt.META
if event.state() & qt.Qt.ControlButton: key |= qt.Qt.CTRL
if event.state() & qt.Qt.AltButton: key |= qt.Qt.ALT
self.key = qt.QKeySequence(key)
event.accept()
self.accept()
return
event.ignore()
class KeyBindingControl:
entry = None
button = None
cont = None
def __init__(self, cont, name):
self.cont = cont
self.entry = getattr(cont, name + "Entry")
self.button = getattr(cont, name + "Button")
cont.connect(self.button, qt.SIGNAL("clicked()"),
self.button_clicked)
def destroy(self):
self.entry = None
self.button = None
self.cont = None
def get_value(self):
return unicode(self.entry.text())
def set_value(self, value):
self.entry.setText(value)
def button_clicked(self, *args):
dialog = KeyDialog(self.cont, None, 1, 0)
if dialog.exec_loop() == dialog.Accepted:
self.entry.setText(qt.QString(dialog.key))
class OptionsDialog(chestnut_dialer.qt_ui.optionsdialog.OptionsDialog):
config = None
show_help = None
accel_controls = None
accel_map = None
def __init__(self, config, show_help, *args):
apply(chestnut_dialer.qt_ui.optionsdialog.OptionsDialog.__init__,
(self,) + args)
self.config = config
self.show_help = show_help
self.MonitorPeriod.setValue(int(self.config.monitor_period))
self.StatusRefreshPeriod.setValue(int(self.config.status_refresh_period))
self.connect(self.Icons, qt.SIGNAL("activated(const QString &)"),
self.icons_activate)
j = None; i = 0
for d in chestnut_dialer.get_dockicons_dir_list():
self.Icons.insertItem(d)
if d == self.config.dockicons_dir: j = i
i += 1
if j != None:
self.Icons.setCurrentItem(j)
self.icons_activate(self.config.dockicons_dir)
on_connect_actions = self.get_on_connect_actions()
text_dict = self.get_on_connect_text_dict()
for a in on_connect_actions:
self.WhenConnect.insertItem(text_dict[a])
try:
self.WhenConnect.setCurrentItem(
on_connect_actions.index(self.config.qt_ui.on_connect))
except AttributeError: pass
except ValueError: pass
self.WndTitleFmtDisconnected.setText(self.config.wnd_title_fmt_disconnected)
self.WndTitleFmtConnecting.setText(self.config.wnd_title_fmt_connecting)
self.WndTitleFmtConnected.setText(self.config.wnd_title_fmt_connected)
self.connect(self.WndTitleFmtHelp, qt.SIGNAL("clicked()"),
self.show_wnd_title_fmt_help)
self.QtStyle.insertItem("")
try: current_qt_style = self.config.qt_ui.style
except AttributeError: current_qt_style = ""
i = 1; j = 0
for qt_style in qt.QStyleFactory.keys():
self.QtStyle.insertItem(qt_style)
if unicode(qt_style) == current_qt_style: j = i
i += 1
self.QtStyle.setCurrentItem(j)
self.accel_controls = [
("Main/Dial",
KeyBindingControl(self, "DialKey")),
("Main/AccountsConf",
KeyBindingControl(self, "AccountsConfKey")),
("Main/Config",
KeyBindingControl(self, "ConfigKey")),
("Main/Connecting",
KeyBindingControl(self, "ConnectingKey")),
("Main/Connecting/Stop",
KeyBindingControl(self, "ConnectingStopKey")),
("Main/Status",
KeyBindingControl(self, "StatusKey")),
("Main/Status/Disconnect",
KeyBindingControl(self, "StatusDisconnectKey")),
("Main/Quit",
KeyBindingControl(self, "QuitKey"))]
self.accel_map = {}
for path, accel in map(lambda e: e.split(':'),
self.config.qt_ui.accel_map.split(';')):
self.accel_map[path] = accel
for path, control in self.accel_controls:
control.set_value(self.accel_map[path])
self.ConfirmExit.setOn(self.config.confirm_exit)
self.ConfirmDeleteAccount.setOn(self.config.confirm_delete_account)
self.PppdCbcpWithAutoAnswer.setOn(self.config.pppd_cbcp_with_auto_answer)
self.WriteDnsToResolvConf.setOn(self.config.write_dns_to_resolv_conf)
try:
self.Browser.setCurrentText(self.config.qt_ui.browser)
except AttributeError:
self.Browser.setCurrentText("")
try:
self.PlainTextViewer.setCurrentText(self.config.qt_ui.plain_text_viewer)
except AttributeError:
self.PlainTextViewer.setCurrentText("")
self.connect(self.OkButton, qt.SIGNAL("clicked()"), self.ok_action)
self.connect(self.CancelButton, qt.SIGNAL("clicked()"), self.cancel_action)
def closeEvent(self, e):
if self.accel_controls != None:
for path, control in self.accel_controls:
control.destroy()
self.accel_controls = None
self.accel_map = None
self.config = None
self.show_help = None
e.accept()
def icons_activate(self, dockicons_dir):
dockicons_dir = unicode(dockicons_dir)
self.DisconnectedIcon.setPixmap(qt.QPixmap(
chestnut_dialer.get_dockicon_file(dockicons_dir, "disconnected")))
self.ConnectingIcon.setPixmap(qt.QPixmap(
chestnut_dialer.get_dockicon_file(dockicons_dir, "connecting")))
self.ConnectedIcon.setPixmap(qt.QPixmap(
chestnut_dialer.get_dockicon_file(dockicons_dir, "connected")))
def ok_action(self):
self.config.monitor_period = self.MonitorPeriod.value()
self.config.status_refresh_period = self.StatusRefreshPeriod.value()
self.config.dockicons_dir = unicode(self.Icons.currentText())
self.config.qt_ui.on_connect = self.get_on_connect_actions()[
self.WhenConnect.currentItem()]
self.config.wnd_title_fmt_disconnected = unicode(self.WndTitleFmtDisconnected.text())
self.config.wnd_title_fmt_connecting = unicode(self.WndTitleFmtConnecting.text())
self.config.wnd_title_fmt_connected = unicode(self.WndTitleFmtConnected.text())
if unicode(self.QtStyle.currentText()) != "":
self.config.qt_ui.style = unicode(self.QtStyle.currentText())
else:
try: del self.config.qt_ui.style
except AttributeError: pass
for path, control in self.accel_controls:
k = qt.QKeySequence(control.get_value())
if not k.isEmpty():
self.accel_map[path] = unicode(qt.QString(k))
self.config.qt_ui.accel_map = ';'.join(
map(lambda p: "%s:%s" % (p, self.accel_map[p]), self.accel_map.keys()))
self.config.confirm_exit = self.ConfirmExit.isOn()
self.config.confirm_delete_account = self.ConfirmDeleteAccount.isOn()
self.config.pppd_cbcp_with_auto_answer = self.PppdCbcpWithAutoAnswer.isOn()
self.config.write_dns_to_resolv_conf = self.WriteDnsToResolvConf.isOn()
self.config.qt_ui.browser = unicode(self.Browser.currentText())
self.config.qt_ui.plain_text_viewer = unicode(self.PlainTextViewer.currentText())
self.close()
def cancel_action(self):
self.close()
def show_wnd_title_fmt_help(self):
self.show_help("Custom Window Title")
def get_on_connect_actions(self):
return ["nothing", "iconify"]
def get_on_connect_text_dict(self):
return {"nothing": _("Nothing"),
"iconify": _("Minimize Window")}
class EditDefAccountDialog(chestnut_dialer.qt_ui.editdefaccountdialog.EditDefAccountDialog):
controls = None
show_help = None
def __init__(self, acc, show_help, *args):
apply(chestnut_dialer.qt_ui.editdefaccountdialog.EditDefAccountDialog.__init__,
(self,) + args)
self.show_help = show_help
self.controls = [
EditAccountEntryControl( acc, self, 'DialPrefix', 'dial_prefix'),
EditAccountSpinControl( acc, self, 'Redial', 'redial_attempts', 1),
EditAccountCheckControl( acc, self, 'RedialAuto', 'redial_auto'),
EditAccountSpinControl( acc, self, 'MinSpeed', 'min_speed'),
EditAccountCheckGroupControl(acc,self,'RedialIf', 'redial_if',
['no-dialtone', 'auth-fail']),
EditAccountSpinControl( acc, self, 'ModemTimeout', 'modem_timeout'),
EditAccountSpinControl( acc, self, 'Timeout', 'dial_timeout'),
EditAccountSpinControl( acc, self, 'PPPTimeout', 'ppp_timeout'),
EditAccountSpinControl( acc, self, 'PromptTimeout', 'prompt_timeout'),
EditAccountCheckControl( acc, self, 'AskPassword', 'ask_passwd'),
EditAccountCheckControl( acc, self, 'UsePasswordfd', 'use_passwordfd'),
EditAccountEntryControl( acc, self, 'RemoteName', 'remotename'),
EditAccountEntryControl( acc, self, 'ChatLoginPrompt', 'chat_login_prompt'),
EditAccountEntryControl( acc, self, 'ChatPasswordPrompt','chat_passwd_prompt'),
EditAccountTextControl( acc, self, 'ChatScript', 'chat_script'),
EditAccountEntryControl( acc, self, 'LocalIP', 'ip', 1),
EditAccountEntryControl( acc, self, 'NetMask', 'mask', 1),
EditAccountEntryControl( acc, self, 'RemoteIP', 'remote', 1),
EditAccountListControl( acc, self, 'DNSServer', 'dns_servers', 1),
EditAccountComboControl( acc, self, 'Device', 'device'),
EditAccountOptionControl( acc, self, 'Speed', 'speed',
['115200', '57600', '38400', '19200', '9600', '4800', '2400', '1200']),
EditAccountCheckControl( acc, self, 'Modem', 'modem'),
EditAccountOptionControl( acc, self, 'FlowControl', 'flow_control',
['crtscts', 'cdtrcts', 'xonxoff', 'no-change']),
EditAccountOptionControl( acc, self, 'ModemTerm', 'modem_term',
['\\r\\n', '\\r', '\\n']),
EditAccountScaleControl( acc, self, 'Volume', 'volume_setting'),
EditAccountCheckControl( acc, self, 'DefaultRoute', 'default_route'),
EditAccountCheckControl( acc, self, 'LockDevice', 'lock_device'),
EditAccountSpinControl( acc, self, 'MTU', 'mtu'),
EditAccountSpinControl( acc, self, 'MRU', 'mru'),
EditAccountCheckControl( acc, self, 'Callback', 'callback'),
EditAccountEntryControl( acc, self, 'CallbackPhoneNumber','callback_phone_number'),
EditAccountEntryControl( acc, self, 'PPPOptions', 'ppp_options'),
EditAccountEntryControl( acc, self, 'ConnectProg', 'connect_program'),
EditAccountEntryControl( acc, self, 'DisconnectProg', 'disconnect_program'),
EditAccountEntryControl( acc, self, 'ErrorResp', 'error_resp'),
EditAccountEntryControl( acc, self, 'InitCmd', 'init_cmd'),
EditAccountEntryControl( acc, self, 'Init2Cmd', 'init2_cmd'),
EditAccountEntryControl( acc, self, 'InitResp', 'init_resp'),
EditAccountEntryControl( acc, self, 'VolumeMuteCmd', 'mute_cmd'),
EditAccountEntryControl( acc, self, 'VolumeLowCmd', 'low_vol_cmd'),
EditAccountEntryControl( acc, self, 'VolumeMaxCmd', 'max_vol_cmd'),
EditAccountEntryControl( acc, self, 'VolumeResp', 'vol_resp'),
EditAccountEntryControl( acc, self, 'DialCmd', 'dial_cmd'),
EditAccountEntryControl( acc, self, 'ConnectResp', 'connect_resp'),
EditAccountEntryControl( acc, self, 'BusyResp', 'busy_resp'),
EditAccountEntryControl( acc, self, 'NoAnswerResp', 'noanswer_resp'),
EditAccountEntryControl( acc, self, 'NoCarrierResp', 'nocarrier_resp'),
EditAccountEntryControl( acc, self, 'NoDialtoneResp', 'nodialtone_resp'),
EditAccountEntryControl( acc, self, 'CallbackInitCmd', 'callback_init_cmd'),
EditAccountEntryControl( acc, self, 'CallbackInit2Cmd', 'callback_init2_cmd'),
EditAccountEntryControl( acc, self, 'RingResp', 'ring_resp'),
EditAccountEntryControl( acc, self, 'AnswerCmd', 'answer_cmd')
]
for c in self.controls: c.load_value()
self.connect(self.ChatScriptHelp, qt.SIGNAL("clicked()"),
self.show_chat_script_help)
self.connect(self.OkButton, qt.SIGNAL("clicked()"), self.ok_action)
self.connect(self.CancelButton, qt.SIGNAL("clicked()"), self.cancel_action)
def closeEvent(self, e):
self.controls = None
self.show_help = None
e.accept()
def ok_action(self):
for c in self.controls: c.save_value()
self.close()
def cancel_action(self):
self.close()
def show_chat_script_help(self):
self.show_help("Chat Scripts")
class ConfigBox(qt.QScrollView):
app = None
def __init__(self, app, *args):
apply(qt.QScrollView.__init__, (self,) + args)
self.setResizePolicy(qt.QScrollView.AutoOneFit)
vb = qt.QVButtonGroup(self.viewport())
vb.setFrameShape(qt.QFrame.NoFrame)
vb.setInsideMargin(0)
vb.setInsideSpacing(0)
self.addChild(vb)
self.app = app
self.init_buttons(vb)
def closeEvent(self, e):
self.app = None
e.accept()
def init_buttons(self, parent):
btn = qt.QPushButton(_("Options"), parent)
self.connect(btn, qt.SIGNAL("clicked()"), self.options_action)
btn = qt.QPushButton(_("Default Account"), parent)
self.connect(btn, qt.SIGNAL("clicked()"), self.default_account_action)
btn = qt.QPushButton(_("View Connecting Log"), parent)
self.connect(btn, qt.SIGNAL("clicked()"), self.view_connecting_log_action)
def options_action(self):
dlg = OptionsDialog(self.app.config, self.app.show_help, self, None, 1)
dlg.show()
def default_account_action(self):
dlg = EditDefAccountDialog(self.app.config.default_account,
self.app.show_help, self, None, 1)
dlg.show()
def view_connecting_log_action(self):
dlg = chestnut_dialer.qt_ui.connectinglog.ConnectingLog(self)
dlg.connect(dlg.CloseButton, qt.SIGNAL("clicked()"),
dlg, qt.SLOT("close()"))
dlg.Text.setText(self.app.connecting_log)
dlg.show()
|