Back to index

scribus-ng  1.3.4.dfsg+svn20071115
nftemplate.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 /***************************************************************************
00008  *   Riku Leino, tsoots@gmail.com                                          *
00009  ***************************************************************************/
00010 #include <qstring.h>
00011 #include <qcursor.h>
00012 #include <qdir.h>
00013 #include <qwidget.h>
00014 
00015 #include "scribus.h"
00016 #include "scribuscore.h"
00017 #include "nftemplate.h"
00018 #include "nftemplate.moc"
00019 #include "nftdialog.h"
00020 #include "scraction.h"
00021 #include "menumanager.h"
00022 #include "undomanager.h"
00023 #include "prefsmanager.h"
00024 
00025 int newfromtemplateplugin_getPluginAPIVersion()
00026 {
00027        return PLUGIN_API_VERSION;
00028 }
00029 
00030 ScPlugin* newfromtemplateplugin_getPlugin()
00031 {
00032        NewFromTemplatePlugin* plug = new NewFromTemplatePlugin();
00033        Q_CHECK_PTR(plug);
00034        return plug;
00035 }
00036 
00037 void newfromtemplateplugin_freePlugin(ScPlugin* plugin)
00038 {
00039        NewFromTemplatePlugin* plug = dynamic_cast<NewFromTemplatePlugin*>(plugin);
00040        Q_ASSERT(plug);
00041        delete plug;
00042 }
00043 
00044 NewFromTemplatePlugin::NewFromTemplatePlugin() : ScActionPlugin()
00045 {
00046        // Set action info in languageChange, so we only have to do
00047        // it in one place.
00048        languageChange();
00049 }
00050 
00051 NewFromTemplatePlugin::~NewFromTemplatePlugin() {};
00052 
00053 void NewFromTemplatePlugin::languageChange()
00054 {
00055        // Note that we leave the unused members unset. They'll be initialised
00056        // with their default ctors during construction.
00057        // Action name
00058        m_actionInfo.name = "NewFromDocumentTemplate";
00059        // Action text for menu, including accel
00060        m_actionInfo.text = tr("New &from Template...");
00061        // Shortcut
00062        m_actionInfo.keySequence = "Ctrl+Alt+N";
00063        // Menu
00064        m_actionInfo.menu = "File";
00065        m_actionInfo.menuAfterName = "New";
00066        m_actionInfo.enabledOnStartup = true;
00067 }
00068 
00069 const QString NewFromTemplatePlugin::fullTrName() const
00070 {
00071        return QObject::tr("New From Template");
00072 }
00073 
00074 const ScActionPlugin::AboutData* NewFromTemplatePlugin::getAboutData() const
00075 {
00076        AboutData* about = new AboutData;
00077        Q_CHECK_PTR(about);
00078        about->authors = QString::fromUtf8("Riku Leino <riku@scribus.info>");
00079        about->shortDescription = tr("Load documents with predefined layout");
00080        about->description = tr("Start a document from a template made by other users or "
00081                                "yourself (f.e. for documents you have a constant style).");
00082     // about->version
00083     // about->releaseDate
00084     // about->copyright
00085        about->license = "GPL";
00086        return about;
00087 }
00088 
00089 void NewFromTemplatePlugin::deleteAboutData(const AboutData* about) const
00090 {
00091        Q_ASSERT(about);
00092        delete about;
00093 }
00094 
00095 bool NewFromTemplatePlugin::run(ScribusDoc* doc, QString target)
00096 {
00097        Q_ASSERT(target.isNull());
00098        Nft = new MenuNFT();
00099        Q_CHECK_PTR(Nft);
00100        Nft->RunNFTPlug(doc);
00101        return true;
00102 }
00103 
00104 
00105 void MenuNFT::RunNFTPlug(ScribusDoc* /*doc*/)
00106 {
00107        ScribusMainWindow* mw=ScCore->primaryMainWindow();
00108        nftdialog* nftdia = new nftdialog(mw, ScCore->getGuiLanguage(), PrefsManager::instance()->appPrefs.documentTemplatesDir);
00109        if (nftdia->exec())
00110        {
00111               qApp->setOverrideCursor(QCursor(Qt::WaitCursor), true);
00112               if (mw->loadDoc(QDir::cleanDirPath(nftdia->currentDocumentTemplate->file)))
00113               {
00114                      mw->doc->hasName = false;
00115                      UndoManager::instance()->renameStack(nftdia->currentDocumentTemplate->name);
00116                      mw->doc->DocName = nftdia->currentDocumentTemplate->name;
00117                      mw->updateActiveWindowCaption(QObject::tr("Document Template: ") + nftdia->currentDocumentTemplate->name);
00118                      QDir::setCurrent(PrefsManager::instance()->documentDir());
00119                      mw->removeRecent(QDir::cleanDirPath(nftdia->currentDocumentTemplate->file));
00120               }
00121               qApp->restoreOverrideCursor();
00122        }
00123        delete nftdia;
00124 }