eric6/Cooperation/ChatWidget.py

Sun, 29 Nov 2020 14:10:18 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Nov 2020 14:10:18 +0100
changeset 7844
cb108454eda7
parent 7836
2f0d208b8137
child 7923
91e843545d9a
permissions
-rw-r--r--

WebBrowserWindow: removed the use of QTextCodec to prepare the Qt6 migration.

149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7250
diff changeset
3 # Copyright (c) 2010 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the chat dialog.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 from PyQt5.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtGui import QColor
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
14 from E5Gui.E5Application import e5App
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
15 from E5Gui import E5MessageBox, E5FileDialog
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
16
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
17 from Globals import recentNameHosts
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
18
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from .CooperationClient import CooperationClient
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from .Ui_ChatWidget import Ui_ChatWidget
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 import Preferences
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
24 import Utilities
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 import UI.PixmapCache
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
27
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 class ChatWidget(QWidget, Ui_ChatWidget):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 Class implementing the chat dialog.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
31
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
32 @signal connected(connected) emitted to signal a change of the connected
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 165
diff changeset
33 state (bool)
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
34 @signal editorCommand(hashStr, filename, message) emitted when an editor
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
35 command has been received (string, string, string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
36 @signal shareEditor(share) emitted to signal a share is requested (bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
37 @signal startEdit() emitted to start a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
38 @signal sendEdit() emitted to send a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
39 @signal cancelEdit() emitted to cancel a shared edit session
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
41 connected = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
42 editorCommand = pyqtSignal(str, str, str)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
43
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
44 shareEditor = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
45 startEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
46 sendEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
47 cancelEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
48
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
49 def __init__(self, ui, port=-1, parent=None):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 Constructor
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
53 @param ui reference to the user interface object (UserInterface)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 @param port port to be used for the cooperation server (integer)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 @param parent reference to the parent widget (QWidget)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2436
diff changeset
57 super(ChatWidget, self).__init__(parent)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.setupUi(self)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
60 self.shareButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
61 UI.PixmapCache.getIcon("sharedEditDisconnected"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
62 self.startEditButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
63 UI.PixmapCache.getIcon("sharedEditStart"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
64 self.sendEditButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
65 UI.PixmapCache.getIcon("sharedEditSend"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
66 self.cancelEditButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
67 UI.PixmapCache.getIcon("sharedEditCancel"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
68
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
69 self.__ui = ui
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
70 self.__client = CooperationClient(self)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__myNickName = self.__client.nickName()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
73 self.__initChatMenu()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
74 self.__initUsersMenu()
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
75
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.messageEdit.returnPressed.connect(self.__handleMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.sendButton.clicked.connect(self.__handleMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__client.newMessage.connect(self.appendMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__client.newParticipant.connect(self.__newParticipant)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__client.participantLeft.connect(self.__participantLeft)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__client.connectionError.connect(self.__showErrorMessage)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.__client.cannotConnect.connect(self.__initialConnectionRefused)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
83 self.__client.editorCommand.connect(self.__editorCommandMessage)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
85 self.serverButton.setText(self.tr("Start Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.serverLed.setColor(QColor(Qt.red))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if port == -1:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 port = Preferences.getCooperation("ServerPort")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.on_serverButton_clicked()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
96
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
97 self.recent = []
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
98 self.__loadHostsHistory()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
99
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
100 def __loadHostsHistory(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
101 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
102 Private method to load the recently connected hosts.
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
103 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
104 self.__recent = []
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
105 Preferences.Prefs.rsettings.sync()
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
106 rh = Preferences.Prefs.rsettings.value(recentNameHosts)
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
107 if rh is not None:
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
108 self.__recent = rh[:20]
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
109 self.hostEdit.clear()
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
110 self.hostEdit.addItems(self.__recent)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
111 self.hostEdit.clearEditText()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
112
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
113 def __saveHostsHistory(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
114 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
115 Private method to save the list of recently connected hosts.
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
116 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
117 Preferences.Prefs.rsettings.setValue(recentNameHosts, self.__recent)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
118 Preferences.Prefs.rsettings.sync()
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
119
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
120 def __setHostsHistory(self, host):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
121 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
122 Private method to remember the given host as the most recent entry.
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
123
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
124 @param host host entry to remember (string)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
125 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
126 if host in self.__recent:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
127 self.__recent.remove(host)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
128 self.__recent.insert(0, host)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
129 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
130 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
131 self.hostEdit.addItems(self.__recent)
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
132
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
133 def __clearHostsHistory(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
134 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
135 Private slot to clear the hosts history.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
136 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
137 self.__recent = []
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
138 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
139 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
140 self.hostEdit.addItems(self.__recent)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 def __handleMessage(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 Private slot handling the Return key pressed in the message edit.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 text = self.messageEdit.text()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 if text == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 if text.startswith("/"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 self.__showErrorMessage(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
152 self.tr("! Unknown command: {0}\n")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
153 .format(text.split()[0]))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 self.__client.sendMessage(text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.appendMessage(self.__myNickName, text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.messageEdit.clear()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 def __newParticipant(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 Private slot handling a new participant joining.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 @param nick nick name of the new participant (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
172 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
173 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
174 self.chatEdit.append(self.tr("* {0} has joined.\n").format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 QListWidgetItem(
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 UI.PixmapCache.getIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179 "chatUser{0}".format(1 + self.usersList.count() % 6)),
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 nick, self.usersList)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 self.__setConnected(True)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
184
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
185 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
186 self.__ui.showNotification(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
187 UI.PixmapCache.getPixmap("cooperation48"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
188 self.tr("New User"), self.tr("{0} has joined.")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
189 .format(nick))
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
190
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 def __participantLeft(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 Private slot handling a participant leaving the session.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 @param nick nick name of the participant (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 items = self.usersList.findItems(nick, Qt.MatchExactly)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 for item in items:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.usersList.takeItem(self.usersList.row(item))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 del item
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
208 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
209 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
210 self.chatEdit.append(self.tr("* {0} has left.\n").format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 if not self.__client.hasConnections():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 self.__setConnected(False)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
215
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
216 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
217 self.__ui.showNotification(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
218 UI.PixmapCache.getPixmap("cooperation48"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
219 self.tr("User Left"), self.tr("{0} has left.")
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
220 .format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 def appendMessage(self, from_, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 Public slot to append a message to the display.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @param from_ originator of the message (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 @param message message to be appended (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 if from_ == "" or message == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 self.chatEdit.append(
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
233 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 " <" + from_ + ">:")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 self.chatEdit.append(message + "\n")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 bar = self.chatEdit.verticalScrollBar()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 bar.setValue(bar.maximum())
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
238
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
239 if not self.isVisible():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
240 self.__ui.showNotification(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
241 UI.PixmapCache.getPixmap("cooperation48"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
242 self.tr("Message from <{0}>").format(from_), message)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 @pyqtSlot(str)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
245 def on_hostEdit_editTextChanged(self, host):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 Private slot handling the entry of a host to connect to.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 @param host host to connect to (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 self.connectButton.setEnabled(host != "")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
254 def __getConnectionParameters(self):
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
255 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
256 Private method to determine the connection parameters.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
257
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
258 @return tuple with hostname and port (string, integer)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
259 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
260 hostEntry = self.hostEdit.currentText()
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
261 if "@" in hostEntry:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
262 host, port = hostEntry.split("@")
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
263 try:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
264 port = int(port)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
265 except ValueError:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
266 port = Preferences.getCooperation("ServerPort")
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
267 self.hostEdit.setEditText("{0}@{1}".format(host, port))
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
268 else:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
269 host = hostEntry
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
270 port = Preferences.getCooperation("ServerPort")
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
271 self.hostEdit.setEditText("{0}@{1}".format(host, port))
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
272 return host, port
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
273
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 @pyqtSlot()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 def on_connectButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 Private slot initiating the connection.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 if not self.__connected:
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
280 host, port = self.__getConnectionParameters()
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
281 self.__setHostsHistory(self.hostEdit.currentText())
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
282 if not self.__client.isListening():
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 self.on_serverButton_clicked()
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
284 if self.__client.isListening():
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
285 self.__client.connectToHost(host, port)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 self.__setConnected(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 self.__client.disconnectConnections()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 @pyqtSlot()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
292 def on_clearHostsButton_clicked(self):
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
293 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
294 Private slot to clear the hosts list.
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
295 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
296 self.__clearHostsHistory()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
297
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
298 @pyqtSlot()
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 def on_serverButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 Private slot to start the server.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
303 if self.__client.isListening():
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
304 self.__client.close()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
305 self.serverButton.setText(self.tr("Start Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 self.serverPortSpin.setEnabled(True)
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
307 if (self.serverPortSpin.value() !=
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
308 Preferences.getCooperation("ServerPort")):
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
309 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
310 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 self.serverLed.setColor(QColor(Qt.red))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 else:
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
313 res, port = self.__client.startListening(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
314 self.serverPortSpin.value())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 if res:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
316 self.serverButton.setText(self.tr("Stop Server"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 self.serverPortSpin.setEnabled(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 self.serverLed.setColor(QColor(Qt.green))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.__showErrorMessage(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
322 self.tr("! Server Error: {0}\n").format(
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
323 self.__client.errorString())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 )
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 def __setConnected(self, connected):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 Private slot to set the connected state.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 @param connected new connected state (boolean)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 if connected:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
333 self.connectButton.setText(self.tr("Disconnect"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 self.connectButton.setEnabled(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 self.connectionLed.setColor(QColor(Qt.green))
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
337 self.connectButton.setText(self.tr("Connect"))
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
338 self.connectButton.setEnabled(self.hostEdit.currentText() != "")
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 self.connectionLed.setColor(QColor(Qt.red))
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
340 self.on_cancelEditButton_clicked()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
341 self.shareButton.setChecked(False)
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
342 self.on_shareButton_clicked(False)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
343 self.__connected = connected
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
344 self.hostEdit.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
345 self.serverButton.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
346 self.sharingGroup.setEnabled(connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
347
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
348 if connected:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
349 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
350 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
351 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
352 self.checkEditorActions(aw)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 def __showErrorMessage(self, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 Private slot to show an error message.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 @param message error message to show (string)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 self.chatEdit.setTextColor(Qt.red)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
363 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
364 ":")
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
365 self.chatEdit.append(message + "\n")
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 def __initialConnectionRefused(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 Private slot to handle the refusal of the initial connection.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 def preferencesChanged(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 Public slot to handle a change of preferences.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
378 if not self.__client.isListening():
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
379 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
380 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 self.on_serverButton_clicked()
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
383
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
384 def getClient(self):
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
385 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
386 Public method to get a reference to the cooperation client.
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2436
diff changeset
387
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2436
diff changeset
388 @return reference to the cooperation client (CooperationClient)
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
389 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
390 return self.__client
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
391
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
392 def __editorCommandMessage(self, hashStr, fileName, message):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
393 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
394 Private slot to handle editor command messages from the client.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
395
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
396 @param hashStr hash of the project (string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
397 @param fileName project relative file name of the editor (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
398 @param message command message (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
399 """
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
400 self.editorCommand.emit(hashStr, fileName, message)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
401
2400
c1726b754f96 Started with delaying the import upon the time it is needed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
402 from QScintilla.Editor import Editor
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
403 if (message.startswith(Editor.StartEditToken + Editor.Separator) or
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
404 message.startswith(Editor.EndEditToken + Editor.Separator)):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
405 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
406 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
407 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
408 self.checkEditorActions(aw)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
409
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
410 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
411 def on_shareButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
412 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
413 Private slot to share the current editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
414
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
415 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
416 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
417 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
418 self.shareButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
419 UI.PixmapCache.getIcon("sharedEditConnected"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
420 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
421 self.shareButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
422 UI.PixmapCache.getIcon("sharedEditDisconnected"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
423 self.startEditButton.setEnabled(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
424
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
425 self.shareEditor.emit(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
426
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
427 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
428 def on_startEditButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
429 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
430 Private slot to start a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
431
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
432 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
433 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
434 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
435 self.sendEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
436 self.cancelEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
437 self.shareButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
438 self.startEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
439
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
440 self.startEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
441
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
442 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
443 def on_sendEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
444 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
445 Private slot to end a shared edit session and send the changes.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
446 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
447 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
448 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
449 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
450 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
451 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
452
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
453 self.sendEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
454
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
455 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
456 def on_cancelEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
457 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
458 Private slot to cancel a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
459 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
460 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
461 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
462 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
463 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
464 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
465
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
466 self.cancelEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
467
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
468 def checkEditorActions(self, editor):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
469 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
470 Public slot to set action according to an editor's state.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
471
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
472 @param editor reference to the editor (Editor)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
473 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
474 shareable, sharing, editing, remoteEditing = editor.getSharingStatus()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
475
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
476 self.shareButton.setChecked(sharing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
477 if sharing:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
478 self.shareButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
479 UI.PixmapCache.getIcon("sharedEditConnected"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
480 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
481 self.shareButton.setIcon(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
482 UI.PixmapCache.getIcon("sharedEditDisconnected"))
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
483 self.startEditButton.setChecked(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
484
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
485 self.shareButton.setEnabled(shareable and not editing)
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
486 self.startEditButton.setEnabled(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
487 sharing and not editing and not remoteEditing)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
488 self.sendEditButton.setEnabled(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
489 self.cancelEditButton.setEnabled(editing)
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
490
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
491 def __initChatMenu(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
492 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
493 Private slot to initialize the chat edit context menu.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
494 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
495 self.__chatMenu = QMenu(self)
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
496 self.__copyChatAct = self.__chatMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
497 UI.PixmapCache.getIcon("editCopy"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
498 self.tr("Copy"), self.__copyChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
499 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
500 self.__cutAllChatAct = self.__chatMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
501 UI.PixmapCache.getIcon("editCut"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
502 self.tr("Cut all"), self.__cutAllChat)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
503 self.__copyAllChatAct = self.__chatMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
504 UI.PixmapCache.getIcon("editCopy"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
505 self.tr("Copy all"), self.__copyAllChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
506 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
507 self.__clearChatAct = self.__chatMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
508 UI.PixmapCache.getIcon("editDelete"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
509 self.tr("Clear"), self.__clearChat)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
510 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
511 self.__saveChatAct = self.__chatMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
512 UI.PixmapCache.getIcon("fileSave"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
513 self.tr("Save"), self.__saveChat)
2250
810e9c7b61e3 Fixed a little issue in the initialisation of the Cooperation Chat window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
514
810e9c7b61e3 Fixed a little issue in the initialisation of the Cooperation Chat window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
515 self.on_chatEdit_copyAvailable(False)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
516
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
517 @pyqtSlot(bool)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
518 def on_chatEdit_copyAvailable(self, yes):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
519 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
520 Private slot to react to text selection/deselection of the chat edit.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
521
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
522 @param yes flag signaling the availability of selected text (boolean)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
523 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
524 self.__copyChatAct.setEnabled(yes)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
525
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
526 @pyqtSlot(QPoint)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
527 def on_chatEdit_customContextMenuRequested(self, pos):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
528 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
529 Private slot to show the context menu for the chat.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
530
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
531 @param pos the position of the mouse pointer (QPoint)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
532 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
533 enable = self.chatEdit.toPlainText() != ""
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
534 self.__saveChatAct.setEnabled(enable)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
535 self.__copyAllChatAct.setEnabled(enable)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
536 self.__cutAllChatAct.setEnabled(enable)
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
537 self.__chatMenu.popup(self.chatEdit.mapToGlobal(pos))
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
538
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
539 def __clearChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
540 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
541 Private slot to clear the contents of the chat display.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
542 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
543 self.chatEdit.clear()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
544
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
545 def __saveChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
546 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
547 Private slot to save the contents of the chat display.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
548 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
549 txt = self.chatEdit.toPlainText()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
550 if txt:
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
551 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
552 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
553 self.tr("Save Chat"),
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
554 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
555 self.tr("Text Files (*.txt);;All Files (*)"),
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
556 None,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
557 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
558 if fname:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
559 ext = QFileInfo(fname).suffix()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
560 if not ext:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
561 ex = selectedFilter.split("(*")[1].split(")")[0]
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
562 if ex:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
563 fname += ex
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
564 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
565 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
566 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
567 self.tr("Save Chat"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
568 self.tr("<p>The file <b>{0}</b> already exists."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
569 " Overwrite it?</p>").format(fname),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
570 icon=E5MessageBox.Warning)
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
571 if not res:
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
572 return
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
573 fname = Utilities.toNativeSeparators(fname)
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
574
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
575 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
576 with open(fname, "w", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
577 f.write(txt)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
578 except OSError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
579 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
580 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
581 self.tr("Error saving Chat"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
582 self.tr("""<p>The chat contents could not be"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
583 """ written to <b>{0}</b></p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
584 """<p>Reason: {1}</p>""") .format(
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
585 fname, str(err)))
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
586
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
587 def __copyChat(self):
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
588 """
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
589 Private slot to copy the contents of the chat display to the clipboard.
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
590 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
591 self.chatEdit.copy()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
592
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
593 def __copyAllChat(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
594 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
595 Private slot to copy the contents of the chat display to the clipboard.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
596 """
160
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
597 txt = self.chatEdit.toPlainText()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
598 if txt:
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
599 cb = QApplication.clipboard()
32cc58d56d4d Added a context menu to the chat widget to clear the chat, to save it or to copy it to the clipboard.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 158
diff changeset
600 cb.setText(txt)
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
601
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
602 def __cutAllChat(self):
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
603 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
604 Private slot to cut the contents of the chat display to the clipboard.
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
605 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
606 txt = self.chatEdit.toPlainText()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
607 if txt:
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
608 cb = QApplication.clipboard()
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
609 cb.setText(txt)
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
610 self.chatEdit.clear()
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
611
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
612 def __initUsersMenu(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
613 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
614 Private slot to initialize the users list context menu.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
615 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
616 self.__usersMenu = QMenu(self)
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
617 self.__kickUserAct = self.__usersMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
618 UI.PixmapCache.getIcon("chatKickUser"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
619 self.tr("Kick User"), self.__kickUser)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
620 self.__banUserAct = self.__usersMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
621 UI.PixmapCache.getIcon("chatBanUser"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
622 self.tr("Ban User"), self.__banUser)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
623 self.__banKickUserAct = self.__usersMenu.addAction(
7533
88261c96484b Removed the '.png' extension from all call to get an icon or a pixmap from the PixmapCache because this is not needed anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
624 UI.PixmapCache.getIcon("chatBanKickUser"),
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
625 self.tr("Ban and Kick User"), self.__banKickUser)
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
626
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
627 @pyqtSlot(QPoint)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
628 def on_usersList_customContextMenuRequested(self, pos):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
629 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
630 Private slot to show the context menu for the users list.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
631
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
632 @param pos the position of the mouse pointer (QPoint)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
633 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
634 itm = self.usersList.itemAt(pos)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
635 self.__kickUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
636 self.__banUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
637 self.__banKickUserAct.setEnabled(itm is not None)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
638 self.__usersMenu.popup(self.usersList.mapToGlobal(pos))
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
639
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
640 def __kickUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
641 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
642 Private slot to disconnect a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
643 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
644 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
645 self.__client.kickUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
646
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
647 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
648 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
649 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
650 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
651 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
652 self.chatEdit.append(self.tr("* {0} has been kicked.\n").format(
2285
a6fc5bda1de9 Corrected a few issues in the Cooperation function introduced during the IPv6 extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2250
diff changeset
653 itm.text().split("@")[0]))
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
654 self.chatEdit.setTextColor(color)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
655
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
656 def __banUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
657 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
658 Private slot to ban a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
659 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
660 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
661 self.__client.banUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
662
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
663 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
664 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
665 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
666 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
667 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
668 self.chatEdit.append(self.tr("* {0} has been banned.\n").format(
2285
a6fc5bda1de9 Corrected a few issues in the Cooperation function introduced during the IPv6 extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2250
diff changeset
669 itm.text().split("@")[0]))
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
670 self.chatEdit.setTextColor(color)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
671
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
672 def __banKickUser(self):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
673 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
674 Private slot to ban and kick a user.
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
675 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
676 itm = self.usersList.currentItem()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
677 self.__client.banKickUser(itm.text())
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
678
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
679 color = self.chatEdit.textColor()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
680 self.chatEdit.setTextColor(Qt.darkYellow)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
681 self.chatEdit.append(
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
682 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
683 ":")
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
684 self.chatEdit.append(
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
685 self.tr("* {0} has been banned and kicked.\n")
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
686 .format(itm.text().split("@")[0]))
880
52ed20236a1c Added the option to not use the native file dialog to prevent crashes on Linux.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
687 self.chatEdit.setTextColor(color)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
688
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
689 def shutdown(self):
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
690 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
691 Public method to shut down the cooperation system.
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
692 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
693 self.__client.disconnectConnections()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
694 self.__setConnected(False)

eric ide

mercurial