Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scgtplugin.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 // kk2006
00008 
00009 
00010 #include "scgtplugin.h"
00011 #include "scgtplugin.moc"
00012 
00013 #include <qcheckbox.h>
00014 #include <qstring.h>
00015 #include <qstringlist.h>
00016 #include <qptrlist.h>
00017 #include <qdir.h>
00018 #include <qobject.h>
00019 #include <qhbox.h>
00020 
00021 /***************************************************************************************/
00022 /***************************************************************************************/
00023 
00024 ScGTPluginManager* ScGTPluginManager::instance_ = 0; // init static variables
00025 
00026 ScGTPluginManager::ScGTPluginManager()
00027 {
00028        plugins_.setAutoDelete(false);
00029 }
00030 
00031 ScGTPluginManager* ScGTPluginManager::instance()
00032 {
00033        if (!ScGTPluginManager::instance_)
00034               instance_ = new ScGTPluginManager();
00035        
00036        return instance_;
00037 }
00038 
00039 void ScGTPluginManager::deleteInstance()
00040 {
00041        delete instance_;
00042        instance_ = 0;
00043 }
00044 
00045 void ScGTPluginManager::registerGTPlugin(ScGTPlugin *plugin)
00046 {
00047        if (plugin)
00048               plugins_.append(plugin);
00049 }
00050 
00051 void ScGTPluginManager::unRegisterGTPlugin(ScGTPlugin *plugin)
00052 {
00053        plugins_.remove(plugin);
00054 }
00055 
00056 void ScGTPluginManager::run()
00057 {
00058        // TODO prefs
00059        ScGTFileDialog *dia = new ScGTFileDialog(".", fileFilter(), 0, "dia");
00060        if (dia->exec())
00061        {
00062               
00063        }
00064        delete dia;
00065 }
00066 
00067 QString ScGTPluginManager::fileFilter()
00068 {
00069        QString filters = "";
00070        QString allSupported = QObject::tr("All Supported Formats") + " (";
00071        for (uint i = 0; i < plugins_.count(); ++i)
00072        {
00073               if (plugins_.at(i)->fileExtensions().count() != 0)
00074               {
00075                      filters += plugins_.at(i)->fileFormatName() + " (";
00076                      QStringList fileExtensions = plugins_.at(i)->fileExtensions();
00077                      for (uint j = 0; j < fileExtensions.count(); ++j)
00078                      {
00079                             filters += "*." + fileExtensions[j] + " ";
00080                             allSupported += "*." + fileExtensions[j] + " ";
00081                      }
00082                      filters = filters.stripWhiteSpace();
00083                      filters += ");;";
00084               }
00085        }
00086        allSupported = allSupported.stripWhiteSpace();
00087        allSupported += ");;";
00088        filters = allSupported + filters;
00089        filters += QObject::tr("All Files (*)");
00090 
00091        return filters;
00092 }
00093 
00094 void ScGTPluginManager::options()
00095 {
00096        
00097 }
00098 
00099 ScGTPluginManager::~ScGTPluginManager()
00100 {
00101        
00102 }
00103 
00104 /***************************************************************************************/
00105 /***************************************************************************************/
00106 
00107 ScGTFileDialog::ScGTFileDialog(const QString & dirName,
00108                                const QString & filters,
00109                                QWidget * parent, const char * name)
00110 : CustomFDialog(parent, dirName, tr("Select a file to import"), filters)
00111 {
00112        customize();
00113 }
00114 
00115 bool ScGTFileDialog::showOptions() const
00116 {
00117        return showOptionsBox_->isChecked();
00118 }
00119 
00120 bool ScGTFileDialog::append() const
00121 {
00122        return appendBox_->isChecked();
00123 }
00124 
00125 void ScGTFileDialog::customize()
00126 {
00127        diaExtension_ = new QHBox(this, "diaExtension_");
00128        diaExtension_->setSpacing(5);
00129 
00130        appendBox_      = new QCheckBox( tr("Append"), diaExtension_, "appendBox_");
00131        showOptionsBox_ = new QCheckBox( tr("Show options"), diaExtension_, "showOptionsBox_");
00132 
00133        addWidgets(0, diaExtension_, 0);
00134 }
00135 
00136 ScGTFileDialog::~ScGTFileDialog()
00137 {
00138        delete showOptionsBox_;
00139        delete appendBox_;
00140        delete diaExtension_;
00141 }
00142 
00143 /***************************************************************************************/
00144 /***************************************************************************************/
00145 
00146 
00147