eric6/Cooperation/ChatWidget.py

Sun, 02 Feb 2020 11:04:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2020 11:04:32 +0100
changeset 7380
c99320e859ca
parent 7360
9190402e4505
child 7533
88261c96484b
permissions
-rw-r--r--

Fixed an issue related to showing the application name in the menu bar of Gnome desktop under Wayland.

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
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
10
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 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
12 from PyQt5.QtGui import QColor
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 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
14
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
15 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
16 from E5Gui import E5MessageBox, E5FileDialog
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
17
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
18 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
19
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 from .CooperationClient import CooperationClient
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 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
23
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 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
25 import Utilities
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 import UI.PixmapCache
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
28
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 class ChatWidget(QWidget, Ui_ChatWidget):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Class implementing the chat dialog.
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
32
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
33 @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
34 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
35 @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
36 command has been received (string, string, string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
37 @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
38 @signal startEdit() emitted to start a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
39 @signal sendEdit() emitted to send a shared edit session
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
40 @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
41 """
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
42 connected = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
43 editorCommand = pyqtSignal(str, str, str)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
44
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
45 shareEditor = pyqtSignal(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
46 startEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
47 sendEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
48 cancelEdit = pyqtSignal()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
49
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
50 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
51 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 Constructor
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
54 @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
55 @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
56 @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
57 """
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
58 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
59 self.setupUi(self)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
61 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
62 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
63 self.startEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
64 UI.PixmapCache.getIcon("sharedEditStart.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
65 self.sendEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
66 UI.PixmapCache.getIcon("sharedEditSend.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
67 self.cancelEditButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
68 UI.PixmapCache.getIcon("sharedEditCancel.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
69
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
70 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
71 self.__client = CooperationClient(self)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__myNickName = self.__client.nickName()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
165
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.__initChatMenu()
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
75 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
76
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 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
78 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
79 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
80 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
81 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
82 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
83 self.__client.cannotConnect.connect(self.__initialConnectionRefused)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
84 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
85
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
86 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
87 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
88 if port == -1:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 port = Preferences.getCooperation("ServerPort")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 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
97
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
98 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
99 self.__loadHostsHistory()
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
100
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
101 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
102 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
103 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
104 """
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
105 self.__recent = []
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113
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
114 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
115 """
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
116 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
117 """
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
118 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
119 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
120
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
121 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
122 """
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
123 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
124
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
125 @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
126 """
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
127 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
128 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
129 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
130 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
131 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
132 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
133
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 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
135 """
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 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
137 """
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.__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
139 self.__saveHostsHistory()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
140 self.hostEdit.clear()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
141 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
142
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 def __handleMessage(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 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
146 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 text = self.messageEdit.text()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 if text == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if text.startswith("/"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 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
153 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
154 .format(text.split()[0]))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 self.__client.sendMessage(text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.appendMessage(self.__myNickName, text)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 self.messageEdit.clear()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 def __newParticipant(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 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
164
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @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
166 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 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
173 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
174 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
175 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
176 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 QListWidgetItem(
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 UI.PixmapCache.getIcon(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
180 "chatUser{0}.png".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
181 nick, self.usersList)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 self.__setConnected(True)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
185
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
186 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
187 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
188 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
189 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
190 .format(nick))
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
191
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 def __participantLeft(self, nick):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 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
195
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 @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
197 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if nick == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 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
202 for item in items:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 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
204 del item
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 self.chatEdit.setTextColor(Qt.gray)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 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
209 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
210 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
211 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
212 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 if not self.__client.hasConnections():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 self.__setConnected(False)
2190
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
216
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
217 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
218 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
219 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
220 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
221 .format(nick))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 def appendMessage(self, from_, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 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
226
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 @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
228 @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
229 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 if from_ == "" or message == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 return
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 self.chatEdit.append(
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
234 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
235 " <" + from_ + ">:")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.chatEdit.append(message + "\n")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 bar = self.chatEdit.verticalScrollBar()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 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
239
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
240 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
241 self.__ui.showNotification(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
242 UI.PixmapCache.getPixmap("cooperation48.png"),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
243 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
244
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @pyqtSlot(str)
161
bb3cc98f4104 Added code to remember the 20 most recently connected hosts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 160
diff changeset
246 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
247 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 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
249
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 @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
251 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 if not self.__connected:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 self.connectButton.setEnabled(host != "")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
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
255 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
256 """
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
257 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
258
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 @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
260 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
261 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
262 if "@" in hostEntry:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270 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
271 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
272 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
273 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
274
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 @pyqtSlot()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 def on_connectButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 Private slot initiating the connection.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 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
281 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
282 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
283 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
284 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
285 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
286 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
287 self.__setConnected(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 self.__client.disconnectConnections()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292 @pyqtSlot()
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
293 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
294 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
295 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
296 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
297 self.__clearHostsHistory()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
298
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
299 @pyqtSlot()
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 def on_serverButton_clicked(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 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
303 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
304 if self.__client.isListening():
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
305 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
306 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
307 self.serverPortSpin.setEnabled(True)
3021
801289962f4e Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
308 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
309 Preferences.getCooperation("ServerPort")):
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
310 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
311 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 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
313 else:
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
314 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
315 self.serverPortSpin.value())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 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
317 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
318 self.serverPortSpin.setValue(port)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 self.serverPortSpin.setEnabled(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 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
321 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 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
323 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
324 self.__client.errorString())
149
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
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 def __setConnected(self, connected):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 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
330
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 @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
332 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 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
334 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
335 self.connectButton.setEnabled(True)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 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
337 else:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
338 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
339 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
340 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
341 self.on_cancelEditButton_clicked()
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
342 self.shareButton.setChecked(False)
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 163
diff changeset
343 self.on_shareButton_clicked(False)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
344 self.__connected = connected
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
345 self.hostEdit.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
346 self.serverButton.setEnabled(not connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
347 self.sharingGroup.setEnabled(connected)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
348
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
349 if connected:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
350 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
351 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
352 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
353 self.checkEditorActions(aw)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def __showErrorMessage(self, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 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
358
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 @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
360 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 color = self.chatEdit.textColor()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 self.chatEdit.setTextColor(Qt.red)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 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
364 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
365 ":")
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
366 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
367 self.chatEdit.setTextColor(color)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 def __initialConnectionRefused(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 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
372 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 self.__setConnected(False)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 def preferencesChanged(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
379 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
380 self.serverPortSpin.setValue(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
381 Preferences.getCooperation("ServerPort"))
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 if Preferences.getCooperation("AutoStartServer"):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 self.on_serverButton_clicked()
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
384
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
385 def getClient(self):
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
386 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
387 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
388
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2436
diff changeset
389 @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
390 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
391 return self.__client
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
392
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
393 def __editorCommandMessage(self, hashStr, fileName, message):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
394 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
395 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
396
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
397 @param hashStr hash of the project (string)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
398 @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
399 @param message command message (string)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
400 """
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
401 self.editorCommand.emit(hashStr, fileName, message)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
402
2400
c1726b754f96 Started with delaying the import upon the time it is needed.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
403 from QScintilla.Editor import Editor
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
404 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
405 message.startswith(Editor.EndEditToken + Editor.Separator)):
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
406 vm = e5App().getObject("ViewManager")
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
407 aw = vm.activeWindow()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
408 if aw:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
409 self.checkEditorActions(aw)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
410
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
411 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
412 def on_shareButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
413 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
414 Private slot to share the current editor.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
415
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
416 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
417 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
418 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
419 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
420 UI.PixmapCache.getIcon("sharedEditConnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
421 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
422 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
423 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
424 self.startEditButton.setEnabled(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
425
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
426 self.shareEditor.emit(checked)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
427
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
428 @pyqtSlot(bool)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
429 def on_startEditButton_clicked(self, checked):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
430 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
431 Private slot to start a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
432
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
433 @param checked flag indicating the button state (boolean)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
434 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
435 if checked:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
436 self.sendEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
437 self.cancelEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
438 self.shareButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
439 self.startEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
440
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
441 self.startEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
442
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
443 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
444 def on_sendEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
445 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
446 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
447 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
448 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
449 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
450 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
451 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
452 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
453
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
454 self.sendEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
455
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
456 @pyqtSlot()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
457 def on_cancelEditButton_clicked(self):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
458 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
459 Private slot to cancel a shared edit session.
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
460 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
461 self.sendEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
462 self.cancelEditButton.setEnabled(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
463 self.shareButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
464 self.startEditButton.setEnabled(True)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
465 self.startEditButton.setChecked(False)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
466
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
467 self.cancelEdit.emit()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
468
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
469 def checkEditorActions(self, editor):
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
470 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
471 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
472
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
473 @param editor reference to the editor (Editor)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
474 """
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
475 shareable, sharing, editing, remoteEditing = editor.getSharingStatus()
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
476
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
477 self.shareButton.setChecked(sharing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
478 if sharing:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
479 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
480 UI.PixmapCache.getIcon("sharedEditConnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
481 else:
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
482 self.shareButton.setIcon(
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
483 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
484 self.startEditButton.setChecked(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
485
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
486 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
487 self.startEditButton.setEnabled(
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
488 sharing and not editing and not remoteEditing)
158
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
489 self.sendEditButton.setEnabled(editing)
6a561f87bc07 Added shared editor functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
490 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
491
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
492 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
493 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
494 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
495 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
496 self.__chatMenu = QMenu(self)
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
497 self.__copyChatAct = self.__chatMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
498 UI.PixmapCache.getIcon("editCopy.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
499 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
500 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
501 self.__cutAllChatAct = self.__chatMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
502 UI.PixmapCache.getIcon("editCut.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
503 self.tr("Cut all"), self.__cutAllChat)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
504 self.__copyAllChatAct = self.__chatMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
505 UI.PixmapCache.getIcon("editCopy.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
506 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
507 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
508 self.__clearChatAct = self.__chatMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
509 UI.PixmapCache.getIcon("editDelete.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
510 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
511 self.__chatMenu.addSeparator()
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
512 self.__saveChatAct = self.__chatMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
513 UI.PixmapCache.getIcon("fileSave.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
514 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
515
810e9c7b61e3 Fixed a little issue in the initialisation of the Cooperation Chat window.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2223
diff changeset
516 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
517
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
518 @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
519 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
520 """
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 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
522
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 @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
524 """
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 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
526
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
527 @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
528 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
529 """
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 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
531
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 @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
533 """
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
534 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
535 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
536 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
537 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
538 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
539
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 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
541 """
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 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
543 """
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 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
545
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 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
547 """
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 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
549 """
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 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
551 if txt:
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
552 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
553 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
554 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
555 "",
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
556 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
557 None,
882
34b86be88bf0 Redid the native file dialog code to be future proof.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 880
diff changeset
558 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
559 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
560 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
561 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
562 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
563 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
564 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
565 if QFileInfo(fname).exists():
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
566 res = E5MessageBox.yesNo(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
567 self,
3190
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("Save Chat"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
569 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
570 " 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
571 icon=E5MessageBox.Warning)
546
c3e7bf5648be Continued replacing QMessageBox.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 539
diff changeset
572 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
573 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
574 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
575
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
576 try:
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 882
diff changeset
577 f = open(fname, "w", encoding="utf-8")
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
578 f.write(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
579 f.close()
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
580 except IOError as err:
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
581 E5MessageBox.critical(
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2986
diff changeset
582 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
583 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
584 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
585 """ 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
586 """<p>Reason: {1}</p>""") .format(
3032
927a2f8b3669 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3021
diff changeset
587 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
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 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
590 """
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
591 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
592 """
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
593 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
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 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
596 """
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 161
diff changeset
597 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
598 """
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
599 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
600 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
601 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
602 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
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 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
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 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
607 """
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 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
609 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
610 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
611 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
612 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
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 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
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 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
617 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
618 self.__usersMenu = QMenu(self)
7250
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
619 self.__kickUserAct = self.__usersMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
620 UI.PixmapCache.getIcon("chatKickUser.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
621 self.tr("Kick User"), self.__kickUser)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
622 self.__banUserAct = self.__usersMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
623 UI.PixmapCache.getIcon("chatBanUser.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
624 self.tr("Ban User"), self.__banUser)
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
625 self.__banKickUserAct = self.__usersMenu.addAction(
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
626 UI.PixmapCache.getIcon("chatBanKickUser.png"),
d8bdc55aee1a Started to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
627 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
628
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
629 @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
630 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
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 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
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 @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
635 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
636 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
637 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
638 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
639 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
640 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
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 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
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 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
645 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
646 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
647 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
648
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
649 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
650 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
651 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
652 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
653 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
654 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
655 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
656 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
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 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
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 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
661 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
662 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
663 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
664
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
665 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
666 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
667 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
668 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
669 ":")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
670 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
671 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
672 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
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 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
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 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
677 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
678 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
679 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
680
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
681 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
682 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
683 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
684 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
685 ":")
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
686 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
687 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
688 .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
689 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
690
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
691 def shutdown(self):
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 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
694 """
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
695 self.__client.disconnectConnections()
abd65b78425e Added a notification system and updated the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
696 self.__setConnected(False)

eric ide

mercurial