Wed, 28 Nov 2012 20:11:46 +0100
Continued with IRC management.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Network/IRC/IrcChannelEditDialog.py Wed Nov 28 20:11:46 2012 +0100 @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing a dialog to edit channel data. +""" + +from PyQt4.QtCore import pyqtSlot +from PyQt4.QtGui import QDialog, QDialogButtonBox + +from .Ui_IrcChannelEditDialog import Ui_IrcChannelEditDialog + + +class IrcChannelEditDialog(QDialog, Ui_IrcChannelEditDialog): + """ + Class implementing a dialog to edit channel data. + """ + def __init__(self, name, key, autoJoin, edit, parent=None): + """ + Constructor + + @param name channel name (string) + @param key channel key (string) + @param autoJoin flag indicating, that the channel should + be joined automatically (boolean) + @param edit flag indicating an edit of an existing + channel (boolean) + @param parent reference to the parent widget (QWidget) + """ + super().__init__(parent) + self.setupUi(self) + + self.nameEdit.setText(name) + self.keyEdit.setText(key) + self.autoJoinCheckBox.setChecked(autoJoin) + + self.nameEdit.setReadOnly(edit) + + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(name != "") + + @pyqtSlot(str) + def on_nameEdit_textChanged(self, txt): + """ + Private slot to handle changes of the given name. + """ + self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(txt != "") + + def getData(self): + """ + Public method to get the channel data. + + @return tuple giving the channel name, channel key and a flag + indicating, that the channel should be joined automatically + (string, string, boolean) + """ + return (self.nameEdit.text(), + self.keyEdit.text(), + self.autoJoinCheckBox.isChecked())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Network/IRC/IrcChannelEditDialog.ui Wed Nov 28 20:11:46 2012 +0100 @@ -0,0 +1,114 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>IrcChannelEditDialog</class> + <widget class="QDialog" name="IrcChannelEditDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>303</width> + <height>128</height> + </rect> + </property> + <property name="windowTitle"> + <string>IRC Channel</string> + </property> + <property name="sizeGripEnabled"> + <bool>true</bool> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="nameEdit"> + <property name="toolTip"> + <string>Enter the channel name</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Key:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="keyEdit"> + <property name="toolTip"> + <string>Enter the channel key/password</string> + </property> + <property name="echoMode"> + <enum>QLineEdit::Password</enum> + </property> + </widget> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QCheckBox" name="autoJoinCheckBox"> + <property name="toolTip"> + <string>Select to join this channel automatically</string> + </property> + <property name="text"> + <string>Join channel automatically</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <tabstops> + <tabstop>nameEdit</tabstop> + <tabstop>keyEdit</tabstop> + <tabstop>autoJoinCheckBox</tabstop> + <tabstop>buttonBox</tabstop> + </tabstops> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>IrcChannelEditDialog</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>IrcChannelEditDialog</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui>
--- a/Network/IRC/IrcNetworkEditDialog.py Wed Nov 28 19:00:40 2012 +0100 +++ b/Network/IRC/IrcNetworkEditDialog.py Wed Nov 28 20:11:46 2012 +0100 @@ -7,12 +7,15 @@ Module implementing a dialog for editing IRC network definitions. """ +import copy + from PyQt4.QtCore import pyqtSlot from PyQt4.QtGui import QDialog, QDialogButtonBox, QTreeWidgetItem from .Ui_IrcNetworkEditDialog import Ui_IrcNetworkEditDialog -from .IrcNetworkManager import IrcIdentity +from .IrcNetworkManager import IrcIdentity, IrcChannel +from .IrcChannelEditDialog import IrcChannelEditDialog import UI.PixmapCache @@ -42,7 +45,8 @@ self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) - self.__network = self.__manager.getNetwork(networkName) + # TODO: add the ADD mode + self.__network = copy.deepcopy(self.__manager.getNetwork(networkName)) # network name self.networkEdit.setText(networkName) @@ -69,7 +73,6 @@ self.serverCombo.setCurrentIndex(index) # channels - # TODO: change this to use channel objects for channelName in sorted(self.__network.getChannelNames()): channel = self.__network.getChannel(channelName) if channel.autoJoin(): @@ -140,7 +143,7 @@ """ itm = self.channelList.selectedItems()[0] if itm: - self.__editChannel(itm.text(0)) + self.__editChannel(itm) @pyqtSlot() def on_deleteChannelButton_clicked(self): @@ -158,7 +161,7 @@ @param item reference to the activated item (QTreeWidgetItem) @param column column the activation occurred in (integer) """ - self.__editChannel(item.text(0)) + self.__editChannel(item) @pyqtSlot() def on_channelList_itemSelectionChanged(self): @@ -173,11 +176,47 @@ self.editChannelButton.setEnabled(enable) self.deleteChannelButton.setEnabled(enable) - def __editChannel(self, name): + def __editChannel(self, itm): """ Private method to edit a channel. - @param name name of the channel (string) + @param itm reference to the item to be edited (QTreeWidgetItem) """ - # TODO: not implemented yet - raise NotImplementedError + if itm: + channel = self.__network.getChannel(itm.text(0)) + name = channel.getName() + key = channel.getKey() + autoJoin = channel.autoJoin() + else: + # add a new channel + name = "" + key = "" + autoJoin = False + + dlg = IrcChannelEditDialog(name, key, autoJoin, itm is not None, self) + if dlg.exec_() == QDialog.Accepted: + name, key, autoJoin = dlg.getData() + channel = IrcChannel(name) + channel.setKey(key) + channel.setAutoJoin(autoJoin) + if itm: + if autoJoin: + itm.setText(1, self.trUtf8("Yes")) + else: + itm.setText(1, self.trUtf8("No")) + self.__network.setChannel(channel) + else: + if autoJoin: + autoJoinTxt = self.trUtf8("Yes") + else: + autoJoinTxt = self.trUtf8("No") + QTreeWidgetItem(self.channelList, [name, autoJoinTxt]) + self.__network.addChannel(channel) + + def getData(self): + """ + Public method to get the network data. + + @return edited network object (IrcNetwork) + """ + return self.__network
--- a/Network/IRC/IrcNetworkManager.py Wed Nov 28 19:00:40 2012 +0100 +++ b/Network/IRC/IrcNetworkManager.py Wed Nov 28 20:11:46 2012 +0100 @@ -15,21 +15,20 @@ import Preferences -class IrcIdentity(QObject): +class IrcIdentity(object): """ Class implementing the IRC identity object. """ DefaultIdentityName = "0default" DefaultIdentityDisplay = QCoreApplication.translate("IrcIdentity", "Default Identity") - def __init__(self, name, parent=None): + def __init__(self, name): """ Constructor @param name name of the identity (string) - @param parent reference to the parent object (QObject) """ - super().__init__(parent) + super().__init__() self.__name = name self.__realName = "" @@ -133,20 +132,19 @@ return pwConvert(self.__password, encode=False) -class IrcServer(QObject): +class IrcServer(object): """ Class implementing the IRC identity object. """ DefaultPort = 6667 - def __init__(self, name, parent=None): + def __init__(self, name): """ Constructor @param name name of the server (string) - @param parent reference to the parent object (QObject) """ - super().__init__(parent) + super().__init__() self.__server = name self.__port = IrcServer.DefaultPort @@ -231,18 +229,17 @@ return pwConvert(self.__password, encode=False) -class IrcChannel(QObject): +class IrcChannel(object): """ Class implementing the IRC channel object. """ - def __init__(self, name, parent=None): + def __init__(self, name): """ Constructor @param name name of the network (string) - @param parent reference to the parent object (QObject) """ - super().__init__(parent) + super().__init__() self.__name = name self.__key = "" @@ -310,18 +307,17 @@ self.__autoJoin = enable -class IrcNetwork(QObject): +class IrcNetwork(object): """ Class implementing the IRC network object. """ - def __init__(self, name, parent=None): + def __init__(self, name): """ Constructor @param name name of the network (string) - @param parent reference to the parent object (QObject) """ - super().__init__(parent) + super().__init__() self.__name = name self.__identity = "" @@ -354,7 +350,7 @@ self.__server = settings.value("Server", "") settings.beginGroup("Channels") for key in self.__channels: - self.__channels[key] = IrcChannel(key, self) + self.__channels[key] = IrcChannel(key) settings.beginGroup(key) self.__channels[key].load(settings) settings.endGroup() @@ -446,7 +442,6 @@ """ channelName = channel.getName() if channelName in self.__channels: - channel.setParent(self) self.__channels[channelName] = channel def addChannel(self, channel): @@ -457,7 +452,6 @@ """ channelName = channel.getName() if channelName not in self.__channels: - channel.setParent(self) self.__channels[channelName] = channel @@ -545,7 +539,7 @@ # identities self.__settings.beginGroup("Identities") for key in self.__settings.childKeys(): - self.__identities[key] = IrcIdentity(key, self) + self.__identities[key] = IrcIdentity(key) self.__settings.beginGroup(key) self.__identities[key].load(self.__settings) self.__settings.endGroup() @@ -554,7 +548,7 @@ # servers self.__settings.beginGroup("Servers") for key in self.__settings.childKeys(): - self.__servers[key] = IrcServer(key, self) + self.__servers[key] = IrcServer(key) self.__settings.beginGroup(key) self.__servers[key].load(self.__settings) self.__settings.endGroup() @@ -563,7 +557,7 @@ # networks self.__settings.beginGroup("Networks") for key in self.__settings.childKeys(): - self.__networks[key] = IrcNetwork(key, self) + self.__networks[key] = IrcNetwork(key) self.__settings.beginGroup(key) self.__networks[key].load(self.__settings) self.__settings.endGroup() @@ -596,23 +590,23 @@ # identity userName = Utilities.getUserName() - identity = IrcIdentity(IrcIdentity.DefaultIdentityName, self) + identity = IrcIdentity(IrcIdentity.DefaultIdentityName) identity.setNickNames([userName, userName + "_", userName + "__"]) self.__identities[IrcIdentity.DefaultIdentityName] = identity if not identityOnly: # server serverName = "chat.freenode.net" - server = IrcServer(serverName, self) + server = IrcServer(serverName) server.setPort(8001) self.__servers[serverName] = server # network networkName = "Freenode" - network = IrcNetwork(networkName, self) + network = IrcNetwork(networkName) network.setIdentityName(IrcIdentity.DefaultIdentityName) network.setServerName(serverName) - channel = IrcChannel("#eric-ide", network) + channel = IrcChannel("#eric-ide") channel.setAutoJoin(False) network.addChannel(channel) self.__networks[networkName] = network @@ -637,7 +631,7 @@ if name in self.__identities: return self.__identities[name] elif create: - id = IrcIdentity(name, self) + id = IrcIdentity(name) self.__identities[name] = id self.dataChanged.emit() @@ -697,6 +691,7 @@ """ self.dataChanged.emit() + # TODO: move server to network because it belongs there def getServer(self, name, create=False): """ Public method to get a server object. @@ -715,7 +710,7 @@ if name in self.__servers: return self.__servers[name] elif create: - server = IrcServer(name, self) + server = IrcServer(name) self.__servers[name] = server self.dataChanged.emit() @@ -756,6 +751,7 @@ else: return None + # TODO: check, if this method is needed def createNetwork(self, name, identity, server, channels=None): """ Public method to create a new network object.
--- a/eric5.e4p Wed Nov 28 19:00:40 2012 +0100 +++ b/eric5.e4p Wed Nov 28 20:11:46 2012 +0100 @@ -1064,6 +1064,7 @@ <Source>Preferences/ConfigurationPages/IrcPage.py</Source> <Source>Network/IRC/IrcNetworkListDialog.py</Source> <Source>Network/IRC/IrcNetworkEditDialog.py</Source> + <Source>Network/IRC/IrcChannelEditDialog.py</Source> </Sources> <Forms> <Form>PyUnit/UnittestDialog.ui</Form> @@ -1374,6 +1375,7 @@ <Form>Preferences/ConfigurationPages/IrcPage.ui</Form> <Form>Network/IRC/IrcNetworkListDialog.ui</Form> <Form>Network/IRC/IrcNetworkEditDialog.ui</Form> + <Form>Network/IRC/IrcChannelEditDialog.ui</Form> </Forms> <Translations> <Translation>i18n/eric5_cs.qm</Translation>