예제 #1
0
 def closeTab(self, index):
     widget = self.tabWidget.widget(index)
     msgBox = QMessageBox()
     msgBox.setText(u'是否真的要关闭: ' + self.tabWidget.tabText(index))
     msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
     msgBox.setDefaultButton(QMessageBox.No)
     msgBox.setWindowTitle(u'关闭tab页')
     info = widget.information()
     if info:
         try:
             accounts = info['accounts']
             text = u'该tab页已登陆帐号:\n'
             for account in accounts:
                 text += account + '\n'
             text.rstrip('\n')
             msgBox.setInformativeText(unicode(text))
         except KeyError:
             pass
     result = msgBox.exec_()
     if result == QMessageBox.Yes:
         for webChat in widget.webchats:
             vmId = webChat.vmId()
             clientId = application.lookUpClientIdByResourceId(vmId)
             message = Message(cmd=Message.CMD_CLOSE_VM)
             message['vmId'] = vmId
             EventManager.trigger(Event('Client.replyReady.' + clientId, message))
         self.tabWidget.removeTab(index)
예제 #2
0
 def _sendAccountData(self, data, clientId):
     accounts = []
     for account in data:
         accounts.append({'id': account[1], 'desc': account[2], 'username': account[3], 'password': account[4]})
     message = Message(cmd=Message.CMD_QUERY_ACCOUNT_OK)
     message['accounts'] = accounts
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #3
0
 def _sendGpsData(self, data, clientId):
     gps_ = []
     for gps in data:
         gps_.append({'id': gps[1], 'desc': gps[2], 'lng': gps[3], 'lat': gps[4]})
     message = Message(cmd=Message.CMD_QUERY_GPS_OK)
     message['gps'] = gps_
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #4
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.controlInfo = ControlInfo()

        self.accountEdit = AccountEdit()
        self.accountList = AccountList()
        accountLayout = QVBoxLayout()
        accountLayout.setContentsMargins(0, 2, 0, 0)
        accountLayout.addWidget(self.accountEdit)
        accountLayout.addWidget(self.accountList)
        w = QWidget()
        w.setLayout(accountLayout)

        self.splitter = QSplitter(Qt.Vertical)
        self.splitter.setHandleWidth(1)
        self.splitter.setChildrenCollapsible(False)
        self.splitter.addWidget(self.controlInfo)
        self.splitter.addWidget(w)

        mainLayout = QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        mainLayout.setSpacing(0)
        mainLayout.addWidget(self.splitter)
        self.setLayout(mainLayout)
        self.setStyleSheet('InfoPanel {border-bottom: 1px solid #818A9A}'
                           'QTableView{border-top: 1px solid #818A9A}')
        self.currentWebchat = None
        EventManager.bind('Webchat.currentChanged', self.setCurrentWebchat)
        self.accountEdit.wantSaveAccount.connect(self.accountList.addItem)
예제 #5
0
 def _addGpsData(self, params, clientId):
     message = Message(cmd=Message.CMD_ADD_GPS_OK, id=params['id'])
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_GPS_ADDED)
     gps = [{'id': params['id'], 'desc': params['desc'], 'lng': params['lng'], 'lat': params['lat']}]
     message['gps'] = gps
     EventManager.trigger(Event('Message.broadcast', message, (clientId,)))
예제 #6
0
 def deleteSelectedItems(self):
     selection = self.gpsTable.selectionModel()
     indexes = selection.selectedRows()
     #uuids: {clientId: [uuid,]}
     uuids = {}
     for index in indexes:
         uuid_ = self.gpsModel.gpsItems[index.row()].id()
         clientId = application.lookUpClientIdByResourceId(uuid_)
         if clientId in uuids:
             uuids[clientId].append(uuid_)
         else:
             uuids[clientId] = [uuid_]
     if len(uuids) == 0:
         return
     for clientId in uuids:
         message = Message(cmd=Message.CMD_DELETE_GPS)
         message['ids'] = uuids[clientId]
         EventManager.trigger(Event('Client.replyReady.' + clientId, message))
         self.deleteGpsItems(uuids[clientId])
         for uuid_ in uuids[clientId]:
             toolBarId = application.lookUpToolBarIdByResourceId(uuid_)
             if toolBarId:
                 EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, True))
             else:
                 Log.e(u'未找到对应的ToolBar')
예제 #7
0
 def dispatchRequest(self, request):
     cmd = request.getCMD()
     if not cmd:
         Log.i('缺少cmd参数')
     identifier = request.getParam('identifier')
     EventManager.trigger(Event('Socket.addReply.' + identifier,
                                request))
예제 #8
0
 def setClientId(self, clientId):
     """服务器与客户端之间的约定为仅设置clientId一次,否则需要修改资源管理器的行为"""
     self.clientId = clientId
     if self.clientId != -1:
         EventManager.bind('Client.replyReady.' + self.clientId,
                           self.addReply)
         application.addResource([], self.clientId)
예제 #9
0
 def handleAddGpsOk(self, request):
     toolBarId = application.lookUpToolBarIdByResourceId(request['id'])
     if toolBarId:
         EventManager.trigger(
             Event('ToolBar.changeState.' + toolBarId, False))
     else:
         Log.e(u'未找到需要改变状态的ToolBar')
예제 #10
0
 def closeTab(self, index):
     widget = self.tabWidget.widget(index)
     msgBox = QMessageBox()
     msgBox.setText(u'是否真的要关闭: ' + self.tabWidget.tabText(index))
     msgBox.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
     msgBox.setDefaultButton(QMessageBox.No)
     msgBox.setWindowTitle(u'关闭tab页')
     info = widget.information()
     if info:
         try:
             accounts = info['accounts']
             text = u'该tab页已登陆帐号:\n'
             for account in accounts:
                 text += account + '\n'
             text.rstrip('\n')
             msgBox.setInformativeText(unicode(text))
         except KeyError:
             pass
     result = msgBox.exec_()
     if result == QMessageBox.Yes:
         for webChat in widget.webchats:
             vmId = webChat.vmId()
             clientId = application.lookUpClientIdByResourceId(vmId)
             message = Message(cmd=Message.CMD_CLOSE_VM)
             message['vmId'] = vmId
             EventManager.trigger(
                 Event('Client.replyReady.' + clientId, message))
         self.tabWidget.removeTab(index)
예제 #11
0
    def closeVM(self, request):
        clientId = request.getParam('clientId')
        if not clientId:
            Log.e('ExternalDispatcher.closeVM: 权限不足')
            return
        if clientId not in self.server.clients:
            Log.e('ExternalDispatcher.closeVM: 该客户端在服务器中不存在')
            return

        vmId = request.getParam('vmId')
        if not vmId:
            Log.e('ExternalDispatcher.closeVM: 缺少虚拟机Id参数')
            return

        for vm in self.externalToVm[clientId]:
            if vm[0] == vmId:
                success, vmInfo = self.vm.closeMachine(vmId)
                if not success:
                    break
                self.externalToVm[clientId].remove(vm)
                message = Message(cmd=Message.CMD_VM_UPDATED,
                                  vmId=vmId,
                                  status=VirtualMachine.Status_Idle)
                EventManager.trigger(Event('Message.broadcast', message, ()))
                return True
        Log.e("关闭虚拟机失败")
예제 #12
0
 def handleSaveClicked(self):
     readable = self.readableEdit.text()
     username = self.nameEdit.text()
     password = self.passwordEdit.text()
     if len(username) > 0 and len(password) > 0:
         resourceId = uuid.uuid4().hex
         account = {
             'id': resourceId,
             'desc': readable,
             'username': username,
             'password': password
         }
         self.wantSaveAccount.emit(account)
         clientId = application.getRandomClientId()
         message = Message(cmd=Message.CMD_ADD_ACCOUNT)
         message['account'] = account
         if clientId:
             EventManager.trigger(
                 Event('Client.replyReady.' + clientId, message))
             application.addResource(resourceId, clientId)
             toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
             if toolBarId:
                 EventManager.trigger(
                     Event('ToolBar.changeState.' + toolBarId, True))
         else:
             Log.e(u'未找到对应的服务器,增加失败')
     else:
         Log.w(u'用户名和密码均不为空时才能保存')
예제 #13
0
 def queryVms(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.queryVms: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.queryVms: 该客户端在服务器中不存在')
         return
     vms = self.vm.getAllMachines()
     vms_ = {}
     for index, vmId in enumerate(vms):
         vm = vms[vmId]
         vms_[vm['name']] = {
             'status': vm['status'],
             'vmId': vmId,
             'vmType': vm['type'],
             'desc': vm['desc']
         }
     message = Message(cmd=Message.CMD_QUERY_VMS_OK)
     message['vms'] = {
         'name': '服务器',
         'serverId': clientId,
         'desc': '',
         'vms': vms_
     }
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #14
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.controlInfo = ControlInfo()

        self.accountEdit = AccountEdit()
        self.accountList = AccountList()
        accountLayout = QVBoxLayout()
        accountLayout.setContentsMargins(0, 2, 0, 0)
        accountLayout.addWidget(self.accountEdit)
        accountLayout.addWidget(self.accountList)
        w = QWidget()
        w.setLayout(accountLayout)

        self.splitter = QSplitter(Qt.Vertical)
        self.splitter.setHandleWidth(1)
        self.splitter.setChildrenCollapsible(False)
        self.splitter.addWidget(self.controlInfo)
        self.splitter.addWidget(w)

        mainLayout = QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        mainLayout.setSpacing(0)
        mainLayout.addWidget(self.splitter)
        self.setLayout(mainLayout)
        self.setStyleSheet(
            'InfoPanel {border-bottom: 1px solid #818A9A}'
            'QTableView{border-top: 1px solid #818A9A}'
        )
        self.currentWebchat = None
        EventManager.bind('Webchat.currentChanged', self.setCurrentWebchat)
        self.accountEdit.wantSaveAccount.connect(self.accountList.addItem)
예제 #15
0
 def loadVms(self, request):
     vms = request['vms']
     clientId = request['clientId']
     pureVms = vms['vms']
     for name in pureVms:
         application.addResource(pureVms[name]['vmId'], clientId)
         application.addItemToToolBar(pureVms[name]['vmId'], 0, 0)
     EventManager.trigger(Event('Message.addVms', vms))
예제 #16
0
 def __init__(self, inSocket, identifier, parent=None):
     QObject.__init__(self, parent)
     self.socket = inSocket
     self.replies = Queue()
     self.requests = Queue()
     self.identifier = identifier
     self.buf = bytes()
     EventManager.bind('Socket.addReply.' + self.identifier, self.addReply)
예제 #17
0
 def loadVms(self, request):
     vms = request['vms']
     clientId = request['clientId']
     pureVms = vms['vms']
     for name in pureVms:
         application.addResource(pureVms[name]['vmId'], clientId)
         application.addItemToToolBar(pureVms[name]['vmId'], 0, 0)
     EventManager.trigger(Event('Message.addVms', vms))
예제 #18
0
 def registerCurrentLocation(self, *args):
     if len(args) == 1 and isinstance(args[0], dict):
         current = args[0]
     elif len(args) == 3:
         current = {'desc': args[2], 'lng': args[0], 'lat': args[1]}
     else:
         raise ValueError(u'参数个数不合法')
     EventManager.trigger(Event('Map.locationChanged', current))
예제 #19
0
 def startNewVm(self, info):
     webchat = WebChat(info['vmId'], info['vmType'], info['desc'])
     index, tab = self.tabContainer.lookUpVmSpace()
     tab.addWebchat(webchat)
     self.tabContainer.adjustTabName(tab)
     self.tabContainer.setCurrentWidget(tab, index)
     message = Message(cmd=Message.CMD_START_VM, vmId=info['vmId'])
     EventManager.trigger(Event('Client.replyReady.' + info['serverId'], message))
예제 #20
0
 def registerCurrentLocation(self, *args):
     if len(args) == 1 and isinstance(args[0], dict):
         current = args[0]
     elif len(args) == 3:
         current = {'desc': args[2], 'lng': args[0], 'lat': args[1]}
     else:
         raise ValueError(u'参数个数不合法')
     EventManager.trigger(Event('Map.locationChanged', current))
예제 #21
0
 def _addAccountData(self, params, clientId):
     message = Message(cmd=Message.CMD_ADD_ACCOUNT_OK, id=params['id'])
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_ACCOUNT_ADDED)
     accounts = [{'id': params['id'], 'desc': params['desc'], 'username': params['username'],
                 'password': params['password']}]
     message['accounts'] = accounts
     EventManager.trigger(Event('Message.broadcast', message, (clientId,)))
예제 #22
0
 def startNewVm(self, info):
     webchat = WebChat(info['vmId'], info['vmType'], info['desc'])
     index, tab = self.tabContainer.lookUpVmSpace()
     tab.addWebchat(webchat)
     self.tabContainer.adjustTabName(tab)
     self.tabContainer.setCurrentWidget(tab, index)
     message = Message(cmd=Message.CMD_START_VM, vmId=info['vmId'])
     EventManager.trigger(
         Event('Client.replyReady.' + info['serverId'], message))
예제 #23
0
 def setupDatabase(self):
     from collections import OrderedDict
     self.db = Database('chat-advance.db')
     if not self.db.createConnection():
         EventManager.trigger(Event('Database.databaseConnectionFail'))
         return
     if not self.db.isTableExist(DataCenter.TABLE_FRIENDS):
         self.db.createTable(DataCenter.TABLE_SERVERS, OrderedDict([('name', Database.TYPE_TEXT),
                             ('url', Database.TYPE_TEXT), ('port', Database.TYPE_TEXT)]))
예제 #24
0
 def queryAccount(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.queryAccount: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.queryAccount: 该客户端在服务器中不存在')
         return
     EventManager.trigger(Event('DataCenter.loadAllAccount', clientId))
예제 #25
0
 def handleDeleteGpsOk(self, request):
     ids = request['ids']
     for id_ in ids:
         toolBarId = application.lookUpToolBarIdByResourceId(id_)
         if toolBarId:
             EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, False))
         else:
             Log.e(u'未找到需要改变状态的ToolBar')
         application.delItemFromToolBar(id_)
예제 #26
0
 def queryAccount(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.queryAccount: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.queryAccount: 该客户端在服务器中不存在')
         return
     EventManager.trigger(Event('DataCenter.loadAllAccount', clientId))
예제 #27
0
 def updateGps(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.updateGps: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.updateGps: 该客户端在服务器中不存在')
         return
     EventManager.trigger(Event('DataCenter.updateGps', request['id'], request['desc'], clientId))
예제 #28
0
 def clearVmForClient(self, clientId):
     if clientId in self.externalToVm:
         for vm in self.externalToVm[clientId]:
             success, vmInfo = self.vm.closeMachine(vm[0])
             if not success:
                 Log.e('关闭虚拟机失败:' + vm[1]['name'])
                 continue
             message = Message(cmd=Message.CMD_VM_UPDATED, vmId=vm[0], status=VirtualMachine.Status_Idle)
             EventManager.trigger(Event('Message.broadcast', message, ()))
         del self.externalToVm[clientId]
예제 #29
0
 def handleDeleteGpsOk(self, request):
     ids = request['ids']
     for id_ in ids:
         toolBarId = application.lookUpToolBarIdByResourceId(id_)
         if toolBarId:
             EventManager.trigger(
                 Event('ToolBar.changeState.' + toolBarId, False))
         else:
             Log.e(u'未找到需要改变状态的ToolBar')
         application.delItemFromToolBar(id_)
예제 #30
0
 def deleteGps(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.deleteGps: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.deleteGps: 该客户端在服务器中不存在')
         return
     EventManager.trigger(
         Event('DataCenter.deleteGps', request['ids'], clientId))
예제 #31
0
 def clearVmForClient(self, clientId):
     if clientId in self.externalToVm:
         for vm in self.externalToVm[clientId]:
             success, vmInfo = self.vm.closeMachine(vm[0])
             if not success:
                 Log.e('关闭虚拟机失败:' + vm[1]['name'])
                 continue
             message = Message(cmd=Message.CMD_VM_UPDATED,
                               vmId=vm[0],
                               status=VirtualMachine.Status_Idle)
             EventManager.trigger(Event('Message.broadcast', message, ()))
         del self.externalToVm[clientId]
예제 #32
0
 def __init__(self, port, parent=None):
     QThread.__init__(self, parent)
     self.port = port
     self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.serverSocket.bind(('', self.port))
     self.serverSocket.listen(5)
     self.serverSocket.setblocking(False)
     self.dispatcher = Dispatcher(self)
     #clients --> {clientId: Socket object}
     self.clients = {}
     EventManager.bind('Message.broadcast', self.broadcast)
예제 #33
0
 def _sendGpsData(self, data, clientId):
     gps_ = []
     for gps in data:
         gps_.append({
             'id': gps[1],
             'desc': gps[2],
             'lng': gps[3],
             'lat': gps[4]
         })
     message = Message(cmd=Message.CMD_QUERY_GPS_OK)
     message['gps'] = gps_
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #34
0
 def addGps(self, request):
     clientId = request.getParam('clientId')
     gps = request['gps']
     if not clientId:
         Log.e('ExternalDispatcher.updateGps: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.updateGps: 该客户端在服务器中不存在')
         return
     EventManager.trigger(
         Event('DataCenter.addGps', gps['id'], gps['desc'], gps['lng'],
               gps['lat'], clientId))
예제 #35
0
 def _addGpsData(self, params, clientId):
     message = Message(cmd=Message.CMD_ADD_GPS_OK, id=params['id'])
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_GPS_ADDED)
     gps = [{
         'id': params['id'],
         'desc': params['desc'],
         'lng': params['lng'],
         'lat': params['lat']
     }]
     message['gps'] = gps
     EventManager.trigger(Event('Message.broadcast', message, (clientId, )))
예제 #36
0
 def addAccount(self, request):
     clientId = request.getParam('clientId')
     account = request['account']
     if not clientId:
         Log.e('ExternalDispatcher.addAccount: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.addAccount: 该客户端在服务器中不存在')
         return
     EventManager.trigger(
         Event('DataCenter.addAccount', account['id'], account['desc'],
               account['username'], account['password'], clientId))
예제 #37
0
 def dispatchRequest(self, request):
     cmd = request.getCMD()
     if cmd in self.callbacks:
         self.callbacks[cmd](request)
     elif Message.CMD_BRIDGE_START <= cmd < Message.CMD_WEBCHAT_END:
         try:
             webchatId = request.getParam('webchatId')
             EventManager.trigger(Event('Socket.addReply.' + webchatId, request))
         except Exception as e:
             Log.e(getExceptionInfo(e))
     else:
         Log.w('未实现的命令: ' + str(cmd))
예제 #38
0
 def _sendAccountData(self, data, clientId):
     accounts = []
     for account in data:
         accounts.append({
             'id': account[1],
             'desc': account[2],
             'username': account[3],
             'password': account[4]
         })
     message = Message(cmd=Message.CMD_QUERY_ACCOUNT_OK)
     message['accounts'] = accounts
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #39
0
 def _addAccountData(self, params, clientId):
     message = Message(cmd=Message.CMD_ADD_ACCOUNT_OK, id=params['id'])
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_ACCOUNT_ADDED)
     accounts = [{
         'id': params['id'],
         'desc': params['desc'],
         'username': params['username'],
         'password': params['password']
     }]
     message['accounts'] = accounts
     EventManager.trigger(Event('Message.broadcast', message, (clientId, )))
예제 #40
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.createModelAndView()
     #self.createOp()
     mainLayout = QVBoxLayout()
     mainLayout.setContentsMargins(0, 0, 0, 0)
     mainLayout.setSpacing(0)
     mainLayout.addWidget(self.treeView)
     self.setLayout(mainLayout)
     self.setStyleSheet('QLineEdit{padding: 0;}')
     EventManager.bind('Message.addVms', self.addVms)
     EventManager.bind('Message.updateVm', self.resetVm)
예제 #41
0
 def setCurrent(self, index):
     if index == -1:
         self.current = None
         EventManager.trigger(Event('Webchat.currentChanged', self.current))
         return
     self.webchats[index].setStyleSheet(
         "WebChat{background-color: #b2d235;}")
     self.current = self.webchats[index]
     for i, webchat in enumerate(self.webchats):
         if i != index:
             self.webchats[i].setStyleSheet(
                 "WebChat{background-color: #FF0;}")
     EventManager.trigger(Event('Webchat.currentChanged', self.current))
예제 #42
0
 def addAccount(self, request):
     clientId = request.getParam('clientId')
     account = request['account']
     if not clientId:
         Log.e('ExternalDispatcher.addAccount: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.addAccount: 该客户端在服务器中不存在')
         return
     EventManager.trigger(
         Event('DataCenter.addAccount', account['id'], account['desc'], account['username'],
               account['password'], clientId)
     )
예제 #43
0
 def dispatchRequest(self, request):
     cmd = request.getCMD()
     if cmd in self.callbacks:
         self.callbacks[cmd](request)
     elif Message.CMD_BRIDGE_START <= cmd < Message.CMD_WEBCHAT_END:
         try:
             webchatId = request.getParam('webchatId')
             EventManager.trigger(
                 Event('Socket.addReply.' + webchatId, request))
         except Exception as e:
             Log.e(getExceptionInfo(e))
     else:
         Log.w('未实现的命令: ' + str(cmd))
예제 #44
0
 def updateVm(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.updateVm: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.updateVm: 该客户端在服务器中不存在')
     vmId = request['vmId']
     self.vm.setGuestPropertyValue(vmId, 'desc', request['desc'])
     message = Message(cmd=Message.CMD_UPDATE_VM_OK, vmId=vmId)
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_VM_UPDATED, vmId=vmId, desc=request['desc'])
     EventManager.trigger(Event('Message.broadcast', message, (clientId,)))
예제 #45
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.createModelAndView()
     #self.createOp()
     mainLayout = QVBoxLayout()
     mainLayout.setContentsMargins(0, 0, 0, 0)
     mainLayout.setSpacing(0)
     mainLayout.addWidget(self.treeView)
     self.setLayout(mainLayout)
     self.setStyleSheet(
         'QLineEdit{padding: 0;}'
     )
     EventManager.bind('Message.addVms', self.addVms)
     EventManager.bind('Message.updateVm', self.resetVm)
예제 #46
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.tabWidget = QTabWidget()
     self.tabWidget.setTabsClosable(True)
     self.tabWidget.setMovable(True)
     self.tabWidget.tabCloseRequested.connect(self.closeTab)
     mainLayout = QHBoxLayout()
     mainLayout.addWidget(self.tabWidget)
     mainLayout.setContentsMargins(0, 0, 0, 0)
     mainLayout.setSpacing(0)
     self.setLayout(mainLayout)
     self.tabWidget.currentChanged.connect(self.resetCurrentWebchat)
     EventManager.bind('Message.vmStarted', self.syncVideoOfVm)
     EventManager.bind('Message.vmStartFail', self.closeWebchat)
예제 #47
0
 def __init__(self, parent=None):
     QWidget.__init__(self, parent)
     self.tabWidget = QTabWidget()
     self.tabWidget.setTabsClosable(True)
     self.tabWidget.setMovable(True)
     self.tabWidget.tabCloseRequested.connect(self.closeTab)
     mainLayout = QHBoxLayout()
     mainLayout.addWidget(self.tabWidget)
     mainLayout.setContentsMargins(0, 0, 0, 0)
     mainLayout.setSpacing(0)
     self.setLayout(mainLayout)
     self.tabWidget.currentChanged.connect(self.resetCurrentWebchat)
     EventManager.bind('Message.vmStarted', self.syncVideoOfVm)
     EventManager.bind('Message.vmStartFail', self.closeWebchat)
예제 #48
0
 def updateVm(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.updateVm: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.updateVm: 该客户端在服务器中不存在')
     vmId = request['vmId']
     self.vm.setGuestPropertyValue(vmId, 'desc', request['desc'])
     message = Message(cmd=Message.CMD_UPDATE_VM_OK, vmId=vmId)
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
     message = Message(cmd=Message.CMD_VM_UPDATED,
                       vmId=vmId,
                       desc=request['desc'])
     EventManager.trigger(Event('Message.broadcast', message, (clientId, )))
예제 #49
0
 def queryVms(self, request):
     clientId = request.getParam('clientId')
     if not clientId:
         Log.e('ExternalDispatcher.queryVms: 权限不足')
         return
     if clientId not in self.server.clients:
         Log.e('ExternalDispatcher.queryVms: 该客户端在服务器中不存在')
         return
     vms = self.vm.getAllMachines()
     vms_ = {}
     for index, vmId in enumerate(vms):
         vm = vms[vmId]
         vms_[vm['name']] = {'status': vm['status'], 'vmId': vmId, 'vmType': vm['type'], 'desc': vm['desc']}
     message = Message(cmd=Message.CMD_QUERY_VMS_OK)
     message['vms'] = {'name': '服务器', 'serverId': clientId, 'desc': '', 'vms': vms_}
     EventManager.trigger(Event('Socket.addReply.' + clientId, message))
예제 #50
0
 def editVm(self, index, unused, roles):
     """同步修改到服务器,只能修改虚拟机备注"""
     if Qt.EditRole not in roles:
         self.treeView.update()
         return
     item = self.model.itemForIndex(index)
     resourceId = item.id()
     clientId = application.lookUpClientIdByResourceId(resourceId)
     if clientId:
         message = Message(cmd=Message.CMD_UPDATE_VM)
         message['vmId'] = resourceId
         message['desc'] = item.description()
         EventManager.trigger(Event('Client.replyReady.' + clientId, message))
         toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
         if toolBarId:
             print 'ToolBar.changeState.' + toolBarId
             EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, True))
예제 #51
0
 def editLocation(self, index, unused, roles):
     """同步修改到服务器,对于GPS坐标来说,客户端只能更改坐标备注"""
     if Qt.EditRole not in roles:
         self.gpsTable.update()
         return
     item = self.gpsModel.itemForIndex(index)
     resourceId = item.id()
     clientId = application.lookUpClientIdByResourceId(resourceId)
     if clientId:
         message = Message(cmd=Message.CMD_UPDATE_GPS)
         message['id'] = resourceId
         message['desc'] = item.description()
         EventManager.trigger(Event('Client.replyReady.' + clientId, message))
         toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
         if toolBarId:
             print 'ToolBar.changeState.' + toolBarId
             EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, True))
     else:
         Log.e(u'未找到对应的服务器,修改失败')
예제 #52
0
 def editVm(self, index, unused, roles):
     """同步修改到服务器,只能修改虚拟机备注"""
     if Qt.EditRole not in roles:
         self.treeView.update()
         return
     item = self.model.itemForIndex(index)
     resourceId = item.id()
     clientId = application.lookUpClientIdByResourceId(resourceId)
     if clientId:
         message = Message(cmd=Message.CMD_UPDATE_VM)
         message['vmId'] = resourceId
         message['desc'] = item.description()
         EventManager.trigger(
             Event('Client.replyReady.' + clientId, message))
         toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
         if toolBarId:
             print 'ToolBar.changeState.' + toolBarId
             EventManager.trigger(
                 Event('ToolBar.changeState.' + toolBarId, True))
예제 #53
0
파일: bars.py 프로젝트: RoyZeng/ivy-webchat
 def __init__(self, title=None, parent=None):
     QWidget.__init__(self, parent)
     self._id = uuid.uuid4().hex
     self.label = QLabel()
     self.label.setAlignment(Qt.AlignCenter)
     if title:
         self.setTitle(title)
     self.indicator = StatusIndicator()
     self.indicatorReference = 0
     mainLayout = QHBoxLayout()
     mainLayout.addWidget(self.label, 0, Qt.AlignVCenter | Qt.AlignLeading)
     mainLayout.addWidget(self.indicator, 0, Qt.AlignVCenter | Qt.AlignLeft)
     mainLayout.addStretch()
     mainLayout.setContentsMargins(4, 4, 4, 4)
     mainLayout.setSpacing(5)
     self.setLayout(mainLayout)
     self.hideIndicator()
     EventManager.bind('ToolBar.changeState.' + self._id, self.changeIndicatorStatus)
     print 'ToolBar.changeState.' + self._id
예제 #54
0
 def setupDatabase(self):
     from collections import OrderedDict
     self.db = Database('server.db')
     if not self.db.createConnection():
         EventManager.trigger(Event('Database.databaseConnectionFail'))
         return
     if not self.db.isTableExist(DataCenter.TABLE_GPS):
         self.db.createTable(
             DataCenter.TABLE_GPS, OrderedDict(
                 [('uuid', Database.TYPE_TEXT), ('desc', Database.TYPE_TEXT), ('lng', Database.TYPE_TEXT),
                  ('lat', Database.TYPE_TEXT)]
             )
         )
     if not self.db.isTableExist(DataCenter.TABLE_ACCOUNT):
         self.db.createTable(
             DataCenter.TABLE_ACCOUNT, OrderedDict(
                 [('uuid', Database.TYPE_TEXT), ('desc', Database.TYPE_TEXT), ('username', Database.TYPE_TEXT),
                  ('password', Database.TYPE_TEXT)]
             )
         )
예제 #55
0
 def editAccount(self, index, unused, roles):
     """同步修改到服务器"""
     if Qt.EditRole not in roles:
         self.table.update()
         return
     item = self.model.itemForIndex(index)
     resourceId = item.id()
     clientId = application.lookUpClientIdByResourceId(resourceId)
     if clientId:
         message = Message(cmd=Message.CMD_UPDATE_ACCOUNT)
         message['id'] = resourceId
         message['desc'] = item.description()
         message['username'] = item.username()
         message['password'] = item.password()
         EventManager.trigger(Event('Client.replyReady.' + clientId, message))
         toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
         if toolBarId:
             print 'ToolBar.changeState.' + toolBarId
             EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, True))
     else:
         Log.e(u'未找到对应的服务器,修改失败')
예제 #56
0
 def handleSaveClicked(self):
     readable = self.readableEdit.text()
     lng = self.lngEdit.text()
     lat = self.latEdit.text()
     if len(lng) > 0 and len(lat) > 0:
         resourceId = uuid.uuid4().hex
         gps = {'id': resourceId, 'desc': readable, 'lng': lng, 'lat': lat}
         self.wantSaveLocation.emit(gps)
         clientId = application.getRandomClientId()
         message = Message(cmd=Message.CMD_ADD_GPS)
         message['gps'] = gps
         if clientId:
             EventManager.trigger(Event('Client.replyReady.' + clientId, message))
             application.addResource(resourceId, clientId)
             toolBarId = application.lookUpToolBarIdByResourceId(resourceId)
             if toolBarId:
                 EventManager.trigger(Event('ToolBar.changeState.' + toolBarId, True))
         else:
             Log.e(u'未找到对应的服务器,增加失败')
     else:
         Log.w(u'经度和纬度均不为空时才能保存')