From 8a155895a4b5288034224e10c84fc80adfa0eebe Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sun, 22 Aug 2010 13:44:23 +0200 Subject: [PATCH] add channel functions: add/delete/change name, description. fixes #89 --- pyweb/mumble/MumbleCtlDbus.py | 12 ++++++ pyweb/mumble/MumbleCtlIce.py | 23 +++++++++++ pyweb/mumble/media/js/channelviewerplugins.js | 40 ++++++++++++++++++- pyweb/mumble/models.py | 9 +++++ pyweb/mumble/templates/mumble/mumble.html | 4 +- pyweb/mumble/views.py | 21 ++++++++++ 6 files changed, 107 insertions(+), 2 deletions(-) diff --git a/pyweb/mumble/MumbleCtlDbus.py b/pyweb/mumble/MumbleCtlDbus.py index 2118bba..f94cb65 100644 --- a/pyweb/mumble/MumbleCtlDbus.py +++ b/pyweb/mumble/MumbleCtlDbus.py @@ -306,6 +306,18 @@ class MumbleCtlDbus_118(MumbleCtlBase): (session, ismute, isdeaf, suppressed, selfMute, selfDeaf, channel) = srv.getPlayerState(dbus.UInt32(sessionid)) srv.setPlayerState((session, ismute, deaf, suppressed, selfMute, selfDeaf, channel)) + def addChannel( self, srvid, name, parentid ): + return self._getDbusServerObject(srvid).addChannel( name.encode( "UTF-8" ), parentid ) + + def removeChannel( self, srvid, channelid ): + return self._getDbusServerObject(srvid).removeChannel( channelid ) + + def renameChannel( self, srvid, channelid, name, description ): + srv = self._getDbusServerObject(srvid) + state = srv.getChannelState(channelid) + (chanid, oldname, parent, links) = srv.getChannelState(dbus.UInt32(channelid)) + srv.setChannelState((chanid, name, parent, links)) + def moveChannel(self, srvid, channelid, parentid): srv = self._getDbusServerObject(srvid) (chanid, name, parent, links) = srv.getChannelState(dbus.UInt32(channelid)) diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index 21dd20f..f74aa98 100644 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -434,6 +434,21 @@ class MumbleCtlIce_118(MumbleCtlBase): def getLog( self, srvid, first=0, last=100 ): return self._getIceServerObject(srvid).getLog( first, last ) + @protectDjangoErrPage + def addChannel( self, srvid, name, parentid ): + return self._getIceServerObject(srvid).addChannel( name.encode( "UTF-8" ), parentid ) + + @protectDjangoErrPage + def removeChannel( self, srvid, channelid ): + return self._getIceServerObject(srvid).removeChannel( channelid ) + + @protectDjangoErrPage + def renameChannel( self, srvid, channelid, name, description ): + srv = self._getIceServerObject(srvid) + state = srv.getChannelState(channelid) + state.name = name.encode("UTF-8") + srv.setChannelState(state) + @protectDjangoErrPage def moveChannel(self, srvid, channelid, parentid): srv = self._getIceServerObject(srvid) @@ -602,6 +617,14 @@ class MumbleCtlIce_120(MumbleCtlIce_118): def kickUser(self, srvid, userid, reason=""): return self._getIceServerObject(srvid).kickUser( userid, reason.encode("UTF-8") ) + @protectDjangoErrPage + def renameChannel( self, srvid, channelid, name, description ): + srv = self._getIceServerObject(srvid) + state = srv.getChannelState(channelid) + state.name = name.encode("UTF-8") + state.description = description.encode("UTF-8") + srv.setChannelState(state) + @protectDjangoErrPage def getUptime(self, srvid): return self._getIceServerObject(srvid).getUptime() diff --git a/pyweb/mumble/media/js/channelviewerplugins.js b/pyweb/mumble/media/js/channelviewerplugins.js index 74cb04d..85d93c7 100644 --- a/pyweb/mumble/media/js/channelviewerplugins.js +++ b/pyweb/mumble/media/js/channelviewerplugins.js @@ -150,6 +150,7 @@ Ext.ux.MumbleChannelEditor = Ext.extend( Ext.Component, { activate: function( chandata ){ if( !this.wnd ){ + this.chandata = chandata; this.wnd = new Ext.Window({ title: this.windowTitle || gettext("Channel details"), layout: 'fit', @@ -162,12 +163,49 @@ Ext.ux.MumbleChannelEditor = Ext.extend( Ext.Component, { title: gettext("Channel description"), defaults: { "anchor": "-20px" }, items: [{ + xtype: "textfield", + fieldLabel: "x", + hideLabel: true, + name: "name", + value: chandata.name + }, { xtype: "htmleditor", fieldLabel: 'x', hideLabel: true, name: "description", - value: chandata.description, + value: chandata.description }], + fbar: [{ + text: gettext('Add subchannel...'), + scope: this, + handler: function(btn){ + Ext.Msg.prompt(gettext('Name'), gettext('Please enter the channel name:'), function(btn, text){ + if (btn == 'ok'){ + Mumble.addChannel( this.serverid, text, this.chandata.id ); + } + }, this); + } + }, { + scope: this, + text: gettext("Submit name/description"), + handler: function(btn){ + f = btn.ownerCt.ownerCt.getForm().getValues(); + Mumble.renameChannel(this.serverid, this.chandata.id, f.name, f.description); + } + }, { + text: gettext('Delete channel'), + scope: this, + handler: function(btn){ + Ext.Msg.confirm( + gettext('Confirm channel deletion'), + gettext('Are you sure you want to delete channel x?'), + function(btn){ + if( btn == 'yes' ){ + Mumble.removeChannel( this.serverid, this.chandata.id ); + } + }, this); + } + }] }], }], width: 500, diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 12a200b..01a4b59 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -586,6 +586,15 @@ class Mumble( models.Model ): def setUserTexture( self, userid, image ): return self.ctl.setTexture( self.srvid, userid, image ) + def addChannel( self, name, parentid ): + return self.ctl.addChannel( self.srvid, name, parentid ) + + def removeChannel( self, channelid ): + return self.ctl.removeChannel( self.srvid, channelid ) + + def renameChannel( self, channelid, name, description ): + return self.ctl.renameChannel( self.srvid, channelid, name, description ) + def moveChannel( self, channelid, parentid ): return self.ctl.moveChannel( self.srvid, channelid, parentid ) diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html index 6055460..7c0031d 100644 --- a/pyweb/mumble/templates/mumble/mumble.html +++ b/pyweb/mumble/templates/mumble/mumble.html @@ -79,7 +79,9 @@ new Ext.ux.MumbleUserEditor({ serverid: {{MumbleServer.id}} }), - new Ext.ux.MumbleChannelEditor() + new Ext.ux.MumbleChannelEditor({ + serverid: {{MumbleServer.id}} + }) ], source_url: "{% url mumble.views.cvp_json MumbleServer.id %}", imageurl: '{{MUMBLE_MEDIA_PREFIX}}/img', diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index ad4c762..6930eea 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -300,6 +300,27 @@ def deafenUser( request, server, sessionid, deaf ): raise Exception( 'Access denied' ) srv.deafenUser(sessionid, deaf) +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def addChannel( request, server, name, parentid ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + srv.addChannel(name, parentid) + +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def removeChannel( request, server, channelid ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + srv.removeChannel(channelid) + +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def renameChannel( request, server, channelid, name, description ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + srv.renameChannel(channelid, name, description) + @EXT_DIRECT_PROVIDER.register_method( "MumbleUserAdmin" ) def users( request, server ): """ Create a list of MumbleUsers for a given server serialized as a JSON object.