Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

tabexternaltoolswidget.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 *   Copyright (C) 2005 by Craig Bradney                                   *
00009 *   cbradney@zip.com.au                                                   *
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 *   This program is distributed in the hope that it will be useful,       *
00017 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019 *   GNU General Public License for more details.                          *
00020 *                                                                         *
00021 *   You should have received a copy of the GNU General Public License     *
00022 *   along with this program; if not, write to the                         *
00023 *   Free Software Foundation, Inc.,                                       *
00024 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025 ***************************************************************************/
00026 
00027 #include "tabexternaltoolswidget.h"
00028 #include <QFileDialog>
00029 #include <QProcess>
00030 #include "util_ghostscript.h"
00031 #include "scpaths.h"
00032 #include "prefsstructs.h"
00033 #include "latexhelpers.h"
00034 
00035 TabExternalToolsWidget::TabExternalToolsWidget(struct ApplicationPrefs *prefsData, QWidget* parent)
00036 : QWidget(parent)
00037 {
00038     setupUi(this);
00039     // switched off as it's called in main prefs classes - PV
00040     //restoreDefaults(prefsData);
00041     
00042     connect(psToolChangeButton, SIGNAL(clicked()), this, SLOT(changePostScriptTool()));
00043     connect(imageToolChangeButton, SIGNAL(clicked()), this, SLOT(changeImageTool()));
00044     connect(extBrowserToolChangeButton, SIGNAL(clicked()), this, SLOT(changeExtBrowserTool()));
00045     connect(latexEditorChangeButton, SIGNAL(clicked()), this, SLOT(changeLatexEditor()));
00046     connect(rescanButton, SIGNAL(clicked()), this, SLOT(rescanForTools()));
00047     connect(latexConfigUpButton, SIGNAL(clicked()), this, SLOT(upButtonPressed()));
00048     connect(latexConfigDownButton, SIGNAL(clicked()), this, SLOT(downButtonPressed()));
00049     connect(latexConfigAddButton, SIGNAL(clicked()), this, SLOT(addConfig()));
00050     connect(latexConfigDeleteButton, SIGNAL(clicked()), this, SLOT(deleteConfig()));
00051     connect(latexEmbeddedEditorCheckBox, SIGNAL(stateChanged(int)), 
00052             this, SLOT(changeLatexEmbeddedActive(int)));
00053 }
00054 
00055 TabExternalToolsWidget::~TabExternalToolsWidget()
00056 {
00057 }
00058 
00059 const QString TabExternalToolsWidget::newPSTool() const 
00060 { 
00061     return ScPaths::separatorsToSlashes(psToolLineEdit->text()); 
00062 }
00063 
00064 const QString TabExternalToolsWidget::newImageTool() const 
00065 { 
00066     return ScPaths::separatorsToSlashes(imageToolLineEdit->text());
00067 }
00068 
00069 const QString TabExternalToolsWidget::newExtBrowserTool() const 
00070 { 
00071     return ScPaths::separatorsToSlashes(extBrowserToolLineEdit->text()); 
00072 }
00073 
00074 const QString TabExternalToolsWidget::newLatexEditor() const 
00075 {
00076     return ScPaths::separatorsToSlashes(latexEditorLineEdit->text());
00077 }
00078 
00079 const QStringList TabExternalToolsWidget::newLatexConfigs() const
00080 {
00081     QStringList list;
00082     int i;
00083     for (i=0; i < latexConfigsListWidget->count(); i++) {
00084         list.append(latexConfigsListWidget->item(i)->data(Qt::UserRole).toString());
00085     }
00086     
00087     return list;
00088 }
00089 
00090 void TabExternalToolsWidget::restoreDefaults(struct ApplicationPrefs *prefsData)
00091 {
00092     psToolLineEdit->setText(QDir::convertSeparators(prefsData->gs_exe));
00093     psAntialiasTextCheckBox->setChecked(prefsData->gs_AntiAliasText);
00094     psAntialiasGraphicsCheckBox->setChecked(prefsData->gs_AntiAliasGraphics);
00095     psResolutionSpinBox->setValue(prefsData->gs_Resolution);
00096     imageToolLineEdit->setText(QDir::convertSeparators(prefsData->imageEditorExecutable));
00097     extBrowserToolLineEdit->setText(QDir::convertSeparators(prefsData->extBrowserExecutable));
00098     latexResolutionSpinBox->setValue(prefsData->latexResolution);
00099     latexEditorLineEdit->setText(prefsData->latexEditorExecutable);
00100     latexForceDpiCheckBox->setCheckState(prefsData->latexForceDpi?Qt::Checked:Qt::Unchecked);
00101     latexEmbeddedEditorCheckBox->setCheckState(prefsData->latexUseEmbeddedEditor?Qt::Checked:Qt::Unchecked);
00102     latexEmptyFrameCheckBox->setCheckState(prefsData->latexStartWithEmptyFrames?Qt::Checked:Qt::Unchecked);
00103     latexConfigsListWidget->clear();
00104     QStringList configs = prefsData->latexConfigs;
00105     foreach (QString config, configs) {
00106         insertConfigItem(config);
00107     }
00108     latexConfigsListWidget->setCurrentRow(0);
00109 }
00110 
00111 void TabExternalToolsWidget::changePostScriptTool()
00112 {
00113     QFileInfo fi(psToolLineEdit->text());
00114     QString s = QFileDialog::getOpenFileName(this, tr("Locate Ghostscript"), fi.path());
00115     if (!s.isEmpty())
00116         psToolLineEdit->setText( QDir::convertSeparators(s) );
00117 }
00118 
00119 void TabExternalToolsWidget::changeImageTool()
00120 {
00121     QFileInfo fi(imageToolLineEdit->text());
00122     QString s = QFileDialog::getOpenFileName(this, tr("Locate your image editor"), fi.path());
00123     if (!s.isEmpty())
00124         imageToolLineEdit->setText( QDir::convertSeparators(s) );
00125 }
00126 
00127 void TabExternalToolsWidget::changeExtBrowserTool()
00128 {
00129     QFileInfo fi(extBrowserToolLineEdit->text());
00130     QString s = QFileDialog::getOpenFileName(this, tr("Locate your web browser"), fi.path());
00131     if (!s.isEmpty())
00132         extBrowserToolLineEdit->setText( QDir::convertSeparators(s) );
00133 }
00134 
00135 void TabExternalToolsWidget::changeLatexEditor()
00136 {
00137     QFileInfo fi(latexEditorLineEdit->text());
00138     QString s = QFileDialog::getOpenFileName(this, tr("Locate your LaTeX editor"), fi.path());
00139     if (!s.isEmpty())
00140         latexEditorLineEdit->setText( QDir::convertSeparators(s) );
00141 }
00142 
00143 void TabExternalToolsWidget::insertConfigItem(QString config, int row)
00144 {
00145     QListWidgetItem *widget = new QListWidgetItem(
00146             QString("%1 (%2)").arg(LatexConfigCache::instance()->parser(config)->description()).
00147             arg(QDir::toNativeSeparators(QDir::cleanPath(config))));
00148     widget->setData(Qt::UserRole, config);
00149     if (row == -1) {
00150         latexConfigsListWidget->addItem(widget);
00151     } else {
00152         latexConfigsListWidget->insertItem(row, widget);
00153     }
00154     latexConfigsListWidget->setCurrentItem(widget);
00155 }
00156 
00157 void TabExternalToolsWidget::addConfig()
00158 {
00159     QString s = QFileDialog::getOpenFileName(this, 
00160         tr("Locate a Configuration file"), 
00161         ScPaths::instance().shareDir() + "/editorconfig/",
00162         tr("Configuration files")+" (*.xml)");
00163     if (!s.isEmpty()) {
00164         insertConfigItem(s);
00165     }
00166 }
00167 
00168 void TabExternalToolsWidget::deleteConfig()
00169 {
00170     if (latexConfigsListWidget->currentItem()) {
00171         delete latexConfigsListWidget->currentItem();
00172     }
00173 }
00174 
00175 void TabExternalToolsWidget::upButtonPressed()
00176 {
00177     if (latexConfigsListWidget->currentRow() < 1) return;
00178     QListWidgetItem *old = latexConfigsListWidget->currentItem();
00179     QString config = old->data(Qt::UserRole).toString();
00180     insertConfigItem(config, latexConfigsListWidget->currentRow()-1);
00181     delete old;
00182 }
00183 
00184 void TabExternalToolsWidget::downButtonPressed()
00185 {
00186     if (latexConfigsListWidget->currentRow() >= latexConfigsListWidget->count()-1) return;
00187     QListWidgetItem *old = latexConfigsListWidget->currentItem();
00188     QString config = old->data(Qt::UserRole).toString();
00189     insertConfigItem(config, latexConfigsListWidget->currentRow()+2);
00190     delete old;
00191 }
00192 
00193 
00194 bool TabExternalToolsWidget::fileInPath(QString file)
00195 {
00196     if (file.isEmpty()) 
00197         return false;
00198     file = file.split(' ', QString::SkipEmptyParts).at(0); //Ignore parameters
00199     
00200     file = ScPaths::separatorsToSlashes(file);
00201     if (file.indexOf('/') >= 0) {
00202         //Looks like an absolute path
00203         QFileInfo info(file);
00204         return info.exists();
00205     }
00206     
00207     //Get $PATH
00208     QStringList env = QProcess::systemEnvironment();
00209     QString path;
00210     foreach (QString line, env) {
00211         if (line.indexOf("PATH") == 0) {
00212             path = line.mid(5); //Strip "PATH="
00213             break;
00214         }
00215     }
00216     QStringList splitpath;
00217     //TODO: Check this again! OS2?
00218     #ifdef _WIN32
00219         splitpath = path.split(';', QString::SkipEmptyParts);
00220     #else
00221         splitpath = path.split(':', QString::SkipEmptyParts);
00222     #endif
00223     foreach (QString dir, splitpath) {
00224         QFileInfo info(dir, file);
00225         if (info.exists()) {
00226             return true;
00227         }
00228     }
00229     return false;
00230 }
00231 
00232 void TabExternalToolsWidget::rescanForTools()
00233 {
00234     if (!fileInPath(psToolLineEdit->text()))
00235     {
00236         QString gsDef = getGSDefaultExeName();
00237         psToolLineEdit->setText( QDir::convertSeparators(gsDef) );
00238     }
00239     
00240     if (!fileInPath(imageToolLineEdit->text()))
00241         imageToolLineEdit->setText("gimp");
00242     
00243     if (!fileInPath(latexEditorLineEdit->text())) {
00244         QStringList editors;
00245         editors << 
00246                 /*Linux */ "kwrite" << "kate" << "gedit" << "gvim" <<
00247                 /*Windows */ "notepad" << 
00248                 /*Mac OS*/ "open";
00249         foreach (QString editor, editors) {
00250             if (fileInPath(editor)) {
00251                 latexEditorLineEdit->setText(editor);
00252                 break;
00253             }
00254         }
00255     }
00256 }
00257 
00258 void TabExternalToolsWidget::changeLatexEmbeddedActive(int state)
00259 {
00260     bool enable = state == Qt::Unchecked;
00261     latexEditorLineEdit->setEnabled(enable);
00262     latexEditorChangeButton->setEnabled(enable);
00263 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.