Index: cmdobj.cpp
===================================================================
RCS file: /cvs/Scribus/scribus/plugins/scriptplugin/cmdobj.cpp,v
retrieving revision 1.18
diff -u -r1.18 cmdobj.cpp
--- cmdobj.cpp	10 Dec 2004 19:28:41 -0000	1.18
+++ cmdobj.cpp	11 Dec 2004 18:18:26 -0000
@@ -4,12 +4,12 @@
 PyObject *scribus_newrect(PyObject *self, PyObject* args)
 {
 	double x, y, b, h;
-	char *Name = "";
-	if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
+	char *Name = NULL;
+	if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -19,8 +19,8 @@
 															Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
 	Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
 	if (Name != "")
-		Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
-	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
+		Carrier->doc->ActPage->Items.at(i)->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName.utf8());
 }
 
 
@@ -28,11 +28,11 @@
 {
 	double x, y, b, h;
 	char *Name = "";
-	if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
+	if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -40,8 +40,8 @@
 	int i = Carrier->doc->ActPage->PaintEllipse(ValueToPoint(x), ValueToPoint(y), ValueToPoint(b), ValueToPoint(h),  Carrier->doc->Dwidth, Carrier->doc->Dbrush, Carrier->doc->Dpen);
 	Carrier->doc->ActPage->SetOvalFrame(Carrier->doc->ActPage->Items.at(i));
 	if (Name != "")
-		Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
-	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
+		Carrier->doc->ActPage->Items.at(i)->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName.utf8());
 }
 
 
@@ -49,11 +49,11 @@
 {
 	double x, y, b, h;
 	char *Name = "";
-	if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
+	if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -61,8 +61,8 @@
 	int i = Carrier->doc->ActPage->PaintPict(ValueToPoint(x), ValueToPoint(y), ValueToPoint(b), ValueToPoint(h));
 	Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
 	if (Name != "")
-		Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
-	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
+		Carrier->doc->ActPage->Items.at(i)->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName.utf8());
 }
 
 
@@ -70,11 +70,11 @@
 {
 	double x, y, b, h;
 	char *Name = "";
-	if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
+	if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -84,8 +84,8 @@
 															Carrier->doc->Dwidth, Carrier->doc->DpenText);
 	Carrier->doc->ActPage->SetRectFrame(Carrier->doc->ActPage->Items.at(i));
 	if (Name != "")
-		Carrier->doc->ActPage->Items.at(i)->AnName = QString(Name);
-	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName);
+		Carrier->doc->ActPage->Items.at(i)->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(Carrier->doc->ActPage->Items.at(i)->AnName.utf8());
 }
 
 
@@ -93,11 +93,11 @@
 {
 	double x, y, b, h;
 	char *Name = "";
-	if (!PyArg_ParseTuple(args, "dddd|s", &x, &y, &b, &h, &Name))
+	if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &b, &h, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -127,8 +127,8 @@
 	Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), i, false, false);
 	Carrier->doc->ActPage->AdjustItemSize(it);
 	if (Name != "")
-		it->AnName = QString(Name);
-	return PyString_FromString(it->AnName);
+		it->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(it->AnName.utf8());
 }
 
 
@@ -136,7 +136,8 @@
 {
 	char *Name = "";
 	PyObject *il;
-	if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
+	// FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
+	if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
@@ -151,7 +152,7 @@
 		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values","python error"));
 		return NULL;
 	}
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -200,9 +201,9 @@
 	Carrier->doc->ActPage->AdjustItemSize(it);
 	if (Name != "")
 	{
-		it->AnName = QString(Name);
+		it->AnName = QString::fromUtf8(Name);
 	}
-	return PyString_FromString(it->AnName);
+	return PyString_FromString(it->AnName.utf8());
 }
 
 
@@ -210,7 +211,8 @@
 {
 	char *Name = "";
 	PyObject *il;
-	if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
+	// FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
+	if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
@@ -225,7 +227,7 @@
 		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values","python error"));
 		return NULL;
 	}
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -278,15 +280,16 @@
 	Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
 	Carrier->doc->ActPage->AdjustItemSize(it);
 	if (Name != "")
-		it->AnName = QString(Name);
-	return PyString_FromString(it->AnName);
+		it->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(it->AnName.utf8());
 }
 
 PyObject *scribus_bezierline(PyObject *self, PyObject* args)
 {
 	char *Name = "";
 	PyObject *il;
-	if ((!PyArg_ParseTuple(args, "O|s", &il, &Name)) || (!PyList_Check(il)))
+	// FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
+	if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
@@ -301,7 +304,7 @@
 		PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values","python error"));
 		return NULL;
 	}
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
@@ -363,8 +366,8 @@
 	Carrier->doc->ActPage->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false);
 	Carrier->doc->ActPage->AdjustItemSize(it);
 	if (Name != "")
-		it->AnName = QString(Name);
-	return PyString_FromString(it->AnName);
+		it->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(it->AnName.utf8());
 }
 
 
@@ -376,19 +379,19 @@
 	char *Name = "";
 	char *TextB = "";
 	char *PolyB = "";
-	if (!PyArg_ParseTuple(args, "ddss|s", &x, &y, &TextB, &PolyB, &Name))
+	if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(Name)))
+	if (ItemExists(QString::fromUtf8(Name)))
 	{
 		PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists","python error"));
 		return NULL;
 	}
 	//FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
 	// its sets for us?
-	int i = GetItem(QString(TextB));
-	int ii = GetItem(QString(PolyB));
+	int i = GetItem(QString::fromUtf8(TextB));
+	int ii = GetItem(QString::fromUtf8(PolyB));
 	if ((i == -1) || (ii == -1))
 	{
 		PyErr_SetString(NotFoundError, QObject::tr("Object not found","python error"));
@@ -398,11 +401,13 @@
 	Carrier->doc->ActPage->SelItem.append(Carrier->doc->ActPage->Items.at(i));
 	Carrier->doc->ActPage->SelItem.append(Carrier->doc->ActPage->Items.at(ii));
 	PageItem *it = Carrier->doc->ActPage->Items.at(i);
+	// FIXME: If this fails, because of eg wrong item types, we don't notice. Worse, change the
+	// name of the item BEFORE we fail to notice. Looks like a core bug.
 	Carrier->doc->ActPage->ToPathText();
 	Carrier->doc->ActPage->MoveItem(ValueToPoint(x) - it->Xpos, ValueToPoint(y) - it->Ypos, it);
 	if (Name != "")
-		it->AnName = QString(Name);
-	return PyString_FromString(it->AnName);
+		it->AnName = QString::fromUtf8(Name);
+	return PyString_FromString(it->AnName.utf8());
 }
 
 
@@ -411,11 +416,11 @@
 PyObject *scribus_deleteobj(PyObject *self, PyObject* args)
 {
 	char *Name = "";
-	if (!PyArg_ParseTuple(args, "|s", &Name))
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	PageItem *i = GetUniqueItem(QString(Name));
+	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
 	if (i == NULL)
 		return NULL;
 	i->OwnPage->SelItem.clear();
@@ -433,11 +438,11 @@
 	char *name = "";
 	int state = -1;
 
-	if (!PyArg_ParseTuple(args, "s|i", &name, &state))
+	if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	PageItem *i = GetUniqueItem(QString(name));
+	PageItem *i = GetUniqueItem(QString::fromUtf8(name));
 	if (i == NULL)
 		return NULL;
 	if (state == -1)
@@ -454,11 +459,11 @@
 PyObject *scribus_objectexists(PyObject *self, PyObject* args)
 {
 	char* name = "";
-	if (!PyArg_ParseTuple(args, "|s", &name))
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	if (ItemExists(QString(name)))
+	if (ItemExists(QString::fromUtf8(name)))
 		return PyBool_FromLong(static_cast<long>(true));
 	return PyBool_FromLong(static_cast<long>(false));
 }
@@ -470,16 +475,16 @@
  */
 PyObject *scribus_setstyle(PyObject *self, PyObject* args)
 {
-	char *Style = "";
+	char *style = "";
 	char *name = "";
-	if (!PyArg_ParseTuple(args, "s|s", &Style, &name))
+	if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
 		return NULL;
 	if(!checkHaveDocument())
 		return NULL;
-	PageItem *item = GetUniqueItem(QString(name));
+	PageItem *item = GetUniqueItem(QString::fromUtf8(name));
 	if (item == NULL)
 		return NULL;
-	if (item->PType == FRAME_TEXT)
+	if ((item->PType == FRAME_TEXT) || (item->PType == FRAME_PATHTEXT))
 	{
 		/*
 		 * First, find the style number associated with the requested style
@@ -492,7 +497,7 @@
 		// We start at zero here because it's OK to match an internal name
 		for (uint i=0; i < Carrier->doc->Vorlagen.count(); ++i)
 		{
-			if (Carrier->doc->Vorlagen[i].Vname == Style) {
+			if (Carrier->doc->Vorlagen[i].Vname == QString::fromUtf8(style)) {
 				found = true;
 				styleid = i;
 				break;
@@ -536,7 +541,7 @@
 	*/
 	for (uint i=0; i < Carrier->doc->Vorlagen.count(); ++i)
 	{
-		if (PyList_Append(styleList, PyString_FromString(Carrier->doc->Vorlagen[i].Vname)))
+		if (PyList_Append(styleList, PyString_FromString(Carrier->doc->Vorlagen[i].Vname.utf8())))
 		{
 			// An exception will have already been set by PyList_Append apparently.
 			return NULL;
