Browse Source

implemented setting user textures

Natenom/support-murmur-13-1446181288462
Michael Ziegler 16 years ago
parent
commit
d62cb9f453
  1. 8
      pyweb/mumble/forms.py
  2. 21
      pyweb/mumble/models.py
  3. 14
      pyweb/mumble/views.py
  4. 20
      template/mumble/mumble.htm

8
pyweb/mumble/forms.py

@ -14,7 +14,8 @@
* GNU General Public License for more details.
"""
from django.forms import ModelForm
from django import forms
from django.forms import Form, ModelForm
from models import *
class MumbleForm( ModelForm ):
@ -28,3 +29,8 @@ class MumbleUserForm( ModelForm ):
model = MumbleUser;
fields = ( 'name', 'password' );
class MumbleTextureForm( Form ):
texturefile = forms.ImageField();

21
pyweb/mumble/models.py

@ -14,6 +14,10 @@
* GNU General Public License for more details.
"""
from PIL import Image
from struct import pack
from zlib import compress
from django.contrib.auth.models import User
from django.db import models
@ -219,6 +223,23 @@ class MumbleUser( models.Model ):
bus.setACL( *acl.pack() );
return value;
def setTexture( self, infile ):
# open image, convert to RGBA, and resize to 600x60
img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 60 ) );
# iterate over the list and pack everything into a string
bgrastring = "";
for ent in list( img.getdata() ):
# ent is in RGBA format, but Murmur wants BGRA (ARGB inverse), so stuff needs
# to be reordered when passed to pack()
bgrastring += pack( "4B", ent[2], ent[1], ent[0], ent[3] );
# compress using zlib
compressed = compress( bgrastring );
# pack the original length in 4 byte big endian, and concat the compressed
# data to it to emulate qCompress().
texture = pack( ">L", len(bgrastring) ) + compressed;
# finally call murmur and set the texture
murmur = self.server.getDbusObject();
murmur.setTexture( dbus.Int32( self.mumbleid ), texture );
@staticmethod
def pre_delete_listener( **kwargs ):

14
pyweb/mumble/views.py

@ -66,6 +66,7 @@ def show( request, server ):
adminform = None;
registered = False;
if request.user.is_authenticated():
if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'reg':
try:
@ -92,8 +93,18 @@ def show( request, server ):
else:
regform = MumbleUserForm( instance=user );
registered = True;
if request.method == 'POST' and 'mode' in request.POST and request.POST['mode'] == 'texture' and registered:
textureform = MumbleTextureForm( request.POST, request.FILES );
if textureform.is_valid():
user.setTexture( request.FILES['texturefile'] );
return HttpResponseRedirect( '/mumble/%d' % int(server) );
else:
textureform = MumbleTextureForm();
else:
regform = None;
textureform = None;
return render_to_response(
'mumble/mumble.htm',
@ -104,6 +115,7 @@ def show( request, server ):
"CurrentUserIsAdmin": isAdmin,
"AdminForm": adminform,
"RegForm": regform,
"TextureForm": textureform,
"Registered": registered,
"DisplayTab": displayTab,
'MumbleActive': True,
@ -168,5 +180,3 @@ def renderListItem( item, level ):
Storage.s.append( ( level, item ) );

20
template/mumble/mumble.htm

@ -37,6 +37,20 @@
{% endif %}
</div>
{% if Registered %}
<div id="mumble_texture">
<h2>User Texture</h2>
You can upload an image that you would like to use as your user texture here.<br />
<form action="" method="post" enctype="multipart/form-data">
<table>
{{ TextureForm }}
</table>
<input type="hidden" name="mode" value="texture" />
<input type="submit" />
</form>
</div>
{% endif %}
{% if CurrentUserIsAdmin %}
<div id="mumble_admin">
<h2>Server administration</h2>
@ -87,6 +101,9 @@
<script type="text/javascript">
Ext.onReady( function(){
Ext.get( 'mumble_registration' ).addClass( 'x-hide-display' );
{% if Registered %}
Ext.get( 'mumble_texture' ).addClass( 'x-hide-display' );
{% endif %}
{% if CurrentUserIsAdmin %}
Ext.get( 'mumble_admin' ).addClass( 'x-hide-display' );
{% endif %}
@ -105,6 +122,9 @@
activeTab: {{ DisplayTab }},
items: [
{ contentEl: 'mumble_registration', title: 'Registration', autoScroll: true },
{% if Registered %}
{ contentEl: 'mumble_texture', title: 'User Texture', autoScroll: true },
{% endif %}
{% if CurrentUserIsAdmin %}
{ contentEl: 'mumble_admin', title: 'Administration', autoScroll: true },
{% endif %}

Loading…
Cancel
Save