Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cmddialog.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "cmddialog.h"
00008 #include "cmdutil.h"
00009 #include "scribuscore.h"
00010 #include "valuedialog.h"
00011 #include "editformats.h"
00012 #include "customfdialog.h"
00013 #include "stylemanager.h"
00014 #include "styleitem.h"
00015 
00016 #include <qmessagebox.h>
00017 #include <qcursor.h>
00018 
00019 PyObject *scribus_newdocdia(PyObject* /* self */)
00020 {
00021        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
00022        bool ret = ScCore->primaryMainWindow()->slotFileNew();
00023        QApplication::restoreOverrideCursor();
00024        return PyInt_FromLong(static_cast<long>(ret));
00025 }
00026 
00027 PyObject *scribus_filedia(PyObject* /* self */, PyObject* args, PyObject* kw)
00028 {
00029        char *caption = const_cast<char*>("");
00030        char *filter = const_cast<char*>("");
00031        char *defName = const_cast<char*>("");
00032        int haspreview = 0;
00033        int issave = 0;
00034        int isdir = 0;
00035        // FIXME: parsing named params failure. e.g. fileDialog(caption="foo", issave=True)
00036        // FIXME: it's a bug in Python. I'm monitoring it
00037        // https://sourceforge.net/tracker/index.php?func=detail&aid=893549&group_id=5470&atid=105470
00038        char* kwargs[] = {const_cast<char*>("caption"), const_cast<char*>("filter"),
00039                                           const_cast<char*>("defaultname"), const_cast<char*>("haspreview"),
00040                                           const_cast<char*>("issave"), const_cast<char*>("isdir"),
00041                                           NULL};
00042        if (!PyArg_ParseTupleAndKeywords(args, kw, "es|esesiii", kwargs,
00043                                                                 "utf-8", &caption, "utf-8", &filter, "utf-8", &defName,
00044                                                                 &haspreview, &issave, &isdir))
00045        {
00046               return NULL;
00047        }
00048        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
00049        /* nobool = Nothing doing boolean for CFileDialog last attrs.
00050        Due the 'isdir' parameter. CFileDialog needs the last 2 pointers
00051        initialized. */
00052        bool nobool = false;
00053        int optionFlags = 0;
00054        if (haspreview)
00055               optionFlags |= fdShowPreview;
00056        if (issave)
00057               optionFlags |= fdExistingFiles;
00058        if (isdir)
00059               optionFlags |= fdDirectoriesOnly;
00060        QString fName = ScCore->primaryMainWindow()->CFileDialog(".",
00061                                                                        QString::fromUtf8(caption),
00062                                                                        QString::fromUtf8(filter),
00063                                                                        QString::fromUtf8(defName),
00064                                                                        optionFlags,
00065                                                                        &nobool,
00066                                                                        &nobool,
00067                                                                        &nobool
00068                                                                       );
00069        QApplication::restoreOverrideCursor();
00070        // FIXME: filename return unicode OK?
00071        return PyString_FromString(fName.utf8());
00072 }
00073 
00074 PyObject *scribus_messdia(PyObject* /* self */, PyObject* args, PyObject* kw)
00075 {
00076        char *caption = const_cast<char*>("");
00077        char *message = const_cast<char*>("");
00078        uint result;
00079        QMessageBox::Icon ico = QMessageBox::NoIcon;
00080        int butt1 = QMessageBox::Ok|QMessageBox::Default;
00081        int butt2 = QMessageBox::NoButton;
00082        int butt3 = QMessageBox::NoButton;
00083        char* kwargs[] = {const_cast<char*>("caption"), const_cast<char*>("message"),
00084                                           const_cast<char*>("icon"), const_cast<char*>("button1"),
00085                                           const_cast<char*>("button2"), const_cast<char*>("button3"), NULL};
00086        if (!PyArg_ParseTupleAndKeywords(args, kw, "eses|iiii", kwargs, "utf-8", &caption, "utf-8", &message, &ico, &butt1, &butt2, &butt3))
00087               return NULL;
00088        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
00089        QMessageBox mb(QString::fromUtf8(caption), QString::fromUtf8(message), ico, butt1, butt2, butt3, ScCore->primaryMainWindow());
00090        result = mb.exec();
00091        QApplication::restoreOverrideCursor();
00092        return PyInt_FromLong(static_cast<long>(result));
00093 }
00094 
00095 PyObject *scribus_valdialog(PyObject* /* self */, PyObject* args)
00096 {
00097        char *caption = const_cast<char*>("");
00098        char *message = const_cast<char*>("");
00099        char *value = const_cast<char*>("");
00100        if (!PyArg_ParseTuple(args, "eses|es", "utf-8", &caption, "utf-8", &message, "utf-8", &value))
00101               return NULL;
00102        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
00103        ValueDialog *d = new ValueDialog(ScCore->primaryMainWindow(), "d", true, 0);
00104        d->dialogLabel->setText(QString::fromUtf8(message));
00105        d->valueEdit->setText(QString::fromUtf8(value));
00106        d->setCaption(QString::fromUtf8(caption));
00107        d->exec();
00108        QApplication::restoreOverrideCursor();
00109        return PyString_FromString(d->valueEdit->text().utf8());
00110 }
00111 
00112 PyObject *scribus_newstyledialog(PyObject*, PyObject* args)
00113 {
00114        if(!checkHaveDocument())
00115               return NULL;
00116 
00117        ScribusDoc *d = ScCore->primaryMainWindow()->doc;
00118        bool ok;
00119        QString s = QInputDialog::getText(
00120                      "New Paragraph Style",
00121                      "Enter name of the new paragraph style:",
00122                      QLineEdit::Normal,
00123                      QString::null, &ok, ScCore->primaryMainWindow());
00124 
00125        if (ok && !s.isEmpty())
00126        {
00127               StyleSet<ParagraphStyle> st;
00128               st.redefine(d->paragraphStyles(), true);
00129               ParagraphStyle p;
00130               p.setName(s);
00131               st.create(p);
00132               d->redefineStyles(st, false);
00133               ScCore->primaryMainWindow()->styleMgr()->setDoc(d);
00134               return PyString_FromString(s.utf8());
00135        }
00136        else
00137               Py_RETURN_NONE;
00138 }
00139 
00143 void cmddialogdocwarnings()
00144 {
00145     QStringList s;
00146     s << scribus_newdocdia__doc__ << scribus_filedia__doc__ << scribus_messdia__doc__;
00147     s << scribus_valdialog__doc__ << scribus_newstyledialog__doc__;
00148 }