fix handling of unicode characters in filenames, bump version to 1.0.0b2

This commit is contained in:
Kilian Valkhof 2010-03-28 16:11:50 +02:00
parent e382b579ec
commit a506c0fee4
5 changed files with 45 additions and 24 deletions

8
debian/changelog vendored
View file

@ -1,6 +1,6 @@
trimage (1.0.0b-0ubuntu1) jaunty; urgency=low trimage (1.0.0b2-0ubuntu1) jaunty; urgency=low
* Trimage image compressor * correct parsing of unicode characters in filenames
* changelog
-- Kilian Valkhof <help@trimage.org> Tue, 23 Mar 2010 20:18:17 +0100
-- Kilian Valkhof <kilian@kdesktop> Sun, 28 Mar 2010 16:09:45 +0200

View file

@ -3,7 +3,7 @@
from distutils.core import setup from distutils.core import setup
setup(name = "trimage", setup(name = "trimage",
version = "1.0.0b", version = "1.0.0b2",
description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files", description = "Trimage image compressor - A cross-platform tool for optimizing PNG and JPG files",
author = "Kilian Valkhof, Paul Chaplin", author = "Kilian Valkhof, Paul Chaplin",
author_email = "help@trimage.org", author_email = "help@trimage.org",

View file

@ -13,7 +13,8 @@ from hurry.filesize import *
from ui import Ui_trimage from ui import Ui_trimage
VERSION = "1.0.0b" VERSION = "1.0.0b2"
class StartQT4(QMainWindow): class StartQT4(QMainWindow):
@ -100,7 +101,8 @@ class StartQT4(QMainWindow):
imagedir = listdir(directory) imagedir = listdir(directory)
filelist = QStringList() filelist = QStringList()
for image in imagedir: for image in imagedir:
image = QString(path.join(dirpath, image)) image = self.unicodize(path.join(dirpath, image))
if self.checkname(image):
filelist.append(image) filelist.append(image)
self.delegator(filelist) self.delegator(filelist)
@ -109,13 +111,16 @@ class StartQT4(QMainWindow):
self.showapp = False self.showapp = False
image = path.abspath(image) image = path.abspath(image)
filecmdlist = QStringList() filecmdlist = QStringList()
filecmdlist.append(image) if self.checkname(image):
filecmdlist.append(self.unicodize(image))
self.delegator(filecmdlist) self.delegator(filecmdlist)
def file_drop(self, images): def file_drop(self, images):
""" """
Get a file from the drag and drop handler and send it to compress_file. Get a file from the drag and drop handler and send it to compress_file.
""" """
for image in images:
image = self.unicodize(unicode(image).encode('utf-8'))
self.delegator(images) self.delegator(images)
def file_dialog(self): def file_dialog(self):
@ -126,6 +131,10 @@ class StartQT4(QMainWindow):
"", # directory "", # directory
# this is a fix for file dialog differentiating between cases # this is a fix for file dialog differentiating between cases
"Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)") "Image files (*.png *.jpg *.jpeg *.PNG *.JPG *.JPEG)")
for image in images:
image = self.unicodize(unicode(image))
self.delegator(images) self.delegator(images)
def recompress_files(self): def recompress_files(self):
@ -151,7 +160,7 @@ class StartQT4(QMainWindow):
self.imagelist.append(("Compressing...", "", "", "", image, self.imagelist.append(("Compressing...", "", "", "", image,
QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif"))))) QIcon(QPixmap(self.ui.get_image("pixmaps/compressing.gif")))))
else: else:
sys.stderr.write("[error] %s not an image file" % image) sys.stderr.write("[error] %s not an image file\n" % image)
self.update_table() self.update_table()
self.thread.compress_file(delegatorlist, self.showapp, self.verbose, self.thread.compress_file(delegatorlist, self.showapp, self.verbose,
@ -195,7 +204,7 @@ class StartQT4(QMainWindow):
def checkname(self, name): def checkname(self, name):
"""Check if the file is a jpg or png.""" """Check if the file is a jpg or png."""
return path.splitext(str(name))[1].lower() in [".jpg", ".jpeg", ".png"] return path.splitext(unicode(name))[1].lower() in [".jpg", ".jpeg", ".png"]
def enable_recompress(self): def enable_recompress(self):
"""Enable the recompress button.""" """Enable the recompress button."""
@ -230,6 +239,13 @@ class StartQT4(QMainWindow):
else: else:
raise raise
def unicodize(self, obj, encoding='utf-8'):
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
class TriTableModel(QAbstractTableModel): class TriTableModel(QAbstractTableModel):
def __init__(self, parent, imagelist, header, *args): def __init__(self, parent, imagelist, header, *args):
@ -294,7 +310,7 @@ class Worker(QThread):
"""Compress the given file, get data from it and call update_table.""" """Compress the given file, get data from it and call update_table."""
for image in self.images: for image in self.images:
#gather old file data #gather old file data
filename = str(image[0]) filename = unicode(image[0])
icon = image[1] icon = image[1]
oldfile = QFileInfo(filename) oldfile = QFileInfo(filename)
name = oldfile.fileName() name = oldfile.fileName()
@ -305,10 +321,9 @@ class Worker(QThread):
extention = path.splitext(filename)[1] extention = path.splitext(filename)[1]
#decide with tool to use #decide with tool to use
if extention in [".jpg", ".jpeg"]: if extention in [".jpg", ".jpeg"]:
runString = "jpegoptim -f --strip-all '%(file)s'" runString = u"jpegoptim -f --strip-all '%(file)s'"
elif extention in [".png"]: elif extention in [".png"]:
runString = ("optipng -force -o7 '%(file)s';" runString = (u"optipng -force -o7 '%(file)s'; advpng -z4 '%(file)s'")
"advpng -z4 '%(file)s'")
else: else:
sys.stderr.write("[error] %s not an image file" % filename) sys.stderr.write("[error] %s not an image file" % filename)

View file

@ -9,7 +9,7 @@ class TrimageTableView(QTableView):
self.setAcceptDrops(True) self.setAcceptDrops(True)
def dragEnterEvent(self, event): def dragEnterEvent(self, event):
if event.mimeData().hasFormat("text/uri-list"): if event.mimeData().hasUrls:
event.accept() event.accept()
else: else:
event.ignore() event.ignore()
@ -18,10 +18,12 @@ class TrimageTableView(QTableView):
event.accept() event.accept()
def dropEvent(self, event): def dropEvent(self, event):
files = str(event.mimeData().data("text/uri-list")).strip().split() event.accept()
for i, file in enumerate(files): filelist = []
files[i] = QUrl(QString(file)).toLocalFile() for url in event.mimeData().urls():
self.emit(SIGNAL("fileDropEvent"), (files)) filelist.append(unicode(url.toLocalFile()))
self.emit(SIGNAL("fileDropEvent"), (filelist))
class Ui_trimage(object): class Ui_trimage(object):

View file

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<meta charset="utf8"> <meta charset="utf8">
<title>Trimage image compressor</title> <title>Trimage (lossless) image compressor</title>
<link href="http://github.com/Kilian/sencss/raw/master/source/sen.css" rel="stylesheet" type="text/css"> <link href="http://github.com/Kilian/sencss/raw/master/source/sen.css" rel="stylesheet" type="text/css">
<style> <style>
body { body {
@ -42,7 +42,6 @@
-webkit-column-count:3; -webkit-column-count:3;
-moz-column-gap:2em; -moz-column-gap:2em;
-webkit-column-gap:2em; -webkit-column-gap:2em;
text-align:justify;
} }
img { img {
margin-bottom:1.5em; margin-bottom:1.5em;
@ -70,8 +69,8 @@
<body> <body>
<div id="wrap"> <div id="wrap">
<h1><img src="trimage-icon.png" alt=""> Trimage image compressor &ndash; 1.0.0b (beta)</h1> <h1><img src="trimage-icon.png" alt=""> Trimage image compressor &ndash; 1.0.0b2 (beta)</h1>
<span class="subtitle">A cross-platform tool for optimizing PNG and JPG files.</span> <span class="subtitle">A cross-platform tool for losslessy optimizing PNG and JPG files.</span>
<p class="tri">Trimage is a cross-platform GUI and command-line interface to optimize image <p class="tri">Trimage is a cross-platform GUI and command-line interface to optimize image
files via <a href="http://optipng.sourceforge.net/">optipng</a>, files via <a href="http://optipng.sourceforge.net/">optipng</a>,
<a href="http://advancemame.sourceforge.net/comp-readme.html">advpng</a> and <a href="http://advancemame.sourceforge.net/comp-readme.html">advpng</a> and
@ -94,6 +93,11 @@
<li><code>sudo apt-get install trimage</code></li> <li><code>sudo apt-get install trimage</code></li>
</ol> </ol>
<p>If you are still on Jaunty, read <a href="https://launchpad.net/+help/soyuz/ppa-sources-list.html">this guide</a> on installing PPA's.</p> <p>If you are still on Jaunty, read <a href="https://launchpad.net/+help/soyuz/ppa-sources-list.html">this guide</a> on installing PPA's.</p>
<h3>Arch Linux</h3>
Trimage is available from AUR, to install, type:
<ol>
<li><code>yaourt -S trimage-git</code></li>
</ol>
<h3><img src="linux.png" alt=""> Other *nix</h3> <h3><img src="linux.png" alt=""> Other *nix</h3>
<ol> <ol>
<li>Download the source via git or bzr (see repositories)</li> <li>Download the source via git or bzr (see repositories)</li>